32 require
'../main.inc.php';
33 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.form.class.php';
34 require_once DOL_DOCUMENT_ROOT.
'/user/class/usergroup.class.php';
35 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
36 require_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
37 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
38 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
39 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
40 require_once DOL_DOCUMENT_ROOT.
'/core/lib/holiday.lib.php';
41 require_once DOL_DOCUMENT_ROOT.
'/holiday/class/holiday.class.php';
42 require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
45 $action =
GETPOST(
'action',
'aZ09');
46 $cancel =
GETPOST(
'cancel',
'alpha');
47 $confirm =
GETPOST(
'confirm',
'alpha');
51 $fuserid = (
GETPOST(
'fuserid',
'int') ?
GETPOST(
'fuserid',
'int') : $user->id);
52 $socid =
GETPOST(
'socid',
'int');
55 $langs->loadLangs(array(
"other",
"holiday",
"mails",
"trips"));
61 $childids = $user->getAllChildIds(1);
64 if (!empty($conf->global->HOLIDAY_HIDE_FOR_NON_SALARIES)) {
65 $morefilter =
'AND employee = 1';
73 $extrafields->fetch_name_optionals_label($object->table_element);
75 if (($id > 0) || $ref) {
76 $object->fetch($id, $ref);
80 if (!empty($user->rights->holiday->readall)) {
83 if (!empty($user->rights->holiday->read) && in_array($object->fk_user, $childids)) {
92 $hookmanager->initHooks(array(
'holidaycard',
'globalcard'));
96 if (!empty($user->rights->holiday->write) && in_array($fuserid, $childids)) {
99 if (!empty($user->rights->holiday->writeall)) {
105 if (!empty($user->rights->holiday->delete)) {
108 if ($object->statut ==
Holiday::STATUS_DRAFT && $user->rights->holiday->write && in_array($object->fk_user, $childids)) {
114 $socid = $user->socid;
116 $result =
restrictedArea($user,
'holiday', $object->id,
'holiday',
'',
'',
'rowid', $object->statut);
124 $reshook = $hookmanager->executeHooks(
'doActions',
$parameters, $object, $action);
129 if (empty($reshook)) {
130 $backurlforlist = DOL_URL_ROOT.
'/holiday/list.php';
132 if (empty($backtopage) || ($cancel && empty($id))) {
133 if (empty($backtopage) || ($cancel && strpos($backtopage,
'__ID__'))) {
134 if (empty($id) && (($action !=
'add' && $action !=
'create') || $cancel)) {
135 $backtopage = $backurlforlist;
137 $backtopage = DOL_URL_ROOT.
'/holiday/card.php?id='.((!empty($id) && $id > 0) ? $id :
'__ID__');
143 if (!empty($backtopageforcancel)) {
144 header(
"Location: ".$backtopageforcancel);
146 } elseif (!empty($backtopage)) {
147 header(
"Location: ".$backtopage);
154 if ($action ==
'add') {
171 $starthalfday =
GETPOST(
'starthalfday');
172 $endhalfday =
GETPOST(
'endhalfday');
175 if ($starthalfday ==
'afternoon' && $endhalfday ==
'morning') {
177 } elseif ($starthalfday ==
'afternoon') {
179 } elseif ($endhalfday ==
'morning') {
183 $approverid =
GETPOST(
'valideur',
'int');
184 $description = trim(
GETPOST(
'description',
'restricthtml'));
187 if (!$cancreateall) {
188 if (empty($conf->global->MAIN_USE_ADVANCED_PERMS)) {
189 if (empty($user->rights->holiday->write)) {
192 } elseif (!in_array($fuserid, $childids)) {
198 if (empty($user->rights->holiday->write) && empty($user->rights->holiday->writeall_advance)) {
201 } elseif (empty($user->rights->holiday->writeall_advance) && !in_array($fuserid, $childids)) {
211 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type")),
null,
'errors');
217 if (empty($date_debut)) {
223 if (empty($date_fin)) {
229 if ($date_debut > $date_fin) {
236 $verifCP = $object->verifDateHolidayCP($fuserid, $date_debut, $date_fin, $halfday);
244 $nbopenedday =
num_open_day($date_debut_gmt, $date_fin_gmt, 0, 1, $halfday);
245 if ($nbopenedday < 0.5) {
252 if ($approverid < 1) {
253 setEventMessages($langs->transnoentitiesnoconv(
'InvalidValidatorCP'),
null,
'errors');
258 $ret = $extrafields->setOptionalsFromPost(
null, $object);
266 $object->fk_user = $fuserid;
267 $object->description = $description;
268 $object->fk_validator = $approverid;
269 $object->fk_type = $type;
270 $object->date_debut = $date_debut;
271 $object->date_fin = $date_fin;
272 $object->halfday = $halfday;
274 $result = $object->create($user);
285 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?id='.$object->id);
294 if ($action ==
'update' &&
GETPOSTISSET(
'savevalidator') && !empty($user->rights->holiday->approve)) {
299 $object->fk_validator =
GETPOST(
'valideur',
'int');
301 if ($object->fk_validator != $object->oldcopy->fk_validator) {
302 $verif = $object->update($user);
306 $action =
'editvalidator';
308 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?id='.$object->id);
316 if ($action ==
'update' && !
GETPOSTISSET(
'savevalidator')) {
321 $starthalfday =
GETPOST(
'starthalfday');
322 $endhalfday =
GETPOST(
'endhalfday');
324 if ($starthalfday ==
'afternoon' && $endhalfday ==
'morning') {
326 } elseif ($starthalfday ==
'afternoon') {
328 } elseif ($endhalfday ==
'morning') {
333 if (!$cancreateall) {
335 if (!in_array($fuserid, $childids)) {
337 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?action=create');
342 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?action=create');
353 $approverid =
GETPOST(
'valideur',
'int');
356 $description = trim(
GETPOST(
'description',
'restricthtml'));
360 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=edit&token='.
newToken().
'&error=nodatedebut');
366 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=edit&token='.
newToken().
'&error=nodatefin');
371 if ($date_debut > $date_fin) {
372 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=edit&token='.
newToken().
'&error=datefin');
377 if ($approverid < 1) {
378 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=edit&token='.
newToken().
'&error=Valideur');
383 $nbopenedday =
num_open_day($date_debut_gmt, $date_fin_gmt, 0, 1, $halfday);
384 if ($nbopenedday < 0.5) {
385 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=edit&error=DureeHoliday');
389 $object->description = $description;
390 $object->date_debut = $date_debut;
391 $object->date_fin = $date_fin;
392 $object->fk_validator = $approverid;
393 $object->halfday = $halfday;
396 $verif = $object->update($user);
402 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?id='.$object->id);
416 if ($action ==
'confirm_delete' &&
GETPOST(
'confirm') ==
'yes' && $candelete) {
425 $result = $object->delete($user);
434 header(
'Location: list.php?restore_lastsearch_values=1');
442 if ($action ==
'confirm_send') {
451 $verif = $object->validate($user);
456 $destinataire =
new User($db);
457 $destinataire->fetch($object->fk_validator);
458 $emailTo = $destinataire->email;
461 dol_syslog(
"Expected validator has no email, so we redirect directly to finished page without sending email");
462 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?id='.$object->id);
467 $expediteur =
new User($db);
468 $expediteur->fetch($object->fk_user);
470 $emailFrom = $conf->global->MAIN_MAIL_EMAIL_FROM;
473 $societeName = $conf->global->MAIN_INFO_SOCIETE_NOM;
474 if (!empty($conf->global->MAIN_APPLICATION_TITLE)) {
475 $societeName = $conf->global->MAIN_APPLICATION_TITLE;
478 $subject = $societeName.
" - ".$langs->transnoentitiesnoconv(
"HolidaysToValidate");
481 $message =
"<p>".$langs->transnoentitiesnoconv(
"Hello").
" ".$destinataire->firstname.
",</p>\n";
483 $message .=
"<p>".$langs->transnoentities(
"HolidaysToValidateBody").
"</p>\n";
487 if (empty($conf->global->HOLIDAY_HIDE_APPROVER_ABOUT_TOO_LOW_DELAY)) {
488 $delayForRequest = 0;
489 if ($delayForRequest) {
492 if ($object->date_debut < $nowplusdelay) {
493 $message =
"<p>".$langs->transnoentities(
"HolidaysToValidateDelay", $delayForRequest).
"</p>\n";
499 if (empty($conf->global->HOLIDAY_HIDE_APPROVER_ABOUT_NEGATIVE_BALANCE)) {
500 $nbopenedday =
num_open_day($object->date_debut_gmt, $object->date_fin_gmt, 0, 1, $object->halfday);
502 if ($nbopenedday > $object->getCPforUser($object->fk_user, $object->fk_type)) {
503 $message .=
"<p>".$langs->transnoentities(
"HolidaysToValidateAlertSolde").
"</p>\n";
507 $link =
dol_buildpath(
"/holiday/card.php", 3) .
'?id='.$object->id;
510 $message .=
"<li>".$langs->transnoentitiesnoconv(
"Name").
" : ".
dolGetFirstLastname($expediteur->firstname, $expediteur->lastname).
"</li>\n";
511 $message .=
"<li>".$langs->transnoentitiesnoconv(
"Period").
" : ".
dol_print_date($object->date_debut,
'day').
" ".$langs->transnoentitiesnoconv(
"To").
" ".
dol_print_date($object->date_fin,
'day').
"</li>\n";
512 $message .=
"<li>".$langs->transnoentitiesnoconv(
"Link").
' : <a href="'.$link.
'" target="_blank">'.$link.
"</a></li>\n";
513 $message .=
"</ul>\n";
515 $trackid =
'leav'.$object->id;
517 $mail =
new CMailFile($subject, $emailTo, $emailFrom, $message, array(), array(), array(),
'',
'', 0, 1,
'',
'', $trackid);
520 $result = $mail->sendfile();
526 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?id='.$object->id);
536 if ($action ==
'update_extras') {
540 $ret = $extrafields->setOptionalsFromPost(
null, $object,
GETPOST(
'attribute',
'restricthtml'));
547 $result = $object->insertExtraFields(
'HOLIDAY_MODIFY');
555 $action =
'edit_extras';
560 if ($action ==
'confirm_valid') {
567 $object->date_valid =
dol_now();
568 $object->fk_user_valid = $user->id;
573 $verif = $object->approve($user);
582 $nbopenedday =
num_open_day($object->date_debut_gmt, $object->date_fin_gmt, 0, 1, $object->halfday);
583 $soldeActuel = $object->getCpforUser($object->fk_user, $object->fk_type);
584 $newSolde = ($soldeActuel - $nbopenedday);
585 $label = $langs->transnoentitiesnoconv(
"Holidays").
' - '.$object->ref;
588 $result = $object->addLogCP($user->id, $object->fk_user, $label, $newSolde, $object->fk_type);
595 $result = $object->updateSoldeCP($object->fk_user, $newSolde, $object->fk_type);
604 $destinataire =
new User($db);
605 $destinataire->fetch($object->fk_user);
606 $emailTo = $destinataire->email;
609 dol_syslog(
"User that request leave has no email, so we redirect directly to finished page without sending email");
612 $expediteur =
new User($db);
613 $expediteur->fetch($object->fk_validator);
615 $emailFrom = $conf->global->MAIN_MAIL_EMAIL_FROM;
618 $societeName = $conf->global->MAIN_INFO_SOCIETE_NOM;
619 if (!empty($conf->global->MAIN_APPLICATION_TITLE)) {
620 $societeName = $conf->global->MAIN_APPLICATION_TITLE;
623 $subject = $societeName.
" - ".$langs->transnoentitiesnoconv(
"HolidaysValidated");
626 $message =
"<p>".$langs->transnoentitiesnoconv(
"Hello").
" ".$destinataire->firstname.
",</p>\n";
628 $message .=
"<p>".$langs->transnoentities(
"HolidaysValidatedBody",
dol_print_date($object->date_debut,
'day'),
dol_print_date($object->date_fin,
'day')).
"</p>\n";
630 $link =
dol_buildpath(
'/holiday/card.php', 3).
'?id='.$object->id;
632 $message .=
"<ul>\n";
633 $message .=
"<li>".$langs->transnoentitiesnoconv(
"ValidatedBy").
" : ".
dolGetFirstLastname($expediteur->firstname, $expediteur->lastname).
"</li>\n";
634 $message .=
"<li>".$langs->transnoentitiesnoconv(
"Link").
' : <a href="'.$link.
'" target="_blank">'.$link.
"</a></li>\n";
635 $message .=
"</ul>\n";
637 $trackid =
'leav'.$object->id;
639 $mail =
new CMailFile($subject, $emailTo, $emailFrom, $message, array(), array(), array(),
'',
'', 0, 1,
'',
'', $trackid);
642 $result = $mail->sendfile();
654 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?id='.$object->id);
663 if ($action ==
'confirm_refuse' &&
GETPOST(
'confirm',
'alpha') ==
'yes') {
664 if (
GETPOST(
'detail_refuse')) {
670 $object->fk_user_refuse = $user->id;
672 $object->detail_refuse =
GETPOST(
'detail_refuse',
'alphanohtml');
676 $verif = $object->update($user);
685 $destinataire =
new User($db);
686 $destinataire->fetch($object->fk_user);
687 $emailTo = $destinataire->email;
690 dol_syslog(
"User that request leave has no email, so we redirect directly to finished page without sending email");
693 $expediteur =
new User($db);
694 $expediteur->fetch($object->fk_validator);
696 $emailFrom = $conf->global->MAIN_MAIL_EMAIL_FROM;
699 $societeName = $conf->global->MAIN_INFO_SOCIETE_NOM;
700 if (!empty($conf->global->MAIN_APPLICATION_TITLE)) {
701 $societeName = $conf->global->MAIN_APPLICATION_TITLE;
704 $subject = $societeName.
" - ".$langs->transnoentitiesnoconv(
"HolidaysRefused");
707 $message =
"<p>".$langs->transnoentitiesnoconv(
"Hello").
" ".$destinataire->firstname.
",</p>\n";
709 $message .=
"<p>".$langs->transnoentities(
"HolidaysRefusedBody",
dol_print_date($object->date_debut,
'day'),
dol_print_date($object->date_fin,
'day')).
"<p>\n";
710 $message .=
"<p>".GETPOST(
'detail_refuse',
'alpha').
"</p>";
712 $link =
dol_buildpath(
'/holiday/card.php', 3).
'?id='.$object->id;
714 $message .=
"<ul>\n";
715 $message .=
"<li>".$langs->transnoentitiesnoconv(
"ModifiedBy").
" : ".
dolGetFirstLastname($expediteur->firstname, $expediteur->lastname).
"</li>\n";
716 $message .=
"<li>".$langs->transnoentitiesnoconv(
"Link").
' : <a href="'.$link.
'" target="_blank">'.$link.
"</a></li>\n";
719 $trackid =
'leav'.$object->id;
721 $mail =
new CMailFile($subject, $emailTo, $emailFrom, $message, array(), array(), array(),
'',
'', 0, 1,
'',
'', $trackid);
724 $result = $mail->sendfile();
738 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?id='.$object->id);
746 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"DetailRefusCP")),
null,
'errors');
753 if ($action ==
'confirm_draft' &&
GETPOST(
'confirm') ==
'yes') {
758 $oldstatus = $object->statut;
761 $result = $object->update($user);
764 setEventMessages($langs->trans(
'ErrorBackToDraft').
' '.$object->error, $object->errors,
'errors');
770 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?id='.$object->id);
778 if ($action ==
'confirm_cancel' &&
GETPOST(
'confirm') ==
'yes') {
785 (!empty($user->admin) || $user->id == $object->fk_validator || $cancreate || $cancreateall)) {
788 $oldstatus = $object->statut;
789 $object->date_cancel =
dol_now();
790 $object->fk_user_cancel = $user->id;
793 $result = $object->update($user);
797 $result = $object->call_trigger(
'HOLIDAY_CANCEL', $user);
803 $nbopenedday =
num_open_day($object->date_debut_gmt, $object->date_fin_gmt, 0, 1, $object->halfday);
805 $soldeActuel = $object->getCpforUser($object->fk_user, $object->fk_type);
806 $newSolde = ($soldeActuel + $nbopenedday);
809 $result1 = $object->addLogCP($user->id, $object->fk_user, $langs->transnoentitiesnoconv(
"HolidaysCancelation"), $newSolde, $object->fk_type);
812 $result2 = $object->updateSoldeCP($object->fk_user, $newSolde, $object->fk_type);
814 if ($result1 < 0 || $result2 < 0) {
816 setEventMessages($langs->trans(
'ErrorCantDeleteCP').
' '.$object->error, $object->errors,
'errors');
827 if (!$error && $result > 0) {
829 $destinataire =
new User($db);
830 $destinataire->fetch($object->fk_user);
831 $emailTo = $destinataire->email;
834 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?id='.$object->id);
839 $expediteur =
new User($db);
840 $expediteur->fetch($object->fk_user_cancel);
842 $emailFrom = $conf->global->MAIN_MAIL_EMAIL_FROM;
845 $societeName = $conf->global->MAIN_INFO_SOCIETE_NOM;
846 if (!empty($conf->global->MAIN_APPLICATION_TITLE)) {
847 $societeName = $conf->global->MAIN_APPLICATION_TITLE;
850 $subject = $societeName.
" - ".$langs->transnoentitiesnoconv(
"HolidaysCanceled");
853 $message =
"<p>".$langs->transnoentitiesnoconv(
"Hello").
" ".$destinataire->firstname.
",</p>\n";
855 $message .=
"<p>".$langs->transnoentities(
"HolidaysCanceledBody",
dol_print_date($object->date_debut,
'day'),
dol_print_date($object->date_fin,
'day')).
"</p>\n";
857 $link =
dol_buildpath(
'/holiday/card.php', 3).
'?id='.$object->id;
859 $message .=
"<ul>\n";
860 $message .=
"<li>".$langs->transnoentitiesnoconv(
"ModifiedBy").
" : ".
dolGetFirstLastname($expediteur->firstname, $expediteur->lastname).
"</li>\n";
861 $message .=
"<li>".$langs->transnoentitiesnoconv(
"Link").
' : <a href="'.$link.
'" target="_blank">'.$link.
"</a></li>\n";
862 $message .=
"</ul>\n";
864 $trackid =
'leav'.$object->id;
866 $mail =
new CMailFile($subject, $emailTo, $emailFrom, $message, array(), array(), array(),
'',
'', 0, 1,
'',
'', $trackid);
869 $result = $mail->sendfile();
875 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?id='.$object->id);
908 $listhalfday = array(
'morning'=>$langs->trans(
"Morning"),
"afternoon"=>$langs->trans(
"Afternoon"));
910 $title = $langs->trans(
'Leave');
917 if ((empty($id) && empty($ref)) || $action ==
'create' || $action ==
'add') {
919 if ((in_array($fuserid, $childids) && empty($user->rights->holiday->write)) || (!in_array($fuserid, $childids) && (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || empty($user->rights->holiday->writeall_advance)))) {
920 $errors[] = $langs->trans(
'CantCreateCP');
929 $errors[] = $langs->trans(
'ErrorEndDateCP');
932 $errors[] = $langs->trans(
'ErrorSQLCreateCP');
935 $errors[] = $langs->trans(
'CantCreateCP');
938 $errors[] = $langs->trans(
'InvalidValidatorCP');
941 $errors[] = $langs->trans(
'NoDateDebut');
944 $errors[] = $langs->trans(
'NoDateFin');
947 $errors[] = $langs->trans(
'ErrorDureeCP');
950 $errors[] = $langs->trans(
'alreadyCPexist');
958 print
'<script type="text/javascript">
959 $( document ).ready(function() {
960 $("input.button-save").click("submit", function(e) {
961 console.log("Call valider()");
962 if (document.demandeCP.date_debut_.value != "")
964 if(document.demandeCP.date_fin_.value != "")
966 if(document.demandeCP.valideur.value != "-1") {
970 alert("'.dol_escape_js($langs->transnoentities(
'InvalidValidatorCP')).
'");
976 alert("'.
dol_escape_js($langs->transnoentities(
'NoDateFin')).
'");
982 alert("'.
dol_escape_js($langs->transnoentities(
'NoDateDebut')).
'");
991 print
'<form method="POST" action="'.$_SERVER[
'PHP_SELF'].
'" name="demandeCP">'.
"\n";
992 print
'<input type="hidden" name="token" value="'.newToken().
'" />'.
"\n";
993 print
'<input type="hidden" name="action" value="add" />'.
"\n";
995 if (empty($conf->global->HOLIDAY_HIDE_BALANCE)) {
1000 $typeleaves = $object->getTypes(1, 1);
1001 foreach ($typeleaves as $key => $val) {
1002 $nb_type = $object->getCPforUser($user->id, $val[
'rowid']);
1003 $nb_holiday += $nb_type;
1005 $out .=
' - '.($langs->trans($val[
'code']) != $val[
'code'] ? $langs->trans($val[
'code']) : $val[
'label']).
': <strong>'.($nb_type ?
price2num($nb_type) : 0).
'</strong><br>';
1008 print $langs->trans(
'SoldeCPUser', round($nb_holiday, 5)).
'<br>';
1012 } elseif (!is_numeric($conf->global->HOLIDAY_HIDE_BALANCE)) {
1013 print $langs->trans($conf->global->HOLIDAY_HIDE_BALANCE).
'<br>';
1020 print
'<table class="border centpercent">';
1025 print
'<td class="titlefield fieldrequired">'.$langs->trans(
"User").
'</td>';
1027 if ($cancreate && !$cancreateall) {
1028 print
img_picto(
'',
'user').$form->select_dolusers(($fuserid ? $fuserid : $user->id),
'fuserid', 0,
'', 0,
'hierarchyme',
'',
'0,'.$conf->entity, 0, 0, $morefilter, 0,
'',
'minwidth200 maxwidth500');
1031 print
img_picto(
'',
'user').$form->select_dolusers($fuserid ? $fuserid : $user->id,
'fuserid', 0,
'', 0,
'',
'',
'0,'.$conf->entity, 0, 0, $morefilter, 0,
'',
'minwidth200 maxwidth500');
1038 print
'<td class="fieldrequired">'.$langs->trans(
"Type").
'</td>';
1040 $typeleaves = $object->getTypes(1, -1);
1041 $arraytypeleaves = array();
1042 foreach ($typeleaves as $key => $val) {
1043 $labeltoshow = ($langs->trans($val[
'code']) != $val[
'code'] ? $langs->trans($val[
'code']) : $val[
'label']);
1044 $labeltoshow .= ($val[
'delay'] > 0 ?
' ('.$langs->trans(
"NoticePeriod").
': '.$val[
'delay'].
' '.$langs->trans(
"days").
')' :
'');
1045 $arraytypeleaves[$val[
'rowid']] = $labeltoshow;
1047 print
$form->selectarray(
'type', $arraytypeleaves, (
GETPOST(
'type',
'alpha') ?
GETPOST(
'type',
'alpha') :
''), 1, 0, 0,
'', 0, 0, 0,
'',
'', true);
1049 print
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
1056 print
'<td class="fieldrequired">';
1057 print
$form->textwithpicto($langs->trans(
"DateDebCP"), $langs->trans(
"FirstDayOfHoliday"));
1061 if (!
GETPOST(
'date_debut_')) {
1062 print
$form->selectDate(-1,
'date_debut_', 0, 0, 0,
'', 1, 1);
1065 print
$form->selectDate($tmpdate,
'date_debut_', 0, 0, 0,
'', 1, 1);
1067 print
' ';
1068 print
$form->selectarray(
'starthalfday', $listhalfday, (
GETPOST(
'starthalfday',
'alpha') ?
GETPOST(
'starthalfday',
'alpha') :
'morning'));
1074 print
'<td class="fieldrequired">';
1075 print
$form->textwithpicto($langs->trans(
"DateFinCP"), $langs->trans(
"LastDayOfHoliday"));
1079 print
$form->selectDate(-1,
'date_fin_', 0, 0, 0,
'', 1, 1);
1082 print
$form->selectDate($tmpdate,
'date_fin_', 0, 0, 0,
'', 1, 1);
1084 print
' ';
1085 print
$form->selectarray(
'endhalfday', $listhalfday, (
GETPOST(
'endhalfday',
'alpha') ?
GETPOST(
'endhalfday',
'alpha') :
'afternoon'));
1091 print
'<td class="fieldrequired">'.$langs->trans(
"ReviewedByCP").
'</td>';
1095 $include_users = $object->fetch_users_approver_holiday();
1096 if (empty($include_users)) {
1097 print
img_warning().
' '.$langs->trans(
"NobodyHasPermissionToValidateHolidays");
1101 $defaultselectuser = (empty($user->fk_user_holiday_validator) ? $user->fk_user : $user->fk_user_holiday_validator);
1102 if (!empty($conf->global->HOLIDAY_DEFAULT_VALIDATOR)) {
1103 $defaultselectuser = $conf->global->HOLIDAY_DEFAULT_VALIDATOR;
1105 if (
GETPOST(
'valideur',
'int') > 0) {
1106 $defaultselectuser =
GETPOST(
'valideur',
'int');
1108 $s =
$form->select_dolusers($defaultselectuser,
"valideur", 1,
'', 0, $include_users,
'',
'0,'.$conf->entity, 0, 0,
'', 0,
'',
'minwidth200 maxwidth500');
1109 print
img_picto(
'',
'user').$form->textwithpicto($s, $langs->trans(
"AnyOtherInThisListCanValidate"));
1118 print
'<td>'.$langs->trans(
"DescCP").
'</td>';
1119 print
'<td class="tdtop">';
1120 $doleditor =
new DolEditor(
'description',
GETPOST(
'description',
'restricthtml'),
'', 80,
'dolibarr_notes',
'In', 0,
false, empty($conf->fckeditor->enabled) ?
false : $conf->fckeditor->enabled, ROWS_3,
'90%');
1121 print $doleditor->Create(1);
1125 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_add.tpl.php';
1132 print
$form->buttonsSaveCancel(
"SendRequestCP");
1134 print
'</from>'.
"\n";
1138 print
'<div class="tabBar">';
1140 print
'<br><br><input type="button" value="'.$langs->trans(
"ReturnCP").
'" class="button" onclick="history.go(-1)" />';
1144 if (($id > 0) || $ref) {
1145 $result = $object->fetch($id, $ref);
1147 $approverexpected =
new User($db);
1148 $approverexpected->fetch($object->fk_validator);
1150 $userRequest =
new User($db);
1151 $userRequest->fetch($object->fk_user);
1159 $errors[] = $langs->transnoentitiesnoconv(
'ErrorEndDateCP');
1162 $errors[] = $langs->transnoentitiesnoconv(
'ErrorSQLCreateCP');
1165 $errors[] = $langs->transnoentitiesnoconv(
'CantCreateCP');
1168 $errors[] = $langs->transnoentitiesnoconv(
'InvalidValidatorCP');
1171 $errors[] = $langs->transnoentitiesnoconv(
'NoDateDebut');
1174 $errors[] = $langs->transnoentitiesnoconv(
'NoDateFin');
1176 case 'DureeHoliday':
1177 $errors[] = $langs->transnoentitiesnoconv(
'ErrorDureeCP');
1179 case 'NoMotifRefuse':
1180 $errors[] = $langs->transnoentitiesnoconv(
'NoMotifRefuseCP');
1183 $errors[] = $langs->transnoentitiesnoconv(
'ErrorMailNotSend');
1194 if (($action ==
'edit' && $object->statut ==
Holiday::STATUS_DRAFT) || ($action ==
'editvalidator')) {
1199 print
'<form method="post" action="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'">'.
"\n";
1200 print
'<input type="hidden" name="token" value="'.newToken().
'" />'.
"\n";
1201 print
'<input type="hidden" name="action" value="update"/>'.
"\n";
1202 print
'<input type="hidden" name="id" value="'.$object->id.
'" />'.
"\n";
1205 print
dol_get_fiche_head($head,
'card', $langs->trans(
"CPTitreMenu"), -1,
'holiday');
1207 $linkback =
'<a href="'.DOL_URL_ROOT.
'/holiday/list.php?restore_lastsearch_values=1">'.$langs->trans(
"BackToList").
'</a>';
1212 print
'<div class="fichecenter">';
1213 print
'<div class="fichehalfleft">';
1214 print
'<div class="underbanner clearboth"></div>';
1216 print
'<table class="border tableforfield centpercent">';
1221 print
'<td class="titlefield">'.$langs->trans(
"User").
'</td>';
1223 print $userRequest->getNomUrl(-1,
'leave');
1228 print
'<td>'.$langs->trans(
"Type").
'</td>';
1230 $typeleaves = $object->getTypes(1, -1);
1231 $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']);
1232 print empty($labeltoshow) ? $langs->trans(
"TypeWasDisabledOrRemoved", $object->fk_type) : $labeltoshow;
1236 $starthalfday = ($object->halfday == -1 || $object->halfday == 2) ?
'afternoon' :
'morning';
1237 $endhalfday = ($object->halfday == 1 || $object->halfday == 2) ?
'morning' :
'afternoon';
1241 print
'<td class="nowrap">';
1242 print
$form->textwithpicto($langs->trans(
'DateDebCP'), $langs->trans(
"FirstDayOfHoliday"));
1244 print
'<td>'.dol_print_date($object->date_debut,
'day');
1245 print
' ';
1246 print
'<span class="opacitymedium">'.$langs->trans($listhalfday[$starthalfday]).
'</span>';
1251 print
'<td class="nowrap">';
1252 print
$form->textwithpicto($langs->trans(
'DateDebCP'), $langs->trans(
"FirstDayOfHoliday"));
1255 print
$form->selectDate($object->date_debut,
'date_debut_');
1256 print
' ';
1257 print
$form->selectarray(
'starthalfday', $listhalfday, (
GETPOST(
'starthalfday') ?
GETPOST(
'starthalfday') : $starthalfday));
1264 print
'<td class="nowrap">';
1265 print
$form->textwithpicto($langs->trans(
'DateFinCP'), $langs->trans(
"LastDayOfHoliday"));
1267 print
'<td>'.dol_print_date($object->date_fin,
'day');
1268 print
' ';
1269 print
'<span class="opacitymedium">'.$langs->trans($listhalfday[$endhalfday]).
'</span>';
1274 print
'<td class="nowrap">';
1275 print
$form->textwithpicto($langs->trans(
'DateFinCP'), $langs->trans(
"LastDayOfHoliday"));
1278 print
$form->selectDate($object->date_fin,
'date_fin_');
1279 print
' ';
1280 print
$form->selectarray(
'endhalfday', $listhalfday, (
GETPOST(
'endhalfday') ?
GETPOST(
'endhalfday') : $endhalfday));
1288 $htmlhelp = $langs->trans(
'NbUseDaysCPHelp');
1289 $includesaturday = (isset($conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_SATURDAY) ? $conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_SATURDAY : 1);
1290 $includesunday = (isset($conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_SUNDAY) ? $conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_SUNDAY : 1);
1291 if ($includesaturday) {
1292 $htmlhelp .=
'<br>'.$langs->trans(
"DayIsANonWorkingDay", $langs->trans(
"Saturday"));
1294 if ($includesunday) {
1295 $htmlhelp .=
'<br>'.$langs->trans(
"DayIsANonWorkingDay", $langs->trans(
"Sunday"));
1297 print
$form->textwithpicto($langs->trans(
'NbUseDaysCP'), $htmlhelp);
1300 print
num_open_day($object->date_debut_gmt, $object->date_fin_gmt, 0, 1, $object->halfday);
1306 print
'<td>'.$langs->trans(
'DetailRefusCP').
'</td>';
1307 print
'<td>'.$object->detail_refuse.
'</td>';
1314 print
'<td>'.$langs->trans(
'DescCP').
'</td>';
1315 print
'<td>'.nl2br($object->description).
'</td>';
1319 print
'<td>'.$langs->trans(
'DescCP').
'</td>';
1320 print
'<td class="tdtop">';
1321 $doleditor =
new DolEditor(
'description', $object->description,
'', 80,
'dolibarr_notes',
'In', 0,
false, empty($conf->fckeditor->enabled) ?
false : $conf->fckeditor->enabled, ROWS_3,
'90%');
1322 print $doleditor->Create(1);
1327 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
1330 print
'</table>'.
"\n";
1333 print
'<div class="fichehalfright">';
1335 print
'<div class="underbanner clearboth"></div>';
1338 print
'<table class="border tableforfield centpercent">'.
"\n";
1341 if (!empty($object->fk_user_create)) {
1342 $userCreate =
new User($db);
1343 $userCreate->fetch($object->fk_user_create);
1345 print
'<td class="titlefield">'.$langs->trans(
'RequestByCP').
'</td>';
1346 print
'<td>'.$userCreate->getNomUrl(-1).
'</td>';
1351 if (!$edit && $action !=
'editvalidator') {
1353 print
'<td class="titlefield">';
1355 print $langs->trans(
'ApprovedBy');
1357 print $langs->trans(
'ReviewedByCP');
1362 $approverdone =
new User($db);
1363 $approverdone->fetch($object->fk_user_valid);
1364 print $approverdone->getNomUrl(-1);
1366 print $approverexpected->getNomUrl(-1);
1368 $include_users = $object->fetch_users_approver_holiday();
1370 print
'<a class="editfielda paddingleft" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=editvalidator&token='.
newToken().
'">'.
img_edit($langs->trans(
"Edit")).
'</a>';
1376 print
'<td class="titlefield">'.$langs->trans(
'ReviewedByCP').
'</td>';
1378 $include_users = $object->fetch_users_approver_holiday();
1379 if (!in_array($object->fk_validator, $include_users)) {
1380 $include_users[] = $object->fk_validator;
1382 if (empty($include_users)) {
1383 print
img_warning().
' '.$langs->trans(
"NobodyHasPermissionToValidateHolidays");
1385 $arrayofvalidatorstoexclude = (($user->admin || ($user->id != $userRequest->id)) ?
'' : array($user->id));
1386 $s =
$form->select_dolusers($object->fk_validator,
"valideur", (($action ==
'editvalidator') ? 0 : 1), $arrayofvalidatorstoexclude, 0, $include_users);
1387 print
$form->textwithpicto($s, $langs->trans(
"AnyOtherInThisListCanValidate"));
1389 if ($action ==
'editvalidator') {
1390 print
'<input type="submit" class="button button-save" name="savevalidator" value="'.$langs->trans(
"Save").
'">';
1391 print
'<input type="submit" class="button button-cancel" name="cancel" value="'.$langs->trans(
"Cancel").
'">';
1398 print
'<td>'.$langs->trans(
'DateCreation').
'</td>';
1399 print
'<td>'.dol_print_date($object->date_create,
'dayhour',
'tzuser').
'</td>';
1403 print
'<td>'.$langs->trans(
'DateValidCP').
'</td>';
1404 print
'<td>'.dol_print_date($object->date_valid,
'dayhour',
'tzuser').
'</td>';
1409 print
'<td>'.$langs->trans(
'DateCancelCP').
'</td>';
1410 print
'<td>'.dol_print_date($object->date_cancel,
'dayhour',
'tzuser').
'</td>';
1415 print
'<td>'.$langs->trans(
'DateRefusCP').
'</td>';
1416 print
'<td>'.dol_print_date($object->date_refuse,
'dayhour',
'tzuser').
'</td>';
1425 print
'<div class="clearboth"></div>';
1431 if ($action ==
'delete') {
1433 print
$form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".$object->id, $langs->trans(
"TitleDeleteCP"), $langs->trans(
"ConfirmDeleteCP"),
"confirm_delete",
'', 0, 1);
1439 print
$form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".$object->id, $langs->trans(
"TitleToValidCP"), $langs->trans(
"ConfirmToValidCP"),
"confirm_send",
'', 1, 1);
1443 if ($action ==
'valid') {
1444 print
$form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".$object->id, $langs->trans(
"TitleValidCP"), $langs->trans(
"ConfirmValidCP"),
"confirm_valid",
'', 1, 1);
1448 if ($action ==
'refuse') {
1449 $array_input = array(array(
'type'=>
"text",
'label'=> $langs->trans(
'DetailRefusCP'),
'name'=>
"detail_refuse",
'size'=>
"50",
'value'=>
""));
1450 print
$form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".$object->id.
"&action=confirm_refuse", $langs->trans(
"TitleRefuseCP"), $langs->trans(
'ConfirmRefuseCP'),
"confirm_refuse", $array_input, 1, 0);
1454 if ($action ==
'cancel') {
1455 print
$form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".$object->id, $langs->trans(
"TitleCancelCP"), $langs->trans(
"ConfirmCancelCP"),
"confirm_cancel",
'', 1, 1);
1459 if ($action ==
'backtodraft') {
1460 print
$form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".$object->id, $langs->trans(
"TitleSetToDraft"), $langs->trans(
"ConfirmSetToDraft"),
"confirm_draft",
'', 1, 1);
1463 if (($action ==
'edit' && $object->statut ==
Holiday::STATUS_DRAFT) || ($action ==
'editvalidator')) {
1466 print
$form->buttonsSaveCancel();
1476 print
'<div class="tabsAction">';
1479 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=edit&token='.
newToken().
'" class="butAction">'.$langs->trans(
"EditCP").
'</a>';
1483 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=sendToValidate&token='.
newToken().
'" class="butAction">'.$langs->trans(
"Validate").
'</a>';
1488 if ($user->id == $object->fk_validator) {
1489 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=valid" class="butAction">'.$langs->trans(
"Approve").
'</a>';
1490 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=refuse" class="butAction">'.$langs->trans(
"ActionRefuseCP").
'</a>';
1492 print
'<a href="#" class="butActionRefused classfortooltip" title="'.$langs->trans(
"NotTheAssignedApprover").
'">'.$langs->trans(
"Approve").
'</a>';
1493 print
'<a href="#" class="butActionRefused classfortooltip" title="'.$langs->trans(
"NotTheAssignedApprover").
'">'.$langs->trans(
"ActionRefuseCP").
'</a>';
1496 if ($cancreate || $cancreateall) {
1497 if (($object->date_debut >
dol_now()) || !empty($user->admin)) {
1498 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=cancel&token='.
newToken().
'" class="butAction">'.$langs->trans(
"ActionCancelCP").
'</a>';
1500 print
'<a href="#" class="butActionRefused classfortooltip" title="'.$langs->trans(
"HolidayStarted").
'-'.$langs->trans(
"NotAllowed").
'">'.$langs->trans(
"ActionCancelCP").
'</a>';
1506 if ($user->id == $object->fk_validator || $cancreate || $cancreateall) {
1507 if (($object->date_debut >
dol_now()) || !empty($user->admin)) {
1508 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=cancel&token='.
newToken().
'" class="butAction">'.$langs->trans(
"ActionCancelCP").
'</a>';
1510 print
'<a href="#" class="butActionRefused classfortooltip" title="'.$langs->trans(
"HolidayStarted").
'-'.$langs->trans(
"NotAllowed").
'">'.$langs->trans(
"ActionCancelCP").
'</a>';
1513 if (!empty($user->admin)) {
1514 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=cancel&token='.
newToken().
'" class="butAction">'.$langs->trans(
"ActionCancelCP").
'</a>';
1516 print
'<a href="#" class="butActionRefused classfortooltip" title="'.$langs->trans(
"NotAllowed").
'">'.$langs->trans(
"ActionCancelCP").
'</a>';
1522 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=backtodraft" class="butAction">'.$langs->trans(
"SetToDraft").
'</a>';
1525 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=delete&token='.
newToken().
'" class="butActionDelete">'.$langs->trans(
"DeleteCP").
'</a>';
1531 print
'<div class="tabBar">';
1532 print $langs->trans(
'ErrorUserViewCP');
1533 print
'<br><br><input type="button" value="'.$langs->trans(
"ReturnCP").
'" class="button" onclick="history.go(-1)" />';
1537 print
'<div class="tabBar">';
1538 print $langs->trans(
'ErrorIDFicheCP');
1539 print
'<br><br><input type="button" value="'.$langs->trans(
"ReturnCP").
'" class="button" onclick="history.go(-1)" />';
1545 if (
GETPOST(
'modelselected')) {
1546 $action =
'presend';
1549 if ($action !=
'presend' && $action !=
'edit') {
1550 print
'<div class="fichecenter"><div class="fichehalfleft">';
1551 print
'<a name="builddoc"></a>';
1553 $includedocgeneration = 0;
1556 if ($includedocgeneration) {
1558 $relativepath = $objref.
'/'.$objref.
'.pdf';
1559 $filedir = $conf->holiday->dir_output.
'/'.$object->element.
'/'.$objref;
1560 $urlsource = $_SERVER[
"PHP_SELF"].
"?id=".$object->id;
1561 $genallowed = ($user->rights->holiday->read && $object->fk_user == $user->id) || !empty($user->rights->holiday->readall);
1562 $delallowed = ($user->rights->holiday->write && $object->fk_user == $user->id) || !empty($user->rights->holiday->writeall_advance);
1563 print $formfile->showdocuments(
'holiday:Holiday', $object->element.
'/'.$objref, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0,
'',
'',
'', $langs->defaultlang);
1571 print
'</div><div class="fichehalfright">';
1574 $morehtmlright =
'';
1577 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formactions.class.php';
1579 $somethingshown =
$formactions->showactions($object, $object->element, (is_object($object->thirdparty) ? $object->thirdparty->id : 0), 1,
'', $MAXEVENT,
'', $morehtmlright);
1581 print
'</div></div>';
1589 if (is_object($db)) {