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