dolibarr 19.0.3
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
30require '../main.inc.php';
31
32require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
33require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
34require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
35
36// load hrm libraries
37require_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');
64if (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)
85if (!$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}
89if (!$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();
96foreach ($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();
108foreach ($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();
116foreach ($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
130include 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->hasRight('hrm', 'all', 'read');
137$permissiontoadd = $user->hasRight('hrm', 'all', 'write');
138$permissiontodelete = $user->hasRight('hrm', 'all', 'delete');
139
140// Security check (enable the most restrictive one)
141if ($user->socid > 0) {
143}
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);
148if (!isModEnabled('hrm')) {
149 accessforbidden('Module hrm not enabled');
150}
151if (!$permissiontoread) {
153}
154
155
156
157/*
158 * Actions
159 */
160
161if (GETPOST('cancel', 'alpha')) {
162 $action = 'list';
163 $massaction = '';
164}
165if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
166 $massaction = '';
167}
168
169$parameters = array();
170$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
171if ($reshook < 0) {
172 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
173}
174
175if (empty($reshook)) {
176 // Selection of new fields
177 include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
178
179 // Purge search criteria
180 if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers
181 foreach ($object->fields as $key => $val) {
182 $search[$key] = '';
183 if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
184 $search[$key.'_dtstart'] = '';
185 $search[$key.'_dtend'] = '';
186 }
187 }
188 $toselect = array();
189 $search_array_options = array();
190 }
191 if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')
192 || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) {
193 $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation
194 }
195
196 // Mass actions
197 $objectclass = 'Job';
198 $objectlabel = 'Job';
199 $uploaddir = $conf->hrm->dir_output;
200 include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
201}
202
203
204
205/*
206 * View
207 */
208
209$form = new Form($db);
210
211$now = dol_now();
212
213//$help_url="EN:Module_Job|FR:Module_Job_FR|ES:Módulo_Job";
214$help_url = '';
215$title = $langs->trans("JobsProfiles");
216$morejs = array();
217$morecss = array();
218
219
220// Build and execute select
221// --------------------------------------------------------------------
222$sql = 'SELECT ';
223$sql .= $object->getFieldList('t');
224// Add fields from extrafields
225if (!empty($extrafields->attributes[$object->table_element]['label'])) {
226 foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
227 $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');
228 }
229}
230// Add fields from hooks
231$parameters = array();
232$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object); // Note that $action and $object may have been modified by hook
233$sql .= $hookmanager->resPrint;
234$sql = preg_replace('/,\s*$/', '', $sql);
235$sql .= " FROM ".MAIN_DB_PREFIX.$object->table_element." as t";
236if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
237 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (t.rowid = ef.fk_object)";
238}
239// Add table from hooks
240$parameters = array();
241$reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object); // Note that $action and $object may have been modified by hook
242$sql .= $hookmanager->resPrint;
243if ($object->ismultientitymanaged == 1) {
244 $sql .= " WHERE t.entity IN (".getEntity($object->element).")";
245} else {
246 $sql .= " WHERE 1 = 1";
247}
248foreach ($search as $key => $val) {
249 if (array_key_exists($key, $object->fields)) {
250 if ($key == 'status' && $search[$key] == -1) {
251 continue;
252 }
253 $mode_search = (($object->isInt($object->fields[$key]) || $object->isFloat($object->fields[$key])) ? 1 : 0);
254 if ((strpos($object->fields[$key]['type'], 'integer:') === 0) || (strpos($object->fields[$key]['type'], 'sellist:') === 0) || !empty($object->fields[$key]['arrayofkeyval'])) {
255 if ($search[$key] == '-1' || ($search[$key] === '0' && (empty($object->fields[$key]['arrayofkeyval']) || !array_key_exists('0', $object->fields[$key]['arrayofkeyval'])))) {
256 $search[$key] = '';
257 }
258 $mode_search = 2;
259 }
260 if ($search[$key] != '') {
261 $sql .= natural_search("t.".$db->escape($key), $search[$key], (($key == 'status') ? 2 : $mode_search));
262 }
263 } else {
264 if (preg_match('/(_dtstart|_dtend)$/', $key) && $search[$key] != '') {
265 $columnName=preg_replace('/(_dtstart|_dtend)$/', '', $key);
266 if (preg_match('/^(date|timestamp|datetime)/', $object->fields[$columnName]['type'])) {
267 if (preg_match('/_dtstart$/', $key)) {
268 $sql .= " AND t.".$db->escape($columnName)." >= '".$db->idate($search[$key])."'";
269 }
270 if (preg_match('/_dtend$/', $key)) {
271 $sql .= " AND t.".$db->escape($columnName)." <= '".$db->idate($search[$key])."'";
272 }
273 }
274 }
275 }
276}
277if ($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
282include 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 ";
290foreach($object->fields as $key => $val) {
291 $sql .= "t.".$db->escape($key).", ";
292}
293// Add fields from extrafields
294if (!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// Count total nb of records
307$nbtotalofrecords = '';
308if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
309 $resql = $db->query($sql);
310 $nbtotalofrecords = $db->num_rows($resql);
311 if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0
312 $page = 0;
313 $offset = 0;
314 }
315 $db->free($resql);
316}
317
318// Complete request and execute it with limit
319$sql .= $db->order($sortfield, $sortorder);
320if ($limit) {
321 $sql .= $db->plimit($limit + 1, $offset);
322}
323
324$resql = $db->query($sql);
325if (!$resql) {
326 dol_print_error($db);
327 exit;
328}
329
330$num = $db->num_rows($resql);
331
332
333// Direct jump if only one record found
334if ($num == 1 && getDolGlobalString('MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE') && $search_all && !$page) {
335 $obj = $db->fetch_object($resql);
336 $id = $obj->rowid;
337 header("Location: ".dol_buildpath('/hrm/job_card.php', 1).'?id='.$id);
338 exit;
339}
340
341
342// Output page
343// --------------------------------------------------------------------
344
345llxHeader('', $title, $help_url, '', 0, 0, $morejs, $morecss, '', '');
346
347// Example : Adding jquery code
348// print '<script type="text/javascript" language="javascript">
349// jQuery(document).ready(function() {
350// function init_myfunc()
351// {
352// jQuery("#myid").removeAttr(\'disabled\');
353// jQuery("#myid").attr(\'disabled\',\'disabled\');
354// }
355// init_myfunc();
356// jQuery("#mybutton").click(function() {
357// init_myfunc();
358// });
359// });
360// </script>';
361
362$arrayofselected = is_array($toselect) ? $toselect : array();
363
364$param = '';
365if (!empty($mode)) {
366 $param .= '&mode='.urlencode($mode);
367}
368if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
369 $param .= '&contextpage='.urlencode($contextpage);
370}
371if ($limit > 0 && $limit != $conf->liste_limit) {
372 $param .= '&limit='.((int) $limit);
373}
374foreach ($search as $key => $val) {
375 if (is_array($search[$key])) {
376 foreach ($search[$key] as $skey) {
377 if ($skey != '') {
378 $param .= '&search_'.$key.'[]='.urlencode($skey);
379 }
380 }
381 } elseif (preg_match('/(_dtstart|_dtend)$/', $key) && !empty($val)) {
382 $param .= '&search_'.$key.'month='.((int) GETPOST('search_'.$key.'month', 'int'));
383 $param .= '&search_'.$key.'day='.((int) GETPOST('search_'.$key.'day', 'int'));
384 $param .= '&search_'.$key.'year='.((int) GETPOST('search_'.$key.'year', 'int'));
385 } elseif ($search[$key] != '') {
386 $param .= '&search_'.$key.'='.urlencode($search[$key]);
387 }
388}
389if ($optioncss != '') {
390 $param .= '&optioncss='.urlencode($optioncss);
391}
392// Add $param from extra fields
393include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
394// Add $param from hooks
395$parameters = array('param' => &$param);
396$reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object); // Note that $action and $object may have been modified by hook
397$param .= $hookmanager->resPrint;
398
399// List of mass actions available
400$arrayofmassactions = array(
401 //'validate'=>img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Validate"),
402 //'generate_doc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"),
403 //'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
404 //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
405);
406if (!empty($permissiontodelete)) {
407 $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
408}
409if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) {
410 $arrayofmassactions = array();
411}
412$massactionbutton = $form->selectMassAction('', $arrayofmassactions);
413
414print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
415if ($optioncss != '') {
416 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
417}
418print '<input type="hidden" name="token" value="'.newToken().'">';
419print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
420print '<input type="hidden" name="action" value="list">';
421print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
422print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
423print '<input type="hidden" name="page" value="'.$page.'">';
424print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
425print '<input type="hidden" name="mode" value="'.$mode.'">';
426
427
428$newcardbutton = '';
429$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'));
430$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'));
431$newcardbutton .= dolGetButtonTitleSeparator();
432$newcardbutton .= dolGetButtonTitle($langs->trans('New'), '', 'fa fa-plus-circle', dol_buildpath('/hrm/job_card.php', 1).'?action=create', '', $permissiontoadd);
433
434print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'object_'.$object->picto, 0, $newcardbutton, '', $limit, 0, 0, 1);
435
436// Add code for pre mass action (confirmation or email presend form)
437$topicmail = "SendJobRef";
438$modelmail = "job";
439$objecttmp = new Job($db);
440$trackid = 'xxxx'.$object->id;
441include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
442
443if ($search_all) {
444 $setupstring = '';
445 foreach ($fieldstosearchall as $key => $val) {
446 $fieldstosearchall[$key] = $langs->trans($val);
447 $setupstring .= $key."=".$val.";";
448 }
449 print '<!-- Search done like if JOBPOSITION_QUICKSEARCH_ON_FIELDS = '.$setupstring.' -->'."\n";
450 print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).join(', ', $fieldstosearchall).'</div>';
451}
452
453$moreforfilter = '';
454/*$moreforfilter.='<div class="divsearchfield">';
455$moreforfilter.= $langs->trans('MyFilter') . ': <input type="text" name="search_myfield" value="'.dol_escape_htmltag($search_myfield).'">';
456$moreforfilter.= '</div>';*/
457
458$parameters = array();
459$reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
460if (empty($reshook)) {
461 $moreforfilter .= $hookmanager->resPrint;
462} else {
463 $moreforfilter = $hookmanager->resPrint;
464}
465
466if (!empty($moreforfilter)) {
467 print '<div class="liste_titre liste_titre_bydiv centpercent">';
468 print $moreforfilter;
469 print '</div>';
470}
471
472$varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
473$selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN', '')); // This also change content of $arrayfields
474$selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
475
476print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
477print '<table class="tagtable nobottomiftotal liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
478
479
480// Fields title search
481// --------------------------------------------------------------------
482print '<tr class="liste_titre">';
483// Action column
484if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
485 print '<td class="liste_titre maxwidthsearch">';
486 $searchpicto = $form->showFilterButtons('left');
487 print $searchpicto;
488 print '</td>';
489}
490foreach ($object->fields as $key => $val) {
491 $searchkey = empty($search[$key]) ? '' : $search[$key];
492 $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
493 if ($key == 'status') {
494 $cssforfield .= ($cssforfield ? ' ' : '').'center';
495 } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
496 $cssforfield .= ($cssforfield ? ' ' : '').'center';
497 } elseif (in_array($val['type'], array('timestamp'))) {
498 $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
499 } 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'])) {
500 $cssforfield .= ($cssforfield ? ' ' : '').'right';
501 }
502 if (!empty($arrayfields['t.'.$key]['checked'])) {
503 print '<td class="liste_titre'.($cssforfield ? ' '.$cssforfield : '').'">';
504 if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
505 print $form->selectarray('search_'.$key, $val['arrayofkeyval'], (isset($search[$key]) ? $search[$key] : ''), $val['notnull'], 0, 0, '', 1, 0, 0, '', 'maxwidth100', 1);
506 } elseif ((strpos($val['type'], 'integer:') === 0) || (strpos($val['type'], 'sellist:') === 0)) {
507 print $object->showInputField($val, $key, (isset($search[$key]) ? $search[$key] : ''), '', '', 'search_', $cssforfield.' maxwidth125', 1);
508 } elseif (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
509 print '<div class="nowrap">';
510 print $form->selectDate($search[$key.'_dtstart'] ? $search[$key.'_dtstart'] : '', "search_".$key."_dtstart", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
511 print '</div>';
512 print '<div class="nowrap">';
513 print $form->selectDate($search[$key.'_dtend'] ? $search[$key.'_dtend'] : '', "search_".$key."_dtend", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
514 print '</div>';
515 } elseif ($key == 'lang') {
516 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
517 $formadmin = new FormAdmin($db);
518 print $formadmin->select_language($search[$key], 'search_lang', 0, null, 1, 0, 0, 'minwidth150 maxwidth200', 2);
519 } else {
520 print '<input type="text" class="flat maxwidth75" name="search_'.$key.'" value="'.dol_escape_htmltag(isset($search[$key]) ? $search[$key] : '').'">';
521 }
522 print '</td>';
523 }
524}
525// Extra fields
526include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
527
528// Fields from hook
529$parameters = array('arrayfields'=>$arrayfields);
530$reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object); // Note that $action and $object may have been modified by hook
531print $hookmanager->resPrint;
532// Action column
533if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
534 print '<td class="liste_titre maxwidthsearch">';
535 $searchpicto = $form->showFilterButtons();
536 print $searchpicto;
537 print '</td>';
538}
539print '</tr>'."\n";
540
541$totalarray = array();
542$totalarray['nbfield'] = 0;
543
544// Fields title label
545// --------------------------------------------------------------------
546print '<tr class="liste_titre">';
547if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
548 print getTitleFieldOfList(($mode != 'kanban' ? $selectedfields : ''), 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
549}
550foreach ($object->fields as $key => $val) {
551 $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
552 if ($key == 'status') {
553 $cssforfield .= ($cssforfield ? ' ' : '').'center';
554 } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
555 $cssforfield .= ($cssforfield ? ' ' : '').'center';
556 } elseif (in_array($val['type'], array('timestamp'))) {
557 $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
558 } 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'])) {
559 $cssforfield .= ($cssforfield ? ' ' : '').'right';
560 }
561 $cssforfield = preg_replace('/small\s*/', '', $cssforfield); // the 'small' css must not be used for the title label
562 if (!empty($arrayfields['t.'.$key]['checked'])) {
563 print getTitleFieldOfList($arrayfields['t.'.$key]['label'], 0, $_SERVER['PHP_SELF'], 't.'.$key, '', $param, ($cssforfield ? 'class="'.$cssforfield.'"' : ''), $sortfield, $sortorder, ($cssforfield ? $cssforfield.' ' : ''))."\n";
564 $totalarray['nbfield']++;
565 }
566}
567// Extra fields
568include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
569// Hook fields
570$parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder, 'totalarray'=>&$totalarray);
571$reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
572print $hookmanager->resPrint;
573// Action column
574if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
575 print getTitleFieldOfList(($mode != 'kanban' ? $selectedfields : ''), 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
576}
577$totalarray['nbfield']++;
578print '</tr>'."\n";
579
580
581// Detect if we need a fetch on each output line
582$needToFetchEachLine = 0;
583if (isset($extrafields->attributes[$object->table_element]['computed']) && is_array($extrafields->attributes[$object->table_element]['computed']) && count($extrafields->attributes[$object->table_element]['computed']) > 0) {
584 foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val) {
585 if (!is_null($val) && preg_match('/\$object/', $val)) {
586 $needToFetchEachLine++; // There is at least one compute field that use $object
587 }
588 }
589}
590
591
592// Loop on record
593// --------------------------------------------------------------------
594$i = 0;
595$savnbfield = $totalarray['nbfield'];
596$totalarray = array();
597$totalarray['nbfield'] = 0;
598$imaxinloop = ($limit ? min($num, $limit) : $num);
599while ($i < $imaxinloop) {
600 $obj = $db->fetch_object($resql);
601 if (empty($obj)) {
602 break; // Should not happen
603 }
604
605 // Store properties in $object
606 $object->setVarsFromFetchObj($obj);
607
608 if ($mode == 'kanban') {
609 $object->deplacement = $obj->deplacement;
610 $object->description = $obj->description;
611
612 if ($i == 0) {
613 print '<tr class="trkanban"><td colspan="'.$savnbfield.'">';
614 print '<div class="box-flex-container kanban">';
615 }
616 // Output Kanban
617 $selected = -1;
618 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
619 $selected = 0;
620 if (in_array($object->id, $arrayofselected)) {
621 $selected = 1;
622 }
623 }
624 print $object->getKanbanView('', array('selected' => $selected));
625 if ($i == ($imaxinloop - 1)) {
626 print '</div>';
627 print '</td></tr>';
628 }
629 } else {
630 // Show here line of result
631 $j = 0;
632 print '<tr data-rowid="'.$object->id.'" class="oddeven">';
633 // Action column
634 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
635 print '<td class="nowrap center">';
636 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
637 $selected = 0;
638 if (in_array($object->id, $arrayofselected)) {
639 $selected = 1;
640 }
641 print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
642 }
643 print '</td>';
644 }
645 foreach ($object->fields as $key => $val) {
646 $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
647 if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
648 $cssforfield .= ($cssforfield ? ' ' : '').'center';
649 } elseif ($key == 'status') {
650 $cssforfield .= ($cssforfield ? ' ' : '').'center';
651 }
652
653 if (in_array($val['type'], array('timestamp'))) {
654 $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
655 } elseif ($key == 'ref') {
656 $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
657 }
658
659 if (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && !in_array($key, array('rowid', 'status')) && empty($val['arrayofkeyval'])) {
660 $cssforfield .= ($cssforfield ? ' ' : '').'right';
661 }
662 //if (in_array($key, array('fk_soc', 'fk_user', 'fk_warehouse'))) $cssforfield = 'tdoverflowmax100';
663
664 if (!empty($arrayfields['t.'.$key]['checked'])) {
665 print '<td'.($cssforfield ? ' class="'.$cssforfield.(preg_match('/tdoverflow/', $cssforfield) ? ' classfortooltip' : '').'"' : '');
666 if (preg_match('/tdoverflow/', $cssforfield) && !is_numeric($object->$key)) {
667 print ' title="'.dol_escape_htmltag($object->$key).'"';
668 }
669 print '>';
670 if ($key == 'status') {
671 print $object->getLibStatut(5);
672 } elseif ($key == 'rowid') {
673 print $object->showOutputField($val, $key, $object->id, '');
674 } elseif ($key == 'label') {
675 print $object->getNomUrl(1);
676 } else {
677 print $object->showOutputField($val, $key, $object->$key, '');
678 }
679 print '</td>';
680 if (!$i) {
681 $totalarray['nbfield']++;
682 }
683 if (!empty($val['isameasure']) && $val['isameasure'] == 1) {
684 if (!$i) {
685 $totalarray['pos'][$totalarray['nbfield']] = 't.'.$key;
686 }
687 if (!isset($totalarray['val'])) {
688 $totalarray['val'] = array();
689 }
690 if (!isset($totalarray['val']['t.'.$key])) {
691 $totalarray['val']['t.'.$key] = 0;
692 }
693 $totalarray['val']['t.'.$key] += $object->$key;
694 }
695 }
696 }
697 // Extra fields
698 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
699 // Fields from hook
700 $parameters = array('arrayfields'=>$arrayfields, 'object'=>$object, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
701 $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object); // Note that $action and $object may have been modified by hook
702 print $hookmanager->resPrint;
703 // Action column
704 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
705 print '<td class="nowrap center">';
706 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
707 $selected = 0;
708 if (in_array($object->id, $arrayofselected)) {
709 $selected = 1;
710 }
711 print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
712 }
713 print '</td>';
714 }
715 if (!$i) {
716 $totalarray['nbfield']++;
717 }
718
719 print '</tr>'."\n";
720 }
721
722 $i++;
723}
724
725// Show total line
726include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
727
728// If no record found
729if ($num == 0) {
730 $colspan = 1;
731 foreach ($arrayfields as $key => $val) {
732 if (!empty($val['checked'])) {
733 $colspan++;
734 }
735 }
736 print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
737}
738
739
740$db->free($resql);
741
742$parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
743$reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
744print $hookmanager->resPrint;
745
746print '</table>'."\n";
747print '</div>'."\n";
748
749print '</form>'."\n";
750
751if (in_array('builddoc', array_keys($arrayofmassactions)) && ($nbtotalofrecords === '' || $nbtotalofrecords)) {
752 $hidegeneratedfilelistifempty = 1;
753 if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
754 $hidegeneratedfilelistifempty = 0;
755 }
756
757 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
758 $formfile = new FormFile($db);
759
760 // Show list of available documents
761 $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
762 $urlsource .= str_replace('&amp;', '&', $param);
763
764 $filedir = $diroutputmassaction;
765 $genallowed = $permissiontoread;
766 $delallowed = $permissiontoadd;
767
768 print $formfile->showdocuments('massfilesarea_hrm', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
769}
770
771// End of page
772llxFooter();
773$db->close();
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Definition wrapper.php:55
llxFooter()
Empty footer.
Definition wrapper.php:69
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
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 a 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.
dolGetButtonTitleSeparator($moreClass="")
Add space between dolGetButtonTitle.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
print_barre_liste($titre, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $hideselectlimit=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.