dolibarr 21.0.0-alpha
workstation_list.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (C) 2007-2017 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2020 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
5 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
6 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
28// Load Dolibarr environment
29require '../main.inc.php';
30require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
31require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
32require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
33require_once DOL_DOCUMENT_ROOT.'/resource/class/html.formresource.class.php';
34require_once DOL_DOCUMENT_ROOT.'/workstation/class/workstation.class.php';
35
36global $conf, $db, $hookmanager, $langs, $user;
37
38// Load translation files required by the page
39$langs->loadLangs(array('mrp', 'other'));
40
41$action = GETPOST('action', 'aZ09') ? GETPOST('action', 'aZ09') : 'view'; // The action 'create'/'add', 'edit'/'update', 'view', ...
42$massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists)
43$show_files = GETPOSTINT('show_files'); // Show files area generated by bulk actions ?
44$confirm = GETPOST('confirm', 'alpha'); // Result of a confirmation
45$cancel = GETPOST('cancel', 'alpha'); // We click on a Cancel button
46$toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list
47$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : str_replace('_', '', basename(dirname(__FILE__)).basename(__FILE__, '.php')); // To manage different context of search
48$backtopage = GETPOST('backtopage', 'alpha'); // Go back to a dedicated page
49$optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
50$mode = GETPOST('mode', 'aZ'); // The output mode ('list', 'kanban', 'hierarchy', 'calendar', ...)
51
52$id = GETPOSTINT('id');
53$ref = GETPOST('ref', 'alpha');
54
55// Load variable for pagination
56$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
57$sortfield = GETPOST('sortfield', 'aZ09comma');
58$sortorder = GETPOST('sortorder', 'aZ09comma');
59$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
60if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
61 // If $page is not defined, or '' or -1 or if we click on clear filters
62 $page = 0;
63}
64$offset = $limit * $page;
65$pageprev = $page - 1;
66$pagenext = $page + 1;
67
68// Initialize a technical objects
69$object = new Workstation($db);
70$extrafields = new ExtraFields($db);
71$diroutputmassaction = $conf->workstation->dir_output.'/temp/massgeneration/'.$user->id;
72$hookmanager->initHooks(array('workstationlist')); // Note that conf->hooks_modules contains array
73
74// Fetch optionals attributes and labels
75$extrafields->fetch_name_optionals_label($object->table_element);
76//$extrafields->fetch_name_optionals_label($object->table_element_line);
77
78$search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
79
80// Default sort order (if not yet defined by previous GETPOST)
81if (!$sortfield) {
82 reset($object->fields); // Reset is required to avoid key() to return null.
83 $sortfield = "t.".key($object->fields); // Set here default search field. By default 1st field in definition.
84}
85if (!$sortorder) {
86 $sortorder = "ASC";
87}
88
89// Initialize array of search criteria
90$search_all = trim(GETPOST('search_all', 'alphanohtml'));
91$search = array();
92
93foreach ($object->fields as $key => $val) {
94 if (GETPOST('search_'.$key, 'alpha') !== '') {
95 $search[$key] = GETPOST('search_'.$key, 'alpha');
96 }
97 if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
98 $search[$key.'_dtstart'] = dol_mktime(0, 0, 0, GETPOSTINT('search_'.$key.'_dtstartmonth'), GETPOSTINT('search_'.$key.'_dtstartday'), GETPOSTINT('search_'.$key.'_dtstartyear'));
99 $search[$key.'_dtend'] = dol_mktime(23, 59, 59, GETPOSTINT('search_'.$key.'_dtendmonth'), GETPOSTINT('search_'.$key.'_dtendday'), GETPOSTINT('search_'.$key.'_dtendyear'));
100 }
101}
102
103$groups = GETPOST('groups', 'array:int');
104$resources = GETPOST('resources', 'array:int');
105
106// List of fields to search into when doing a "search in all"
107$fieldstosearchall = array();
108foreach ($object->fields as $key => $val) {
109 if (!empty($val['searchall'])) {
110 $fieldstosearchall['t.'.$key] = $val['label'];
111 }
112}
113
114// Definition of array of fields for columns
115$arrayfields = array();
116foreach ($object->fields as $key => $val) {
117 // If $val['visible']==0, then we never show the field
118 if (!empty($val['visible'])) {
119 $visible = (int) dol_eval((string) $val['visible'], 1);
120 $arrayfields['t.'.$key] = array(
121 'label' => $val['label'],
122 'checked' => (($visible < 0) ? 0 : 1),
123 'enabled' => (abs($visible) != 3 && (bool) dol_eval($val['enabled'], 1)),
124 'position' => $val['position'],
125 'help' => isset($val['help']) ? $val['help'] : ''
126 );
127 }
128}
129
130$arrayfields['wug.fk_usergroup'] = array(
131 'label' => $langs->trans('UserGroups'),
132 'checked' => (($visible < 0) ? 0 : 1),
133 'enabled' => (abs($visible) != 3 && (bool) dol_eval($val['enabled'], 1)),
134 'position' => 1000,
135 'help' => empty($val['help']) ? '' : $val['help'],
136 'csslist' => 'minwidth100'
137);
138
139/* disabled because adding resources to workstation seems not yet available in GUI
140$arrayfields['wr.fk_resource'] = array(
141 'label'=>$langs->trans('Resources'),
142 'checked'=>(($visible < 0) ? 0 : 1),
143 'enabled'=>(abs($visible) != 3 && (bool) dol_eval($val['enabled'], 1)),
144 'position'=>1001,
145 'help' => empty($val['help']) ? '' : $val['help']
146);
147*/
148
149// Extra fields
150include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
151
152$object->fields = dol_sort_array($object->fields, 'position');
153$arrayfields = dol_sort_array($arrayfields, 'position');
154'@phan-var-force array<string,array{label:string,checked?:int<0,1>,position?:int,help?:string}> $arrayfields'; // dol_sort_array looses type for Phan
155
156$permissiontoread = $user->hasRight('workstation', 'workstation', 'read');
157$permissiontoadd = $user->hasRight('workstation', 'workstation', 'write');
158$permissiontodelete = $user->hasRight('workstation', 'workstation', 'delete');
159
160// Security check
161restrictedArea($user, $object->element, 0, $object->table_element, 'workstation');
162
163
164/*
165 * Actions
166 */
167
168if (GETPOST('cancel', 'alpha')) {
169 $action = 'list';
170 $massaction = '';
171}
172if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
173 $massaction = '';
174}
175
176$parameters = array();
177$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
178if ($reshook < 0) {
179 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
180}
181
182if (empty($reshook)) {
183 // Selection of new fields
184 include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
185
186 // Purge search criteria
187 if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers
188 foreach ($object->fields as $key => $val) {
189 $search[$key] = '';
190 if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
191 $search[$key.'_dtstart'] = '';
192 $search[$key.'_dtend'] = '';
193 }
194 }
195 $groups = $resources = array();
196 $toselect = array();
197 $search_array_options = array();
198 }
199 if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')
200 || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) {
201 $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation
202 }
203
204 // Mass actions
205 $objectclass = 'Workstation';
206 $objectlabel = 'Workstation';
207 $uploaddir = $conf->workstation->dir_output;
208 include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
209}
210
211
212
213/*
214 * View
215 */
216
217$form = new Form($db);
218$formresource = new FormResource($db);
219
220$now = dol_now();
221
222$title = $langs->trans("Workstations");
223$help_url = 'EN:Module_Workstation';
224$morejs = array();
225$morecss = array();
226
227
228// Build and execute select
229// --------------------------------------------------------------------
230$sql = 'SELECT ';
231$sql .= $object->getFieldList('t');
232// Add fields from extrafields
233if (!empty($extrafields->attributes[$object->table_element]['label'])) {
234 foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
235 // @phan-suppress-next-line PhanTypeArraySuspiciousNullable
236 $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');
237 }
238}
239// Add fields from hooks
240$parameters = array();
241$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
242$sql .= $hookmanager->resPrint;
243$sql = preg_replace('/,\s*$/', '', $sql);
244
245$sqlfields = $sql; // $sql fields to remove for count total
246
247$sql .= " FROM ".MAIN_DB_PREFIX.$object->table_element." as t";
248if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
249 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (t.rowid = ef.fk_object)";
250}
251if (!empty($groups)) {
252 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'workstation_workstation_usergroup wug ON (wug.fk_workstation = t.rowid)';
253}
254if (!empty($resources)) {
255 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'workstation_workstation_resource wr ON (wr.fk_workstation = t.rowid)';
256}
257// Add table from hooks
258$parameters = array();
259$reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
260$sql .= $hookmanager->resPrint;
261if ($object->ismultientitymanaged == 1) {
262 $sql .= " WHERE t.entity IN (".getEntity($object->element, (GETPOSTINT('search_current_entity') ? 0 : 1)).")";
263} else {
264 $sql .= " WHERE 1 = 1";
265}
266foreach ($search as $key => $val) {
267 if (array_key_exists($key, $object->fields)) {
268 if ($key == 'status' && $search[$key] == -1) {
269 continue;
270 }
271 $mode_search = (($object->isInt($object->fields[$key]) || $object->isFloat($object->fields[$key])) ? 1 : 0);
272 if ((strpos($object->fields[$key]['type'], 'integer:') === 0) || (strpos($object->fields[$key]['type'], 'sellist:') === 0) || !empty($object->fields[$key]['arrayofkeyval'])) {
273 if ($search[$key] == '-1' || ($search[$key] === '0' && (empty($object->fields[$key]['arrayofkeyval']) || !array_key_exists('0', $object->fields[$key]['arrayofkeyval'])))) {
274 $search[$key] = '';
275 }
276 $mode_search = 2;
277 }
278 if ($search[$key] != '') {
279 $sql .= natural_search("t.".$db->escape($key), $search[$key], (($key == 'status') ? 2 : $mode_search));
280 }
281 } else {
282 if (preg_match('/(_dtstart|_dtend)$/', $key) && $search[$key] != '') {
283 $columnName = preg_replace('/(_dtstart|_dtend)$/', '', $key);
284 if (preg_match('/^(date|timestamp|datetime)/', $object->fields[$columnName]['type'])) {
285 if (preg_match('/_dtstart$/', $key)) {
286 $sql .= " AND t.".$db->escape($columnName)." >= '".$db->idate($search[$key])."'";
287 }
288 if (preg_match('/_dtend$/', $key)) {
289 $sql .= " AND t.".$db->escape($columnName)." <= '".$db->idate($search[$key])."'";
290 }
291 }
292 }
293 }
294}
295if ($search_all) {
296 $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
297}
298//$sql.= dolSqlDateFilter("t.field", $search_xxxday, $search_xxxmonth, $search_xxxyear);
299// Add where from extra fields
300
301// usergroups
302if (!empty($groups)) {
303 $sql .= ' AND wug.fk_usergroup IN('.$db->sanitize(implode(',', $groups)).')';
304}
305
306// resources
307if (!empty($resources)) {
308 $sql .= ' AND wr.fk_resource IN('.$db->sanitize(implode(',', $resources)).')';
309}
310
311include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
312// Add where from hooks
313$parameters = array();
314$reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
315$sql .= $hookmanager->resPrint;
316
317$sql .= " GROUP BY ";
318foreach ($object->fields as $key => $val) {
319 $sql .= "t.".$db->escape($key).", ";
320}
321// Add fields from extrafields
322if (! empty($extrafields->attributes[$object->table_element]['label'])) {
323 foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
324 // @phan-suppress-next-line PhanTypeArraySuspiciousNullable
325 $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? "ef.".$key.', ' : '');
326 }
327}
328// Add groupby from hooks
329$parameters = array();
330$reshook = $hookmanager->executeHooks('printFieldListGroupBy', $parameters, $object); // Note that $action and $object may have been modified by hook
331$sql .= $hookmanager->resPrint;
332$sql = preg_replace('/,\s*$/', '', $sql);
333
334// Count total nb of records
335$nbtotalofrecords = '';
336if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
337 /* The fast and low memory method to get and count full list converts the sql into a sql count */
338 $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
339 $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
340
341 $resql = $db->query($sqlforcount);
342 if ($resql) {
343 $objforcount = $db->fetch_object($resql);
344 $nbtotalofrecords = $objforcount->nbtotalofrecords;
345 } else {
346 dol_print_error($db);
347 }
348
349 if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller than the paging size (filtering), goto and load page 0
350 $page = 0;
351 $offset = 0;
352 }
353 $db->free($resql);
354}
355
356// Complete request and execute it with limit
357$sql .= $db->order($sortfield, $sortorder);
358if ($limit) {
359 $sql .= $db->plimit($limit + 1, $offset);
360}
361
362$resql = $db->query($sql);
363if (!$resql) {
364 dol_print_error($db);
365 exit;
366}
367
368$num = $db->num_rows($resql);
369
370
371// Direct jump if only one record found
372if ($num == 1 && getDolGlobalInt('MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE') && $search_all && !$page) {
373 $obj = $db->fetch_object($resql);
374 $id = $obj->rowid;
375 header("Location: ".DOL_URL_ROOT.'/workstation/workstation_card.php?id='.((int) $id));
376 exit;
377}
378
379
380// Output page
381// --------------------------------------------------------------------
382
383llxHeader('', $title, $help_url, '', 0, 0, $morejs, $morecss, '', 'classforhorizontalscrolloftabs');
384
385$arrayofselected = is_array($toselect) ? $toselect : array();
386
387$param = '';
388if (!empty($mode)) {
389 $param .= '&mode='.urlencode($mode);
390}
391if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
392 $param .= '&contextpage='.urlencode($contextpage);
393}
394if ($limit > 0 && $limit != $conf->liste_limit) {
395 $param .= '&limit='.((int) $limit);
396}
397if ($optioncss != '') {
398 $param .= '&optioncss='.urlencode($optioncss);
399}
400foreach ($search as $key => $val) {
401 if (is_array($search[$key])) {
402 foreach ($search[$key] as $skey) {
403 if ($skey != '') {
404 $param .= '&search_'.$key.'[]='.urlencode($skey);
405 }
406 }
407 } elseif (preg_match('/(_dtstart|_dtend)$/', $key) && !empty($val)) {
408 $param .= '&search_'.$key.'month='.(GETPOSTINT('search_'.$key.'month'));
409 $param .= '&search_'.$key.'day='.(GETPOSTINT('search_'.$key.'day'));
410 $param .= '&search_'.$key.'year='.(GETPOSTINT('search_'.$key.'year'));
411 } elseif ($search[$key] != '') {
412 $param .= '&search_'.$key.'='.urlencode($search[$key]);
413 }
414}
415// Add $param from extra fields
416include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
417// Add $param from hooks
418$parameters = array('param' => &$param);
419$reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
420$param .= $hookmanager->resPrint;
421
422// List of mass actions available
423$arrayofmassactions = array(
424 //'validate'=>img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Validate"),
425 //'generate_doc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"),
426 //'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
427 //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
428);
429if (!empty($permissiontodelete)) {
430 $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
431}
432if (GETPOSTINT('nomassaction') || in_array($massaction, array('presend', 'predelete'))) {
433 $arrayofmassactions = array();
434}
435$massactionbutton = $form->selectMassAction('', $arrayofmassactions);
436
437print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
438if ($optioncss != '') {
439 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
440}
441print '<input type="hidden" name="token" value="'.newToken().'">';
442print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
443print '<input type="hidden" name="action" value="list">';
444print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
445print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
446print '<input type="hidden" name="page" value="'.$page.'">';
447print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
448print '<input type="hidden" name="page_y" value="">';
449print '<input type="hidden" name="mode" value="'.$mode.'">';
450
451$newcardbutton = '';
452$newcardbutton .= dolGetButtonTitle($langs->trans('ViewList'), '', 'fa fa-bars imgforviewmode', $_SERVER["PHP_SELF"].'?mode=common'.preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', ((empty($mode) || $mode == 'common') ? 2 : 1), array('morecss' => 'reposition'));
453$newcardbutton .= dolGetButtonTitle($langs->trans('ViewKanban'), '', 'fa fa-th-list imgforviewmode', $_SERVER["PHP_SELF"].'?mode=kanban'.preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', ($mode == 'kanban' ? 2 : 1), array('morecss' => 'reposition'));
454$newcardbutton .= dolGetButtonTitleSeparator();
455$newcardbutton .= dolGetButtonTitle($langs->trans('New'), '', 'fa fa-plus-circle', dol_buildpath('/workstation/workstation_card.php', 1).'?action=create&backtopage='.urlencode($_SERVER['PHP_SELF']), '', $permissiontoadd);
456
457print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'object_'.$object->picto, 0, $newcardbutton, '', $limit, 0, 0, 1);
458
459// Add code for pre mass action (confirmation or email presend form)
460$topicmail = "SendWorkstationRef";
461$modelmail = "workstation";
462$objecttmp = new Workstation($db);
463$trackid = 'xxxx'.$object->id;
464include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
465
466if ($search_all) {
467 $setupstring = '';
468 foreach ($fieldstosearchall as $key => $val) {
469 $fieldstosearchall[$key] = $langs->trans($val);
470 $setupstring .= $key."=".$val.";";
471 }
472 print '<!-- Search done like if WORKSTATION_QUICKSEARCH_ON_FIELDS = '.$setupstring.' -->'."\n";
473 print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).implode(', ', $fieldstosearchall).'</div>';
474}
475
476$moreforfilter = '';
477/*$moreforfilter.='<div class="divsearchfield">';
478$moreforfilter.= $langs->trans('MyFilter') . ': <input type="text" name="search_myfield" value="'.dol_escape_htmltag($search_myfield).'">';
479$moreforfilter.= '</div>';*/
480
481$parameters = array();
482$reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
483if (empty($reshook)) {
484 $moreforfilter .= $hookmanager->resPrint;
485} else {
486 $moreforfilter = $hookmanager->resPrint;
487}
488
489if (!empty($moreforfilter)) {
490 print '<div class="liste_titre liste_titre_bydiv centpercent">';
491 print $moreforfilter;
492 print '</div>';
493}
494
495$varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
496$htmlofselectarray = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')); // This also change content of $arrayfields with user setup
497$selectedfields = ($mode != 'kanban' ? $htmlofselectarray : '');
498$selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
499
500print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you don't need reserved height for your table
501print '<table class="tagtable nobottomiftotal liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
502
503
504// Fields title search
505// --------------------------------------------------------------------
506
507print '<tr class="liste_titre_filter">';
508// Action column
509if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
510 print '<td class="liste_titre center maxwidthsearch">';
511 $searchpicto = $form->showFilterButtons('left');
512 print $searchpicto;
513 print '</td>';
514}
515foreach ($object->fields as $key => $val) {
516 $searchkey = empty($search[$key]) ? '' : $search[$key];
517 $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
518 if ($key == 'status') {
519 $cssforfield .= ($cssforfield ? ' ' : '').'center';
520 } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
521 $cssforfield .= ($cssforfield ? ' ' : '').'center';
522 } elseif (in_array($val['type'], array('timestamp'))) {
523 $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
524 } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && !in_array($key, array('id', 'rowid', 'ref', 'status')) && $val['label'] != 'TechnicalID' && empty($val['arrayofkeyval'])) {
525 $cssforfield .= ($cssforfield ? ' ' : '').'right';
526 }
527 if (!empty($arrayfields['t.'.$key]['checked'])) {
528 print '<td class="liste_titre'.($cssforfield ? ' '.$cssforfield : '').($key == 'status' ? ' parentonrightofpage' : '').'">';
529 if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
530 print $form->selectarray('search_'.$key, $val['arrayofkeyval'], (isset($search[$key]) ? $search[$key] : ''), 1, 0, 0, '', 1, 0, 0, '', 'maxwidth100'.($key == 'status' ? ' search_status width100 onrightofpage' : ''), 1);
531 } elseif ((strpos($val['type'], 'integer:') === 0) || (strpos($val['type'], 'sellist:') === 0)) {
532 print $object->showInputField($val, $key, (isset($search[$key]) ? $search[$key] : ''), '', '', 'search_', $cssforfield.' maxwidth250', 1);
533 } elseif (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
534 print '<div class="nowrap">';
535 print $form->selectDate($search[$key.'_dtstart'] ? $search[$key.'_dtstart'] : '', "search_".$key."_dtstart", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
536 print '</div>';
537 print '<div class="nowrap">';
538 print $form->selectDate($search[$key.'_dtend'] ? $search[$key.'_dtend'] : '', "search_".$key."_dtend", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
539 print '</div>';
540 } elseif ($key == 'lang') {
541 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
542 $formadmin = new FormAdmin($db);
543 print $formadmin->select_language($search[$key], 'search_lang', 0, null, 1, 0, 0, 'minwidth100imp maxwidth125', 2);
544 } else {
545 print '<input type="text" class="flat maxwidth'.($val['type'] == 'integer' ? '50' : '75').'" name="search_'.$key.'" value="'.dol_escape_htmltag(isset($search[$key]) ? $search[$key] : '').'">';
546 }
547 print '</td>';
548 }
549}
550
551// usergroups
552if (!empty($arrayfields['wug.fk_usergroup']['checked'])) {
553 print '<td class="liste_titre minwidth100">';
554 print $form->select_dolgroups($groups, 'groups', 1, '', 0, '', '', $conf->entity, true);
555 print '</td>';
556}
557
558// resources
559if (!empty($arrayfields['wr.fk_resource']['checked'])) {
560 print '<td class="liste_titre">';
561 print $formresource->select_resource_list($resources, 'resources', [], '', 0, '', '', $conf->entity, true, 0, '', true);
562 print '</td>';
563}
564
565// Extra fields
566include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
567
568// Fields from hook
569$parameters = array('arrayfields' => $arrayfields);
570$reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
571print $hookmanager->resPrint;
572// Action column
573if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
574 print '<td class="liste_titre center maxwidthsearch">';
575 $searchpicto = $form->showFilterButtons();
576 print $searchpicto;
577 print '</td>';
578}
579print '</tr>'."\n";
580
581$totalarray = array();
582$totalarray['nbfield'] = 0;
583
584// Fields title label
585// --------------------------------------------------------------------
586print '<tr class="liste_titre">';
587// Action column
588if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
589 print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
590 $totalarray['nbfield']++;
591}
592foreach ($object->fields as $key => $val) {
593 $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
594 if ($key == 'status') {
595 $cssforfield .= ($cssforfield ? ' ' : '').'center';
596 } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
597 $cssforfield .= ($cssforfield ? ' ' : '').'center';
598 } elseif (in_array($val['type'], array('timestamp'))) {
599 $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
600 } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && !in_array($key, array('id', 'rowid', 'ref', 'status')) && $val['label'] != 'TechnicalID' && empty($val['arrayofkeyval'])) {
601 $cssforfield .= ($cssforfield ? ' ' : '').'right';
602 }
603 $cssforfield = preg_replace('/small\s*/', '', $cssforfield); // the 'small' css must not be used for the title label
604 if (!empty($arrayfields['t.'.$key]['checked'])) {
605 print getTitleFieldOfList($arrayfields['t.'.$key]['label'], 0, $_SERVER['PHP_SELF'], 't.'.$key, '', $param, ($cssforfield ? 'class="'.$cssforfield.'"' : ''), $sortfield, $sortorder, ($cssforfield ? $cssforfield.' ' : ''), 0, (empty($val['helplist']) ? '' : $val['helplist']))."\n";
606 $totalarray['nbfield']++;
607 }
608}
609
610// usergroups
611if (!empty($arrayfields['wug.fk_usergroup']['checked'])) {
612 // @phan-suppress-next-line PhanTypeInvalidDimOffset
613 print getTitleFieldOfList($arrayfields['wug.fk_usergroup']['label'], 0, $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, '') . "\n";
614}
615
616// resources
617if (!empty($arrayfields['wr.fk_resource']['checked'])) {
618 print getTitleFieldOfList($arrayfields['wr.fk_resource']['label'], 0, $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, '') . "\n";
619}
620
621// Extra fields
622include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
623// Hook fields
624$parameters = array('arrayfields' => $arrayfields, 'param' => $param, 'sortfield' => $sortfield, 'sortorder' => $sortorder, 'totalarray' => &$totalarray);
625$reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
626print $hookmanager->resPrint;
627// Action column
628if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
629 print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
630 $totalarray['nbfield']++;
631}
632print '</tr>'."\n";
633
634
635// Detect if we need a fetch on each output line
636$needToFetchEachLine = 0;
637if (isset($extrafields->attributes[$object->table_element]['computed']) && is_array($extrafields->attributes[$object->table_element]['computed']) && count($extrafields->attributes[$object->table_element]['computed']) > 0) {
638 foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val) {
639 if (!is_null($val) && preg_match('/\$object/', $val)) {
640 $needToFetchEachLine++; // There is at least one compute field that use $object
641 }
642 }
643}
644
645
646// Loop on record
647// --------------------------------------------------------------------
648$i = 0;
649$savnbfield = $totalarray['nbfield'];
650$totalarray = array();
651$totalarray['nbfield'] = 0;
652$imaxinloop = ($limit ? min($num, $limit) : $num);
653while ($i < $imaxinloop) {
654 $obj = $db->fetch_object($resql);
655 if (empty($obj)) {
656 break; // Should not happen
657 }
658
659 // Store properties in $object
660 $object->setVarsFromFetchObj($obj);
661
664
665 if ($mode == 'kanban') {
666 if ($i == 0) {
667 print '<tr class="trkanban"><td colspan="'.($savnbfield + 1).'">';
668 print '<div class="box-flex-container kanban">';
669 }
670 // Output Kanban
671 $selected = -1;
672 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
673 $selected = 0;
674 if (in_array($object->id, $arrayofselected)) {
675 $selected = 1;
676 }
677 }
678 print $object->getKanbanView('', array('selected' => $selected));
679 if ($i == ($imaxinloop - 1)) {
680 print '</div>';
681 print '</td></tr>';
682 }
683 } else {
684 // Show line of result
685 $j = 0;
686 print '<tr data-rowid="'.$object->id.'" class="oddeven">';
687 // Action column
688 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
689 print '<td class="nowrap center">';
690 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
691 $selected = 0;
692 if (in_array($object->id, $arrayofselected)) {
693 $selected = 1;
694 }
695 print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
696 }
697 print '</td>';
698 if (!$i) {
699 $totalarray['nbfield']++;
700 }
701 }
702 foreach ($object->fields as $key => $val) {
703 $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
704 if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
705 $cssforfield .= ($cssforfield ? ' ' : '').'center';
706 } elseif ($key == 'status') {
707 $cssforfield .= ($cssforfield ? ' ' : '').'center';
708 }
709
710 if (in_array($val['type'], array('timestamp'))) {
711 $cssforfield .= ($cssforfield ? ' ' : '').'nowraponall';
712 } elseif ($key == 'ref') {
713 $cssforfield .= ($cssforfield ? ' ' : '').'nowraponall';
714 }
715
716 if (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && !in_array($key, array('id', 'rowid', 'ref', 'status')) && empty($val['arrayofkeyval'])) {
717 $cssforfield .= ($cssforfield ? ' ' : '').'right';
718 }
719 //if (in_array($key, array('fk_soc', 'fk_user', 'fk_warehouse'))) $cssforfield = 'tdoverflowmax100';
720
721 if (!empty($arrayfields['t.'.$key]['checked'])) {
722 print '<td'.($cssforfield ? ' class="'.$cssforfield.(preg_match('/tdoverflow/', $cssforfield) ? ' classfortooltip' : '').'"' : '');
723 if (preg_match('/tdoverflow/', $cssforfield) && !in_array($val['type'], array('ip', 'url')) && !is_numeric($object->$key)) {
724 print ' title="'.dol_escape_htmltag($object->$key).'"';
725 }
726 print '>';
727 if ($key == 'status') {
728 print $object->getLibStatut(5);
729 } elseif ($key == 'rowid') {
730 print $object->showOutputField($val, $key, $object->id, '');
731 } else {
732 print $object->showOutputField($val, $key, $object->$key, '');
733 }
734 print '</td>';
735 if (!$i) {
736 $totalarray['nbfield']++;
737 }
738 if (!empty($val['isameasure']) && $val['isameasure'] == 1) {
739 if (!$i) {
740 $totalarray['pos'][$totalarray['nbfield']] = 't.'.$key;
741 }
742 if (!isset($totalarray['val'])) {
743 $totalarray['val'] = array();
744 }
745 if (!isset($totalarray['val']['t.'.$key])) {
746 $totalarray['val']['t.'.$key] = 0;
747 }
748 $totalarray['val']['t.'.$key] += $object->$key;
749 }
750 }
751 }
752
753 if (!empty($arrayfields['wug.fk_usergroup']['checked'])) {
754 $toprint = array();
755 $cssforli = '';
756 if (count($object->usergroups) >= 4) {
757 $cssforli = 'tdoverflowmax60';
758 } elseif (count($object->usergroups) >= 2) {
759 $cssforli = 'tdoverflowmax80';
760 }
761 foreach ($object->usergroups as $id_group) {
762 $g = new UserGroup($db);
763 $g->fetch($id_group);
764 $toprint[] = '<li class="select2-search-choice-dolibarr noborderoncategories'.($cssforli ? ' '.$cssforli : '').'" style="background: #bbb">' . $g->getNomUrl(1, '', 0, 'categtextwhite') . '</li>';
765 }
766
767 print '<td class="minwidth300imp nowraponall">';
768 print '<div class="select2-container-multi-dolibarr"><ul class="select2-choices-dolibarr">' . implode(' ', $toprint) . '</ul></div>';
769 print '</td>';
770 }
771
772 if (!empty($arrayfields['wr.fk_resource']['checked'])) {
773 $toprint = array();
774 $cssforli = '';
775 if (count($object->resources) >= 4) {
776 $cssforli = 'tdoverflowmax60';
777 } elseif (count($object->resources) >= 2) {
778 $cssforli = 'tdoverflowmax80';
779 }
780 foreach ($object->resources as $id_resource) {
781 $r = new Dolresource($db);
782 $r->fetch($id_resource);
783 $toprint[] = '<li class="select2-search-choice-dolibarr noborderoncategories'.($cssforli ? ' '.$cssforli : '').'" style="background: #bbb">' . $r->getNomUrl(1, '', '', 0, 'categtextwhite') . '</li>';
784 }
785
786 print '<td class="minwidth300imp">';
787 print '<div class="select2-container-multi-dolibarr"><ul class="select2-choices-dolibarr">' . implode(' ', $toprint) . '</ul></div>';
788 print '</td>';
789 }
790
791 // Extra fields
792 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
793 // Fields from hook
794 $parameters = array('arrayfields' => $arrayfields, 'object' => $object, 'obj' => $obj, 'i' => $i, 'totalarray' => &$totalarray);
795 $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
796 print $hookmanager->resPrint;
797 // Action column
798 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
799 print '<td class="nowrap center">';
800 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
801 $selected = 0;
802 if (in_array($object->id, $arrayofselected)) {
803 $selected = 1;
804 }
805 print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
806 }
807 print '</td>';
808 if (!$i) {
809 $totalarray['nbfield']++;
810 }
811 }
812
813 print '</tr>'."\n";
814 }
815
816 $i++;
817}
818
819// Show total line
820include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
821
822// If no record found
823if ($num == 0) {
824 $colspan = 1;
825 foreach ($arrayfields as $key => $val) {
826 if (!empty($val['checked'])) {
827 $colspan++;
828 }
829 }
830 print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
831}
832
833
834$db->free($resql);
835
836$parameters = array('arrayfields' => $arrayfields, 'sql' => $sql);
837$reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
838print $hookmanager->resPrint;
839
840print '</table>'."\n";
841print '</div>'."\n";
842
843print '</form>'."\n";
844
845if (in_array('builddoc', array_keys($arrayofmassactions)) && ($nbtotalofrecords === '' || $nbtotalofrecords)) {
846 $hidegeneratedfilelistifempty = 1;
847 if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
848 $hidegeneratedfilelistifempty = 0;
849 }
850
851 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
852 $formfile = new FormFile($db);
853
854 // Show list of available documents
855 $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
856 $urlsource .= str_replace('&amp;', '&', $param);
857
858 $filedir = $diroutputmassaction;
859 $genallowed = $permissiontoread;
860 $delallowed = $permissiontoadd;
861
862 print $formfile->showdocuments('massfilesarea_'.$object->module, '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
863}
864
865// End of page
866llxFooter();
867$db->close();
$id
Definition account.php:39
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:70
DAO Resource object.
Class to manage standard extra fields.
Class to generate html code for admin pages.
Class to offer components to list and upload files.
Class to manage generation of HTML components Only common components must be here.
Class to manage forms for the module resource.
Class to manage user groups.
Class for Workstation.
static getAllResourcesOfWorkstation($fk_workstation)
Function used to get an array with all resources linked to a workstation.
static getAllGroupsOfWorkstation($fk_workstation)
Function used to get an array with all usergroups linked to a workstation.
llxFooter()
Footer empty.
Definition document.php:107
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
print_barre_liste($title, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $selectlimitsuffix=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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.
dol_eval($s, $returnvalue=1, $hideerrors=1, $onlysimplestring='1')
Replace eval function to add more security.
natural_search($fields, $value, $mode=0, $nofirstand=0)
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
dol_now($mode='auto')
Return date for now.
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 the value of a given key, which produces ascending (default) or descending out...
getTitleFieldOfList($name, $thead=0, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $disablesortlink=0, $tooltip='', $forcenowrapcolumntitle=0)
Get title line of an array.
dolGetButtonTitleSeparator($moreClass="")
Add space between dolGetButtonTitle.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.