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