dolibarr  13.0.2
list.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2011 Dimitri Mouillard <dmouillard@teclib.com>
3  * Copyright (C) 2013-2020 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2012-2016 Regis Houssin <regis.houssin@inodbox.com>
5  * Copyright (C) 2018 Charlene Benke <charlie@patas-monkey.com>
6  * Copyright (C) 2019 Frédéric France <frederic.france@netlogic.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 require '../main.inc.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
33 require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
34 require_once DOL_DOCUMENT_ROOT.'/user/class/usergroup.class.php';
35 require_once DOL_DOCUMENT_ROOT.'/holiday/class/holiday.class.php';
36 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
37 require_once DOL_DOCUMENT_ROOT.'/core/lib/usergroups.lib.php';
38 
39 // Load translation files required by the page
40 $langs->loadLangs(array('users', 'other', 'holiday', 'hrm'));
41 
42 // Protection if external user
43 if ($user->socid > 0) accessforbidden();
44 
45 $action = GETPOST('action', 'aZ09'); // The action 'add', 'create', 'edit', 'update', 'view', ...
46 $massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists)
47 $show_files = GETPOST('show_files', 'int'); // Show files area generated by bulk actions ?
48 $confirm = GETPOST('confirm', 'alpha'); // Result of a confirmation
49 $cancel = GETPOST('cancel', 'alpha'); // We click on a Cancel button
50 $toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list
51 $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'holidaylist'; // To manage different context of search
52 
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 
58 $childids = $user->getAllChildIds(1);
59 
60 // Security check
61 $socid = 0;
62 if ($user->socid > 0) // Protection if external user
63 {
64  //$socid = $user->socid;
66 }
67 $result = restrictedArea($user, 'holiday', '', '');
68 // If we are on the view of a specific user
69 if ($id > 0)
70 {
71  $canread = 0;
72  if ($id == $user->id) $canread = 1;
73  if (!empty($user->rights->holiday->readall)) $canread = 1;
74  if (!empty($user->rights->holiday->read) && in_array($id, $childids)) $canread = 1;
75  if (!$canread)
76  {
78  }
79 }
80 
81 $diroutputmassaction = $conf->holiday->dir_output.'/temp/massgeneration/'.$user->id;
82 
83 
84 // Load variable for pagination
85 $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
86 $sortfield = GETPOST('sortfield', 'aZ09comma');
87 $sortorder = GETPOST('sortorder', 'aZ09comma');
88 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
89 if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
90 $offset = $limit * $page;
91 $pageprev = $page - 1;
92 $pagenext = $page + 1;
93 if (!$sortorder) $sortorder = "DESC";
94 if (!$sortfield) $sortfield = "cp.rowid";
95 
96 $sall = trim((GETPOST('search_all', 'alphanohtml') != '') ?GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml'));
97 $search_ref = GETPOST('search_ref', 'alphanohtml');
98 $search_day_create = GETPOST('search_day_create', 'int');
99 $search_month_create = GETPOST('search_month_create', 'int');
100 $search_year_create = GETPOST('search_year_create', 'int');
101 $search_day_start = GETPOST('search_day_start', 'int');
102 $search_month_start = GETPOST('search_month_start', 'int');
103 $search_year_start = GETPOST('search_year_start', 'int');
104 $search_day_end = GETPOST('search_day_end', 'int');
105 $search_month_end = GETPOST('search_month_end', 'int');
106 $search_year_end = GETPOST('search_year_end', 'int');
107 $search_employee = GETPOST('search_employee', 'int');
108 $search_valideur = GETPOST('search_valideur', 'int');
109 $search_status = GETPOST('search_statut', 'int');
110 $search_type = GETPOST('search_type', 'int');
111 
112 // Initialize technical objects
113 $object = new Holiday($db);
114 $extrafields = new ExtraFields($db);
115 $hookmanager->initHooks(array('holidaylist')); // Note that conf->hooks_modules contains array
116 
117 // Fetch optionals attributes and labels
118 $extrafields->fetch_name_optionals_label($object->table_element);
119 
120 $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
121 
122 // List of fields to search into when doing a "search in all"
123 $fieldstosearchall = array(
124  'cp.ref'=>'Ref',
125  'cp.description'=>'Description',
126  'uu.lastname'=>'EmployeeLastname',
127  'uu.firstname'=>'EmployeeFirstname',
128  'uu.login'=>'Login'
129 );
130 
131 $arrayfields = array(
132  'cp.ref'=>array('label'=>$langs->trans("Ref"), 'checked'=>1),
133  'cp.fk_user'=>array('label'=>$langs->trans("Employee"), 'checked'=>1, 'position'=>20),
134  'cp.fk_validator'=>array('label'=>$langs->trans("ValidatorCP"), 'checked'=>1, 'position'=>30),
135  'cp.fk_type'=>array('label'=>$langs->trans("Type"), 'checked'=>1, 'position'=>35),
136  'duration'=>array('label'=>$langs->trans("NbUseDaysCPShort"), 'checked'=>1, 'position'=>38),
137  'cp.date_debut'=>array('label'=>$langs->trans("DateStart"), 'checked'=>1, 'position'=>40),
138  'cp.date_fin'=>array('label'=>$langs->trans("DateEnd"), 'checked'=>1, 'position'=>42),
139  'cp.date_valid'=>array('label'=>$langs->trans("DateValidation"), 'checked'=>1, 'position'=>60),
140  'cp.date_approve'=>array('label'=>$langs->trans("DateApprove"), 'checked'=>1, 'position'=>70),
141  'cp.date_create'=>array('label'=>$langs->trans("DateCreation"), 'checked'=>0, 'position'=>500),
142  'cp.tms'=>array('label'=>$langs->trans("DateModificationShort"), 'checked'=>0, 'position'=>501),
143  'cp.statut'=>array('label'=>$langs->trans("Status"), 'checked'=>1, 'position'=>1000),
144 );
145 // Extra fields
146 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
147 
148 if (empty($conf->holiday->enabled))
149 {
150  llxHeader('', $langs->trans('CPTitreMenu'));
151  print '<div class="tabBar">';
152  print '<span style="color: #FF0000;">'.$langs->trans('NotActiveModCP').'</span>';
153  print '</div>';
154  llxFooter();
155  exit();
156 }
157 
158 
159 /*
160  * Actions
161  */
162 
163 if (GETPOST('cancel', 'alpha')) { $action = 'list'; $massaction = ''; }
164 if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { $massaction = ''; }
165 
166 $parameters = array('socid'=>$socid);
167 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
168 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
169 
170 if (empty($reshook))
171 {
172  // Selection of new fields
173  include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
174 
175  // Purge search criteria
176  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
177  {
178  $search_ref = "";
179  $search_month_create = "";
180  $search_year_create = "";
181  $search_month_start = "";
182  $search_year_start = "";
183  $search_month_end = "";
184  $search_year_end = "";
185  $search_employee = "";
186  $search_valideur = "";
187  $search_status = "";
188  $search_type = '';
189  $toselect = '';
190  $search_array_options = array();
191  }
192  if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')
193  || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha'))
194  {
195  $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation
196  }
197 
198  // Mass actions
199  $objectclass = 'Holiday';
200  $objectlabel = 'Holiday';
201  $permissiontoread = $user->rights->holiday->read;
202  $permissiontodelete = $user->rights->holiday->delete;
203  $uploaddir = $conf->holiday->dir_output;
204  include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
205 }
206 
207 
208 
209 
210 /*
211  * View
212  */
213 
214 $form = new Form($db);
215 $formother = new FormOther($db);
216 $formfile = new FormFile($db);
217 
218 $fuser = new User($db);
219 $holidaystatic = new Holiday($db);
220 
221 // Update sold
222 $result = $object->updateBalance();
223 
224 $title = $langs->trans('CPTitreMenu');
225 llxHeader('', $title);
226 
227 $max_year = 5;
228 $min_year = 10;
229 
230 // Get current user id
231 $user_id = $user->id;
232 
233 if ($id > 0)
234 {
235  // Charge utilisateur edite
236  $fuser->fetch($id, '', '', 1);
237  $fuser->getrights();
238  $user_id = $fuser->id;
239 
240  $search_employee = $user_id;
241 }
242 
243 // Récupération des congés payés de l'utilisateur ou de tous les users de sa hierarchy
244 // Load array $object->holiday
245 
246 $sql = "SELECT";
247 $sql .= " cp.rowid,";
248 $sql .= " cp.ref,";
249 
250 $sql .= " cp.fk_user,";
251 $sql .= " cp.fk_type,";
252 $sql .= " cp.date_create,";
253 $sql .= " cp.tms as date_update,";
254 $sql .= " cp.description,";
255 $sql .= " cp.date_debut,";
256 $sql .= " cp.date_fin,";
257 $sql .= " cp.halfday,";
258 $sql .= " cp.statut as status,";
259 $sql .= " cp.fk_validator,";
260 $sql .= " cp.date_valid,";
261 $sql .= " cp.fk_user_valid,";
262 $sql .= " cp.date_refuse,";
263 $sql .= " cp.fk_user_refuse,";
264 $sql .= " cp.date_cancel,";
265 $sql .= " cp.fk_user_cancel,";
266 $sql .= " cp.detail_refuse,";
267 
268 $sql .= " uu.lastname as user_lastname,";
269 $sql .= " uu.firstname as user_firstname,";
270 $sql .= " uu.admin as user_admin,";
271 $sql .= " uu.email as user_email,";
272 $sql .= " uu.login as user_login,";
273 $sql .= " uu.statut as user_status,";
274 $sql .= " uu.photo as user_photo,";
275 
276 $sql .= " ua.lastname as validator_lastname,";
277 $sql .= " ua.firstname as validator_firstname,";
278 $sql .= " ua.admin as validator_admin,";
279 $sql .= " ua.email as validator_email,";
280 $sql .= " ua.login as validator_login,";
281 $sql .= " ua.statut as validator_status,";
282 $sql .= " ua.photo as validator_photo";
283 // Add fields from extrafields
284 if (!empty($extrafields->attributes[$object->table_element]['label'])) {
285  foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key.' as options_'.$key : '');
286 }
287 // Add fields from hooks
288 $parameters = array();
289 $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook
290 $sql .= $hookmanager->resPrint;
291 $sql .= " FROM ".MAIN_DB_PREFIX."holiday as cp";
292 if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (cp.rowid = ef.fk_object)";
293 $sql .= ", ".MAIN_DB_PREFIX."user as uu, ".MAIN_DB_PREFIX."user as ua";
294 $sql .= " WHERE cp.entity IN (".getEntity('holiday').")";
295 $sql .= " AND cp.fk_user = uu.rowid AND cp.fk_validator = ua.rowid "; // Hack pour la recherche sur le tableau
296 // Search all
297 if (!empty($sall)) $sql .= natural_search(array_keys($fieldstosearchall), $sall);
298 // Ref
299 if (!empty($search_ref)) $sql .= natural_search("cp.ref", $search_ref);
300 // Start date
301 $sql .= dolSqlDateFilter("cp.date_debut", $search_day_start, $search_month_start, $search_year_start);
302 // End date
303 $sql .= dolSqlDateFilter("cp.date_fin", $search_day_end, $search_month_end, $search_year_end);
304 // Create date
305 $sql .= dolSqlDateFilter("cp.date_create", $search_day_create, $search_month_create, $search_year_create);
306 // Employee
307 if (!empty($search_employee) && $search_employee != -1) {
308  $sql .= " AND cp.fk_user = '".$db->escape($search_employee)."'\n";
309 }
310 // Validator
311 if (!empty($search_valideur) && $search_valideur != -1) {
312  $sql .= " AND cp.fk_validator = '".$db->escape($search_valideur)."'\n";
313 }
314 // Type
315 if (!empty($search_type) && $search_type != -1) {
316  $sql .= ' AND cp.fk_type IN ('.$db->sanitize($db->escape($search_type)).')';
317 }
318 // Status
319 if (!empty($search_status) && $search_status != -1) {
320  $sql .= " AND cp.statut = '".$db->escape($search_status)."'\n";
321 }
322 
323 if (empty($user->rights->holiday->readall)) $sql .= ' AND cp.fk_user IN ('.join(',', $childids).')';
324 if ($id > 0) $sql .= " AND cp.fk_user IN (".$id.")";
325 
326 // Add where from extra fields
327 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
328 // Add where from hooks
329 $parameters = array();
330 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by hook
331 $sql .= $hookmanager->resPrint;
332 
333 $sql .= $db->order($sortfield, $sortorder);
334 
335 // Count total nb of records
336 $nbtotalofrecords = '';
337 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
338 {
339  $result = $db->query($sql);
340  $nbtotalofrecords = $db->num_rows($result);
341  if (($page * $limit) > $nbtotalofrecords) // if total resultset is smaller then paging size (filtering), goto and load page 0
342  {
343  $page = 0;
344  $offset = 0;
345  }
346 }
347 
348 $sql .= $db->plimit($limit + 1, $offset);
349 
350 
351 //print $sql;
352 $resql = $db->query($sql);
353 if ($resql)
354 {
355  $num = $db->num_rows($resql);
356 
357  $arrayofselected = is_array($toselect) ? $toselect : array();
358 
359  $param = '';
360  if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.urlencode($contextpage);
361  if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.urlencode($limit);
362  if ($optioncss != '') $param .= '&optioncss='.urlencode($optioncss);
363  if ($search_ref) $param .= '&search_ref='.urlencode($search_ref);
364  if ($search_day_create) $param .= '&search_day_create='.urlencode($search_day_create);
365  if ($search_month_create) $param .= '&search_month_create='.urlencode($search_month_create);
366  if ($search_year_create) $param .= '&search_year_create='.urlencode($search_year_create);
367  if ($search_day_start) $param .= '&search_day_start='.urlencode($search_day_start);
368  if ($search_month_start) $param .= '&search_month_start='.urlencode($search_month_start);
369  if ($search_year_start) $param .= '&search_year_start='.urlencode($search_year_start);
370  if ($search_day_end) $param .= '&search_day_end='.urlencode($search_day_end);
371  if ($search_month_end) $param .= '&search_month_end='.urlencode($search_month_end);
372  if ($search_year_end) $param .= '&search_year_end='.urlencode($search_year_end);
373  if ($search_employee > 0) $param .= '&search_employee='.urlencode($search_employee);
374  if ($search_valideur > 0) $param .= '&search_valideur='.urlencode($search_valideur);
375  if ($search_type > 0) $param .= '&search_type='.urlencode($search_type);
376  if ($search_status > 0) $param .= '&search_status='.urlencode($search_status);
377  // Add $param from extra fields
378  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
379 
380  // List of mass actions available
381  $arrayofmassactions = array(
382  //'generate_doc'=>$langs->trans("ReGeneratePDF"),
383  //'builddoc'=>$langs->trans("PDFMerge"),
384  //'presend'=>$langs->trans("SendByMail"),
385  );
386  if ($user->rights->holiday->supprimer) $arrayofmassactions['predelete'] = '<span class="fa fa-trash paddingrightonly"></span>'.$langs->trans("Delete");
387  if (in_array($massaction, array('presend', 'predelete'))) $arrayofmassactions = array();
388  $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
389 
390  // Lines of title fields
391  print '<form id="searchFormList" action="'.$_SERVER["PHP_SELF"].'" method="POST">'."\n";
392  if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
393  print '<input type="hidden" name="token" value="'.newToken().'">';
394  print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
395  print '<input type="hidden" name="action" value="'.($action == 'edit' ? 'update' : 'list').'">';
396  print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
397  print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
398  print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
399  if ($id > 0) print '<input type="hidden" name="id" value="'.$id.'">';
400 
401  if ($id > 0) // For user tab
402  {
403  $title = $langs->trans("User");
404  $linkback = '<a href="'.DOL_URL_ROOT.'/user/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
405  $head = user_prepare_head($fuser);
406 
407  print dol_get_fiche_head($head, 'paidholidays', $title, -1, 'user');
408 
409  dol_banner_tab($fuser, 'id', $linkback, $user->rights->user->user->lire || $user->admin);
410 
411  if (empty($conf->global->HOLIDAY_HIDE_BALANCE))
412  {
413  print '<div class="underbanner clearboth"></div>';
414 
415  print '<br>';
416 
417  showMyBalance($object, $user_id);
418  }
419 
420  print dol_get_fiche_end();
421 
422  // Buttons for actions
423 
424  print '<div class="tabsAction">';
425 
426  $canedit = (($user->id == $user_id && $user->rights->holiday->write) || ($user->id != $user_id && (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->holiday->writeall_advance))));
427 
428  if ($canedit)
429  {
430  print '<a href="'.DOL_URL_ROOT.'/holiday/card.php?action=create&fuserid='.$user_id.'" class="butAction">'.$langs->trans("AddCP").'</a>';
431  }
432 
433  print '</div>';
434  } else {
435  $title = $langs->trans("ListeCP");
436 
437  $newcardbutton = dolGetButtonTitle($langs->trans('MenuAddCP'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/holiday/card.php?action=create', '', $user->rights->holiday->write);
438 
439  print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'title_hrm', 0, $newcardbutton, '', $limit, 0, 0, 1);
440  }
441 
442  $topicmail = "Information";
443  $modelmail = "leaverequest";
444  $objecttmp = new Holiday($db);
445  $trackid = 'leav'.$object->id;
446  include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
447 
448  if ($sall)
449  {
450  foreach ($fieldstosearchall as $key => $val) $fieldstosearchall[$key] = $langs->trans($val);
451  print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $sall).join(', ', $fieldstosearchall).'</div>';
452  }
453 
454  $moreforfilter = '';
455 
456  $parameters = array();
457  $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook
458  if (empty($reshook)) $moreforfilter .= $hookmanager->resPrint;
459  else $moreforfilter = $hookmanager->resPrint;
460 
461  if (!empty($moreforfilter))
462  {
463  print '<div class="liste_titre liste_titre_bydiv centpercent">';
464  print $moreforfilter;
465  print '</div>';
466  }
467 
468  $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
469  $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
470  $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
471 
472 
473  $include = '';
474  if (empty($user->rights->holiday->readall)) $include = 'hierarchyme'; // Can see only its hierarchyl
475 
476  print '<div class="div-table-responsive">';
477  print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
478 
479 
480  // Filters
481  print '<tr class="liste_titre_filter">';
482 
483  if (!empty($arrayfields['cp.ref']['checked']))
484  {
485  print '<td class="liste_titre">';
486  print '<input class="flat maxwidth50" type="text" name="search_ref" value="'.dol_escape_htmltag($search_ref).'">';
487  print '</td>';
488  }
489 
490  if (!empty($arrayfields['cp.fk_user']['checked']))
491  {
492  $morefilter = '';
493  if (!empty($conf->global->HOLIDAY_HIDE_FOR_NON_SALARIES)) $morefilter = 'AND employee = 1';
494 
495  // User
496  $disabled = 0;
497  // If into the tab holiday of a user ($id is set in such a case)
498  if ($id && !GETPOSTISSET('search_employee'))
499  {
500  $search_employee = $id;
501  $disabled = 1;
502  }
503 
504  print '<td class="liste_titre maxwidthonsmartphone left">';
505  print $form->select_dolusers($search_employee, "search_employee", 1, "", $disabled, $include, '', 0, 0, 0, $morefilter, 0, '', 'maxwidth150');
506  print '</td>';
507  }
508 
509  // Approver
510  if (!empty($arrayfields['cp.fk_validator']['checked']))
511  {
512  if ($user->rights->holiday->readall)
513  {
514  print '<td class="liste_titre maxwidthonsmartphone left">';
515  $validator = new UserGroup($db);
516  $excludefilter = $user->admin ? '' : 'u.rowid <> '.$user->id;
517  $valideurobjects = $validator->listUsersForGroup($excludefilter);
518  $valideurarray = array();
519  foreach ($valideurobjects as $val) $valideurarray[$val->id] = $val->id;
520  print $form->select_dolusers($search_valideur, "search_valideur", 1, "", 0, $valideurarray, '', 0, 0, 0, $morefilter, 0, '', 'maxwidth150');
521  print '</td>';
522  } else {
523  print '<td class="liste_titre">&nbsp;</td>';
524  }
525  }
526 
527  // Type
528  if (!empty($arrayfields['cp.fk_type']['checked']))
529  {
530  print '<td class="liste_titre">';
531  if (empty($mysoc->country_id)) {
532  setEventMessages(null, array($langs->trans("ErrorSetACountryFirst"), $langs->trans("CompanyFoundation")), 'errors');
533  } else {
534  $typeleaves = $holidaystatic->getTypes(1, -1);
535  $arraytypeleaves = array();
536  foreach ($typeleaves as $key => $val)
537  {
538  $labeltoshow = ($langs->trans($val['code']) != $val['code'] ? $langs->trans($val['code']) : $val['label']);
539  //$labeltoshow .= ($val['delay'] > 0 ? ' ('.$langs->trans("NoticePeriod").': '.$val['delay'].' '.$langs->trans("days").')':'');
540  $arraytypeleaves[$val['rowid']] = $labeltoshow;
541  }
542  print $form->selectarray('search_type', $arraytypeleaves, $search_type, 1, 0, 0, '', 0, 0, 0, '', '', 1);
543  }
544  print '</td>';
545  }
546 
547  // Duration
548  if (!empty($arrayfields['duration']['checked']))
549  {
550  print '<td class="liste_titre">&nbsp;</td>';
551  }
552 
553  // Start date
554  if (!empty($arrayfields['cp.date_debut']['checked']))
555  {
556  print '<td class="liste_titre center nowraponall">';
557  print '<input class="flat valignmiddle maxwidth25" type="text" maxlength="2" name="search_month_start" value="'.dol_escape_htmltag($search_month_start).'">';
558  $formother->select_year($search_year_start, 'search_year_start', 1, $min_year, $max_year);
559  print '</td>';
560  }
561 
562  // End date
563  if (!empty($arrayfields['cp.date_fin']['checked']))
564  {
565  print '<td class="liste_titre center nowraponall">';
566  print '<input class="flat valignmiddle maxwidth25" type="text" maxlength="2" name="search_month_end" value="'.dol_escape_htmltag($search_month_end).'">';
567  $formother->select_year($search_year_end, 'search_year_end', 1, $min_year, $max_year);
568  print '</td>';
569  }
570 
571  // Extra fields
572  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
573  // Fields from hook
574  $parameters = array('arrayfields'=>$arrayfields);
575  $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook
576  print $hookmanager->resPrint;
577 
578  // Create date
579  if (!empty($arrayfields['cp.date_create']['checked']))
580  {
581  print '<td class="liste_titre center nowraponall">';
582  print '<input class="flat valignmiddle maxwidth25" type="text" maxlength="2" name="search_month_create" value="'.dol_escape_htmltag($search_month_create).'">';
583  $formother->select_year($search_year_create, 'search_year_create', 1, $min_year, 0);
584  print '</td>';
585  }
586 
587  // Create date
588  if (!empty($arrayfields['cp.tms']['checked']))
589  {
590  print '<td class="liste_titre center nowraponall">';
591  print '<input class="flat valignmiddle maxwidth25" type="text" maxlength="2" name="search_month_update" value="'.dol_escape_htmltag($search_month_update).'">';
592  $formother->select_year($search_year_update, 'search_year_update', 1, $min_year, 0);
593  print '</td>';
594  }
595 
596  // Status
597  if (!empty($arrayfields['cp.statut']['checked']))
598  {
599  print '<td class="liste_titre maxwidthonsmartphone maxwidth200 right">';
600  $object->selectStatutCP($search_status, 'search_status');
601  print '</td>';
602  }
603 
604  // Action column
605  print '<td class="liste_titre maxwidthsearch">';
606  $searchpicto = $form->showFilterButtons();
607  print $searchpicto;
608  print '</td>';
609 
610  print "</tr>\n";
611 
612  print '<tr class="liste_titre">';
613  if (!empty($arrayfields['cp.ref']['checked'])) print_liste_field_titre($arrayfields['cp.ref']['label'], $_SERVER["PHP_SELF"], "cp.ref", "", $param, '', $sortfield, $sortorder);
614  if (!empty($arrayfields['cp.fk_user']['checked'])) print_liste_field_titre($arrayfields['cp.fk_user']['label'], $_SERVER["PHP_SELF"], "cp.fk_user", "", $param, '', $sortfield, $sortorder);
615  if (!empty($arrayfields['cp.fk_validator']['checked'])) print_liste_field_titre($arrayfields['cp.fk_validator']['label'], $_SERVER["PHP_SELF"], "cp.fk_validator", "", $param, '', $sortfield, $sortorder);
616  if (!empty($arrayfields['cp.fk_type']['checked'])) print_liste_field_titre($arrayfields['cp.fk_type']['label'], $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder);
617  if (!empty($arrayfields['duration']['checked'])) print_liste_field_titre($arrayfields['duration']['label'], $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'right maxwidth100');
618  if (!empty($arrayfields['cp.date_debut']['checked'])) print_liste_field_titre($arrayfields['cp.date_debut']['label'], $_SERVER["PHP_SELF"], "cp.date_debut", "", $param, '', $sortfield, $sortorder, 'center ');
619  if (!empty($arrayfields['cp.date_fin']['checked'])) print_liste_field_titre($arrayfields['cp.date_fin']['label'], $_SERVER["PHP_SELF"], "cp.date_fin", "", $param, '', $sortfield, $sortorder, 'center ');
620  // Extra fields
621  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
622  // Hook fields
623  $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
624  $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook
625  print $hookmanager->resPrint;
626  if (!empty($arrayfields['cp.date_create']['checked'])) print_liste_field_titre($arrayfields['cp.date_create']['label'], $_SERVER["PHP_SELF"], "cp.date_create", "", $param, '', $sortfield, $sortorder, 'center ');
627  if (!empty($arrayfields['cp.tms']['checked'])) print_liste_field_titre($arrayfields['cp.tms']['label'], $_SERVER["PHP_SELF"], "cp.tms", "", $param, '', $sortfield, $sortorder, 'center ');
628  if (!empty($arrayfields['cp.statut']['checked'])) print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "cp.statut", "", $param, '', $sortfield, $sortorder, 'right ');
629  print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', 'align="center"', $sortfield, $sortorder, 'maxwidthsearch ');
630  print "</tr>\n";
631 
632  $listhalfday = array('morning'=>$langs->trans("Morning"), "afternoon"=>$langs->trans("Afternoon"));
633 
634 
635  // If we ask a dedicated card and not allow to see it, we force on user.
636  if ($id && empty($user->rights->holiday->readall) && !in_array($id, $childids)) {
637  $langs->load("errors");
638  print '<tr class="oddeven opacitymediuem"><td colspan="10">'.$langs->trans("NotEnoughPermissions").'</td></tr>';
639  $result = 0;
640  } elseif ($num > 0 && !empty($mysoc->country_id))
641  {
642  // Lines
643  $userstatic = new User($db);
644  $approbatorstatic = new User($db);
645 
646  $typeleaves = $object->getTypes(1, -1);
647 
648  $i = 0;
649  $totalarray = array();
650  while ($i < min($num, $limit))
651  {
652  $obj = $db->fetch_object($resql);
653 
654  // Leave request
655  $holidaystatic->id = $obj->rowid;
656  $holidaystatic->ref = ($obj->ref ? $obj->ref : $obj->rowid);
657  $holidaystatic->statut = $obj->status;
658 
659  // User
660  $userstatic->id = $obj->fk_user;
661  $userstatic->lastname = $obj->user_lastname;
662  $userstatic->firstname = $obj->user_firstname;
663  $userstatic->admin = $obj->user_admin;
664  $userstatic->email = $obj->user_email;
665  $userstatic->login = $obj->user_login;
666  $userstatic->statut = $obj->user_status;
667  $userstatic->photo = $obj->user_photo;
668 
669  // Validator
670  $approbatorstatic->id = $obj->fk_validator;
671  $approbatorstatic->lastname = $obj->validator_lastname;
672  $approbatorstatic->firstname = $obj->validator_firstname;
673  $approbatorstatic->admin = $obj->validator_admin;
674  $approbatorstatic->email = $obj->validator_email;
675  $approbatorstatic->login = $obj->validator_login;
676  $approbatorstatic->statut = $obj->validator_status;
677  $approbatorstatic->photo = $obj->validator_photo;
678 
679  $date = $obj->date_create;
680  $date_modif = $obj->date_update;
681 
682  $starthalfday = ($obj->halfday == -1 || $obj->halfday == 2) ? 'afternoon' : 'morning';
683  $endhalfday = ($obj->halfday == 1 || $obj->halfday == 2) ? 'morning' : 'afternoon';
684 
685  print '<tr class="oddeven">';
686 
687  if (!empty($arrayfields['cp.ref']['checked']))
688  {
689  print '<td class="nowraponall">';
690  print $holidaystatic->getNomUrl(1, 1);
691  print '</td>';
692  if (!$i) $totalarray['nbfield']++;
693  }
694  if (!empty($arrayfields['cp.fk_user']['checked']))
695  {
696  print '<td class="tdoverflowmax150">'.$userstatic->getNomUrl(-1, 'leave').'</td>';
697  if (!$i) $totalarray['nbfield']++;
698  }
699  if (!empty($arrayfields['cp.fk_validator']['checked']))
700  {
701  print '<td class="tdoverflowmax150">'.$approbatorstatic->getNomUrl(-1).'</td>';
702  if (!$i) $totalarray['nbfield']++;
703  }
704  if (!empty($arrayfields['cp.fk_type']['checked']))
705  {
706  print '<td>';
707  $labeltypeleavetoshow = ($langs->trans($typeleaves[$obj->fk_type]['code']) != $typeleaves[$obj->fk_type]['code'] ? $langs->trans($typeleaves[$obj->fk_type]['code']) : $typeleaves[$obj->fk_type]['label']);
708  print empty($typeleaves[$obj->fk_type]['label']) ? $langs->trans("TypeWasDisabledOrRemoved", $obj->fk_type) : $labeltypeleavetoshow;
709  print '</td>';
710  if (!$i) $totalarray['nbfield']++;
711  }
712  if (!empty($arrayfields['duration']['checked']))
713  {
714  print '<td class="right">';
715  $nbopenedday = num_open_day($db->jdate($obj->date_debut, 1), $db->jdate($obj->date_fin, 1), 0, 1, $obj->halfday);
716  print $nbopenedday.' '.$langs->trans('DurationDays');
717  print '</td>';
718  if (!$i) $totalarray['nbfield']++;
719  }
720  if (!empty($arrayfields['cp.date_debut']['checked']))
721  {
722  print '<td class="center">';
723  print dol_print_date($db->jdate($obj->date_debut), 'day');
724  print ' <span class="opacitymedium nowraponall">('.$langs->trans($listhalfday[$starthalfday]).')</span>';
725  print '</td>';
726  if (!$i) $totalarray['nbfield']++;
727  }
728  if (!empty($arrayfields['cp.date_fin']['checked']))
729  {
730  print '<td class="center">';
731  print dol_print_date($db->jdate($obj->date_fin), 'day');
732  print ' <span class="opacitymedium nowraponall">('.$langs->trans($listhalfday[$endhalfday]).')</span>';
733  print '</td>';
734  if (!$i) $totalarray['nbfield']++;
735  }
736 
737  // Extra fields
738  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
739  // Fields from hook
740  $parameters = array('arrayfields'=>$arrayfields, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
741  $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook
742  print $hookmanager->resPrint;
743 
744  // Date creation
745  if (!empty($arrayfields['cp.date_create']['checked']))
746  {
747  print '<td style="text-align: center;">'.dol_print_date($date, 'dayhour').'</td>';
748  if (!$i) $totalarray['nbfield']++;
749  }
750  if (!empty($arrayfields['cp.tms']['checked']))
751  {
752  print '<td style="text-align: center;">'.dol_print_date($date_modif, 'dayhour').'</td>';
753  if (!$i) $totalarray['nbfield']++;
754  }
755  if (!empty($arrayfields['cp.statut']['checked']))
756  {
757  print '<td class="right nowrap">'.$holidaystatic->getLibStatut(5).'</td>';
758  if (!$i) $totalarray['nbfield']++;
759  }
760 
761  // Action column
762  print '<td class="nowrap center">';
763  if ($massactionbutton || $massaction) // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
764  {
765  $selected = 0;
766  if (in_array($obj->rowid, $arrayofselected)) $selected = 1;
767  print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
768  }
769  print '</td>';
770  if (!$i) $totalarray['nbfield']++;
771 
772  print '</tr>'."\n";
773 
774  $i++;
775  }
776  }
777 
778  // Si il n'y a pas d'enregistrement suite à une recherche
779  if ($num == 0)
780  {
781  $colspan = 1;
782  foreach ($arrayfields as $key => $val) { if (!empty($val['checked'])) $colspan++; }
783  print '<tr><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoRecordFound").'</td></tr>';
784  }
785 
786  print '</table>';
787  print '</div>';
788 
789  print '</form>';
790 } else {
791  dol_print_error($db);
792 }
793 
794 // End of page
795 llxFooter();
796 $db->close();
797 
798 
799 
800 
801 
809 function showMyBalance($holiday, $user_id)
810 {
811  global $conf, $langs;
812 
813  $alltypeleaves = $holiday->getTypes(1, -1); // To have labels
814 
815  $out = '';
816  $nb_holiday = 0;
817  $typeleaves = $holiday->getTypes(1, 1);
818  foreach ($typeleaves as $key => $val)
819  {
820  $nb_type = $holiday->getCPforUser($user_id, $val['rowid']);
821  $nb_holiday += $nb_type;
822  $out .= ' - '.$val['label'].': <strong>'.($nb_type ?price2num($nb_type) : 0).'</strong><br>';
823  }
824  print $langs->trans('SoldeCPUser', round($nb_holiday, 5)).'<br>';
825  print $out;
826 }
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Class of the module paid holiday.
user_prepare_head($object)
Prepare array with list of tabs.
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.
Class to manage Dolibarr users.
Definition: user.class.php:44
Class to manage user groups.
llxHeader()
Empty header.
Definition: wrapper.php:45
Class to manage standard extra fields.
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
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.
Class to manage generation of HTML components Only common components must be here.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname.
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
price2num($amount, $rounding= '', $option=0)
Function that return a number with universal decimal format (decimal separator is &#39;...
Classe permettant la generation de composants html autre Only common components are here...
num_open_day($timestampStart, $timestampEnd, $inhour=0, $lastday=0, $halfday=0, $country_code= '')
Function to return number of working days (and text of units) between two dates (working days) ...
Definition: date.lib.php:863
restrictedArea($user, $features, $objectid=0, $tableandshare= '', $feature2= '', $dbt_keyfield= 'fk_soc', $dbt_select= 'rowid', $isdraft=0)
Check permissions of a user to show a page and an object.
accessforbidden($message= '', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
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...
dolSqlDateFilter($datefield, $day_date, $month_date, $year_date, $excludefirstand=0)
Generate a SQL string to make a filter into a range (for second of date until last second of date) ...
Definition: date.lib.php:281
Class to offer components to list and upload files.
print $_SERVER["PHP_SELF"]
Edit parameters.
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
print
Draft customers invoices.
Definition: index.php:89
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
showMyBalance($holiday, $user_id)
Show balance of user.
Definition: list.php:809
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1232
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_get_fiche_end($notab=0)
Return tab footer of a card.
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.
llxFooter()
Empty footer.
Definition: wrapper.php:59