dolibarr 22.0.5
card.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2011 Dimitri Mouillard <dmouillard@teclib.com>
3 * Copyright (C) 2012-2016 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2012-2016 Regis Houssin <regis.houssin@inodbox.com>
5 * Copyright (C) 2013 Juanjo Menent <jmenent@2byte.es>
6 * Copyright (C) 2017-2024 Alexandre Spangaro <alexandre@inovea-conseil.com>
7 * Copyright (C) 2014-2017 Ferran Marcet <fmarcet@2byte.es>
8 * Copyright (C) 2018-2024 Frédéric France <frederic.france@free.fr>
9 * Copyright (C) 2020-2021 Udo Tamm <dev@dolibit.de>
10 * Copyright (C) 2022 Anthony Berton <anthony.berton@bb2a.fr>
11 * Copyright (C) 2024 Charlene Benke <charlene@patas-monkey.com>
12 * Copyright (C) 2025 MDW <mdeweerd@users.noreply.github.com>
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 3 of the License, orwrite
17 * (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program. If not, see <https://www.gnu.org/licenses/>.
26 */
27
34// Load Dolibarr environment
35require '../main.inc.php';
36require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
37require_once DOL_DOCUMENT_ROOT.'/user/class/usergroup.class.php';
38require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
39require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
40require_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
41require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
42require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
43require_once DOL_DOCUMENT_ROOT.'/core/lib/holiday.lib.php';
44require_once DOL_DOCUMENT_ROOT.'/holiday/class/holiday.class.php';
45require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
46
55// Get parameters
56$action = GETPOST('action', 'aZ09');
57$cancel = GETPOST('cancel', 'alpha');
58$confirm = GETPOST('confirm', 'alpha');
59$backtopage = GETPOST('backtopage', 'alpha');
60$backtopageforcancel = GETPOST('backtopageforcancel', 'alpha');
61
62$id = GETPOSTINT('id');
63$ref = GETPOST('ref', 'alpha');
64$fuserid = (GETPOSTINT('fuserid') ? GETPOSTINT('fuserid') : ($action == 'create' ? $user->id : 0));
65$socid = GETPOSTINT('socid');
66
67// Load translation files required by the page
68$langs->loadLangs(array("other", "holiday", "mails", "trips"));
69
70$error = 0;
71$errors = [];
72
73$now = dol_now();
74
75$childids = $user->getAllChildIds(1);
76
77$morefilter = '';
78if (getDolGlobalString('HOLIDAY_HIDE_FOR_NON_SALARIES')) {
79 $morefilter = 'AND employee = 1';
80}
81
82$object = new Holiday($db);
83
84$extrafields = new ExtraFields($db);
85
86// fetch optionals attributes and labels
87$extrafields->fetch_name_optionals_label($object->table_element);
88
89// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
90$hookmanager->initHooks(array('holidaycard', 'globalcard'));
91
92$permissiontoapprove = $user->hasRight('holiday', 'approve');
93
94$canread = 0;
95if (($id > 0) || $ref) {
96 $object->fetch($id, $ref);
97 if ($object->id > 0) {
98 $fuserid = $object->fk_user; // On an existing leave request, permissions are checked on its owner, never on the fuserid parameter
99 }
100
101 // Check current user can read this leave request
102 if ($user->hasRight('holiday', 'readall')) {
103 $canread = 1;
104 }
105 if ($user->hasRight('holiday', 'read') && in_array($object->fk_user, $childids)) {
106 $canread = 1;
107 }
108 if ($permissiontoapprove && $object->fk_validator == $user->id && !getDolGlobalString('HOLIDAY_CAN_APPROVE_ONLY_THE_SUBORDINATES')) { // TODO HOLIDAY_CAN_APPROVE_ONLY_THE_SUBORDINATES not completely implemented
109 $canread = 1;
110 }
111 if (!$canread) {
113 }
114 if ($fuserid == 0) {
115 $fuserid = $object->fk_user; // If $fuserid is not defined, set it to the owner of the leave request
116 }
117}
118
119$permissiontoadd = 0;
120$permissiontoaddall = 0;
121if ($user->hasRight('holiday', 'write') && in_array($fuserid, $childids)) {
122 $permissiontoadd = 1;
123}
124if ($user->hasRight('holiday', 'writeall')) {
125 $permissiontoadd = 1;
126 $permissiontoaddall = 1;
127}
128$permissiontoeditextra = $permissiontoadd;
129if (GETPOST('attribute', 'aZ09') && isset($extrafields->attributes[$object->table_element]['perms'][GETPOST('attribute', 'aZ09')])) {
130 // For action 'update_extras', is there a specific permission set for the attribute to update
131 $permissiontoeditextra = dol_eval((string) $extrafields->attributes[$object->table_element]['perms'][GETPOST('attribute', 'aZ09')]);
132}
133
134$candelete = 0;
135if ($user->hasRight('holiday', 'delete')) {
136 $candelete = 1;
137}
138if (($object->status == Holiday::STATUS_DRAFT || $object->status == Holiday::STATUS_CANCELED || $object->status == Holiday::STATUS_REFUSED) && $user->hasRight('holiday', 'write') && in_array($object->fk_user, $childids)) {
139 $candelete = 1;
140}
141
142// Protection if external user
143if ($user->socid) {
144 $socid = $user->socid;
145}
146$result = restrictedArea($user, 'holiday', $object->id, 'holiday', '', '', 'rowid', $object->status);
147
148
149/*
150 * Actions
151 */
152
153$parameters = array('socid' => $socid);
154$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
155if ($reshook < 0) {
156 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
157}
158
159if (empty($reshook)) {
160 $backurlforlist = DOL_URL_ROOT.'/holiday/list.php';
161
162 if (empty($backtopage) || ($cancel && empty($id))) {
163 if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) {
164 if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) {
165 $backtopage = $backurlforlist;
166 } else {
167 $backtopage = DOL_URL_ROOT.'/holiday/card.php?id='.((!empty($id) && $id > 0) ? $id : '__ID__');
168 }
169 }
170 }
171
172 if ($cancel) {
173 if (!empty($backtopageforcancel)) {
174 header("Location: ".$backtopageforcancel);
175 exit;
176 } elseif (!empty($backtopage)) {
177 header("Location: ".$backtopage);
178 exit;
179 }
180 $action = '';
181 }
182
183 // Add leave request
184 if ($action == 'add' && $permissiontoadd) {
185 $object = new Holiday($db);
186
187 $db->begin();
188
189 $date_debut = GETPOSTDATE('date_debut_', '00:00:00');
190 $date_fin = GETPOSTDATE('date_fin_', '00:00:00');
191 $date_debut_gmt = GETPOSTDATE('date_debut_', '00:00:00', 1);
192 $date_fin_gmt = GETPOSTDATE('date_fin_', '00:00:00', 1);
193 $starthalfday = GETPOST('starthalfday');
194 $endhalfday = GETPOST('endhalfday');
195 $type = GETPOST('type');
196 $halfday = 0;
197 if ($starthalfday == 'afternoon' && $endhalfday == 'morning') {
198 $halfday = 2;
199 } elseif ($starthalfday == 'afternoon') {
200 $halfday = -1;
201 } elseif ($endhalfday == 'morning') {
202 $halfday = 1;
203 }
204
205 $approverid = GETPOSTINT('valideur');
206 $description = trim(GETPOST('description', 'restricthtml'));
207
208 // Check that leave is for a user inside the hierarchy or advanced permission for all is set
209 if (!$permissiontoaddall) {
210 if (!getDolGlobalString('MAIN_USE_ADVANCED_PERMS')) {
211 if (!$user->hasRight('holiday', 'write')) {
212 $error++;
213 setEventMessages($langs->trans("NotEnoughPermissions"), null, 'errors');
214 } elseif (!in_array($fuserid, $childids)) {
215 $error++;
216 setEventMessages($langs->trans("UserNotInHierachy"), null, 'errors');
217 $action = 'create';
218 }
219 } else {
220 if (!$user->hasRight('holiday', 'write') && !$user->hasRight('holiday', 'writeall_advance')) {
221 $error++;
222 setEventMessages($langs->trans("NotEnoughPermissions"), null, 'errors');
223 } elseif (!$user->hasRight('holiday', 'writeall_advance') && !in_array($fuserid, $childids)) {
224 $error++;
225 setEventMessages($langs->trans("UserNotInHierachy"), null, 'errors');
226 $action = 'create';
227 }
228 }
229 }
230
231 // If no type
232 if ($type <= 0) {
233 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type")), null, 'errors');
234 $error++;
235 $action = 'create';
236 }
237
238 // If no start date
239 if (empty($date_debut)) {
240 setEventMessages($langs->trans("NoDateDebut"), null, 'errors');
241 $error++;
242 $action = 'create';
243 }
244 // If no end date
245 if (empty($date_fin)) {
246 setEventMessages($langs->trans("NoDateFin"), null, 'errors');
247 $error++;
248 $action = 'create';
249 }
250 // If start date after end date
251 if ($date_debut > $date_fin) {
252 setEventMessages($langs->trans("ErrorEndDateCP"), null, 'errors');
253 $error++;
254 $action = 'create';
255 }
256
257 // Check if there is already holiday for this period
258 $verifCP = $object->verifDateHolidayCP($fuserid, $date_debut, $date_fin, $halfday);
259 if (!$verifCP) {
260 setEventMessages($langs->trans("alreadyCPexist"), null, 'errors');
261 $error++;
262 $action = 'create';
263 }
264
265 // If there is no Business Days within request
266 $nbopenedday = num_open_day($date_debut_gmt, $date_fin_gmt, 0, 1, $halfday);
267 if ($nbopenedday < 0.5) {
268 setEventMessages($langs->trans("ErrorDureeCP"), null, 'errors'); // No working day
269 $error++;
270 $action = 'create';
271 }
272
273 // If no validator designated
274 if ($approverid < 1) {
275 setEventMessages($langs->transnoentitiesnoconv('InvalidValidatorCP'), null, 'errors');
276 $error++;
277 }
278
279 $approverslist = $object->fetch_users_approver_holiday();
280 if (!in_array($approverid, $approverslist)) {
281 setEventMessages($langs->transnoentitiesnoconv('InvalidValidator'), null, 'errors');
282 $error++;
283 }
284
285 // Fill array 'array_options' with data from add form
286 $ret = $extrafields->setOptionalsFromPost(null, $object);
287 if ($ret < 0) {
288 $error++;
289 }
290
291 $result = 0;
292
293 if (!$error) {
294 $object->fk_user = $fuserid;
295 $object->description = $description;
296 $object->fk_validator = $approverid;
297 $object->fk_type = $type;
298 $object->date_debut = $date_debut;
299 $object->date_fin = $date_fin;
300 $object->halfday = $halfday;
301 $object->entity = $conf->entity;
302
303 $result = $object->create($user);
304 if ($result <= 0) {
305 setEventMessages($object->error, $object->errors, 'errors');
306 $error++;
307 }
308 }
309
310 // If no SQL error we redirect to the request card
311 if (!$error) {
312 $db->commit();
313
314 header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
315 exit;
316 } else {
317 $db->rollback();
318 }
319 }
320
321 // If this is an update and we are an approver, we can update to change the expected approver with another one (including himself)
322 if ($action == 'update' && GETPOSTISSET('savevalidator') && $permissiontoapprove) {
323 $object->fetch($id);
324
325 $object->oldcopy = dol_clone($object, 2); // @phan-suppress-current-line PhanTypeMismatchProperty
326
327 $object->fk_validator = GETPOSTINT('valideur');
328
329 if ($object->fk_validator != $object->oldcopy->fk_validator) {
330 $verif = $object->update($user);
331
332 if ($verif <= 0) {
333 setEventMessages($object->error, $object->errors, 'warnings');
334 $action = 'editvalidator';
335 } else {
336 header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
337 exit;
338 }
339 }
340
341 $action = '';
342 }
343
344 if ($action == 'update' && !GETPOSTISSET('savevalidator')) { // Test on permission done later
345 $date_debut = GETPOSTDATE('date_debut_', '00:00:00');
346 $date_fin = GETPOSTDATE('date_fin_', '00:00:00');
347 $date_debut_gmt = GETPOSTDATE('date_debut_', '00:00:00', 1);
348 $date_fin_gmt = GETPOSTDATE('date_fin_', '00:00:00', 1);
349 $starthalfday = GETPOST('starthalfday');
350 $endhalfday = GETPOST('endhalfday');
351 $halfday = 0;
352 if ($starthalfday == 'afternoon' && $endhalfday == 'morning') {
353 $halfday = 2;
354 } elseif ($starthalfday == 'afternoon') {
355 $halfday = -1;
356 } elseif ($endhalfday == 'morning') {
357 $halfday = 1;
358 }
359
360 // If no right to modify a request
361 if (!$permissiontoaddall) {
362 if ($permissiontoadd) {
363 if (!in_array($fuserid, $childids)) {
364 setEventMessages($langs->trans("UserNotInHierachy"), null, 'errors');
365 header('Location: '.$_SERVER["PHP_SELF"].'?action=create');
366 exit;
367 }
368 } else {
369 setEventMessages($langs->trans("NotEnoughPermissions"), null, 'errors');
370 header('Location: '.$_SERVER["PHP_SELF"].'?action=create');
371 exit;
372 }
373 }
374
375 $object->fetch($id);
376
377 // If under validation
378 if ($object->status == Holiday::STATUS_DRAFT) {
379 // If this is the requester or has read/write rights
380 if ($permissiontoadd) {
381 $approverid = GETPOSTINT('valideur');
382 // TODO Check this approver user id has the permission for approval
383
384 $description = trim(GETPOST('description', 'restricthtml'));
385
386 // If no end date
387 if (!GETPOST('date_fin_')) {
388 setEventMessages($langs->trans('NoDateFin'), null, 'warnings');
389 $error++;
390 $action = 'edit';
391 }
392
393 // If start date after end date
394 if ($date_debut > $date_fin) {
395 setEventMessages($langs->trans('ErrorEndDateCP'), null, 'warnings');
396 $error++;
397 $action = 'edit';
398 }
399
400 // If no validator designated
401 if ($approverid < 1) {
402 setEventMessages($langs->trans('InvalidValidatorCP'), null, 'warnings');
403 $error++;
404 $action = 'edit';
405 }
406
407 // If there is no Business Days within request
408 $nbopenedday = num_open_day($date_debut_gmt, $date_fin_gmt, 0, 1, $halfday);
409 if ($nbopenedday < 0.5) {
410 setEventMessages($langs->trans('ErrorDureeCP'), null, 'warnings');
411 $error++;
412 $action = 'edit';
413 }
414
415 $db->begin();
416
417 if (!$error) {
418 $object->description = $description;
419 $object->date_debut = $date_debut;
420 $object->date_fin = $date_fin;
421 $object->fk_validator = $approverid;
422 $object->halfday = $halfday;
423
424 // Update
425 $verif = $object->update($user);
426
427 if ($verif <= 0) {
428 setEventMessages($object->error, $object->errors, 'warnings');
429 $error++;
430 $action = 'edit';
431 }
432 }
433
434 if (!$error) {
435 $db->commit();
436
437 header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
438 exit;
439 } else {
440 $db->rollback();
441 }
442 } else {
443 setEventMessages($langs->trans("NotEnoughPermissions"), null, 'errors');
444 $action = '';
445 }
446 } else {
447 setEventMessages($langs->trans("ErrorBadStatus"), null, 'errors');
448 $action = '';
449 }
450 }
451
452 // If delete of request
453 if ($action == 'confirm_delete' && GETPOST('confirm') == 'yes' && $candelete) {
454 $error = 0;
455
456 $db->begin();
457
458 $object->fetch($id);
459
460 // If this is a rough draft, approved, canceled or refused
462 $result = $object->delete($user);
463 } else {
464 $error++;
465 setEventMessages($langs->trans('BadStatusOfObject'), null, 'errors');
466 $action = '';
467 }
468
469 if (!$error) {
470 $db->commit();
471 header('Location: list.php?restore_lastsearch_values=1');
472 exit;
473 } else {
474 $db->rollback();
475 }
476 }
477
478 // Action validate (+ send email for approval to the expected approver)
479 if ($action == 'confirm_send') { // Test on permission done later
480 $object->fetch($id);
481
482 // If draft and owner of leave
483 if ($object->status == Holiday::STATUS_DRAFT && $permissiontoadd) {
484 $object->oldcopy = dol_clone($object, 2); // @phan-suppress-current-line PhanTypeMismatchProperty
485
487
488 $verif = $object->validate($user);
489
490 // If no SQL error, we redirect to the request form
491 if ($verif > 0) {
492 // To
493 $destinataire = new User($db);
494 $destinataire->fetch($object->fk_validator);
495 $emailTo = $destinataire->email;
496
497 if (!$emailTo) {
498 dol_syslog("Expected validator has no email, so we redirect directly to finished page without sending email");
499 header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
500 exit;
501 }
502
503 // From
504 $expediteur = new User($db);
505 $expediteur->fetch($object->fk_user);
506 //$emailFrom = $expediteur->email; Email of user can be an email into another company. Sending will fails, we must use the generic email.
507 $emailFrom = getDolGlobalString('MAIN_MAIL_EMAIL_FROM');
508
509 // Subject
510 $societeName = getDolGlobalString('MAIN_INFO_SOCIETE_NOM');
511 if (getDolGlobalString('MAIN_APPLICATION_TITLE')) {
512 $societeName = getDolGlobalString('MAIN_APPLICATION_TITLE');
513 }
514
515 $subject = $societeName." - ".$langs->transnoentitiesnoconv("HolidaysToValidate");
516
517 // Content
518 $message = "<p>".$langs->transnoentitiesnoconv("Hello")." ".$destinataire->firstname.",</p>\n";
519
520 $message .= "<p>".$langs->transnoentities("HolidaysToValidateBody")."</p>\n";
521
522
523 // option to warn the validator in case of too short delay
524 if (!getDolGlobalString('HOLIDAY_HIDE_APPROVER_ABOUT_TOO_LOW_DELAY')) {
525 $delayForRequest = 0; // TODO Set delay depending of holiday leave type
526 if ($delayForRequest) {
527 $nowplusdelay = dol_time_plus_duree($now, $delayForRequest, 'd');
528
529 if ($object->date_debut < $nowplusdelay) {
530 $message = "<p>".$langs->transnoentities("HolidaysToValidateDelay", $delayForRequest)."</p>\n";
531 }
532 }
533 }
534
535
536 // option to notify the validator if the balance is less than the request
537 // (only for leave types that actually use the balance counter)
538 if (!getDolGlobalString('HOLIDAY_HIDE_APPROVER_ABOUT_NEGATIVE_BALANCE')) {
539 $affectingtypes = $object->getTypes(1, 1);
540 if (!empty($affectingtypes[$object->fk_type])) {
541 $nbopenedday = num_open_day($object->date_debut_gmt, $object->date_fin_gmt, 0, 1, $object->halfday);
542
543 if ($nbopenedday > $object->getCPforUser($object->fk_user, $object->fk_type)) {
544 $message .= "<p>".$langs->transnoentities("HolidaysToValidateAlertSolde")."</p>\n";
545 }
546 }
547 }
548
549 $typeleaves = $object->getTypes(1, -1);
550 if (empty($typeleaves[$object->fk_type])) {
551 $labeltoshow = $langs->trans("TypeWasDisabledOrRemoved", $object->fk_type);
552 } else {
553 $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']);
554 }
555 if ($object->halfday == 2) {
556 $starthalfdaykey = "Afternoon";
557 $endhalfdaykey = "Morning";
558 } elseif ($object->halfday == -1) {
559 $starthalfdaykey = "Afternoon";
560 $endhalfdaykey = "Afternoon";
561 } elseif ($object->halfday == 1) {
562 $starthalfdaykey = "Morning";
563 $endhalfdaykey = "Morning";
564 } elseif ($object->halfday == 0 || $object->halfday == 2) {
565 $starthalfdaykey = "Morning";
566 $endhalfdaykey = "Afternoon";
567 } else {
568 $starthalfdaykey = "";
569 $endhalfdaykey = "";
570 }
571
572 $link = dol_buildpath("/holiday/card.php", 3) . '?id='.$object->id;
573
574 $message .= "<ul>";
575 $message .= "<li>".$langs->transnoentitiesnoconv("Name")." : ".dolGetFirstLastname($expediteur->firstname, $expediteur->lastname)."</li>\n";
576 $message .= "<li>".$langs->transnoentitiesnoconv("Type")." : ".(empty($labeltoshow) ? $langs->trans("TypeWasDisabledOrRemoved", $object->fk_type) : $labeltoshow)."</li>\n";
577 $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";
578 $message .= "<li>".$langs->transnoentitiesnoconv("Link").' : <a href="'.$link.'" target="_blank">'.$link."</a></li>\n";
579 $message .= "</ul>\n";
580
581 $trackid = 'leav'.$object->id;
582
583 $sendtobcc = getDolGlobalString('MAIN_MAIL_AUTOCOPY_HOLIDAY_TO');
584
585 $mail = new CMailFile($subject, $emailTo, $emailFrom, $message, array(), array(), array(), '', $sendtobcc, 0, 1, '', '', $trackid);
586
587 // Sending the email
588 $result = $mail->sendfile();
589
590 if (!$result) {
591 setEventMessages($mail->error, $mail->errors, 'warnings');
592 $action = '';
593 } else {
594 header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
595 exit;
596 }
597 } else {
598 setEventMessages($object->error, $object->errors, 'errors');
599 $action = '';
600 }
601 }
602 }
603
604 if ($action == 'update_extras' && $permissiontoeditextra) {
605 $object->oldcopy = dol_clone($object, 2); // @phan-suppress-current-line PhanTypeMismatchProperty
606
607 $attribute_name = GETPOST('attribute', 'aZ09');
608
609 // Fill array 'array_options' with data from update form
610 $ret = $extrafields->setOptionalsFromPost(null, $object, $attribute_name);
611 if ($ret < 0) {
612 $error++;
613 }
614
615 if (!$error) {
616 $result = $object->updateExtraField($attribute_name, 'HOLIDAY_MODIFY');
617 if ($result < 0) {
618 setEventMessages($object->error, $object->errors, 'errors');
619 $error++;
620 }
621 }
622
623 if ($error) {
624 $action = 'edit_extras';
625 }
626 }
627
628 // Approve leave request
629 if ($action == 'confirm_valid' && $permissiontoapprove) { // Test on permission done later
630 $object->fetch($id);
631
632 // If status is waiting approval and approver is also user
633 if ($object->status == Holiday::STATUS_VALIDATED && ($user->id == $object->fk_validator || $permissiontoaddall)) {
634 $object->oldcopy = dol_clone($object, 2); // @phan-suppress-current-line PhanTypeMismatchProperty
635
636 $object->date_approval = dol_now();
637 $object->fk_user_approve = $user->id;
640
641 $decrease = getDolGlobalInt('HOLIDAY_DECREASE_AT_END_OF_MONTH');
642
643 $db->begin();
644
645 $verif = $object->approve($user);
646 if ($verif <= 0) {
647 setEventMessages($object->error, $object->errors, 'errors');
648 $error++;
649 }
650
651 // If no SQL error, we redirect to the request form
652 if (!$error && empty($decrease)) {
653 // Calculate number of days consumed
654 $nbopenedday = num_open_day($object->date_debut_gmt, $object->date_fin_gmt, 0, 1, $object->halfday);
655 $soldeActuel = $object->getCpforUser($object->fk_user, $object->fk_type);
656 $newSolde = ($soldeActuel - $nbopenedday);
657 $label = $object->ref.' - '.$langs->transnoentitiesnoconv("HolidayConsumption");
658
659 // The modification is added to the LOG
660 $result = $object->addLogCP($user->id, $object->fk_user, $label, $newSolde, $object->fk_type);
661 if ($result < 0) {
662 $error++;
663 setEventMessages(null, $object->errors, 'errors');
664 }
665
666 // Update balance
667 $result = $object->updateSoldeCP($object->fk_user, $newSolde, $object->fk_type);
668 if ($result < 0) {
669 $error++;
670 setEventMessages(null, $object->errors, 'errors');
671 }
672 }
673
674 if (!$error) {
675 // To
676 $destinataire = new User($db);
677 $destinataire->fetch($object->fk_user);
678 $emailTo = $destinataire->email;
679
680 if (!$emailTo) {
681 dol_syslog("User that request leave has no email, so we redirect directly to finished page without sending email");
682 } else {
683 // From
684 $expediteur = new User($db);
685 $expediteur->fetch($object->fk_validator);
686 //$emailFrom = $expediteur->email; Email of user can be an email into another company. Sending will fails, we must use the generic email.
687 $emailFrom = getDolGlobalString('MAIN_MAIL_EMAIL_FROM');
688
689 // Subject
690 $societeName = getDolGlobalString('MAIN_INFO_SOCIETE_NOM');
691 if (getDolGlobalString('MAIN_APPLICATION_TITLE')) {
692 $societeName = getDolGlobalString('MAIN_APPLICATION_TITLE');
693 }
694
695 $subject = '['.$societeName."] ".$langs->transnoentitiesnoconv("HolidaysValidated");
696
697 // Content
698 $message = "<p>".$langs->transnoentitiesnoconv("Hello")." ".$destinataire->firstname.",</p>\n";
699
700 $message .= "<p>".$langs->transnoentities("HolidaysValidatedBody", dol_print_date($object->date_debut, 'day'), dol_print_date($object->date_fin, 'day'))."</p>\n";
701
702 $link = dol_buildpath('/holiday/card.php', 3).'?id='.$object->id;
703
704 $message .= "<ul>\n";
705 $message .= "<li>".$langs->transnoentitiesnoconv("ValidatedBy")." : ".dolGetFirstLastname($expediteur->firstname, $expediteur->lastname)."</li>\n";
706 $message .= "<li>".$langs->transnoentitiesnoconv("Link").' : <a href="'.$link.'" target="_blank">'.$link."</a></li>\n";
707 $message .= "</ul>\n";
708
709 $trackid = 'leav'.$object->id;
710
711 $sendtobcc = getDolGlobalString('MAIN_MAIL_AUTOCOPY_HOLIDAY_TO');
712
713 $mail = new CMailFile($subject, $emailTo, $emailFrom, $message, array(), array(), array(), '', $sendtobcc, 0, 1, '', '', $trackid);
714
715 // Sending email
716 $result = $mail->sendfile();
717
718 if (!$result) {
719 setEventMessages($mail->error, $mail->errors, 'warnings'); // Show error, but do no make rollback, so $error is not set to 1
720 $action = '';
721 }
722 }
723 }
724
725 if (!$error) {
726 $db->commit();
727 } else {
728 $db->rollback();
729 $action = '';
730 }
731
732 header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
733 exit;
734 }
735 }
736
737 if ($action == 'confirm_refuse' && GETPOST('confirm', 'alpha') == 'yes' && $permissiontoapprove) { // Test on permission done later
738 if (GETPOST('detail_refuse')) {
739 $object->fetch($id);
740
741 // If status pending validation and validator = user
742 if ($object->status == Holiday::STATUS_VALIDATED && ($user->id == $object->fk_validator || $permissiontoaddall)) {
743 $object->date_refuse = dol_now();
744 $object->fk_user_refuse = $user->id;
747 $object->detail_refuse = GETPOST('detail_refuse', 'alphanohtml');
748
749 $db->begin();
750
751 $verif = $object->update($user);
752 if ($verif <= 0) {
753 $error++;
754 setEventMessages($object->error, $object->errors, 'errors');
755 }
756
757 // If no SQL error, we redirect to the request form
758 if (!$error) {
759 // To
760 $destinataire = new User($db);
761 $destinataire->fetch($object->fk_user);
762 $emailTo = $destinataire->email;
763
764 if (!$emailTo) {
765 dol_syslog("User that request leave has no email, so we redirect directly to finished page without sending email");
766 } else {
767 // From
768 $expediteur = new User($db);
769 $expediteur->fetch($object->fk_validator);
770 //$emailFrom = $expediteur->email; Email of user can be an email into another company. Sending will fails, we must use the generic email.
771 $emailFrom = getDolGlobalString('MAIN_MAIL_EMAIL_FROM');
772
773 // Subject
774 $societeName = getDolGlobalString('MAIN_INFO_SOCIETE_NOM');
775 if (getDolGlobalString('MAIN_APPLICATION_TITLE')) {
776 $societeName = getDolGlobalString('MAIN_APPLICATION_TITLE');
777 }
778
779 $subject = $societeName." - ".$langs->transnoentitiesnoconv("HolidaysRefused");
780
781 // Content
782 $message = "<p>".$langs->transnoentitiesnoconv("Hello")." ".$destinataire->firstname.",</p>\n";
783
784 $message .= "<p>".$langs->transnoentities("HolidaysRefusedBody", dol_print_date($object->date_debut, 'day'), dol_print_date($object->date_fin, 'day'))."<p>\n";
785 $message .= "<p>".GETPOST('detail_refuse', 'alpha')."</p>";
786
787 $link = dol_buildpath('/holiday/card.php', 3).'?id='.$object->id;
788
789 $message .= "<ul>\n";
790 $message .= "<li>".$langs->transnoentitiesnoconv("ModifiedBy")." : ".dolGetFirstLastname($expediteur->firstname, $expediteur->lastname)."</li>\n";
791 $message .= "<li>".$langs->transnoentitiesnoconv("Link").' : <a href="'.$link.'" target="_blank">'.$link."</a></li>\n";
792 $message .= "</ul>";
793
794 $trackid = 'leav'.$object->id;
795
796 $sendtobcc = getDolGlobalString('MAIN_MAIL_AUTOCOPY_HOLIDAY_TO');
797
798 $mail = new CMailFile($subject, $emailTo, $emailFrom, $message, array(), array(), array(), '', $sendtobcc, 0, 1, '', '', $trackid);
799
800 // sending email
801 $result = $mail->sendfile();
802
803 if (!$result) {
804 setEventMessages($mail->error, $mail->errors, 'warnings'); // Show error, but do no make rollback, so $error is not set to 1
805 $action = '';
806 }
807 }
808 } else {
809 $action = '';
810 }
811
812 if (!$error) {
813 $db->commit();
814
815 header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
816 exit;
817 } else {
818 $db->rollback();
819 $action = '';
820 }
821 }
822 } else {
823 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("DetailRefusCP")), null, 'errors');
824 $action = 'refuse';
825 }
826 }
827
828
829 // If the request is validated
830 if ($action == 'confirm_draft' && GETPOST('confirm') == 'yes' && $permissiontoadd) { // Test on permission done later
831 $error = 0;
832
833 $object->fetch($id);
834
835 // Same rules as the SetToDraft button: user allowed to edit the leave request of its owner, and canceled leave request only
836 if (!$user->hasRight('holiday', 'writeall') && !($user->hasRight('holiday', 'write') && in_array($object->fk_user, $childids))) {
838 }
839 if ($object->status != Holiday::STATUS_CANCELED) {
840 $error++;
841 setEventMessages($langs->trans('StatusOfRefMustBe', $object->ref, $langs->transnoentitiesnoconv('Canceled')), null, 'errors');
842 }
843
844 if (!$error) {
845 $oldstatus = $object->status;
848
849 $result = $object->update($user);
850 if ($result < 0) {
851 $error++;
852 setEventMessages($langs->trans('ErrorBackToDraft').' '.$object->error, $object->errors, 'errors');
853 }
854 }
855
856 if (!$error) {
857 $db->commit();
858
859 header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
860 exit;
861 } else {
862 $db->rollback();
863 }
864 }
865
866 // An approved leave request that is already over can be canceled only by an approver (same rule as the Cancel button)
867 if ($action == 'confirm_cancel' && $object->status == Holiday::STATUS_APPROVED && $object->date_fin <= dol_now() && empty($user->admin) && $user->id != $object->fk_user_approve && !$user->hasRight('holiday', 'approve')) {
868 setEventMessages($langs->trans("HolidayStarted").' - '.$langs->trans("NotAllowed"), null, 'errors');
869 $action = '';
870 }
871
872 // If confirmation of cancellation
873 if ($action == 'confirm_cancel' && GETPOST('confirm') == 'yes') { // Test on permission done later
874 $error = 0;
875
876 $object->fetch($id);
877
878 // If status pending validation and validator = validator or user, or rights to do for others
879 if (($object->status == Holiday::STATUS_VALIDATED || $object->status == Holiday::STATUS_APPROVED) &&
880 ($user->id == $object->fk_validator || $permissiontoadd || $permissiontoaddall || $permissiontoapprove)) {
881 $db->begin();
882
883 $oldstatus = $object->status;
884 $object->date_cancel = dol_now();
885 $object->fk_user_cancel = $user->id;
888
889 $decrease = getDolGlobalInt('HOLIDAY_DECREASE_AT_END_OF_MONTH');
890
891 $result = $object->update($user);
892
893 if ($result >= 0 && $oldstatus == Holiday::STATUS_APPROVED) { // holiday was already validated, status 3, so we must increase back the balance
894 // Call trigger
895 $result = $object->call_trigger('HOLIDAY_CANCEL', $user);
896 if ($result < 0) {
897 $error++;
898 }
899
900 $startDate = $object->date_debut_gmt;
901 $endDate = $object->date_fin_gmt;
902 $alreadydebited = true;
903
904 if (!empty($decrease)) {
905 $lastUpdate = strtotime($object->getConfCP('lastUpdate', dol_print_date(dol_now(), '%Y%m%d%H%M%S')));
906 $date = strtotime('-1 month', $lastUpdate);
907 $endOfMonthBeforeLastUpdate = dol_mktime(0, 0, 0, (int) date('m', $date), (int) date('t', $date), (int) date('Y', $date), 1);
908 if ($object->date_debut_gmt < $endOfMonthBeforeLastUpdate && $object->date_fin_gmt > $endOfMonthBeforeLastUpdate) {
909 $endDate = $endOfMonthBeforeLastUpdate;
910 } elseif ($object->date_debut_gmt > $endOfMonthBeforeLastUpdate) {
911 $alreadydebited = false; // Leave after the last month processed by updateSoldeCP(), so nothing was debited yet
912 }
913 }
914
915 // Calculate number of days consumed
916 $nbopenedday = num_open_day($startDate, $endDate, 0, 1, $object->halfday);
917
918 if (!$alreadydebited) {
919 $nbopenedday = 0;
920 }
921 $soldeActuel = $object->getCpforUser($object->fk_user, $object->fk_type);
922 $newSolde = ($soldeActuel + $nbopenedday);
923
924 // The modification is added to the LOG
925 $result1 = $object->addLogCP($user->id, $object->fk_user, $object->ref.' - '.$langs->transnoentitiesnoconv("HolidayCreditAfterCancellation"), $newSolde, $object->fk_type);
926
927 // Update of the balance
928 $result2 = $object->updateSoldeCP($object->fk_user, $newSolde, $object->fk_type);
929
930 if ($result1 < 0 || $result2 < 0) {
931 $error++;
932 setEventMessages($langs->trans('ErrorCantDeleteCP').' '.$object->error, $object->errors, 'errors');
933 }
934 }
935
936 if (!$error) {
937 $db->commit();
938 } else {
939 $db->rollback();
940 }
941
942 // If no SQL error, we redirect to the request form
943 if (!$error && $result > 0) {
944 // To
945 $destinataire = new User($db);
946 $destinataire->fetch($object->fk_user);
947 $emailTo = $destinataire->email;
948
949 if (!$emailTo) {
950 header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
951 exit;
952 }
953
954 // From
955 $expediteur = new User($db);
956 $expediteur->fetch($object->fk_user_cancel);
957 //$emailFrom = $expediteur->email; Email of user can be an email into another company. Sending will fails, we must use the generic email.
958 $emailFrom = getDolGlobalString('MAIN_MAIL_EMAIL_FROM');
959
960 // Subject
961 $societeName = getDolGlobalString('MAIN_INFO_SOCIETE_NOM');
962 if (getDolGlobalString('MAIN_APPLICATION_TITLE')) {
963 $societeName = getDolGlobalString('MAIN_APPLICATION_TITLE');
964 }
965
966 $subject = $societeName." - ".$langs->transnoentitiesnoconv("HolidaysCanceled");
967
968 // Content
969 $message = "<p>".$langs->transnoentitiesnoconv("Hello")." ".$destinataire->firstname.",</p>\n";
970
971 $message .= "<p>".$langs->transnoentities("HolidaysCanceledBody", dol_print_date($object->date_debut, 'day'), dol_print_date($object->date_fin, 'day'))."</p>\n";
972
973 $link = dol_buildpath('/holiday/card.php', 3).'?id='.$object->id;
974
975 $message .= "<ul>\n";
976 $message .= "<li>".$langs->transnoentitiesnoconv("ModifiedBy")." : ".dolGetFirstLastname($expediteur->firstname, $expediteur->lastname)."</li>\n";
977 $message .= "<li>".$langs->transnoentitiesnoconv("Link").' : <a href="'.$link.'" target="_blank">'.$link."</a></li>\n";
978 $message .= "</ul>\n";
979
980 $trackid = 'leav'.$object->id;
981
982 $sendtobcc = getDolGlobalString('MAIN_MAIL_AUTOCOPY_HOLIDAY_TO');
983
984 $mail = new CMailFile($subject, $emailTo, $emailFrom, $message, array(), array(), array(), '', $sendtobcc, 0, 1, '', '', $trackid);
985
986 // sending email
987 $result = $mail->sendfile();
988
989 if (!$result) {
990 setEventMessages($mail->error, $mail->errors, 'warnings');
991 $action = '';
992 } else {
993 header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
994 exit;
995 }
996 }
997 }
998 }
999
1000 /*
1001 // Actions when printing a doc from card
1002 include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
1003
1004 // Actions to send emails
1005 $triggersendname = 'HOLIDAY_SENTBYMAIL';
1006 $autocopy='MAIN_MAIL_AUTOCOPY_HOLIDAY_TO';
1007 $trackid='leav'.$object->id;
1008 include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
1009
1010 // Actions to build doc
1011 $upload_dir = $conf->holiday->dir_output;
1012 $permissiontoadd = $user->rights->holiday->creer;
1013 include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
1014 */
1015}
1016
1017
1018
1019/*
1020 * View
1021 */
1022
1023$form = new Form($db);
1024$formfile = new FormFile($db);
1025$object = new Holiday($db);
1026
1027$listhalfday = array('morning' => $langs->trans("Morning"), "afternoon" => $langs->trans("Afternoon"));
1028
1029$title = $langs->trans('Leave');
1030$help_url = 'EN:Module_Holiday';
1031
1032llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-holiday page-card');
1033
1034$edit = false;
1035
1036if ((empty($id) && empty($ref)) || $action == 'create' || $action == 'add') {
1037 // If user has no permission to create a leave
1038 if ((in_array($fuserid, $childids) && !$user->hasRight('holiday', 'write')) || (!in_array($fuserid, $childids) && ((getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && !$user->hasRight('holiday', 'writeall_advance') || !$user->hasRight('holiday', 'writeall'))))) {
1039 $errors[] = $langs->trans('CantCreateCP');
1040 } else {
1041 // Form to add a leave request
1042 print load_fiche_titre($langs->trans('MenuAddCP'), '', 'title_hrm.png');
1043
1044 // Error management
1045 if (GETPOST('error')) {
1046 switch (GETPOST('error')) {
1047 case 'datefin':
1048 $errors[] = $langs->trans('ErrorEndDateCP');
1049 break;
1050 case 'SQL_Create':
1051 $errors[] = $langs->trans('ErrorSQLCreateCP');
1052 break;
1053 case 'CantCreate':
1054 $errors[] = $langs->trans('CantCreateCP');
1055 break;
1056 case 'Valideur':
1057 $errors[] = $langs->trans('InvalidValidatorCP');
1058 break;
1059 case 'nodatedebut':
1060 $errors[] = $langs->trans('NoDateDebut');
1061 break;
1062 case 'nodatefin':
1063 $errors[] = $langs->trans('NoDateFin');
1064 break;
1065 case 'DureeHoliday':
1066 $errors[] = $langs->trans('ErrorDureeCP');
1067 break;
1068 case 'alreadyCP':
1069 $errors[] = $langs->trans('alreadyCPexist');
1070 break;
1071 }
1072
1073 setEventMessages(null, $errors, 'errors');
1074 }
1075
1076
1077 print '<script type="text/javascript">
1078 $( document ).ready(function() {
1079 $("input.button-save").click("submit", function(e) {
1080 console.log("Call valider()");
1081 if (document.demandeCP.date_debut_.value != "")
1082 {
1083 if(document.demandeCP.date_fin_.value != "")
1084 {
1085 if(document.demandeCP.valideur.value != "-1") {
1086 return true;
1087 }
1088 else {
1089 alert("'.dol_escape_js($langs->transnoentities('InvalidValidatorCP')).'");
1090 return false;
1091 }
1092 }
1093 else
1094 {
1095 alert("'.dol_escape_js($langs->transnoentities('NoDateFin')).'");
1096 return false;
1097 }
1098 }
1099 else
1100 {
1101 alert("'.dol_escape_js($langs->transnoentities('NoDateDebut')).'");
1102 return false;
1103 }
1104 });
1105 });
1106 </script>'."\n";
1107
1108
1109 // Formulaire de demande
1110 print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'" name="demandeCP">'."\n";
1111 print '<input type="hidden" name="token" value="'.newToken().'" />'."\n";
1112 print '<input type="hidden" name="action" value="add" />'."\n";
1113
1114 print dol_get_fiche_head();
1115
1116 //print '<span>'.$langs->trans('DelayToRequestCP',$object->getConfCP('delayForRequest')).'</span><br><br>';
1117
1118 print '<table class="border centpercent">';
1119 print '<tbody>';
1120
1121 // User for leave request
1122 print '<tr>';
1123 print '<td class="titlefield fieldrequired tdtop">'.$langs->trans("User").'</td>';
1124 print '<td><div class="inline-block">';
1125 if ($permissiontoadd && !$permissiontoaddall) {
1126 print img_picto('', 'user', 'class="pictofixedwidth"').$form->select_dolusers(($fuserid ? $fuserid : $user->id), 'fuserid', 0, null, 0, 'hierarchyme', '', '0,'.$conf->entity, 0, 0, $morefilter, 0, '', 'minwidth200 maxwidth500 inline-block');
1127 //print '<input type="hidden" name="fuserid" value="'.($fuserid?$fuserid:$user->id).'">';
1128 } else {
1129 print img_picto('', 'user', 'class="pictofixedwidth"').$form->select_dolusers($fuserid ? $fuserid : $user->id, 'fuserid', 0, null, 0, '', '', '0,'.$conf->entity, 0, 0, $morefilter, 0, '', 'minwidth200 maxwidth500 inline-block');
1130 }
1131 print '</div>';
1132
1133 if (!getDolGlobalString('HOLIDAY_HIDE_BALANCE')) {
1134 print '<div class="leaveuserbalance paddingtop inline-block floatright badge badge-status0 badge-status margintoponsmartphone">';
1135
1136 $out = '';
1137 $nb_holiday = 0;
1138 $typeleaves = $object->getTypes(1, 1);
1139 foreach ($typeleaves as $key => $val) {
1140 $nb_type = $object->getCPforUser(($fuserid ? $fuserid : $user->id), $val['rowid']);
1141 $nb_holiday += $nb_type;
1142
1143 $out .= ' - '.($langs->trans($val['code']) != $val['code'] ? $langs->trans($val['code']) : $val['label']).': <strong>'.($nb_type ? price2num($nb_type) : 0).'</strong><br>';
1144 //$out .= ' - '.$val['label'].': <strong>'.($nb_type ?price2num($nb_type) : 0).'</strong><br>';
1145 }
1146 print ' &nbsp; &nbsp; ';
1147
1148 $htmltooltip = $langs->trans("Detail").'<br>';
1149 $htmltooltip .= $out;
1150
1151 print $form->textwithtooltip($langs->trans('SoldeCPUser', (string) round($nb_holiday, 5)).' '.img_picto('', 'help'), $htmltooltip);
1152
1153 print '</div>';
1154 if (!empty($conf->use_javascript_ajax)) {
1155 print '<script>';
1156 print '$( document ).ready(function() {
1157 jQuery("#fuserid").change(function() {
1158 console.log("We change to user id "+jQuery("#fuserid").val());
1159 if (jQuery("#fuserid").val() == '.((int) $user->id).') {
1160 jQuery(".leaveuserbalance").show();
1161 } else {
1162 jQuery(".leaveuserbalance").hide();
1163 }
1164 });
1165 });';
1166 print '</script>';
1167 }
1168 } elseif (!is_numeric(getDolGlobalString('HOLIDAY_HIDE_BALANCE'))) {
1169 print '<div class="leaveuserbalance paddingtop">';
1170 print $langs->trans(getDolGlobalString('HOLIDAY_HIDE_BALANCE'));
1171 print '</div>';
1172 }
1173
1174 print '</td>';
1175 print '</tr>';
1176
1177 // Type
1178 print '<tr>';
1179 print '<td class="fieldrequired">'.$langs->trans("Type").'</td>';
1180 print '<td>';
1181 $typeleaves = $object->getTypes(1, -1);
1182 $arraytypeleaves = array();
1183 foreach ($typeleaves as $key => $val) {
1184 $labeltoshow = ($langs->trans($val['code']) != $val['code'] ? $langs->trans($val['code']) : $val['label']);
1185 $labeltoshow .= ($val['delay'] > 0 ? ' ('.$langs->trans("NoticePeriod").': '.$val['delay'].' '.$langs->trans("days").')' : '');
1186 $arraytypeleaves[$val['rowid']] = $labeltoshow;
1187 }
1188 if (empty($typeleaves)) {
1189 print $langs->trans("PleaseDefineSomeTypeOfHolidayFirst");
1190 } else {
1191 print $form->selectarray('type', $arraytypeleaves, (GETPOST('type', 'alpha') ? GETPOST('type', 'alpha') : ''), 1, 0, 0, '', 0, 0, 0, '', '', 1);
1192 if ($user->admin) {
1193 print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
1194 }
1195 }
1196 print '</td>';
1197 print '</tr>';
1198
1199 // Date start
1200 print '<tr>';
1201 print '<td class="fieldrequired">';
1202 print $form->textwithpicto($langs->trans("DateDebCP"), $langs->trans("FirstDayOfHoliday"));
1203 print '</td>';
1204 print '<td>'.img_picto('', 'action', 'class="pictofixedwidth"');
1205 if (!GETPOST('date_debut_')) { // If visitor does not come from agenda
1206 print $form->selectDate(-1, 'date_debut_', 0, 0, 0, '', 1, 1);
1207 } else {
1208 $tmpdate = GETPOSTDATE('date_debut_', '00:00:00');
1209 print $form->selectDate($tmpdate, 'date_debut_', 0, 0, 0, '', 1, 1);
1210 }
1211 print ' &nbsp; &nbsp; ';
1212 print $form->selectarray('starthalfday', $listhalfday, (GETPOST('starthalfday', 'alpha') ? GETPOST('starthalfday', 'alpha') : 'morning'));
1213 print '</td>';
1214 print '</tr>';
1215
1216 // Date end
1217 print '<tr>';
1218 print '<td class="fieldrequired">';
1219 print $form->textwithpicto($langs->trans("DateFinCP"), $langs->trans("LastDayOfHoliday"));
1220 print '</td>';
1221 print '<td>'.img_picto('', 'action', 'class="pictofixedwidth"');
1222 if (!GETPOST('date_fin_')) {
1223 print $form->selectDate(-1, 'date_fin_', 0, 0, 0, '', 1, 1);
1224 } else {
1225 $tmpdate = GETPOSTDATE('date_fin_', '00:00:00');
1226 print $form->selectDate($tmpdate, 'date_fin_', 0, 0, 0, '', 1, 1);
1227 }
1228 print ' &nbsp; &nbsp; ';
1229 print $form->selectarray('endhalfday', $listhalfday, (GETPOST('endhalfday', 'alpha') ? GETPOST('endhalfday', 'alpha') : 'afternoon'));
1230 print '</td>';
1231 print '</tr>';
1232
1233 // Approver
1234 print '<tr>';
1235 print '<td class="fieldrequired">'.$langs->trans("ReviewedByCP").'</td>';
1236 print '<td>';
1237
1238 $object = new Holiday($db);
1239 $include_users = $object->fetch_users_approver_holiday();
1240 if (empty($include_users)) {
1241 print img_warning().' '.$langs->trans("NobodyHasPermissionToValidateHolidays");
1242 } else {
1243 // Defined default approver (the forced approver of edited user or the supervisor of user if no forced value defined)
1244 // Note: This user will be set only if the defined approver has permission to approve so is inside include_users
1245 $defaultselectuser = (empty($user->fk_user_holiday_validator) ? $user->fk_user : $user->fk_user_holiday_validator);
1246 if ($fuserid != $user->id) {
1247 $fuser = new User($db);
1248 $fuser->fetch($fuserid);
1249 $defaultselectuser = (empty($fuser->fk_user_holiday_validator) ? $fuser->fk_user : $fuser->fk_user_holiday_validator);
1250 }
1251
1252 if (getDolGlobalString('HOLIDAY_DEFAULT_VALIDATOR')) {
1253 $defaultselectuser = getDolGlobalString('HOLIDAY_DEFAULT_VALIDATOR'); // Can force default approver
1254 }
1255 if (GETPOSTINT('valideur') > 0) {
1256 $defaultselectuser = GETPOSTINT('valideur');
1257 }
1258 $s = $form->select_dolusers($defaultselectuser, "valideur", 1, null, 0, $include_users, '', '0,'.$conf->entity, 0, 0, '', 0, '', 'minwidth200 maxwidth500');
1259 print img_picto('', 'user', 'class="pictofixedwidth"').$form->textwithpicto($s, $langs->trans("AnyOtherInThisListCanValidate"));
1260 }
1261
1262 //print $form->select_dolusers((GETPOST('valideur','int')>0?GETPOST('valideur','int'):$user->fk_user), "valideur", 1, ($user->admin ? '' : array($user->id)), 0, '', 0, 0, 0, 0, '', 0, '', '', 1); // By default, hierarchical parent
1263 print '</td>';
1264 print '</tr>';
1265
1266 // Description
1267 print '<tr>';
1268 print '<td>'.$langs->trans("DescCP").'</td>';
1269 print '<td class="tdtop">';
1270 $doleditor = new DolEditor('description', GETPOST('description', 'restricthtml'), '', 80, 'dolibarr_notes', 'In', false, false, isModEnabled('fckeditor'), ROWS_3, '90%');
1271 print $doleditor->Create(1);
1272 print '</td></tr>';
1273
1274 // Other attributes
1275 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php';
1276
1277 print '</tbody>';
1278 print '</table>';
1279
1280 print dol_get_fiche_end();
1281
1282 print $form->buttonsSaveCancel("SendRequestCP");
1283
1284 print '</from>'."\n";
1285 }
1286} else {
1287 if ($error && $action != 'edit') {
1288 print '<div class="tabBar">';
1289 print '<br><br><input type="button" value="'.$langs->trans("ReturnCP").'" class="button" onclick="history.go(-1)" />';
1290 print '</div>';
1291 } else {
1292 // Show page in view or edit mode
1293 if (($id > 0) || $ref) {
1294 $result = $object->fetch($id, $ref);
1295
1296 $approverexpected = new User($db);
1297 $approverexpected->fetch($object->fk_validator); // Use that should be the approver
1298
1299 $userRequest = new User($db);
1300 $userRequest->fetch($object->fk_user);
1301
1302 //print load_fiche_titre($langs->trans('TitreRequestCP'));
1303
1304 // Si il y a une erreur
1305 if (GETPOST('error')) {
1306 switch (GETPOST('error')) {
1307 case 'datefin':
1308 $errors[] = $langs->transnoentitiesnoconv('ErrorEndDateCP');
1309 break;
1310 case 'SQL_Create':
1311 $errors[] = $langs->transnoentitiesnoconv('ErrorSQLCreateCP');
1312 break;
1313 case 'CantCreate':
1314 $errors[] = $langs->transnoentitiesnoconv('CantCreateCP');
1315 break;
1316 case 'Valideur':
1317 $errors[] = $langs->transnoentitiesnoconv('InvalidValidatorCP');
1318 break;
1319 case 'nodatedebut':
1320 $errors[] = $langs->transnoentitiesnoconv('NoDateDebut');
1321 break;
1322 case 'nodatefin':
1323 $errors[] = $langs->transnoentitiesnoconv('NoDateFin');
1324 break;
1325 case 'DureeHoliday':
1326 $errors[] = $langs->transnoentitiesnoconv('ErrorDureeCP');
1327 break;
1328 case 'NoMotifRefuse':
1329 $errors[] = $langs->transnoentitiesnoconv('NoMotifRefuseCP');
1330 break;
1331 case 'mail':
1332 $errors[] = $langs->transnoentitiesnoconv('ErrorMailNotSend');
1333 break;
1334 }
1335
1336 setEventMessages(null, $errors, 'errors');
1337 }
1338
1339 // check if the user has the right to read this request
1340 if ($canread) {
1342
1343 if (($action == 'edit' && $object->status == Holiday::STATUS_DRAFT) || ($action == 'editvalidator')) {
1344 if ($action == 'edit' && $object->status == Holiday::STATUS_DRAFT) {
1345 $edit = true;
1346 }
1347
1348 print '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">'."\n";
1349 print '<input type="hidden" name="token" value="'.newToken().'" />'."\n";
1350 print '<input type="hidden" name="action" value="update"/>'."\n";
1351 print '<input type="hidden" name="id" value="'.$object->id.'" />'."\n";
1352 }
1353
1354 print dol_get_fiche_head($head, 'card', $langs->trans("CPTitreMenu"), -1, 'holiday');
1355
1356 $linkback = '<a href="'.DOL_URL_ROOT.'/holiday/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
1357
1358 dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref');
1359
1360
1361 print '<div class="fichecenter">';
1362 print '<div class="fichehalfleft">';
1363 print '<div class="underbanner clearboth"></div>';
1364
1365 print '<table class="border tableforfield centpercent">';
1366 print '<tbody>';
1367
1368 // User
1369 print '<tr>';
1370 print '<td class="titlefield">'.$langs->trans("User").'</td>';
1371 print '<td>';
1372 print $userRequest->getNomUrl(-1, 'leave');
1373 print '</td></tr>';
1374
1375 // Type
1376 print '<tr>';
1377 print '<td>'.$langs->trans("Type").'</td>';
1378 print '<td>';
1379 $typeleaves = $object->getTypes(1, -1);
1380 if (empty($typeleaves[$object->fk_type])) {
1381 $labeltoshow = $langs->trans("TypeWasDisabledOrRemoved", $object->fk_type);
1382 } else {
1383 $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']);
1384 }
1385 print $labeltoshow;
1386 print '</td>';
1387 print '</tr>';
1388
1389 $starthalfday = ($object->halfday == -1 || $object->halfday == 2) ? 'afternoon' : 'morning';
1390 $endhalfday = ($object->halfday == 1 || $object->halfday == 2) ? 'morning' : 'afternoon';
1391
1392 if (!$edit) {
1393 print '<tr>';
1394 print '<td class="nowrap">';
1395 print $form->textwithpicto($langs->trans('DateDebCP'), $langs->trans("FirstDayOfHoliday"));
1396 print '</td>';
1397 print '<td>'.dol_print_date($object->date_debut, 'day');
1398 print ' &nbsp; &nbsp; ';
1399 print '<span class="opacitymedium">'.$langs->trans($listhalfday[$starthalfday]).'</span>';
1400 print '</td>';
1401 print '</tr>';
1402 } else {
1403 print '<tr>';
1404 print '<td class="nowrap">';
1405 print $form->textwithpicto($langs->trans('DateDebCP'), $langs->trans("FirstDayOfHoliday"));
1406 print '</td>';
1407 print '<td>';
1408 $tmpdate = GETPOSTDATE('date_debut_', '00:00:00');
1409 print $form->selectDate($tmpdate ? $tmpdate : $object->date_debut, 'date_debut_');
1410 print ' &nbsp; &nbsp; ';
1411 print $form->selectarray('starthalfday', $listhalfday, (GETPOST('starthalfday') ? GETPOST('starthalfday') : $starthalfday));
1412 print '</td>';
1413 print '</tr>';
1414 }
1415
1416 if (!$edit) {
1417 print '<tr>';
1418 print '<td class="nowrap">';
1419 print $form->textwithpicto($langs->trans('DateFinCP'), $langs->trans("LastDayOfHoliday"));
1420 print '</td>';
1421 print '<td>'.dol_print_date($object->date_fin, 'day');
1422 print ' &nbsp; &nbsp; ';
1423 print '<span class="opacitymedium">'.$langs->trans($listhalfday[$endhalfday]).'</span>';
1424 print '</td>';
1425 print '</tr>';
1426 } else {
1427 print '<tr>';
1428 print '<td class="nowrap">';
1429 print $form->textwithpicto($langs->trans('DateFinCP'), $langs->trans("LastDayOfHoliday"));
1430 print '</td>';
1431 print '<td>';
1432 print $form->selectDate($object->date_fin, 'date_fin_');
1433 print ' &nbsp; &nbsp; ';
1434 print $form->selectarray('endhalfday', $listhalfday, (GETPOST('endhalfday') ? GETPOST('endhalfday') : $endhalfday));
1435 print '</td>';
1436 print '</tr>';
1437 }
1438
1439 // Nb of days
1440 print '<tr>';
1441 print '<td>';
1442 $htmlhelp = $langs->trans('NbUseDaysCPHelp');
1443 $includesaturday = getDolGlobalInt('MAIN_NON_WORKING_DAYS_INCLUDE_SATURDAY', 1);
1444 $includesunday = getDolGlobalInt('MAIN_NON_WORKING_DAYS_INCLUDE_SUNDAY', 1);
1445 if ($includesaturday) {
1446 $htmlhelp .= '<br>'.$langs->trans("DayIsANonWorkingDay", $langs->trans("Saturday"));
1447 }
1448 if ($includesunday) {
1449 $htmlhelp .= '<br>'.$langs->trans("DayIsANonWorkingDay", $langs->trans("Sunday"));
1450 }
1451 print $form->textwithpicto($langs->trans('NbUseDaysCP'), $htmlhelp);
1452 print '</td>';
1453 print '<td>';
1454 print num_open_day($object->date_debut_gmt, $object->date_fin_gmt, 0, 1, $object->halfday);
1455 print '</td>';
1456 print '</tr>';
1457
1458 if ($object->status == Holiday::STATUS_REFUSED) {
1459 print '<tr>';
1460 print '<td>'.$langs->trans('DetailRefusCP').'</td>';
1461 print '<td>'.$object->detail_refuse.'</td>';
1462 print '</tr>';
1463 }
1464
1465 // Description
1466 if (!$edit) {
1467 print '<tr>';
1468 print '<td>'.$langs->trans('DescCP').'</td>';
1469 print '<td>'.nl2br($object->description).'</td>';
1470 print '</tr>';
1471 } else {
1472 print '<tr>';
1473 print '<td>'.$langs->trans('DescCP').'</td>';
1474 print '<td class="tdtop">';
1475 $doleditor = new DolEditor('description', $object->description, '', 80, 'dolibarr_notes', 'In', false, false, isModEnabled('fckeditor'), ROWS_3, '90%');
1476 print $doleditor->Create(1);
1477 print '</td></tr>';
1478 }
1479
1480 // Other attributes
1481 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
1482
1483 print '</tbody>';
1484 print '</table>'."\n";
1485
1486 print '</div>';
1487 print '<div class="fichehalfright">';
1488
1489 print '<div class="underbanner clearboth"></div>';
1490
1491 // Info workflow
1492 print '<table class="border tableforfield centpercent">'."\n";
1493 print '<tbody>';
1494
1495 if (!empty($object->fk_user_create)) {
1496 $userCreate = new User($db);
1497 $userCreate->fetch($object->fk_user_create);
1498 print '<tr>';
1499 print '<td class="titlefield">'.$langs->trans('RequestByCP').'</td>';
1500 print '<td>'.$userCreate->getNomUrl(-1).'</td>';
1501 print '</tr>';
1502 }
1503
1504 // Approver
1505 if (!$edit && $action != 'editvalidator') {
1506 print '<tr>';
1507 print '<td class="titlefield">';
1509 print $langs->trans('ApprovedBy');
1510 } else {
1511 print $langs->trans('ReviewedByCP');
1512 }
1513 print '</td>';
1514 print '<td>';
1516 if ($object->fk_user_approve > 0) {
1517 $approverdone = new User($db);
1518 $approverdone->fetch($object->fk_user_approve);
1519 print $approverdone->getNomUrl(-1);
1520 }
1521 } else {
1522 print $approverexpected->getNomUrl(-1);
1523 }
1524 $include_users = $object->fetch_users_approver_holiday();
1525 if (is_array($include_users) && in_array($user->id, $include_users) && $object->status == Holiday::STATUS_VALIDATED) {
1526 print '<a class="editfielda paddingleft" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=editvalidator">'.img_edit($langs->trans("Edit")).'</a>';
1527 }
1528 print '</td>';
1529 print '</tr>';
1530 } else {
1531 print '<tr>';
1532 print '<td class="titlefield">'.$langs->trans('ReviewedByCP').'</td>'; // Will be approved by
1533 print '<td>';
1534 $include_users = $object->fetch_users_approver_holiday();
1535 if (!in_array($object->fk_validator, $include_users)) { // Add the current validator to the list to not lose it when editing.
1536 $include_users[] = $object->fk_validator;
1537 }
1538 if (empty($include_users)) {
1539 print img_warning().' '.$langs->trans("NobodyHasPermissionToValidateHolidays");
1540 } else {
1541 $arrayofvalidatorstoexclude = (($user->admin || ($user->id != $userRequest->id)) ? '' : array($user->id)); // We exclude ourself from validator list. Not if we are admin or if we are on the leave of someone else
1542 $s = $form->select_dolusers($object->fk_validator, "valideur", (($action == 'editvalidator') ? 0 : 1), $arrayofvalidatorstoexclude, 0, $include_users);
1543 print $form->textwithpicto($s, $langs->trans("AnyOtherInThisListCanValidate"));
1544 }
1545 if ($action == 'editvalidator') {
1546 print '<input type="submit" class="button button-save" name="savevalidator" value="'.$langs->trans("Save").'">';
1547 print '<input type="submit" class="button button-cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
1548 }
1549 print '</td>';
1550 print '</tr>';
1551 }
1552
1553 print '<tr>';
1554 print '<td>'.$langs->trans('DateCreation').'</td>';
1555 print '<td>'.dol_print_date($object->date_create, 'dayhour', 'tzuser').'</td>';
1556 print '</tr>';
1558 print '<tr>';
1559 print '<td>'.$langs->trans('DateValidCP').'</td>';
1560 print '<td>'.dol_print_date($object->date_approval, 'dayhour', 'tzuser').'</td>'; // warning: date_valid is approval date on holiday module
1561 print '</tr>';
1562 }
1563 if ($object->status == Holiday::STATUS_CANCELED) {
1564 print '<tr>';
1565 print '<td>'.$langs->trans('DateCancelCP').'</td>';
1566 print '<td>'.dol_print_date($object->date_cancel, 'dayhour', 'tzuser').'</td>';
1567 print '</tr>';
1568 }
1569 if ($object->status == Holiday::STATUS_REFUSED) {
1570 print '<tr>';
1571 print '<td>'.$langs->trans('DateRefusCP').'</td>';
1572 print '<td>'.dol_print_date($object->date_refuse, 'dayhour', 'tzuser').'</td>';
1573 print '</tr>';
1574 }
1575 print '</tbody>';
1576 print '</table>';
1577
1578 print '</div>';
1579 print '</div>';
1580
1581 print '<div class="clearboth"></div>';
1582
1583 print dol_get_fiche_end();
1584
1585
1586 // Confirmation messages
1587 if ($action == 'delete') {
1588 if ($candelete) {
1589 print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans("TitleDeleteCP"), $langs->trans("ConfirmDeleteCP"), "confirm_delete", '', 0, 1);
1590 }
1591 }
1592
1593 // Si envoi en validation
1594 if ($action == 'sendToValidate' && $object->status == Holiday::STATUS_DRAFT) {
1595 print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans("TitleToValidCP"), $langs->trans("ConfirmToValidCP"), "confirm_send", '', 1, 1);
1596 }
1597
1598 // Si validation de la demande
1599 if ($action == 'valid') {
1600 print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans("TitleValidCP"), $langs->trans("ConfirmValidCP"), "confirm_valid", '', 1, 1);
1601 }
1602
1603 // Si refus de la demande
1604 if ($action == 'refuse') {
1605 $array_input = array(array('type' => "text", 'label' => $langs->trans('DetailRefusCP'), 'name' => "detail_refuse", 'size' => "50", 'value' => ""));
1606 print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id."&action=confirm_refuse", $langs->trans("TitleRefuseCP"), $langs->trans('ConfirmRefuseCP'), "confirm_refuse", $array_input, 1, 0);
1607 }
1608
1609 // Si annulation de la demande
1610 if ($action == 'cancel') {
1611 print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans("TitleCancelCP"), $langs->trans("ConfirmCancelCP"), "confirm_cancel", '', 1, 1);
1612 }
1613
1614 // Si back to draft
1615 if ($action == 'backtodraft') {
1616 print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans("TitleSetToDraft"), $langs->trans("ConfirmSetToDraft"), "confirm_draft", '', 1, 1);
1617 }
1618
1619 if (($action == 'edit' && $object->status == Holiday::STATUS_DRAFT) || ($action == 'editvalidator')) {
1620 if ($action == 'edit' && $object->status == Holiday::STATUS_DRAFT) {
1621 if ($permissiontoadd && $object->status == Holiday::STATUS_DRAFT) {
1622 print $form->buttonsSaveCancel();
1623 }
1624 }
1625
1626 print '</form>';
1627 }
1628
1629 if (!$edit) {
1630 // Buttons for actions
1631
1632 print '<div class="tabsAction">';
1633
1634 if ($permissiontoadd && $object->status == Holiday::STATUS_DRAFT) {
1635 print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=edit&token='.newToken().'" class="butAction">'.$langs->trans("EditCP").'</a>';
1636 }
1637
1638 if ($permissiontoadd && $object->status == Holiday::STATUS_DRAFT) { // If draft
1639 print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=sendToValidate&token='.newToken().'" class="butAction">'.$langs->trans("Validate").'</a>';
1640 }
1641
1642 if ($object->status == Holiday::STATUS_VALIDATED) { // If validated
1643 // Button Approve / Refuse
1644 if (($user->id == $object->fk_validator || $permissiontoaddall) && $permissiontoapprove) {
1645 print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=valid&token='.newToken().'" class="butAction">'.$langs->trans("Approve").'</a>';
1646 print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=refuse&token='.newToken().'" class="butAction">'.$langs->trans("ActionRefuseCP").'</a>';
1647 } else {
1648 print '<a href="#" class="butActionRefused classfortooltip" title="'.$langs->trans("NotTheAssignedApprover").'">'.$langs->trans("Approve").'</a>';
1649 print '<a href="#" class="butActionRefused classfortooltip" title="'.$langs->trans("NotTheAssignedApprover").'">'.$langs->trans("ActionRefuseCP").'</a>';
1650
1651 // Button Cancel (because we can't approve)
1652 if ($permissiontoadd || $permissiontoaddall) {
1653 if (($object->date_fin > dol_now()) || !empty($user->admin)) {
1654 print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=cancel&token='.newToken().'" class="butAction">'.$langs->trans("ActionCancelCP").'</a>';
1655 } else {
1656 print '<a href="#" class="butActionRefused classfortooltip" title="'.$langs->trans("HolidayStarted").' - '.$langs->trans("NotAllowed").'">'.$langs->trans("ActionCancelCP").'</a>';
1657 }
1658 }
1659 }
1660 }
1661 if ($object->status == Holiday::STATUS_APPROVED) { // If validated and approved
1662 if ($user->id == $object->fk_validator || $user->id == $object->fk_user_approve || $permissiontoadd || $permissiontoaddall || $permissiontoapprove) {
1663 if ((($object->date_fin > dol_now()) && $permissiontoapprove) || $user->id == $object->fk_user_approve) {
1664 print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=cancel&token='.newToken().'" class="butAction">'.$langs->trans("ActionCancelCP").'</a>';
1665 } else {
1666 if ($object->date_fin <= dol_now() && $permissiontoapprove) {
1667 print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=cancel&token='.newToken().'" class="butAction">'.$langs->trans("ActionCancelCP").'</a>';
1668 } else {
1669 print '<a href="#" class="butActionRefused classfortooltip" title="'.$langs->trans("HolidayStarted").' - '.$langs->trans("NotAllowed").'">'.$langs->trans("ActionCancelCP").'</a>';
1670 }
1671 }
1672 } else { // I have no rights on the user of the holiday.
1673 print '<a href="#" class="butActionRefused classfortooltip" title="'.$langs->trans("NotAllowed").'">'.$langs->trans("ActionCancelCP").'</a>';
1674 }
1675 }
1676
1677 if (($permissiontoadd || $permissiontoaddall) && $object->status == Holiday::STATUS_CANCELED) {
1678 print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=backtodraft&token='.newToken().'" class="butAction">'.$langs->trans("SetToDraft").'</a>';
1679 }
1680 if ($candelete) { // If draft or canceled or refused
1681 print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken().'" class="butActionDelete">'.$langs->trans("DeleteCP").'</a>';
1682 }
1683
1684 print '</div>';
1685 }
1686 } else {
1687 print '<div class="tabBar">';
1688 print $langs->trans('ErrorUserViewCP');
1689 print '<br><br><input type="button" value="'.$langs->trans("ReturnCP").'" class="button" onclick="history.go(-1)" />';
1690 print '</div>';
1691 }
1692 } else {
1693 print '<div class="tabBar">';
1694 print $langs->trans('ErrorIDFicheCP');
1695 print '<br><br><input type="button" value="'.$langs->trans("ReturnCP").'" class="button" onclick="history.go(-1)" />';
1696 print '</div>';
1697 }
1698
1699
1700 // Select mail models is same action as presend
1701 if (GETPOST('modelselected')) {
1702 $action = 'presend';
1703 }
1704
1705 if ($action != 'presend' && $action != 'edit') {
1706 print '<div class="fichecenter"><div class="fichehalfleft">';
1707 print '<a name="builddoc"></a>'; // ancre
1708
1709 // Documents
1710 /* $includedocgeneration = 0;
1711 if ($includedocgeneration) {
1712 $objref = dol_sanitizeFileName($object->ref);
1713 $relativepath = $objref.'/'.$objref.'.pdf';
1714 $filedir = $conf->holiday->dir_output.'/'.$object->element.'/'.$objref;
1715 $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
1716 $genallowed = ($user->hasRight('holiday', 'read') && $object->fk_user == $user->id) || $user->hasRight('holiday', 'readall'); // If you can read, you can build the PDF to read content
1717 $delallowed = ($user->hasRight('holiday', 'write') && $object->fk_user == $user->id) || $user->hasRight('holiday', 'writeall_advance'); // If you can create/edit, you can remove a file on card
1718 print $formfile->showdocuments('holiday:Holiday', $object->element.'/'.$objref, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', '', '', $langs->defaultlang);
1719 } */
1720
1721 // Show links to link elements
1722 //$tmparray = $form->showLinkToObjectBlock($object, null, array('myobject'), 1);
1723 //$somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
1724
1725
1726 print '</div><div class="fichehalfright">';
1727
1728 $MAXEVENT = 10;
1729
1730 // TODO Add the page holiday_agenda.php
1731 //$morehtmlcenter = dolGetButtonTitle($langs->trans('SeeAll'), '', 'fa fa-bars imgforviewmode', DOL_URL_ROOT.'/holiday/holiday_agenda.php?id='.$object->id);
1732 $morehtmlcenter = '';
1733
1734 // List of actions on element
1735 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
1736 $formactions = new FormActions($db);
1737 $somethingshown = $formactions->showactions($object, $object->element, (is_object($object->thirdparty) ? $object->thirdparty->id : 0), 1, '', $MAXEVENT, '', $morehtmlcenter);
1738
1739 print '</div></div>';
1740 }
1741 }
1742}
1743
1744// End of page
1745llxFooter();
1746
1747if (is_object($db)) {
1748 $db->close();
1749}
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:48
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:67
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
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.
Definition wrapper.php:73
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 building of HTML components.
Class to offer components to list and upload files.
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.
const STATUS_REFUSED
Refused.
const STATUS_CANCELED
Canceled.
const STATUS_APPROVED
Approved.
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:125
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
GETPOSTDATE($prefix, $hourTime='', $gm='auto', $saverestore='')
Helper function that combines values of a dolibarr DatePicker (such as Form\selectDate) for year,...
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
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, $morecssdiv='')
Show tabs of a record.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_eval($s, $returnvalue=1, $hideerrors=1, $onlysimplestring='1')
Replace eval function to add more security.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
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).
newToken()
Return the value of token currently saved into session with name 'newtoken'.
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.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_clone($object, $native=2)
Create a clone of instance of object (new instance with same value for each properties) With native =...
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.
img_edit($titlealt='default', $float=0, $other='')
Show logo edit/modify fiche.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
holiday_prepare_head($object)
Return array head with list of tabs to view object information.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
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.