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