dolibarr 18.0.6
card_group.php
1<?php
2/* Copyright (C) 2011 Dimitri Mouillard <dmouillard@teclib.com>
3 * Copyright (C) 2012-2016 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2012-2016 Regis Houssin <regis.houssin@inodbox.com>
5 * Copyright (C) 2013 Juanjo Menent <jmenent@2byte.es>
6 * Copyright (C) 2017 Alexandre Spangaro <aspangaro@open-dsi.fr>
7 * Copyright (C) 2014-2017 Ferran Marcet <fmarcet@2byte.es>
8 * Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
9 * Copyright (C) 2020-2021 Udo Tamm <dev@dolibit.de>
10 * Copyright (C) 2022 Anthony Berton <anthony.berton@bb2a.fr>
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 3 of the License, orwrite
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program. If not, see <https://www.gnu.org/licenses/>.
24 */
25
32// Load Dolibarr environment
33require '../main.inc.php';
34require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
35require_once DOL_DOCUMENT_ROOT.'/user/class/usergroup.class.php';
36require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
37require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
38require_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
39require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
40require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
41require_once DOL_DOCUMENT_ROOT.'/core/lib/holiday.lib.php';
42require_once DOL_DOCUMENT_ROOT.'/holiday/class/holiday.class.php';
43require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
44
45// Get parameters
46$action = GETPOST('action', 'aZ09');
47$cancel = GETPOST('cancel', 'alpha');
48$confirm = GETPOST('confirm', 'alpha');
49$id = GETPOST('id', 'int');
50$ref = GETPOST('ref', 'alpha');
51$fuserid = (GETPOST('fuserid', 'int') ?GETPOST('fuserid', 'int') : $user->id);
52$users = (GETPOST('users', 'array') ?GETPOST('users', 'array') : array($user->id));
53$groups = GETPOST('groups', 'array');
54$socid = GETPOST('socid', 'int');
55$autoValidation = GETPOST('autoValidation', 'int');
56$AutoSendMail = GETPOST('AutoSendMail', 'int');
57// Load translation files required by the page
58$langs->loadLangs(array("other", "holiday", "mails", "trips"));
59
60$error = 0;
61
62$now = dol_now();
63
64$childids = $user->getAllChildIds(1);
65
66$morefilter = '';
67if (!empty($conf->global->HOLIDAY_HIDE_FOR_NON_SALARIES)) {
68 $morefilter = 'AND employee = 1';
69}
70
71$object = new Holiday($db);
72
73$extrafields = new ExtraFields($db);
74
75// fetch optionals attributes and labels
76$extrafields->fetch_name_optionals_label($object->table_element);
77
78if (($id > 0) || $ref) {
79 $object->fetch($id, $ref);
80
81 // Check current user can read this leave request
82 $canread = 0;
83 if (!empty($user->rights->holiday->readall)) {
84 $canread = 1;
85 }
86 if (!empty($user->rights->holiday->read) && in_array($object->fk_user, $childids)) {
87 $canread = 1;
88 }
89 if (!$canread) {
91 }
92}
93
94// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
95$hookmanager->initHooks(array('holidaycard', 'globalcard'));
96
97$cancreate = 0;
98$cancreateall = 0;
99if (!empty($user->rights->holiday->write) && in_array($fuserid, $childids)) {
100 $cancreate = 1;
101}
102if (!empty($user->rights->holiday->writeall)) {
103 $cancreate = 1;
104 $cancreateall = 1;
105}
106
107$candelete = 0;
108if (!empty($user->rights->holiday->delete)) {
109 $candelete = 1;
110}
111if ($object->statut == Holiday::STATUS_DRAFT && $user->rights->holiday->write && in_array($object->fk_user, $childids)) {
112 $candelete = 1;
113}
114
115// Protection if external user
116if ($user->socid) {
117 $socid = $user->socid;
118}
119$result = restrictedArea($user, 'holiday', $object->id, 'holiday', '', '', 'rowid', $object->statut);
120
121
122/*
123 * Actions
124 */
125
126$parameters = array('socid' => $socid);
127$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
128if ($reshook < 0) {
129 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
130}
131
132if (empty($reshook)) {
133 $backurlforlist = DOL_URL_ROOT.'/holiday/list.php';
134
135 if (empty($backtopage) || ($cancel && empty($id))) {
136 if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) {
137 if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) {
138 $backtopage = $backurlforlist;
139 } else {
140 $backtopage = DOL_URL_ROOT.'/holiday/card_group.php?id='.((!empty($id) && $id > 0) ? $id : '__ID__');
141 }
142 }
143 }
144
145 if ($cancel) {
146 if (!empty($backtopageforcancel)) {
147 header("Location: ".$backtopageforcancel);
148 exit;
149 } elseif (!empty($backtopage)) {
150 header("Location: ".$backtopage);
151 exit;
152 }
153 $action = '';
154 }
155
156 // Add leave request
157 if ($action == 'add') {
158 // If no right to create a request
159 if (!$cancreate) {
160 $error++;
161 setEventMessages($langs->trans('CantCreateCP'), null, 'errors');
162 $action = 'create';
163 }
164
165 if (!$error) {
166 $users = GETPOST('users', 'array');
167 $groups = GETPOST('groups', 'array');
168
169 $date_debut = dol_mktime(0, 0, 0, GETPOST('date_debut_month'), GETPOST('date_debut_day'), GETPOST('date_debut_year'));
170 $date_fin = dol_mktime(0, 0, 0, GETPOST('date_fin_month'), GETPOST('date_fin_day'), GETPOST('date_fin_year'));
171 $date_debut_gmt = dol_mktime(0, 0, 0, GETPOST('date_debut_month'), GETPOST('date_debut_day'), GETPOST('date_debut_year'), 1);
172 $date_fin_gmt = dol_mktime(0, 0, 0, GETPOST('date_fin_month'), GETPOST('date_fin_day'), GETPOST('date_fin_year'), 1);
173 $starthalfday = GETPOST('starthalfday');
174 $endhalfday = GETPOST('endhalfday');
175 $type = GETPOST('type');
176
177 $halfday = 0;
178 if ($starthalfday == 'afternoon' && $endhalfday == 'morning') {
179 $halfday = 2;
180 } elseif ($starthalfday == 'afternoon') {
181 $halfday = -1;
182 } elseif ($endhalfday == 'morning') {
183 $halfday = 1;
184 }
185
186 $approverid = GETPOST('valideur', 'int');
187 $description = trim(GETPOST('description', 'restricthtml'));
188
189 // Check that leave is for a user inside the hierarchy or advanced permission for all is set
190 if (!$cancreateall) {
191 if (empty($conf->global->MAIN_USE_ADVANCED_PERMS)) {
192 if (empty($user->rights->holiday->write)) {
193 $error++;
194 setEventMessages($langs->trans("NotEnoughPermissions"), null, 'errors');
195 } elseif (!in_array($fuserid, $childids)) {
196 $error++;
197 setEventMessages($langs->trans("UserNotInHierachy"), null, 'errors');
198 $action = 'create';
199 }
200 } else {
201 if (empty($user->rights->holiday->write) && empty($user->rights->holiday->writeall_advance)) {
202 $error++;
203 setEventMessages($langs->trans("NotEnoughPermissions"), null, 'errors');
204 } elseif (empty($user->rights->holiday->writeall_advance) && !in_array($fuserid, $childids)) {
205 $error++;
206 setEventMessages($langs->trans("UserNotInHierachy"), null, 'errors');
207 $action = 'create';
208 }
209 }
210 }
211 // If no groups and no users
212 if (empty($groups) && empty($users)) {
213 setEventMessages($langs->trans("ErrorFieldRequiredUserOrGroup"), null, 'errors');
214 //setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("UserOrGroup")), null, 'errors');
215 //setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Group")), null, 'errors');
216 $error++;
217 $action = 'create';
218 }
219 // If no type
220 if ($type <= 0) {
221 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type")), null, 'errors');
222 $error++;
223 $action = 'create';
224 }
225
226 // If no start date
227 if (empty($date_debut)) {
228 setEventMessages($langs->trans("NoDateDebut"), null, 'errors');
229 $error++;
230 $action = 'create';
231 }
232 // If no end date
233 if (empty($date_fin)) {
234 setEventMessages($langs->trans("NoDateFin"), null, 'errors');
235 $error++;
236 $action = 'create';
237 }
238 // If start date after end date
239 if ($date_debut > $date_fin) {
240 setEventMessages($langs->trans("ErrorEndDateCP"), null, 'errors');
241 $error++;
242 $action = 'create';
243 }
244
245 // If there is no Business Days within request
246 $nbopenedday = num_open_day($date_debut_gmt, $date_fin_gmt, 0, 1, $halfday);
247 if ($nbopenedday < 0.5) {
248 setEventMessages($langs->trans("ErrorDureeCP"), null, 'errors'); // No working day
249 $error++;
250 $action = 'create';
251 }
252
253 // If no validator designated
254 if ($approverid < 1) {
255 setEventMessages($langs->transnoentitiesnoconv('InvalidValidatorCP'), null, 'errors');
256 $error++;
257 }
258
259 $result = 0;
260
261
262 if (!$error) {
263 $TusersToProcess = array();
264 // usergroup select
265 // better perf on single sql
267 $sql = ' SELECT DISTINCT u.rowid,u.lastname,u.firstname from ' . MAIN_DB_PREFIX . 'user as u';
268 $sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'usergroup_user as ug on ug.fk_user = u.rowid ';
269 $sql .= ' WHERE fk_usergroup in (' .$db->sanitize(implode(',', $groups)) . ')';
270 $resql = $db->query($sql);
271
272 if ($resql) {
273 while ($obj = $db->fetch_object($resql)) {
274 $TusersToProcess[$obj->rowid] = $obj->rowid;
275 }
276 }
278 if (is_array($users) && count($users) > 0) {
279 foreach ($users as $u) {
280 $TusersToProcess[$u] = $u;
281 }
282 }
283 foreach ($TusersToProcess as $u) {
284 // Check if there is already holiday for this period pour chaque user
285 $verifCP = $object->verifDateHolidayCP($u, $date_debut, $date_fin, $halfday);
286 if (!$verifCP) {
287 //setEventMessages($langs->trans("alreadyCPexist"), null, 'errors');
288
289 $userError = new User($db);
290 $result = $userError->fetch($u);
291
292 if ($result) {
293 setEventMessages($langs->trans("UseralreadyCPexist", $userError->firstname . ' '. $userError->lastname), null, 'errors');
294 } else {
295 setEventMessages($langs->trans("ErrorUserFetch", $u), null, 'errors');
296 }
297
298 $error++;
299 $action = 'create';
300 }
301 }
302
303 if (!$error) {
304 $db->begin();
305 // non errors we can insert all
306 foreach ($TusersToProcess as $u) {
307 $object = new Holiday($db);
308 $object->fk_user = $u;
309 $object->description = $description;
310 $object->fk_validator = $approverid;
311 $object->fk_type = $type;
312 $object->date_debut = $date_debut;
313 $object->date_fin = $date_fin;
314 $object->halfday = $halfday;
315
316 $result = $object->create($user);
317
318 if ($result <= 0) {
319 setEventMessages($object->error, $object->errors, 'errors');
320 $error++;
321 } else {
322 //@TODO changer le nom si validated
323 if ($autoValidation) {
324 $htemp = new Holiday($db);
325 $htemp->fetch($result);
326
327 $htemp->statut = Holiday::STATUS_VALIDATED;
328 $resultValidated = $htemp->update($approverid);
329
330 if ($resultValidated < 0 ) {
331 setEventMessages($object->error, $object->errors, 'errors');
332 $error++;
333 }
334 // we can auto send mail if we are in auto validation behavior
335
336 if ($AutoSendMail && !$error) {
337 // send a mail to the user
338 $returnSendMail = sendMail($result, $cancreate, $now, $autoValidation);
339 if (!empty($returnSendMail->msg)) setEventMessage($returnSendMail->msg, $returnSendMail->style);
340 }
341 }
342 }
343 }
344 }
345 // If no SQL error we redirect to the request card
346 if (!$error) {
347 $db->commit();
348 header('Location: '.DOL_URL_ROOT.'/holiday/list.php');
349 exit;
350 } else {
351 $db->rollback();
352 }
353 }
354 }
355 }
356}
357
358
359
360/*
361 * View
362 */
363
364$form = new Form($db);
365$object = new Holiday($db);
366
367$listhalfday = array('morning'=>$langs->trans("Morning"), "afternoon"=>$langs->trans("Afternoon"));
368
369$title = $langs->trans('Leave');
370$help_url = 'EN:Module_Holiday';
371
372llxHeader('', $title, $help_url);
373
374if ((empty($id) && empty($ref)) || $action == 'create' || $action == 'add') {
375 // If user has no permission to create a leave
376 if ((in_array($fuserid, $childids) && empty($user->rights->holiday->writeall)) || (!in_array($fuserid, $childids) && (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || empty($user->rights->holiday->writeall_advance)))) {
377 $errors[] = $langs->trans('CantCreateCP');
378 } else {
379 // Form to add a leave request
380 print load_fiche_titre($langs->trans('MenuCollectiveAddCP'), '', 'title_hrm.png');
381
382 // Error management
383 if (GETPOST('error')) {
384 switch (GETPOST('error')) {
385 case 'datefin':
386 $errors[] = $langs->trans('ErrorEndDateCP');
387 break;
388 case 'SQL_Create':
389 $errors[] = $langs->trans('ErrorSQLCreateCP');
390 break;
391 case 'CantCreate':
392 $errors[] = $langs->trans('CantCreateCP');
393 break;
394 case 'Valideur':
395 $errors[] = $langs->trans('InvalidValidatorCP');
396 break;
397 case 'nodatedebut':
398 $errors[] = $langs->trans('NoDateDebut');
399 break;
400 case 'nodatefin':
401 $errors[] = $langs->trans('NoDateFin');
402 break;
403 case 'DureeHoliday':
404 $errors[] = $langs->trans('ErrorDureeCP');
405 break;
406 case 'alreadyCP':
407 $errors[] = $langs->trans('alreadyCPexist');
408 break;
409 }
410
411 setEventMessages($errors, null, 'errors');
412 }
413
414
415 print '<script type="text/javascript">
416 $( document ).ready(function() {
417
418 if( $("input[name=autoValidation]").is(":checked") ){
419 $("#AutoSendMail").prop("disabled", false);
420 $("#AutoSendMail").prop("checked", true);
421
422 } else {
423 $("#AutoSendMail").prop("disabled", true);
424 $("#AutoSendMail").prop("checked", false);
425 }
426
427 $("input[name=autoValidation]").click( function(e) {
428
429
430 if( $("input[name=autoValidation]").is(":checked") ){
431 $("#AutoSendMail").prop("disabled", false);
432 $("#AutoSendMail").prop("checked", true);
433 } else {
434 $("#AutoSendMail").prop("disabled", true);
435 $("#AutoSendMail").prop("checked", false);
436 }
437 });
438
439
440
441 $("input.button-save").click("submit", function(e) {
442 console.log("Call valider()");
443 if (document.demandeCP.date_debut_.value != "")
444 {
445 if(document.demandeCP.date_fin_.value != "")
446 {
447 if(document.demandeCP.valideur.value != "-1") {
448 return true;
449 }
450 else {
451 alert("'.dol_escape_js($langs->transnoentities('InvalidValidatorCP')).'");
452 return false;
453 }
454 }
455 else
456 {
457 alert("'.dol_escape_js($langs->transnoentities('NoDateFin')).'");
458 return false;
459 }
460 }
461 else
462 {
463 alert("'.dol_escape_js($langs->transnoentities('NoDateDebut')).'");
464 return false;
465 }
466 })
467
468 $("#autoValidation").change(function(){
469 if( $("input[name=autoValidation]").is(":checked") ){
470 $("#AutoSendMail").prop("disabled", false);
471 } else {
472 $("#AutoSendMail").prop("disabled", true);
473 $("#AutoSendMail").prop("checked", false);
474 }
475 })
476 });
477 </script>'."\n";
478
479
480 // Formulaire de demande
481 print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'" name="demandeCP">'."\n";
482 print '<input type="hidden" name="token" value="'.newToken().'" />'."\n";
483 print '<input type="hidden" name="action" value="add" />'."\n";
484
485 print dol_get_fiche_head();
486
487 print '<table class="border centpercent">';
488 print '<tbody>';
489
490 // Groups of users
491 print '<tr>';
492 print '<td class="titlefield fieldrequired">';
493 print $form->textwithpicto($langs->trans("groups"), $langs->trans("fusionGroupsUsers"));
494 print '</td>';
495 print '<td>';
496 print img_picto($langs->trans("groups"), 'group', 'class="pictofixedwidth"');
497
498 $sql =' SELECT rowid, nom from '.MAIN_DB_PREFIX.'usergroup WHERE entity IN ('.getEntity('usergroup').')';
499 $resql = $db->query($sql);
500 $Tgroup = array();
501 while ($obj = $db->fetch_object($resql)) {
502 $Tgroup[$obj->rowid] = $obj->nom;
503 }
504
505 print $form->multiselectarray('groups', $Tgroup, GETPOST('groups', 'array'), '', 0, 'quatrevingtpercent widthcentpercentminusx', 0, 0);
506
507 print '</td>';
508
509 // Users
510 print '<tr>';
511 print '<td class="titlefield fieldrequired">';
512 print $form->textwithpicto($langs->trans("users"), $langs->trans("fusionGroupsUsers"));
513 print '<td>';
514 print img_picto($langs->trans("users"), 'user', 'class="pictofixedwidth"');
515
516 $sql = ' SELECT u.rowid, u.lastname, u.firstname from '.MAIN_DB_PREFIX.'user as u';
517 $sql .= ' WHERE 1=1';
518 $sql .= !empty($morefilter) ? $morefilter : '';
519
520 $resql = $db->query($sql);
521 if ($resql) {
522 while ($obj = $db->fetch_object($resql)) {
523 $userlist[$obj->rowid] = dolGetFirstLastname($obj->firstname, $obj->lastname);
524 }
525 }
526
527 print img_picto('', 'users') . $form->multiselectarray('users', $userlist, GETPOST('users', 'array'), '', 0, 'quatrevingtpercent widthcentpercentminusx', 0, 0);
528 print '</td>';
529
530 // Type
531 print '<tr>';
532 print '<td class="fieldrequired">'.$langs->trans("Type").'</td>';
533 print '<td>';
534 $typeleaves = $object->getTypes(1, -1);
535 $arraytypeleaves = array();
536 foreach ($typeleaves as $key => $val) {
537 $labeltoshow = ($langs->trans($val['code']) != $val['code'] ? $langs->trans($val['code']) : $val['label']);
538 $labeltoshow .= ($val['delay'] > 0 ? ' ('.$langs->trans("NoticePeriod").': '.$val['delay'].' '.$langs->trans("days").')' : '');
539 $arraytypeleaves[$val['rowid']] = $labeltoshow;
540 }
541 print $form->selectarray('type', $arraytypeleaves, (GETPOST('type', 'alpha') ?GETPOST('type', 'alpha') : ''), 1, 0, 0, '', 0, 0, 0, '', '', true);
542 if ($user->admin) {
543 print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
544 }
545 print '</td>';
546 print '</tr>';
547
548 // Date start
549 print '<tr>';
550 print '<td class="fieldrequired">';
551 print $form->textwithpicto($langs->trans("DateDebCP"), $langs->trans("FirstDayOfHoliday"));
552 print '</td>';
553 print '<td>';
554 // Si la demande ne vient pas de l'agenda
555 if (!GETPOST('date_debut_')) {
556 print $form->selectDate(-1, 'date_debut_', 0, 0, 0, '', 1, 1);
557 } else {
558 $tmpdate = dol_mktime(0, 0, 0, GETPOST('date_debut_month', 'int'), GETPOST('date_debut_day', 'int'), GETPOST('date_debut_year', 'int'));
559 print $form->selectDate($tmpdate, 'date_debut_', 0, 0, 0, '', 1, 1);
560 }
561 print ' &nbsp; &nbsp; ';
562 print $form->selectarray('starthalfday', $listhalfday, (GETPOST('starthalfday', 'alpha') ?GETPOST('starthalfday', 'alpha') : 'morning'));
563 print '</td>';
564 print '</tr>';
565
566 // Date end
567 print '<tr>';
568 print '<td class="fieldrequired">';
569 print $form->textwithpicto($langs->trans("DateFinCP"), $langs->trans("LastDayOfHoliday"));
570 print '</td>';
571 print '<td>';
572 if (!GETPOST('date_fin_')) {
573 print $form->selectDate(-1, 'date_fin_', 0, 0, 0, '', 1, 1);
574 } else {
575 $tmpdate = dol_mktime(0, 0, 0, GETPOST('date_fin_month', 'int'), GETPOST('date_fin_day', 'int'), GETPOST('date_fin_year', 'int'));
576 print $form->selectDate($tmpdate, 'date_fin_', 0, 0, 0, '', 1, 1);
577 }
578 print ' &nbsp; &nbsp; ';
579 print $form->selectarray('endhalfday', $listhalfday, (GETPOST('endhalfday', 'alpha') ?GETPOST('endhalfday', 'alpha') : 'afternoon'));
580 print '</td>';
581 print '</tr>';
582
583 // Approver
584 print '<tr>';
585 print '<td class="fieldrequired">'.$langs->trans("ReviewedByCP").'</td>';
586 print '<td>';
587
588 $object = new Holiday($db);
589 $include_users = $object->fetch_users_approver_holiday();
590 if (empty($include_users)) {
591 print img_warning().' '.$langs->trans("NobodyHasPermissionToValidateHolidays");
592 } else {
593 // Defined default approver (the forced approved of user or the supervisor if no forced value defined)
594 // Note: This use will be set only if the deinfed approvr has permission to approve so is inside include_users
595 $defaultselectuser = (empty($user->fk_user_holiday_validator) ? $user->fk_user : $user->fk_user_holiday_validator);
596 if (!empty($conf->global->HOLIDAY_DEFAULT_VALIDATOR)) {
597 $defaultselectuser = $conf->global->HOLIDAY_DEFAULT_VALIDATOR; // Can force default approver
598 }
599 if (GETPOST('valideur', 'int') > 0) {
600 $defaultselectuser = GETPOST('valideur', 'int');
601 }
602 $s = $form->select_dolusers($defaultselectuser, "valideur", 1, '', 0, $include_users, '', '0,'.$conf->entity, 0, 0, '', 0, '', 'minwidth200 maxwidth500');
603 print img_picto('', 'user').$form->textwithpicto($s, $langs->trans("AnyOtherInThisListCanValidate"));
604 }
605
606
607 print '</td>';
608 print '</tr>';
609
610 //auto validation ON CREATE
611 print '<tr><td>'.$langs->trans("AutoValidationOnCreate").'</td><td>';
612 print '<input type="checkbox" id="autoValidation" name="autoValidation" value="1"'.($autoValidation ? ' checked="checked"' : '').'>';
613 print '</td></tr>'."\n";
614
615
616 //no auto SEND MAIL
617 print '<tr><td>'.$langs->trans("AutoSendMail").'</td><td>';
618 print '<input type="checkbox" id="AutoSendMail" name="AutoSendMail" value="1"'.($AutoSendMail ? ' checked="checked"' : '').'>';
619 print '</td></tr>'."\n";
620
621 // Description
622 print '<tr>';
623 print '<td>'.$langs->trans("DescCP").'</td>';
624 print '<td class="tdtop">';
625 $doleditor = new DolEditor('description', GETPOST('description', 'restricthtml'), '', 80, 'dolibarr_notes', 'In', 0, false, isModEnabled('fckeditor'), ROWS_3, '90%');
626 print $doleditor->Create(1);
627 print '</td></tr>';
628
629 // Other attributes
630 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php';
631
632 print '</tbody>';
633 print '</table>';
634
635 print dol_get_fiche_end();
636
637 print $form->buttonsSaveCancel("SendRequestCollectiveCP");
638
639 print '</from>'."\n";
640 }
641} else {
642 if ($error) {
643 print '<div class="tabBar">';
644 print $error;
645 print '<br><br><input type="button" value="'.$langs->trans("ReturnCP").'" class="button" onclick="history.go(-1)" />';
646 print '</div>';
647 }
648}
649
650// End of page
651llxFooter();
652
653if (is_object($db)) {
654 $db->close();
655}
667function sendMail($id, $cancreate, $now, $autoValidation)
668{
669 $objStd = new stdClass();
670 $objStd->msg = '';
671 $objStd->status = 'success';
672 $objStd->error = 0;
673 $objStd->style = '';
674
675 global $db, $user, $conf, $langs;
676
677 $object = new Holiday($db);
678
679 $result = $object->fetch($id);
680
681 if ($result) {
682 // If draft and owner of leave
683 if ($object->statut == Holiday::STATUS_VALIDATED && $cancreate) {
684 $object->oldcopy = dol_clone($object);
685
686 //if ($autoValidation) $object->statut = Holiday::STATUS_VALIDATED;
687
688 $verif = $object->validate($user);
689
690 if ($verif > 0) {
691 // To
692 $destinataire = new User($db);
693 $destinataire->fetch($object->fk_validator);
694 $emailTo = $destinataire->email;
695
696
697 if (!$emailTo) {
698 dol_syslog("Expected validator has no email, so we redirect directly to finished page without sending email");
699
700 $objStd->error++;
701 $objStd->msg = $langs->trans('ErroremailTo');
702 $objStd->status = 'error';
703 $objStd->style="warnings";
704 return $objStd;
705 }
706
707 // From
708 $expediteur = new User($db);
709 $expediteur->fetch($object->fk_user);
710 //$emailFrom = $expediteur->email; Email of user can be an email into another company. Sending will fails, we must use the generic email.
711 $emailFrom = $conf->global->MAIN_MAIL_EMAIL_FROM;
712
713 // Subject
714 $societeName = $conf->global->MAIN_INFO_SOCIETE_NOM;
715 if (!empty($conf->global->MAIN_APPLICATION_TITLE)) {
716 $societeName = $conf->global->MAIN_APPLICATION_TITLE;
717 }
718
719 $subject = $societeName." - ".$langs->transnoentitiesnoconv("HolidaysToValidate");
720
721 // Content
722 $message = "<p>".$langs->transnoentitiesnoconv("Hello")." ".$destinataire->firstname.",</p>\n";
723
724 $message .= "<p>".$langs->transnoentities("HolidaysToValidateBody")."</p>\n";
725
726
727 // option to warn the validator in case of too short delay
728 if (empty($conf->global->HOLIDAY_HIDE_APPROVER_ABOUT_TOO_LOW_DELAY)) {
729 $delayForRequest = 0; // TODO Set delay depending of holiday leave type
730 if ($delayForRequest) {
731 $nowplusdelay = dol_time_plus_duree($now, $delayForRequest, 'd');
732
733 if ($object->date_debut < $nowplusdelay) {
734 $message = "<p>".$langs->transnoentities("HolidaysToValidateDelay", $delayForRequest)."</p>\n";
735 }
736 }
737 }
738
739 // option to notify the validator if the balance is less than the request
740 if (empty($conf->global->HOLIDAY_HIDE_APPROVER_ABOUT_NEGATIVE_BALANCE)) {
741 $nbopenedday = num_open_day($object->date_debut_gmt, $object->date_fin_gmt, 0, 1, $object->halfday);
742
743 if ($nbopenedday > $object->getCPforUser($object->fk_user, $object->fk_type)) {
744 $message .= "<p>".$langs->transnoentities("HolidaysToValidateAlertSolde")."</p>\n";
745 }
746 }
747
748 $link = dol_buildpath("/holiday/card.php", 3) . '?id='.$object->id;
749
750 $message .= "<ul>";
751 $message .= "<li>".$langs->transnoentitiesnoconv("Name")." : ".dolGetFirstLastname($expediteur->firstname, $expediteur->lastname)."</li>\n";
752 $message .= "<li>".$langs->transnoentitiesnoconv("Period")." : ".dol_print_date($object->date_debut, 'day')." ".$langs->transnoentitiesnoconv("To")." ".dol_print_date($object->date_fin, 'day')."</li>\n";
753 $message .= "<li>".$langs->transnoentitiesnoconv("Link").' : <a href="'.$link.'" target="_blank">'.$link."</a></li>\n";
754 $message .= "</ul>\n";
755
756 $trackid = 'leav'.$object->id;
757
758 $mail = new CMailFile($subject, $emailTo, $emailFrom, $message, array(), array(), array(), '', '', 0, 1, '', '', $trackid);
759
760 // Sending the email
761 $result = $mail->sendfile();
762
763 if (!$result) {
764 $objStd->error++;
765 $objStd->msg = $langs->trans('ErroreSendmail');
766 $objStd->style="warnings";
767 $objStd->status = 'error';
768 } else {
769 $objStd->msg = $langs->trans('mailSended');
770 }
771
772 return $objStd;
773 } else {
774 $objStd->error++;
775 $objStd->msg = $langs->trans('ErroreVerif');
776 $objStd->status = 'error';
777 $objStd->style="errors";
778 return $objStd;
779 }
780 }
781 } else {
782 $objStd->error++;
783 $objStd->msg = $langs->trans('ErrorloadUserOnSendingMail');
784 $objStd->status = 'error';
785 $objStd->style="warnings";
786 return $objStd;
787 }
788
789 return $objStd;
790}
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Definition wrapper.php:56
llxFooter()
Empty footer.
Definition wrapper.php:70
Class to send emails (with attachments or not) Usage: $mailfile = new CMailFile($subject,...
Class to manage a WYSIWYG editor.
Class to manage standard extra fields.
Class to manage generation of HTML components Only common components must be here.
Class of the module paid holiday.
const STATUS_VALIDATED
Validated status.
const STATUS_DRAFT
Draft status.
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.
Definition date.lib.php:122
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
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_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_escape_js($stringtoescape, $mode=0, $noescapebackslashn=0)
Returns text escaped for inclusion into javascript code.
dol_clone($object, $native=0)
Create a clone of instance of object (new instance with same value for each properties) With native =...
dolGetFirstLastname($firstname, $lastname, $nameorder=-1)
Return firstname and lastname in correct order.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='')
Show information for admin users or standard users.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_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.