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