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