2014-01-02 07:07:43 +01:00
< ? php
2019-12-15 10:02:20 +01:00
/* Copyright ( C ) 2013 - 2014 Jean - François Ferry < jfefe @ aternatik . fr >
* Copyright ( C ) 2018 Nicolas ZABOURI < info @ inovea - conseil . com >
2021-03-14 23:33:06 +01:00
* Copyright ( C ) 2018 - 2021 Frédéric France < frederic . france @ netlogic . fr >
2018-08-12 19:59:39 +02:00
*
2014-01-02 07:07:43 +01:00
* This program is free software : you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation , either version 3 of the License , or
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
2019-09-23 21:55:30 +02:00
* along with this program . If not , see < https :// www . gnu . org / licenses />.
2014-01-02 07:07:43 +01:00
*/
/**
2019-12-15 10:02:20 +01:00
* \file htdocs / resource / list . php
2018-03-31 18:48:27 +02:00
* \ingroup resource
* \brief Page to manage resource objects
2014-01-02 07:07:43 +01:00
*/
2015-11-26 20:30:11 +01:00
require '../main.inc.php' ;
2016-01-21 11:18:29 +01:00
require_once DOL_DOCUMENT_ROOT . '/resource/class/dolresource.class.php' ;
2014-01-02 07:07:43 +01:00
2018-05-26 18:41:16 +02:00
// Load translation files required by the page
2019-11-13 19:35:39 +01:00
$langs -> loadLangs ( array ( " resource " , " companies " , " other " ));
2014-01-02 07:07:43 +01:00
// Get parameters
2019-01-27 11:55:16 +01:00
$id = GETPOST ( 'id' , 'int' );
$action = GETPOST ( 'action' , 'alpha' );
2014-01-02 07:07:43 +01:00
2019-01-27 11:55:16 +01:00
$lineid = GETPOST ( 'lineid' , 'int' );
$element = GETPOST ( 'element' , 'alpha' );
$element_id = GETPOST ( 'element_id' , 'int' );
$resource_id = GETPOST ( 'resource_id' , 'int' );
2014-01-02 07:07:43 +01:00
2022-01-13 11:09:37 +01:00
$sortorder = GETPOST ( 'sortorder' , 'aZ09comma' );
2020-09-18 17:13:01 +02:00
$sortfield = GETPOST ( 'sortfield' , 'aZ09comma' );
2021-03-14 23:33:06 +01:00
$optioncss = GETPOST ( 'optioncss' , 'alpha' );
2016-10-19 22:14:51 +02:00
// Initialize context for list
2019-11-13 19:35:39 +01:00
$contextpage = GETPOST ( 'contextpage' , 'aZ' ) ? GETPOST ( 'contextpage' , 'aZ' ) : 'resourcelist' ;
2014-01-02 07:07:43 +01:00
2018-03-31 18:48:27 +02:00
// Initialize technical objects
2016-01-21 11:18:29 +01:00
$object = new Dolresource ( $db );
2016-10-19 22:14:51 +02:00
$extrafields = new ExtraFields ( $db );
// fetch optionals attributes and labels
2019-10-06 14:41:52 +02:00
$extrafields -> fetch_name_optionals_label ( $object -> table_element );
2019-11-22 14:14:59 +01:00
$search_array_options = $extrafields -> getOptionalsFromPost ( $object -> table_element , '' , 'search_' );
2021-02-26 20:53:03 +01:00
if ( ! is_array ( $search_array_options )) {
$search_array_options = array ();
}
2020-01-29 11:38:06 +01:00
$search_ref = GETPOST ( " search_ref " , 'alpha' );
$search_type = GETPOST ( " search_type " , 'alpha' );
2016-10-19 22:14:51 +02:00
2020-04-12 18:13:43 +02:00
// Load variable for pagination
$limit = GETPOST ( 'limit' , 'int' ) ? GETPOST ( 'limit' , 'int' ) : $conf -> liste_limit ;
2019-11-22 14:14:59 +01:00
$filter = array ();
2016-10-19 22:14:51 +02:00
2018-03-31 18:48:27 +02:00
$hookmanager -> initHooks ( array ( 'resourcelist' ));
2014-01-02 07:07:43 +01:00
2021-02-26 20:53:03 +01:00
if ( empty ( $sortorder )) {
$sortorder = " ASC " ;
}
if ( empty ( $sortfield )) {
$sortfield = " t.ref " ;
}
if ( empty ( $arch )) {
$arch = 0 ;
}
2014-01-02 07:07:43 +01:00
2019-11-22 14:14:59 +01:00
$limit = GETPOST ( 'limit' , 'int' ) ? GETPOST ( 'limit' , 'int' ) : $conf -> liste_limit ;
2020-03-13 13:07:11 +01:00
$page = GETPOSTISSET ( 'pageplusone' ) ? ( GETPOST ( 'pageplusone' ) - 1 ) : GETPOST ( " page " , 'int' );
2021-02-26 20:53:03 +01:00
if ( empty ( $page ) || $page == - 1 ) {
$page = 0 ;
} // If $page is not defined, or '' or -1
2019-11-22 14:14:59 +01:00
$offset = $limit * $page ;
2014-01-02 07:07:43 +01:00
$pageprev = $page - 1 ;
$pagenext = $page + 1 ;
2016-10-19 22:14:51 +02:00
$arrayfields = array (
't.ref' => array (
'label' => $langs -> trans ( " Ref " ),
'checked' => 1
),
'ty.label' => array (
'label' => $langs -> trans ( " ResourceType " ),
'checked' => 1
),
);
// Extra fields
2020-12-23 19:14:47 +01:00
include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_array_fields.tpl.php' ;
2019-10-22 17:08:37 +02:00
$object -> fields = dol_sort_array ( $object -> fields , 'position' );
$arrayfields = dol_sort_array ( $arrayfields , 'position' );
2016-10-19 22:14:51 +02:00
include DOL_DOCUMENT_ROOT . '/core/actions_changeselectedfields.inc.php' ;
2014-01-02 07:07:43 +01:00
2016-10-19 22:14:51 +02:00
// Do we click on purge search criteria ?
2021-02-26 20:53:03 +01:00
if ( GETPOST ( 'button_removefilter_x' , 'alpha' ) || GETPOST ( 'button_removefilter.x' , 'alpha' ) || GETPOST ( 'button_removefilter' , 'alpha' )) { // Both test are required to be compatible with all browsers
2019-11-13 19:35:39 +01:00
$search_ref = " " ;
$search_type = " " ;
$search_array_options = array ();
$filter = array ();
2016-10-19 22:14:51 +02:00
}
2014-01-02 07:07:43 +01:00
2021-10-25 15:32:10 +02:00
if ( empty ( $user -> rights -> resource -> read )) {
accessforbidden ();
}
2020-04-13 04:14:28 +02:00
2014-09-28 03:41:32 +02:00
/*
2021-11-06 21:04:17 +01:00
* Actions
2014-09-28 03:41:32 +02:00
*/
2021-11-06 21:04:17 +01:00
if ( GETPOST ( 'cancel' , 'alpha' )) {
$action = 'list' ;
$massaction = '' ;
}
if ( ! GETPOST ( 'confirmmassaction' , 'alpha' ) && $massaction != 'presend' && $massaction != 'confirm_presend' ) {
$massaction = '' ;
}
2019-11-13 19:35:39 +01:00
$parameters = array ();
$reshook = $hookmanager -> executeHooks ( 'doActions' , $parameters , $object , $action ); // Note that $action and $object may have been modified by some hooks
2021-02-26 20:53:03 +01:00
if ( $reshook < 0 ) {
setEventMessages ( $hookmanager -> error , $hookmanager -> errors , 'errors' );
}
2014-09-28 03:41:32 +02:00
/*
* View
*/
2014-01-02 07:07:43 +01:00
2019-11-13 19:35:39 +01:00
$form = new Form ( $db );
2014-01-02 07:07:43 +01:00
2021-11-06 21:04:17 +01:00
//$help_url="EN:Module_MyObject|FR:Module_MyObject_FR|ES:Módulo_MyObject";
$help_url = '' ;
2019-11-13 19:35:39 +01:00
$pagetitle = $langs -> trans ( 'ResourcePageIndex' );
2021-11-06 21:04:17 +01:00
llxHeader ( '' , $pagetitle , $help_url );
$sql = '' ;
include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_search_sql.tpl.php' ;
$param = '' ;
if ( ! empty ( $contextpage ) && $contextpage != $_SERVER [ " PHP_SELF " ]) {
$param .= '&contextpage=' . urlencode ( $contextpage );
}
if ( $limit > 0 && $limit != $conf -> liste_limit ) {
$param .= '&limit=' . urlencode ( $limit );
}
if ( $search_ref != '' ) {
$param .= '&search_ref=' . urlencode ( $search_ref );
$filter [ 't.ref' ] = $search_ref ;
}
if ( $search_type != '' ) {
$param .= '&search_type=' . urlencode ( $search_type );
$filter [ 'ty.label' ] = $search_type ;
}
// Including the previous script generate the correct SQL filter for all the extrafields
// we are playing with the behaviour of the Dolresource::fetch_all() by generating a fake
// extrafields filter key to make it works
$filter [ 'ef.resource' ] = $sql ;
if ( ! empty ( $contextpage ) && $contextpage != $_SERVER [ " PHP_SELF " ]) $param .= '&contextpage=' . urlencode ( $contextpage );
// Add $param from extra fields
include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_search_param.tpl.php' ;
2014-01-02 07:07:43 +01:00
2014-03-23 23:13:17 +01:00
// Confirmation suppression resource line
2021-02-26 20:53:03 +01:00
if ( $action == 'delete_resource' ) {
2019-01-27 11:55:16 +01:00
print $form -> formconfirm ( $_SERVER [ 'PHP_SELF' ] . " ?element= " . $element . " &element_id= " . $element_id . " &lineid= " . $lineid , $langs -> trans ( " DeleteResource " ), $langs -> trans ( " ConfirmDeleteResourceElement " ), " confirm_delete_resource " , '' , '' , 1 );
2014-03-23 23:13:17 +01:00
}
2014-01-02 07:07:43 +01:00
2019-11-13 19:35:39 +01:00
$varpage = empty ( $contextpage ) ? $_SERVER [ " PHP_SELF " ] : $contextpage ;
$selectedfields = $form -> multiSelectArrayWithCheckbox ( 'selectedfields' , $arrayfields , $varpage );
2016-10-19 22:14:51 +02:00
2021-11-06 21:04:17 +01:00
2016-10-19 22:14:51 +02:00
print '<form method="POST" id="searchFormList" action="' . $_SERVER [ " PHP_SELF " ] . '">' ;
2021-02-26 20:53:03 +01:00
if ( $optioncss != '' ) {
print '<input type="hidden" name="optioncss" value="' . $optioncss . '">' ;
}
2019-12-18 23:12:31 +01:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
2016-10-19 22:14:51 +02:00
print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">' ;
print '<input type="hidden" name="action" value="list">' ;
print '<input type="hidden" name="sortfield" value="' . $sortfield . '">' ;
print '<input type="hidden" name="sortorder" value="' . $sortorder . '">' ;
print '<input type="hidden" name="contextpage" value="' . $contextpage . '">' ;
2021-02-26 20:53:03 +01:00
if ( empty ( $conf -> global -> MAIN_DISABLE_FULL_SCANLIST )) {
2022-04-30 19:50:20 +02:00
$ret = $object -> fetchAll ( '' , '' , 0 , 0 , $filter );
2019-11-13 19:35:39 +01:00
if ( $ret == - 1 ) {
2019-01-27 11:55:16 +01:00
dol_print_error ( $db , $object -> error );
2017-09-21 12:02:45 +02:00
exit ;
2019-11-13 19:35:39 +01:00
} else {
2017-09-21 12:02:45 +02:00
$nbtotalofrecords = $ret ;
}
}
// Load object list
2022-04-30 19:50:20 +02:00
$ret = $object -> fetchAll ( $sortorder , $sortfield , $limit , $offset , $filter );
2019-11-13 19:35:39 +01:00
if ( $ret == - 1 ) {
2019-01-27 11:55:16 +01:00
dol_print_error ( $db , $object -> error );
2017-09-21 12:02:45 +02:00
exit ;
} else {
2019-11-13 19:35:39 +01:00
$newcardbutton = '' ;
2021-02-26 20:53:03 +01:00
if ( $user -> rights -> resource -> write ) {
2020-10-07 15:01:28 +02:00
$newcardbutton .= dolGetButtonTitle ( $langs -> trans ( 'MenuResourceAdd' ), '' , 'fa fa-plus-circle' , DOL_URL_ROOT . '/resource/card.php?action=create' );
}
2018-04-03 15:28:12 +02:00
2020-04-13 04:14:28 +02:00
print_barre_liste ( $pagetitle , $page , $_SERVER [ " PHP_SELF " ], $param , $sortfield , $sortorder , '' , $ret + 1 , $nbtotalofrecords , 'object_resource' , 0 , $newcardbutton , '' , $limit , 0 , 0 , 1 );
2017-09-21 12:02:45 +02:00
}
2016-11-27 13:49:46 +01:00
$moreforfilter = '' ;
print '<div class="div-table-responsive">' ;
2019-11-13 19:35:39 +01:00
print '<table class="tagtable liste' . ( $moreforfilter ? " listwithfilterbefore " : " " ) . '">' . " \n " ;
2016-11-27 13:49:46 +01:00
2017-03-30 16:00:53 +02:00
print '<tr class="liste_titre_filter">' ;
2021-02-26 20:53:03 +01:00
if ( ! empty ( $arrayfields [ 't.ref' ][ 'checked' ])) {
2016-10-19 22:14:51 +02:00
print '<td class="liste_titre">' ;
print '<input type="text" class="flat" name="search_ref" value="' . $search_ref . '" size="6">' ;
print '</td>' ;
}
2021-02-26 20:53:03 +01:00
if ( ! empty ( $arrayfields [ 'ty.label' ][ 'checked' ])) {
2016-10-19 22:14:51 +02:00
print '<td class="liste_titre">' ;
print '<input type="text" class="flat" name="search_type" value="' . $search_type . '" size="6">' ;
print '</td>' ;
}
// Extra fields
2017-11-27 15:24:29 +01:00
include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_search_input.tpl.php' ;
2016-10-19 22:14:51 +02:00
// Action column
2019-05-19 13:51:47 +02:00
print '<td class="liste_titre maxwidthsearch">' ;
2019-11-13 19:35:39 +01:00
$searchpicto = $form -> showFilterAndCheckAddButtons ( 0 );
2017-05-14 21:06:33 +02:00
print $searchpicto ;
2016-10-19 22:14:51 +02:00
print '</td>' ;
2016-08-02 13:10:09 +02:00
print " </tr> \n " ;
2017-03-30 16:00:53 +02:00
print '<tr class="liste_titre">' ;
2021-02-26 20:53:03 +01:00
if ( ! empty ( $arrayfields [ 't.ref' ][ 'checked' ])) {
print_liste_field_titre ( $arrayfields [ 't.ref' ][ 'label' ], $_SERVER [ " PHP_SELF " ], " t.ref " , " " , $param , " " , $sortfield , $sortorder );
}
if ( ! empty ( $arrayfields [ 'ty.label' ][ 'checked' ])) {
print_liste_field_titre ( $arrayfields [ 'ty.label' ][ 'label' ], $_SERVER [ " PHP_SELF " ], " ty.label " , " " , $param , " " , $sortfield , $sortorder );
}
2017-03-30 16:00:53 +02:00
// Extra fields
2017-11-27 15:24:29 +01:00
include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_search_title.tpl.php' ;
2019-02-23 21:47:04 +01:00
print_liste_field_titre ( $selectedfields , $_SERVER [ " PHP_SELF " ], " " , '' , '' , '' , $sortfield , $sortorder , 'center maxwidthsearch ' );
2017-03-30 16:00:53 +02:00
print " </tr> \n " ;
2021-02-26 20:53:03 +01:00
if ( $ret ) {
foreach ( $object -> lines as $resource ) {
2020-10-07 15:01:28 +02:00
print '<tr class="oddeven">' ;
2021-02-26 20:53:03 +01:00
if ( ! empty ( $arrayfields [ 't.ref' ][ 'checked' ])) {
2020-10-07 15:01:28 +02:00
print '<td>' ;
print $resource -> getNomUrl ( 5 );
print '</td>' ;
2021-02-26 20:53:03 +01:00
if ( ! $i ) {
$totalarray [ 'nbfield' ] ++ ;
}
2020-10-07 15:01:28 +02:00
}
2021-02-26 20:53:03 +01:00
if ( ! empty ( $arrayfields [ 'ty.label' ][ 'checked' ])) {
2020-10-07 15:01:28 +02:00
print '<td>' ;
print $resource -> type_label ;
print '</td>' ;
2021-02-26 20:53:03 +01:00
if ( ! $i ) {
$totalarray [ 'nbfield' ] ++ ;
}
2020-10-07 15:01:28 +02:00
}
// Extra fields
$obj = ( Object ) $resource -> array_options ;
include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_print_fields.tpl.php' ;
print '<td class="center">' ;
print '<a class="editfielda" href="./card.php?action=edit&token=' . newToken () . '&id=' . $resource -> id . '">' ;
print img_edit ();
print '</a>' ;
print ' ' ;
print '<a href="./card.php?action=delete&token=' . newToken () . '&id=' . $resource -> id . '">' ;
print img_delete ( '' , 'class="marginleftonly"' );
print '</a>' ;
print '</td>' ;
2021-02-26 20:53:03 +01:00
if ( ! $i ) {
$totalarray [ 'nbfield' ] ++ ;
}
2020-10-07 15:01:28 +02:00
print '</tr>' ;
}
2020-05-21 15:05:19 +02:00
} else {
2020-10-07 15:01:28 +02:00
$colspan = 1 ;
2021-02-26 20:53:03 +01:00
foreach ( $arrayfields as $key => $val ) {
if ( ! empty ( $val [ 'checked' ])) {
$colspan ++ ;
}
}
2020-10-07 15:01:28 +02:00
print '<tr><td colspan="' . $colspan . '" class="opacitymedium">' . $langs -> trans ( " NoRecordFound " ) . '</td></tr>' ;
2014-01-02 07:07:43 +01:00
}
2017-06-08 12:21:41 +02:00
print '</table>' ;
print " </form> \n " ;
2014-01-02 07:07:43 +01:00
2018-08-06 11:53:33 +02:00
// End of page
2017-06-08 12:21:41 +02:00
llxFooter ();
2014-01-02 07:07:43 +01:00
$db -> close ();