dolibarr 18.0.6
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
27require '../main.inc.php';
28require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
29require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
30require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
31require_once DOL_DOCUMENT_ROOT.'/resource/class/html.formresource.class.php';
32require_once DOL_DOCUMENT_ROOT.'/workstation/class/workstation.class.php';
33
34// Load translation files required by the page
35$langs->loadLangs(array('mrp', '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');
55if (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)
76if (!$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}
80if (!$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
88foreach ($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();
103foreach ($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();
111foreach ($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
144include 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
154restrictedArea($user, $object->element, 0, $object->table_element, 'workstation');
155
156
157/*
158 * Actions
159 */
160
161if (GETPOST('cancel', 'alpha')) {
162 $action = 'list';
163 $massaction = '';
164}
165if (!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
171if ($reshook < 0) {
172 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
173}
174
175if (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
226if (!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 .= $hookmanager->resPrint;
235$sql = preg_replace('/,\s*$/', '', $sql);
236$sql .= " FROM ".MAIN_DB_PREFIX.$object->table_element." as t";
237if (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}
240if (!empty($groups)) {
241 $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'workstation_workstation_usergroup wug ON (wug.fk_workstation = t.rowid)';
242}
243if (!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;
250if ($object->ismultientitymanaged == 1) {
251 $sql .= " WHERE t.entity IN (".getEntity($object->element).")";
252} else {
253 $sql .= " WHERE 1 = 1";
254}
255foreach ($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}
284if ($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
291if (!empty($groups)) {
292 $sql.= ' AND wug.fk_usergroup IN('.$db->sanitize(implode(',', $groups)).')';
293}
294
295// resources
296if (!empty($resources)) {
297 $sql.= ' AND wr.fk_resource IN('.$db->sanitize(implode(',', $resources)).')';
298}
299
300include 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 ";
307foreach ($object->fields as $key => $val) {
308 $sql .= "t.".$db->escape($key).", ";
309}
310// Add fields from extrafields
311if (! 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 = '';
324if (!getDolGlobalInt('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);
338if ($limit) {
339 $sql .= $db->plimit($limit + 1, $offset);
340}
341
342$resql = $db->query($sql);
343if (!$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
352if ($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
363llxHeader('', $title, $help_url, '', 0, 0, $morejs, $morecss, '', 'classforhorizontalscrolloftabs');
364
365$arrayofselected = is_array($toselect) ? $toselect : array();
366
367$param = '';
368if (!empty($mode)) {
369 $param .= '&mode='.urlencode($mode);
370}
371if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
372 $param .= '&contextpage='.urlencode($contextpage);
373}
374if ($limit > 0 && $limit != $conf->liste_limit) {
375 $param .= '&limit='.((int) $limit);
376}
377foreach ($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}
388if ($optioncss != '') {
389 $param .= '&optioncss='.urlencode($optioncss);
390}
391// Add $param from extra fields
392include 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);
405if ($permissiontodelete) {
406 $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
407}
408if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) {
409 $arrayofmassactions = array();
410}
411$massactionbutton = $form->selectMassAction('', $arrayofmassactions);
412
413print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
414if ($optioncss != '') {
415 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
416}
417print '<input type="hidden" name="token" value="'.newToken().'">';
418print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
419print '<input type="hidden" name="action" value="list">';
420print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
421print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
422print '<input type="hidden" name="page" value="'.$page.'">';
423print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
424print '<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
429print_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;
436include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
437
438if ($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
452if (empty($reshook)) {
453 $moreforfilter .= $hookmanager->resPrint;
454} else {
455 $moreforfilter = $hookmanager->resPrint;
456}
457
458if (!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, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')); // This also change content of $arrayfields
466$selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
467
468print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
469print '<table class="tagtable nobottomiftotal liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
470
471
472// Fields title search
473// --------------------------------------------------------------------
474
475print '<tr class="liste_titre">';
476// Action column
477if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
478 print '<td class="liste_titre maxwidthsearch">';
479 $searchpicto = $form->showFilterButtons('left');
480 print $searchpicto;
481 print '</td>';
482}
483foreach ($object->fields as $key => $val) {
484 $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
485 if ($key == 'status') {
486 $cssforfield .= ($cssforfield ? ' ' : '').'center';
487 } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
488 $cssforfield .= ($cssforfield ? ' ' : '').'center';
489 } elseif (in_array($val['type'], array('timestamp'))) {
490 $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
491 } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID' && empty($val['arrayofkeyval'])) {
492 $cssforfield .= ($cssforfield ? ' ' : '').'right';
493 }
494 if (!empty($arrayfields['t.'.$key]['checked'])) {
495 print '<td class="liste_titre'.($cssforfield ? ' '.$cssforfield : '').'">';
496 if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
497 print $form->selectarray('search_'.$key, $val['arrayofkeyval'], (isset($search[$key]) ? $search[$key] : ''), $val['notnull'], 0, 0, '', 1, 0, 0, '', 'maxwidth100', 1);
498 } elseif ((strpos($val['type'], 'integer:') === 0) || (strpos($val['type'], 'sellist:') === 0)) {
499 print $object->showInputField($val, $key, (isset($search[$key]) ? $search[$key] : ''), '', '', 'search_', 'maxwidth125', 1);
500 } elseif (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
501 print '<div class="nowrap">';
502 print $form->selectDate($search[$key.'_dtstart'] ? $search[$key.'_dtstart'] : '', "search_".$key."_dtstart", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
503 print '</div>';
504 print '<div class="nowrap">';
505 print $form->selectDate($search[$key.'_dtend'] ? $search[$key.'_dtend'] : '', "search_".$key."_dtend", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
506 print '</div>';
507 } elseif ($key == 'lang') {
508 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
509 $formadmin = new FormAdmin($db);
510 print $formadmin->select_language($search[$key], 'search_lang', 0, null, 1, 0, 0, 'minwidth150 maxwidth200', 2);
511 } else {
512 print '<input type="text" class="flat maxwidth75" name="search_'.$key.'" value="'.dol_escape_htmltag(isset($search[$key]) ? $search[$key] : '').'">';
513 }
514 print '</td>';
515 }
516}
517
518// usergroups
519if (!empty($arrayfields['wug.fk_usergroup']['checked'])) {
520 print '<td class="liste_titre">';
521 print $form->select_dolgroups($groups, 'groups', 1, '', 0, '', '', $conf->entity, true);
522 print '</td>';
523}
524
525// resources
526if (!empty($arrayfields['wr.fk_resource']['checked'])) {
527 print '<td class="liste_titre">';
528 print $formresource->select_resource_list($resources, 'resources', '', '', 0, '', '', $conf->entity, true, 0, '', true);
529 print '</td>';
530}
531
532// Extra fields
533include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
534
535// Fields from hook
536$parameters = array('arrayfields'=>$arrayfields);
537$reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object); // Note that $action and $object may have been modified by hook
538print $hookmanager->resPrint;
539// Action column
540if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
541 print '<td class="liste_titre maxwidthsearch">';
542 $searchpicto = $form->showFilterButtons();
543 print $searchpicto;
544 print '</td>';
545}
546print '</tr>'."\n";
547
548$totalarray = array();
549$totalarray['nbfield'] = 0;
550
551// Fields title label
552// --------------------------------------------------------------------
553print '<tr class="liste_titre">';
554// Action column
555if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
556 print getTitleFieldOfList(($mode != 'kanban' ? $selectedfields : ''), 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
557 $totalarray['nbfield']++;
558}
559foreach ($object->fields as $key => $val) {
560 $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
561 if ($key == 'status') {
562 $cssforfield .= ($cssforfield ? ' ' : '').'center';
563 } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
564 $cssforfield .= ($cssforfield ? ' ' : '').'center';
565 } elseif (in_array($val['type'], array('timestamp'))) {
566 $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
567 } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID' && empty($val['arrayofkeyval'])) {
568 $cssforfield .= ($cssforfield ? ' ' : '').'right';
569 }
570 if (!empty($arrayfields['t.'.$key]['checked'])) {
571 print getTitleFieldOfList($arrayfields['t.'.$key]['label'], 0, $_SERVER['PHP_SELF'], 't.'.$key, '', $param, ($cssforfield ? 'class="'.$cssforfield.'"' : ''), $sortfield, $sortorder, ($cssforfield ? $cssforfield.' ' : ''))."\n";
572 $totalarray['nbfield']++;
573 }
574}
575
576// usergroups
577if (!empty($arrayfields['wug.fk_usergroup']['checked'])) {
578 print getTitleFieldOfList($arrayfields['wug.fk_usergroup']['label'], 0, $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, '') . "\n";
579}
580
581// resources
582if (!empty($arrayfields['wr.fk_resource']['checked'])) {
583 print getTitleFieldOfList($arrayfields['wr.fk_resource']['label'], 0, $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, '') . "\n";
584}
585
586// Extra fields
587include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
588// Hook fields
589$parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder, 'totalarray'=>&$totalarray);
590$reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
591print $hookmanager->resPrint;
592// Action column
593if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
594 print getTitleFieldOfList(($mode != 'kanban' ? $selectedfields : ''), 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
595 $totalaray['nbfield']++;
596}
597print '</tr>'."\n";
598
599
600// Detect if we need a fetch on each output line
601$needToFetchEachLine = 0;
602if (isset($extrafields->attributes[$object->table_element]['computed']) && is_array($extrafields->attributes[$object->table_element]['computed']) && count($extrafields->attributes[$object->table_element]['computed']) > 0) {
603 foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val) {
604 if (!is_null($val) && preg_match('/\$object/', $val)) {
605 $needToFetchEachLine++; // There is at least one compute field that use $object
606 }
607 }
608}
609
610
611// Loop on record
612// --------------------------------------------------------------------
613$i = 0;
614$savnbfield = $totalarray['nbfield'];
615$totalarray['nbfield'] = 0;
616$imaxinloop = ($limit ? min($num, $limit) : $num);
617while ($i < $imaxinloop) {
618 $obj = $db->fetch_object($resql);
619 if (empty($obj)) {
620 break; // Should not happen
621 }
622
623 // Store properties in $object
624 $object->setVarsFromFetchObj($obj);
625
626 $object->usergroups = WorkstationUserGroup::getAllGroupsOfWorkstation($obj->rowid);
627 $object->resources = WorkstationResource::getAllResourcesOfWorkstation($obj->rowid);
628
629 if ($mode == 'kanban') {
630 if ($i == 0) {
631 print '<tr class="trkanban"><td colspan="'.$savnbfield.'">';
632 print '<div class="box-flex-container kanban">';
633 }
634 // Output Kanban
635 print $object->getKanbanView('', array('selected' => in_array($object->id, $arrayofselected)));
636 if ($i == ($imaxinloop - 1)) {
637 print '</div>';
638 print '</td></tr>';
639 }
640 } else {
641 // Show here line of result
642 $j = 0;
643 print '<tr data-rowid="'.$object->id.'" class="oddeven">';
644 // Action column
645 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
646 print '<td class="nowrap center">';
647 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
648 $selected = 0;
649 if (in_array($object->id, $arrayofselected)) {
650 $selected = 1;
651 }
652 print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
653 }
654 print '</td>';
655 if (!$i) {
656 $totalarray['nbfield']++;
657 }
658 }
659 foreach ($object->fields as $key => $val) {
660 $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
661 if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
662 $cssforfield .= ($cssforfield ? ' ' : '').'center';
663 } elseif ($key == 'status') {
664 $cssforfield .= ($cssforfield ? ' ' : '').'center';
665 }
666
667 if (in_array($val['type'], array('timestamp'))) {
668 $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
669 } elseif ($key == 'ref') {
670 $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
671 }
672
673 if (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && !in_array($key, array('rowid', 'status')) && empty($val['arrayofkeyval'])) {
674 $cssforfield .= ($cssforfield ? ' ' : '').'right';
675 }
676 //if (in_array($key, array('fk_soc', 'fk_user', 'fk_warehouse'))) $cssforfield = 'tdoverflowmax100';
677
678 if (!empty($arrayfields['t.'.$key]['checked'])) {
679 print '<td'.($cssforfield ? ' class="'.$cssforfield.'"' : '').'>';
680 if ($key == 'status') {
681 print $object->getLibStatut(5);
682 } elseif ($key == 'rowid') {
683 print $object->showOutputField($val, $key, $object->id, '');
684 } else {
685 print $object->showOutputField($val, $key, $object->$key, '');
686 }
687 print '</td>';
688 if (!$i) {
689 $totalarray['nbfield']++;
690 }
691 if (!empty($val['isameasure']) && $val['isameasure'] == 1) {
692 if (!$i) {
693 $totalarray['pos'][$totalarray['nbfield']] = 't.'.$key;
694 }
695 if (!isset($totalarray['val'])) {
696 $totalarray['val'] = array();
697 }
698 if (!isset($totalarray['val']['t.'.$key])) {
699 $totalarray['val']['t.'.$key] = 0;
700 }
701 $totalarray['val']['t.'.$key] += $object->$key;
702 }
703 }
704 }
705
706 if (!empty($arrayfields['wug.fk_usergroup']['checked'])) {
707 $toprint = array();
708 $cssforli = '';
709 if (count($object->usergroups) >= 4) {
710 $cssforli = 'tdoverflowmax60';
711 } elseif (count($object->usergroups) >= 2) {
712 $cssforli = 'tdoverflowmax80';
713 }
714 foreach ($object->usergroups as $id_group) {
715 $g = new UserGroup($db);
716 $g->fetch($id_group);
717 $toprint[] = '<li class="select2-search-choice-dolibarr noborderoncategories'.($cssforli ? ' '.$cssforli : '').'" style="background: #bbb">' . $g->getNomUrl(1, '', 0, 'categtextwhite') . '</li>';
718 }
719
720 print '<td>';
721 print '<div class="select2-container-multi-dolibarr"><ul class="select2-choices-dolibarr">' . implode(' ', $toprint) . '</ul></div>';
722 print '</td>';
723 }
724
725 if (!empty($arrayfields['wr.fk_resource']['checked'])) {
726 $toprint = array();
727 $cssforli = '';
728 if (count($object->resources) >= 4) {
729 $cssforli = 'tdoverflowmax60';
730 } elseif (count($object->resources) >= 2) {
731 $cssforli = 'tdoverflowmax80';
732 }
733 foreach ($object->resources as $id_resource) {
734 $r = new Dolresource($db);
735 $r->fetch($id_resource);
736 $toprint[] = '<li class="select2-search-choice-dolibarr noborderoncategories'.($cssforli ? ' '.$cssforli : '').'" style="background: #bbb">' . $r->getNomUrl(1, '', '', 0, 'categtextwhite') . '</li>';
737 }
738
739 print '<td>';
740 print '<div class="select2-container-multi-dolibarr"><ul class="select2-choices-dolibarr">' . implode(' ', $toprint) . '</ul></div>';
741 print '</td>';
742 }
743
744 // Extra fields
745 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
746 // Fields from hook
747 $parameters = array('arrayfields'=>$arrayfields, 'object'=>$object, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
748 $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object); // Note that $action and $object may have been modified by hook
749 print $hookmanager->resPrint;
750 // Action column
751 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
752 print '<td class="nowrap center">';
753 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
754 $selected = 0;
755 if (in_array($object->id, $arrayofselected)) {
756 $selected = 1;
757 }
758 print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
759 }
760 print '</td>';
761 if (!$i) {
762 $totalarray['nbfield']++;
763 }
764 }
765
766 print '</tr>'."\n";
767 }
768
769 $i++;
770}
771
772// Show total line
773include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
774
775// If no record found
776if ($num == 0) {
777 $colspan = 1;
778 foreach ($arrayfields as $key => $val) {
779 if (!empty($val['checked'])) {
780 $colspan++;
781 }
782 }
783 print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
784}
785
786
787$db->free($resql);
788
789$parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
790$reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object); // Note that $action and $object may have been modified by hook
791print $hookmanager->resPrint;
792
793print '</table>'."\n";
794print '</div>'."\n";
795
796print '</form>'."\n";
797
798if (in_array('builddoc', array_keys($arrayofmassactions)) && ($nbtotalofrecords === '' || $nbtotalofrecords)) {
799 $hidegeneratedfilelistifempty = 1;
800 if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
801 $hidegeneratedfilelistifempty = 0;
802 }
803
804 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
805 $formfile = new FormFile($db);
806
807 // Show list of available documents
808 $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
809 $urlsource .= str_replace('&amp;', '&', $param);
810
811 $filedir = $diroutputmassaction;
812 $genallowed = $permissiontoread;
813 $delallowed = $permissiontoadd;
814
815 print $formfile->showdocuments('massfilesarea_workstation', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
816}
817
818// End of page
819llxFooter();
820$db->close();
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Definition wrapper.php: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.
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_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...
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
print_barre_liste($titre, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $hideselectlimit=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
getDolGlobalString($key, $default='')
Return 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.