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