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