dolibarr 19.0.4
list.php
Go to the documentation of this file.
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-2021 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
26// Load Dolibarr environment
27require '../main.inc.php';
28require_once DOL_DOCUMENT_ROOT.'/resource/class/dolresource.class.php';
29
30// Load translation files required by the page
31$langs->loadLangs(array("resource", "companies", "other"));
32
33// Get parameters
34$id = GETPOST('id', 'int');
35$action = GETPOST('action', 'alpha');
36$massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists)
37
38$lineid = GETPOST('lineid', 'int');
39$element = GETPOST('element', 'alpha');
40$element_id = GETPOST('element_id', 'int');
41$resource_id = GETPOST('resource_id', 'int');
42
43$sortorder = GETPOST('sortorder', 'aZ09comma');
44$sortfield = GETPOST('sortfield', 'aZ09comma');
45$optioncss = GETPOST('optioncss', 'alpha');
46
47// Initialize context for list
48$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'resourcelist';
49
50// Initialize technical objects
51$object = new Dolresource($db);
52$extrafields = new ExtraFields($db);
53
54// fetch optionals attributes and labels
55$extrafields->fetch_name_optionals_label($object->table_element);
56$search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
57if (!is_array($search_array_options)) {
58 $search_array_options = array();
59}
60$search_ref = GETPOST("search_ref", 'alpha');
61$search_type = GETPOST("search_type", 'alpha');
62
63// Load variable for pagination
64$limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
65
66$filter = array();
67
68$hookmanager->initHooks(array('resourcelist'));
69
70if (empty($sortorder)) {
71 $sortorder = "ASC";
72}
73if (empty($sortfield)) {
74 $sortfield = "t.ref";
75}
76if (empty($arch)) {
77 $arch = 0;
78}
79
80$limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
81$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
82if (empty($page) || $page == -1) {
83 $page = 0;
84} // If $page is not defined, or '' or -1
85$offset = $limit * $page;
86$pageprev = $page - 1;
87$pagenext = $page + 1;
88
89$arrayfields = array(
90 't.ref' => array(
91 'label' => $langs->trans("Ref"),
92 'checked' => 1
93 ),
94 'ty.label' => array(
95 'label' => $langs->trans("ResourceType"),
96 'checked' => 1
97 ),
98);
99// Extra fields
100include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
101
102$object->fields = dol_sort_array($object->fields, 'position');
103$arrayfields = dol_sort_array($arrayfields, 'position');
104
105
106include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
107
108// Do we click on purge search criteria ?
109if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // Both test are required to be compatible with all browsers
110 $search_ref = "";
111 $search_type = "";
112 $search_array_options = array();
113 $filter = array();
114}
115
116if (!$user->hasRight('resource', 'read')) {
118}
119
120
121/*
122 * Actions
123 */
124
125if (GETPOST('cancel', 'alpha')) {
126 $action = 'list';
127 $massaction = '';
128}
129if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
130 $massaction = '';
131}
132
133$parameters = array();
134$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
135if ($reshook < 0) {
136 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
137}
138
139
140/*
141 * View
142 */
143
144$form = new Form($db);
145
146//$help_url="EN:Module_MyObject|FR:Module_MyObject_FR|ES:Módulo_MyObject";
147$help_url = '';
148$title = $langs->trans('Resources');
149llxHeader('', $title, $help_url);
150
151
152$sql = '';
153include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
154
155$param = '';
156if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
157 $param .= '&contextpage='.urlencode($contextpage);
158}
159if ($limit > 0 && $limit != $conf->liste_limit) {
160 $param .= '&limit='.((int) $limit);
161}
162
163if ($search_ref != '') {
164 $param .= '&search_ref='.urlencode($search_ref);
165 $filter['t.ref'] = $search_ref;
166}
167if ($search_type != '') {
168 $param .= '&search_type='.urlencode($search_type);
169 $filter['ty.label'] = $search_type;
170}
171
172// Including the previous script generate the correct SQL filter for all the extrafields
173// we are playing with the behaviour of the Dolresource::fetchAll() by generating a fake
174// extrafields filter key to make it works
175$filter['ef.resource'] = $sql;
176
177if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
178 $param .= '&contextpage='.urlencode($contextpage);
179}
180
181// Add $param from extra fields
182include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
183
184
185// Confirmation suppression resource line
186if ($action == 'delete_resource') {
187 print $form->formconfirm($_SERVER['PHP_SELF']."?element=".$element."&element_id=".$element_id."&lineid=".$lineid, $langs->trans("DeleteResource"), $langs->trans("ConfirmDeleteResourceElement"), "confirm_delete_resource", '', '', 1);
188}
189
190$varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
191$selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN'));
192
193
194print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
195if ($optioncss != '') {
196 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
197}
198print '<input type="hidden" name="token" value="'.newToken().'">';
199print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
200print '<input type="hidden" name="action" value="list">';
201print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
202print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
203print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
204
205if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
206 $ret = $object->fetchAll('', '', 0, 0, $filter);
207 if ($ret == -1) {
208 dol_print_error($db, $object->error);
209 exit;
210 } else {
211 $nbtotalofrecords = $ret;
212 }
213}
214
215// Load object list
216$ret = $object->fetchAll($sortorder, $sortfield, $limit, $offset, $filter);
217if ($ret == -1) {
218 dol_print_error($db, $object->error);
219 exit;
220} else {
221 $newcardbutton = '';
222 if ($user->hasRight('resource', 'write')) {
223 $newcardbutton .= dolGetButtonTitle($langs->trans('MenuResourceAdd'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/resource/card.php?action=create');
224 }
225
226 print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $ret + 1, $nbtotalofrecords, 'object_resource', 0, $newcardbutton, '', $limit, 0, 0, 1);
227}
228
229$moreforfilter = '';
230
231print '<div class="div-table-responsive">';
232print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
233
234print '<tr class="liste_titre_filter">';
235// Action column
236if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
237 print '<td class="liste_titre maxwidthsearch">';
238 $searchpicto = $form->showFilterAndCheckAddButtons(0);
239 print $searchpicto;
240 print '</td>';
241}
242if (!empty($arrayfields['t.ref']['checked'])) {
243 print '<td class="liste_titre">';
244 print '<input type="text" class="flat" name="search_ref" value="'.$search_ref.'" size="6">';
245 print '</td>';
246}
247if (!empty($arrayfields['ty.label']['checked'])) {
248 print '<td class="liste_titre">';
249 print '<input type="text" class="flat" name="search_type" value="'.$search_type.'" size="6">';
250 print '</td>';
251}
252// Extra fields
253include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
254// Action column
255if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
256 print '<td class="liste_titre maxwidthsearch">';
257 $searchpicto = $form->showFilterAndCheckAddButtons(0);
258 print $searchpicto;
259 print '</td>';
260}
261print "</tr>\n";
262
263print '<tr class="liste_titre">';
264// Action column
265if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
266 print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
267}
268if (!empty($arrayfields['t.ref']['checked'])) {
269 print_liste_field_titre($arrayfields['t.ref']['label'], $_SERVER["PHP_SELF"], "t.ref", "", $param, "", $sortfield, $sortorder);
270}
271if (!empty($arrayfields['ty.label']['checked'])) {
272 print_liste_field_titre($arrayfields['ty.label']['label'], $_SERVER["PHP_SELF"], "ty.label", "", $param, "", $sortfield, $sortorder);
273}
274// Extra fields
275include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
276// Action column
277if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
278 print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
279}
280print "</tr>\n";
281
282
283if ($ret) {
284 foreach ($object->lines as $resource) {
285 print '<tr class="oddeven">';
286
287 // Action column
288 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
289 print '<td class="center">';
290 print '<a class="editfielda" href="./card.php?action=edit&token='.newToken().'&id='.$resource->id.'">';
291 print img_edit();
292 print '</a>';
293 print '&nbsp;';
294 print '<a href="./card.php?action=delete&token='.newToken().'&id='.$resource->id.'">';
295 print img_delete('', 'class="marginleftonly"');
296 print '</a>';
297 print '</td>';
298 }
299
300 if (!empty($arrayfields['t.ref']['checked'])) {
301 print '<td>';
302 print $resource->getNomUrl(5);
303 print '</td>';
304 if (!$i) {
305 $totalarray['nbfield']++;
306 }
307 }
308
309 if (!empty($arrayfields['ty.label']['checked'])) {
310 print '<td>';
311 print $resource->type_label;
312 print '</td>';
313 if (!$i) {
314 $totalarray['nbfield']++;
315 }
316 }
317 // Extra fields
318 $obj = (object) $resource->array_options;
319 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
320
321 // Action column
322 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
323 print '<td class="center">';
324 print '<a class="editfielda" href="./card.php?action=edit&token='.newToken().'&id='.$resource->id.'">';
325 print img_edit();
326 print '</a>';
327 print '&nbsp;';
328 print '<a href="./card.php?action=delete&token='.newToken().'&id='.$resource->id.'">';
329 print img_delete('', 'class="marginleftonly"');
330 print '</a>';
331 print '</td>';
332 }
333 if (!$i) {
334 $totalarray['nbfield']++;
335 }
336
337 print '</tr>';
338 }
339} else {
340 $colspan = 1;
341 foreach ($arrayfields as $key => $val) {
342 if (!empty($val['checked'])) {
343 $colspan++;
344 }
345 }
346 print '<tr><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoRecordFound").'</td></tr>';
347}
348
349print '</table>';
350print "</form>\n";
351
352// End of page
353llxFooter();
354$db->close();
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Definition wrapper.php:55
llxFooter()
Empty footer.
Definition wrapper.php:69
DAO Resource object.
Class to manage standard extra fields.
Class to manage generation of HTML components Only common components must be here.
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dolGetButtonTitle($label, $helpText='', $iconClass='fa fa-file', $url='', $id='', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by second index function, which produces ascending (default) or descending output...
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
print_barre_liste($titre, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $hideselectlimit=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
img_edit($titlealt='default', $float=0, $other='')
Show logo editer/modifier fiche.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.