dolibarr  19.0.0-dev
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 $mode = GETPOST('mode', 'alpha'); // for view result with other mode
56 
57 $id = GETPOST('id', 'int');
58 
59 // Load variable for pagination
60 $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
61 $sortfield = GETPOST('sortfield', 'aZ09comma');
62 $sortorder = GETPOST('sortorder', 'aZ09comma');
63 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
64 if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
65  // If $page is not defined, or '' or -1 or if we click on clear filters
66  $page = 0;
67 }
68 $offset = $limit * $page;
69 $pageprev = $page - 1;
70 $pagenext = $page + 1;
71 
72 // Initialize technical objects
73 $object = new Job($db);
74 $extrafields = new ExtraFields($db);
75 $diroutputmassaction = $conf->hrm->dir_output.'/temp/massgeneration/'.$user->id;
76 $hookmanager->initHooks(array('joblist')); // Note that conf->hooks_modules contains array
77 
78 // Fetch optionals attributes and labels
79 $extrafields->fetch_name_optionals_label($object->table_element);
80 //$extrafields->fetch_name_optionals_label($object->table_element_line);
81 
82 $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
83 
84 // Default sort order (if not yet defined by previous GETPOST)
85 if (!$sortfield) {
86  reset($object->fields); // Reset is required to avoid key() to return null.
87  $sortfield = "t.".key($object->fields); // Set here default search field. By default 1st field in definition.
88 }
89 if (!$sortorder) {
90  $sortorder = "ASC";
91 }
92 
93 // Initialize array of search criterias
94 $search_all = GETPOST('search_all', 'alphanohtml') ? GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml');
95 $search = array();
96 foreach ($object->fields as $key => $val) {
97  if (GETPOST('search_'.$key, 'alpha') !== '') {
98  $search[$key] = GETPOST('search_'.$key, 'alpha');
99  }
100  if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
101  $search[$key.'_dtstart'] = dol_mktime(0, 0, 0, GETPOST('search_'.$key.'_dtstartmonth', 'int'), GETPOST('search_'.$key.'_dtstartday', 'int'), GETPOST('search_'.$key.'_dtstartyear', 'int'));
102  $search[$key.'_dtend'] = dol_mktime(23, 59, 59, GETPOST('search_'.$key.'_dtendmonth', 'int'), GETPOST('search_'.$key.'_dtendday', 'int'), GETPOST('search_'.$key.'_dtendyear', 'int'));
103  }
104 }
105 
106 // List of fields to search into when doing a "search in all"
107 $fieldstosearchall = array();
108 foreach ($object->fields as $key => $val) {
109  if (!empty($val['searchall'])) {
110  $fieldstosearchall['t.'.$key] = $val['label'];
111  }
112 }
113 
114 // Definition of array of fields for columns
115 $arrayfields = array();
116 foreach ($object->fields as $key => $val) {
117  // If $val['visible']==0, then we never show the field
118  if (!empty($val['visible'])) {
119  $visible = (int) dol_eval($val['visible'], 1);
120  $arrayfields['t.'.$key] = array(
121  'label'=>$val['label'],
122  'checked'=>(($visible < 0) ? 0 : 1),
123  'enabled'=>(abs($visible) != 3 && dol_eval($val['enabled'], 1)),
124  'position'=>$val['position'],
125  'help'=> isset($val['help']) ? $val['help'] : ''
126  );
127  }
128 }
129 // Extra fields
130 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
131 
132 $object->fields = dol_sort_array($object->fields, 'position');
133 $arrayfields = dol_sort_array($arrayfields, 'position');
134 
135 // Permissions
136 $permissiontoread = $user->rights->hrm->all->read;
137 $permissiontoadd = $user->rights->hrm->all->write;
138 $permissiontodelete = $user->rights->hrm->all->delete;
139 
140 // Security check (enable the most restrictive one)
141 if ($user->socid > 0) accessforbidden();
142 //if ($user->socid > 0) accessforbidden();
143 //$socid = 0; if ($user->socid > 0) $socid = $user->socid;
144 //$isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
145 //restrictedArea($user, $object->element, $object->id, $object->table_element, '', 'fk_soc', 'rowid', $isdraft);
146 if (!isModEnabled('hrm')) {
147  accessforbidden('Module hrm not enabled');
148 }
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 = 'Job';
194  $objectlabel = 'Job';
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_Job|FR:Module_Job_FR|ES:Módulo_Job";
210 $help_url = '';
211 $title = $langs->trans("JobsProfiles");
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 .= $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' && (empty($object->fields[$key]['arrayofkeyval']) || !array_key_exists('0', $object->fields[$key]['arrayofkeyval'])))) {
252  $search[$key] = '';
253  }
254  $mode_search = 2;
255  }
256  if ($search[$key] != '') {
257  $sql .= natural_search("t.".$db->escape($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.".$db->escape($columnName)." >= '".$db->idate($search[$key])."'";
265  }
266  if (preg_match('/_dtend$/', $key)) {
267  $sql .= " AND t.".$db->escape($columnName)." <= '".$db->idate($search[$key])."'";
268  }
269  }
270  }
271  }
272 }
273 if ($search_all) {
274  $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
275 }
276 //$sql.= dolSqlDateFilter("t.field", $search_xxxday, $search_xxxmonth, $search_xxxyear);
277 // Add where from extra fields
278 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
279 // Add where from hooks
280 $parameters = array();
281 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object); // Note that $action and $object may have been modified by hook
282 $sql .= $hookmanager->resPrint;
283 
284 /* If a group by is required
285 $sql .= " GROUP BY ";
286 foreach($object->fields as $key => $val) {
287  $sql .= "t.".$db->escape($key).", ";
288 }
289 // Add fields from extrafields
290 if (!empty($extrafields->attributes[$object->table_element]['label'])) {
291  foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
292  $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? "ef.".$key.', ' : '');
293  }
294 }
295 // Add where from hooks
296 $parameters = array();
297 $reshook = $hookmanager->executeHooks('printFieldListGroupBy', $parameters, $object); // Note that $action and $object may have been modified by hook
298 $sql .= $hookmanager->resPrint;
299 $sql = preg_replace('/,\s*$/', '', $sql);
300 */
301 
302 // Count total nb of records
303 $nbtotalofrecords = '';
304 if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
305  $resql = $db->query($sql);
306  $nbtotalofrecords = $db->num_rows($resql);
307  if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0
308  $page = 0;
309  $offset = 0;
310  }
311  $db->free($resql);
312 }
313 
314 // Complete request and execute it with limit
315 $sql .= $db->order($sortfield, $sortorder);
316 if ($limit) {
317  $sql .= $db->plimit($limit + 1, $offset);
318 }
319 
320 $resql = $db->query($sql);
321 if (!$resql) {
322  dol_print_error($db);
323  exit;
324 }
325 
326 $num = $db->num_rows($resql);
327 
328 
329 // Direct jump if only one record found
330 if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $search_all && !$page) {
331  $obj = $db->fetch_object($resql);
332  $id = $obj->rowid;
333  header("Location: ".dol_buildpath('/hrm/job_card.php', 1).'?id='.$id);
334  exit;
335 }
336 
337 
338 // Output page
339 // --------------------------------------------------------------------
340 
341 llxHeader('', $title, $help_url, '', 0, 0, $morejs, $morecss, '', '');
342 
343 // Example : Adding jquery code
344 // print '<script type="text/javascript" language="javascript">
345 // jQuery(document).ready(function() {
346 // function init_myfunc()
347 // {
348 // jQuery("#myid").removeAttr(\'disabled\');
349 // jQuery("#myid").attr(\'disabled\',\'disabled\');
350 // }
351 // init_myfunc();
352 // jQuery("#mybutton").click(function() {
353 // init_myfunc();
354 // });
355 // });
356 // </script>';
357 
358 $arrayofselected = is_array($toselect) ? $toselect : array();
359 
360 $param = '';
361 if (!empty($mode)) {
362  $param .= '&mode='.urlencode($mode);
363 }
364 if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
365  $param .= '&contextpage='.urlencode($contextpage);
366 }
367 if ($limit > 0 && $limit != $conf->liste_limit) {
368  $param .= '&limit='.((int) $limit);
369 }
370 foreach ($search as $key => $val) {
371  if (is_array($search[$key])) {
372  foreach ($search[$key] as $skey) {
373  if ($skey != '') {
374  $param .= '&search_'.$key.'[]='.urlencode($skey);
375  }
376  }
377  } elseif (preg_match('/(_dtstart|_dtend)$/', $key) && !empty($val)) {
378  $param .= '&search_'.$key.'month='.((int) GETPOST('search_'.$key.'month', 'int'));
379  $param .= '&search_'.$key.'day='.((int) GETPOST('search_'.$key.'day', 'int'));
380  $param .= '&search_'.$key.'year='.((int) GETPOST('search_'.$key.'year', 'int'));
381  } elseif ($search[$key] != '') {
382  $param .= '&search_'.$key.'='.urlencode($search[$key]);
383  }
384 }
385 if ($optioncss != '') {
386  $param .= '&optioncss='.urlencode($optioncss);
387 }
388 // Add $param from extra fields
389 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
390 // Add $param from hooks
391 $parameters = array();
392 $reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object); // Note that $action and $object may have been modified by hook
393 $param .= $hookmanager->resPrint;
394 
395 // List of mass actions available
396 $arrayofmassactions = array(
397  //'validate'=>img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Validate"),
398  //'generate_doc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"),
399  //'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
400  //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
401 );
402 if (!empty($permissiontodelete)) {
403  $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
404 }
405 if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) {
406  $arrayofmassactions = array();
407 }
408 $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
409 
410 print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
411 if ($optioncss != '') {
412  print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
413 }
414 print '<input type="hidden" name="token" value="'.newToken().'">';
415 print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
416 print '<input type="hidden" name="action" value="list">';
417 print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
418 print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
419 print '<input type="hidden" name="page" value="'.$page.'">';
420 print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
421 print '<input type="hidden" name="mode" value="'.$mode.'">';
422 
423 
424 $newcardbutton = '';
425 $newcardbutton .= dolGetButtonTitle($langs->trans('ViewList'), '', 'fa fa-bars imgforviewmode', $_SERVER["PHP_SELF"].'?mode=common'.preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', ((empty($mode) || $mode == 'common') ? 2 : 1), array('morecss'=>'reposition'));
426 $newcardbutton .= dolGetButtonTitle($langs->trans('ViewKanban'), '', 'fa fa-th-list imgforviewmode', $_SERVER["PHP_SELF"].'?mode=kanban'.preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', ($mode == 'kanban' ? 2 : 1), array('morecss'=>'reposition'));
427 $newcardbutton .= dolGetButtonTitle($langs->trans('New'), '', 'fa fa-plus-circle', dol_buildpath('/hrm/job_card.php', 1).'?action=create', '', $permissiontoadd);
428 
429 print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'object_'.$object->picto, 0, $newcardbutton, '', $limit, 0, 0, 1);
430 
431 // Add code for pre mass action (confirmation or email presend form)
432 $topicmail = "SendJobRef";
433 $modelmail = "job";
434 $objecttmp = new Job($db);
435 $trackid = 'xxxx'.$object->id;
436 include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
437 
438 if ($search_all) {
439  $setupstring = '';
440  foreach ($fieldstosearchall as $key => $val) {
441  $fieldstosearchall[$key] = $langs->trans($val);
442  $setupstring .= $key."=".$val.";";
443  }
444  print '<!-- Search done like if JOBPOSITION_QUICKSEARCH_ON_FIELDS = '.$setupstring.' -->'."\n";
445  print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).join(', ', $fieldstosearchall).'</div>';
446 }
447 
448 $moreforfilter = '';
449 /*$moreforfilter.='<div class="divsearchfield">';
450 $moreforfilter.= $langs->trans('MyFilter') . ': <input type="text" name="search_myfield" value="'.dol_escape_htmltag($search_myfield).'">';
451 $moreforfilter.= '</div>';*/
452 
453 $parameters = array();
454 $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
455 if (empty($reshook)) {
456  $moreforfilter .= $hookmanager->resPrint;
457 } else {
458  $moreforfilter = $hookmanager->resPrint;
459 }
460 
461 if (!empty($moreforfilter)) {
462  print '<div class="liste_titre liste_titre_bydiv centpercent">';
463  print $moreforfilter;
464  print '</div>';
465 }
466 
467 $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
468 $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN', '')); // This also change content of $arrayfields
469 $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
470 
471 print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
472 print '<table class="tagtable nobottomiftotal liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
473 
474 
475 // Fields title search
476 // --------------------------------------------------------------------
477 print '<tr class="liste_titre">';
478 // Action column
479 if (!empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
480  print '<td class="liste_titre maxwidthsearch">';
481  $searchpicto = $form->showFilterButtons('left');
482  print $searchpicto;
483  print '</td>';
484 }
485 foreach ($object->fields as $key => $val) {
486  $searchkey = empty($search[$key]) ? '' : $search[$key];
487  $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
488  if ($key == 'status') {
489  $cssforfield .= ($cssforfield ? ' ' : '').'center';
490  } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
491  $cssforfield .= ($cssforfield ? ' ' : '').'center';
492  } elseif (in_array($val['type'], array('timestamp'))) {
493  $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
494  } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && !in_array($key, array('id', 'rowid', 'ref', 'status')) && $val['label'] != 'TechnicalID' && empty($val['arrayofkeyval'])) {
495  $cssforfield .= ($cssforfield ? ' ' : '').'right';
496  }
497  if (!empty($arrayfields['t.'.$key]['checked'])) {
498  print '<td class="liste_titre'.($cssforfield ? ' '.$cssforfield : '').'">';
499  if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
500  print $form->selectarray('search_'.$key, $val['arrayofkeyval'], (isset($search[$key]) ? $search[$key] : ''), $val['notnull'], 0, 0, '', 1, 0, 0, '', 'maxwidth100', 1);
501  } elseif ((strpos($val['type'], 'integer:') === 0) || (strpos($val['type'], 'sellist:') === 0)) {
502  print $object->showInputField($val, $key, (isset($search[$key]) ? $search[$key] : ''), '', '', 'search_', $cssforfield.' maxwidth125', 1);
503  } elseif (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
504  print '<div class="nowrap">';
505  print $form->selectDate($search[$key.'_dtstart'] ? $search[$key.'_dtstart'] : '', "search_".$key."_dtstart", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
506  print '</div>';
507  print '<div class="nowrap">';
508  print $form->selectDate($search[$key.'_dtend'] ? $search[$key.'_dtend'] : '', "search_".$key."_dtend", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
509  print '</div>';
510  } elseif ($key == 'lang') {
511  require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
512  $formadmin = new FormAdmin($db);
513  print $formadmin->select_language($search[$key], 'search_lang', 0, null, 1, 0, 0, 'minwidth150 maxwidth200', 2);
514  } else {
515  print '<input type="text" class="flat maxwidth75" name="search_'.$key.'" value="'.dol_escape_htmltag(isset($search[$key]) ? $search[$key] : '').'">';
516  }
517  print '</td>';
518  }
519 }
520 // Extra fields
521 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
522 
523 // Fields from hook
524 $parameters = array('arrayfields'=>$arrayfields);
525 $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object); // Note that $action and $object may have been modified by hook
526 print $hookmanager->resPrint;
527 // Action column
528 if (empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
529  print '<td class="liste_titre maxwidthsearch">';
530  $searchpicto = $form->showFilterButtons();
531  print $searchpicto;
532  print '</td>';
533 }
534 print '</tr>'."\n";
535 
536 $totalarray = array();
537 $totalarray['nbfield'] = 0;
538 
539 // Fields title label
540 // --------------------------------------------------------------------
541 print '<tr class="liste_titre">';
542 if (!empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
543  print getTitleFieldOfList(($mode != 'kanban' ? $selectedfields : ''), 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
544 }
545 foreach ($object->fields as $key => $val) {
546  $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
547  if ($key == 'status') {
548  $cssforfield .= ($cssforfield ? ' ' : '').'center';
549  } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
550  $cssforfield .= ($cssforfield ? ' ' : '').'center';
551  } elseif (in_array($val['type'], array('timestamp'))) {
552  $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
553  } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && !in_array($key, array('id', 'rowid', 'ref', 'status')) && $val['label'] != 'TechnicalID' && empty($val['arrayofkeyval'])) {
554  $cssforfield .= ($cssforfield ? ' ' : '').'right';
555  }
556  $cssforfield = preg_replace('/small\s*/', '', $cssforfield); // the 'small' css must not be used for the title label
557  if (!empty($arrayfields['t.'.$key]['checked'])) {
558  print getTitleFieldOfList($arrayfields['t.'.$key]['label'], 0, $_SERVER['PHP_SELF'], 't.'.$key, '', $param, ($cssforfield ? 'class="'.$cssforfield.'"' : ''), $sortfield, $sortorder, ($cssforfield ? $cssforfield.' ' : ''))."\n";
559  $totalarray['nbfield']++;
560  }
561 }
562 // Extra fields
563 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
564 // Hook fields
565 $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder, 'totalarray'=>&$totalarray);
566 $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
567 print $hookmanager->resPrint;
568 // Action column
569 if (empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
570  print getTitleFieldOfList(($mode != 'kanban' ? $selectedfields : ''), 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
571 }
572 $totalarray['nbfield']++;
573 print '</tr>'."\n";
574 
575 
576 // Detect if we need a fetch on each output line
577 $needToFetchEachLine = 0;
578 if (isset($extrafields->attributes[$object->table_element]['computed']) && is_array($extrafields->attributes[$object->table_element]['computed']) && count($extrafields->attributes[$object->table_element]['computed']) > 0) {
579  foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val) {
580  if (!is_null($val) && preg_match('/\$object/', $val)) {
581  $needToFetchEachLine++; // There is at least one compute field that use $object
582  }
583  }
584 }
585 
586 
587 // Loop on record
588 // --------------------------------------------------------------------
589 $i = 0;
590 $savnbfield = $totalarray['nbfield'];
591 $totalarray = array();
592 $totalarray['nbfield'] = 0;
593 $imaxinloop = ($limit ? min($num, $limit) : $num);
594 while ($i < $imaxinloop) {
595  $obj = $db->fetch_object($resql);
596  if (empty($obj)) {
597  break; // Should not happen
598  }
599 
600  // Store properties in $object
601  $object->setVarsFromFetchObj($obj);
602 
603  if ($mode == 'kanban') {
604  $object->deplacement = $obj->deplacement;
605  $object->description = $obj->description;
606 
607  if ($i == 0) {
608  print '<tr class="trkanban"><td colspan="'.$savnbfield.'">';
609  print '<div class="box-flex-container kanban">';
610  }
611  // Output Kanban
612  print $object->getKanbanView('', array('selected' => in_array($object->id, $arrayofselected)));
613  if ($i == ($imaxinloop - 1)) {
614  print '</div>';
615  print '</td></tr>';
616  }
617  } else {
618  // Show here line of result
619  $j = 0;
620  print '<tr data-rowid="'.$object->id.'" class="oddeven">';
621  // Action column
622  if (!empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
623  print '<td class="nowrap center">';
624  if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
625  $selected = 0;
626  if (in_array($object->id, $arrayofselected)) {
627  $selected = 1;
628  }
629  print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
630  }
631  print '</td>';
632  }
633  foreach ($object->fields as $key => $val) {
634  $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
635  if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
636  $cssforfield .= ($cssforfield ? ' ' : '').'center';
637  } elseif ($key == 'status') {
638  $cssforfield .= ($cssforfield ? ' ' : '').'center';
639  }
640 
641  if (in_array($val['type'], array('timestamp'))) {
642  $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
643  } elseif ($key == 'ref') {
644  $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
645  }
646 
647  if (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && !in_array($key, array('rowid', 'status')) && empty($val['arrayofkeyval'])) {
648  $cssforfield .= ($cssforfield ? ' ' : '').'right';
649  }
650  //if (in_array($key, array('fk_soc', 'fk_user', 'fk_warehouse'))) $cssforfield = 'tdoverflowmax100';
651 
652  if (!empty($arrayfields['t.'.$key]['checked'])) {
653  print '<td'.($cssforfield ? ' class="'.$cssforfield.(preg_match('/tdoverflow/', $cssforfield) ? ' classfortooltip' : '').'"' : '');
654  if (preg_match('/tdoverflow/', $cssforfield) && !is_numeric($object->$key)) {
655  print ' title="'.dol_escape_htmltag($object->$key).'"';
656  }
657  print '>';
658  if ($key == 'status') {
659  print $object->getLibStatut(5);
660  } elseif ($key == 'rowid') {
661  print $object->showOutputField($val, $key, $object->id, '');
662  } elseif ($key == 'label') {
663  print $object->getNomUrl(1);
664  } else {
665  print $object->showOutputField($val, $key, $object->$key, '');
666  }
667  print '</td>';
668  if (!$i) {
669  $totalarray['nbfield']++;
670  }
671  if (!empty($val['isameasure']) && $val['isameasure'] == 1) {
672  if (!$i) {
673  $totalarray['pos'][$totalarray['nbfield']] = 't.'.$key;
674  }
675  if (!isset($totalarray['val'])) {
676  $totalarray['val'] = array();
677  }
678  if (!isset($totalarray['val']['t.'.$key])) {
679  $totalarray['val']['t.'.$key] = 0;
680  }
681  $totalarray['val']['t.'.$key] += $object->$key;
682  }
683  }
684  }
685  // Extra fields
686  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
687  // Fields from hook
688  $parameters = array('arrayfields'=>$arrayfields, 'object'=>$object, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
689  $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object); // Note that $action and $object may have been modified by hook
690  print $hookmanager->resPrint;
691  // Action column
692  if (empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
693  print '<td class="nowrap center">';
694  if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
695  $selected = 0;
696  if (in_array($object->id, $arrayofselected)) {
697  $selected = 1;
698  }
699  print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
700  }
701  print '</td>';
702  }
703  if (!$i) {
704  $totalarray['nbfield']++;
705  }
706 
707  print '</tr>'."\n";
708  }
709 
710  $i++;
711 }
712 
713 // Show total line
714 include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
715 
716 // If no record found
717 if ($num == 0) {
718  $colspan = 1;
719  foreach ($arrayfields as $key => $val) {
720  if (!empty($val['checked'])) {
721  $colspan++;
722  }
723  }
724  print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
725 }
726 
727 
728 $db->free($resql);
729 
730 $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
731 $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
732 print $hookmanager->resPrint;
733 
734 print '</table>'."\n";
735 print '</div>'."\n";
736 
737 print '</form>'."\n";
738 
739 if (in_array('builddoc', $arrayofmassactions) && ($nbtotalofrecords === '' || $nbtotalofrecords)) {
740  $hidegeneratedfilelistifempty = 1;
741  if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
742  $hidegeneratedfilelistifempty = 0;
743  }
744 
745  require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
746  $formfile = new FormFile($db);
747 
748  // Show list of available documents
749  $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
750  $urlsource .= str_replace('&amp;', '&', $param);
751 
752  $filedir = $diroutputmassaction;
753  $genallowed = $permissiontoread;
754  $delallowed = $permissiontoadd;
755 
756  print $formfile->showdocuments('massfilesarea_hrm', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
757 }
758 
759 // End of page
760 llxFooter();
761 $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') && $user->hasRight('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') && $user->hasRight('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)) $sql
Social contributions to pay.
Definition: index.php:746
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_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dolGetButtonTitle($label, $helpText='', $iconClass='fa fa-file', $url='', $id='', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
natural_search($fields, $value, $mode=0, $nofirstand=0)
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by second index function, which produces ascending (default) or descending output...
dol_eval($s, $returnvalue=0, $hideerrors=1, $onlysimplestring='1')
Replace eval function to add more security.
getTitleFieldOfList($name, $thead=0, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $disablesortlink=0, $tooltip='', $forcenowrapcolumntitle=0)
Get title line of an array.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
print_barre_liste($titre, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $hideselectlimit=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.