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