dolibarr  17.0.4
evaluation_list.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2007-2017 Laurent Destailleur <eldy@users.sourceforge.net>
3  * Copyright (C) 2021 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
4  * Copyright (C) 2021 Greg Rastklan <greg.rastklan@atm-consulting.fr>
5  * Copyright (C) 2021 Jean-Pascal BOUDET <jean-pascal.boudet@atm-consulting.fr>
6  * Copyright (C) 2021 Grégory BLEMAND <gregory.blemand@atm-consulting.fr>
7  *
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 
29 // Load Dolibarr environment
30 require '../main.inc.php';
31 
32 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
33 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
34 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
35 
36 // load hrm libraries
37 require_once __DIR__.'/class/evaluation.class.php';
38 
39 // for other modules
40 //dol_include_once('/othermodule/class/otherobject.class.php');
41 
42 // Load translation files required by the page
43 $langs->loadLangs(array('hrm', 'other'));
44 
45 // Get Parameters
46 $action = GETPOST('action', 'aZ09') ?GETPOST('action', 'aZ09') : 'view'; // The action 'add', 'create', 'edit', 'update', 'view', ...
47 $massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists)
48 $show_files = GETPOST('show_files', 'int'); // Show files area generated by bulk actions ?
49 $confirm = GETPOST('confirm', 'alpha'); // Result of a confirmation
50 $cancel = GETPOST('cancel', 'alpha'); // We click on a Cancel button
51 $toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list
52 $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'evaluationlist'; // To manage different context of search
53 $backtopage = GETPOST('backtopage', 'alpha'); // Go back to a dedicated page
54 $optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
55 
56 $id = GETPOST('id', 'int');
57 $ref = GETPOST('ref', 'alpha');
58 
59 // Load variable for pagination
60 $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
61 $sortfield = GETPOST('sortfield', 'aZ09comma');
62 $sortorder = GETPOST('sortorder', 'aZ09comma');
63 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
64 if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
65  // If $page is not defined, or '' or -1 or if we click on clear filters
66  $page = 0;
67 }
68 $offset = $limit * $page;
69 $pageprev = $page - 1;
70 $pagenext = $page + 1;
71 
72 // Initialize technical objects
73 $object = new Evaluation($db);
74 $extrafields = new ExtraFields($db);
75 $diroutputmassaction = $conf->hrm->dir_output.'/temp/massgeneration/'.$user->id;
76 $hookmanager->initHooks(array('evaluationlist')); // Note that conf->hooks_modules contains array
77 
78 // Fetch optionals attributes and labels
79 $extrafields->fetch_name_optionals_label($object->table_element);
80 //$extrafields->fetch_name_optionals_label($object->table_element_line);
81 
82 $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
83 
84 // Default sort order (if not yet defined by previous GETPOST)
85 if (!$sortfield) {
86  reset($object->fields); // Reset is required to avoid key() to return null.
87  $sortfield = "t.".key($object->fields); // Set here default search field. By default 1st field in definition.
88 }
89 if (!$sortorder) {
90  $sortorder = "ASC";
91 }
92 
93 // Initialize array of search criterias
94 $search_all = GETPOST('search_all', 'alphanohtml') ? GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml');
95 $search = array();
96 foreach ($object->fields as $key => $val) {
97  if (GETPOST('search_'.$key, 'alpha') !== '') {
98  $search[$key] = GETPOST('search_'.$key, 'alpha');
99  }
100  if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
101  $search[$key.'_dtstart'] = dol_mktime(0, 0, 0, GETPOST('search_'.$key.'_dtstartmonth', 'int'), GETPOST('search_'.$key.'_dtstartday', 'int'), GETPOST('search_'.$key.'_dtstartyear', 'int'));
102  $search[$key.'_dtend'] = dol_mktime(23, 59, 59, GETPOST('search_'.$key.'_dtendmonth', 'int'), GETPOST('search_'.$key.'_dtendday', 'int'), GETPOST('search_'.$key.'_dtendyear', 'int'));
103  }
104 }
105 
106 // List of fields to search into when doing a "search in all"
107 $fieldstosearchall = array();
108 foreach ($object->fields as $key => $val) {
109  if (!empty($val['searchall'])) {
110  $fieldstosearchall['t.'.$key] = $val['label'];
111  }
112 }
113 
114 // Definition of array of fields for columns
115 $arrayfields = array();
116 foreach ($object->fields as $key => $val) {
117  // If $val['visible']==0, then we never show the field
118  if (!empty($val['visible'])) {
119  $visible = (int) dol_eval($val['visible'], 1, 1, '1');
120  $arrayfields['t.'.$key] = array(
121  'label'=>$val['label'],
122  'checked'=>(($visible < 0) ? 0 : 1),
123  'enabled'=>($visible != 3 && dol_eval($val['enabled'], 1, 1, '1')),
124  'position'=>$val['position'],
125  'help'=> isset($val['help']) ? $val['help'] : ''
126  );
127  }
128 }
129 // Extra fields
130 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
131 
132 $object->fields = dol_sort_array($object->fields, 'position');
133 $arrayfields = dol_sort_array($arrayfields, 'position');
134 
135 // Permissions
136 $permissiontoread = $user->hasRight('hrm', 'evaluation', 'read');
137 $permissiontoreadall = $user->hasRight('hrm', 'evaluation', 'readall');
138 $permissiontoadd = $user->hasRight('hrm', 'evaluation', 'write');
139 $permissiontodelete = $user->hasRight('hrm', 'evaluation', 'delete');
140 
141 // Security check
142 if (!isModEnabled('hrm')) {
143  accessforbidden('Module not enabled');
144 }
145 
146 // Security check (enable the most restrictive one)
147 if ($user->socid > 0) accessforbidden();
148 //if ($user->socid > 0) accessforbidden();
149 //$socid = 0; if ($user->socid > 0) $socid = $user->socid;
150 //$isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
151 //restrictedArea($user, $object->element, $object->id, $object->table_element, '', 'fk_soc', 'rowid', $isdraft);
152 //if (empty($conf->hrm->enabled)) accessforbidden();
153 if (!$permissiontoread) accessforbidden();
154 
155 
156 
157 /*
158  * Actions
159  */
160 
161 if (GETPOST('cancel', 'alpha')) {
162  $action = 'list';
163  $massaction = '';
164 }
165 if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
166  $massaction = '';
167 }
168 
169 $parameters = array();
170 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
171 if ($reshook < 0) {
172  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
173 }
174 
175 if (empty($reshook)) {
176  // Selection of new fields
177  include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
178 
179  // Purge search criteria
180  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
181  foreach ($object->fields as $key => $val) {
182  $search[$key] = '';
183  if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
184  $search[$key.'_dtstart'] = '';
185  $search[$key.'_dtend'] = '';
186  }
187  }
188  $toselect = array();
189  $search_array_options = array();
190  }
191  if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')
192  || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) {
193  $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation
194  }
195 
196  // Mass actions
197  $objectclass = 'Evaluation';
198  $objectlabel = 'Evaluation';
199  $uploaddir = $conf->hrm->dir_output;
200  include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
201 }
202 
203 
204 
205 /*
206  * View
207  */
208 
209 $form = new Form($db);
210 
211 $now = dol_now();
212 
213 //$help_url="EN:Module_Evaluation|FR:Module_Evaluation_FR|ES:Módulo_Evaluation";
214 $help_url = '';
215 $title = $langs->trans('Evaluations');
216 $morejs = array();
217 $morecss = array();
218 
219 
220 // Build and execute select
221 // --------------------------------------------------------------------
222 $sql = 'SELECT ';
223 $sql .= $object->getFieldList('t');
224 // Add fields from extrafields
225 if (!empty($extrafields->attributes[$object->table_element]['label'])) {
226  foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
227  $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');
228  }
229 }
230 // Add fields from hooks
231 $parameters = array();
232 $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object); // Note that $action and $object may have been modified by hook
233 $sql .= preg_replace('/^,/', '', $hookmanager->resPrint);
234 $sql = preg_replace('/,\s*$/', '', $sql);
235 $sql .= " FROM ".MAIN_DB_PREFIX.$object->table_element." as t";
236 if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
237  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (t.rowid = ef.fk_object)";
238 }
239 // Add table from hooks
240 $parameters = array();
241 $reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object); // Note that $action and $object may have been modified by hook
242 $sql .= $hookmanager->resPrint;
243 if ($object->ismultientitymanaged == 1) {
244  $sql .= " WHERE t.entity IN (".getEntity($object->element).")";
245 } else {
246  $sql .= " WHERE 1 = 1";
247 }
248 foreach ($search as $key => $val) {
249  if (array_key_exists($key, $object->fields)) {
250  if ($key == 'status' && $search[$key] == -1) {
251  continue;
252  }
253  $mode_search = (($object->isInt($object->fields[$key]) || $object->isFloat($object->fields[$key])) ? 1 : 0);
254  if ((strpos($object->fields[$key]['type'], 'integer:') === 0) || (strpos($object->fields[$key]['type'], 'sellist:') === 0) || !empty($object->fields[$key]['arrayofkeyval'])) {
255  if ($search[$key] == '-1' || ($search[$key] === '0' && (empty($object->fields[$key]['arrayofkeyval']) || !array_key_exists('0', $object->fields[$key]['arrayofkeyval'])))) {
256  $search[$key] = '';
257  }
258  $mode_search = 2;
259  }
260  if ($search[$key] != '') {
261  $sql .= natural_search($key, $search[$key], (($key == 'status') ? 2 : $mode_search));
262  }
263  } else {
264  if (preg_match('/(_dtstart|_dtend)$/', $key) && $search[$key] != '') {
265  $columnName=preg_replace('/(_dtstart|_dtend)$/', '', $key);
266  if (preg_match('/^(date|timestamp|datetime)/', $object->fields[$columnName]['type'])) {
267  if (preg_match('/_dtstart$/', $key)) {
268  $sql .= " AND t." . $columnName . " >= '" . $db->idate($search[$key]) . "'";
269  }
270  if (preg_match('/_dtend$/', $key)) {
271  $sql .= " AND t." . $columnName . " <= '" . $db->idate($search[$key]) . "'";
272  }
273  }
274  }
275  }
276 }
277 if ($search_all) {
278  $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
279 }
280 
281 if (empty($permissiontoreadall)) {
282  $sql.= " AND t.fk_user IN(".$db->sanitize(implode(", ", $user->getAllChildIds(1))).") ";
283 }
284 
285 //$sql.= dolSqlDateFilter("t.field", $search_xxxday, $search_xxxmonth, $search_xxxyear);
286 // Add where from extra fields
287 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
288 // Add where from hooks
289 $parameters = array();
290 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object); // Note that $action and $object may have been modified by hook
291 $sql .= $hookmanager->resPrint;
292 
293 /* If a group by is required
294 $sql .= " GROUP BY ";
295 foreach($object->fields as $key => $val) {
296  $sql .= "t.".$key.", ";
297 }
298 // Add fields from extrafields
299 if (!empty($extrafields->attributes[$object->table_element]['label'])) {
300  foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
301  $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? "ef.".$key.', ' : '');
302  }
303 }
304 // Add where from hooks
305 $parameters = array();
306 $reshook = $hookmanager->executeHooks('printFieldListGroupBy', $parameters, $object); // Note that $action and $object may have been modified by hook
307 $sql .= $hookmanager->resPrint;
308 $sql = preg_replace('/,\s*$/', '', $sql);
309 */
310 
311 $sql .= $db->order($sortfield, $sortorder);
312 
313 // Count total nb of records
314 $nbtotalofrecords = '';
315 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
316  $resql = $db->query($sql);
317  $nbtotalofrecords = $db->num_rows($resql);
318  if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0
319  $page = 0;
320  $offset = 0;
321  }
322 }
323 // if total of record found is smaller than limit, no need to do paging and to restart another select with limits set.
324 if (is_numeric($nbtotalofrecords) && ($limit > $nbtotalofrecords || empty($limit))) {
325  $num = $nbtotalofrecords;
326 } else {
327  if ($limit) {
328  $sql .= $db->plimit($limit + 1, $offset);
329  }
330 
331  $resql = $db->query($sql);
332  if (!$resql) {
333  dol_print_error($db);
334  exit;
335  }
336 
337  $num = $db->num_rows($resql);
338 }
339 
340 // Direct jump if only one record found
341 if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $search_all && !$page) {
342  $obj = $db->fetch_object($resql);
343  $id = $obj->rowid;
344  header("Location: ".dol_buildpath('/hrm/evaluation_card.php', 1).'?id='.$id);
345  exit;
346 }
347 
348 
349 // Output page
350 // --------------------------------------------------------------------
351 
352 llxHeader('', $title, $help_url, '', 0, 0, $morejs, $morecss, '', '');
353 
354 // Example : Adding jquery code
355 // print '<script type="text/javascript" language="javascript">
356 // jQuery(document).ready(function() {
357 // function init_myfunc()
358 // {
359 // jQuery("#myid").removeAttr(\'disabled\');
360 // jQuery("#myid").attr(\'disabled\',\'disabled\');
361 // }
362 // init_myfunc();
363 // jQuery("#mybutton").click(function() {
364 // init_myfunc();
365 // });
366 // });
367 // </script>';
368 
369 $arrayofselected = is_array($toselect) ? $toselect : array();
370 
371 $param = '';
372 if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
373  $param .= '&contextpage='.urlencode($contextpage);
374 }
375 if ($limit > 0 && $limit != $conf->liste_limit) {
376  $param .= '&limit='.urlencode($limit);
377 }
378 foreach ($search as $key => $val) {
379  if (is_array($search[$key]) && count($search[$key])) {
380  foreach ($search[$key] as $skey) {
381  $param .= '&search_'.$key.'[]='.urlencode($skey);
382  }
383  } else {
384  $param .= '&search_'.$key.'='.urlencode($search[$key]);
385  }
386 }
387 if ($optioncss != '') {
388  $param .= '&optioncss='.urlencode($optioncss);
389 }
390 // Add $param from extra fields
391 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
392 // Add $param from hooks
393 $parameters = array();
394 $reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object); // Note that $action and $object may have been modified by hook
395 $param .= $hookmanager->resPrint;
396 
397 // List of mass actions available
398 $arrayofmassactions = array(
399  //'validate'=>img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Validate"),
400  //'generate_doc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"),
401  //'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
402  //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
403 );
404 if ($permissiontodelete) {
405  $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
406 }
407 if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) {
408  $arrayofmassactions = array();
409 }
410 $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
411 
412 print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
413 if ($optioncss != '') {
414  print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
415 }
416 print '<input type="hidden" name="token" value="'.newToken().'">';
417 print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
418 print '<input type="hidden" name="action" value="list">';
419 print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
420 print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
421 print '<input type="hidden" name="page" value="'.$page.'">';
422 print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
423 
424 $newcardbutton = dolGetButtonTitle($langs->trans('New'), '', 'fa fa-plus-circle', dol_buildpath('/hrm/evaluation_card.php', 1).'?action=create', '', $permissiontoadd);
425 
426 print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'object_'.$object->picto, 0, $newcardbutton, '', $limit, 0, 0, 1);
427 
428 // Add code for pre mass action (confirmation or email presend form)
429 $topicmail = "SendEvaluationRef";
430 $modelmail = "evaluation";
431 $objecttmp = new Evaluation($db);
432 $trackid = 'xxxx'.$object->id;
433 include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
434 
435 if ($search_all) {
436  foreach ($fieldstosearchall as $key => $val) {
437  $fieldstosearchall[$key] = $langs->trans($val);
438  }
439  print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).join(', ', $fieldstosearchall).'</div>';
440 }
441 
442 $moreforfilter = '';
443 /*$moreforfilter.='<div class="divsearchfield">';
444 $moreforfilter.= $langs->trans('MyFilter') . ': <input type="text" name="search_myfield" value="'.dol_escape_htmltag($search_myfield).'">';
445 $moreforfilter.= '</div>';*/
446 
447 $parameters = array();
448 $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
449 if (empty($reshook)) {
450  $moreforfilter .= $hookmanager->resPrint;
451 } else {
452  $moreforfilter = $hookmanager->resPrint;
453 }
454 
455 if (!empty($moreforfilter)) {
456  print '<div class="liste_titre liste_titre_bydiv centpercent">';
457  print $moreforfilter;
458  print '</div>';
459 }
460 
461 $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
462 $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
463 $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
464 
465 print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
466 print '<table class="tagtable nobottomiftotal liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
467 
468 
469 // Fields title search
470 // --------------------------------------------------------------------
471 print '<tr class="liste_titre">';
472 foreach ($object->fields as $key => $val) {
473  $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
474  if ($key == 'status') {
475  $cssforfield .= ($cssforfield ? ' ' : '').'center';
476  } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
477  $cssforfield .= ($cssforfield ? ' ' : '').'center';
478  } elseif (in_array($val['type'], array('timestamp'))) {
479  $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
480  } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID' && empty($val['arrayofkeyval'])) {
481  $cssforfield .= ($cssforfield ? ' ' : '').'right';
482  }
483  if (!empty($arrayfields['t.'.$key]['checked'])) {
484  print '<td class="liste_titre'.($cssforfield ? ' '.$cssforfield : '').'">';
485  if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
486  print $form->selectarray('search_'.$key, $val['arrayofkeyval'], (isset($search[$key]) ? $search[$key] : ''), $val['notnull'], 0, 0, '', 1, 0, 0, '', 'maxwidth100', 1);
487  } elseif ((strpos($val['type'], 'integer:') === 0) || (strpos($val['type'], 'sellist:') === 0)) {
488  print $object->showInputField($val, $key, (isset($search[$key]) ? $search[$key] : ''), '', '', 'search_', 'maxwidth125', 1);
489  } elseif (!preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
490  print '<input type="text" class="flat maxwidth75" name="search_'.$key.'" value="'.dol_escape_htmltag(isset($search[$key]) ? $search[$key] : '').'">';
491  } elseif (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
492  print '<div class="nowrap">';
493  print $form->selectDate($search[$key.'_dtstart'] ? $search[$key.'_dtstart'] : '', "search_".$key."_dtstart", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
494  print '</div>';
495  print '<div class="nowrap">';
496  print $form->selectDate($search[$key.'_dtend'] ? $search[$key.'_dtend'] : '', "search_".$key."_dtend", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
497  print '</div>';
498  }
499  print '</td>';
500  }
501 }
502 // Extra fields
503 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
504 
505 // Fields from hook
506 $parameters = array('arrayfields'=>$arrayfields);
507 $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object); // Note that $action and $object may have been modified by hook
508 print $hookmanager->resPrint;
509 // Action column
510 print '<td class="liste_titre maxwidthsearch">';
511 $searchpicto = $form->showFilterButtons();
512 print $searchpicto;
513 print '</td>';
514 print '</tr>'."\n";
515 
516 
517 // Fields title label
518 // --------------------------------------------------------------------
519 print '<tr class="liste_titre">';
520 foreach ($object->fields as $key => $val) {
521  $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
522  if ($key == 'status') {
523  $cssforfield .= ($cssforfield ? ' ' : '').'center';
524  } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
525  $cssforfield .= ($cssforfield ? ' ' : '').'center';
526  } elseif (in_array($val['type'], array('timestamp'))) {
527  $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
528  } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID' && empty($val['arrayofkeyval'])) {
529  $cssforfield .= ($cssforfield ? ' ' : '').'right';
530  }
531  if (!empty($arrayfields['t.'.$key]['checked'])) {
532  print getTitleFieldOfList($arrayfields['t.'.$key]['label'], 0, $_SERVER['PHP_SELF'], 't.'.$key, '', $param, ($cssforfield ? 'class="'.$cssforfield.'"' : ''), $sortfield, $sortorder, ($cssforfield ? $cssforfield.' ' : ''))."\n";
533  }
534 }
535 // Extra fields
536 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
537 // Hook fields
538 $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
539 $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
540 print $hookmanager->resPrint;
541 // Action column
542 print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
543 print '</tr>'."\n";
544 
545 
546 // Detect if we need a fetch on each output line
547 $needToFetchEachLine = 0;
548 if (isset($extrafields->attributes[$object->table_element]['computed']) && is_array($extrafields->attributes[$object->table_element]['computed']) && count($extrafields->attributes[$object->table_element]['computed']) > 0) {
549  foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val) {
550  if (preg_match('/\$object/', $val)) {
551  $needToFetchEachLine++; // There is at least one compute field that use $object
552  }
553  }
554 }
555 
556 
557 // Loop on record
558 // --------------------------------------------------------------------
559 $i = 0;
560 $totalarray = array();
561 $totalarray['nbfield'] = 0;
562 while ($i < ($limit ? min($num, $limit) : $num)) {
563  $obj = $db->fetch_object($resql);
564  if (empty($obj)) {
565  break; // Should not happen
566  }
567 
568  // Store properties in $object
569  $object->setVarsFromFetchObj($obj);
570 
571  // Show here line of result
572  print '<tr class="oddeven">';
573  foreach ($object->fields as $key => $val) {
574  $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
575  if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
576  $cssforfield .= ($cssforfield ? ' ' : '').'center';
577  } elseif ($key == 'status') {
578  $cssforfield .= ($cssforfield ? ' ' : '').'center';
579  }
580 
581  if (in_array($val['type'], array('timestamp'))) {
582  $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
583  } elseif ($key == 'ref') {
584  $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
585  }
586 
587  if (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && !in_array($key, array('rowid', 'status')) && empty($val['arrayofkeyval'])) {
588  $cssforfield .= ($cssforfield ? ' ' : '').'right';
589  }
590  //if (in_array($key, array('fk_soc', 'fk_user', 'fk_warehouse'))) $cssforfield = 'tdoverflowmax100';
591 
592  if (!empty($arrayfields['t.'.$key]['checked'])) {
593  print '<td'.($cssforfield ? ' class="'.$cssforfield.'"' : '').'>';
594  if ($key == 'status') {
595  print $object->getLibStatut(5);
596  } elseif ($key == 'rowid') {
597  print $object->showOutputField($val, $key, $object->id, '');
598  } else {
599  print $object->showOutputField($val, $key, $object->$key, '');
600  }
601  print '</td>';
602  if (!$i) {
603  $totalarray['nbfield']++;
604  }
605  if (!empty($val['isameasure']) && $val['isameasure'] == 1) {
606  if (!$i) {
607  $totalarray['pos'][$totalarray['nbfield']] = 't.'.$key;
608  }
609  if (!isset($totalarray['val'])) {
610  $totalarray['val'] = array();
611  }
612  if (!isset($totalarray['val']['t.'.$key])) {
613  $totalarray['val']['t.'.$key] = 0;
614  }
615  $totalarray['val']['t.'.$key] += $object->$key;
616  }
617  }
618  }
619  // Extra fields
620  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
621  // Fields from hook
622  $parameters = array('arrayfields'=>$arrayfields, 'object'=>$object, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
623  $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object); // Note that $action and $object may have been modified by hook
624  print $hookmanager->resPrint;
625  // Action column
626  print '<td class="nowrap center">';
627  if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
628  $selected = 0;
629  if (in_array($object->id, $arrayofselected)) {
630  $selected = 1;
631  }
632  print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
633  }
634  print '</td>';
635  if (!$i) {
636  $totalarray['nbfield']++;
637  }
638 
639  print '</tr>'."\n";
640 
641  $i++;
642 }
643 
644 // Show total line
645 include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
646 
647 // If no record found
648 if ($num == 0) {
649  $colspan = 1;
650  foreach ($arrayfields as $key => $val) {
651  if (!empty($val['checked'])) {
652  $colspan++;
653  }
654  }
655  print '<tr><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoRecordFound").'</td></tr>';
656 }
657 
658 
659 $db->free($resql);
660 
661 $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
662 $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object); // Note that $action and $object may have been modified by hook
663 print $hookmanager->resPrint;
664 
665 print '</table>'."\n";
666 print '</div>'."\n";
667 
668 print '</form>'."\n";
669 
670 if (in_array('builddoc', $arrayofmassactions) && ($nbtotalofrecords === '' || $nbtotalofrecords)) {
671  $hidegeneratedfilelistifempty = 1;
672  if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
673  $hidegeneratedfilelistifempty = 0;
674  }
675 
676  require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
677  $formfile = new FormFile($db);
678 
679  // Show list of available documents
680  $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
681  $urlsource .= str_replace('&amp;', '&', $param);
682 
683  $filedir = $diroutputmassaction;
684  $genallowed = $permissiontoread;
685  $delallowed = $permissiontoadd;
686 
687  print $formfile->showdocuments('massfilesarea_hrm', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
688 }
689 
690 // End of page
691 llxFooter();
692 $db->close();
if(GETPOST('button_removefilter_x', 'alpha')||GETPOST('button_removefilter.x', 'alpha')||GETPOST('button_removefilter', 'alpha')) if(GETPOST('button_search_x', 'alpha')||GETPOST('button_search.x', 'alpha')||GETPOST('button_search', 'alpha')) if($action=="save" &&empty($cancel)) $help_url
View.
Definition: agenda.php:118
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 for Evaluation.
Class to manage standard extra fields.
Class to offer components to list and upload files.
Class to manage generation of HTML components Only common components must be here.
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:745
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
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...
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
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.
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...
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
dol_now($mode='auto')
Return date for now.
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.
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.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
isModEnabled($module)
Is Dolibarr module enabled.
$nbtotalofrecords
Count total nb of records.
Definition: list.php:329
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.