dolibarr 18.0.6
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 = GETPOST('id', 'int');
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 = '';
241llxHeader('', $title, $help_url);
242
243$now = dol_now();
244
245// Part to create
246if ($action == 'create') {
247 $object = new Position($db);
248 // Fetch optionals attributes and labels
249 $extrafields->fetch_name_optionals_label($object->table_element);
250 print load_fiche_titre($langs->trans("NewObject", $langs->transnoentitiesnoconv("Position")), '', 'object_' . $object->picto);
251
252 print '<form method="POST" action="' . $_SERVER["PHP_SELF"] . '">';
253 print '<input type="hidden" name="token" value="' . newToken() . '">';
254 print '<input type="hidden" name="action" value="add">';
255 if ($backtopage) {
256 print '<input type="hidden" name="backtopage" value="' . $backtopage . '">';
257 }
258 if ($backtopageforcancel) {
259 print '<input type="hidden" name="backtopageforcancel" value="' . $backtopageforcancel . '">';
260 }
261
262 print dol_get_fiche_head(array(), '');
263
264 print '<table class="border centpercent tableforfieldcreate">' . "\n";
265
266 // Common attributes
267 include DOL_DOCUMENT_ROOT . '/core/tpl/commonfields_add.tpl.php';
268
269 // Other attributes
270 include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_add.tpl.php';
271
272 print '</table>' . "\n";
273
274 print dol_get_fiche_end();
275
276 print $form->buttonsSaveCancel("Create");
277
278 print '</form>';
279
280 //dol_set_focus('input[name="ref"]');
281}
282if ($job->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) {
283 if ($backtopage) {
284 print '<input type="hidden" name="backtopage" value="' . $backtopage . '">';
285 }
286 if ($backtopageforcancel) {
287 print '<input type="hidden" name="backtopageforcancel" value="' . $backtopageforcancel . '">';
288 }
289
290 // Part to show record
291
292 $res = $object->fetch_optionals();
293
294 $head = jobPrepareHead($object);
295
296 print dol_get_fiche_head($head, 'position', $langs->trans("Workstation"), -1, $object->picto);
297
298 // Object card
299 // ------------------------------------------------------------
300 $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>';
301
302 $morehtmlref = '<div class="refid">';
303 $morehtmlref.= $object->label;
304 $morehtmlref .= '</div>';
305
306 dol_banner_tab($object, 'fk_job', $linkback, 1, 'rowid', 'rowid', $morehtmlref);
307
308
309 print '<div class="fichecenter">';
310 print '<div class="fichehalfleft">';
311 print '<div class="underbanner clearboth"></div>';
312 print '<table class="border centpercent tableforfield">' . "\n";
313
314 // Common attributes
315 //$keyforbreak='fieldkeytoswitchonsecondcolumn'; // We change column just before this field
316 //unset($object->fields['fk_project']); // Hide field already shown in banner
317 //unset($object->fields['fk_soc']); // Hide field already shown in banner
318 $object->fields['label']['visible']=0; // Already in banner
319 include DOL_DOCUMENT_ROOT . '/core/tpl/commonfields_view.tpl.php';
320
321 // Other attributes. Fields from hook formObjectOptions and Extrafields.
322 include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
323
324 print '</table>';
325 print '</div>';
326 print '</div>';
327
328 print '<div class="clearboth"></div>';
329
330 print dol_get_fiche_end();
331
332
333 // List of positions
334
335 $object = $objectposition;
336
337
338 //$help_url="EN:Module_Position|FR:Module_Position_FR|ES:MĂ³dulo_Position";
339 $help_url = '';
340 $title = $langs->trans("Positions");
341 $morejs = array();
342 $morecss = array();
343
344
345 // Build and execute select
346 // --------------------------------------------------------------------
347 $sql = 'SELECT ';
348 $sql .= $object->getFieldList('t');
349 // Add fields from extrafields
350 if (!empty($extrafields->attributes[$object->table_element]['label'])) {
351 foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
352 $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef." . $key . " as options_" . $key . ', ' : '');
353 }
354 }
355 // Add fields from hooks
356 $parameters = array();
357 $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object); // Note that $action and $object may have been modified by hook
358 $sql .= $hookmanager->resPrint;
359 $sql = preg_replace('/,\s*$/', '', $sql);
360 $sql .= " FROM " . MAIN_DB_PREFIX . $object->table_element . " as t";
361 if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
362 $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . $object->table_element . "_extrafields as ef on (t.rowid = ef.fk_object)";
363 }
364 // Add table from hooks
365 $parameters = array();
366 $reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object); // Note that $action and $object may have been modified by hook
367 $sql .= $hookmanager->resPrint;
368 if ($object->ismultientitymanaged == 1) {
369 $sql .= " WHERE t.entity IN (" . getEntity($object->element) . ")";
370 } else {
371 $sql .= " WHERE 1 = 1";
372 }
373 $sql .= " AND t.fk_job = " . ((int) $fk_job) . " ";
374
375 foreach ($search as $key => $val) {
376 if (array_key_exists($key, $object->fields)) {
377 if ($key == 'status' && $search[$key] == -1) {
378 continue;
379 }
380 $mode_search = (($object->isInt($object->fields[$key]) || $object->isFloat($object->fields[$key])) ? 1 : 0);
381 if ((strpos($object->fields[$key]['type'], 'integer:') === 0) || (strpos($object->fields[$key]['type'], 'sellist:') === 0) || !empty($object->fields[$key]['arrayofkeyval'])) {
382 if ($search[$key] == '-1' || $search[$key] === '0') {
383 $search[$key] = '';
384 }
385 $mode_search = 2;
386 }
387 if ($search[$key] != '') {
388 $sql .= natural_search($key, $search[$key], (($key == 'status') ? 2 : $mode_search));
389 }
390 } else {
391 if (preg_match('/(_dtstart|_dtend)$/', $key) && $search[$key] != '') {
392 $columnName = preg_replace('/(_dtstart|_dtend)$/', '', $key);
393 if (preg_match('/^(date|timestamp|datetime)/', $object->fields[$columnName]['type'])) {
394 if (preg_match('/_dtstart$/', $key)) {
395 $sql .= " AND t." . $columnName . " >= '" . $db->idate($search[$key]) . "'";
396 }
397 if (preg_match('/_dtend$/', $key)) {
398 $sql .= " AND t." . $columnName . " <= '" . $db->idate($search[$key]) . "'";
399 }
400 }
401 }
402 }
403 }
404 if ($search_all) {
405 $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
406 }
407 //$sql.= dolSqlDateFilter("t.field", $search_xxxday, $search_xxxmonth, $search_xxxyear);
408 // Add where from extra fields
409 include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_search_sql.tpl.php';
410 // Add where from hooks
411 $parameters = array();
412 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object); // Note that $action and $object may have been modified by hook
413 $sql .= $hookmanager->resPrint;
414
415 $sql .= $db->order($sortfield, $sortorder);
416
417 // Count total nb of records
418 $nbtotalofrecords = '';
419 if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
420 $resql = $db->query($sql);
421 $nbtotalofrecords = $db->num_rows($resql);
422 if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0
423 $page = 0;
424 $offset = 0;
425 }
426 }
427 // if total of record found is smaller than limit, no need to do paging and to restart another select with limits set.
428 if (is_numeric($nbtotalofrecords) && ($limit > $nbtotalofrecords || empty($limit))) {
429 $num = $nbtotalofrecords;
430 } else {
431 if ($limit) {
432 $sql .= $db->plimit($limit + 1, $offset);
433 }
434
435 $resql = $db->query($sql);
436 if (!$resql) {
437 dol_print_error($db);
438 exit;
439 }
440
441 $num = $db->num_rows($resql);
442 }
443
444 // Direct jump if only one record found
445 if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $search_all && !$page) {
446 $obj = $db->fetch_object($resql);
447 $id = $obj->rowid;
448 header("Location: " . dol_buildpath('/hrm/position.php', 1) . '?id=' . $id);
449 exit;
450 }
451
452 $arrayofselected = is_array($toselect) ? $toselect : array();
453
454 $param = 'fk_job=' . $fk_job;
455 if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
456 $param .= '&contextpage=' . urlencode($contextpage);
457 }
458 if ($limit > 0 && $limit != $conf->liste_limit) {
459 $param .= '&limit='.((int) $limit);
460 }
461 foreach ($search as $key => $val) {
462 if (is_array($search[$key]) && count($search[$key])) {
463 foreach ($search[$key] as $skey) {
464 $param .= '&search_' . $key . '[]=' . urlencode($skey);
465 }
466 } else {
467 $param .= '&search_' . $key . '=' . urlencode($search[$key]);
468 }
469 }
470 if ($optioncss != '') {
471 $param .= '&optioncss=' . urlencode($optioncss);
472 }
473 // Add $param from extra fields
474 include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_search_param.tpl.php';
475 // Add $param from hooks
476 $parameters = array();
477 $reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object); // Note that $action and $object may have been modified by hook
478 $param .= $hookmanager->resPrint;
479
480 // List of mass actions available
481 $arrayofmassactions = array(
482 //'validate'=>img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Validate"),
483 //'generate_doc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"),
484 //'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
485 //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
486 );
487 if ($permissiontodelete) {
488 $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"') . $langs->trans("Delete");
489 }
490 if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) {
491 $arrayofmassactions = array();
492 }
493 $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
494
495 print '<form method="POST" id="searchFormList" action="' . $_SERVER["PHP_SELF"] . '?fk_job=' . $fk_job . '">' . "\n";
496 if ($optioncss != '') {
497 print '<input type="hidden" name="optioncss" value="' . $optioncss . '">';
498 }
499 print '<input type="hidden" name="token" value="' . newToken() . '">';
500 print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
501 print '<input type="hidden" name="action" value="list">';
502 print '<input type="hidden" name="massaction" value="' . $massaction . '">';
503 print '<input type="hidden" name="sortfield" value="' . $sortfield . '">';
504 print '<input type="hidden" name="sortorder" value="' . $sortorder . '">';
505 print '<input type="hidden" name="page" value="' . $page . '">';
506 print '<input type="hidden" name="contextpage" value="' . $contextpage . '">';
507
508 $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);
509
510 print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'object_' . $object->picto, 0, $newcardbutton, '', $limit, 0, 0, 1);
511
512 // Add code for pre mass action (confirmation or email presend form)
513 $topicmail = "SendPositionRef";
514 $modelmail = "position";
515 $objecttmp = new Position($db);
516 $trackid = 'xxxx' . $object->id;
517 include DOL_DOCUMENT_ROOT . '/core/tpl/massactions_pre.tpl.php';
518
519 if ($search_all) {
520 foreach ($fieldstosearchall as $key => $val) {
521 $fieldstosearchall[$key] = $langs->trans($val);
522 }
523 print '<div class="divsearchfieldfilter">' . $langs->trans("FilterOnInto", $search_all) . join(', ', $fieldstosearchall) . '</div>';
524 }
525
526 $moreforfilter = '';
527 /*$moreforfilter.='<div class="divsearchfield">';
528 $moreforfilter.= $langs->trans('MyFilter') . ': <input type="text" name="search_myfield" value="'.dol_escape_htmltag($search_myfield).'">';
529 $moreforfilter.= '</div>';*/
530
531 $parameters = array();
532 $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
533 if (empty($reshook)) {
534 $moreforfilter .= $hookmanager->resPrint;
535 } else {
536 $moreforfilter = $hookmanager->resPrint;
537 }
538
539 if (!empty($moreforfilter)) {
540 print '<div class="liste_titre liste_titre_bydiv centpercent">';
541 print $moreforfilter;
542 print '</div>';
543 }
544
545 $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
546 $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
547 $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
548
549 print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
550 print '<table class="tagtable nobottomiftotal liste' . ($moreforfilter ? " listwithfilterbefore" : "") . '">' . "\n";
551
552 // Fields title search
553 // --------------------------------------------------------------------
554 print '<tr class="liste_titre">';
555 foreach ($object->fields as $key => $val) {
556 $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
557 if ($key == 'status') {
558 $cssforfield .= ($cssforfield ? ' ' : '') . 'center';
559 } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
560 $cssforfield .= ($cssforfield ? ' ' : '') . 'center';
561 } elseif (in_array($val['type'], array('timestamp'))) {
562 $cssforfield .= ($cssforfield ? ' ' : '') . 'nowrap';
563 } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID' && empty($val['arrayofkeyval'])) {
564 $cssforfield .= ($cssforfield ? ' ' : '') . 'right';
565 }
566 if (!empty($arrayfields['t.' . $key]['checked'])) {
567 print '<td class="liste_titre' . ($cssforfield ? ' ' . $cssforfield : '') . '">';
568 if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
569 print $form->selectarray('search_' . $key, $val['arrayofkeyval'], (isset($search[$key]) ? $search[$key] : ''), $val['notnull'], 0, 0, '', 1, 0, 0, '', 'maxwidth100', 1);
570 } elseif ((strpos($val['type'], 'integer:') === 0) || (strpos($val['type'], 'sellist:') === 0)) {
571 print $object->showInputField($val, $key, (isset($search[$key]) ? $search[$key] : ''), '', '', 'search_', 'maxwidth125', 1);
572 } elseif (!preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
573 print '<input type="text" class="flat maxwidth75" name="search_' . $key . '" value="' . dol_escape_htmltag(isset($search[$key]) ? $search[$key] : '') . '">';
574 } elseif (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
575 print '<div class="nowrap">';
576 print $form->selectDate($search[$key . '_dtstart'] ? $search[$key . '_dtstart'] : '', "search_" . $key . "_dtstart", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
577 print '</div>';
578 print '<div class="nowrap">';
579 print $form->selectDate($search[$key . '_dtend'] ? $search[$key . '_dtend'] : '', "search_" . $key . "_dtend", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
580 print '</div>';
581 }
582 print '</td>';
583 }
584 }
585 // Extra fields
586 include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_search_input.tpl.php';
587
588 // Fields from hook
589 $parameters = array('arrayfields' => $arrayfields);
590 $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object); // Note that $action and $object may have been modified by hook
591 print $hookmanager->resPrint;
592 // Action column
593 print '<td class="liste_titre maxwidthsearch">';
594 $searchpicto = $form->showFilterButtons();
595 print $searchpicto;
596 print '</td>';
597 print '</tr>' . "\n";
598
599
600 // Fields title label
601 // --------------------------------------------------------------------
602 print '<tr class="liste_titre">';
603 foreach ($object->fields as $key => $val) {
604 $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
605 if ($key == 'status') {
606 $cssforfield .= ($cssforfield ? ' ' : '') . 'center';
607 } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
608 $cssforfield .= ($cssforfield ? ' ' : '') . 'center';
609 } elseif (in_array($val['type'], array('timestamp'))) {
610 $cssforfield .= ($cssforfield ? ' ' : '') . 'nowrap';
611 } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID' && empty($val['arrayofkeyval'])) {
612 $cssforfield .= ($cssforfield ? ' ' : '') . 'right';
613 }
614 if (!empty($arrayfields['t.' . $key]['checked'])) {
615 print getTitleFieldOfList($arrayfields['t.' . $key]['label'], 0, $_SERVER['PHP_SELF'], 't.' . $key, '', $param, ($cssforfield ? 'class="' . $cssforfield . '"' : ''), $sortfield, $sortorder, ($cssforfield ? $cssforfield . ' ' : '')) . "\n";
616 }
617 }
618 // Extra fields
619 include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_search_title.tpl.php';
620 // Hook fields
621 $parameters = array('arrayfields' => $arrayfields, 'param' => $param, 'sortfield' => $sortfield, 'sortorder' => $sortorder);
622 $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
623 print $hookmanager->resPrint;
624 // Action column
625 print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ') . "\n";
626 print '</tr>' . "\n";
627
628 // Detect if we need a fetch on each output line
629 $needToFetchEachLine = 0;
630 if (isset($extrafields->attributes[$object->table_element]['computed']) && is_array($extrafields->attributes[$object->table_element]['computed']) && count($extrafields->attributes[$object->table_element]['computed']) > 0) {
631 foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val) {
632 if (!is_null($val) && preg_match('/\$object/', $val)) {
633 $needToFetchEachLine++; // There is at least one compute field that use $object
634 }
635 }
636 }
637
638
639 // Loop on record
640 // --------------------------------------------------------------------
641 $i = 0;
642 $totalarray = array();
643 $totalarray['nbfield'] = 0;
644 while ($i < ($limit ? min($num, $limit) : $num)) {
645 $obj = $db->fetch_object($resql);
646 if (empty($obj)) {
647 break; // Should not happen
648 }
649
650 // Store properties in $object
651 $object->setVarsFromFetchObj($obj);
652
653 // Show here line of result
654 print '<tr class="oddeven">';
655 foreach ($object->fields as $key => $val) {
656 $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
657 if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
658 $cssforfield .= ($cssforfield ? ' ' : '') . 'center';
659 } elseif ($key == 'status') {
660 $cssforfield .= ($cssforfield ? ' ' : '') . 'center';
661 }
662
663 if (in_array($val['type'], array('timestamp'))) {
664 $cssforfield .= ($cssforfield ? ' ' : '') . 'nowrap';
665 } elseif ($key == 'ref') {
666 $cssforfield .= ($cssforfield ? ' ' : '') . 'nowrap';
667 }
668
669 if (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && !in_array($key, array('rowid', 'status')) && empty($val['arrayofkeyval'])) {
670 $cssforfield .= ($cssforfield ? ' ' : '') . 'right';
671 }
672 //if (in_array($key, array('fk_soc', 'fk_user', 'fk_warehouse'))) $cssforfield = 'tdoverflowmax100';
673
674 if (!empty($arrayfields['t.' . $key]['checked'])) {
675 print '<td' . ($cssforfield ? ' class="' . $cssforfield . '"' : '') . '>';
676 if ($key == 'status') {
677 print $object->getLibStatut(5);
678 } elseif ($key == 'rowid') {
679 print $object->getNomUrl(1);
680 } else {
681 print $object->showOutputField($val, $key, $object->$key, '');
682 }
683 print '</td>';
684 if (!$i) {
685 $totalarray['nbfield']++;
686 }
687 if (!empty($val['isameasure']) && $val['isameasure'] == 1) {
688 if (!$i) {
689 $totalarray['pos'][$totalarray['nbfield']] = 't.' . $key;
690 }
691 if (!isset($totalarray['val'])) {
692 $totalarray['val'] = array();
693 }
694 if (!isset($totalarray['val']['t.' . $key])) {
695 $totalarray['val']['t.' . $key] = 0;
696 }
697 $totalarray['val']['t.' . $key] += $object->$key;
698 }
699 }
700 }
701 // Extra fields
702 include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_print_fields.tpl.php';
703 // Fields from hook
704 $parameters = array('arrayfields' => $arrayfields, 'object' => $object, 'obj' => $obj, 'i' => $i, 'totalarray' => &$totalarray);
705 $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object); // Note that $action and $object may have been modified by hook
706 print $hookmanager->resPrint;
707 // Action column
708 print '<td class="nowrap center">';
709 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
710 $selected = 0;
711 if (in_array($object->id, $arrayofselected)) {
712 $selected = 1;
713 }
714 print '<input id="cb' . $object->id . '" class="flat checkforselect" type="checkbox" name="toselect[]" value="' . $object->id . '"' . ($selected ? ' checked="checked"' : '') . '>';
715 }
716 print '</td>';
717 if (!$i) {
718 $totalarray['nbfield']++;
719 }
720
721 print '</tr>' . "\n";
722
723 $i++;
724 }
725
726 // Show total line
727 include DOL_DOCUMENT_ROOT . '/core/tpl/list_print_total.tpl.php';
728
729 // If no record found
730 if ($num == 0) {
731 $colspan = 1;
732 foreach ($arrayfields as $key => $val) {
733 if (!empty($val['checked'])) {
734 $colspan++;
735 }
736 }
737 print '<tr><td colspan="' . $colspan . '"><span class="opacitymedium">' . $langs->trans("NoRecordFound") . '</span></td></tr>';
738 }
739
740
741 $db->free($resql);
742
743 $parameters = array('arrayfields' => $arrayfields, 'sql' => $sql);
744 $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object); // Note that $action and $object may have been modified by hook
745 print $hookmanager->resPrint;
746
747 print '</table>' . "\n";
748 print '</div>' . "\n";
749
750 print '</form>' . "\n";
751
752 if (in_array('builddoc', array_keys($arrayofmassactions)) && ($nbtotalofrecords === '' || $nbtotalofrecords)) {
753 $hidegeneratedfilelistifempty = 1;
754 if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
755 $hidegeneratedfilelistifempty = 0;
756 }
757
758 require_once DOL_DOCUMENT_ROOT . '/core/class/html.formfile.class.php';
759 $formfile = new FormFile($db);
760
761 // Show list of available documents
762 $urlsource = $_SERVER['PHP_SELF'] . '?sortfield=' . $sortfield . '&sortorder=' . $sortorder;
763 $urlsource .= str_replace('&amp;', '&', $param);
764
765 $filedir = $diroutputmassaction;
766 $genallowed = $permissiontoread;
767 $delallowed = $permissiontoadd;
768
769 print $formfile->showdocuments('massfilesarea_hrm', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
770 }
771}
772
773
774
775
782{
783 global $user, $langs, $db, $conf, $extrafields, $hookmanager, $permissiontoadd, $permissiontodelete;
784
785 $action = GETPOST('action', 'aZ09') ? GETPOST('action', 'aZ09') : 'view'; // The action 'add', 'create', 'edit', 'update', 'view', ...
786 $massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists)
787 $show_files = GETPOST('show_files', 'int'); // Show files area generated by bulk actions ?
788 $confirm = GETPOST('confirm', 'alpha'); // Result of a confirmation
789 $cancel = GETPOST('cancel', 'alpha'); // We click on a Cancel button
790 $toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list
791 $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'positionlist'; // To manage different context of search
792 $optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
793 $id = GETPOST('id', 'int');
794 $fk_job = GETPOST('fk_job', 'int');
795
796 // Load variable for pagination
797 $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
798 $sortfield = GETPOST('sortfield', 'aZ09comma');
799 $sortorder = GETPOST('sortorder', 'aZ09comma');
800 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
801 if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
802 // If $page is not defined, or '' or -1 or if we click on clear filters
803 $page = 0;
804 }
805 $offset = $limit * $page;
806 $pageprev = $page - 1;
807 $pagenext = $page + 1;
808
809 // Initialize technical objects
810 $object = new Position($db);
811
812 $extrafields = new ExtraFields($db);
813 $diroutputmassaction = $conf->hrm->dir_output . '/temp/massgeneration/' . $user->id;
814 $hookmanager->initHooks(array('positiontablist')); // Note that conf->hooks_modules contains array
815
816 // Fetch optionals attributes and labels
817 $extrafields->fetch_name_optionals_label($object->table_element);
818 //$extrafields->fetch_name_optionals_label($object->table_element_line);
819
820 $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
821
822 // Default sort order (if not yet defined by previous GETPOST)
823 if (!$sortfield) {
824 reset($object->fields); // Reset is required to avoid key() to return null.
825 $sortfield = "t." . key($object->fields); // Set here default search field. By default 1st field in definition.
826 }
827 if (!$sortorder) {
828 $sortorder = "ASC";
829 }
830
831 // Initialize array of search criterias
832 $search_all = GETPOST('search_all', 'alphanohtml') ? GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml');
833 $search = array();
834 foreach ($object->fields as $key => $val) {
835 if (GETPOST('search_' . $key, 'alpha') !== '') {
836 $search[$key] = GETPOST('search_' . $key, 'alpha');
837 }
838 if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
839 $search[$key . '_dtstart'] = dol_mktime(0, 0, 0, GETPOST('search_' . $key . '_dtstartmonth', 'int'), GETPOST('search_' . $key . '_dtstartday', 'int'), GETPOST('search_' . $key . '_dtstartyear', 'int'));
840 $search[$key . '_dtend'] = dol_mktime(23, 59, 59, GETPOST('search_' . $key . '_dtendmonth', 'int'), GETPOST('search_' . $key . '_dtendday', 'int'), GETPOST('search_' . $key . '_dtendyear', 'int'));
841 }
842 }
843
844 // List of fields to search into when doing a "search in all"
845 $fieldstosearchall = array();
846 foreach ($object->fields as $key => $val) {
847 if (!empty($val['searchall'])) {
848 $fieldstosearchall['t.' . $key] = $val['label'];
849 }
850 }
851
852 // Definition of array of fields for columns
853 $arrayfields = array();
854 foreach ($object->fields as $key => $val) {
855 // If $val['visible']==0, then we never show the field
856 if (!empty($val['visible'])) {
857 $visible = (int) dol_eval($val['visible'], 1, 1, '1');
858 $arrayfields['t.' . $key] = array(
859 'label' => $val['label'],
860 'checked' => (($visible < 0) ? 0 : 1),
861 'enabled' => ($visible != 3 && dol_eval($val['enabled'], 1, 1, '1')),
862 'position' => $val['position'],
863 'help' => isset($val['help']) ? $val['help'] : ''
864 );
865 }
866 }
867 // Extra fields
868 include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_array_fields.tpl.php';
869
870 $object->fields = dol_sort_array($object->fields, 'position');
871 $arrayfields = dol_sort_array($arrayfields, 'position');
872
873 // Security check
874 if (empty($conf->hrm->enabled)) {
875 accessforbidden('Module not enabled');
876 }
877
878 // Security check (enable the most restrictive one)
879 if ($user->socid > 0) accessforbidden();
880 //if ($user->socid > 0) accessforbidden();
881 //$socid = 0; if ($user->socid > 0) $socid = $user->socid;
882 //$isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
883 //restrictedArea($user, $object->element, $object->id, $object->table_element, '', 'fk_soc', 'rowid', $isdraft);
884 //if (empty($conf->hrm->enabled)) accessforbidden();
885 //if (!$permissiontoread) accessforbidden();
886
887
888 // Build and execute select
889 // --------------------------------------------------------------------
890 $sql = 'SELECT ';
891 $sql .= $object->getFieldList('t');
892 // Add fields from extrafields
893 if (!empty($extrafields->attributes[$object->table_element]['label'])) {
894 foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
895 $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef." . $key . " as options_" . $key . ', ' : '');
896 }
897 }
898 // Add fields from hooks
899 $parameters = array();
900 $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object); // Note that $action and $object may have been modified by hook
901 $sql .= $hookmanager->resPrint;
902 $sql = preg_replace('/,\s*$/', '', $sql);
903 $sql .= " FROM " . MAIN_DB_PREFIX . $object->table_element . " as t";
904 if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
905 $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . $object->table_element . "_extrafields as ef on (t.rowid = ef.fk_object)";
906 }
907 // Add table from hooks
908 $parameters = array();
909 $reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object); // Note that $action and $object may have been modified by hook
910 $sql .= $hookmanager->resPrint;
911 if ($object->ismultientitymanaged == 1) {
912 $sql .= " WHERE t.entity IN (" . getEntity($object->element) . ")";
913 } else {
914 $sql .= " WHERE 1 = 1";
915 }
916 $sql .= " AND t.fk_job = " . ((int) $fk_job) . " ";
917
918 foreach ($search as $key => $val) {
919 if (array_key_exists($key, $object->fields)) {
920 if ($key == 'status' && $search[$key] == -1) {
921 continue;
922 }
923 $mode_search = (($object->isInt($object->fields[$key]) || $object->isFloat($object->fields[$key])) ? 1 : 0);
924 if ((strpos($object->fields[$key]['type'], 'integer:') === 0) || (strpos($object->fields[$key]['type'], 'sellist:') === 0) || !empty($object->fields[$key]['arrayofkeyval'])) {
925 if ($search[$key] == '-1' || $search[$key] === '0') {
926 $search[$key] = '';
927 }
928 $mode_search = 2;
929 }
930 if ($search[$key] != '') {
931 $sql .= natural_search($key, $search[$key], (($key == 'status') ? 2 : $mode_search));
932 }
933 } else {
934 if (preg_match('/(_dtstart|_dtend)$/', $key) && $search[$key] != '') {
935 $columnName = preg_replace('/(_dtstart|_dtend)$/', '', $key);
936 if (preg_match('/^(date|timestamp|datetime)/', $object->fields[$columnName]['type'])) {
937 if (preg_match('/_dtstart$/', $key)) {
938 $sql .= " AND t." . $columnName . " >= '" . $db->idate($search[$key]) . "'";
939 }
940 if (preg_match('/_dtend$/', $key)) {
941 $sql .= " AND t." . $columnName . " <= '" . $db->idate($search[$key]) . "'";
942 }
943 }
944 }
945 }
946 }
947 if ($search_all) {
948 $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
949 }
950 //$sql.= dolSqlDateFilter("t.field", $search_xxxday, $search_xxxmonth, $search_xxxyear);
951 // Add where from extra fields
952 include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_search_sql.tpl.php';
953 // Add where from hooks
954 $parameters = array();
955 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object); // Note that $action and $object may have been modified by hook
956 $sql .= $hookmanager->resPrint;
957
958 /* If a group by is required
959 $sql .= " GROUP BY ";
960 foreach($object->fields as $key => $val) {
961 $sql .= "t.".$key.", ";
962 }
963 // Add fields from extrafields
964 if (!empty($extrafields->attributes[$object->table_element]['label'])) {
965 foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
966 $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? "ef.".$key.', ' : '');
967 }
968 }
969 // Add where from hooks
970 $parameters = array();
971 $reshook = $hookmanager->executeHooks('printFieldListGroupBy', $parameters, $object); // Note that $action and $object may have been modified by hook
972 $sql .= $hookmanager->resPrint;
973 $sql = preg_replace('/,\s*$/', '', $sql);
974 */
975
976 $sql .= $db->order($sortfield, $sortorder);
977
978 // Count total nb of records
979 $nbtotalofrecords = '';
980 if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
981 $resql = $db->query($sql);
982 $nbtotalofrecords = $db->num_rows($resql);
983 if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0
984 $page = 0;
985 $offset = 0;
986 }
987 }
988 // if total of record found is smaller than limit, no need to do paging and to restart another select with limits set.
989 if (is_numeric($nbtotalofrecords) && ($limit > $nbtotalofrecords || empty($limit))) {
990 $num = $nbtotalofrecords;
991 } else {
992 if ($limit) {
993 $sql .= $db->plimit($limit + 1, $offset);
994 }
995
996 $resql = $db->query($sql);
997 if (!$resql) {
998 dol_print_error($db);
999 exit;
1000 }
1001
1002 $num = $db->num_rows($resql);
1003 }
1004
1005 // Direct jump if only one record found
1006 if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $search_all && !$page) {
1007 $obj = $db->fetch_object($resql);
1008 $id = $obj->rowid;
1009 header("Location: " . dol_buildpath('/hrm/position.php', 1) . '?id=' . $id);
1010 exit;
1011 }
1012
1013 $arrayofselected = is_array($toselect) ? $toselect : array();
1014
1015 $param = 'fk_job='.$fk_job;
1016 if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
1017 $param .= '&contextpage='.urlencode($contextpage);
1018 }
1019 if ($limit > 0 && $limit != $conf->liste_limit) {
1020 $param .= '&limit='.((int) $limit);
1021 }
1022 foreach ($search as $key => $val) {
1023 if (is_array($search[$key]) && count($search[$key])) {
1024 foreach ($search[$key] as $skey) {
1025 $param .= '&search_'.$key.'[]='.urlencode($skey);
1026 }
1027 } else {
1028 $param .= '&search_'.$key.'='.urlencode($search[$key]);
1029 }
1030 }
1031 if ($optioncss != '') {
1032 $param .= '&optioncss='.urlencode($optioncss);
1033 }
1034 // Add $param from extra fields
1035 include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_search_param.tpl.php';
1036 // Add $param from hooks
1037 $parameters = array();
1038 $reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object); // Note that $action and $object may have been modified by hook
1039 $param .= $hookmanager->resPrint;
1040
1041 // List of mass actions available
1042 $arrayofmassactions = array(
1043 //'validate'=>img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Validate"),
1044 //'generate_doc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"),
1045 //'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
1046 //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
1047 );
1048 if ($permissiontodelete) {
1049 $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"') . $langs->trans("Delete");
1050 }
1051 if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) {
1052 $arrayofmassactions = array();
1053 }
1054 $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
1055
1056 print '<form method="POST" id="searchFormList" action="' . $_SERVER["PHP_SELF"] . '?fk_job=' . $fk_job . '">' . "\n";
1057 if ($optioncss != '') {
1058 print '<input type="hidden" name="optioncss" value="' . $optioncss . '">';
1059 }
1060 print '<input type="hidden" name="token" value="' . newToken() . '">';
1061 print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
1062 print '<input type="hidden" name="action" value="list">';
1063 print '<input type="hidden" name="massaction" value="' . $massaction . '">';
1064 print '<input type="hidden" name="sortfield" value="' . $sortfield . '">';
1065 print '<input type="hidden" name="sortorder" value="' . $sortorder . '">';
1066 print '<input type="hidden" name="page" value="' . $page . '">';
1067 print '<input type="hidden" name="contextpage" value="' . $contextpage . '">';
1068
1069 $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);
1070
1071 print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'object_' . $object->picto, 0, $newcardbutton, '', $limit, 0, 0, 1);
1072
1073 // Add code for pre mass action (confirmation or email presend form)
1074 $topicmail = "SendPositionRef";
1075 $modelmail = "position";
1076 $objecttmp = new Position($db);
1077 $trackid = 'xxxx' . $object->id;
1078 include DOL_DOCUMENT_ROOT . '/core/tpl/massactions_pre.tpl.php';
1079
1080 if ($search_all) {
1081 foreach ($fieldstosearchall as $key => $val) {
1082 $fieldstosearchall[$key] = $langs->trans($val);
1083 }
1084 print '<div class="divsearchfieldfilter">' . $langs->trans("FilterOnInto", $search_all) . join(', ', $fieldstosearchall) . '</div>';
1085 }
1086
1087 $moreforfilter = '';
1088 /*$moreforfilter.='<div class="divsearchfield">';
1089 $moreforfilter.= $langs->trans('MyFilter') . ': <input type="text" name="search_myfield" value="'.dol_escape_htmltag($search_myfield).'">';
1090 $moreforfilter.= '</div>';*/
1091
1092 $parameters = array();
1093 $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
1094 if (empty($reshook)) {
1095 $moreforfilter .= $hookmanager->resPrint;
1096 } else {
1097 $moreforfilter = $hookmanager->resPrint;
1098 }
1099
1100 if (!empty($moreforfilter)) {
1101 print '<div class="liste_titre liste_titre_bydiv centpercent">';
1102 print $moreforfilter;
1103 print '</div>';
1104 }
1105
1106 $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
1107 $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
1108 $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
1109
1110 print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
1111 print '<table class="tagtable nobottomiftotal liste' . ($moreforfilter ? " listwithfilterbefore" : "") . '">' . "\n";
1112
1113
1114 // Fields title search
1115 // --------------------------------------------------------------------
1116 print '<tr class="liste_titre">';
1117 foreach ($object->fields as $key => $val) {
1118 $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
1119 if ($key == 'status') {
1120 $cssforfield .= ($cssforfield ? ' ' : '') . 'center';
1121 } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
1122 $cssforfield .= ($cssforfield ? ' ' : '') . 'center';
1123 } elseif (in_array($val['type'], array('timestamp'))) {
1124 $cssforfield .= ($cssforfield ? ' ' : '') . 'nowrap';
1125 } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID' && empty($val['arrayofkeyval'])) {
1126 $cssforfield .= ($cssforfield ? ' ' : '') . 'right';
1127 }
1128 if (!empty($arrayfields['t.' . $key]['checked'])) {
1129 print '<td class="liste_titre' . ($cssforfield ? ' ' . $cssforfield : '') . '">';
1130 if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
1131 print $form->selectarray('search_' . $key, $val['arrayofkeyval'], (isset($search[$key]) ? $search[$key] : ''), $val['notnull'], 0, 0, '', 1, 0, 0, '', 'maxwidth100', 1);
1132 } elseif ((strpos($val['type'], 'integer:') === 0) || (strpos($val['type'], 'sellist:') === 0)) {
1133 print $object->showInputField($val, $key, (isset($search[$key]) ? $search[$key] : ''), '', '', 'search_', 'maxwidth125', 1);
1134 } elseif (!preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
1135 print '<input type="text" class="flat maxwidth75" name="search_' . $key . '" value="' . dol_escape_htmltag(isset($search[$key]) ? $search[$key] : '') . '">';
1136 } elseif (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
1137 print '<div class="nowrap">';
1138 print $form->selectDate($search[$key . '_dtstart'] ? $search[$key . '_dtstart'] : '', "search_" . $key . "_dtstart", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
1139 print '</div>';
1140 print '<div class="nowrap">';
1141 print $form->selectDate($search[$key . '_dtend'] ? $search[$key . '_dtend'] : '', "search_" . $key . "_dtend", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
1142 print '</div>';
1143 }
1144 print '</td>';
1145 }
1146 }
1147 // Extra fields
1148 include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_search_input.tpl.php';
1149
1150 // Fields from hook
1151 $parameters = array('arrayfields' => $arrayfields);
1152 $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object); // Note that $action and $object may have been modified by hook
1153 print $hookmanager->resPrint;
1154 // Action column
1155 print '<td class="liste_titre maxwidthsearch">';
1156 $searchpicto = $form->showFilterButtons();
1157 print $searchpicto;
1158 print '</td>';
1159 print '</tr>' . "\n";
1160
1161
1162 // Fields title label
1163 // --------------------------------------------------------------------
1164 print '<tr class="liste_titre">';
1165 foreach ($object->fields as $key => $val) {
1166 $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
1167 if ($key == 'status') {
1168 $cssforfield .= ($cssforfield ? ' ' : '') . 'center';
1169 } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
1170 $cssforfield .= ($cssforfield ? ' ' : '') . 'center';
1171 } elseif (in_array($val['type'], array('timestamp'))) {
1172 $cssforfield .= ($cssforfield ? ' ' : '') . 'nowrap';
1173 } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID' && empty($val['arrayofkeyval'])) {
1174 $cssforfield .= ($cssforfield ? ' ' : '') . 'right';
1175 }
1176 if (!empty($arrayfields['t.' . $key]['checked'])) {
1177 print getTitleFieldOfList($arrayfields['t.' . $key]['label'], 0, $_SERVER['PHP_SELF'], 't.' . $key, '', $param, ($cssforfield ? 'class="' . $cssforfield . '"' : ''), $sortfield, $sortorder, ($cssforfield ? $cssforfield . ' ' : '')) . "\n";
1178 }
1179 }
1180 // Extra fields
1181 include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_search_title.tpl.php';
1182 // Hook fields
1183 $parameters = array('arrayfields' => $arrayfields, 'param' => $param, 'sortfield' => $sortfield, 'sortorder' => $sortorder);
1184 $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
1185 print $hookmanager->resPrint;
1186 // Action column
1187 print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ') . "\n";
1188 print '</tr>' . "\n";
1189
1190 // Detect if we need a fetch on each output line
1191 $needToFetchEachLine = 0;
1192 if (isset($extrafields->attributes[$object->table_element]['computed']) && is_array($extrafields->attributes[$object->table_element]['computed']) && count($extrafields->attributes[$object->table_element]['computed']) > 0) {
1193 foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val) {
1194 if (!is_null($val) && preg_match('/\$object/', $val)) {
1195 $needToFetchEachLine++; // There is at least one compute field that use $object
1196 }
1197 }
1198 }
1199
1200
1201 // Loop on record
1202 // --------------------------------------------------------------------
1203 $i = 0;
1204 $totalarray = array();
1205 $totalarray['nbfield'] = 0;
1206 while ($i < ($limit ? min($num, $limit) : $num)) {
1207 $obj = $db->fetch_object($resql);
1208 if (empty($obj)) {
1209 break; // Should not happen
1210 }
1211
1212 // Store properties in $object
1213 $object->setVarsFromFetchObj($obj);
1214
1215 // Show here line of result
1216 print '<tr class="oddeven">';
1217 foreach ($object->fields as $key => $val) {
1218 $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
1219 if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
1220 $cssforfield .= ($cssforfield ? ' ' : '') . 'center';
1221 } elseif ($key == 'status') {
1222 $cssforfield .= ($cssforfield ? ' ' : '') . 'center';
1223 }
1224
1225 if (in_array($val['type'], array('timestamp'))) {
1226 $cssforfield .= ($cssforfield ? ' ' : '') . 'nowrap';
1227 } elseif ($key == 'ref') {
1228 $cssforfield .= ($cssforfield ? ' ' : '') . 'nowrap';
1229 }
1230
1231 if (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && !in_array($key, array('rowid', 'status')) && empty($val['arrayofkeyval'])) {
1232 $cssforfield .= ($cssforfield ? ' ' : '') . 'right';
1233 }
1234 //if (in_array($key, array('fk_soc', 'fk_user', 'fk_warehouse'))) $cssforfield = 'tdoverflowmax100';
1235
1236 if (!empty($arrayfields['t.' . $key]['checked'])) {
1237 print '<td' . ($cssforfield ? ' class="' . $cssforfield . '"' : '') . '>';
1238 if ($key == 'status') {
1239 print $object->getLibStatut(5);
1240 } elseif ($key == 'rowid') {
1241 print $object->getNomUrl(1);
1242 } else {
1243 print $object->showOutputField($val, $key, $object->$key, '');
1244 }
1245 print '</td>';
1246 if (!$i) {
1247 $totalarray['nbfield']++;
1248 }
1249 if (!empty($val['isameasure']) && $val['isameasure'] == 1) {
1250 if (!$i) {
1251 $totalarray['pos'][$totalarray['nbfield']] = 't.' . $key;
1252 }
1253 if (!isset($totalarray['val'])) {
1254 $totalarray['val'] = array();
1255 }
1256 if (!isset($totalarray['val']['t.' . $key])) {
1257 $totalarray['val']['t.' . $key] = 0;
1258 }
1259 $totalarray['val']['t.' . $key] += $object->$key;
1260 }
1261 }
1262 }
1263 // Extra fields
1264 include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_print_fields.tpl.php';
1265 // Fields from hook
1266 $parameters = array('arrayfields' => $arrayfields, 'object' => $object, 'obj' => $obj, 'i' => $i, 'totalarray' => &$totalarray);
1267 $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object); // Note that $action and $object may have been modified by hook
1268 print $hookmanager->resPrint;
1269 // Action column
1270 print '<td class="nowrap center">';
1271 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
1272 $selected = 0;
1273 if (in_array($object->id, $arrayofselected)) {
1274 $selected = 1;
1275 }
1276 print '<input id="cb' . $object->id . '" class="flat checkforselect" type="checkbox" name="toselect[]" value="' . $object->id . '"' . ($selected ? ' checked="checked"' : '') . '>';
1277 }
1278 print '</td>';
1279 if (!$i) {
1280 $totalarray['nbfield']++;
1281 }
1282
1283 print '</tr>' . "\n";
1284
1285 $i++;
1286 }
1287
1288 // Show total line
1289 include DOL_DOCUMENT_ROOT . '/core/tpl/list_print_total.tpl.php';
1290
1291 // If no record found
1292 if ($num == 0) {
1293 $colspan = 1;
1294 foreach ($arrayfields as $key => $val) {
1295 if (!empty($val['checked'])) {
1296 $colspan++;
1297 }
1298 }
1299 print '<tr><td colspan="' . $colspan . '"><span class="opacitymedium">' . $langs->trans("NoRecordFound") . '</span></td></tr>';
1300 }
1301
1302
1303 $db->free($resql);
1304
1305 $parameters = array('arrayfields' => $arrayfields, 'sql' => $sql);
1306 $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object); // Note that $action and $object may have been modified by hook
1307 print $hookmanager->resPrint;
1308
1309 print '</table>' . "\n";
1310 print '</div>' . "\n";
1311
1312 print '</form>' . "\n";
1313
1314 if (in_array('builddoc', array_keys($arrayofmassactions)) && ($nbtotalofrecords === '' || $nbtotalofrecords)) {
1315 $hidegeneratedfilelistifempty = 1;
1316 if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
1317 $hidegeneratedfilelistifempty = 0;
1318 }
1319
1320 require_once DOL_DOCUMENT_ROOT . '/core/class/html.formfile.class.php';
1321 $formfile = new FormFile($db);
1322
1323 // Show list of available documents
1324 $urlsource = $_SERVER['PHP_SELF'] . '?sortfield=' . $sortfield . '&sortorder=' . $sortorder;
1325 $urlsource .= str_replace('&amp;', '&', $param);
1326
1327 $filedir = $diroutputmassaction;
1328 $genallowed = $permissiontoread;
1329 $delallowed = $permissiontoadd;
1330
1331 print $formfile->showdocuments('massfilesarea_hrm', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
1332 }
1333}
1334
1335// End of page
1336llxFooter();
1337$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:56
llxFooter()
Empty footer.
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: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 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.
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.
if($action=='create') if( $job->id > 0 &&(empty( $action)||( $action !='edit' &&$action !='create')) DisplayPositionList)()
Show a list of positions for the current job.
Definition position.php:781
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.