dolibarr  19.0.0-dev
card.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2011 Dimitri Mouillard <dmouillard@teclib.com>
3  * Copyright (C) 2012-2016 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2012-2016 Regis Houssin <regis.houssin@inodbox.com>
5  * Copyright (C) 2013 Juanjo Menent <jmenent@2byte.es>
6  * Copyright (C) 2017 Alexandre Spangaro <aspangaro@open-dsi.fr>
7  * Copyright (C) 2014-2017 Ferran Marcet <fmarcet@2byte.es>
8  * Copyright (C) 2018-2023 Frédéric France <frederic.france@netlogic.fr>
9  * Copyright (C) 2020-2021 Udo Tamm <dev@dolibit.de>
10  * Copyright (C) 2022 Anthony Berton <anthony.berton@bb2a.fr>
11  *
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 3 of the License, orwrite
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program. If not, see <https://www.gnu.org/licenses/>.
24  */
25 
32 // Load Dolibarr environment
33 require '../main.inc.php';
34 require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
35 require_once DOL_DOCUMENT_ROOT.'/user/class/usergroup.class.php';
36 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
37 require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
38 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
39 require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
40 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
41 require_once DOL_DOCUMENT_ROOT.'/core/lib/holiday.lib.php';
42 require_once DOL_DOCUMENT_ROOT.'/holiday/class/holiday.class.php';
43 require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
44 
45 // Get parameters
46 $action = GETPOST('action', 'aZ09');
47 $cancel = GETPOST('cancel', 'alpha');
48 $confirm = GETPOST('confirm', 'alpha');
49 $backtopage = GETPOST('backtopage', 'alpha');
50 $backtopageforcancel = GETPOST('backtopageforcancel', 'alpha');
51 
52 $id = GETPOST('id', 'int');
53 $ref = GETPOST('ref', 'alpha');
54 $fuserid = (GETPOST('fuserid', 'int') ?GETPOST('fuserid', 'int') : $user->id);
55 $socid = GETPOST('socid', 'int');
56 
57 // Load translation files required by the page
58 $langs->loadLangs(array("other", "holiday", "mails", "trips"));
59 
60 $error = 0;
61 
62 $now = dol_now();
63 
64 $childids = $user->getAllChildIds(1);
65 
66 $morefilter = '';
67 if (!empty($conf->global->HOLIDAY_HIDE_FOR_NON_SALARIES)) {
68  $morefilter = 'AND employee = 1';
69 }
70 
71 $object = new Holiday($db);
72 
73 $extrafields = new ExtraFields($db);
74 
75 // fetch optionals attributes and labels
76 $extrafields->fetch_name_optionals_label($object->table_element);
77 
78 if (($id > 0) || $ref) {
79  $object->fetch($id, $ref);
80 
81  // Check current user can read this leave request
82  $canread = 0;
83  if (!empty($user->rights->holiday->readall)) {
84  $canread = 1;
85  }
86  if (!empty($user->rights->holiday->read) && in_array($object->fk_user, $childids)) {
87  $canread = 1;
88  }
89  if (!$canread) {
91  }
92 }
93 
94 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
95 $hookmanager->initHooks(array('holidaycard', 'globalcard'));
96 
97 $cancreate = 0;
98 $cancreateall = 0;
99 if (!empty($user->rights->holiday->write) && in_array($fuserid, $childids)) {
100  $cancreate = 1;
101 }
102 if (!empty($user->rights->holiday->writeall)) {
103  $cancreate = 1;
104  $cancreateall = 1;
105 }
106 
107 $candelete = 0;
108 if (!empty($user->rights->holiday->delete)) {
109  $candelete = 1;
110 }
111 if ($object->statut == Holiday::STATUS_DRAFT && $user->rights->holiday->write && in_array($object->fk_user, $childids)) {
112  $candelete = 1;
113 }
114 
115 // Protection if external user
116 if ($user->socid) {
117  $socid = $user->socid;
118 }
119 $result = restrictedArea($user, 'holiday', $object->id, 'holiday', '', '', 'rowid', $object->statut);
120 
121 
122 /*
123  * Actions
124  */
125 
126 $parameters = array('socid' => $socid);
127 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
128 if ($reshook < 0) {
129  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
130 }
131 
132 if (empty($reshook)) {
133  $backurlforlist = DOL_URL_ROOT.'/holiday/list.php';
134 
135  if (empty($backtopage) || ($cancel && empty($id))) {
136  if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) {
137  if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) {
138  $backtopage = $backurlforlist;
139  } else {
140  $backtopage = DOL_URL_ROOT.'/holiday/card.php?id='.((!empty($id) && $id > 0) ? $id : '__ID__');
141  }
142  }
143  }
144 
145  if ($cancel) {
146  if (!empty($backtopageforcancel)) {
147  header("Location: ".$backtopageforcancel);
148  exit;
149  } elseif (!empty($backtopage)) {
150  header("Location: ".$backtopage);
151  exit;
152  }
153  $action = '';
154  }
155 
156  // Add leave request
157  if ($action == 'add') {
158  // If no right to create a request
159  if (!$cancreate) {
160  $error++;
161  setEventMessages($langs->trans('CantCreateCP'), null, 'errors');
162  $action = 'create';
163  }
164 
165  if (!$error) {
166  $object = new Holiday($db);
167 
168  $db->begin();
169 
170  $date_debut = dol_mktime(0, 0, 0, GETPOST('date_debut_month'), GETPOST('date_debut_day'), GETPOST('date_debut_year'));
171  $date_fin = dol_mktime(0, 0, 0, GETPOST('date_fin_month'), GETPOST('date_fin_day'), GETPOST('date_fin_year'));
172  $date_debut_gmt = dol_mktime(0, 0, 0, GETPOST('date_debut_month'), GETPOST('date_debut_day'), GETPOST('date_debut_year'), 1);
173  $date_fin_gmt = dol_mktime(0, 0, 0, GETPOST('date_fin_month'), GETPOST('date_fin_day'), GETPOST('date_fin_year'), 1);
174  $starthalfday = GETPOST('starthalfday');
175  $endhalfday = GETPOST('endhalfday');
176  $type = GETPOST('type');
177  $halfday = 0;
178  if ($starthalfday == 'afternoon' && $endhalfday == 'morning') {
179  $halfday = 2;
180  } elseif ($starthalfday == 'afternoon') {
181  $halfday = -1;
182  } elseif ($endhalfday == 'morning') {
183  $halfday = 1;
184  }
185 
186  $approverid = GETPOST('valideur', 'int');
187  $description = trim(GETPOST('description', 'restricthtml'));
188 
189  // Check that leave is for a user inside the hierarchy or advanced permission for all is set
190  if (!$cancreateall) {
191  if (empty($conf->global->MAIN_USE_ADVANCED_PERMS)) {
192  if (empty($user->rights->holiday->write)) {
193  $error++;
194  setEventMessages($langs->trans("NotEnoughPermissions"), null, 'errors');
195  } elseif (!in_array($fuserid, $childids)) {
196  $error++;
197  setEventMessages($langs->trans("UserNotInHierachy"), null, 'errors');
198  $action = 'create';
199  }
200  } else {
201  if (empty($user->rights->holiday->write) && empty($user->rights->holiday->writeall_advance)) {
202  $error++;
203  setEventMessages($langs->trans("NotEnoughPermissions"), null, 'errors');
204  } elseif (empty($user->rights->holiday->writeall_advance) && !in_array($fuserid, $childids)) {
205  $error++;
206  setEventMessages($langs->trans("UserNotInHierachy"), null, 'errors');
207  $action = 'create';
208  }
209  }
210  }
211 
212  // If no type
213  if ($type <= 0) {
214  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type")), null, 'errors');
215  $error++;
216  $action = 'create';
217  }
218 
219  // If no start date
220  if (empty($date_debut)) {
221  setEventMessages($langs->trans("NoDateDebut"), null, 'errors');
222  $error++;
223  $action = 'create';
224  }
225  // If no end date
226  if (empty($date_fin)) {
227  setEventMessages($langs->trans("NoDateFin"), null, 'errors');
228  $error++;
229  $action = 'create';
230  }
231  // If start date after end date
232  if ($date_debut > $date_fin) {
233  setEventMessages($langs->trans("ErrorEndDateCP"), null, 'errors');
234  $error++;
235  $action = 'create';
236  }
237 
238  // Check if there is already holiday for this period
239  $verifCP = $object->verifDateHolidayCP($fuserid, $date_debut, $date_fin, $halfday);
240  if (!$verifCP) {
241  setEventMessages($langs->trans("alreadyCPexist"), null, 'errors');
242  $error++;
243  $action = 'create';
244  }
245 
246  // If there is no Business Days within request
247  $nbopenedday = num_open_day($date_debut_gmt, $date_fin_gmt, 0, 1, $halfday);
248  if ($nbopenedday < 0.5) {
249  setEventMessages($langs->trans("ErrorDureeCP"), null, 'errors'); // No working day
250  $error++;
251  $action = 'create';
252  }
253 
254  // If no validator designated
255  if ($approverid < 1) {
256  setEventMessages($langs->transnoentitiesnoconv('InvalidValidatorCP'), null, 'errors');
257  $error++;
258  }
259 
260  $approverslist = $object->fetch_users_approver_holiday();
261  if (!in_array($approverid, $approverslist)) {
262  setEventMessages($langs->transnoentitiesnoconv('InvalidValidator'), null, 'errors');
263  $error++;
264  }
265 
266  // Fill array 'array_options' with data from add form
267  $ret = $extrafields->setOptionalsFromPost(null, $object);
268  if ($ret < 0) {
269  $error++;
270  }
271 
272  $result = 0;
273 
274  if (!$error) {
275  $object->fk_user = $fuserid;
276  $object->description = $description;
277  $object->fk_validator = $approverid;
278  $object->fk_type = $type;
279  $object->date_debut = $date_debut;
280  $object->date_fin = $date_fin;
281  $object->halfday = $halfday;
282 
283  $result = $object->create($user);
284  if ($result <= 0) {
285  setEventMessages($object->error, $object->errors, 'errors');
286  $error++;
287  }
288  }
289 
290  // If no SQL error we redirect to the request card
291  if (!$error) {
292  $db->commit();
293 
294  header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
295  exit;
296  } else {
297  $db->rollback();
298  }
299  }
300  }
301 
302  // If this is an update and we are an approver, we can update to change the expected approver with another one (including himself)
303  if ($action == 'update' && GETPOSTISSET('savevalidator') && !empty($user->rights->holiday->approve)) {
304  $object->fetch($id);
305 
306  $object->oldcopy = dol_clone($object);
307 
308  $object->fk_validator = GETPOST('valideur', 'int');
309 
310  if ($object->fk_validator != $object->oldcopy->fk_validator) {
311  $verif = $object->update($user);
312 
313  if ($verif <= 0) {
314  setEventMessages($object->error, $object->errors, 'warnings');
315  $action = 'editvalidator';
316  } else {
317  header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
318  exit;
319  }
320  }
321 
322  $action = '';
323  }
324 
325  if ($action == 'update' && !GETPOSTISSET('savevalidator')) {
326  $date_debut = dol_mktime(0, 0, 0, GETPOST('date_debut_month'), GETPOST('date_debut_day'), GETPOST('date_debut_year'));
327  $date_fin = dol_mktime(0, 0, 0, GETPOST('date_fin_month'), GETPOST('date_fin_day'), GETPOST('date_fin_year'));
328  $date_debut_gmt = dol_mktime(0, 0, 0, GETPOST('date_debut_month'), GETPOST('date_debut_day'), GETPOST('date_debut_year'), 1);
329  $date_fin_gmt = dol_mktime(0, 0, 0, GETPOST('date_fin_month'), GETPOST('date_fin_day'), GETPOST('date_fin_year'), 1);
330  $starthalfday = GETPOST('starthalfday');
331  $endhalfday = GETPOST('endhalfday');
332  $halfday = 0;
333  if ($starthalfday == 'afternoon' && $endhalfday == 'morning') {
334  $halfday = 2;
335  } elseif ($starthalfday == 'afternoon') {
336  $halfday = -1;
337  } elseif ($endhalfday == 'morning') {
338  $halfday = 1;
339  }
340 
341  // If no right to modify a request
342  if (!$cancreateall) {
343  if ($cancreate) {
344  if (!in_array($fuserid, $childids)) {
345  setEventMessages($langs->trans("UserNotInHierachy"), null, 'errors');
346  header('Location: '.$_SERVER["PHP_SELF"].'?action=create');
347  exit;
348  }
349  } else {
350  setEventMessages($langs->trans("NotEnoughPermissions"), null, 'errors');
351  header('Location: '.$_SERVER["PHP_SELF"].'?action=create');
352  exit;
353  }
354  }
355 
356  $object->fetch($id);
357 
358  // If under validation
359  if ($object->statut == Holiday::STATUS_DRAFT) {
360  // If this is the requestor or has read/write rights
361  if ($cancreate) {
362  $approverid = GETPOST('valideur', 'int');
363  // TODO Check this approver user id has the permission for approval
364 
365  $description = trim(GETPOST('description', 'restricthtml'));
366 
367  // If no end date
368  if (!GETPOST('date_fin_')) {
369  setEventMessages($langs->trans('NoDateFin'), null, 'warnings');
370  $error++;
371  $action = 'edit';
372  }
373 
374  // If start date after end date
375  if ($date_debut > $date_fin) {
376  setEventMessages($langs->trans('ErrorEndDateCP'), null, 'warnings');
377  $error++;
378  $action = 'edit';
379  }
380 
381  // If no validator designated
382  if ($approverid < 1) {
383  setEventMessages($langs->trans('InvalidValidatorCP'), null, 'warnings');
384  $error++;
385  $action = 'edit';
386  }
387 
388  // If there is no Business Days within request
389  $nbopenedday = num_open_day($date_debut_gmt, $date_fin_gmt, 0, 1, $halfday);
390  if ($nbopenedday < 0.5) {
391  setEventMessages($langs->trans('ErrorDureeCP'), null, 'warnings');
392  $error++;
393  $action = 'edit';
394  }
395 
396  $db->begin();
397 
398  if (!$error) {
399  $object->description = $description;
400  $object->date_debut = $date_debut;
401  $object->date_fin = $date_fin;
402  $object->fk_validator = $approverid;
403  $object->halfday = $halfday;
404 
405  // Update
406  $verif = $object->update($user);
407 
408  if ($verif <= 0) {
409  setEventMessages($object->error, $object->errors, 'warnings');
410  $error++;
411  $action = 'edit';
412  }
413  }
414 
415  if (!$error) {
416  $db->commit();
417 
418  header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
419  exit;
420  } else {
421  $db->rollback();
422  }
423  } else {
424  setEventMessages($langs->trans("NotEnoughPermissions"), null, 'errors');
425  $action = '';
426  }
427  } else {
428  setEventMessages($langs->trans("ErrorBadStatus"), null, 'errors');
429  $action = '';
430  }
431  }
432 
433  // If delete of request
434  if ($action == 'confirm_delete' && GETPOST('confirm') == 'yes' && $candelete) {
435  $error = 0;
436 
437  $db->begin();
438 
439  $object->fetch($id);
440 
441  // If this is a rough draft, approved, canceled or refused
442  if ($object->statut == Holiday::STATUS_DRAFT || $object->statut == Holiday::STATUS_CANCELED || $object->statut == Holiday::STATUS_REFUSED) {
443  $result = $object->delete($user);
444  } else {
445  $error++;
446  setEventMessages($langs->trans('BadStatusOfObject'), null, 'errors');
447  $action = '';
448  }
449 
450  if (!$error) {
451  $db->commit();
452  header('Location: list.php?restore_lastsearch_values=1');
453  exit;
454  } else {
455  $db->rollback();
456  }
457  }
458 
459  // Action validate (+ send email for approval to the expected approver)
460  if ($action == 'confirm_send') {
461  $object->fetch($id);
462 
463  // If draft and owner of leave
464  if ($object->statut == Holiday::STATUS_DRAFT && $cancreate) {
465  $object->oldcopy = dol_clone($object);
466 
467  $object->statut = Holiday::STATUS_VALIDATED;
468 
469  $verif = $object->validate($user);
470 
471  // If no SQL error, we redirect to the request form
472  if ($verif > 0) {
473  // To
474  $destinataire = new User($db);
475  $destinataire->fetch($object->fk_validator);
476  $emailTo = $destinataire->email;
477 
478  if (!$emailTo) {
479  dol_syslog("Expected validator has no email, so we redirect directly to finished page without sending email");
480  header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
481  exit;
482  }
483 
484  // From
485  $expediteur = new User($db);
486  $expediteur->fetch($object->fk_user);
487  //$emailFrom = $expediteur->email; Email of user can be an email into another company. Sending will fails, we must use the generic email.
488  $emailFrom = $conf->global->MAIN_MAIL_EMAIL_FROM;
489 
490  // Subject
491  $societeName = $conf->global->MAIN_INFO_SOCIETE_NOM;
492  if (!empty($conf->global->MAIN_APPLICATION_TITLE)) {
493  $societeName = $conf->global->MAIN_APPLICATION_TITLE;
494  }
495 
496  $subject = $societeName." - ".$langs->transnoentitiesnoconv("HolidaysToValidate");
497 
498  // Content
499  $message = "<p>".$langs->transnoentitiesnoconv("Hello")." ".$destinataire->firstname.",</p>\n";
500 
501  $message .= "<p>".$langs->transnoentities("HolidaysToValidateBody")."</p>\n";
502 
503 
504  // option to warn the validator in case of too short delay
505  if (empty($conf->global->HOLIDAY_HIDE_APPROVER_ABOUT_TOO_LOW_DELAY)) {
506  $delayForRequest = 0; // TODO Set delay depending of holiday leave type
507  if ($delayForRequest) {
508  $nowplusdelay = dol_time_plus_duree($now, $delayForRequest, 'd');
509 
510  if ($object->date_debut < $nowplusdelay) {
511  $message = "<p>".$langs->transnoentities("HolidaysToValidateDelay", $delayForRequest)."</p>\n";
512  }
513  }
514  }
515 
516  // option to notify the validator if the balance is less than the request
517  if (empty($conf->global->HOLIDAY_HIDE_APPROVER_ABOUT_NEGATIVE_BALANCE)) {
518  $nbopenedday = num_open_day($object->date_debut_gmt, $object->date_fin_gmt, 0, 1, $object->halfday);
519 
520  if ($nbopenedday > $object->getCPforUser($object->fk_user, $object->fk_type)) {
521  $message .= "<p>".$langs->transnoentities("HolidaysToValidateAlertSolde")."</p>\n";
522  }
523  }
524 
525  $typeleaves = $object->getTypes(1, -1);
526  $labeltoshow = (($typeleaves[$object->fk_type]['code'] && $langs->trans($typeleaves[$object->fk_type]['code']) != $typeleaves[$object->fk_type]['code']) ? $langs->trans($typeleaves[$object->fk_type]['code']) : $typeleaves[$object->fk_type]['label']);
527 
528  if ($object->halfday == 2) {
529  $starthalfdaykey = "Afternoon";
530  $endhalfdaykey = "Morning";
531  } elseif ($object->halfday == -1) {
532  $starthalfdaykey = "Afternoon";
533  $endhalfdaykey = "Afternoon";
534  } elseif ($object->halfday == 1) {
535  $starthalfdaykey = "Morning";
536  $endhalfdaykey = "Morning";
537  } elseif ($object->halfday == 2) {
538  $starthalfdaykey = "Morning";
539  $endhalfdaykey = "Afternoon";
540  }
541 
542  $link = dol_buildpath("/holiday/card.php", 3) . '?id='.$object->id;
543 
544  $message .= "<ul>";
545  $message .= "<li>".$langs->transnoentitiesnoconv("Name")." : ".dolGetFirstLastname($expediteur->firstname, $expediteur->lastname)."</li>\n";
546  $message .= "<li>".$langs->transnoentitiesnoconv("Type")." : ".(empty($labeltoshow) ? $langs->trans("TypeWasDisabledOrRemoved", $object->fk_type) : $labeltoshow)."</li>\n";
547  $message .= "<li>".$langs->transnoentitiesnoconv("Period")." : ".dol_print_date($object->date_debut, 'day')." ".$langs->transnoentitiesnoconv($starthalfdaykey)." ".$langs->transnoentitiesnoconv("To")." ".dol_print_date($object->date_fin, 'day')." ".$langs->transnoentitiesnoconv($endhalfdaykey)."</li>\n";
548  $message .= "<li>".$langs->transnoentitiesnoconv("Link").' : <a href="'.$link.'" target="_blank">'.$link."</a></li>\n";
549  $message .= "</ul>\n";
550 
551  $trackid = 'leav'.$object->id;
552 
553  $mail = new CMailFile($subject, $emailTo, $emailFrom, $message, array(), array(), array(), '', '', 0, 1, '', '', $trackid);
554 
555  // Sending the email
556  $result = $mail->sendfile();
557 
558  if (!$result) {
559  setEventMessages($mail->error, $mail->errors, 'warnings');
560  $action = '';
561  } else {
562  header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
563  exit;
564  }
565  } else {
566  setEventMessages($object->error, $object->errors, 'errors');
567  $action = '';
568  }
569  }
570  }
571 
572  if ($action == 'update_extras') {
573  $object->oldcopy = dol_clone($object);
574 
575  // Fill array 'array_options' with data from update form
576  $ret = $extrafields->setOptionalsFromPost(null, $object, GETPOST('attribute', 'restricthtml'));
577  if ($ret < 0) {
578  $error++;
579  }
580 
581  if (!$error) {
582  // Actions on extra fields
583  $result = $object->insertExtraFields('HOLIDAY_MODIFY');
584  if ($result < 0) {
585  setEventMessages($object->error, $object->errors, 'errors');
586  $error++;
587  }
588  }
589 
590  if ($error) {
591  $action = 'edit_extras';
592  }
593  }
594 
595  // Approve leave request
596  if ($action == 'confirm_valid') {
597  $object->fetch($id);
598 
599  // If status is waiting approval and approver is also user
600  if ($object->statut == Holiday::STATUS_VALIDATED && $user->id == $object->fk_validator) {
601  $object->oldcopy = dol_clone($object);
602 
603  $object->date_approval = dol_now();
604  $object->fk_user_approve = $user->id;
605  $object->statut = Holiday::STATUS_APPROVED;
606  $object->status = Holiday::STATUS_APPROVED;
607 
608  $db->begin();
609 
610  $verif = $object->approve($user);
611  if ($verif <= 0) {
612  setEventMessages($object->error, $object->errors, 'errors');
613  $error++;
614  }
615 
616  // If no SQL error, we redirect to the request form
617  if (!$error) {
618  // Calculcate number of days consumed
619  $nbopenedday = num_open_day($object->date_debut_gmt, $object->date_fin_gmt, 0, 1, $object->halfday);
620  $soldeActuel = $object->getCpforUser($object->fk_user, $object->fk_type);
621  $newSolde = ($soldeActuel - $nbopenedday);
622  $label = $langs->transnoentitiesnoconv("Holidays").' - '.$object->ref;
623 
624  // The modification is added to the LOG
625  $result = $object->addLogCP($user->id, $object->fk_user, $label, $newSolde, $object->fk_type);
626  if ($result < 0) {
627  $error++;
628  setEventMessages(null, $object->errors, 'errors');
629  }
630 
631  // Update balance
632  $result = $object->updateSoldeCP($object->fk_user, $newSolde, $object->fk_type);
633  if ($result < 0) {
634  $error++;
635  setEventMessages(null, $object->errors, 'errors');
636  }
637  }
638 
639  if (!$error) {
640  // To
641  $destinataire = new User($db);
642  $destinataire->fetch($object->fk_user);
643  $emailTo = $destinataire->email;
644 
645  if (!$emailTo) {
646  dol_syslog("User that request leave has no email, so we redirect directly to finished page without sending email");
647  } else {
648  // From
649  $expediteur = new User($db);
650  $expediteur->fetch($object->fk_validator);
651  //$emailFrom = $expediteur->email; Email of user can be an email into another company. Sending will fails, we must use the generic email.
652  $emailFrom = $conf->global->MAIN_MAIL_EMAIL_FROM;
653 
654  // Subject
655  $societeName = $conf->global->MAIN_INFO_SOCIETE_NOM;
656  if (!empty($conf->global->MAIN_APPLICATION_TITLE)) {
657  $societeName = $conf->global->MAIN_APPLICATION_TITLE;
658  }
659 
660  $subject = $societeName." - ".$langs->transnoentitiesnoconv("HolidaysValidated");
661 
662  // Content
663  $message = "<p>".$langs->transnoentitiesnoconv("Hello")." ".$destinataire->firstname.",</p>\n";
664 
665  $message .= "<p>".$langs->transnoentities("HolidaysValidatedBody", dol_print_date($object->date_debut, 'day'), dol_print_date($object->date_fin, 'day'))."</p>\n";
666 
667  $link = dol_buildpath('/holiday/card.php', 3).'?id='.$object->id;
668 
669  $message .= "<ul>\n";
670  $message .= "<li>".$langs->transnoentitiesnoconv("ValidatedBy")." : ".dolGetFirstLastname($expediteur->firstname, $expediteur->lastname)."</li>\n";
671  $message .= "<li>".$langs->transnoentitiesnoconv("Link").' : <a href="'.$link.'" target="_blank">'.$link."</a></li>\n";
672  $message .= "</ul>\n";
673 
674  $trackid = 'leav'.$object->id;
675 
676  $mail = new CMailFile($subject, $emailTo, $emailFrom, $message, array(), array(), array(), '', '', 0, 1, '', '', $trackid);
677 
678  // Sending email
679  $result = $mail->sendfile();
680 
681  if (!$result) {
682  setEventMessages($mail->error, $mail->errors, 'warnings'); // Show error, but do no make rollback, so $error is not set to 1
683  $action = '';
684  }
685  }
686  }
687 
688  if (!$error) {
689  $db->commit();
690 
691  header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
692  exit;
693  } else {
694  $db->rollback();
695  $action = '';
696  }
697  }
698  }
699 
700  if ($action == 'confirm_refuse' && GETPOST('confirm', 'alpha') == 'yes') {
701  if (GETPOST('detail_refuse')) {
702  $object->fetch($id);
703 
704  // If status pending validation and validator = user
705  if ($object->statut == Holiday::STATUS_VALIDATED && $user->id == $object->fk_validator) {
706  $object->date_refuse = dol_now();
707  $object->fk_user_refuse = $user->id;
708  $object->statut = Holiday::STATUS_REFUSED;
709  $object->status = Holiday::STATUS_REFUSED;
710  $object->detail_refuse = GETPOST('detail_refuse', 'alphanohtml');
711 
712  $db->begin();
713 
714  $verif = $object->update($user);
715  if ($verif <= 0) {
716  $error++;
717  setEventMessages($object->error, $object->errors, 'errors');
718  }
719 
720  // If no SQL error, we redirect to the request form
721  if (!$error) {
722  // To
723  $destinataire = new User($db);
724  $destinataire->fetch($object->fk_user);
725  $emailTo = $destinataire->email;
726 
727  if (!$emailTo) {
728  dol_syslog("User that request leave has no email, so we redirect directly to finished page without sending email");
729  } else {
730  // From
731  $expediteur = new User($db);
732  $expediteur->fetch($object->fk_validator);
733  //$emailFrom = $expediteur->email; Email of user can be an email into another company. Sending will fails, we must use the generic email.
734  $emailFrom = $conf->global->MAIN_MAIL_EMAIL_FROM;
735 
736  // Subject
737  $societeName = $conf->global->MAIN_INFO_SOCIETE_NOM;
738  if (!empty($conf->global->MAIN_APPLICATION_TITLE)) {
739  $societeName = $conf->global->MAIN_APPLICATION_TITLE;
740  }
741 
742  $subject = $societeName." - ".$langs->transnoentitiesnoconv("HolidaysRefused");
743 
744  // Content
745  $message = "<p>".$langs->transnoentitiesnoconv("Hello")." ".$destinataire->firstname.",</p>\n";
746 
747  $message .= "<p>".$langs->transnoentities("HolidaysRefusedBody", dol_print_date($object->date_debut, 'day'), dol_print_date($object->date_fin, 'day'))."<p>\n";
748  $message .= "<p>".GETPOST('detail_refuse', 'alpha')."</p>";
749 
750  $link = dol_buildpath('/holiday/card.php', 3).'?id='.$object->id;
751 
752  $message .= "<ul>\n";
753  $message .= "<li>".$langs->transnoentitiesnoconv("ModifiedBy")." : ".dolGetFirstLastname($expediteur->firstname, $expediteur->lastname)."</li>\n";
754  $message .= "<li>".$langs->transnoentitiesnoconv("Link").' : <a href="'.$link.'" target="_blank">'.$link."</a></li>\n";
755  $message .= "</ul>";
756 
757  $trackid = 'leav'.$object->id;
758 
759  $mail = new CMailFile($subject, $emailTo, $emailFrom, $message, array(), array(), array(), '', '', 0, 1, '', '', $trackid);
760 
761  // sending email
762  $result = $mail->sendfile();
763 
764  if (!$result) {
765  setEventMessages($mail->error, $mail->errors, 'warnings'); // Show error, but do no make rollback, so $error is not set to 1
766  $action = '';
767  }
768  }
769  } else {
770  $action = '';
771  }
772 
773  if (!$error) {
774  $db->commit();
775 
776  header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
777  exit;
778  } else {
779  $db->rollback();
780  $action = '';
781  }
782  }
783  } else {
784  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("DetailRefusCP")), null, 'errors');
785  $action = 'refuse';
786  }
787  }
788 
789 
790  // If the request is validated
791  if ($action == 'confirm_draft' && GETPOST('confirm') == 'yes') {
792  $error = 0;
793 
794  $object->fetch($id);
795 
796  $oldstatus = $object->statut;
797  $object->statut = Holiday::STATUS_DRAFT;
798  $object->status = Holiday::STATUS_DRAFT;
799 
800  $result = $object->update($user);
801  if ($result < 0) {
802  $error++;
803  setEventMessages($langs->trans('ErrorBackToDraft').' '.$object->error, $object->errors, 'errors');
804  }
805 
806  if (!$error) {
807  $db->commit();
808 
809  header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
810  exit;
811  } else {
812  $db->rollback();
813  }
814  }
815 
816  // If confirmation of cancellation
817  if ($action == 'confirm_cancel' && GETPOST('confirm') == 'yes') {
818  $error = 0;
819 
820  $object->fetch($id);
821 
822  // If status pending validation and validator = validator or user, or rights to do for others
823  if (($object->statut == Holiday::STATUS_VALIDATED || $object->statut == Holiday::STATUS_APPROVED) &&
824  (!empty($user->admin) || $user->id == $object->fk_validator || $cancreate || $cancreateall)) {
825  $db->begin();
826 
827  $oldstatus = $object->statut;
828  $object->date_cancel = dol_now();
829  $object->fk_user_cancel = $user->id;
830  $object->statut = Holiday::STATUS_CANCELED;
831  $object->status = Holiday::STATUS_CANCELED;
832 
833  $result = $object->update($user);
834 
835  if ($result >= 0 && $oldstatus == Holiday::STATUS_APPROVED) { // holiday was already validated, status 3, so we must increase back the balance
836  // Call trigger
837  $result = $object->call_trigger('HOLIDAY_CANCEL', $user);
838  if ($result < 0) {
839  $error++;
840  }
841 
842  // Calculcate number of days consumed
843  $nbopenedday = num_open_day($object->date_debut_gmt, $object->date_fin_gmt, 0, 1, $object->halfday);
844 
845  $soldeActuel = $object->getCpforUser($object->fk_user, $object->fk_type);
846  $newSolde = ($soldeActuel + $nbopenedday);
847 
848  // The modification is added to the LOG
849  $result1 = $object->addLogCP($user->id, $object->fk_user, $langs->transnoentitiesnoconv("HolidaysCancelation"), $newSolde, $object->fk_type);
850 
851  // Update of the balance
852  $result2 = $object->updateSoldeCP($object->fk_user, $newSolde, $object->fk_type);
853 
854  if ($result1 < 0 || $result2 < 0) {
855  $error++;
856  setEventMessages($langs->trans('ErrorCantDeleteCP').' '.$object->error, $object->errors, 'errors');
857  }
858  }
859 
860  if (!$error) {
861  $db->commit();
862  } else {
863  $db->rollback();
864  }
865 
866  // If no SQL error, we redirect to the request form
867  if (!$error && $result > 0) {
868  // To
869  $destinataire = new User($db);
870  $destinataire->fetch($object->fk_user);
871  $emailTo = $destinataire->email;
872 
873  if (!$emailTo) {
874  header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
875  exit;
876  }
877 
878  // From
879  $expediteur = new User($db);
880  $expediteur->fetch($object->fk_user_cancel);
881  //$emailFrom = $expediteur->email; Email of user can be an email into another company. Sending will fails, we must use the generic email.
882  $emailFrom = $conf->global->MAIN_MAIL_EMAIL_FROM;
883 
884  // Subject
885  $societeName = $conf->global->MAIN_INFO_SOCIETE_NOM;
886  if (!empty($conf->global->MAIN_APPLICATION_TITLE)) {
887  $societeName = $conf->global->MAIN_APPLICATION_TITLE;
888  }
889 
890  $subject = $societeName." - ".$langs->transnoentitiesnoconv("HolidaysCanceled");
891 
892  // Content
893  $message = "<p>".$langs->transnoentitiesnoconv("Hello")." ".$destinataire->firstname.",</p>\n";
894 
895  $message .= "<p>".$langs->transnoentities("HolidaysCanceledBody", dol_print_date($object->date_debut, 'day'), dol_print_date($object->date_fin, 'day'))."</p>\n";
896 
897  $link = dol_buildpath('/holiday/card.php', 3).'?id='.$object->id;
898 
899  $message .= "<ul>\n";
900  $message .= "<li>".$langs->transnoentitiesnoconv("ModifiedBy")." : ".dolGetFirstLastname($expediteur->firstname, $expediteur->lastname)."</li>\n";
901  $message .= "<li>".$langs->transnoentitiesnoconv("Link").' : <a href="'.$link.'" target="_blank">'.$link."</a></li>\n";
902  $message .= "</ul>\n";
903 
904  $trackid = 'leav'.$object->id;
905 
906  $mail = new CMailFile($subject, $emailTo, $emailFrom, $message, array(), array(), array(), '', '', 0, 1, '', '', $trackid);
907 
908  // sending email
909  $result = $mail->sendfile();
910 
911  if (!$result) {
912  setEventMessages($mail->error, $mail->errors, 'warnings');
913  $action = '';
914  } else {
915  header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
916  exit;
917  }
918  }
919  }
920  }
921 
922  /*
923  // Actions when printing a doc from card
924  include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
925 
926  // Actions to send emails
927  $triggersendname = 'HOLIDAY_SENTBYMAIL';
928  $autocopy='MAIN_MAIL_AUTOCOPY_HOLIDAY_TO';
929  $trackid='leav'.$object->id;
930  include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
931 
932  // Actions to build doc
933  $upload_dir = $conf->holiday->dir_output;
934  $permissiontoadd = $user->rights->holiday->creer;
935  include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
936  */
937 }
938 
939 
940 
941 /*
942  * View
943  */
944 
945 $form = new Form($db);
946 $object = new Holiday($db);
947 
948 $listhalfday = array('morning'=>$langs->trans("Morning"), "afternoon"=>$langs->trans("Afternoon"));
949 
950 $title = $langs->trans('Leave');
951 $help_url = 'EN:Module_Holiday';
952 
953 llxHeader('', $title, $help_url);
954 
955 $edit = false;
956 
957 if ((empty($id) && empty($ref)) || $action == 'create' || $action == 'add') {
958  // If user has no permission to create a leave
959  if ((in_array($fuserid, $childids) && empty($user->rights->holiday->write)) || (!in_array($fuserid, $childids) && ((!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->holiday->writeall_advance) || empty($user->rights->holiday->writeall))))) {
960  $errors[] = $langs->trans('CantCreateCP');
961  } else {
962  // Form to add a leave request
963  print load_fiche_titre($langs->trans('MenuAddCP'), '', 'title_hrm.png');
964 
965  // Error management
966  if (GETPOST('error')) {
967  switch (GETPOST('error')) {
968  case 'datefin':
969  $errors[] = $langs->trans('ErrorEndDateCP');
970  break;
971  case 'SQL_Create':
972  $errors[] = $langs->trans('ErrorSQLCreateCP');
973  break;
974  case 'CantCreate':
975  $errors[] = $langs->trans('CantCreateCP');
976  break;
977  case 'Valideur':
978  $errors[] = $langs->trans('InvalidValidatorCP');
979  break;
980  case 'nodatedebut':
981  $errors[] = $langs->trans('NoDateDebut');
982  break;
983  case 'nodatefin':
984  $errors[] = $langs->trans('NoDateFin');
985  break;
986  case 'DureeHoliday':
987  $errors[] = $langs->trans('ErrorDureeCP');
988  break;
989  case 'alreadyCP':
990  $errors[] = $langs->trans('alreadyCPexist');
991  break;
992  }
993 
994  setEventMessages($errors, null, 'errors');
995  }
996 
997 
998  print '<script type="text/javascript">
999  $( document ).ready(function() {
1000  $("input.button-save").click("submit", function(e) {
1001  console.log("Call valider()");
1002  if (document.demandeCP.date_debut_.value != "")
1003  {
1004  if(document.demandeCP.date_fin_.value != "")
1005  {
1006  if(document.demandeCP.valideur.value != "-1") {
1007  return true;
1008  }
1009  else {
1010  alert("'.dol_escape_js($langs->transnoentities('InvalidValidatorCP')).'");
1011  return false;
1012  }
1013  }
1014  else
1015  {
1016  alert("'.dol_escape_js($langs->transnoentities('NoDateFin')).'");
1017  return false;
1018  }
1019  }
1020  else
1021  {
1022  alert("'.dol_escape_js($langs->transnoentities('NoDateDebut')).'");
1023  return false;
1024  }
1025  });
1026  });
1027  </script>'."\n";
1028 
1029 
1030  // Formulaire de demande
1031  print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'" name="demandeCP">'."\n";
1032  print '<input type="hidden" name="token" value="'.newToken().'" />'."\n";
1033  print '<input type="hidden" name="action" value="add" />'."\n";
1034 
1035  print dol_get_fiche_head();
1036 
1037  //print '<span>'.$langs->trans('DelayToRequestCP',$object->getConfCP('delayForRequest')).'</span><br><br>';
1038 
1039  print '<table class="border centpercent">';
1040  print '<tbody>';
1041 
1042  // User for leave request
1043  print '<tr>';
1044  print '<td class="titlefield fieldrequired tdtop">'.$langs->trans("User").'</td>';
1045  print '<td><div class="inline-block">';
1046  if ($cancreate && !$cancreateall) {
1047  print img_picto('', 'user', 'class="pictofixedwidth"').$form->select_dolusers(($fuserid ? $fuserid : $user->id), 'fuserid', 0, '', 0, 'hierarchyme', '', '0,'.$conf->entity, 0, 0, $morefilter, 0, '', 'minwidth200 maxwidth500 inline-block');
1048  //print '<input type="hidden" name="fuserid" value="'.($fuserid?$fuserid:$user->id).'">';
1049  } else {
1050  print img_picto('', 'user', 'class="pictofixedwidth"').$form->select_dolusers($fuserid ? $fuserid : $user->id, 'fuserid', 0, '', 0, '', '', '0,'.$conf->entity, 0, 0, $morefilter, 0, '', 'minwidth200 maxwidth500 inline-block');
1051  }
1052  print '</div>';
1053 
1054  if (empty($conf->global->HOLIDAY_HIDE_BALANCE)) {
1055  print '<div class="leaveuserbalance paddingtop inline-block floatright badge badge-status0 badge-status margintoponsmartphone">';
1056 
1057  $out = '';
1058  $nb_holiday = 0;
1059  $typeleaves = $object->getTypes(1, 1);
1060  foreach ($typeleaves as $key => $val) {
1061  $nb_type = $object->getCPforUser(($fuserid ? $fuserid : $user->id), $val['rowid']);
1062  $nb_holiday += $nb_type;
1063 
1064  $out .= ' - '.($langs->trans($val['code']) != $val['code'] ? $langs->trans($val['code']) : $val['label']).': <strong>'.($nb_type ? price2num($nb_type) : 0).'</strong><br>';
1065  //$out .= ' - '.$val['label'].': <strong>'.($nb_type ?price2num($nb_type) : 0).'</strong><br>';
1066  }
1067  print ' &nbsp; &nbsp; ';
1068 
1069  $htmltooltip = $langs->trans("Detail").'<br>';
1070  $htmltooltip .= $out;
1071 
1072  print $form->textwithtooltip($langs->trans('SoldeCPUser', round($nb_holiday, 5)).' '.img_picto('', 'help'), $htmltooltip);
1073 
1074  print '</div>';
1075  if (!empty($conf->use_javascript_ajax)) {
1076  print '<script>';
1077  print '$( document ).ready(function() {
1078  jQuery("#fuserid").change(function() {
1079  console.log("We change to user id "+jQuery("#fuserid").val());
1080  if (jQuery("#fuserid").val() == '.((int) $user->id).') {
1081  jQuery(".leaveuserbalance").show();
1082  } else {
1083  jQuery(".leaveuserbalance").hide();
1084  }
1085  });
1086  });';
1087  print '</script>';
1088  }
1089  } elseif (!is_numeric($conf->global->HOLIDAY_HIDE_BALANCE)) {
1090  print '<div class="leaveuserbalance paddingtop">';
1091  print $langs->trans($conf->global->HOLIDAY_HIDE_BALANCE);
1092  print '</div>';
1093  }
1094 
1095  print '</td>';
1096  print '</tr>';
1097 
1098  // Type
1099  print '<tr>';
1100  print '<td class="fieldrequired">'.$langs->trans("Type").'</td>';
1101  print '<td>';
1102  $typeleaves = $object->getTypes(1, -1);
1103  $arraytypeleaves = array();
1104  foreach ($typeleaves as $key => $val) {
1105  $labeltoshow = ($langs->trans($val['code']) != $val['code'] ? $langs->trans($val['code']) : $val['label']);
1106  $labeltoshow .= ($val['delay'] > 0 ? ' ('.$langs->trans("NoticePeriod").': '.$val['delay'].' '.$langs->trans("days").')' : '');
1107  $arraytypeleaves[$val['rowid']] = $labeltoshow;
1108  }
1109  print $form->selectarray('type', $arraytypeleaves, (GETPOST('type', 'alpha') ?GETPOST('type', 'alpha') : ''), 1, 0, 0, '', 0, 0, 0, '', '', true);
1110  if ($user->admin) {
1111  print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
1112  }
1113  print '</td>';
1114  print '</tr>';
1115 
1116  // Date start
1117  print '<tr>';
1118  print '<td class="fieldrequired">';
1119  print $form->textwithpicto($langs->trans("DateDebCP"), $langs->trans("FirstDayOfHoliday"));
1120  print '</td>';
1121  print '<td>'.img_picto('', 'action', 'class="pictofixedwidth"');
1122  if (!GETPOST('date_debut_')) { // If visitor does not come from agenda
1123  print $form->selectDate(-1, 'date_debut_', 0, 0, 0, '', 1, 1);
1124  } else {
1125  $tmpdate = dol_mktime(0, 0, 0, GETPOST('date_debut_month', 'int'), GETPOST('date_debut_day', 'int'), GETPOST('date_debut_year', 'int'));
1126  print $form->selectDate($tmpdate, 'date_debut_', 0, 0, 0, '', 1, 1);
1127  }
1128  print ' &nbsp; &nbsp; ';
1129  print $form->selectarray('starthalfday', $listhalfday, (GETPOST('starthalfday', 'alpha') ?GETPOST('starthalfday', 'alpha') : 'morning'));
1130  print '</td>';
1131  print '</tr>';
1132 
1133  // Date end
1134  print '<tr>';
1135  print '<td class="fieldrequired">';
1136  print $form->textwithpicto($langs->trans("DateFinCP"), $langs->trans("LastDayOfHoliday"));
1137  print '</td>';
1138  print '<td>'.img_picto('', 'action', 'class="pictofixedwidth"');
1139  if (!GETPOST('date_fin_')) {
1140  print $form->selectDate(-1, 'date_fin_', 0, 0, 0, '', 1, 1);
1141  } else {
1142  $tmpdate = dol_mktime(0, 0, 0, GETPOST('date_fin_month', 'int'), GETPOST('date_fin_day', 'int'), GETPOST('date_fin_year', 'int'));
1143  print $form->selectDate($tmpdate, 'date_fin_', 0, 0, 0, '', 1, 1);
1144  }
1145  print ' &nbsp; &nbsp; ';
1146  print $form->selectarray('endhalfday', $listhalfday, (GETPOST('endhalfday', 'alpha') ?GETPOST('endhalfday', 'alpha') : 'afternoon'));
1147  print '</td>';
1148  print '</tr>';
1149 
1150  // Approver
1151  print '<tr>';
1152  print '<td class="fieldrequired">'.$langs->trans("ReviewedByCP").'</td>';
1153  print '<td>';
1154 
1155  $object = new Holiday($db);
1156  $include_users = $object->fetch_users_approver_holiday();
1157  if (empty($include_users)) {
1158  print img_warning().' '.$langs->trans("NobodyHasPermissionToValidateHolidays");
1159  } else {
1160  // Defined default approver (the forced approved of user or the supervisor if no forced value defined)
1161  // Note: This use will be set only if the deinfed approvr has permission to approve so is inside include_users
1162  $defaultselectuser = (empty($user->fk_user_holiday_validator) ? $user->fk_user : $user->fk_user_holiday_validator);
1163  if (!empty($conf->global->HOLIDAY_DEFAULT_VALIDATOR)) {
1164  $defaultselectuser = $conf->global->HOLIDAY_DEFAULT_VALIDATOR; // Can force default approver
1165  }
1166  if (GETPOST('valideur', 'int') > 0) {
1167  $defaultselectuser = GETPOST('valideur', 'int');
1168  }
1169  $s = $form->select_dolusers($defaultselectuser, "valideur", 1, '', 0, $include_users, '', '0,'.$conf->entity, 0, 0, '', 0, '', 'minwidth200 maxwidth500');
1170  print img_picto('', 'user', 'class="pictofixedwidth"').$form->textwithpicto($s, $langs->trans("AnyOtherInThisListCanValidate"));
1171  }
1172 
1173  //print $form->select_dolusers((GETPOST('valideur','int')>0?GETPOST('valideur','int'):$user->fk_user), "valideur", 1, ($user->admin ? '' : array($user->id)), 0, '', 0, 0, 0, 0, '', 0, '', '', 1); // By default, hierarchical parent
1174  print '</td>';
1175  print '</tr>';
1176 
1177  // Description
1178  print '<tr>';
1179  print '<td>'.$langs->trans("DescCP").'</td>';
1180  print '<td class="tdtop">';
1181  $doleditor = new DolEditor('description', GETPOST('description', 'restricthtml'), '', 80, 'dolibarr_notes', 'In', 0, false, isModEnabled('fckeditor'), ROWS_3, '90%');
1182  print $doleditor->Create(1);
1183  print '</td></tr>';
1184 
1185  // Other attributes
1186  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php';
1187 
1188  print '</tbody>';
1189  print '</table>';
1190 
1191  print dol_get_fiche_end();
1192 
1193  print $form->buttonsSaveCancel("SendRequestCP");
1194 
1195  print '</from>'."\n";
1196  }
1197 } else {
1198  if ($error && $action != 'edit') {
1199  print '<div class="tabBar">';
1200  print $error;
1201  print '<br><br><input type="button" value="'.$langs->trans("ReturnCP").'" class="button" onclick="history.go(-1)" />';
1202  print '</div>';
1203  } else {
1204  // Show page in view or edit mode
1205  if (($id > 0) || $ref) {
1206  $result = $object->fetch($id, $ref);
1207 
1208  $approverexpected = new User($db);
1209  $approverexpected->fetch($object->fk_validator); // Use that should be the approver
1210 
1211  $userRequest = new User($db);
1212  $userRequest->fetch($object->fk_user);
1213 
1214  //print load_fiche_titre($langs->trans('TitreRequestCP'));
1215 
1216  // Si il y a une erreur
1217  if (GETPOST('error')) {
1218  switch (GETPOST('error')) {
1219  case 'datefin':
1220  $errors[] = $langs->transnoentitiesnoconv('ErrorEndDateCP');
1221  break;
1222  case 'SQL_Create':
1223  $errors[] = $langs->transnoentitiesnoconv('ErrorSQLCreateCP');
1224  break;
1225  case 'CantCreate':
1226  $errors[] = $langs->transnoentitiesnoconv('CantCreateCP');
1227  break;
1228  case 'Valideur':
1229  $errors[] = $langs->transnoentitiesnoconv('InvalidValidatorCP');
1230  break;
1231  case 'nodatedebut':
1232  $errors[] = $langs->transnoentitiesnoconv('NoDateDebut');
1233  break;
1234  case 'nodatefin':
1235  $errors[] = $langs->transnoentitiesnoconv('NoDateFin');
1236  break;
1237  case 'DureeHoliday':
1238  $errors[] = $langs->transnoentitiesnoconv('ErrorDureeCP');
1239  break;
1240  case 'NoMotifRefuse':
1241  $errors[] = $langs->transnoentitiesnoconv('NoMotifRefuseCP');
1242  break;
1243  case 'mail':
1244  $errors[] = $langs->transnoentitiesnoconv('ErrorMailNotSend');
1245  break;
1246  }
1247 
1248  setEventMessages($errors, null, 'errors');
1249  }
1250 
1251  // check if the user has the right to read this request
1252  if ($canread) {
1253  $head = holiday_prepare_head($object);
1254 
1255  if (($action == 'edit' && $object->statut == Holiday::STATUS_DRAFT) || ($action == 'editvalidator')) {
1256  if ($action == 'edit' && $object->statut == Holiday::STATUS_DRAFT) {
1257  $edit = true;
1258  }
1259 
1260  print '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">'."\n";
1261  print '<input type="hidden" name="token" value="'.newToken().'" />'."\n";
1262  print '<input type="hidden" name="action" value="update"/>'."\n";
1263  print '<input type="hidden" name="id" value="'.$object->id.'" />'."\n";
1264  }
1265 
1266  print dol_get_fiche_head($head, 'card', $langs->trans("CPTitreMenu"), -1, 'holiday');
1267 
1268  $linkback = '<a href="'.DOL_URL_ROOT.'/holiday/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
1269 
1270  dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref');
1271 
1272 
1273  print '<div class="fichecenter">';
1274  print '<div class="fichehalfleft">';
1275  print '<div class="underbanner clearboth"></div>';
1276 
1277  print '<table class="border tableforfield centpercent">';
1278  print '<tbody>';
1279 
1280  // User
1281  print '<tr>';
1282  print '<td class="titlefield">'.$langs->trans("User").'</td>';
1283  print '<td>';
1284  print $userRequest->getNomUrl(-1, 'leave');
1285  print '</td></tr>';
1286 
1287  // Type
1288  print '<tr>';
1289  print '<td>'.$langs->trans("Type").'</td>';
1290  print '<td>';
1291  $typeleaves = $object->getTypes(1, -1);
1292  $labeltoshow = (($typeleaves[$object->fk_type]['code'] && $langs->trans($typeleaves[$object->fk_type]['code']) != $typeleaves[$object->fk_type]['code']) ? $langs->trans($typeleaves[$object->fk_type]['code']) : $typeleaves[$object->fk_type]['label']);
1293  print empty($labeltoshow) ? $langs->trans("TypeWasDisabledOrRemoved", $object->fk_type) : $labeltoshow;
1294  print '</td>';
1295  print '</tr>';
1296 
1297  $starthalfday = ($object->halfday == -1 || $object->halfday == 2) ? 'afternoon' : 'morning';
1298  $endhalfday = ($object->halfday == 1 || $object->halfday == 2) ? 'morning' : 'afternoon';
1299 
1300  if (!$edit) {
1301  print '<tr>';
1302  print '<td class="nowrap">';
1303  print $form->textwithpicto($langs->trans('DateDebCP'), $langs->trans("FirstDayOfHoliday"));
1304  print '</td>';
1305  print '<td>'.dol_print_date($object->date_debut, 'day');
1306  print ' &nbsp; &nbsp; ';
1307  print '<span class="opacitymedium">'.$langs->trans($listhalfday[$starthalfday]).'</span>';
1308  print '</td>';
1309  print '</tr>';
1310  } else {
1311  print '<tr>';
1312  print '<td class="nowrap">';
1313  print $form->textwithpicto($langs->trans('DateDebCP'), $langs->trans("FirstDayOfHoliday"));
1314  print '</td>';
1315  print '<td>';
1316  $tmpdate = dol_mktime(0, 0, 0, GETPOST('date_debut_month', 'int'), GETPOST('date_debut_day', 'int'), GETPOST('date_debut_year', 'int'));
1317  print $form->selectDate($tmpdate ? $tmpdate : $object->date_debut, 'date_debut_');
1318  print ' &nbsp; &nbsp; ';
1319  print $form->selectarray('starthalfday', $listhalfday, (GETPOST('starthalfday') ?GETPOST('starthalfday') : $starthalfday));
1320  print '</td>';
1321  print '</tr>';
1322  }
1323 
1324  if (!$edit) {
1325  print '<tr>';
1326  print '<td class="nowrap">';
1327  print $form->textwithpicto($langs->trans('DateFinCP'), $langs->trans("LastDayOfHoliday"));
1328  print '</td>';
1329  print '<td>'.dol_print_date($object->date_fin, 'day');
1330  print ' &nbsp; &nbsp; ';
1331  print '<span class="opacitymedium">'.$langs->trans($listhalfday[$endhalfday]).'</span>';
1332  print '</td>';
1333  print '</tr>';
1334  } else {
1335  print '<tr>';
1336  print '<td class="nowrap">';
1337  print $form->textwithpicto($langs->trans('DateFinCP'), $langs->trans("LastDayOfHoliday"));
1338  print '</td>';
1339  print '<td>';
1340  print $form->selectDate($object->date_fin, 'date_fin_');
1341  print ' &nbsp; &nbsp; ';
1342  print $form->selectarray('endhalfday', $listhalfday, (GETPOST('endhalfday') ?GETPOST('endhalfday') : $endhalfday));
1343  print '</td>';
1344  print '</tr>';
1345  }
1346 
1347  // Nb of days
1348  print '<tr>';
1349  print '<td>';
1350  $htmlhelp = $langs->trans('NbUseDaysCPHelp');
1351  $includesaturday = (isset($conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_SATURDAY) ? $conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_SATURDAY : 1);
1352  $includesunday = (isset($conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_SUNDAY) ? $conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_SUNDAY : 1);
1353  if ($includesaturday) {
1354  $htmlhelp .= '<br>'.$langs->trans("DayIsANonWorkingDay", $langs->trans("Saturday"));
1355  }
1356  if ($includesunday) {
1357  $htmlhelp .= '<br>'.$langs->trans("DayIsANonWorkingDay", $langs->trans("Sunday"));
1358  }
1359  print $form->textwithpicto($langs->trans('NbUseDaysCP'), $htmlhelp);
1360  print '</td>';
1361  print '<td>';
1362  print num_open_day($object->date_debut_gmt, $object->date_fin_gmt, 0, 1, $object->halfday);
1363  print '</td>';
1364  print '</tr>';
1365 
1366  if ($object->statut == Holiday::STATUS_REFUSED) {
1367  print '<tr>';
1368  print '<td>'.$langs->trans('DetailRefusCP').'</td>';
1369  print '<td>'.$object->detail_refuse.'</td>';
1370  print '</tr>';
1371  }
1372 
1373  // Description
1374  if (!$edit) {
1375  print '<tr>';
1376  print '<td>'.$langs->trans('DescCP').'</td>';
1377  print '<td>'.nl2br($object->description).'</td>';
1378  print '</tr>';
1379  } else {
1380  print '<tr>';
1381  print '<td>'.$langs->trans('DescCP').'</td>';
1382  print '<td class="tdtop">';
1383  $doleditor = new DolEditor('description', $object->description, '', 80, 'dolibarr_notes', 'In', 0, false, isModEnabled('fckeditor'), ROWS_3, '90%');
1384  print $doleditor->Create(1);
1385  print '</td></tr>';
1386  }
1387 
1388  // Other attributes
1389  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
1390 
1391  print '</tbody>';
1392  print '</table>'."\n";
1393 
1394  print '</div>';
1395  print '<div class="fichehalfright">';
1396 
1397  print '<div class="underbanner clearboth"></div>';
1398 
1399  // Info workflow
1400  print '<table class="border tableforfield centpercent">'."\n";
1401  print '<tbody>';
1402 
1403  if (!empty($object->fk_user_create)) {
1404  $userCreate = new User($db);
1405  $userCreate->fetch($object->fk_user_create);
1406  print '<tr>';
1407  print '<td class="titlefield">'.$langs->trans('RequestByCP').'</td>';
1408  print '<td>'.$userCreate->getNomUrl(-1).'</td>';
1409  print '</tr>';
1410  }
1411 
1412  // Approver
1413  if (!$edit && $action != 'editvalidator') {
1414  print '<tr>';
1415  print '<td class="titlefield">';
1416  if ($object->statut == Holiday::STATUS_APPROVED || $object->statut == Holiday::STATUS_CANCELED) {
1417  print $langs->trans('ApprovedBy');
1418  } else {
1419  print $langs->trans('ReviewedByCP');
1420  }
1421  print '</td>';
1422  print '<td>';
1423  if ($object->statut == Holiday::STATUS_APPROVED || $object->statut == Holiday::STATUS_CANCELED) {
1424  if ($object->fk_user_approve > 0) {
1425  $approverdone = new User($db);
1426  $approverdone->fetch($object->fk_user_approve);
1427  print $approverdone->getNomUrl(-1);
1428  }
1429  } else {
1430  print $approverexpected->getNomUrl(-1);
1431  }
1432  $include_users = $object->fetch_users_approver_holiday();
1433  if (is_array($include_users) && in_array($user->id, $include_users) && $object->statut == Holiday::STATUS_VALIDATED) {
1434  print '<a class="editfielda paddingleft" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=editvalidator">'.img_edit($langs->trans("Edit")).'</a>';
1435  }
1436  print '</td>';
1437  print '</tr>';
1438  } else {
1439  print '<tr>';
1440  print '<td class="titlefield">'.$langs->trans('ReviewedByCP').'</td>'; // Will be approved by
1441  print '<td>';
1442  $include_users = $object->fetch_users_approver_holiday();
1443  if (!in_array($object->fk_validator, $include_users)) { // Add the current validator to the list to not lose it when editing.
1444  $include_users[] = $object->fk_validator;
1445  }
1446  if (empty($include_users)) {
1447  print img_warning().' '.$langs->trans("NobodyHasPermissionToValidateHolidays");
1448  } else {
1449  $arrayofvalidatorstoexclude = (($user->admin || ($user->id != $userRequest->id)) ? '' : array($user->id)); // Nobody if we are admin or if we are not the user of the leave.
1450  $s = $form->select_dolusers($object->fk_validator, "valideur", (($action == 'editvalidator') ? 0 : 1), $arrayofvalidatorstoexclude, 0, $include_users);
1451  print $form->textwithpicto($s, $langs->trans("AnyOtherInThisListCanValidate"));
1452  }
1453  if ($action == 'editvalidator') {
1454  print '<input type="submit" class="button button-save" name="savevalidator" value="'.$langs->trans("Save").'">';
1455  print '<input type="submit" class="button button-cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
1456  }
1457  print '</td>';
1458  print '</tr>';
1459  }
1460 
1461  print '<tr>';
1462  print '<td>'.$langs->trans('DateCreation').'</td>';
1463  print '<td>'.dol_print_date($object->date_create, 'dayhour', 'tzuser').'</td>';
1464  print '</tr>';
1465  if ($object->statut == Holiday::STATUS_APPROVED || $object->statut == Holiday::STATUS_CANCELED) {
1466  print '<tr>';
1467  print '<td>'.$langs->trans('DateValidCP').'</td>';
1468  print '<td>'.dol_print_date($object->date_approval, 'dayhour', 'tzuser').'</td>'; // warning: date_valid is approval date on holiday module
1469  print '</tr>';
1470  }
1471  if ($object->statut == Holiday::STATUS_CANCELED) {
1472  print '<tr>';
1473  print '<td>'.$langs->trans('DateCancelCP').'</td>';
1474  print '<td>'.dol_print_date($object->date_cancel, 'dayhour', 'tzuser').'</td>';
1475  print '</tr>';
1476  }
1477  if ($object->statut == Holiday::STATUS_REFUSED) {
1478  print '<tr>';
1479  print '<td>'.$langs->trans('DateRefusCP').'</td>';
1480  print '<td>'.dol_print_date($object->date_refuse, 'dayhour', 'tzuser').'</td>';
1481  print '</tr>';
1482  }
1483  print '</tbody>';
1484  print '</table>';
1485 
1486  print '</div>';
1487  print '</div>';
1488 
1489  print '<div class="clearboth"></div>';
1490 
1491  print dol_get_fiche_end();
1492 
1493 
1494  // Confirmation messages
1495  if ($action == 'delete') {
1496  if ($candelete) {
1497  print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans("TitleDeleteCP"), $langs->trans("ConfirmDeleteCP"), "confirm_delete", '', 0, 1);
1498  }
1499  }
1500 
1501  // Si envoi en validation
1502  if ($action == 'sendToValidate' && $object->statut == Holiday::STATUS_DRAFT) {
1503  print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans("TitleToValidCP"), $langs->trans("ConfirmToValidCP"), "confirm_send", '', 1, 1);
1504  }
1505 
1506  // Si validation de la demande
1507  if ($action == 'valid') {
1508  print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans("TitleValidCP"), $langs->trans("ConfirmValidCP"), "confirm_valid", '', 1, 1);
1509  }
1510 
1511  // Si refus de la demande
1512  if ($action == 'refuse') {
1513  $array_input = array(array('type'=>"text", 'label'=> $langs->trans('DetailRefusCP'), 'name'=>"detail_refuse", 'size'=>"50", 'value'=>""));
1514  print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id."&action=confirm_refuse", $langs->trans("TitleRefuseCP"), $langs->trans('ConfirmRefuseCP'), "confirm_refuse", $array_input, 1, 0);
1515  }
1516 
1517  // Si annulation de la demande
1518  if ($action == 'cancel') {
1519  print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans("TitleCancelCP"), $langs->trans("ConfirmCancelCP"), "confirm_cancel", '', 1, 1);
1520  }
1521 
1522  // Si back to draft
1523  if ($action == 'backtodraft') {
1524  print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans("TitleSetToDraft"), $langs->trans("ConfirmSetToDraft"), "confirm_draft", '', 1, 1);
1525  }
1526 
1527  if (($action == 'edit' && $object->statut == Holiday::STATUS_DRAFT) || ($action == 'editvalidator')) {
1528  if ($action == 'edit' && $object->statut == Holiday::STATUS_DRAFT) {
1529  if ($cancreate && $object->statut == Holiday::STATUS_DRAFT) {
1530  print $form->buttonsSaveCancel();
1531  }
1532  }
1533 
1534  print '</form>';
1535  }
1536 
1537  if (!$edit) {
1538  // Buttons for actions
1539 
1540  print '<div class="tabsAction">';
1541 
1542  if ($cancreate && $object->statut == Holiday::STATUS_DRAFT) {
1543  print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=edit&token='.newToken().'" class="butAction">'.$langs->trans("EditCP").'</a>';
1544  }
1545 
1546  if ($cancreate && $object->statut == Holiday::STATUS_DRAFT) { // If draft
1547  print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=sendToValidate&token='.newToken().'" class="butAction">'.$langs->trans("Validate").'</a>';
1548  }
1549 
1550  if ($object->statut == Holiday::STATUS_VALIDATED) { // If validated
1551  // Button Approve / Refuse
1552  if ($user->id == $object->fk_validator) {
1553  print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=valid&token='.newToken().'" class="butAction">'.$langs->trans("Approve").'</a>';
1554  print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=refuse&token='.newToken().'" class="butAction">'.$langs->trans("ActionRefuseCP").'</a>';
1555  } else {
1556  print '<a href="#" class="butActionRefused classfortooltip" title="'.$langs->trans("NotTheAssignedApprover").'">'.$langs->trans("Approve").'</a>';
1557  print '<a href="#" class="butActionRefused classfortooltip" title="'.$langs->trans("NotTheAssignedApprover").'">'.$langs->trans("ActionRefuseCP").'</a>';
1558 
1559  // Button Cancel (because we can't approve)
1560  if ($cancreate || $cancreateall) {
1561  if (($object->date_debut > dol_now()) || !empty($user->admin)) {
1562  print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=cancel&token='.newToken().'" class="butAction">'.$langs->trans("ActionCancelCP").'</a>';
1563  } else {
1564  print '<a href="#" class="butActionRefused classfortooltip" title="'.$langs->trans("HolidayStarted").'-'.$langs->trans("NotAllowed").'">'.$langs->trans("ActionCancelCP").'</a>';
1565  }
1566  }
1567  }
1568  }
1569  if ($object->statut == Holiday::STATUS_APPROVED) { // If validated and approved
1570  if ($user->id == $object->fk_validator || $user->id == $object->fk_user_approve || $cancreate || $cancreateall) {
1571  if (($object->date_debut > dol_now()) || !empty($user->admin) || $user->id == $object->fk_user_approve) {
1572  print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=cancel&token='.newToken().'" class="butAction">'.$langs->trans("ActionCancelCP").'</a>';
1573  } else {
1574  print '<a href="#" class="butActionRefused classfortooltip" title="'.$langs->trans("HolidayStarted").'-'.$langs->trans("NotAllowed").'">'.$langs->trans("ActionCancelCP").'</a>';
1575  }
1576  } else { // I have no rights on the user of the holiday.
1577  if (!empty($user->admin)) { // If current approver can't cancel an approved leave, we allow admin user
1578  print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=cancel&token='.newToken().'" class="butAction">'.$langs->trans("ActionCancelCP").'</a>';
1579  } else {
1580  print '<a href="#" class="butActionRefused classfortooltip" title="'.$langs->trans("NotAllowed").'">'.$langs->trans("ActionCancelCP").'</a>';
1581  }
1582  }
1583  }
1584 
1585  if (($cancreate || $cancreateall) && $object->statut == Holiday::STATUS_CANCELED) {
1586  print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=backtodraft" class="butAction">'.$langs->trans("SetToDraft").'</a>';
1587  }
1588  if ($candelete && ($object->statut == Holiday::STATUS_DRAFT || $object->statut == Holiday::STATUS_CANCELED || $object->statut == Holiday::STATUS_REFUSED)) { // If draft or canceled or refused
1589  print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken().'" class="butActionDelete">'.$langs->trans("DeleteCP").'</a>';
1590  }
1591 
1592  print '</div>';
1593  }
1594  } else {
1595  print '<div class="tabBar">';
1596  print $langs->trans('ErrorUserViewCP');
1597  print '<br><br><input type="button" value="'.$langs->trans("ReturnCP").'" class="button" onclick="history.go(-1)" />';
1598  print '</div>';
1599  }
1600  } else {
1601  print '<div class="tabBar">';
1602  print $langs->trans('ErrorIDFicheCP');
1603  print '<br><br><input type="button" value="'.$langs->trans("ReturnCP").'" class="button" onclick="history.go(-1)" />';
1604  print '</div>';
1605  }
1606 
1607 
1608  // Select mail models is same action as presend
1609  if (GETPOST('modelselected')) {
1610  $action = 'presend';
1611  }
1612 
1613  if ($action != 'presend' && $action != 'edit') {
1614  print '<div class="fichecenter"><div class="fichehalfleft">';
1615  print '<a name="builddoc"></a>'; // ancre
1616 
1617  $includedocgeneration = 0;
1618 
1619  // Documents
1620  if ($includedocgeneration) {
1621  $objref = dol_sanitizeFileName($object->ref);
1622  $relativepath = $objref.'/'.$objref.'.pdf';
1623  $filedir = $conf->holiday->dir_output.'/'.$object->element.'/'.$objref;
1624  $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
1625  $genallowed = ($user->rights->holiday->read && $object->fk_user == $user->id) || !empty($user->rights->holiday->readall); // If you can read, you can build the PDF to read content
1626  $delallowed = ($user->rights->holiday->write && $object->fk_user == $user->id) || !empty($user->rights->holiday->writeall_advance); // If you can create/edit, you can remove a file on card
1627  print $formfile->showdocuments('holiday:Holiday', $object->element.'/'.$objref, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', '', '', $langs->defaultlang);
1628  }
1629 
1630  // Show links to link elements
1631  //$linktoelem = $form->showLinkToObjectBlock($object, null, array('myobject'));
1632  //$somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
1633 
1634 
1635  print '</div><div class="fichehalfright">';
1636 
1637  $MAXEVENT = 10;
1638  $morehtmlright = '';
1639 
1640  // List of actions on element
1641  include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
1642  $formactions = new FormActions($db);
1643  $somethingshown = $formactions->showactions($object, $object->element, (is_object($object->thirdparty) ? $object->thirdparty->id : 0), 1, '', $MAXEVENT, '', $morehtmlright);
1644 
1645  print '</div></div>';
1646  }
1647  }
1648 }
1649 
1650 // End of page
1651 llxFooter();
1652 
1653 if (is_object($db)) {
1654  $db->close();
1655 }
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(preg_match('/set_([a-z0-9_\-]+)/i', $action, $reg)) if(preg_match('/del_([a-z0-9_\-]+)/i', $action, $reg)) if($action=='set') elseif($action=='specimen') elseif($action=='setmodel') elseif($action=='del') elseif($action=='setdoc') $formactions
View.
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 send emails (with attachments or not) Usage: $mailfile = new CMailFile($subject,...
Class to manage a WYSIWYG editor.
Class to manage standard extra fields.
Class to manage building of HTML components.
Class to manage generation of HTML components Only common components must be here.
Class of the module paid holiday.
const STATUS_VALIDATED
Validated status.
const STATUS_DRAFT
Draft status.
const STATUS_REFUSED
Refused.
const STATUS_CANCELED
Canceled.
const STATUS_APPROVED
Approved.
Class to manage Dolibarr users.
Definition: user.class.php:48
$parameters
Actions.
Definition: card.php:83
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
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:1015
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
Definition: date.lib.php:122
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.
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
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.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
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_escape_js($stringtoescape, $mode=0, $noescapebackslashn=0)
Returns text escaped for inclusion into javascript code.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
dol_clone($object, $native=0)
Create a clone of instance of object (new instance with same value for each properties) With native =...
dolGetFirstLastname($firstname, $lastname, $nameorder=-1)
Return firstname and lastname in correct order.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='')
Show information for admin users or standard users.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
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.
img_edit($titlealt='default', $float=0, $other='')
Show logo editer/modifier fiche.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
holiday_prepare_head($object)
Return array head with list of tabs to view object informations.
Definition: holiday.lib.php:31
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=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.