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