1<?php 2/* Copyright (C) 2013-2014 Jean-François Ferry <jfefe@aternatik.fr> 3 * Copyright (C) 2018 Nicolas ZABOURI <info@inovea-conseil.com> 4 * Copyright (C) 2018-2019 Frédéric France <frederic.france@netlogic.fr> 5 * 6 * This program is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation, either version 3 of the License, or 9 * (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program. If not, see <https://www.gnu.org/licenses/>. 18 */ 19 20/** 21 * \file htdocs/resource/list.php 22 * \ingroup resource 23 * \brief Page to manage resource objects 24 */ 25 26require '../main.inc.php'; 27require_once DOL_DOCUMENT_ROOT.'/resource/class/dolresource.class.php'; 28 29// Load translation files required by the page 30$langs->loadLangs(array("resource", "companies", "other")); 31 32// Get parameters 33$id = GETPOST('id', 'int'); 34$action = GETPOST('action', 'alpha'); 35 36$lineid = GETPOST('lineid', 'int'); 37$element = GETPOST('element', 'alpha'); 38$element_id = GETPOST('element_id', 'int'); 39$resource_id = GETPOST('resource_id', 'int'); 40 41$sortorder = GETPOST('sortorder', 'alpha'); 42$sortfield = GETPOST('sortfield', 'aZ09comma'); 43 44// Initialize context for list 45$contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'resourcelist'; 46 47// Initialize technical objects 48$object = new Dolresource($db); 49$extrafields = new ExtraFields($db); 50 51// fetch optionals attributes and labels 52$extrafields->fetch_name_optionals_label($object->table_element); 53$search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_'); 54if (!is_array($search_array_options)) $search_array_options = array(); 55$search_ref = GETPOST("search_ref", 'alpha'); 56$search_type = GETPOST("search_type", 'alpha'); 57 58// Load variable for pagination 59$limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit; 60 61 62$filter = array(); 63 64$param = ''; 65if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.urlencode($contextpage); 66if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.urlencode($limit); 67 68if ($search_ref != '') { 69 $param .= '&search_ref='.urlencode($search_ref); 70 $filter['t.ref'] = $search_ref; 71} 72if ($search_type != '') { 73 $param .= '&search_type='.urlencode($search_type); 74 $filter['ty.label'] = $search_type; 75} 76 77// Add $param from extra fields 78foreach ($search_array_options as $key => $val) 79{ 80 $crit = $val; 81 $tmpkey = preg_replace('/search_options_/', '', $key); 82 $typ = $extrafields->attributes[$object->table_element]['type'][$tmpkey]; 83 if ($val != '') { 84 $param .= '&search_options_'.$tmpkey.'='.urlencode($val); 85 } 86 $mode_search = 0; 87 if (in_array($typ, array('int', 'double', 'real'))) $mode_search = 1; // Search on a numeric 88 if (in_array($typ, array('sellist', 'link')) && $crit != '0' && $crit != '-1') $mode_search = 2; // Search on a foreign key int 89 if ($crit != '' && (!in_array($typ, array('select', 'sellist')) || $crit != '0') && (!in_array($typ, array('link')) || $crit != '-1')) 90 { 91 $filter['ef.'.$tmpkey] = natural_search('ef.'.$tmpkey, $crit, $mode_search); 92 } 93} 94if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.urlencode($contextpage); 95 96 97$hookmanager->initHooks(array('resourcelist')); 98 99if (empty($sortorder)) $sortorder = "ASC"; 100if (empty($sortfield)) $sortfield = "t.ref"; 101if (empty($arch)) $arch = 0; 102 103$limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit; 104$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); 105if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 106$offset = $limit * $page; 107$pageprev = $page - 1; 108$pagenext = $page + 1; 109 110if (!$user->rights->resource->read) { 111 accessforbidden(); 112} 113$arrayfields = array( 114 't.ref' => array( 115 'label' => $langs->trans("Ref"), 116 'checked' => 1 117 ), 118 'ty.label' => array( 119 'label' => $langs->trans("ResourceType"), 120 'checked' => 1 121 ), 122); 123// Extra fields 124include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php'; 125 126$object->fields = dol_sort_array($object->fields, 'position'); 127$arrayfields = dol_sort_array($arrayfields, 'position'); 128 129 130include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php'; 131 132// Do we click on purge search criteria ? 133if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) // Both test are required to be compatible with all browsers 134{ 135 $search_ref = ""; 136 $search_type = ""; 137 $search_array_options = array(); 138 $filter = array(); 139} 140 141 142/* 143 * Action 144 */ 145 146$parameters = array(); 147$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks 148if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); 149 150 151/* 152 * View 153 */ 154 155$form = new Form($db); 156 157$pagetitle = $langs->trans('ResourcePageIndex'); 158llxHeader('', $pagetitle, ''); 159 160// Confirmation suppression resource line 161if ($action == 'delete_resource') 162{ 163 print $form->formconfirm($_SERVER['PHP_SELF']."?element=".$element."&element_id=".$element_id."&lineid=".$lineid, $langs->trans("DeleteResource"), $langs->trans("ConfirmDeleteResourceElement"), "confirm_delete_resource", '', '', 1); 164} 165 166$varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage; 167$selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); 168 169print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'; 170if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">'; 171print '<input type="hidden" name="token" value="'.newToken().'">'; 172print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">'; 173print '<input type="hidden" name="action" value="list">'; 174print '<input type="hidden" name="sortfield" value="'.$sortfield.'">'; 175print '<input type="hidden" name="sortorder" value="'.$sortorder.'">'; 176print '<input type="hidden" name="contextpage" value="'.$contextpage.'">'; 177 178if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) 179{ 180 $ret = $object->fetch_all('', '', 0, 0, $filter); 181 if ($ret == -1) { 182 dol_print_error($db, $object->error); 183 exit; 184 } else { 185 $nbtotalofrecords = $ret; 186 } 187} 188 189// Load object list 190$ret = $object->fetch_all($sortorder, $sortfield, $limit, $offset, $filter); 191if ($ret == -1) { 192 dol_print_error($db, $object->error); 193 exit; 194} else { 195 $newcardbutton = ''; 196 if ($user->rights->resource->write) 197 { 198 $newcardbutton .= dolGetButtonTitle($langs->trans('MenuResourceAdd'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/resource/card.php?action=create'); 199 } 200 201 print_barre_liste($pagetitle, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $ret + 1, $nbtotalofrecords, 'object_resource', 0, $newcardbutton, '', $limit, 0, 0, 1); 202} 203 204$moreforfilter = ''; 205 206print '<div class="div-table-responsive">'; 207print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n"; 208 209print '<tr class="liste_titre_filter">'; 210if (!empty($arrayfields['t.ref']['checked'])) 211{ 212 print '<td class="liste_titre">'; 213 print '<input type="text" class="flat" name="search_ref" value="'.$search_ref.'" size="6">'; 214 print '</td>'; 215} 216if (!empty($arrayfields['ty.label']['checked'])) 217{ 218 print '<td class="liste_titre">'; 219 print '<input type="text" class="flat" name="search_type" value="'.$search_type.'" size="6">'; 220 print '</td>'; 221} 222// Extra fields 223include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php'; 224// Action column 225print '<td class="liste_titre maxwidthsearch">'; 226$searchpicto = $form->showFilterAndCheckAddButtons(0); 227print $searchpicto; 228print '</td>'; 229print "</tr>\n"; 230 231print '<tr class="liste_titre">'; 232if (!empty($arrayfields['t.ref']['checked'])) print_liste_field_titre($arrayfields['t.ref']['label'], $_SERVER["PHP_SELF"], "t.ref", "", $param, "", $sortfield, $sortorder); 233if (!empty($arrayfields['ty.label']['checked'])) print_liste_field_titre($arrayfields['ty.label']['label'], $_SERVER["PHP_SELF"], "ty.label", "", $param, "", $sortfield, $sortorder); 234// Extra fields 235include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php'; 236print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch '); 237print "</tr>\n"; 238 239 240if ($ret) 241{ 242 foreach ($object->lines as $resource) 243 { 244 print '<tr class="oddeven">'; 245 246 if (!empty($arrayfields['t.ref']['checked'])) 247 { 248 print '<td>'; 249 print $resource->getNomUrl(5); 250 print '</td>'; 251 if (!$i) $totalarray['nbfield']++; 252 } 253 254 if (!empty($arrayfields['ty.label']['checked'])) 255 { 256 print '<td>'; 257 print $resource->type_label; 258 print '</td>'; 259 if (!$i) $totalarray['nbfield']++; 260 } 261 // Extra fields 262 $obj = (Object) $resource->array_options; 263 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php'; 264 265 print '<td class="center">'; 266 print '<a class="editfielda" href="./card.php?action=edit&token='.newToken().'&id='.$resource->id.'">'; 267 print img_edit(); 268 print '</a>'; 269 print ' '; 270 print '<a href="./card.php?action=delete&token='.newToken().'&id='.$resource->id.'">'; 271 print img_delete('', 'class="marginleftonly"'); 272 print '</a>'; 273 print '</td>'; 274 if (!$i) $totalarray['nbfield']++; 275 276 print '</tr>'; 277 } 278} else { 279 $colspan = 1; 280 foreach ($arrayfields as $key => $val) { if (!empty($val['checked'])) $colspan++; } 281 print '<tr><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoRecordFound").'</td></tr>'; 282} 283 284print '</table>'; 285print "</form>\n"; 286 287// End of page 288llxFooter(); 289$db->close(); 290