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