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