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