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