dolibarr  9.0.0
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@zendsi.com>
7  * Copyright (C) 2014-2017 Ferran Marcet <fmarcet@2byte.es>
8  * Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 3 of the License, orwrite
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program. If not, see <http://www.gnu.org/licenses/>.
22  */
23 
30 require '../main.inc.php';
31 require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/user/class/usergroup.class.php';
33 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
34 require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
35 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
36 require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
37 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
38 require_once DOL_DOCUMENT_ROOT.'/core/lib/holiday.lib.php';
39 require_once DOL_DOCUMENT_ROOT.'/holiday/common.inc.php';
40 
41 // Get parameters
42 $action=GETPOST('action', 'alpha');
43 $id=GETPOST('id', 'int');
44 $ref=GETPOST('ref', 'alpha');
45 $fuserid = (GETPOST('fuserid','int')?GETPOST('fuserid','int'):$user->id);
46 
47 // Protection if external user
48 if ($user->societe_id > 0) accessforbidden();
49 
50 $now=dol_now();
51 
52 // Load translation files required by the page
53 $langs->load("holiday");
54 
55 $childids = $user->getAllChildIds(1);
56 
57 $cancreate = 0;
58 if (! empty($user->rights->holiday->write_all)) $cancreate=1;
59 if (! empty($user->rights->holiday->write) && in_array($fuserid, $childids)) $cancreate=1;
60 
61 $candelete = 0;
62 if (! empty($user->rights->holiday->delete)) $candelete=1;
63 
64 $morefilter = 'AND employee = 1';
65 if (! empty($conf->global->HOLIDAY_FOR_NON_SALARIES_TOO)) $morefilter = '';
66 
67 
68 /*
69  * Actions
70  */
71 
72 // If create a request
73 if ($action == 'create')
74 {
75  $object = new Holiday($db);
76 
77  // If no right to create a request
78  if (! $cancreate)
79  {
80  $error++;
81  setEventMessages($langs->trans('CantCreateCP'), null, 'errors');
82  $action='request';
83  }
84 
85  if (! $error)
86  {
87  $db->begin();
88 
89  $date_debut = dol_mktime(0, 0, 0, GETPOST('date_debut_month'), GETPOST('date_debut_day'), GETPOST('date_debut_year'));
90  $date_fin = dol_mktime(0, 0, 0, GETPOST('date_fin_month'), GETPOST('date_fin_day'), GETPOST('date_fin_year'));
91  $date_debut_gmt = dol_mktime(0, 0, 0, GETPOST('date_debut_month'), GETPOST('date_debut_day'), GETPOST('date_debut_year'), 1);
92  $date_fin_gmt = dol_mktime(0, 0, 0, GETPOST('date_fin_month'), GETPOST('date_fin_day'), GETPOST('date_fin_year'), 1);
93  $starthalfday=GETPOST('starthalfday');
94  $endhalfday=GETPOST('endhalfday');
95  $type=GETPOST('type');
96  $halfday=0;
97  if ($starthalfday == 'afternoon' && $endhalfday == 'morning') $halfday=2;
98  else if ($starthalfday == 'afternoon') $halfday=-1;
99  else if ($endhalfday == 'morning') $halfday=1;
100 
101  $valideur = GETPOST('valideur');
102  $description = trim(GETPOST('description'));
103 
104  // If no type
105  if ($type <= 0)
106  {
107  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type")), null, 'errors');
108  $error++;
109  $action='create';
110  }
111 
112  // If no start date
113  if (empty($date_debut))
114  {
115  setEventMessages($langs->trans("NoDateDebut"), null, 'errors');
116  $error++;
117  $action='create';
118  }
119  // If no end date
120  if (empty($date_fin))
121  {
122  setEventMessages($langs->trans("NoDateFin"), null, 'errors');
123  $error++;
124  $action='create';
125  }
126  // If start date after end date
127  if ($date_debut > $date_fin)
128  {
129  setEventMessages($langs->trans("ErrorEndDateCP"), null, 'errors');
130  $error++;
131  $action='create';
132  }
133 
134  // Check if there is already holiday for this period
135  $verifCP = $object->verifDateHolidayCP($fuserid, $date_debut, $date_fin, $halfday);
136  if (! $verifCP)
137  {
138  setEventMessages($langs->trans("alreadyCPexist"), null, 'errors');
139  $error++;
140  $action='create';
141  }
142 
143  // If there is no Business Days within request
144  $nbopenedday=num_open_day($date_debut_gmt, $date_fin_gmt, 0, 1, $halfday);
145  if($nbopenedday < 0.5)
146  {
147  setEventMessages($langs->trans("ErrorDureeCP"), null, 'errors');
148  $error++;
149  $action='create';
150  }
151 
152  // If no validator designated
153  if ($valideur < 1)
154  {
155  setEventMessages($langs->transnoentitiesnoconv('InvalidValidatorCP'), null, 'errors');
156  $error++;
157  }
158 
159  $result = 0;
160 
161  if (! $error)
162  {
163  $object->fk_user = $fuserid;
164  $object->description = $description;
165  $object->fk_validator = $valideur;
166  $object->fk_type = $type;
167  $object->date_debut = $date_debut;
168  $object->date_fin = $date_fin;
169  $object->halfday = $halfday;
170 
171  $result = $object->create($user);
172  if ($result <= 0)
173  {
174  setEventMessages($object->error, $object->errors, 'errors');
175  $error++;
176  }
177  }
178 
179  // If no SQL error we redirect to the request card
180  if (! $error)
181  {
182  $db->commit();
183 
184  header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
185  exit;
186  }
187  else
188  {
189  $db->rollback();
190  }
191  }
192 }
193 
194 if ($action == 'update')
195 {
196  $date_debut = dol_mktime(0, 0, 0, GETPOST('date_debut_month'), GETPOST('date_debut_day'), GETPOST('date_debut_year'));
197  $date_fin = dol_mktime(0, 0, 0, GETPOST('date_fin_month'), GETPOST('date_fin_day'), GETPOST('date_fin_year'));
198  $date_debut_gmt = dol_mktime(0, 0, 0, GETPOST('date_debut_month'), GETPOST('date_debut_day'), GETPOST('date_debut_year'), 1);
199  $date_fin_gmt = dol_mktime(0, 0, 0, GETPOST('date_fin_month'), GETPOST('date_fin_day'), GETPOST('date_fin_year'), 1);
200  $starthalfday=GETPOST('starthalfday');
201  $endhalfday=GETPOST('endhalfday');
202  $halfday=0;
203  if ($starthalfday == 'afternoon' && $endhalfday == 'morning') $halfday=2;
204  else if ($starthalfday == 'afternoon') $halfday=-1;
205  else if ($endhalfday == 'morning') $halfday=1;
206 
207  // If no right to modify a request
208  if (! $user->rights->holiday->write)
209  {
210  header('Location: '.$_SERVER["PHP_SELF"].'?action=request&error=CantUpdate');
211  exit;
212  }
213 
214  $object = new Holiday($db);
215  $object->fetch($id);
216 
217  // If under validation
218  if ($object->statut == Holiday::STATUS_DRAFT)
219  {
220  // If this is the requestor or has read/write rights
221  if ($cancreate)
222  {
223  $valideur = $_POST['valideur'];
224  $description = trim($_POST['description']);
225 
226  // If no start date
227  if (empty($_POST['date_debut_'])) {
228  header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=edit&error=nodatedebut');
229  exit;
230  }
231 
232  // If no end date
233  if (empty($_POST['date_fin_'])) {
234  header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=edit&error=nodatefin');
235  exit;
236  }
237 
238  // If start date after end date
239  if ($date_debut > $date_fin) {
240  header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=edit&error=datefin');
241  exit;
242  }
243 
244  // If no validator designated
245  if ($valideur < 1) {
246  header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=edit&error=Valideur');
247  exit;
248  }
249 
250  // If there is no Business Days within request
251  $nbopenedday=num_open_day($date_debut_gmt, $date_fin_gmt, 0, 1, $halfday);
252  if ($nbopenedday < 0.5)
253  {
254  header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=edit&error=DureeHoliday');
255  exit;
256  }
257 
258  $object->description = $description;
259  $object->date_debut = $date_debut;
260  $object->date_fin = $date_fin;
261  $object->fk_validator = $valideur;
262  $object->halfday = $halfday;
263 
264  // Update
265  $verif = $object->update($user);
266 
267  if ($verif <= 0)
268  {
269  setEventMessages($object->error, $object->errors, 'warnings');
270  $action='edit';
271  }
272  else
273  {
274  header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
275  exit;
276  }
277  }
278  else
279  {
280  setEventMessages($langs->trans("NotEnoughPermissions"), null, 'errors');
281  $action='';
282  }
283  }
284  else
285  {
286  setEventMessages($langs->trans("ErrorBadStatus"), null, 'errors');
287  $action='';
288  }
289 }
290 
291 // If delete of request
292 if ($action == 'confirm_delete' && GETPOST('confirm') == 'yes' && $user->rights->holiday->delete)
293 {
294  $error=0;
295 
296  $db->begin();
297 
298  $object = new Holiday($db);
299  $object->fetch($id);
300 
301  // If this is a rough draft, approved, canceled or refused
302  if ($object->statut == Holiday::STATUS_DRAFT || $object->statut == Holiday::STATUS_CANCELED || $object->statut == Holiday::STATUS_REFUSED)
303  {
304  // Si l'utilisateur à le droit de lire cette demande, il peut la supprimer
305  if ($candelete)
306  {
307  $result=$object->delete($user);
308  }
309  else
310  {
311  $error++;
312  setEventMessages($langs->trans('ErrorCantDeleteCP'), null, 'errors');
313  $action='';
314  }
315  }
316 
317  if (! $error)
318  {
319  $db->commit();
320  header('Location: list.php?restore_lastsearch_values=1');
321  exit;
322  }
323  else
324  {
325  $db->rollback();
326  }
327 }
328 
329 // Action validate (+ send email for approval)
330 if ($action == 'confirm_send')
331 {
332  $object = new Holiday($db);
333  $object->fetch($id);
334 
335  // Si brouillon et créateur
336  if($object->statut == Holiday::STATUS_DRAFT && $cancreate)
337  {
338  $object->oldcopy = dol_clone($object);
339 
340  $object->statut = Holiday::STATUS_VALIDATED;
341 
342  $verif = $object->validate($user);
343 
344  // Si pas d'erreur SQL on redirige vers la fiche de la demande
345  if ($verif > 0)
346  {
347  // To
348  $destinataire = new User($db);
349  $destinataire->fetch($object->fk_validator);
350  $emailTo = $destinataire->email;
351 
352  if (!$emailTo)
353  {
354  dol_syslog("Expected validator has no email, so we redirect directly to finished page without sending email");
355  header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
356  exit;
357  }
358 
359  // From
360  $expediteur = new User($db);
361  $expediteur->fetch($object->fk_user);
362  $emailFrom = $expediteur->email;
363 
364  // Subject
365  $societeName = $conf->global->MAIN_INFO_SOCIETE_NOM;
366  if (! empty($conf->global->MAIN_APPLICATION_TITLE)) $societeName = $conf->global->MAIN_APPLICATION_TITLE;
367 
368  $subject = $societeName." - ".$langs->transnoentitiesnoconv("HolidaysToValidate");
369 
370  // Content
371  $message = $langs->transnoentitiesnoconv("Hello")." ".$destinataire->firstname.",\n";
372  $message.= "\n";
373  $message.= $langs->transnoentities("HolidaysToValidateBody")."\n";
374 
375  $delayForRequest = $object->getConfCP('delayForRequest');
376  //$delayForRequest = $delayForRequest * (60*60*24);
377 
378  $nextMonth = dol_time_plus_duree($now, $delayForRequest, 'd');
379 
380  // Si l'option pour avertir le valideur en cas de délai trop court
381  if($object->getConfCP('AlertValidatorDelay'))
382  {
383  if($object->date_debut < $nextMonth)
384  {
385  $message.= "\n";
386  $message.= $langs->transnoentities("HolidaysToValidateDelay",$object->getConfCP('delayForRequest'))."\n";
387  }
388  }
389 
390  // Si l'option pour avertir le valideur en cas de solde inférieur à la demande
391  if ($object->getConfCP('AlertValidatorSolde'))
392  {
393  $nbopenedday=num_open_day($object->date_debut_gmt,$object->date_fin_gmt,0,1,$object->halfday);
394  if ($nbopenedday > $object->getCPforUser($object->fk_user, $object->fk_type))
395  {
396  $message.= "\n";
397  $message.= $langs->transnoentities("HolidaysToValidateAlertSolde")."\n";
398  }
399  }
400 
401  $message.= "\n";
402  $message.= "- ".$langs->transnoentitiesnoconv("Name")." : ".dolGetFirstLastname($expediteur->firstname, $expediteur->lastname)."\n";
403  $message.= "- ".$langs->transnoentitiesnoconv("Period")." : ".dol_print_date($object->date_debut,'day')." ".$langs->transnoentitiesnoconv("To")." ".dol_print_date($object->date_fin,'day')."\n";
404  $message.= "- ".$langs->transnoentitiesnoconv("Link")." : ".$dolibarr_main_url_root."/holiday/card.php?id=".$object->id."\n\n";
405  $message.= "\n";
406 
407  $trackid='leav'.$object->id;
408 
409  $mail = new CMailFile($subject, $emailTo, $emailFrom, $message, array(), array(), array(), '', '', 0, 0, '', '', $trackid);
410 
411  // Envoi du mail
412  $result=$mail->sendfile();
413 
414  if (!$result)
415  {
416  setEventMessages($mail->error, $mail->errors, 'warnings');
417  $action='';
418  }
419  else
420  {
421  header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
422  exit;
423  }
424  }
425  else
426  {
427  setEventMessages($object->error, $object->errors, 'errors');
428  $action='';
429  }
430  }
431 }
432 
433 
434 // Si Validation de la demande
435 if ($action == 'confirm_valid')
436 {
437  $object = new Holiday($db);
438  $object->fetch($id);
439 
440  // Si statut en attente de validation et valideur = utilisateur
441  if ($object->statut == Holiday::STATUS_VALIDATED && $user->id == $object->fk_validator)
442  {
443  $object->oldcopy = dol_clone($object);
444 
445  $object->date_valid = dol_now();
446  $object->fk_user_valid = $user->id;
447  $object->statut = Holiday::STATUS_APPROVED;
448 
449  $verif = $object->approve($user);
450 
451  // Si pas d'erreur SQL on redirige vers la fiche de la demande
452  if ($verif > 0)
453  {
454  // Calculcate number of days consummed
455  $nbopenedday=num_open_day($object->date_debut_gmt,$object->date_fin_gmt,0,1,$object->halfday);
456 
457  $soldeActuel = $object->getCpforUser($object->fk_user, $object->fk_type);
458  $newSolde = $soldeActuel - ($nbopenedday * $object->getConfCP('nbHolidayDeducted'));
459 
460  // On ajoute la modification dans le LOG
461  $result=$object->addLogCP($user->id, $object->fk_user, $langs->transnoentitiesnoconv("Holidays"), $newSolde, $object->fk_type);
462  if ($result<0) {
463  setEventMessages(null, $object->errors,'errors');
464  }
465  // Mise à jour du solde
466  $result=$object->updateSoldeCP($object->fk_user, $newSolde, $object->fk_type);
467  if ($result<0) {
468  setEventMessages(null, $object->errors,'errors');
469  }
470 
471  // To
472  $destinataire = new User($db);
473  $destinataire->fetch($object->fk_user);
474  $emailTo = $destinataire->email;
475 
476  if (!$emailTo)
477  {
478  dol_syslog("User that request leave has no email, so we redirect directly to finished page without sending email");
479  header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
480  exit;
481  }
482 
483  // From
484  $expediteur = new User($db);
485  $expediteur->fetch($object->fk_validator);
486  $emailFrom = $expediteur->email;
487 
488  // Subject
489  $societeName = $conf->global->MAIN_INFO_SOCIETE_NOM;
490  if (! empty($conf->global->MAIN_APPLICATION_TITLE)) $societeName = $conf->global->MAIN_APPLICATION_TITLE;
491 
492  $subject = $societeName." - ".$langs->transnoentitiesnoconv("HolidaysValidated");
493 
494  // Content
495  $message = $langs->transnoentitiesnoconv("Hello")." ".$destinataire->firstname.",\n";
496  $message.= "\n";
497  $message.= $langs->transnoentities("HolidaysValidatedBody", dol_print_date($object->date_debut,'day'),dol_print_date($object->date_fin,'day'))."\n";
498 
499  $message.= "- ".$langs->transnoentitiesnoconv("ValidatedBy")." : ".dolGetFirstLastname($expediteur->firstname, $expediteur->lastname)."\n";
500 
501  $message.= "- ".$langs->transnoentitiesnoconv("Link")." : ".$dolibarr_main_url_root."/holiday/card.php?id=".$object->id."\n\n";
502  $message.= "\n";
503 
504  $trackid='leav'.$object->id;
505 
506  $mail = new CMailFile($subject, $emailTo, $emailFrom, $message, array(), array(), array(), '', '', 0, 0, '', '', $trackid);
507 
508  // Envoi du mail
509  $result=$mail->sendfile();
510 
511  if (!$result)
512  {
513  setEventMessages($mail->error, $mail->errors, 'warnings');
514  $action='';
515  }
516  else
517  {
518  header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
519  exit;
520  }
521  }
522  else
523  {
524  setEventMessages($object->error, $object->errors, 'errors');
525  $action='';
526  }
527  }
528 }
529 
530 if ($action == 'confirm_refuse' && GETPOST('confirm','alpha') == 'yes')
531 {
532  if (! empty($_POST['detail_refuse']))
533  {
534  $object = new Holiday($db);
535  $object->fetch($id);
536 
537  // Si statut en attente de validation et valideur = utilisateur
538  if ($object->statut == Holiday::STATUS_VALIDATED && $user->id == $object->fk_validator)
539  {
540  $object->date_refuse = dol_print_date('dayhour', dol_now());
541  $object->fk_user_refuse = $user->id;
542  $object->statut = Holiday::STATUS_REFUSED;
543  $object->detail_refuse = GETPOST('detail_refuse','alphanohtml');
544 
545  $verif = $object->update($user);
546 
547  // Si pas d'erreur SQL on redirige vers la fiche de la demande
548  if ($verif > 0)
549  {
550  // To
551  $destinataire = new User($db);
552  $destinataire->fetch($object->fk_user);
553  $emailTo = $destinataire->email;
554 
555  if (!$emailTo)
556  {
557  header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
558  exit;
559  }
560 
561  // From
562  $expediteur = new User($db);
563  $expediteur->fetch($object->fk_validator);
564  $emailFrom = $expediteur->email;
565 
566  // Subject
567  $societeName = $conf->global->MAIN_INFO_SOCIETE_NOM;
568  if (! empty($conf->global->MAIN_APPLICATION_TITLE)) $societeName = $conf->global->MAIN_APPLICATION_TITLE;
569 
570  $subject = $societeName." - ".$langs->transnoentitiesnoconv("HolidaysRefused");
571 
572  // Content
573  $message = $langs->transnoentitiesnoconv("Hello")." ".$destinataire->firstname.",\n";
574  $message.= "\n";
575  $message.= $langs->transnoentities("HolidaysRefusedBody", dol_print_date($object->date_debut,'day'), dol_print_date($object->date_fin,'day'))."\n";
576  $message.= GETPOST('detail_refuse','alpha')."\n\n";
577 
578  $message.= "- ".$langs->transnoentitiesnoconv("ModifiedBy")." : ".dolGetFirstLastname($expediteur->firstname, $expediteur->lastname)."\n";
579 
580  $message.= "- ".$langs->transnoentitiesnoconv("Link")." : ".$dolibarr_main_url_root."/holiday/card.php?id=".$object->id."\n\n";
581  $message.= "\n";
582 
583  $trackid='leav'.$object->id;
584 
585  $mail = new CMailFile($subject, $emailTo, $emailFrom, $message, array(), array(), array(), '', '', 0, 0, '', '', $trackid);
586 
587  // Envoi du mail
588  $result=$mail->sendfile();
589 
590  if (!$result)
591  {
592  setEventMessages($mail->error, $mail->errors, 'warnings');
593  $action='';
594  }
595  else
596  {
597  header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
598  exit;
599  }
600  }
601  else
602  {
603  setEventMessages($object->error, $object->errors, 'errors');
604  $action='';
605  }
606  }
607  } else {
608  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("DetailRefusCP")), null, 'errors');
609  $action='refuse';
610  }
611 }
612 
613 
614 // Si Validation de la demande
615 if ($action == 'confirm_draft' && GETPOST('confirm') == 'yes')
616 {
617  $error = 0;
618 
619  $object = new Holiday($db);
620  $object->fetch($id);
621 
622  $oldstatus = $object->statut;
623  $object->statut = Holiday::STATUS_DRAFT;
624 
625  $result = $object->update($user);
626  if ($result < 0)
627  {
628  $error++;
629  setEventMessages($langs->trans('ErrorBackToDraft').' '.$object->error, $object->errors, 'errors');
630  }
631 
632  if (! $error)
633  {
634  $db->commit();
635 
636  header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
637  exit;
638  }
639  else
640  {
641  $db->rollback();
642  }
643 }
644 
645 // Si Validation de la demande
646 if ($action == 'confirm_cancel' && GETPOST('confirm') == 'yes')
647 {
648  $error = 0;
649 
650  $object = new Holiday($db);
651  $object->fetch($id);
652 
653  // Si statut en attente de validation et valideur = valideur ou utilisateur, ou droits de faire pour les autres
654  if (($object->statut == Holiday::STATUS_VALIDATED || $object->statut == Holiday::STATUS_APPROVED) && ($user->id == $object->fk_validator || in_array($object->fk_user, $childids) || ! empty($user->rights->holiday->write_all)))
655  {
656  $db->begin();
657 
658  $oldstatus = $object->statut;
659  $object->date_cancel = dol_now();
660  $object->fk_user_cancel = $user->id;
661  $object->statut = Holiday::STATUS_CANCELED;
662 
663  $result = $object->update($user);
664 
665  if ($result >= 0 && $oldstatus == Holiday::STATUS_APPROVED) // holiday was already validated, status 3, so we must increase back sold
666  {
667  // Calculcate number of days consummed
668  $nbopenedday=num_open_day($object->date_debut_gmt,$object->date_fin_gmt,0,1,$object->halfday);
669 
670  $soldeActuel = $object->getCpforUser($object->fk_user, $object->fk_type);
671  $newSolde = $soldeActuel + ($nbopenedday * $object->getConfCP('nbHolidayDeducted'));
672 
673  // On ajoute la modification dans le LOG
674  $result1=$object->addLogCP($user->id, $object->fk_user, $langs->transnoentitiesnoconv("HolidaysCancelation"), $newSolde, $object->fk_type);
675 
676  // Mise à jour du solde
677  $result2=$object->updateSoldeCP($object->fk_user, $newSolde, $object->fk_type);
678 
679  if ($result1 < 0 || $result2 < 0)
680  {
681  $error++;
682  setEventMessages($langs->trans('ErrorCantDeleteCP').' '.$object->error, $object->errors, 'errors');
683  }
684  }
685 
686  if (! $error)
687  {
688  $db->commit();
689  }
690  else
691  {
692  $db->rollback();
693  }
694 
695  // Si pas d'erreur SQL on redirige vers la fiche de la demande
696  if (! $error && $result > 0)
697  {
698  // To
699  $destinataire = new User($db);
700  $destinataire->fetch($object->fk_user);
701  $emailTo = $destinataire->email;
702 
703  if (!$emailTo)
704  {
705  header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
706  exit;
707  }
708 
709  // From
710  $expediteur = new User($db);
711  $expediteur->fetch($object->fk_user_cancel);
712  $emailFrom = $expediteur->email;
713 
714  // Subject
715  $societeName = $conf->global->MAIN_INFO_SOCIETE_NOM;
716  if (! empty($conf->global->MAIN_APPLICATION_TITLE)) $societeName = $conf->global->MAIN_APPLICATION_TITLE;
717 
718  $subject = $societeName." - ".$langs->transnoentitiesnoconv("HolidaysCanceled");
719 
720  // Content
721  $message = $langs->transnoentitiesnoconv("Hello")." ".$destinataire->firstname.",\n";
722  $message.= "\n";
723 
724  $message.= $langs->transnoentities("HolidaysCanceledBody", dol_print_date($object->date_debut,'day'), dol_print_date($object->date_fin,'day'))."\n";
725  $message.= "- ".$langs->transnoentitiesnoconv("ModifiedBy")." : ".dolGetFirstLastname($expediteur->firstname, $expediteur->lastname)."\n";
726 
727  $message.= "- ".$langs->transnoentitiesnoconv("Link")." : ".$dolibarr_main_url_root."/holiday/card.php?id=".$object->id."\n\n";
728  $message.= "\n";
729 
730  $trackid='leav'.$object->id;
731 
732  $mail = new CMailFile($subject, $emailTo, $emailFrom, $message, array(), array(), array(), '', '', 0, 0, '', '', $trackid);
733 
734  // Envoi du mail
735  $result=$mail->sendfile();
736 
737  if (!$result)
738  {
739  setEventMessages($mail->error, $mail->errors, 'warnings');
740  $action='';
741  }
742  else
743  {
744  header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
745  exit;
746  }
747  }
748  }
749 }
750 
751 
752 
753 /*
754  * View
755  */
756 
757 $form = new Form($db);
758 $object = new Holiday($db);
759 
760 $listhalfday=array('morning'=>$langs->trans("Morning"),"afternoon"=>$langs->trans("Afternoon"));
761 
762 llxHeader('', $langs->trans('CPTitreMenu'));
763 
764 if ((empty($id) && empty($ref)) || $action == 'add' || $action == 'request' || $action == 'create')
765 {
766  // Si l'utilisateur n'a pas le droit de faire une demande
767  if (($fuserid == $user->id && empty($user->rights->holiday->write)) || ($fuserid != $user->id && empty($user->rights->holiday->write_all)))
768  {
769  $errors[]=$langs->trans('CantCreateCP');
770  }
771  else
772  {
773  // Formulaire de demande de congés payés
774  print load_fiche_titre($langs->trans('MenuAddCP'), '', 'title_hrm.png');
775 
776  // Si il y a une erreur
777  if (GETPOST('error')) {
778 
779  switch(GETPOST('error')) {
780  case 'datefin' :
781  $errors[] = $langs->trans('ErrorEndDateCP');
782  break;
783  case 'SQL_Create' :
784  $errors[] = $langs->trans('ErrorSQLCreateCP').' <b>'.htmlentities($_GET['msg']).'</b>';
785  break;
786  case 'CantCreate' :
787  $errors[] = $langs->trans('CantCreateCP');
788  break;
789  case 'Valideur' :
790  $errors[] = $langs->trans('InvalidValidatorCP');
791  break;
792  case 'nodatedebut' :
793  $errors[] = $langs->trans('NoDateDebut');
794  break;
795  case 'nodatefin' :
796  $errors[] = $langs->trans('NoDateFin');
797  break;
798  case 'DureeHoliday' :
799  $errors[] = $langs->trans('ErrorDureeCP');
800  break;
801  case 'alreadyCP' :
802  $errors[] = $langs->trans('alreadyCPexist');
803  break;
804  }
805 
806  setEventMessages($errors, null, 'errors');
807  }
808 
809 
810  $delayForRequest = $object->getConfCP('delayForRequest');
811  //$delayForRequest = $delayForRequest * (60*60*24);
812 
813  $nextMonth = dol_time_plus_duree($now, $delayForRequest, 'd');
814 
815  print '<script type="text/javascript">
816  function valider()
817  {
818  if(document.demandeCP.date_debut_.value != "")
819  {
820  if(document.demandeCP.date_fin_.value != "")
821  {
822  if(document.demandeCP.valideur.value != "-1") {
823  return true;
824  }
825  else {
826  alert("'.dol_escape_js($langs->transnoentities('InvalidValidatorCP')).'");
827  return false;
828  }
829  }
830  else
831  {
832  alert("'.dol_escape_js($langs->transnoentities('NoDateFin')).'");
833  return false;
834  }
835  }
836  else
837  {
838  alert("'.dol_escape_js($langs->transnoentities('NoDateDebut')).'");
839  return false;
840  }
841  }
842  </script>'."\n";
843 
844  // Formulaire de demande
845  print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'" onsubmit="return valider()" name="demandeCP">'."\n";
846  print '<input type="hidden" name="action" value="create" />'."\n";
847 
848  if (empty($conf->global->HOLIDAY_HIDE_BALANCE))
849  {
850  dol_fiche_head('', '', '', -1);
851 
852  $out='';
853  $typeleaves=$object->getTypes(1,1);
854  foreach($typeleaves as $key => $val)
855  {
856  $nb_type = $object->getCPforUser($user->id, $val['rowid']);
857  $nb_holiday += $nb_type;
858  $out .= ' - '.$val['label'].': <strong>'.($nb_type?price2num($nb_type):0).'</strong><br>';
859  }
860  print $langs->trans('SoldeCPUser', round($nb_holiday,5)).'<br>';
861  print $out;
862 
863  dol_fiche_end();
864  }
865  elseif(! is_numeric($conf->global->HOLIDAY_HIDE_BALANCE))
866  {
867  print $langs->trans($conf->global->HOLIDAY_HIDE_BALANCE).'<br>';
868  }
869 
870  dol_fiche_head();
871 
872  //print '<span>'.$langs->trans('DelayToRequestCP',$object->getConfCP('delayForRequest')).'</span><br><br>';
873 
874  print '<table class="border" width="100%">';
875  print '<tbody>';
876 
877  // User for leave request
878  print '<tr>';
879  print '<td class="titlefield fieldrequired">'.$langs->trans("User").'</td>';
880  print '<td>';
881 
882  if (empty($user->rights->holiday->write_all))
883  {
884  print $form->select_dolusers(($fuserid?$fuserid:$user->id), 'fuserid', 0, '', 0, 'hierarchyme', '', '0,'.$conf->entity, 0, 0, $morefilter, 0, '', 'maxwidth300');
885  //print '<input type="hidden" name="fuserid" value="'.($fuserid?$fuserid:$user->id).'">';
886  }
887  else print $form->select_dolusers(GETPOST('fuserid','int')?GETPOST('fuserid','int'):$user->id, 'fuserid', 0, '', 0, '', '', '0,'.$conf->entity, 0, 0, $morefilter, 0, '', 'maxwidth300');
888  print '</td>';
889  print '</tr>';
890 
891  // Type
892  print '<tr>';
893  print '<td class="fieldrequired">'.$langs->trans("Type").'</td>';
894  print '<td>';
895  $typeleaves=$object->getTypes(1,-1);
896  $arraytypeleaves=array();
897  foreach($typeleaves as $key => $val)
898  {
899  $labeltoshow = ($langs->trans($val['code'])!=$val['code'] ? $langs->trans($val['code']) : $val['label']);
900  $labeltoshow .= ($val['delay'] > 0 ? ' ('.$langs->trans("NoticePeriod").': '.$val['delay'].' '.$langs->trans("days").')':'');
901  $arraytypeleaves[$val['rowid']]=$labeltoshow;
902  }
903  print $form->selectarray('type', $arraytypeleaves, (GETPOST('type','alpha')?GETPOST('type','alpha'):''), 1);
904  if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
905  print '</td>';
906  print '</tr>';
907 
908  // Date start
909  print '<tr>';
910  print '<td class="fieldrequired">';
911  print $langs->trans("DateDebCP");
912  print ' ('.$langs->trans("FirstDayOfHoliday").')';
913  print '</td>';
914  print '<td>';
915  // Si la demande ne vient pas de l'agenda
916  if (! GETPOST('date_debut_')) {
917  print $form->selectDate(-1, 'date_debut_', 0, 0, 0, '', 1, 1);
918  } else {
919  $tmpdate = dol_mktime(0, 0, 0, GETPOST('date_debut_month','int'), GETPOST('date_debut_day','int'), GETPOST('date_debut_year','int'));
920  print $form->selectDate($tmpdate, 'date_debut_', 0, 0, 0, '', 1, 1);
921  }
922  print ' &nbsp; &nbsp; ';
923  print $form->selectarray('starthalfday', $listhalfday, (GETPOST('starthalfday','alpha')?GETPOST('starthalfday','alpha'):'morning'));
924  print '</td>';
925  print '</tr>';
926 
927  // Date end
928  print '<tr>';
929  print '<td class="fieldrequired">';
930  print $langs->trans("DateFinCP");
931  print ' ('.$langs->trans("LastDayOfHoliday").')';
932  print '</td>';
933  print '<td>';
934  // Si la demande ne vient pas de l'agenda
935  if (! GETPOST('date_fin_')) {
936  print $form->selectDate(-1, 'date_fin_', 0, 0, 0, '', 1, 1);
937  } else {
938  $tmpdate = dol_mktime(0, 0, 0, GETPOST('date_fin_month','int'), GETPOST('date_fin_day','int'), GETPOST('date_fin_year','int'));
939  print $form->selectDate($tmpdate, 'date_fin_', 0, 0, 0, '', 1, 1);
940  }
941  print ' &nbsp; &nbsp; ';
942  print $form->selectarray('endhalfday', $listhalfday, (GETPOST('endhalfday','alpha')?GETPOST('endhalfday','alpha'):'afternoon'));
943  print '</td>';
944  print '</tr>';
945 
946  // Approver
947  print '<tr>';
948  print '<td class="fieldrequired">'.$langs->trans("ReviewedByCP").'</td>';
949  print '<td>';
950 
951  $object = new Holiday($db);
952  $include_users = $object->fetch_users_approver_holiday();
953  if (empty($include_users)) print img_warning().' '.$langs->trans("NobodyHasPermissionToValidateHolidays");
954  else
955  {
956  $defaultselectuser=$user->fk_user; // Will work only if supervisor has permission to approve so is inside include_users
957  if (! empty($conf->global->HOLIDAY_DEFAULT_VALIDATOR)) $defaultselectuser=$conf->global->HOLIDAY_DEFAULT_VALIDATOR; // Can force default approver
958  if (GETPOST('valideur', 'int') > 0) $defaultselectuser=GETPOST('valideur', 'int');
959  $s=$form->select_dolusers($defaultselectuser, "valideur", 1, "", 0, $include_users);
960  print $form->textwithpicto($s, $langs->trans("AnyOtherInThisListCanValidate"));
961  }
962 
963  //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
964  print '</td>';
965  print '</tr>';
966 
967  // Description
968  print '<tr>';
969  print '<td>'.$langs->trans("DescCP").'</td>';
970  print '<td class="tdtop">';
971  $doleditor = new DolEditor('description', GETPOST('description','none'), '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, '90%');
972  print $doleditor->Create(1);
973  print '</td></tr>';
974 
975  print '</tbody>';
976  print '</table>';
977 
978  dol_fiche_end();
979 
980  print '<div class="center">';
981  print '<input type="submit" value="'.$langs->trans("SendRequestCP").'" name="bouton" class="button">';
982  print '&nbsp; &nbsp; ';
983  print '<input type="button" value="'.$langs->trans("Cancel").'" class="button" onclick="history.go(-1)">';
984  print '</div>';
985 
986  print '</from>'."\n";
987  }
988 }
989 else
990 {
991  if ($error)
992  {
993  print '<div class="tabBar">';
994  print $error;
995  print '<br><br><input type="button" value="'.$langs->trans("ReturnCP").'" class="button" onclick="history.go(-1)" />';
996  print '</div>';
997  }
998  else
999  {
1000  // Affichage de la fiche d'une demande de congés payés
1001  if (($id > 0) || $ref)
1002  {
1003  $result = $object->fetch($id, $ref);
1004 
1005  $valideur = new User($db);
1006  $valideur->fetch($object->fk_validator);
1007 
1008  $userRequest = new User($db);
1009  $userRequest->fetch($object->fk_user);
1010 
1011  //print load_fiche_titre($langs->trans('TitreRequestCP'));
1012 
1013  // Si il y a une erreur
1014  if (GETPOST('error'))
1015  {
1016  switch(GETPOST('error'))
1017  {
1018  case 'datefin' :
1019  $errors[] = $langs->transnoentitiesnoconv('ErrorEndDateCP');
1020  break;
1021  case 'SQL_Create' :
1022  $errors[] = $langs->transnoentitiesnoconv('ErrorSQLCreateCP').' '.$_GET['msg'];
1023  break;
1024  case 'CantCreate' :
1025  $errors[] = $langs->transnoentitiesnoconv('CantCreateCP');
1026  break;
1027  case 'Valideur' :
1028  $errors[] = $langs->transnoentitiesnoconv('InvalidValidatorCP');
1029  break;
1030  case 'nodatedebut' :
1031  $errors[] = $langs->transnoentitiesnoconv('NoDateDebut');
1032  break;
1033  case 'nodatefin' :
1034  $errors[] = $langs->transnoentitiesnoconv('NoDateFin');
1035  break;
1036  case 'DureeHoliday' :
1037  $errors[] = $langs->transnoentitiesnoconv('ErrorDureeCP');
1038  break;
1039  case 'NoMotifRefuse' :
1040  $errors[] = $langs->transnoentitiesnoconv('NoMotifRefuseCP');
1041  break;
1042  case 'mail' :
1043  $errors[] = $langs->transnoentitiesnoconv('ErrorMailNotSend')."\n".$_GET['error_content'];
1044  break;
1045  }
1046 
1047  setEventMessages($errors, null, 'errors');
1048  }
1049 
1050  // On vérifie si l'utilisateur à le droit de lire cette demande
1051  if ($cancreate)
1052  {
1053  $head=holiday_prepare_head($object);
1054 
1055  if ($action == 'edit' && $object->statut == 1)
1056  {
1057  $edit = true;
1058  print '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">'."\n";
1059  print '<input type="hidden" name="action" value="update"/>'."\n";
1060  print '<input type="hidden" name="id" value="'.$object->id.'" />'."\n";
1061  }
1062 
1063  dol_fiche_head($head, 'card', $langs->trans("CPTitreMenu"), -1, 'holiday');
1064 
1065  $linkback='<a href="'.DOL_URL_ROOT.'/holiday/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
1066 
1067  dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref');
1068 
1069 
1070  print '<div class="fichecenter">';
1071  print '<div class="fichehalfleft">';
1072  print '<div class="underbanner clearboth"></div>';
1073 
1074  print '<table class="border centpercent">';
1075  print '<tbody>';
1076 
1077  // User
1078  print '<tr>';
1079  print '<td class="titlefield">'.$langs->trans("User").'</td>';
1080  print '<td>';
1081  print $userRequest->getNomUrl(-1, 'leave');
1082  print '</td></tr>';
1083 
1084  // Type
1085  print '<tr>';
1086  print '<td>'.$langs->trans("Type").'</td>';
1087  print '<td>';
1088  $typeleaves=$object->getTypes(1,-1);
1089  $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']);
1090  print empty($labeltoshow) ? $langs->trans("TypeWasDisabledOrRemoved",$object->fk_type) : $labeltoshow;
1091  print '</td>';
1092  print '</tr>';
1093 
1094  $starthalfday=($object->halfday == -1 || $object->halfday == 2)?'afternoon':'morning';
1095  $endhalfday=($object->halfday == 1 || $object->halfday == 2)?'morning':'afternoon';
1096 
1097  if(!$edit)
1098  {
1099  print '<tr>';
1100  print '<td class="nowrap">'.$langs->trans('DateDebCP').' ('.$langs->trans("FirstDayOfHoliday").')</td>';
1101  print '<td>'.dol_print_date($object->date_debut,'day');
1102  print ' &nbsp; &nbsp; ';
1103  print '<span class="opacitymedium">'.$langs->trans($listhalfday[$starthalfday]).'</span>';
1104  print '</td>';
1105  print '</tr>';
1106  }
1107  else
1108  {
1109  print '<tr>';
1110  print '<td class="nowrap">'.$langs->trans('DateDebCP').' ('.$langs->trans("FirstDayOfHoliday").')</td>';
1111  print '<td>';
1112  print $form->selectDate($object->date_debut, 'date_debut_');
1113  print ' &nbsp; &nbsp; ';
1114  print $form->selectarray('starthalfday', $listhalfday, (GETPOST('starthalfday')?GETPOST('starthalfday'):$starthalfday));
1115  print '</td>';
1116  print '</tr>';
1117  }
1118 
1119  if (!$edit)
1120  {
1121  print '<tr>';
1122  print '<td class="nowrap">'.$langs->trans('DateFinCP').' ('.$langs->trans("LastDayOfHoliday").')</td>';
1123  print '<td>'.dol_print_date($object->date_fin,'day');
1124  print ' &nbsp; &nbsp; ';
1125  print '<span class="opacitymedium">'.$langs->trans($listhalfday[$endhalfday]).'</span>';
1126  print '</td>';
1127  print '</tr>';
1128  }
1129  else
1130  {
1131  print '<tr>';
1132  print '<td class="nowrap">'.$langs->trans('DateFinCP').' ('.$langs->trans("LastDayOfHoliday").')</td>';
1133  print '<td>';
1134  print $form->selectDate($object->date_fin, 'date_fin_');
1135  print ' &nbsp; &nbsp; ';
1136  print $form->selectarray('endhalfday', $listhalfday, (GETPOST('endhalfday')?GETPOST('endhalfday'):$endhalfday));
1137  print '</td>';
1138  print '</tr>';
1139  }
1140  // Nb of days
1141  print '<tr>';
1142  print '<td>'.$langs->trans('NbUseDaysCP').'</td>';
1143  print '<td>'.num_open_day($object->date_debut_gmt, $object->date_fin_gmt, 0, 1, $object->halfday).'</td>';
1144  print '</tr>';
1145 
1146  if ($object->statut == 5)
1147  {
1148  print '<tr>';
1149  print '<td>'.$langs->trans('DetailRefusCP').'</td>';
1150  print '<td>'.$object->detail_refuse.'</td>';
1151  print '</tr>';
1152  }
1153 
1154  // Description
1155  if (!$edit)
1156  {
1157  print '<tr>';
1158  print '<td>'.$langs->trans('DescCP').'</td>';
1159  print '<td>'.nl2br($object->description).'</td>';
1160  print '</tr>';
1161  }
1162  else
1163  {
1164  print '<tr>';
1165  print '<td>'.$langs->trans('DescCP').'</td>';
1166  print '<td class="tdtop">';
1167  $doleditor = new DolEditor('description', $object->description, '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, '90%');
1168  print $doleditor->Create(1);
1169  print '</td></tr>';
1170  }
1171 
1172  print '</tbody>';
1173  print '</table>'."\n";
1174 
1175  print '</div>';
1176  print '<div class="fichehalfright">';
1177  print '<div class="ficheaddleft">';
1178 
1179  print '<div class="underbanner clearboth"></div>';
1180 
1181  // Info workflow
1182  print '<table class="border centpercent">'."\n";
1183  print '<tbody>';
1184 
1185  if (! empty($object->fk_user_create))
1186  {
1187  $userCreate=new User($db);
1188  $userCreate->fetch($object->fk_user_create);
1189  print '<tr>';
1190  print '<td class="titlefield">'.$langs->trans('RequestByCP').'</td>';
1191  print '<td>'.$userCreate->getNomUrl(-1).'</td>';
1192  print '</tr>';
1193  }
1194 
1195  // Validator
1196  if (!$edit) {
1197  print '<tr>';
1198  print '<td class="titlefield">';
1199  if ($object->statut == 3 || $object->statut == 4) print $langs->trans('ApprovedBy');
1200  else print $langs->trans('ReviewedByCP');
1201  print '</td>';
1202  print '<td>'.$valideur->getNomUrl(-1).'</td>';
1203  print '</tr>';
1204  } else {
1205  print '<tr>';
1206  print '<td class="titlefield">'.$langs->trans('ReviewedByCP').'</td>';
1207  print '<td>';
1208  $include_users = $object->fetch_users_approver_holiday();
1209  if (empty($include_users)) print img_warning().' '.$langs->trans("NobodyHasPermissionToValidateHolidays");
1210  else
1211  {
1212  $s=$form->select_dolusers($object->fk_validator, "valideur", 1, ($user->admin ? '' : array($user->id)), 0, $include_users);
1213  print $form->textwithpicto($s, $langs->trans("AnyOtherInThisListCanValidate"));
1214  }
1215  print '</td>';
1216  print '</tr>';
1217  }
1218 
1219  print '<tr>';
1220  print '<td>'.$langs->trans('DateCreateCP').'</td>';
1221  print '<td>'.dol_print_date($object->date_create,'dayhour').'</td>';
1222  print '</tr>';
1223  if ($object->statut == 3 || $object->statut == 4) {
1224  print '<tr>';
1225  print '<td>'.$langs->trans('DateValidCP').'</td>';
1226  print '<td>'.dol_print_date($object->date_valid,'dayhour').'</td>'; // warning: date_valid is approval date on holiday module
1227  print '</tr>';
1228  }
1229  if ($object->statut == 4) {
1230  print '<tr>';
1231  print '<td>'.$langs->trans('DateCancelCP').'</td>';
1232  print '<td>'.dol_print_date($object->date_cancel,'dayhour').'</td>';
1233  print '</tr>';
1234  }
1235  if ($object->statut == 5) {
1236  print '<tr>';
1237  print '<td>'.$langs->trans('DateRefusCP').'</td>';
1238  print '<td>'.dol_print_date($object->date_refuse,'dayhour').'</td>';
1239  print '</tr>';
1240  }
1241  print '</tbody>';
1242  print '</table>';
1243 
1244  print '</div>';
1245  print '</div>';
1246  print '</div>';
1247 
1248  print '<div class="clearboth"></div>';
1249 
1250  dol_fiche_end();
1251 
1252 
1253  // Confirmation messages
1254  if ($action == 'delete')
1255  {
1256  if ($user->rights->holiday->delete)
1257  {
1258  print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id,$langs->trans("TitleDeleteCP"),$langs->trans("ConfirmDeleteCP"),"confirm_delete", '', 0, 1);
1259  }
1260  }
1261 
1262  // Si envoi en validation
1263  if ($action == 'sendToValidate' && $object->statut == Holiday::STATUS_DRAFT)
1264  {
1265  print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id,$langs->trans("TitleToValidCP"),$langs->trans("ConfirmToValidCP"),"confirm_send", '', 1, 1);
1266  }
1267 
1268  // Si validation de la demande
1269  if ($action == 'valid')
1270  {
1271  print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id,$langs->trans("TitleValidCP"),$langs->trans("ConfirmValidCP"),"confirm_valid", '', 1, 1);
1272  }
1273 
1274  // Si refus de la demande
1275  if ($action == 'refuse')
1276  {
1277  $array_input = array(array('type'=>"text",'label'=> $langs->trans('DetailRefusCP'),'name'=>"detail_refuse",'size'=>"50",'value'=>""));
1278  print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id."&action=confirm_refuse", $langs->trans("TitleRefuseCP"), $langs->trans('ConfirmRefuseCP'), "confirm_refuse", $array_input, 1, 0);
1279  }
1280 
1281  // Si annulation de la demande
1282  if ($action == 'cancel')
1283  {
1284  print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id,$langs->trans("TitleCancelCP"),$langs->trans("ConfirmCancelCP"),"confirm_cancel", '', 1, 1);
1285  }
1286 
1287  // Si back to draft
1288  if ($action == 'backtodraft')
1289  {
1290  print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id,$langs->trans("TitleSetToDraft"),$langs->trans("ConfirmSetToDraft"),"confirm_draft", '', 1, 1);
1291  }
1292 
1293 
1294  if ($action == 'edit' && $object->statut == Holiday::STATUS_DRAFT)
1295  {
1296  print '<div align="center">';
1297  if ($cancreate && $object->statut == Holiday::STATUS_DRAFT)
1298  {
1299  print '<input type="submit" value="'.$langs->trans("Save").'" class="button">';
1300  }
1301  print '</div>';
1302 
1303  print '</form>';
1304  }
1305 
1306 
1307  if (! $edit)
1308  {
1309  print '<div class="tabsAction">';
1310 
1311  // Boutons d'actions
1312  if ($cancreate && $object->statut == Holiday::STATUS_DRAFT)
1313  {
1314  print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=edit" class="butAction">'.$langs->trans("EditCP").'</a>';
1315  }
1316  if ($cancreate && $object->statut == Holiday::STATUS_DRAFT) // If draft
1317  {
1318  print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=sendToValidate" class="butAction">'.$langs->trans("Validate").'</a>';
1319  }
1320  if ($object->statut == Holiday::STATUS_VALIDATED) // If validated
1321  {
1322  if ($user->id == $object->fk_validator)
1323  {
1324  print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=valid" class="butAction">'.$langs->trans("Approve").'</a>';
1325  print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=refuse" class="butAction">'.$langs->trans("ActionRefuseCP").'</a>';
1326  }
1327  else
1328  {
1329  print '<a href="#" class="butActionRefused" title="'.$langs->trans("NotTheAssignedApprover").'">'.$langs->trans("Approve").'</a>';
1330  print '<a href="#" class="butActionRefused" title="'.$langs->trans("NotTheAssignedApprover").'">'.$langs->trans("ActionRefuseCP").'</a>';
1331  }
1332  }
1333  if (($user->id == $object->fk_validator || in_array($object->fk_user, $childids) || ! empty($user->rights->holiday->write_all)) && ($object->statut == 2 || $object->statut == 3)) // Status validated or approved
1334  {
1335  if (($object->date_debut > dol_now()) || $user->admin) print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=cancel" class="butAction">'.$langs->trans("ActionCancelCP").'</a>';
1336  else print '<a href="#" class="butActionRefused" title="'.$langs->trans("HolidayStarted").'">'.$langs->trans("ActionCancelCP").'</a>';
1337  }
1338  if ($cancreate && $object->statut == Holiday::STATUS_CANCELED)
1339  {
1340  print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=backtodraft" class="butAction">'.$langs->trans("SetToDraft").'</a>';
1341  }
1342  if ($user->rights->holiday->delete && ($object->statut == Holiday::STATUS_DRAFT || $object->statut == Holiday::STATUS_CANCELED || $object->statut == Holiday::STATUS_REFUSED)) // If draft or canceled or refused
1343  {
1344  print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete" class="butActionDelete">'.$langs->trans("DeleteCP").'</a>';
1345  }
1346 
1347  print '</div>';
1348  }
1349  } else {
1350  print '<div class="tabBar">';
1351  print $langs->trans('ErrorUserViewCP');
1352  print '<br><br><input type="button" value="'.$langs->trans("ReturnCP").'" class="button" onclick="history.go(-1)" />';
1353  print '</div>';
1354  }
1355  } else {
1356  print '<div class="tabBar">';
1357  print $langs->trans('ErrorIDFicheCP');
1358  print '<br><br><input type="button" value="'.$langs->trans("ReturnCP").'" class="button" onclick="history.go(-1)" />';
1359  print '</div>';
1360  }
1361  }
1362 }
1363 
1364 // End of page
1365 llxFooter();
1366 
1367 if (is_object($db)) $db->close();
img_warning($titlealt='default', $moreatt='')
Show warning logo.
Class of the module paid holiday.
llxFooter()
Empty footer.
Definition: wrapper.php:56
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
GETPOST($paramname, $check='none', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
print
Draft customers invoices.
Definition: index.php:91
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
holiday_prepare_head($object)
Return array head with list of tabs to view object informations.
Definition: holiday.lib.php:30
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm=false, $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
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:895
dol_escape_js($stringtoescape, $mode=0, $noescapebackslashn=0)
Returns text escaped for inclusion into javascript code.
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.
Class to manage Dolibarr users.
Definition: user.class.php:41
dol_clone($object, $native=0)
Create a clone of instance of object (new instance with same value for properties) With native = 0: P...
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Class to manage generation of HTML components Only common components must be here.
const STATUS_DRAFT
Draft status.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='')
Show information for admin users or standard users.
dol_fiche_end($notab=0)
Show tab footer of a card.
Class to send emails (with attachments or not) Usage: $mailfile = new CMailFile($subject,$sendto,$replyto,$message,$filepath,$mimetype,$filename,$cc,$ccc,$deliveryreceipt,$msgishtml,$errors_to,$css,$trackid,$moreinheader,$sendcontext); $mailfile->sendfile();.
llxHeader()
Empty header.
Definition: wrapper.php:44
const STATUS_APPROVED
Approved.
dol_now($mode='gmt')
Return date for now.
if($_POST["cancel"]==$langs->trans("Cancel") &&! $id) if($action=='add' && $_POST["cancel"]<> $langs->trans("Cancel")) if($action=='delete') if($id) $form
Actions.
Definition: card.php:153
dol_print_date($time, $format='', $tzoutput='tzserver', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
const STATUS_VALIDATED
Validated status.
Class to manage a WYSIWYG editor.
const STATUS_CANCELED
Canceled.
const STATUS_REFUSED
Refused.
dol_time_plus_duree($time, $duration_value, $duration_unit)
Add a delay to a date.
Definition: date.lib.php:116
price2num($amount, $rounding='', $alreadysqlnb=0)
Function that return a number with universal decimal format (decimal separator is &#39;...
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='')
Show tab header of a card.
dolGetFirstLastname($firstname, $lastname, $nameorder=-1)
Return firstname and lastname in correct order.