dolibarr  17.0.4
position_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) 2021 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
4  * Copyright (C) 2021 Greg Rastklan <greg.rastklan@atm-consulting.fr>
5  * Copyright (C) 2021 Jean-Pascal BOUDET <jean-pascal.boudet@atm-consulting.fr>
6  * Copyright (C) 2021 Grégory BLEMAND <gregory.blemand@atm-consulting.fr>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <https://www.gnu.org/licenses/>.
20  */
21 
29 // Load Dolibarr environment
30 require '../main.inc.php';
31 
32 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
33 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
34 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
35 
36 // load hrm libraries
37 require_once __DIR__.'/class/position.class.php';
38 
39 // for other modules
40 //dol_include_once('/othermodule/class/otherobject.class.php');
41 
42 // Load translation files required by the page
43 $langs->loadLangs(array('hrm', 'other'));
44 
45 // Get Parameters
46 $action = GETPOST('action', 'aZ09') ?GETPOST('action', 'aZ09') : 'view'; // The action 'add', 'create', 'edit', 'update', 'view', ...
47 $massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists)
48 $show_files = GETPOST('show_files', 'int'); // Show files area generated by bulk actions ?
49 $confirm = GETPOST('confirm', 'alpha'); // Result of a confirmation
50 $cancel = GETPOST('cancel', 'alpha'); // We click on a Cancel button
51 $toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list
52 $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'positionlist'; // To manage different context of search
53 $backtopage = GETPOST('backtopage', 'alpha'); // Go back to a dedicated page
54 $optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
55 $mode = GETPOST('mode', 'aZ');
56 
57 $id = GETPOST('id', 'int');
58 $ref = GETPOST('ref', 'alpha');
59 
60 // Load variable for pagination
61 $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
62 $sortfield = GETPOST('sortfield', 'aZ09comma');
63 $sortorder = GETPOST('sortorder', 'aZ09comma');
64 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
65 if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
66  // If $page is not defined, or '' or -1 or if we click on clear filters
67  $page = 0;
68 }
69 $offset = $limit * $page;
70 $pageprev = $page - 1;
71 $pagenext = $page + 1;
72 
73 // Initialize technical objects
74 $object = new Position($db);
75 $extrafields = new ExtraFields($db);
76 $diroutputmassaction = $conf->hrm->dir_output.'/temp/massgeneration/'.$user->id;
77 $hookmanager->initHooks(array('positionlist')); // Note that conf->hooks_modules contains array
78 
79 // Fetch optionals attributes and labels
80 $extrafields->fetch_name_optionals_label($object->table_element);
81 //$extrafields->fetch_name_optionals_label($object->table_element_line);
82 
83 $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
84 
85 // Default sort order (if not yet defined by previous GETPOST)
86 if (!$sortfield) {
87  reset($object->fields); // Reset is required to avoid key() to return null.
88  $sortfield = "t.".key($object->fields); // Set here default search field. By default 1st field in definition.
89 }
90 if (!$sortorder) {
91  $sortorder = "ASC";
92 }
93 
94 // Initialize array of search criterias
95 $search_all = GETPOST('search_all', 'alphanohtml') ? GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml');
96 $search = array();
97 foreach ($object->fields as $key => $val) {
98  if (GETPOST('search_'.$key, 'alpha') !== '') {
99  $search[$key] = GETPOST('search_'.$key, 'alpha');
100  }
101  if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
102  $search[$key.'_dtstart'] = dol_mktime(0, 0, 0, GETPOST('search_'.$key.'_dtstartmonth', 'int'), GETPOST('search_'.$key.'_dtstartday', 'int'), GETPOST('search_'.$key.'_dtstartyear', 'int'));
103  $search[$key.'_dtend'] = dol_mktime(23, 59, 59, GETPOST('search_'.$key.'_dtendmonth', 'int'), GETPOST('search_'.$key.'_dtendday', 'int'), GETPOST('search_'.$key.'_dtendyear', 'int'));
104  }
105 }
106 
107 // List of fields to search into when doing a "search in all"
108 $fieldstosearchall = array();
109 foreach ($object->fields as $key => $val) {
110  if (!empty($val['searchall'])) {
111  $fieldstosearchall['t.'.$key] = $val['label'];
112  }
113 }
114 
115 // Definition of array of fields for columns
116 $arrayfields = array();
117 foreach ($object->fields as $key => $val) {
118  // If $val['visible']==0, then we never show the field
119  if (!empty($val['visible'])) {
120  $visible = (int) dol_eval($val['visible'], 1);
121  $arrayfields['t.'.$key] = array(
122  'label'=>$val['label'],
123  'checked'=>(($visible < 0) ? 0 : 1),
124  'enabled'=>(abs($visible) != 3 && dol_eval($val['enabled'], 1)),
125  'position'=>$val['position'],
126  'help'=> isset($val['help']) ? $val['help'] : ''
127  );
128  }
129 }
130 // Extra fields
131 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
132 
133 $object->fields = dol_sort_array($object->fields, 'position');
134 $arrayfields = dol_sort_array($arrayfields, 'position');
135 
136 // Permissions
137 $permissiontoread = $user->rights->hrm->all->read;
138 $permissiontoadd = $user->rights->hrm->all->write;
139 $permissiontodelete = $user->rights->hrm->all->delete;
140 
141 // Security check (enable the most restrictive one)
142 if ($user->socid > 0) accessforbidden();
143 //if ($user->socid > 0) accessforbidden();
144 //$socid = 0; if ($user->socid > 0) $socid = $user->socid;
145 //$isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
146 //restrictedArea($user, $object->element, $object->id, $object->table_element, '', 'fk_soc', 'rowid', $isdraft);
147 if (!isModEnabled('hrm')) {
148  accessforbidden('Module hrm not enabled');
149 }
150 if (!$permissiontoread) accessforbidden();
151 
152 
153 
154 /*
155  * Actions
156  */
157 
158 if (GETPOST('cancel', 'alpha')) {
159  $action = 'list';
160  $massaction = '';
161 }
162 if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
163  $massaction = '';
164 }
165 
166 $parameters = array();
167 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
168 if ($reshook < 0) {
169  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
170 }
171 
172 if (empty($reshook)) {
173  // Selection of new fields
174  include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
175 
176  // Purge search criteria
177  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
178  foreach ($object->fields as $key => $val) {
179  $search[$key] = '';
180  if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
181  $search[$key.'_dtstart'] = '';
182  $search[$key.'_dtend'] = '';
183  }
184  }
185  $toselect = array();
186  $search_array_options = array();
187  }
188  if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')
189  || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) {
190  $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation
191  }
192 
193  // Mass actions
194  $objectclass = 'Position';
195  $objectlabel = 'Position';
196  $uploaddir = $conf->hrm->dir_output;
197  include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
198 }
199 
200 
201 
202 /*
203  * View
204  */
205 
206 $form = new Form($db);
207 
208 $now = dol_now();
209 
210 //$help_url="EN:Module_Position|FR:Module_Position_FR|ES:Módulo_Position";
211 $help_url = '';
212 $title = $langs->trans('EmployeePositions');
213 $morejs = array();
214 $morecss = array();
215 
216 
217 // Build and execute select
218 // --------------------------------------------------------------------
219 $sql = 'SELECT ';
220 $sql .= $object->getFieldList('t');
221 // Add fields from extrafields
222 if (!empty($extrafields->attributes[$object->table_element]['label'])) {
223  foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
224  $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');
225  }
226 }
227 // Add fields from hooks
228 $parameters = array();
229 $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object); // Note that $action and $object may have been modified by hook
230 $sql .= preg_replace('/^,/', '', $hookmanager->resPrint);
231 $sql = preg_replace('/,\s*$/', '', $sql);
232 $sql .= " FROM ".MAIN_DB_PREFIX.$object->table_element." as t";
233 if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
234  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (t.rowid = ef.fk_object)";
235 }
236 // Add table from hooks
237 $parameters = array();
238 $reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object); // Note that $action and $object may have been modified by hook
239 $sql .= $hookmanager->resPrint;
240 if ($object->ismultientitymanaged == 1) {
241  $sql .= " WHERE t.entity IN (".getEntity($object->element).")";
242 } else {
243  $sql .= " WHERE 1 = 1";
244 }
245 foreach ($search as $key => $val) {
246  if (array_key_exists($key, $object->fields)) {
247  if ($key == 'status' && $search[$key] == -1) {
248  continue;
249  }
250  $mode_search = (($object->isInt($object->fields[$key]) || $object->isFloat($object->fields[$key])) ? 1 : 0);
251  if ((strpos($object->fields[$key]['type'], 'integer:') === 0) || (strpos($object->fields[$key]['type'], 'sellist:') === 0) || !empty($object->fields[$key]['arrayofkeyval'])) {
252  if ($search[$key] == '-1' || ($search[$key] === '0' && (empty($object->fields[$key]['arrayofkeyval']) || !array_key_exists('0', $object->fields[$key]['arrayofkeyval'])))) {
253  $search[$key] = '';
254  }
255  $mode_search = 2;
256  }
257  if ($search[$key] != '') {
258  $sql .= natural_search("t.".$db->escape($key), $search[$key], (($key == 'status') ? 2 : $mode_search));
259  }
260  } else {
261  if (preg_match('/(_dtstart|_dtend)$/', $key) && $search[$key] != '') {
262  $columnName=preg_replace('/(_dtstart|_dtend)$/', '', $key);
263  if (preg_match('/^(date|timestamp|datetime)/', $object->fields[$columnName]['type'])) {
264  if (preg_match('/_dtstart$/', $key)) {
265  $sql .= " AND t.".$db->escape($columnName)." >= '".$db->idate($search[$key])."'";
266  }
267  if (preg_match('/_dtend$/', $key)) {
268  $sql .= " AND t.".$db->escape($columnName)." <= '".$db->idate($search[$key])."'";
269  }
270  }
271  }
272  }
273 }
274 $vacant = GETPOST('search_fk_uservacant', 'alphanohtml') === 'on';
275 if ($vacant) {
276  $sql .= ' AND t.fk_user = 0';
277 }
278 if ($search_all) {
279  $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
280 }
281 //$sql.= dolSqlDateFilter("t.field", $search_xxxday, $search_xxxmonth, $search_xxxyear);
282 // Add where from extra fields
283 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
284 // Add where from hooks
285 $parameters = array();
286 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object); // Note that $action and $object may have been modified by hook
287 $sql .= $hookmanager->resPrint;
288 
289 /* If a group by is required
290 $sql .= " GROUP BY ";
291 foreach($object->fields as $key => $val) {
292  $sql .= "t.".$db->escape($key).", ";
293 }
294 // Add fields from extrafields
295 if (!empty($extrafields->attributes[$object->table_element]['label'])) {
296  foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
297  $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? "ef.".$key.', ' : '');
298  }
299 }
300 // Add where from hooks
301 $parameters = array();
302 $reshook = $hookmanager->executeHooks('printFieldListGroupBy', $parameters, $object); // Note that $action and $object may have been modified by hook
303 $sql .= $hookmanager->resPrint;
304 $sql = preg_replace('/,\s*$/', '', $sql);
305 */
306 
307 // Count total nb of records
308 $nbtotalofrecords = '';
309 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
310  $resql = $db->query($sql);
311  $nbtotalofrecords = $db->num_rows($resql);
312  if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0
313  $page = 0;
314  $offset = 0;
315  }
316  $db->free($resql);
317 }
318 
319 // Complete request and execute it with limit
320 $sql .= $db->order($sortfield, $sortorder);
321 if ($limit) {
322  $sql .= $db->plimit($limit + 1, $offset);
323 }
324 
325 $resql = $db->query($sql);
326 if (!$resql) {
327  dol_print_error($db);
328  exit;
329 }
330 
331 $num = $db->num_rows($resql);
332 
333 
334 // Direct jump if only one record found
335 if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $search_all && !$page) {
336  $obj = $db->fetch_object($resql);
337  $id = $obj->rowid;
338  header("Location: ".dol_buildpath('/hrm/position.php', 1).'?id='.$id);
339  exit;
340 }
341 
342 
343 // Output page
344 // --------------------------------------------------------------------
345 
346 llxHeader('', $title, $help_url, '', 0, 0, $morejs, $morecss, '', '');
347 
348 // Example : Adding jquery code
349 // print '<script type="text/javascript" language="javascript">
350 // jQuery(document).ready(function() {
351 // function init_myfunc()
352 // {
353 // jQuery("#myid").removeAttr(\'disabled\');
354 // jQuery("#myid").attr(\'disabled\',\'disabled\');
355 // }
356 // init_myfunc();
357 // jQuery("#mybutton").click(function() {
358 // init_myfunc();
359 // });
360 // });
361 // </script>';
362 
363 $arrayofselected = is_array($toselect) ? $toselect : array();
364 
365 $param = '';
366 if (!empty($mode)) {
367  $param .= '&mode='.urlencode($mode);
368 }
369 if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
370  $param .= '&contextpage='.urlencode($contextpage);
371 }
372 if ($limit > 0 && $limit != $conf->liste_limit) {
373  $param .= '&limit='.urlencode($limit);
374 }
375 
376 foreach ($search as $key => $val) {
377  if (is_array($search[$key])) {
378  foreach ($search[$key] as $skey) {
379  if ($skey != '') {
380  $param .= '&search_'.$key.'[]='.urlencode($skey);
381  }
382  }
383  } elseif (preg_match('/(_dtstart|_dtend)$/', $key) && !empty($val)) {
384  $param .= '&search_'.$key.'month='.((int) GETPOST('search_'.$key.'month', 'int'));
385  $param .= '&search_'.$key.'day='.((int) GETPOST('search_'.$key.'day', 'int'));
386  $param .= '&search_'.$key.'year='.((int) GETPOST('search_'.$key.'year', 'int'));
387  } elseif ($search[$key] != '') {
388  $param .= '&search_'.$key.'='.urlencode($search[$key]);
389  }
390 }
391 if ($optioncss != '') {
392  $param .= '&optioncss='.urlencode($optioncss);
393 }
394 // Add $param from extra fields
395 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
396 // Add $param from hooks
397 $parameters = array();
398 $reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object); // Note that $action and $object may have been modified by hook
399 $param .= $hookmanager->resPrint;
400 
401 // List of mass actions available
402 $arrayofmassactions = array(
403  //'validate'=>img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Validate"),
404  //'generate_doc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"),
405  //'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
406  //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
407 );
408 if (!empty($permissiontodelete)) {
409  $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
410 }
411 if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) {
412  $arrayofmassactions = array();
413 }
414 $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
415 
416 print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
417 if ($optioncss != '') {
418  print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
419 }
420 print '<input type="hidden" name="token" value="'.newToken().'">';
421 print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
422 print '<input type="hidden" name="action" value="list">';
423 print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
424 print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
425 print '<input type="hidden" name="page" value="'.$page.'">';
426 print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
427 print '<input type="hidden" name="mode" value="'.$mode.'">';
428 
429 $newcardbutton = dolGetButtonTitle($langs->trans('New'), '', 'fa fa-plus-circle', dol_buildpath('/hrm/position.php', 1).'?action=create', '', $permissiontoadd);
430 
431 print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'object_'.$object->picto, 0, $newcardbutton, '', $limit, 0, 0, 1);
432 
433 // Add code for pre mass action (confirmation or email presend form)
434 $topicmail = "SendPositionRef";
435 $modelmail = "position";
436 $objecttmp = new Position($db);
437 $trackid = 'xxxx'.$object->id;
438 include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
439 
440 if ($search_all) {
441  $setupstring = '';
442  foreach ($fieldstosearchall as $key => $val) {
443  $fieldstosearchall[$key] = $langs->trans($val);
444  $setupstring .= $key."=".$val.";";
445  }
446  print '<!-- Search done like if JOBPOSITION_QUICKSEARCH_ON_FIELDS = '.$setupstring.' -->'."\n";
447  print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).join(', ', $fieldstosearchall).'</div>';
448 }
449 
450 $moreforfilter = '';
451 /*$moreforfilter.='<div class="divsearchfield">';
452 $moreforfilter.= $langs->trans('MyFilter') . ': <input type="text" name="search_myfield" value="'.dol_escape_htmltag($search_myfield).'">';
453 $moreforfilter.= '</div>';*/
454 
455 $parameters = array();
456 $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
457 if (empty($reshook)) {
458  $moreforfilter .= $hookmanager->resPrint;
459 } else {
460  $moreforfilter = $hookmanager->resPrint;
461 }
462 
463 if (!empty($moreforfilter)) {
464  print '<div class="liste_titre liste_titre_bydiv centpercent">';
465  print $moreforfilter;
466  print '</div>';
467 }
468 
469 $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
470 $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN', '')); // This also change content of $arrayfields
471 $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
472 
473 print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
474 print '<table class="tagtable nobottomiftotal liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
475 
476 
477 // Fields title search
478 // --------------------------------------------------------------------
479 print '<tr class="liste_titre">';
480 // Action column
481 if (!empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
482  print '<td class="liste_titre maxwidthsearch">';
483  $searchpicto = $form->showFilterButtons('left');
484  print $searchpicto;
485  print '</td>';
486 }
487 foreach ($object->fields as $key => $val) {
488  $searchkey = empty($search[$key]) ? '' : $search[$key];
489  $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
490  if ($key == 'status') {
491  $cssforfield .= ($cssforfield ? ' ' : '').'center';
492  } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
493  $cssforfield .= ($cssforfield ? ' ' : '').'center';
494  } elseif (in_array($val['type'], array('timestamp'))) {
495  $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
496  } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $key != 'rowid' && $val['label'] != 'TechnicalID' && empty($val['arrayofkeyval'])) {
497  $cssforfield .= ($cssforfield ? ' ' : '').'right';
498  }
499  if (!empty($arrayfields['t.'.$key]['checked'])) {
500  print '<td class="liste_titre'.($cssforfield ? ' '.$cssforfield : '').'">';
501  if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
502  print $form->selectarray('search_'.$key, $val['arrayofkeyval'], (isset($search[$key]) ? $search[$key] : ''), $val['notnull'], 0, 0, '', 1, 0, 0, '', 'maxwidth100', 1);
503  } elseif ((strpos($val['type'], 'integer:') === 0) || (strpos($val['type'], 'sellist:') === 0)) {
504  print $object->showInputField($val, $key, (isset($search[$key]) ? $search[$key] : ''), '', '', 'search_', $cssforfield.' maxwidth250', 1);
505  } elseif (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
506  print '<div class="nowrap">';
507  print $form->selectDate($search[$key.'_dtstart'] ? $search[$key.'_dtstart'] : '', "search_".$key."_dtstart", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
508  print '</div>';
509  print '<div class="nowrap">';
510  print $form->selectDate($search[$key.'_dtend'] ? $search[$key.'_dtend'] : '', "search_".$key."_dtend", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
511  print '</div>';
512  } elseif ($key == 'lang') {
513  require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
514  $formadmin = new FormAdmin($db);
515  print $formadmin->select_language($search[$key], 'search_lang', 0, null, 1, 0, 0, 'minwidth150 maxwidth200', 2);
516  } else {
517  print '<input type="text" class="flat maxwidth75" name="search_'.$key.'" value="'.dol_escape_htmltag(isset($search[$key]) ? $search[$key] : '').'">';
518  }
519  print '</td>';
520  }
521 }
522 // Extra fields
523 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
524 
525 // Fields from hook
526 $parameters = array('arrayfields'=>$arrayfields);
527 $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object); // Note that $action and $object may have been modified by hook
528 print $hookmanager->resPrint;
529 // Action column
530 if (empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
531  print '<td class="liste_titre maxwidthsearch">';
532  $searchpicto = $form->showFilterButtons();
533  print $searchpicto;
534  print '</td>';
535 }
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 if (!empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
545  print getTitleFieldOfList(($mode != 'kanban' ? $selectedfields : ''), 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
546 }
547 foreach ($object->fields as $key => $val) {
548  $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
549  if ($key == 'status') {
550  $cssforfield .= ($cssforfield ? ' ' : '').'center';
551  } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
552  $cssforfield .= ($cssforfield ? ' ' : '').'center';
553  } elseif (in_array($val['type'], array('timestamp'))) {
554  $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
555  } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $key != 'rowid' && $val['label'] != 'TechnicalID' && empty($val['arrayofkeyval'])) {
556  $cssforfield .= ($cssforfield ? ' ' : '').'right';
557  }
558  $cssforfield = preg_replace('/small\s*/', '', $cssforfield); // the 'small' css must not be used for the title label
559  if (!empty($arrayfields['t.'.$key]['checked'])) {
560  print getTitleFieldOfList($arrayfields['t.'.$key]['label'], 0, $_SERVER['PHP_SELF'], 't.'.$key, '', $param, ($cssforfield ? 'class="'.$cssforfield.'"' : ''), $sortfield, $sortorder, ($cssforfield ? $cssforfield.' ' : ''))."\n";
561  $totalarray['nbfield']++;
562  }
563 }
564 // Extra fields
565 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
566 // Hook fields
567 $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder, 'totalarray'=>&$totalarray);
568 $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
569 print $hookmanager->resPrint;
570 // Action column
571 if (empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
572  print getTitleFieldOfList(($mode != 'kanban' ? $selectedfields : ''), 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
573 }
574 $totalarray['nbfield']++;
575 print '</tr>'."\n";
576 
577 
578 // Detect if we need a fetch on each output line
579 $needToFetchEachLine = 0;
580 if (isset($extrafields->attributes[$object->table_element]['computed']) && is_array($extrafields->attributes[$object->table_element]['computed']) && count($extrafields->attributes[$object->table_element]['computed']) > 0) {
581  foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val) {
582  if (preg_match('/\$object/', $val)) {
583  $needToFetchEachLine++; // There is at least one compute field that use $object
584  }
585  }
586 }
587 
588 
589 // Loop on record
590 // --------------------------------------------------------------------
591 $i = 0;
592 $savnbfield = $totalarray['nbfield'];
593 $totalarray = array();
594 $totalarray['nbfield'] = 0;
595 $imaxinloop = ($limit ? min($num, $limit) : $num);
596 while ($i < $imaxinloop) {
597  $obj = $db->fetch_object($resql);
598  if (empty($obj)) {
599  break; // Should not happen
600  }
601 
602  // Store properties in $object
603  $object->setVarsFromFetchObj($obj);
604 
605  if ($mode == 'kanban') {
606  if ($i == 0) {
607  print '<tr><td colspan="'.$savnbfield.'">';
608  print '<div class="box-flex-container">';
609  }
610  // Output Kanban
611  print $object->getKanbanView('');
612  if ($i == ($imaxinloop - 1)) {
613  print '</div>';
614  print '</td></tr>';
615  }
616  } else {
617  // Show here line of result
618  $j = 0;
619  print '<tr data-rowid="'.$object->id.'" class="oddeven">';
620  // Action column
621  if (!empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
622  print '<td class="nowrap center">';
623  if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
624  $selected = 0;
625  if (in_array($object->id, $arrayofselected)) {
626  $selected = 1;
627  }
628  print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
629  }
630  print '</td>';
631  }
632  foreach ($object->fields as $key => $val) {
633  $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
634  if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
635  $cssforfield .= ($cssforfield ? ' ' : '').'center';
636  } elseif ($key == 'status') {
637  $cssforfield .= ($cssforfield ? ' ' : '').'center';
638  }
639 
640  if (in_array($val['type'], array('timestamp'))) {
641  $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
642  } elseif ($key == 'ref') {
643  $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
644  }
645 
646  if (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && !in_array($key, array('rowid', 'status')) && empty($val['arrayofkeyval'])) {
647  $cssforfield .= ($cssforfield ? ' ' : '').'right';
648  }
649  //if (in_array($key, array('fk_soc', 'fk_user', 'fk_warehouse'))) $cssforfield = 'tdoverflowmax100';
650 
651  if (!empty($arrayfields['t.'.$key]['checked'])) {
652  print '<td'.($cssforfield ? ' class="'.$cssforfield.'"' : '');
653  if (preg_match('/tdoverflow/', $cssforfield)) {
654  print ' title="'.dol_escape_htmltag($object->$key).'"';
655  }
656  print '>';
657  if ($key == 'status') {
658  print $object->getLibStatut(5);
659  } elseif ($key == 'rowid') {
660  print $object->showOutputField($val, $key, $object->id, '');
661  } else {
662  print $object->showOutputField($val, $key, $object->$key, '');
663  }
664  print '</td>';
665  if (!$i) {
666  $totalarray['nbfield']++;
667  }
668  if (!empty($val['isameasure']) && $val['isameasure'] == 1) {
669  if (!$i) {
670  $totalarray['pos'][$totalarray['nbfield']] = 't.'.$key;
671  }
672  if (!isset($totalarray['val'])) {
673  $totalarray['val'] = array();
674  }
675  if (!isset($totalarray['val']['t.'.$key])) {
676  $totalarray['val']['t.'.$key] = 0;
677  }
678  $totalarray['val']['t.'.$key] += $object->$key;
679  }
680  }
681  }
682  // Extra fields
683  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
684  // Fields from hook
685  $parameters = array('arrayfields'=>$arrayfields, 'object'=>$object, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
686  $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object); // Note that $action and $object may have been modified by hook
687  print $hookmanager->resPrint;
688  // Action column
689  if (empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
690  print '<td class="nowrap center">';
691  if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
692  $selected = 0;
693  if (in_array($object->id, $arrayofselected)) {
694  $selected = 1;
695  }
696  print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
697  }
698  print '</td>';
699  }
700  if (!$i) {
701  $totalarray['nbfield']++;
702  }
703 
704  print '</tr>'."\n";
705  }
706 
707  $i++;
708 }
709 
710 // Show total line
711 include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
712 
713 // If no record found
714 if ($num == 0) {
715  $colspan = 1;
716  foreach ($arrayfields as $key => $val) {
717  if (!empty($val['checked'])) {
718  $colspan++;
719  }
720  }
721  print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
722 }
723 
724 
725 $db->free($resql);
726 
727 $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
728 $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
729 print $hookmanager->resPrint;
730 
731 print '</table>'."\n";
732 print '</div>'."\n";
733 
734 print '</form>'."\n";
735 
736 if (in_array('builddoc', $arrayofmassactions) && ($nbtotalofrecords === '' || $nbtotalofrecords)) {
737  $hidegeneratedfilelistifempty = 1;
738  if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
739  $hidegeneratedfilelistifempty = 0;
740  }
741 
742  require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
743  $formfile = new FormFile($db);
744 
745  // Show list of available documents
746  $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
747  $urlsource .= str_replace('&amp;', '&', $param);
748 
749  $filedir = $diroutputmassaction;
750  $genallowed = $permissiontoread;
751  $delallowed = $permissiontoadd;
752 
753  print $formfile->showdocuments('massfilesarea_hrm', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
754 }
755 
756 // End of page
757 llxFooter();
758 $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
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 for Position.
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.
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
isModEnabled($module)
Is Dolibarr module enabled.
$nbtotalofrecords
Count total nb of records.
Definition: list.php:329
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.