34require
'../main.inc.php';
35require_once DOL_DOCUMENT_ROOT.
'/core/class/html.form.class.php';
36require_once DOL_DOCUMENT_ROOT.
'/user/class/usergroup.class.php';
37require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
38require_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
39require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
40require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
41require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
42require_once DOL_DOCUMENT_ROOT.
'/core/lib/holiday.lib.php';
43require_once DOL_DOCUMENT_ROOT.
'/holiday/class/holiday.class.php';
44require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
47$action =
GETPOST(
'action',
'aZ09');
48$cancel =
GETPOST(
'cancel',
'alpha');
49$confirm =
GETPOST(
'confirm',
'alpha');
53$users = (
GETPOST(
'users',
'array') ?
GETPOST(
'users',
'array') : array($user->id));
54$groups =
GETPOST(
'groups',
'array');
59$langs->loadLangs(array(
"other",
"holiday",
"mails",
"trips"));
65$childids = $user->getAllChildIds(1);
69 $morefilter =
'AND employee = 1';
77$extrafields->fetch_name_optionals_label(
$object->table_element);
79if (($id > 0) || $ref) {
84 if ($user->hasRight(
'holiday',
'readall')) {
87 if ($user->hasRight(
'holiday',
'read') && in_array(
$object->fk_user, $childids)) {
96$hookmanager->initHooks(array(
'holidaycard',
'globalcard'));
100if ($user->hasRight(
'holiday',
'write') && in_array($fuserid, $childids)) {
103if ($user->hasRight(
'holiday',
'writeall')) {
109if ($user->hasRight(
'holiday',
'delete')) {
118 $socid = $user->socid;
127$parameters = array(
'socid' => $socid);
128$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
133if (empty($reshook)) {
134 $backurlforlist = DOL_URL_ROOT.
'/holiday/list.php';
136 if (empty($backtopage) || ($cancel && empty($id))) {
137 if (empty($backtopage) || ($cancel && strpos($backtopage,
'__ID__'))) {
138 if (empty($id) && (($action !=
'add' && $action !=
'create') || $cancel)) {
139 $backtopage = $backurlforlist;
141 $backtopage = DOL_URL_ROOT.
'/holiday/card_group.php?id='.((!empty($id) &&
$id > 0) ? $id :
'__ID__');
147 if (!empty($backtopageforcancel)) {
148 header(
"Location: ".$backtopageforcancel);
150 } elseif (!empty($backtopage)) {
151 header(
"Location: ".$backtopage);
158 if ($action ==
'add') {
167 $users =
GETPOST(
'users',
'array');
168 $groups =
GETPOST(
'groups',
'array');
174 $starthalfday =
GETPOST(
'starthalfday');
175 $endhalfday =
GETPOST(
'endhalfday');
179 if ($starthalfday ==
'afternoon' && $endhalfday ==
'morning') {
181 } elseif ($starthalfday ==
'afternoon') {
183 } elseif ($endhalfday ==
'morning') {
188 $description = trim(
GETPOST(
'description',
'restricthtml'));
191 if (!$cancreateall) {
193 if (!$user->hasRight(
'holiday',
'write')) {
196 } elseif (!in_array($fuserid, $childids)) {
202 if (!$user->hasRight(
'holiday',
'write') && !$user->hasRight(
'holiday',
'writeall_advance')) {
205 } elseif (!$user->hasRight(
'holiday',
'writeall_advance') && !in_array($fuserid, $childids)) {
213 if (empty($groups) && empty($users)) {
214 setEventMessages($langs->trans(
"ErrorFieldRequiredUserOrGroup"),
null,
'errors');
222 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type")),
null,
'errors');
228 if (empty($date_debut)) {
234 if (empty($date_fin)) {
240 if ($date_debut > $date_fin) {
247 $nbopenedday =
num_open_day($date_debut_gmt, $date_fin_gmt, 0, 1, $halfday);
248 if ($nbopenedday < 0.5) {
255 if ($approverid < 1) {
256 setEventMessages($langs->transnoentitiesnoconv(
'InvalidValidatorCP'),
null,
'errors');
264 $TusersToProcess = array();
268 $sql =
' SELECT DISTINCT u.rowid,u.lastname,u.firstname from ' . MAIN_DB_PREFIX .
'user as u';
269 $sql .=
' LEFT JOIN ' . MAIN_DB_PREFIX .
'usergroup_user as ug on ug.fk_user = u.rowid ';
270 $sql .=
' WHERE fk_usergroup in (' .$db->sanitize(implode(
',', $groups)) .
')';
271 $resql = $db->query($sql);
274 while ($obj = $db->fetch_object($resql)) {
275 $TusersToProcess[$obj->rowid] = $obj->rowid;
279 if (is_array($users) && count($users) > 0) {
280 foreach ($users as $u) {
281 $TusersToProcess[$u] = $u;
284 foreach ($TusersToProcess as $u) {
286 $verifCP =
$object->verifDateHolidayCP($u, $date_debut, $date_fin, $halfday);
290 $userError =
new User($db);
291 $result = $userError->fetch($u);
294 setEventMessages($langs->trans(
"UseralreadyCPexist", $userError->firstname .
' '. $userError->lastname),
null,
'errors');
307 foreach ($TusersToProcess as $u) {
310 $object->description = $description;
311 $object->fk_validator = $approverid;
313 $object->date_debut = $date_debut;
317 $result =
$object->create($user);
324 if ($autoValidation) {
326 $htemp->fetch($result);
329 $resultValidated = $htemp->update($approverid);
331 if ($resultValidated < 0) {
337 if ($AutoSendMail && !$error) {
339 $returnSendMail =
sendMail($result, $cancreate, $now, $autoValidation);
340 if (!empty($returnSendMail->msg)) {
351 header(
'Location: '.DOL_URL_ROOT.
'/holiday/list.php');
367$form =
new Form($db);
370$listhalfday = array(
'morning' => $langs->trans(
"Morning"),
"afternoon" => $langs->trans(
"Afternoon"));
372$title = $langs->trans(
'Leave');
373$help_url =
'EN:Module_Holiday';
375llxHeader(
'', $title, $help_url,
'', 0, 0,
'',
'',
'',
'mod-holiday page-card_group');
377if ((empty($id) && empty($ref)) || $action ==
'create' || $action ==
'add') {
379 if ((in_array($fuserid, $childids) && !$user->hasRight(
'holiday',
'writeall')) || (!in_array($fuserid, $childids) && (!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') || !$user->hasRight(
'holiday',
'writeall_advance')))) {
380 $errors[] = $langs->trans(
'CantCreateCP');
383 print
load_fiche_titre($langs->trans(
'MenuCollectiveAddCP'),
'',
'title_hrm.png');
389 $errors[] = $langs->trans(
'ErrorEndDateCP');
392 $errors[] = $langs->trans(
'ErrorSQLCreateCP');
395 $errors[] = $langs->trans(
'CantCreateCP');
398 $errors[] = $langs->trans(
'InvalidValidatorCP');
401 $errors[] = $langs->trans(
'NoDateDebut');
404 $errors[] = $langs->trans(
'NoDateFin');
407 $errors[] = $langs->trans(
'ErrorDureeCP');
410 $errors[] = $langs->trans(
'alreadyCPexist');
418 print
'<script type="text/javascript">
419 $( document ).ready(function() {
421 if( $("input[name=autoValidation]").is(":checked") ){
422 $("#AutoSendMail").prop("disabled", false);
423 $("#AutoSendMail").prop("checked", true);
426 $("#AutoSendMail").prop("disabled", true);
427 $("#AutoSendMail").prop("checked", false);
430 $("input[name=autoValidation]").click( function(e) {
433 if( $("input[name=autoValidation]").is(":checked") ){
434 $("#AutoSendMail").prop("disabled", false);
435 $("#AutoSendMail").prop("checked", true);
437 $("#AutoSendMail").prop("disabled", true);
438 $("#AutoSendMail").prop("checked", false);
444 $("input.button-save").click("submit", function(e) {
445 console.log("Call valider()");
446 if (document.demandeCP.date_debut_.value != "")
448 if(document.demandeCP.date_fin_.value != "")
450 if(document.demandeCP.valideur.value != "-1") {
454 alert("'.dol_escape_js($langs->transnoentities(
'InvalidValidatorCP')).
'");
460 alert("'.
dol_escape_js($langs->transnoentities(
'NoDateFin')).
'");
466 alert("'.
dol_escape_js($langs->transnoentities(
'NoDateDebut')).
'");
471 $("#autoValidation").change(function(){
472 if( $("input[name=autoValidation]").is(":checked") ){
473 $("#AutoSendMail").prop("disabled", false);
475 $("#AutoSendMail").prop("disabled", true);
476 $("#AutoSendMail").prop("checked", false);
484 print
'<form method="POST" action="'.$_SERVER[
'PHP_SELF'].
'" name="demandeCP">'.
"\n";
485 print
'<input type="hidden" name="token" value="'.newToken().
'" />'.
"\n";
486 print
'<input type="hidden" name="action" value="add" />'.
"\n";
490 print
'<table class="border centpercent">';
495 print
'<td class="titlefield fieldrequired">';
496 print $form->textwithpicto($langs->trans(
"groups"), $langs->trans(
"fusionGroupsUsers"));
499 print
img_picto($langs->trans(
"groups"),
'group',
'class="pictofixedwidth"');
501 $sql =
' SELECT rowid, nom from '.MAIN_DB_PREFIX.
'usergroup WHERE entity IN ('.
getEntity(
'usergroup').
')';
502 $resql = $db->query($sql);
504 while ($obj = $db->fetch_object($resql)) {
505 $Tgroup[$obj->rowid] = $obj->nom;
508 print $form->multiselectarray(
'groups', $Tgroup,
GETPOST(
'groups',
'array'),
'', 0,
'quatrevingtpercent widthcentpercentminusx', 0, 0);
514 print
'<td class="titlefield fieldrequired">';
515 print $form->textwithpicto($langs->trans(
"users"), $langs->trans(
"fusionGroupsUsers"));
517 print
img_picto($langs->trans(
"users"),
'user',
'class="pictofixedwidth"');
519 $sql =
' SELECT u.rowid, u.lastname, u.firstname from '.MAIN_DB_PREFIX.
'user as u';
520 $sql .=
' WHERE 1=1';
521 $sql .= !empty($morefilter) ? $morefilter :
'';
525 $resql = $db->query($sql);
527 while ($obj = $db->fetch_object($resql)) {
532 print
img_picto(
'',
'users',
'class="pictofixedwidth"') . $form->multiselectarray(
'users', $userlist,
GETPOST(
'users',
'array'),
'', 0,
'quatrevingtpercent widthcentpercentminusx', 0, 0);
537 print
'<td class="fieldrequired">'.$langs->trans(
"Type").
'</td>';
539 $typeleaves =
$object->getTypes(1, -1);
540 $arraytypeleaves = array();
541 foreach ($typeleaves as $key => $val) {
542 $labeltoshow = ($langs->trans($val[
'code']) != $val[
'code'] ? $langs->trans($val[
'code']) : $val[
'label']);
543 $labeltoshow .= ($val[
'delay'] > 0 ?
' ('.$langs->trans(
"NoticePeriod").
': '.$val[
'delay'].
' '.$langs->trans(
"days").
')' :
'');
544 $arraytypeleaves[$val[
'rowid']] = $labeltoshow;
546 print $form->selectarray(
'type', $arraytypeleaves, (
GETPOST(
'type',
'alpha') ?
GETPOST(
'type',
'alpha') :
''), 1, 0, 0,
'', 0, 0, 0,
'',
'', true);
548 print
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
555 print
'<td class="fieldrequired">';
556 print $form->textwithpicto($langs->trans(
"DateDebCP"), $langs->trans(
"FirstDayOfHoliday"));
561 print $form->selectDate(-1,
'date_debut_', 0, 0, 0,
'', 1, 1);
564 print $form->selectDate($tmpdate,
'date_debut_', 0, 0, 0,
'', 1, 1);
566 print
' ';
567 print $form->selectarray(
'starthalfday', $listhalfday, (
GETPOST(
'starthalfday',
'alpha') ?
GETPOST(
'starthalfday',
'alpha') :
'morning'));
573 print
'<td class="fieldrequired">';
574 print $form->textwithpicto($langs->trans(
"DateFinCP"), $langs->trans(
"LastDayOfHoliday"));
578 print $form->selectDate(-1,
'date_fin_', 0, 0, 0,
'', 1, 1);
581 print $form->selectDate($tmpdate,
'date_fin_', 0, 0, 0,
'', 1, 1);
583 print
' ';
584 print $form->selectarray(
'endhalfday', $listhalfday, (
GETPOST(
'endhalfday',
'alpha') ?
GETPOST(
'endhalfday',
'alpha') :
'afternoon'));
590 print
'<td class="fieldrequired">'.$langs->trans(
"ReviewedByCP").
'</td>';
594 $include_users =
$object->fetch_users_approver_holiday();
595 if (empty($include_users)) {
596 print
img_warning().
' '.$langs->trans(
"NobodyHasPermissionToValidateHolidays");
600 $defaultselectuser = (empty($user->fk_user_holiday_validator) ? $user->fk_user : $user->fk_user_holiday_validator);
607 $s = $form->select_dolusers($defaultselectuser,
"valideur", 1,
'', 0, $include_users,
'',
'0,'.$conf->entity, 0, 0,
'', 0,
'',
'minwidth200 maxwidth500');
608 print
img_picto(
'',
'user').$form->textwithpicto($s, $langs->trans(
"AnyOtherInThisListCanValidate"));
616 print
'<tr><td>'.$langs->trans(
"AutoValidationOnCreate").
'</td><td>';
617 print
'<input type="checkbox" id="autoValidation" name="autoValidation" value="1"'.($autoValidation ?
' checked="checked"' :
'').
'>';
618 print
'</td></tr>'.
"\n";
622 print
'<tr><td>'.$langs->trans(
"AutoSendMail").
'</td><td>';
623 print
'<input type="checkbox" id="AutoSendMail" name="AutoSendMail" value="1"'.($AutoSendMail ?
' checked="checked"' :
'').
'>';
624 print
'</td></tr>'.
"\n";
628 print
'<td>'.$langs->trans(
"DescCP").
'</td>';
629 print
'<td class="tdtop">';
630 $doleditor =
new DolEditor(
'description',
GETPOST(
'description',
'restricthtml'),
'', 80,
'dolibarr_notes',
'In', 0,
false, isModEnabled(
'fckeditor'), ROWS_3,
'90%');
631 print $doleditor->Create(1);
635 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_add.tpl.php';
642 print $form->buttonsSaveCancel(
"SendRequestCollectiveCP");
644 print
'</from>'.
"\n";
648 print
'<div class="tabBar">';
650 print
'<br><br><input type="button" value="'.$langs->trans(
"ReturnCP").
'" class="button" onclick="history.go(-1)" />';
672function sendMail($id, $cancreate, $now, $autoValidation)
676 $objStd->status =
'success';
680 global $db, $user, $conf, $langs;
693 $verif =
$object->validate($user);
697 $destinataire =
new User($db);
698 $destinataire->fetch(
$object->fk_validator);
699 $emailTo = $destinataire->email;
703 dol_syslog(
"Expected validator has no email, so we redirect directly to finished page without sending email");
706 $objStd->msg = $langs->trans(
'ErrorMailRecipientIsEmpty');
707 $objStd->status =
'error';
708 $objStd->style =
"warnings";
713 $expediteur =
new User($db);
714 $expediteur->fetch(
$object->fk_user);
724 $subject = $societeName.
" - ".$langs->transnoentitiesnoconv(
"HolidaysToValidate");
727 $message =
"<p>".$langs->transnoentitiesnoconv(
"Hello").
" ".$destinataire->firstname.
",</p>\n";
729 $message .=
"<p>".$langs->transnoentities(
"HolidaysToValidateBody").
"</p>\n";
734 $delayForRequest = 0;
735 if ($delayForRequest) {
738 if (
$object->date_debut < $nowplusdelay) {
739 $message =
"<p>".$langs->transnoentities(
"HolidaysToValidateDelay", $delayForRequest).
"</p>\n";
749 $message .=
"<p>".$langs->transnoentities(
"HolidaysToValidateAlertSolde").
"</p>\n";
753 $typeleaves =
$object->getTypes(1, -1);
754 $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']);
757 $starthalfdaykey =
"Afternoon";
758 $endhalfdaykey =
"Morning";
759 } elseif (
$object->halfday == -1) {
760 $starthalfdaykey =
"Afternoon";
761 $endhalfdaykey =
"Afternoon";
762 } elseif (
$object->halfday == 1) {
763 $starthalfdaykey =
"Morning";
764 $endhalfdaykey =
"Morning";
766 $starthalfdaykey =
"Morning";
767 $endhalfdaykey =
"Afternoon";
770 $link =
dol_buildpath(
"/holiday/card.php", 3) .
'?id='.$object->id;
773 $message .=
"<li>".$langs->transnoentitiesnoconv(
"Name").
" : ".
dolGetFirstLastname($expediteur->firstname, $expediteur->lastname).
"</li>\n";
774 $message .=
"<li>".$langs->transnoentitiesnoconv(
"Type").
" : ".(empty($labeltoshow) ? $langs->trans(
"TypeWasDisabledOrRemoved",
$object->fk_type) : $labeltoshow).
"</li>\n";
775 $message .=
"<li>".$langs->transnoentitiesnoconv(
"Period").
" : ".
dol_print_date(
$object->date_debut,
'day').
" ".$langs->transnoentitiesnoconv($starthalfdaykey).
" ".$langs->transnoentitiesnoconv(
"To").
" ".
dol_print_date(
$object->date_fin,
'day').
" ".$langs->transnoentitiesnoconv($endhalfdaykey).
"</li>\n";
776 $message .=
"<li>".$langs->transnoentitiesnoconv(
"Link").
' : <a href="'.$link.
'" target="_blank">'.$link.
"</a></li>\n";
777 $message .=
"</ul>\n";
779 $trackid =
'leav'.$object->id;
783 $mail =
new CMailFile($subject, $emailTo, $emailFrom, $message, array(), array(), array(),
'', $sendtobcc, 0, 1,
'',
'', $trackid);
786 $result = $mail->sendfile();
790 $objStd->msg = $langs->trans(
'ErrorMailNotSend');
791 $objStd->style =
"warnings";
792 $objStd->status =
'error';
794 $objStd->msg = $langs->trans(
'MailSent');
800 $objStd->msg = $langs->trans(
'ErrorVerif');
801 $objStd->status =
'error';
802 $objStd->style =
"errors";
808 $objStd->msg = $langs->trans(
'ErrorloadUserOnSendingMail');
809 $objStd->status =
'error';
810 $objStd->style =
"warnings";
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
if(is_object( $db)) sendMail($id, $cancreate, $now, $autoValidation)
send email to validator for current leave represented by (id)
Class to send emails (with attachments or not) Usage: $mailfile = new CMailFile($subject,...
Class to manage a WYSIWYG editor.
Class of the module paid holiday.
const STATUS_VALIDATED
Validated status.
const STATUS_DRAFT
Draft status.
Class to manage Dolibarr users.
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)
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
setEventMessage($mesgs, $style='mesgs', $noduplicate=0)
Set event message in dol_events session object.
dol_now($mode='auto')
Return date for now.
dol_escape_js($stringtoescape, $mode=0, $noescapebackslashn=0)
Returns text escaped for inclusion into javascript code.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_clone($object, $native=0)
Create a clone of instance of object (new instance with same value for each properties) With native =...
dolGetFirstLastname($firstname, $lastname, $nameorder=-1)
Return firstname and lastname in correct order.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='')
Show information in HTML for admin users or standard users.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.