dolibarr  16.0.5
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 $action = GETPOST('action', 'aZ09') ?GETPOST('action', 'aZ09') : 'view'; // The action 'add', 'create', 'edit', 'update', 'view', ...
46 $massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists)
47 $show_files = GETPOST('show_files', 'int'); // Show files area generated by bulk actions ?
48 $confirm = GETPOST('confirm', 'alpha'); // Result of a confirmation
49 $cancel = GETPOST('cancel', 'alpha'); // We click on a Cancel button
50 $toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list
51 $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'positionlist'; // To manage different context of search
52 $backtopage = GETPOST('backtopage', 'alpha'); // Go back to a dedicated page
53 $optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
54 
55 $id = GETPOST('id', 'int');
56 
57 // Load variable for pagination
58 $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
59 $sortfield = GETPOST('sortfield', 'aZ09comma');
60 $sortorder = GETPOST('sortorder', 'aZ09comma');
61 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
62 if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
63  // If $page is not defined, or '' or -1 or if we click on clear filters
64  $page = 0;
65 }
66 $offset = $limit * $page;
67 $pageprev = $page - 1;
68 $pagenext = $page + 1;
69 
70 // Initialize technical objects
71 $object = new Position($db);
72 $extrafields = new ExtraFields($db);
73 $diroutputmassaction = $conf->hrm->dir_output.'/temp/massgeneration/'.$user->id;
74 $hookmanager->initHooks(array('positionlist')); // Note that conf->hooks_modules contains array
75 
76 // Fetch optionals attributes and labels
77 $extrafields->fetch_name_optionals_label($object->table_element);
78 //$extrafields->fetch_name_optionals_label($object->table_element_line);
79 
80 $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
81 
82 // Default sort order (if not yet defined by previous GETPOST)
83 if (!$sortfield) {
84  reset($object->fields); // Reset is required to avoid key() to return null.
85  $sortfield = "t.".key($object->fields); // Set here default search field. By default 1st field in definition.
86 }
87 if (!$sortorder) {
88  $sortorder = "ASC";
89 }
90 
91 // Initialize array of search criterias
92 $search_all = GETPOST('search_all', 'alphanohtml') ? GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml');
93 $search = array();
94 foreach ($object->fields as $key => $val) {
95  if (GETPOST('search_'.$key, 'alpha') !== '') {
96  $search[$key] = GETPOST('search_'.$key, 'alpha');
97  }
98  if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
99  $search[$key.'_dtstart'] = dol_mktime(0, 0, 0, GETPOST('search_'.$key.'_dtstartmonth', 'int'), GETPOST('search_'.$key.'_dtstartday', 'int'), GETPOST('search_'.$key.'_dtstartyear', 'int'));
100  $search[$key.'_dtend'] = dol_mktime(23, 59, 59, GETPOST('search_'.$key.'_dtendmonth', 'int'), GETPOST('search_'.$key.'_dtendday', 'int'), GETPOST('search_'.$key.'_dtendyear', 'int'));
101  }
102 }
103 
104 // List of fields to search into when doing a "search in all"
105 $fieldstosearchall = array();
106 foreach ($object->fields as $key => $val) {
107  if (!empty($val['searchall'])) {
108  $fieldstosearchall['t.'.$key] = $val['label'];
109  }
110 }
111 
112 // Definition of array of fields for columns
113 $arrayfields = array();
114 foreach ($object->fields as $key => $val) {
115  // If $val['visible']==0, then we never show the field
116  if (!empty($val['visible'])) {
117  $visible = (int) dol_eval($val['visible'], 1, 1, '1');
118  $arrayfields['t.'.$key] = array(
119  'label'=>$val['label'],
120  'checked'=>(($visible < 0) ? 0 : 1),
121  'enabled'=>($visible != 3 && dol_eval($val['enabled'], 1, 1, '1')),
122  'position'=>$val['position'],
123  'help'=> isset($val['help']) ? $val['help'] : ''
124  );
125  }
126 }
127 // Extra fields
128 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
129 
130 $object->fields = dol_sort_array($object->fields, 'position');
131 $arrayfields = dol_sort_array($arrayfields, 'position');
132 
133 $permissiontoread = $user->rights->hrm->all->read;
134 $permissiontoadd = $user->rights->hrm->all->write;
135 $permissiontodelete = $user->rights->hrm->all->delete;
136 
137 // Security check
138 if (empty($conf->hrm->enabled)) {
139  accessforbidden('Module not enabled');
140 }
141 
142 // Security check (enable the most restrictive one)
143 if ($user->socid > 0) accessforbidden();
144 //if ($user->socid > 0) accessforbidden();
145 //$socid = 0; if ($user->socid > 0) $socid = $user->socid;
146 //$isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
147 //restrictedArea($user, $object->element, $object->id, $object->table_element, '', 'fk_soc', 'rowid', $isdraft);
148 if (empty($conf->hrm->enabled)) accessforbidden();
149 if (!$permissiontoread) accessforbidden();
150 
151 
152 
153 /*
154  * Actions
155  */
156 
157 if (GETPOST('cancel', 'alpha')) {
158  $action = 'list';
159  $massaction = '';
160 }
161 if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
162  $massaction = '';
163 }
164 
165 $parameters = array();
166 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
167 if ($reshook < 0) {
168  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
169 }
170 
171 if (empty($reshook)) {
172  // Selection of new fields
173  include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
174 
175  // Purge search criteria
176  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
177  foreach ($object->fields as $key => $val) {
178  $search[$key] = '';
179  if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
180  $search[$key.'_dtstart'] = '';
181  $search[$key.'_dtend'] = '';
182  }
183  }
184  $toselect = array();
185  $search_array_options = array();
186  }
187  if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')
188  || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) {
189  $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation
190  }
191 
192  // Mass actions
193  $objectclass = 'Position';
194  $objectlabel = 'Position';
195  $uploaddir = $conf->hrm->dir_output;
196  include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
197 }
198 
199 
200 
201 /*
202  * View
203  */
204 
205 $form = new Form($db);
206 
207 $now = dol_now();
208 
209 //$help_url="EN:Module_Position|FR:Module_Position_FR|ES:Módulo_Position";
210 $help_url = '';
211 $title = $langs->trans('EmployeePositions');
212 $morejs = array();
213 $morecss = array();
214 
215 
216 // Build and execute select
217 // --------------------------------------------------------------------
218 $sql = 'SELECT ';
219 $sql .= $object->getFieldList('t');
220 // Add fields from extrafields
221 if (!empty($extrafields->attributes[$object->table_element]['label'])) {
222  foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
223  $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');
224  }
225 }
226 // Add fields from hooks
227 $parameters = array();
228 $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object); // Note that $action and $object may have been modified by hook
229 $sql .= preg_replace('/^,/', '', $hookmanager->resPrint);
230 $sql = preg_replace('/,\s*$/', '', $sql);
231 $sql .= " FROM ".MAIN_DB_PREFIX.$object->table_element." as t";
232 if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
233  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (t.rowid = ef.fk_object)";
234 }
235 // Add table from hooks
236 $parameters = array();
237 $reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object); // Note that $action and $object may have been modified by hook
238 $sql .= $hookmanager->resPrint;
239 if ($object->ismultientitymanaged == 1) {
240  $sql .= " WHERE t.entity IN (".getEntity($object->element).")";
241 } else {
242  $sql .= " WHERE 1 = 1";
243 }
244 foreach ($search as $key => $val) {
245  if (array_key_exists($key, $object->fields)) {
246  if ($key == 'status' && $search[$key] == -1) {
247  continue;
248  }
249  $mode_search = (($object->isInt($object->fields[$key]) || $object->isFloat($object->fields[$key])) ? 1 : 0);
250  if ((strpos($object->fields[$key]['type'], 'integer:') === 0) || (strpos($object->fields[$key]['type'], 'sellist:') === 0) || !empty($object->fields[$key]['arrayofkeyval'])) {
251  if ($search[$key] == '-1' || $search[$key] === '0') {
252  $search[$key] = '';
253  }
254  $mode_search = 2;
255  }
256  if ($search[$key] != '') {
257  $sql .= natural_search($key, $search[$key], (($key == 'status') ? 2 : $mode_search));
258  }
259  } else {
260  if (preg_match('/(_dtstart|_dtend)$/', $key) && $search[$key] != '') {
261  $columnName=preg_replace('/(_dtstart|_dtend)$/', '', $key);
262  if (preg_match('/^(date|timestamp|datetime)/', $object->fields[$columnName]['type'])) {
263  if (preg_match('/_dtstart$/', $key)) {
264  $sql .= " AND t." . $columnName . " >= '" . $db->idate($search[$key]) . "'";
265  }
266  if (preg_match('/_dtend$/', $key)) {
267  $sql .= " AND t." . $columnName . " <= '" . $db->idate($search[$key]) . "'";
268  }
269  }
270  }
271  }
272 }
273 $vacant = GETPOST('search_fk_uservacant', 'alphanohtml') === 'on';
274 if ($vacant) {
275  $sql .= ' AND t.fk_user = 0';
276 }
277 if ($search_all) {
278  $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
279 }
280 //$sql.= dolSqlDateFilter("t.field", $search_xxxday, $search_xxxmonth, $search_xxxyear);
281 // Add where from extra fields
282 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
283 // Add where from hooks
284 $parameters = array();
285 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object); // Note that $action and $object may have been modified by hook
286 $sql .= $hookmanager->resPrint;
287 
288 /* If a group by is required
289 $sql .= " GROUP BY ";
290 foreach($object->fields as $key => $val) {
291  $sql .= "t.".$key.", ";
292 }
293 // Add fields from extrafields
294 if (!empty($extrafields->attributes[$object->table_element]['label'])) {
295  foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
296  $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? "ef.".$key.', ' : '');
297  }
298 }
299 // Add where from hooks
300 $parameters = array();
301 $reshook = $hookmanager->executeHooks('printFieldListGroupBy', $parameters, $object); // Note that $action and $object may have been modified by hook
302 $sql .= $hookmanager->resPrint;
303 $sql = preg_replace('/,\s*$/', '', $sql);
304 */
305 
306 $sql .= $db->order($sortfield, $sortorder);
307 
308 // Count total nb of records
309 $nbtotalofrecords = '';
310 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
311  $resql = $db->query($sql);
312  $nbtotalofrecords = $db->num_rows($resql);
313  if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0
314  $page = 0;
315  $offset = 0;
316  }
317 }
318 // if total of record found is smaller than limit, no need to do paging and to restart another select with limits set.
319 if (is_numeric($nbtotalofrecords) && ($limit > $nbtotalofrecords || empty($limit))) {
320  $num = $nbtotalofrecords;
321 } else {
322  if ($limit) {
323  $sql .= $db->plimit($limit + 1, $offset);
324  }
325 
326  $resql = $db->query($sql);
327  if (!$resql) {
328  dol_print_error($db);
329  exit;
330  }
331 
332  $num = $db->num_rows($resql);
333 }
334 
335 // Direct jump if only one record found
336 if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $search_all && !$page) {
337  $obj = $db->fetch_object($resql);
338  $id = $obj->rowid;
339  header("Location: ".dol_buildpath('/hrm/position.php', 1).'?id='.$id);
340  exit;
341 }
342 
343 
344 // Output page
345 // --------------------------------------------------------------------
346 
347 llxHeader('', $title, $help_url, '', 0, 0, $morejs, $morecss, '', '');
348 
349 // Example : Adding jquery code
350 // print '<script type="text/javascript" language="javascript">
351 // jQuery(document).ready(function() {
352 // function init_myfunc()
353 // {
354 // jQuery("#myid").removeAttr(\'disabled\');
355 // jQuery("#myid").attr(\'disabled\',\'disabled\');
356 // }
357 // init_myfunc();
358 // jQuery("#mybutton").click(function() {
359 // init_myfunc();
360 // });
361 // });
362 // </script>';
363 
364 $arrayofselected = is_array($toselect) ? $toselect : array();
365 
366 $param = '';
367 if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
368  $param .= '&contextpage='.urlencode($contextpage);
369 }
370 if ($limit > 0 && $limit != $conf->liste_limit) {
371  $param .= '&limit='.urlencode($limit);
372 }
373 
374 foreach ($search as $key => $val) {
375  if (is_array($search[$key]) && count($search[$key])) {
376  foreach ($search[$key] as $skey) {
377  $param .= '&search_'.$key.'[]='.urlencode($skey);
378  }
379  } else {
380  $param .= '&search_'.$key.'='.urlencode($search[$key]);
381  }
382 }
383 if ($optioncss != '') {
384  $param .= '&optioncss='.urlencode($optioncss);
385 }
386 // Add $param from extra fields
387 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
388 // Add $param from hooks
389 $parameters = array();
390 $reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object); // Note that $action and $object may have been modified by hook
391 $param .= $hookmanager->resPrint;
392 
393 // List of mass actions available
394 $arrayofmassactions = array(
395  //'validate'=>img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Validate"),
396  //'generate_doc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"),
397  //'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
398  //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
399 );
400 if ($permissiontodelete) {
401  $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
402 }
403 if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) {
404  $arrayofmassactions = array();
405 }
406 $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
407 
408 print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
409 if ($optioncss != '') {
410  print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
411 }
412 print '<input type="hidden" name="token" value="'.newToken().'">';
413 print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
414 print '<input type="hidden" name="action" value="list">';
415 print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
416 print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
417 print '<input type="hidden" name="page" value="'.$page.'">';
418 print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
419 
420 $newcardbutton = dolGetButtonTitle($langs->trans('New'), '', 'fa fa-plus-circle', dol_buildpath('/hrm/position.php', 1).'?action=create', '', $permissiontoadd);
421 
422 print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'object_'.$object->picto, 0, $newcardbutton, '', $limit, 0, 0, 1);
423 
424 // Add code for pre mass action (confirmation or email presend form)
425 $topicmail = "SendPositionRef";
426 $modelmail = "position";
427 $objecttmp = new Position($db);
428 $trackid = 'xxxx'.$object->id;
429 include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
430 
431 if ($search_all) {
432  foreach ($fieldstosearchall as $key => $val) {
433  $fieldstosearchall[$key] = $langs->trans($val);
434  }
435  print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).join(', ', $fieldstosearchall).'</div>';
436 }
437 
438 $moreforfilter = '';
439 /*$moreforfilter.='<div class="divsearchfield">';
440 $moreforfilter.= $langs->trans('MyFilter') . ': <input type="text" name="search_myfield" value="'.dol_escape_htmltag($search_myfield).'">';
441 $moreforfilter.= '</div>';*/
442 
443 $parameters = array();
444 $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
445 if (empty($reshook)) {
446  $moreforfilter .= $hookmanager->resPrint;
447 } else {
448  $moreforfilter = $hookmanager->resPrint;
449 }
450 
451 if (!empty($moreforfilter)) {
452  print '<div class="liste_titre liste_titre_bydiv centpercent">';
453  print $moreforfilter;
454  print '</div>';
455 }
456 
457 $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
458 $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
459 $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
460 
461 print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
462 print '<table class="tagtable nobottomiftotal liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
463 
464 
465 // Fields title search
466 // --------------------------------------------------------------------
467 print '<tr class="liste_titre">';
468 foreach ($object->fields as $key => $val) {
469  $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
470  if ($key == 'status') {
471  $cssforfield .= ($cssforfield ? ' ' : '').'center';
472  } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
473  $cssforfield .= ($cssforfield ? ' ' : '').'center';
474  } elseif (in_array($val['type'], array('timestamp'))) {
475  $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
476  } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID' && empty($val['arrayofkeyval'])) {
477  $cssforfield .= ($cssforfield ? ' ' : '').'right';
478  }
479  if (!empty($arrayfields['t.'.$key]['checked'])) {
480  print '<td class="liste_titre'.($cssforfield ? ' '.$cssforfield : '').'">';
481  if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
482  print $form->selectarray('search_'.$key, $val['arrayofkeyval'], (isset($search[$key]) ? $search[$key] : ''), $val['notnull'], 0, 0, '', 1, 0, 0, '', 'maxwidth100', 1);
483  } elseif ((strpos($val['type'], 'integer:') === 0) || (strpos($val['type'], 'sellist:') === 0)) {
484  print $object->showInputField($val, $key, (isset($search[$key]) ? $search[$key] : ''), '', '', 'search_', 'maxwidth125', 1);
485  } elseif (!preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
486  print '<input type="text" class="flat maxwidth75" name="search_'.$key.'" value="'.dol_escape_htmltag(isset($search[$key]) ? $search[$key] : '').'">';
487  } elseif (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
488  print '<div class="nowrap">';
489  print $form->selectDate($search[$key.'_dtstart'] ? $search[$key.'_dtstart'] : '', "search_".$key."_dtstart", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
490  print '</div>';
491  print '<div class="nowrap">';
492  print $form->selectDate($search[$key.'_dtend'] ? $search[$key.'_dtend'] : '', "search_".$key."_dtend", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
493  print '</div>';
494  }
495  print '</td>';
496  }
497 }
498 // Extra fields
499 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
500 
501 // Fields from hook
502 $parameters = array('arrayfields'=>$arrayfields);
503 $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object); // Note that $action and $object may have been modified by hook
504 print $hookmanager->resPrint;
505 // Action column
506 print '<td class="liste_titre maxwidthsearch">';
507 $searchpicto = $form->showFilterButtons();
508 print $searchpicto;
509 print '</td>';
510 print '</tr>'."\n";
511 
512 
513 // Fields title label
514 // --------------------------------------------------------------------
515 print '<tr class="liste_titre">';
516 foreach ($object->fields as $key => $val) {
517  $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
518  if ($key == 'status') {
519  $cssforfield .= ($cssforfield ? ' ' : '').'center';
520  } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
521  $cssforfield .= ($cssforfield ? ' ' : '').'center';
522  } elseif (in_array($val['type'], array('timestamp'))) {
523  $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
524  } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID' && empty($val['arrayofkeyval'])) {
525  $cssforfield .= ($cssforfield ? ' ' : '').'right';
526  }
527  if (!empty($arrayfields['t.'.$key]['checked'])) {
528  print getTitleFieldOfList($arrayfields['t.'.$key]['label'], 0, $_SERVER['PHP_SELF'], 't.'.$key, '', $param, ($cssforfield ? 'class="'.$cssforfield.'"' : ''), $sortfield, $sortorder, ($cssforfield ? $cssforfield.' ' : ''))."\n";
529  }
530 }
531 // Extra fields
532 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
533 // Hook fields
534 $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
535 $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
536 print $hookmanager->resPrint;
537 // Action column
538 print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
539 print '</tr>'."\n";
540 
541 
542 // Detect if we need a fetch on each output line
543 $needToFetchEachLine = 0;
544 if (isset($extrafields->attributes[$object->table_element]['computed']) && is_array($extrafields->attributes[$object->table_element]['computed']) && count($extrafields->attributes[$object->table_element]['computed']) > 0) {
545  foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val) {
546  if (preg_match('/\$object/', $val)) {
547  $needToFetchEachLine++; // There is at least one compute field that use $object
548  }
549  }
550 }
551 
552 
553 // Loop on record
554 // --------------------------------------------------------------------
555 $i = 0;
556 $totalarray = array();
557 $totalarray['nbfield'] = 0;
558 while ($i < ($limit ? min($num, $limit) : $num)) {
559  $obj = $db->fetch_object($resql);
560  if (empty($obj)) {
561  break; // Should not happen
562  }
563 
564  // Store properties in $object
565  $object->setVarsFromFetchObj($obj);
566 
567  // Show here line of result
568  print '<tr class="oddeven">';
569  foreach ($object->fields as $key => $val) {
570  $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
571  if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
572  $cssforfield .= ($cssforfield ? ' ' : '').'center';
573  } elseif ($key == 'status') {
574  $cssforfield .= ($cssforfield ? ' ' : '').'center';
575  }
576 
577  if (in_array($val['type'], array('timestamp'))) {
578  $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
579  } elseif ($key == 'ref') {
580  $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
581  }
582 
583  if (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && !in_array($key, array('rowid', 'status')) && empty($val['arrayofkeyval'])) {
584  $cssforfield .= ($cssforfield ? ' ' : '').'right';
585  }
586  //if (in_array($key, array('fk_soc', 'fk_user', 'fk_warehouse'))) $cssforfield = 'tdoverflowmax100';
587 
588  if (!empty($arrayfields['t.'.$key]['checked'])) {
589  print '<td'.($cssforfield ? ' class="'.$cssforfield.'"' : '').'>';
590  if ($key == 'status') {
591  print $object->getLibStatut(5);
592  } elseif ($key == 'rowid') {
593  print $object->getNomUrl(1);
594  } else {
595  print $object->showOutputField($val, $key, $object->$key, '');
596  }
597  print '</td>';
598  if (!$i) {
599  $totalarray['nbfield']++;
600  }
601  if (!empty($val['isameasure']) && $val['isameasure'] == 1) {
602  if (!$i) {
603  $totalarray['pos'][$totalarray['nbfield']] = 't.'.$key;
604  }
605  if (!isset($totalarray['val'])) {
606  $totalarray['val'] = array();
607  }
608  if (!isset($totalarray['val']['t.'.$key])) {
609  $totalarray['val']['t.'.$key] = 0;
610  }
611  $totalarray['val']['t.'.$key] += $object->$key;
612  }
613  }
614  }
615  // Extra fields
616  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
617  // Fields from hook
618  $parameters = array('arrayfields'=>$arrayfields, 'object'=>$object, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
619  $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object); // Note that $action and $object may have been modified by hook
620  print $hookmanager->resPrint;
621  // Action 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  if (!$i) {
632  $totalarray['nbfield']++;
633  }
634 
635  print '</tr>'."\n";
636 
637  $i++;
638 }
639 
640 // Show total line
641 include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
642 
643 // If no record found
644 if ($num == 0) {
645  $colspan = 1;
646  foreach ($arrayfields as $key => $val) {
647  if (!empty($val['checked'])) {
648  $colspan++;
649  }
650  }
651  print '<tr><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoRecordFound").'</td></tr>';
652 }
653 
654 
655 $db->free($resql);
656 
657 $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
658 $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object); // Note that $action and $object may have been modified by hook
659 print $hookmanager->resPrint;
660 
661 print '</table>'."\n";
662 print '</div>'."\n";
663 
664 print '</form>'."\n";
665 
666 if (in_array('builddoc', $arrayofmassactions) && ($nbtotalofrecords === '' || $nbtotalofrecords)) {
667  $hidegeneratedfilelistifempty = 1;
668  if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
669  $hidegeneratedfilelistifempty = 0;
670  }
671 
672  require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
673  $formfile = new FormFile($db);
674 
675  // Show list of available documents
676  $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
677  $urlsource .= str_replace('&amp;', '&', $param);
678 
679  $filedir = $diroutputmassaction;
680  $genallowed = $permissiontoread;
681  $delallowed = $permissiontoadd;
682 
683  print $formfile->showdocuments('massfilesarea_hrm', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
684 }
685 
686 // End of page
687 llxFooter();
688 $db->close();
dol_escape_htmltag
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
Definition: functions.lib.php:1468
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
getTitleFieldOfList
getTitleFieldOfList($name, $thead=0, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $disablesortlink=0, $tooltip='', $forcenowrapcolumntitle=0)
Get title line of an array.
Definition: functions.lib.php:5049
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4844
dol_sort_array
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by second index function, which produces ascending (default) or descending output...
Definition: functions.lib.php:8385
dol_buildpath
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
Definition: functions.lib.php:1062
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
$help_url
if(GETPOST('button_removefilter_x', 'alpha')||GETPOST('button_removefilter.x', 'alpha')||GETPOST('button_removefilter', 'alpha')) if(GETPOST('button_search_x', 'alpha')||GETPOST('button_search.x', 'alpha')||GETPOST('button_search', 'alpha')) if($action=="save" &&empty($cancel)) $help_url
View.
Definition: agenda.php:116
img_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:3880
FormFile
Class to offer components to list and upload files.
Definition: html.formfile.class.php:36
Position
Class for Position.
Definition: position.class.php:36
dolGetButtonTitle
dolGetButtonTitle($label, $helpText='', $iconClass='fa fa-file', $url='', $id='', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
Definition: functions.lib.php:10605
print_barre_liste
print_barre_liste($titre, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $hideselectlimit=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
Definition: functions.lib.php:5257
GETPOSTISSET
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
Definition: functions.lib.php:386
natural_search
natural_search($fields, $value, $mode=0, $nofirstand=0)
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
Definition: functions.lib.php:9420
dol_eval
dol_eval($s, $returnvalue=0, $hideerrors=1, $onlysimplestring='1')
Replace eval function to add more security.
Definition: functions.lib.php:8611
ExtraFields
Class to manage standard extra fields.
Definition: extrafields.class.php:39
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
dol_now
dol_now($mode='auto')
Return date for now.
Definition: functions.lib.php:2845
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice') && $user->rights->supplier_invoice->lire)) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:742
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8137
accessforbidden
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Definition: security.lib.php:933
dol_mktime
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
Definition: functions.lib.php:2757
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59