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