dolibarr 19.0.3
position.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 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
28// Load Dolibarr environment
29require '../main.inc.php';
30require_once DOL_DOCUMENT_ROOT . '/core/class/html.formcompany.class.php';
31require_once DOL_DOCUMENT_ROOT . '/core/class/html.formfile.class.php';
32require_once DOL_DOCUMENT_ROOT . '/core/class/html.formprojet.class.php';
33require_once DOL_DOCUMENT_ROOT . '/hrm/class/position.class.php';
34require_once DOL_DOCUMENT_ROOT . '/hrm/class/job.class.php';
35require_once DOL_DOCUMENT_ROOT . '/hrm/lib/hrm_position.lib.php';
36require_once DOL_DOCUMENT_ROOT . '/hrm/lib/hrm_job.lib.php';
37require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php';
38require_once DOL_DOCUMENT_ROOT . '/core/lib/company.lib.php';
39
40
41// Load translation files required by the page
42$langs->loadLangs(array("hrm", "other", 'products'));
43
44$action = GETPOST('action', 'aZ09') ? GETPOST('action', 'aZ09') : 'view'; // The action 'add', 'create', 'edit', 'update', 'view', ...
45$massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists)
46$show_files = GETPOST('show_files', 'int'); // Show files area generated by bulk actions ?
47$confirm = GETPOST('confirm', 'alpha'); // Result of a confirmation
48$cancel = GETPOST('cancel', 'alpha'); // We click on a Cancel button
49$toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list
50$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'jobpositionlist'; // To manage different context of search
51$optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
52$backtopage = GETPOST('backtopage', 'alpha');
53$backtopageforcancel = GETPOST('backtopageforcancel', 'alpha');
54
55$id = GETPOST('id', 'int');
56$ref = GETPOST('ref', 'alpha');
57$fk_job = (GETPOSTISSET('fk_job') ? GETPOST('fk_job', 'int') : $id);
58$fk_user = GETPOST('fk_user', 'int');
59//$start_date = date('Y-m-d', GETPOST('date_startyear', 'int').'-'.GETPOST('date_startmonth', 'int').'-'.GETPOST('date_startday', 'int'));
60$start_date = dol_mktime(0, 0, 0, GETPOST('date_startmonth', 'int'), GETPOST('date_startday', 'int'), GETPOST('date_startyear', 'int'));
61
62
63// Load variable for pagination
64$limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
65$sortfield = GETPOST('sortfield', 'aZ09comma');
66$sortorder = GETPOST('sortorder', 'aZ09comma');
67$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
68if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
69 // If $page is not defined, or '' or -1 or if we click on clear filters
70 $page = 0;
71}
72$offset = $limit * $page;
73$pageprev = $page - 1;
74$pagenext = $page + 1;
75
76
77// Initialize technical objects
78$object = new Job($db);
79$objectposition = new Position($db);
80$extrafields = new ExtraFields($db);
81$diroutputmassaction = $conf->hrm->dir_output . '/temp/massgeneration/' . $user->id;
82$hookmanager->initHooks(array('jobpositioncard', 'globalcard')); // Note that conf->hooks_modules contains array
83
84
85// Fetch optionals attributes and labels
86$extrafields->fetch_name_optionals_label($objectposition->table_element);
87//$extrafields->fetch_name_optionals_label($object->table_element_line);
88
89$search_array_options = $extrafields->getOptionalsFromPost($objectposition->table_element, '', 'search_');
90
91// Default sort order (if not yet defined by previous GETPOST)
92if (!$sortfield) {
93 reset($objectposition->fields); // Reset is required to avoid key() to return null.
94 $sortfield = "t." . key($objectposition->fields); // Set here default search field. By default 1st field in definition.
95}
96if (!$sortorder) {
97 $sortorder = "ASC";
98}
99
100// Initialize array of search criterias
101$search_all = GETPOST('search_all', 'alphanohtml') ? GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml');
102$search = array();
103foreach ($objectposition->fields as $key => $val) {
104 if (GETPOST('search_' . $key, 'alpha') !== '') {
105 $search[$key] = GETPOST('search_' . $key, 'alpha');
106 }
107 if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
108 $search[$key . '_dtstart'] = dol_mktime(0, 0, 0, GETPOST('search_' . $key . '_dtstartmonth', 'int'), GETPOST('search_' . $key . '_dtstartday', 'int'), GETPOST('search_' . $key . '_dtstartyear', 'int'));
109 $search[$key . '_dtend'] = dol_mktime(23, 59, 59, GETPOST('search_' . $key . '_dtendmonth', 'int'), GETPOST('search_' . $key . '_dtendday', 'int'), GETPOST('search_' . $key . '_dtendyear', 'int'));
110 }
111}
112
113// List of fields to search into when doing a "search in all"
114$fieldstosearchall = array();
115foreach ($objectposition->fields as $key => $val) {
116 if (!empty($val['searchall'])) {
117 $fieldstosearchall['t.' . $key] = $val['label'];
118 }
119}
120
121// Definition of array of fields for columns
122$arrayfields = array();
123foreach ($objectposition->fields as $key => $val) {
124 // If $val['visible']==0, then we never show the field
125 if (!empty($val['visible'])) {
126 $visible = (int) dol_eval($val['visible'], 1, 1, '1');
127 $arrayfields['t.' . $key] = array(
128 'label' => $val['label'],
129 'checked' => (($visible < 0) ? 0 : 1),
130 'enabled' => ($visible != 3 && dol_eval($val['enabled'], 1, 1, '1')),
131 'position' => $val['position'],
132 'help' => isset($val['help']) ? $val['help'] : ''
133 );
134 }
135}
136// Extra fields
137include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_array_fields.tpl.php';
138
139$objectposition->fields = dol_sort_array($objectposition->fields, 'position');
140$arrayfields = dol_sort_array($arrayfields, 'position');
141
142
143
144
145// Load object
146include DOL_DOCUMENT_ROOT . '/core/actions_fetchobject.inc.php'; // Must be include, not include_once.
147
148// Permissions
149$permissiontoread = $user->rights->hrm->all->read;
150$permissiontoadd = $user->rights->hrm->all->write; // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
151$permissiontodelete = $user->rights->hrm->all->delete;
152$upload_dir = $conf->hrm->multidir_output[isset($object->entity) ? $object->entity : 1] . '/position';
153
154// Security check (enable the most restrictive one)
155//if ($user->socid > 0) accessforbidden();
156//if ($user->socid > 0) $socid = $user->socid;
157//$isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
158//restrictedArea($user, $object->element, $object->id, $object->table_element, '', 'fk_soc', 'rowid', $isdraft);
159if (!isModEnabled('hrm')) {
161}
162if (!$permissiontoread || ($action === 'create' && !$permissiontoadd)) {
164}
165
166
167/*
168 * Actions
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}
176if (empty($reshook)) {
177 $error = 0;
178
179 $backurlforlist = dol_buildpath('/hrm/position_list.php', 1);
180 $idBacktoPage = GETPOST('fk_job', 'aZ09');
181 if ($idBacktoPage > 0) {
182 $backtopage = dol_buildpath('/hrm/position.php', 1) . '?id=' . $idBacktoPage;
183 }
184 if (empty($backtopage) || ($cancel && empty($id))) {
185 if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) {
186 if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) {
187 $backtopage = $backurlforlist;
188 } else {
189 if ($fk_job > 0) {
190 $backtopage = dol_buildpath('/hrm/position.php', 1) . '?fk_job=' . ($fk_job > 0 ? $fk_job : '__ID__');
191 } else {
192 $backtopage = dol_buildpath('/hrm/position_card.php', 1) . '?id=__ID__';
193 }
194 }
195 }
196 }
197
198 $triggermodname = 'HRM_POSITION_MODIFY'; // Name of trigger action code to execute when we modify record
199
200 // Actions cancel, add, update, update_extras, confirm_validate, confirm_delete, confirm_deleteline, confirm_clone, confirm_close, confirm_setdraft, confirm_reopen
201 $job = $object;
202 $object = new Position($db);
203
204 // Selection of new fields
205 include DOL_DOCUMENT_ROOT . '/core/actions_changeselectedfields.inc.php';
206
207 // Purge search criteria
208 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
209 foreach ($object->fields as $key => $val) {
210 $search[$key] = '';
211 if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
212 $search[$key . '_dtstart'] = '';
213 $search[$key . '_dtend'] = '';
214 }
215 }
216 $toselect = array();
217 $search_array_options = array();
218 }
219 if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')
220 || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) {
221 $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation
222 }
223
224 // Mass actions
225 $objectclass = 'Position';
226 $objectlabel = 'Position';
227 $uploaddir = $conf->hrm->dir_output;
228 include DOL_DOCUMENT_ROOT . '/core/actions_massactions.inc.php';
229
230 include DOL_DOCUMENT_ROOT . '/core/actions_addupdatedelete.inc.php';
231
232 $object = $job;
233}
234
235/*
236 * View
237 */
238
239$title = $langs->trans("Position");
240//$help_url="EN:Module_Position|FR:Module_Position_FR|ES:Módulo_Position";
241$help_url = '';
242
243llxHeader('', $title, $help_url);
244
245$now = dol_now();
246
247// Part to create
248if ($action == 'create') {
249 $object = new Position($db);
250 // Fetch optionals attributes and labels
251 $extrafields->fetch_name_optionals_label($object->table_element);
252 print load_fiche_titre($langs->trans("NewObject", $langs->transnoentitiesnoconv("Position")), '', 'object_' . $object->picto);
253
254 print '<form method="POST" action="' . $_SERVER["PHP_SELF"] . '">';
255 print '<input type="hidden" name="token" value="' . newToken() . '">';
256 print '<input type="hidden" name="action" value="add">';
257 if ($backtopage) {
258 print '<input type="hidden" name="backtopage" value="' . $backtopage . '">';
259 }
260 if ($backtopageforcancel) {
261 print '<input type="hidden" name="backtopageforcancel" value="' . $backtopageforcancel . '">';
262 }
263
264 print dol_get_fiche_head(array(), '');
265
266 print '<table class="border centpercent tableforfieldcreate">' . "\n";
267
268 // Common attributes
269 include DOL_DOCUMENT_ROOT . '/core/tpl/commonfields_add.tpl.php';
270
271 // Other attributes
272 include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_add.tpl.php';
273
274 print '</table>' . "\n";
275
276 print dol_get_fiche_end();
277
278 print $form->buttonsSaveCancel("Create");
279
280 print '</form>';
281
282 //dol_set_focus('input[name="ref"]');
283}
284if ($job->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) {
285 if ($backtopage) {
286 print '<input type="hidden" name="backtopage" value="' . $backtopage . '">';
287 }
288 if ($backtopageforcancel) {
289 print '<input type="hidden" name="backtopageforcancel" value="' . $backtopageforcancel . '">';
290 }
291
292 // Part to show record
293
294 $res = $object->fetch_optionals();
295
296 $head = jobPrepareHead($object);
297
298 print dol_get_fiche_head($head, 'position', $langs->trans("Workstation"), -1, $object->picto);
299
300 // Object card
301 // ------------------------------------------------------------
302 $linkback = '<a href="' . dol_buildpath('/hrm/position_list.php', 1) . '?restore_lastsearch_values=1' . (!empty($fk_job) ? '&fk_job=' . $fk_job : '') . '">' . $langs->trans("BackToList") . '</a>';
303
304 $morehtmlref = '<div class="refid">';
305 $morehtmlref.= $object->label;
306 $morehtmlref .= '</div>';
307
308 dol_banner_tab($object, 'fk_job', $linkback, 1, 'rowid', 'rowid', $morehtmlref);
309
310
311 print '<div class="fichecenter">';
312 print '<div class="fichehalfleft">';
313 print '<div class="underbanner clearboth"></div>';
314 print '<table class="border centpercent tableforfield">' . "\n";
315
316 // Common attributes
317 //$keyforbreak='fieldkeytoswitchonsecondcolumn'; // We change column just before this field
318 //unset($object->fields['fk_project']); // Hide field already shown in banner
319 //unset($object->fields['fk_soc']); // Hide field already shown in banner
320 $object->fields['label']['visible']=0; // Already in banner
321 include DOL_DOCUMENT_ROOT . '/core/tpl/commonfields_view.tpl.php';
322
323 // Other attributes. Fields from hook formObjectOptions and Extrafields.
324 include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
325
326 print '</table>';
327 print '</div>';
328 print '</div>';
329
330 print '<div class="clearboth"></div>';
331
332 print dol_get_fiche_end();
333
334
335 // List of positions
336
337 $object = $objectposition;
338
339
340 // Build and execute select
341 // --------------------------------------------------------------------
342 $sql = 'SELECT ';
343 $sql .= $object->getFieldList('t');
344 // Add fields from extrafields
345 if (!empty($extrafields->attributes[$object->table_element]['label'])) {
346 foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
347 $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef." . $key . " as options_" . $key . ', ' : '');
348 }
349 }
350 // Add fields from hooks
351 $parameters = array();
352 $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object); // Note that $action and $object may have been modified by hook
353 $sql .= $hookmanager->resPrint;
354 $sql = preg_replace('/,\s*$/', '', $sql);
355 $sql .= " FROM " . MAIN_DB_PREFIX . $object->table_element . " as t";
356 if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
357 $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . $object->table_element . "_extrafields as ef on (t.rowid = ef.fk_object)";
358 }
359 // Add table from hooks
360 $parameters = array();
361 $reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object); // Note that $action and $object may have been modified by hook
362 $sql .= $hookmanager->resPrint;
363 if ($object->ismultientitymanaged == 1) {
364 $sql .= " WHERE t.entity IN (" . getEntity($object->element) . ")";
365 } else {
366 $sql .= " WHERE 1 = 1";
367 }
368 $sql .= " AND t.fk_job = " . ((int) $fk_job) . " ";
369
370 foreach ($search as $key => $val) {
371 if (array_key_exists($key, $object->fields)) {
372 if ($key == 'status' && $search[$key] == -1) {
373 continue;
374 }
375 $mode_search = (($object->isInt($object->fields[$key]) || $object->isFloat($object->fields[$key])) ? 1 : 0);
376 if ((strpos($object->fields[$key]['type'], 'integer:') === 0) || (strpos($object->fields[$key]['type'], 'sellist:') === 0) || !empty($object->fields[$key]['arrayofkeyval'])) {
377 if ($search[$key] == '-1' || $search[$key] === '0') {
378 $search[$key] = '';
379 }
380 $mode_search = 2;
381 }
382 if ($search[$key] != '') {
383 $sql .= natural_search($key, $search[$key], (($key == 'status') ? 2 : $mode_search));
384 }
385 } else {
386 if (preg_match('/(_dtstart|_dtend)$/', $key) && $search[$key] != '') {
387 $columnName = preg_replace('/(_dtstart|_dtend)$/', '', $key);
388 if (preg_match('/^(date|timestamp|datetime)/', $object->fields[$columnName]['type'])) {
389 if (preg_match('/_dtstart$/', $key)) {
390 $sql .= " AND t." . $columnName . " >= '" . $db->idate($search[$key]) . "'";
391 }
392 if (preg_match('/_dtend$/', $key)) {
393 $sql .= " AND t." . $columnName . " <= '" . $db->idate($search[$key]) . "'";
394 }
395 }
396 }
397 }
398 }
399 if ($search_all) {
400 $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
401 }
402 //$sql.= dolSqlDateFilter("t.field", $search_xxxday, $search_xxxmonth, $search_xxxyear);
403 // Add where from extra fields
404 include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_search_sql.tpl.php';
405 // Add where from hooks
406 $parameters = array();
407 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object); // Note that $action and $object may have been modified by hook
408 $sql .= $hookmanager->resPrint;
409
410 $sql .= $db->order($sortfield, $sortorder);
411
412 // Count total nb of records
413 $nbtotalofrecords = '';
414 if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
415 $resql = $db->query($sql);
416 $nbtotalofrecords = $db->num_rows($resql);
417 if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0
418 $page = 0;
419 $offset = 0;
420 }
421 }
422 // if total of record found is smaller than limit, no need to do paging and to restart another select with limits set.
423 if (is_numeric($nbtotalofrecords) && ($limit > $nbtotalofrecords || empty($limit))) {
424 $num = $nbtotalofrecords;
425 } else {
426 if ($limit) {
427 $sql .= $db->plimit($limit + 1, $offset);
428 }
429
430 $resql = $db->query($sql);
431 if (!$resql) {
432 dol_print_error($db);
433 exit;
434 }
435
436 $num = $db->num_rows($resql);
437 }
438
439 // Direct jump if only one record found
440 if ($num == 1 && getDolGlobalString('MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE') && $search_all && !$page) {
441 $obj = $db->fetch_object($resql);
442 $id = $obj->rowid;
443 header("Location: " . dol_buildpath('/hrm/position.php', 1) . '?id=' . $id);
444 exit;
445 }
446
447 $arrayofselected = is_array($toselect) ? $toselect : array();
448
449 $param = 'fk_job=' . $fk_job;
450 if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
451 $param .= '&contextpage=' . urlencode($contextpage);
452 }
453 if ($limit > 0 && $limit != $conf->liste_limit) {
454 $param .= '&limit='.((int) $limit);
455 }
456 foreach ($search as $key => $val) {
457 if (is_array($search[$key]) && count($search[$key])) {
458 foreach ($search[$key] as $skey) {
459 $param .= '&search_' . $key . '[]=' . urlencode($skey);
460 }
461 } else {
462 $param .= '&search_' . $key . '=' . urlencode($search[$key]);
463 }
464 }
465 if ($optioncss != '') {
466 $param .= '&optioncss=' . urlencode($optioncss);
467 }
468 // Add $param from extra fields
469 include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_search_param.tpl.php';
470 // Add $param from hooks
471 $parameters = array('param' => &$param);
472 $reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object); // Note that $action and $object may have been modified by hook
473 $param .= $hookmanager->resPrint;
474
475 // List of mass actions available
476 $arrayofmassactions = array(
477 //'validate'=>img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Validate"),
478 //'generate_doc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"),
479 //'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
480 //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
481 );
482 if ($permissiontodelete) {
483 $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"') . $langs->trans("Delete");
484 }
485 if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) {
486 $arrayofmassactions = array();
487 }
488 $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
489
490 print '<form method="POST" id="searchFormList" action="' . $_SERVER["PHP_SELF"] . '?fk_job=' . $fk_job . '">' . "\n";
491 if ($optioncss != '') {
492 print '<input type="hidden" name="optioncss" value="' . $optioncss . '">';
493 }
494 print '<input type="hidden" name="token" value="' . newToken() . '">';
495 print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
496 print '<input type="hidden" name="action" value="list">';
497 print '<input type="hidden" name="massaction" value="' . $massaction . '">';
498 print '<input type="hidden" name="sortfield" value="' . $sortfield . '">';
499 print '<input type="hidden" name="sortorder" value="' . $sortorder . '">';
500 print '<input type="hidden" name="page" value="' . $page . '">';
501 print '<input type="hidden" name="contextpage" value="' . $contextpage . '">';
502
503 $newcardbutton = '';
504 $newcardbutton .= dolGetButtonTitle($langs->trans('New'), '', 'fa fa-plus-circle', dol_buildpath('/hrm/position.php', 1).'?action=create&backtopage='.urlencode($_SERVER['PHP_SELF']).'&fk_job='.((int) $fk_job), '', $permissiontoadd);
505
506 print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'object_' . $object->picto, 0, $newcardbutton, '', $limit, 0, 0, 1);
507
508 // Add code for pre mass action (confirmation or email presend form)
509 $topicmail = "SendPositionRef";
510 $modelmail = "position";
511 $objecttmp = new Position($db);
512 $trackid = 'xxxx' . $object->id;
513 include DOL_DOCUMENT_ROOT . '/core/tpl/massactions_pre.tpl.php';
514
515 if ($search_all) {
516 foreach ($fieldstosearchall as $key => $val) {
517 $fieldstosearchall[$key] = $langs->trans($val);
518 }
519 print '<div class="divsearchfieldfilter">' . $langs->trans("FilterOnInto", $search_all) . join(', ', $fieldstosearchall) . '</div>';
520 }
521
522 $moreforfilter = '';
523 /*$moreforfilter.='<div class="divsearchfield">';
524 $moreforfilter.= $langs->trans('MyFilter') . ': <input type="text" name="search_myfield" value="'.dol_escape_htmltag($search_myfield).'">';
525 $moreforfilter.= '</div>';*/
526
527 $parameters = array();
528 $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
529 if (empty($reshook)) {
530 $moreforfilter .= $hookmanager->resPrint;
531 } else {
532 $moreforfilter = $hookmanager->resPrint;
533 }
534
535 if (!empty($moreforfilter)) {
536 print '<div class="liste_titre liste_titre_bydiv centpercent">';
537 print $moreforfilter;
538 print '</div>';
539 }
540
541 $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
542 $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
543 $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
544
545 print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
546 print '<table class="tagtable nobottomiftotal liste' . ($moreforfilter ? " listwithfilterbefore" : "") . '">' . "\n";
547
548 // Fields title search
549 // --------------------------------------------------------------------
550 print '<tr class="liste_titre">';
551 foreach ($object->fields as $key => $val) {
552 $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
553 if ($key == 'status') {
554 $cssforfield .= ($cssforfield ? ' ' : '') . 'center';
555 } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
556 $cssforfield .= ($cssforfield ? ' ' : '') . 'center';
557 } elseif (in_array($val['type'], array('timestamp'))) {
558 $cssforfield .= ($cssforfield ? ' ' : '') . 'nowrap';
559 } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID' && empty($val['arrayofkeyval'])) {
560 $cssforfield .= ($cssforfield ? ' ' : '') . 'right';
561 }
562 if (!empty($arrayfields['t.' . $key]['checked'])) {
563 print '<td class="liste_titre' . ($cssforfield ? ' ' . $cssforfield : '') . '">';
564 if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
565 print $form->selectarray('search_' . $key, $val['arrayofkeyval'], (isset($search[$key]) ? $search[$key] : ''), $val['notnull'], 0, 0, '', 1, 0, 0, '', 'maxwidth100', 1);
566 } elseif ((strpos($val['type'], 'integer:') === 0) || (strpos($val['type'], 'sellist:') === 0)) {
567 print $object->showInputField($val, $key, (isset($search[$key]) ? $search[$key] : ''), '', '', 'search_', 'maxwidth125', 1);
568 } elseif (!preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
569 print '<input type="text" class="flat maxwidth75" name="search_' . $key . '" value="' . dol_escape_htmltag(isset($search[$key]) ? $search[$key] : '') . '">';
570 } elseif (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
571 print '<div class="nowrap">';
572 print $form->selectDate($search[$key . '_dtstart'] ? $search[$key . '_dtstart'] : '', "search_" . $key . "_dtstart", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
573 print '</div>';
574 print '<div class="nowrap">';
575 print $form->selectDate($search[$key . '_dtend'] ? $search[$key . '_dtend'] : '', "search_" . $key . "_dtend", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
576 print '</div>';
577 }
578 print '</td>';
579 }
580 }
581 // Extra fields
582 include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_search_input.tpl.php';
583
584 // Fields from hook
585 $parameters = array('arrayfields' => $arrayfields);
586 $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object); // Note that $action and $object may have been modified by hook
587 print $hookmanager->resPrint;
588 // Action column
589 print '<td class="liste_titre maxwidthsearch">';
590 $searchpicto = $form->showFilterButtons();
591 print $searchpicto;
592 print '</td>';
593 print '</tr>' . "\n";
594
595
596 // Fields title label
597 // --------------------------------------------------------------------
598 print '<tr class="liste_titre">';
599 foreach ($object->fields as $key => $val) {
600 $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
601 if ($key == 'status') {
602 $cssforfield .= ($cssforfield ? ' ' : '') . 'center';
603 } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
604 $cssforfield .= ($cssforfield ? ' ' : '') . 'center';
605 } elseif (in_array($val['type'], array('timestamp'))) {
606 $cssforfield .= ($cssforfield ? ' ' : '') . 'nowrap';
607 } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID' && empty($val['arrayofkeyval'])) {
608 $cssforfield .= ($cssforfield ? ' ' : '') . 'right';
609 }
610 if (!empty($arrayfields['t.' . $key]['checked'])) {
611 print getTitleFieldOfList($arrayfields['t.' . $key]['label'], 0, $_SERVER['PHP_SELF'], 't.' . $key, '', $param, ($cssforfield ? 'class="' . $cssforfield . '"' : ''), $sortfield, $sortorder, ($cssforfield ? $cssforfield . ' ' : '')) . "\n";
612 }
613 }
614 // Extra fields
615 include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_search_title.tpl.php';
616 // Hook fields
617 $parameters = array('arrayfields' => $arrayfields, 'param' => $param, 'sortfield' => $sortfield, 'sortorder' => $sortorder);
618 $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
619 print $hookmanager->resPrint;
620 // Action column
621 print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ') . "\n";
622 print '</tr>' . "\n";
623
624 // Detect if we need a fetch on each output line
625 $needToFetchEachLine = 0;
626 if (isset($extrafields->attributes[$object->table_element]['computed']) && is_array($extrafields->attributes[$object->table_element]['computed']) && count($extrafields->attributes[$object->table_element]['computed']) > 0) {
627 foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val) {
628 if (!is_null($val) && preg_match('/\$object/', $val)) {
629 $needToFetchEachLine++; // There is at least one compute field that use $object
630 }
631 }
632 }
633
634
635 // Loop on record
636 // --------------------------------------------------------------------
637 $i = 0;
638 $totalarray = array();
639 $totalarray['nbfield'] = 0;
640 while ($i < ($limit ? min($num, $limit) : $num)) {
641 $obj = $db->fetch_object($resql);
642 if (empty($obj)) {
643 break; // Should not happen
644 }
645
646 // Store properties in $object
647 $object->setVarsFromFetchObj($obj);
648
649 // Show here line of result
650 print '<tr class="oddeven">';
651 foreach ($object->fields as $key => $val) {
652 $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
653 if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
654 $cssforfield .= ($cssforfield ? ' ' : '') . 'center';
655 } elseif ($key == 'status') {
656 $cssforfield .= ($cssforfield ? ' ' : '') . 'center';
657 }
658
659 if (in_array($val['type'], array('timestamp'))) {
660 $cssforfield .= ($cssforfield ? ' ' : '') . 'nowrap';
661 } elseif ($key == 'ref') {
662 $cssforfield .= ($cssforfield ? ' ' : '') . 'nowrap';
663 }
664
665 if (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && !in_array($key, array('rowid', 'status')) && empty($val['arrayofkeyval'])) {
666 $cssforfield .= ($cssforfield ? ' ' : '') . 'right';
667 }
668 //if (in_array($key, array('fk_soc', 'fk_user', 'fk_warehouse'))) $cssforfield = 'tdoverflowmax100';
669
670 if (!empty($arrayfields['t.' . $key]['checked'])) {
671 print '<td' . ($cssforfield ? ' class="' . $cssforfield . '"' : '') . '>';
672 if ($key == 'status') {
673 print $object->getLibStatut(5);
674 } elseif ($key == 'rowid') {
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 print '<td class="nowrap center">';
705 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
706 $selected = 0;
707 if (in_array($object->id, $arrayofselected)) {
708 $selected = 1;
709 }
710 print '<input id="cb' . $object->id . '" class="flat checkforselect" type="checkbox" name="toselect[]" value="' . $object->id . '"' . ($selected ? ' checked="checked"' : '') . '>';
711 }
712 print '</td>';
713 if (!$i) {
714 $totalarray['nbfield']++;
715 }
716
717 print '</tr>' . "\n";
718
719 $i++;
720 }
721
722 // Show total line
723 include DOL_DOCUMENT_ROOT . '/core/tpl/list_print_total.tpl.php';
724
725 // If no record found
726 if ($num == 0) {
727 $colspan = 1;
728 foreach ($arrayfields as $key => $val) {
729 if (!empty($val['checked'])) {
730 $colspan++;
731 }
732 }
733 print '<tr><td colspan="' . $colspan . '"><span class="opacitymedium">' . $langs->trans("NoRecordFound") . '</span></td></tr>';
734 }
735
736
737 $db->free($resql);
738
739 $parameters = array('arrayfields' => $arrayfields, 'sql' => $sql);
740 $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object); // Note that $action and $object may have been modified by hook
741 print $hookmanager->resPrint;
742
743 print '</table>' . "\n";
744 print '</div>' . "\n";
745
746 print '</form>' . "\n";
747
748 if (in_array('builddoc', array_keys($arrayofmassactions)) && ($nbtotalofrecords === '' || $nbtotalofrecords)) {
749 $hidegeneratedfilelistifempty = 1;
750 if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
751 $hidegeneratedfilelistifempty = 0;
752 }
753
754 require_once DOL_DOCUMENT_ROOT . '/core/class/html.formfile.class.php';
755 $formfile = new FormFile($db);
756
757 // Show list of available documents
758 $urlsource = $_SERVER['PHP_SELF'] . '?sortfield=' . $sortfield . '&sortorder=' . $sortorder;
759 $urlsource .= str_replace('&amp;', '&', $param);
760
761 $filedir = $diroutputmassaction;
762 $genallowed = $permissiontoread;
763 $delallowed = $permissiontoadd;
764
765 print $formfile->showdocuments('massfilesarea_hrm', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
766 }
767}
768
769// End of page
770llxFooter();
771$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 offer components to list and upload files.
Class for Job.
Definition job.class.php:37
Class for Position.
dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='rowid', $fieldref='ref', $morehtmlref='', $moreparam='', $nodbprefix=0, $morehtmlleft='', $morehtmlstatus='', $onlybanner=0, $morehtmlright='')
Show tab footer of a card.
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...
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
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.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
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.
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.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
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...
jobPrepareHead($object)
Prepare array of tabs for Job.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.