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