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