dolibarr 24.0.0-beta
card.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2011 Dimitri Mouillard <dmouillard@teclib.com>
3 * Copyright (C) 2012-2016 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2012-2016 Regis Houssin <regis.houssin@inodbox.com>
5 * Copyright (C) 2013 Juanjo Menent <jmenent@2byte.es>
6 * Copyright (C) 2017-2024 Alexandre Spangaro <alexandre@inovea-conseil.com>
7 * Copyright (C) 2014-2017 Ferran Marcet <fmarcet@2byte.es>
8 * Copyright (C) 2018-2026 Frédéric France <frederic.france@free.fr>
9 * Copyright (C) 2020-2021 Udo Tamm <dev@dolibit.de>
10 * Copyright (C) 2022 Anthony Berton <anthony.berton@bb2a.fr>
11 * Copyright (C) 2024 Charlene Benke <charlene@patas-monkey.com>
12 * Copyright (C) 2025 MDW <mdeweerd@users.noreply.github.com>
13 * Copyright (C) 2025 Julien Marchand <julien.marchand@iouston.com>
14 *
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 3 of the License, orwrite
18 * (at your option) any later version.
19 *
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License
26 * along with this program. If not, see <https://www.gnu.org/licenses/>.
27 */
28
35// Load Dolibarr environment
36require '../main.inc.php';
45require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
46require_once DOL_DOCUMENT_ROOT.'/user/class/usergroup.class.php';
47require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
48require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
49require_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
50require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
51require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
52require_once DOL_DOCUMENT_ROOT.'/core/lib/holiday.lib.php';
53require_once DOL_DOCUMENT_ROOT.'/holiday/class/holiday.class.php';
54
55// Get parameters
56$action = GETPOST('action', 'aZ09');
57$cancel = GETPOST('cancel', 'alpha');
58$confirm = GETPOST('confirm', 'alpha');
59$backtopage = GETPOST('backtopage', 'alpha');
60$backtopageforcancel = GETPOST('backtopageforcancel', 'alpha');
61
62$id = GETPOSTINT('id');
63$ref = GETPOST('ref', 'alpha');
64$fuserid = (GETPOSTINT('fuserid') ? GETPOSTINT('fuserid') : ($action == 'create' ? $user->id : 0));
65$socid = GETPOSTINT('socid');
66
67// Load translation files required by the page
68$langs->loadLangs(array("other", "holiday", "mails", "trips"));
69
70$error = 0;
71$errors = [];
72
73$now = dol_now();
74
75$childids = $user->getAllChildIds(1);
76
77$morefilter = '';
78if (getDolGlobalString('HOLIDAY_HIDE_FOR_NON_SALARIES')) {
79 $morefilter = 'AND employee = 1';
80}
81
82$object = new Holiday($db);
83
84// fetch optionals attributes and labels
85$extrafields->fetch_name_optionals_label($object->table_element);
86
87// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
88$hookmanager->initHooks(array('holidaycard', 'globalcard'));
89
90$permissiontoapprove = $user->hasRight('holiday', 'approve');
91
92$canread = 0;
93if (($id > 0) || $ref) {
94 $object->fetch($id, $ref);
95
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_advance')) {
216 $error++;
217 setEventMessages($langs->trans("NotEnoughPermissions"), null, 'errors');
218 } elseif (!$user->hasRight('holiday', 'writeall_advance') && !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 $result = $object->delete($user);
464 } else {
465 $error++;
466 setEventMessages($langs->trans('BadStatusOfObject'), null, 'errors');
467 $action = '';
468 }
469
470 if (!$error) {
471 $db->commit();
472 header('Location: list.php?restore_lastsearch_values=1');
473 exit;
474 } else {
475 $db->rollback();
476 }
477 }
478
479 // Action validate (+ send email for approval to the expected approver)
480 if ($action == 'confirm_send') { // Test on permission done later
481 $object->fetch($id);
482
483 // If draft and owner of leave
484 if ($object->status == Holiday::STATUS_DRAFT && $permissiontoadd) {
485 $object->oldcopy = dol_clone($object, 2); // @phan-suppress-current-line PhanTypeMismatchProperty
486
488
489 $verif = $object->validate($user);
490
491 // If no SQL error, we redirect to the request form
492 if ($verif > 0) {
493 // To
494 $destinataire = new User($db);
495 $destinataire->fetch($object->fk_validator);
496 $emailTo = $destinataire->email;
497
498 if (!$emailTo) {
499 dol_syslog("Expected validator has no email, so we redirect directly to finished page without sending email");
500 header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
501 exit;
502 }
503
504 // From
505 $expediteur = new User($db);
506 $expediteur->fetch($object->fk_user);
507 //$emailFrom = $expediteur->email; Email of user can be an email into another company. Sending will fails, we must use the generic email.
508
509 // You can specify a special address from for holiday
510 $emailFrom = getDolGlobalString('MAIN_MAIL_EMAIL_HOLIDAY_FROM', getDolGlobalString('MAIN_MAIL_EMAIL_FROM'));
511
512 // Subject
513 $societeName = getDolGlobalString('MAIN_INFO_SOCIETE_NOM');
514 if (getDolGlobalString('MAIN_APPLICATION_TITLE')) {
515 $societeName = getDolGlobalString('MAIN_APPLICATION_TITLE');
516 }
517
518 $subject = $societeName." - ".$langs->transnoentitiesnoconv("HolidaysToValidate");
519
520 // Content
521 $message = "<p>".$langs->transnoentitiesnoconv("Hello")." ".$destinataire->firstname.",</p>\n";
522
523 $message .= "<p>".$langs->transnoentities("HolidaysToValidateBody")."</p>\n";
524
525
526 // option to warn the validator in case of too short delay
527 if (!getDolGlobalString('HOLIDAY_HIDE_APPROVER_ABOUT_TOO_LOW_DELAY')) {
528 $delayForRequest = getDolGlobalFloat('HOLIDAY_DELAY_TO_APPROVE_FOR_TYPE_'.$object->fk_type); // Set delay depending of holiday leave type
529 if ($delayForRequest) {
530 $nowplusdelay = dol_time_plus_duree($now, $delayForRequest, 'd');
531
532 if ($object->date_debut < $nowplusdelay) {
533 $message = "<p>".$langs->transnoentities("HolidaysToValidateDelay", (string) $delayForRequest)."</p>\n";
534 }
535 }
536 }
537
538
539 // option to notify the validator if the balance is less than the request
540 // (only for leave types that actually use the balance counter)
541 if (!getDolGlobalString('HOLIDAY_HIDE_APPROVER_ABOUT_NEGATIVE_BALANCE')) {
542 $affectingtypes = $object->getTypes(1, 1);
543 if (!empty($affectingtypes[$object->fk_type])) {
544 $tmpUser = new User($db);
545 $tmpUser->fetch($object->fk_user);
546
547 $nbopenedday = num_open_day($object->date_debut_gmt, $object->date_fin_gmt, 0, 1, $object->halfday, $tmpUser->country_id, $object->fk_user);
548
549 if ($nbopenedday > $object->getCPforUser($object->fk_user, $object->fk_type)) {
550 $message .= "<p>".$langs->transnoentities("HolidaysToValidateAlertSolde")."</p>\n";
551 }
552 }
553 }
554
555 $typeleaves = $object->getTypes(1, -1);
556 if (empty($typeleaves[$object->fk_type])) {
557 $labeltoshow = $langs->trans("TypeWasDisabledOrRemoved", $object->fk_type);
558 } else {
559 $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']);
560 }
561 if ($object->halfday == 2) {
562 $starthalfdaykey = "Afternoon";
563 $endhalfdaykey = "Morning";
564 } elseif ($object->halfday == -1) {
565 $starthalfdaykey = "Afternoon";
566 $endhalfdaykey = "Afternoon";
567 } elseif ($object->halfday == 1) {
568 $starthalfdaykey = "Morning";
569 $endhalfdaykey = "Morning";
570 } elseif ($object->halfday == 0 || $object->halfday == 2) {
571 $starthalfdaykey = "Morning";
572 $endhalfdaykey = "Afternoon";
573 } else {
574 $starthalfdaykey = "";
575 $endhalfdaykey = "";
576 }
577
578 $link = dol_buildpath("/holiday/card.php", 3) . '?id='.$object->id;
579
580 $message .= "<ul>";
581 $message .= "<li>".$langs->transnoentitiesnoconv("Name")." : ".dolGetFirstLastname($expediteur->firstname, $expediteur->lastname)."</li>\n";
582 $message .= "<li>".$langs->transnoentitiesnoconv("Type")." : ".(empty($labeltoshow) ? $langs->trans("TypeWasDisabledOrRemoved", $object->fk_type) : $labeltoshow)."</li>\n";
583 $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";
584 $message .= "<li>".$langs->transnoentitiesnoconv("Link").' : <a href="'.$link.'" target="_blank">'.$link."</a></li>\n";
585 $message .= "</ul>\n";
586
587 $trackid = 'leav'.$object->id;
588
589 $sendtobcc = getDolGlobalString('MAIN_MAIL_AUTOCOPY_HOLIDAY_TO');
590
591 $mail = new CMailFile($subject, $emailTo, $emailFrom, $message, array(), array(), array(), '', $sendtobcc, 0, 1, '', '', $trackid);
592
593 // Sending the email
594 $result = $mail->sendfile();
595
596 if (!$result) {
597 setEventMessages($mail->error, $mail->errors, 'warnings');
598 $action = '';
599 } else {
600 header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
601 exit;
602 }
603 } else {
604 setEventMessages($object->error, $object->errors, 'errors');
605 $action = '';
606 }
607 }
608 }
609
610 if ($action == 'update_extras' && $permissiontoeditextra) {
611 $object->oldcopy = dol_clone($object, 2); // @phan-suppress-current-line PhanTypeMismatchProperty
612
613 $attribute_name = GETPOST('attribute', 'aZ09');
614
615 // Fill array 'array_options' with data from update form
616 $ret = $extrafields->setOptionalsFromPost(null, $object, $attribute_name);
617 if ($ret < 0) {
618 $error++;
619 }
620
621 if (!$error) {
622 $result = $object->updateExtraField($attribute_name, 'HOLIDAY_MODIFY');
623 if ($result < 0) {
624 setEventMessages($object->error, $object->errors, 'errors');
625 $error++;
626 }
627 }
628
629 if ($error) {
630 $action = 'edit_extras';
631 }
632 }
633
634 // Approve leave request
635 if ($action == 'confirm_valid' && $permissiontoapprove) {
636 $object->fetch($id);
637
638 // If status is waiting approval and approver is also user
639 if ($object->status == Holiday::STATUS_VALIDATED && ($user->id == $object->fk_validator || $permissiontoaddall)) {
640 $object->oldcopy = dol_clone($object, 2); // @phan-suppress-current-line PhanTypeMismatchProperty
641
642 $object->date_approval = dol_now();
643 $object->fk_user_approve = $user->id;
646
647 $decrease = getDolGlobalInt('HOLIDAY_DECREASE_AT_END_OF_MONTH');
648
649 $db->begin();
650
651 $verif = $object->approve($user);
652 if ($verif <= 0) {
653 setEventMessages($object->error, $object->errors, 'errors');
654 $error++;
655 }
656
657 // If no SQL error, we redirect to the request form
658 if (!$error && empty($decrease)) {
659 $tmpUser = new User($db);
660 $tmpUser->fetch($object->fk_user);
661
662 // Calculate number of days consumed
663 $nbopenedday = num_open_day($object->date_debut_gmt, $object->date_fin_gmt, 0, 1, $object->halfday, $tmpUser->country_id, $object->fk_user);
664 $soldeActuel = $object->getCpforUser($object->fk_user, $object->fk_type);
665 $newSolde = ($soldeActuel - $nbopenedday);
666 $label = $object->ref.' - '.$langs->transnoentitiesnoconv("HolidayConsumption");
667
668 // The modification is added to the LOG
669 $result = $object->addLogCP($user->id, $object->fk_user, $label, $newSolde, $object->fk_type);
670 if ($result < 0) {
671 $error++;
672 setEventMessages(null, $object->errors, 'errors');
673 }
674
675 // Update balance
676 $result = $object->updateSoldeCP($object->fk_user, $newSolde, $object->fk_type);
677 if ($result < 0) {
678 $error++;
679 setEventMessages(null, $object->errors, 'errors');
680 }
681 }
682
683 if (!$error) {
684 // To
685 $destinataire = new User($db);
686 $destinataire->fetch($object->fk_user);
687 $emailTo = $destinataire->email;
688
689 if (!$emailTo) {
690 dol_syslog("User that request leave has no email, so we redirect directly to finished page without sending email");
691 } else {
692 // From
693 $expediteur = new User($db);
694 $expediteur->fetch($object->fk_validator);
695 //$emailFrom = $expediteur->email; Email of user can be an email into another company. Sending will fails, we must use the generic email.
696 $emailFrom = getDolGlobalString('MAIN_MAIL_EMAIL_FROM');
697
698 // Subject
699 $societeName = getDolGlobalString('MAIN_INFO_SOCIETE_NOM');
700 if (getDolGlobalString('MAIN_APPLICATION_TITLE')) {
701 $societeName = getDolGlobalString('MAIN_APPLICATION_TITLE');
702 }
703
704 $subject = '['.$societeName."] ".$langs->transnoentitiesnoconv("HolidaysValidated");
705
706 // Content
707 $message = "<p>".$langs->transnoentitiesnoconv("Hello")." ".$destinataire->firstname.",</p>\n";
708
709 $message .= "<p>".$langs->transnoentities("HolidaysValidatedBody", dol_print_date($object->date_debut, 'day'), dol_print_date($object->date_fin, 'day'))."</p>\n";
710
711 $link = dol_buildpath('/holiday/card.php', 3).'?id='.$object->id;
712
713 $message .= "<ul>\n";
714 $message .= "<li>".$langs->transnoentitiesnoconv("ValidatedBy")." : ".dolGetFirstLastname($expediteur->firstname, $expediteur->lastname)."</li>\n";
715 $message .= "<li>".$langs->transnoentitiesnoconv("Link").' : <a href="'.$link.'" target="_blank">'.$link."</a></li>\n";
716 $message .= "</ul>\n";
717
718 $trackid = 'leav'.$object->id;
719
720 $sendtobcc = getDolGlobalString('MAIN_MAIL_AUTOCOPY_HOLIDAY_TO');
721
722 $mail = new CMailFile($subject, $emailTo, $emailFrom, $message, array(), array(), array(), '', $sendtobcc, 0, 1, '', '', $trackid);
723
724 // Sending email
725 $result = $mail->sendfile();
726
727 if (!$result) {
728 setEventMessages($mail->error, $mail->errors, 'warnings'); // Show error, but do no make rollback, so $error is not set to 1
729 $action = '';
730 }
731 }
732 }
733
734 if (!$error) {
735 $db->commit();
736 } else {
737 $db->rollback();
738 $action = '';
739 }
740
741 header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
742 exit;
743 }
744 }
745
746 if ($action == 'confirm_refuse' && GETPOST('confirm', 'alpha') == 'yes' && $permissiontoapprove) { // Test on permission done later
747 if (GETPOST('detail_refuse')) {
748 $object->fetch($id);
749
750 // If status pending validation and validator = user
751 if ($object->status == Holiday::STATUS_VALIDATED && ($user->id == $object->fk_validator || $permissiontoaddall)) {
752 $object->date_refuse = dol_now();
753 $object->fk_user_refuse = $user->id;
756 $object->detail_refuse = GETPOST('detail_refuse', 'alphanohtml');
757
758 $db->begin();
759
760 $verif = $object->update($user);
761 if ($verif <= 0) {
762 $error++;
763 setEventMessages($object->error, $object->errors, 'errors');
764 }
765
766 // If no SQL error, we redirect to the request form
767 if (!$error) {
768 // To
769 $destinataire = new User($db);
770 $destinataire->fetch($object->fk_user);
771 $emailTo = $destinataire->email;
772
773 if (!$emailTo) {
774 dol_syslog("User that request leave has no email, so we redirect directly to finished page without sending email");
775 } else {
776 // From
777 $expediteur = new User($db);
778 $expediteur->fetch($object->fk_validator);
779 //$emailFrom = $expediteur->email; Email of user can be an email into another company. Sending will fails, we must use the generic email.
780 $emailFrom = getDolGlobalString('MAIN_MAIL_EMAIL_FROM');
781
782 // Subject
783 $societeName = getDolGlobalString('MAIN_INFO_SOCIETE_NOM');
784 if (getDolGlobalString('MAIN_APPLICATION_TITLE')) {
785 $societeName = getDolGlobalString('MAIN_APPLICATION_TITLE');
786 }
787
788 $subject = $societeName." - ".$langs->transnoentitiesnoconv("HolidaysRefused");
789
790 // Content
791 $message = "<p>".$langs->transnoentitiesnoconv("Hello")." ".$destinataire->firstname.",</p>\n";
792
793 $message .= "<p>".$langs->transnoentities("HolidaysRefusedBody", dol_print_date($object->date_debut, 'day'), dol_print_date($object->date_fin, 'day'))."<p>\n";
794 $message .= "<p>".GETPOST('detail_refuse', 'alpha')."</p>";
795
796 $link = dol_buildpath('/holiday/card.php', 3).'?id='.$object->id;
797
798 $message .= "<ul>\n";
799 $message .= "<li>".$langs->transnoentitiesnoconv("ModifiedBy")." : ".dolGetFirstLastname($expediteur->firstname, $expediteur->lastname)."</li>\n";
800 $message .= "<li>".$langs->transnoentitiesnoconv("Link").' : <a href="'.$link.'" target="_blank">'.$link."</a></li>\n";
801 $message .= "</ul>";
802
803 $trackid = 'leav'.$object->id;
804
805 $sendtobcc = getDolGlobalString('MAIN_MAIL_AUTOCOPY_HOLIDAY_TO');
806
807 $mail = new CMailFile($subject, $emailTo, $emailFrom, $message, array(), array(), array(), '', $sendtobcc, 0, 1, '', '', $trackid);
808
809 // sending email
810 $result = $mail->sendfile();
811
812 if (!$result) {
813 setEventMessages($mail->error, $mail->errors, 'warnings'); // Show error, but do no make rollback, so $error is not set to 1
814 $action = '';
815 }
816 }
817 } else {
818 $action = '';
819 }
820
821 if (!$error) {
822 $db->commit();
823
824 header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
825 exit;
826 } else {
827 $db->rollback();
828 $action = '';
829 }
830 }
831 } else {
832 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("DetailRefusCP")), null, 'errors');
833 $action = 'refuse';
834 }
835 }
836
837 // If the request is validated
838 if ($action == 'confirm_draft' && GETPOST('confirm') == 'yes' && $permissiontoadd) {
839 $error = 0;
840
841 $object->fetch($id);
842
843 $oldstatus = $object->status;
846
847 $result = $object->update($user);
848 if ($result < 0) {
849 $error++;
850 setEventMessages($langs->trans('ErrorBackToDraft').' '.$object->error, $object->errors, 'errors');
851 }
852
853 if (!$error) {
854 $db->commit();
855
856 header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
857 exit;
858 } else {
859 $db->rollback();
860 }
861 }
862
863 // If confirmation of cancellation
864 if ($action == 'confirm_cancel' && GETPOST('confirm') == 'yes') { // Test on permission done later
865 $error = 0;
866
867 $object->fetch($id);
868
869 // If status pending validation and validator = validator or user, or rights to do for others
870 if (($object->status == Holiday::STATUS_VALIDATED || $object->status == Holiday::STATUS_APPROVED) &&
871 ($user->id == $object->fk_validator || $permissiontoadd || $permissiontoaddall || $permissiontoapprove)) {
872 $db->begin();
873
874 $oldstatus = $object->status;
875 $object->date_cancel = dol_now();
876 $object->fk_user_cancel = $user->id;
879
880 $decrease = getDolGlobalInt('HOLIDAY_DECREASE_AT_END_OF_MONTH');
881
882 $result = $object->update($user);
883
884 if ($result >= 0 && $oldstatus == Holiday::STATUS_APPROVED) { // holiday was already validated, status 3, so we must increase back the balance
885 // Call trigger
886 $result = $object->call_trigger('HOLIDAY_CANCEL', $user);
887 if ($result < 0) {
888 $error++;
889 }
890
891 $startDate = $object->date_debut_gmt;
892 $endDate = $object->date_fin_gmt;
893
894 if (!empty($decrease)) {
895 $lastUpdate = strtotime($object->getConfCP('lastUpdate', dol_print_date(dol_now(), '%Y%m%d%H%M%S')));
896 $date = strtotime('-1 month', $lastUpdate);
897 $endOfMonthBeforeLastUpdate = dol_mktime(0, 0, 0, (int) date('m', $date), (int) date('t', $date), (int) date('Y', $date), 1);
898 if ($object->date_debut_gmt < $endOfMonthBeforeLastUpdate && $object->date_fin_gmt > $endOfMonthBeforeLastUpdate) {
899 $endDate = $endOfMonthBeforeLastUpdate;
900 } elseif ($object->date_debut_gmt > $endOfMonthBeforeLastUpdate) {
901 $endDate = $startDate;
902 }
903 }
904
905 $tmpUser = new User($db);
906 $tmpUser->fetch($object->fk_user);
907
908 // Calculate number of days consumed
909 $nbopenedday = num_open_day($startDate, $endDate, 0, 1, $object->halfday, $tmpUser->country_id, $object->fk_user);
910
911 $soldeActuel = $object->getCpforUser($object->fk_user, $object->fk_type);
912 $newSolde = ($soldeActuel + $nbopenedday);
913
914 // The modification is added to the LOG
915 $result1 = $object->addLogCP($user->id, $object->fk_user, $object->ref.' - '.$langs->transnoentitiesnoconv("HolidayCreditAfterCancellation"), $newSolde, $object->fk_type);
916
917 // Update of the balance
918 $result2 = $object->updateSoldeCP($object->fk_user, $newSolde, $object->fk_type);
919
920 if ($result1 < 0 || $result2 < 0) {
921 $error++;
922 setEventMessages($langs->trans('ErrorCantDeleteCP').' '.$object->error, $object->errors, 'errors');
923 }
924 }
925
926 if (!$error) {
927 $db->commit();
928 } else {
929 $db->rollback();
930 }
931
932 // If no SQL error, we redirect to the request form
933 if (!$error && $result > 0) {
934 // To
935 $destinataire = new User($db);
936 $destinataire->fetch($object->fk_user);
937 $emailTo = $destinataire->email;
938
939 if (!$emailTo) {
940 header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
941 exit;
942 }
943
944 // From
945 $expediteur = new User($db);
946 $expediteur->fetch($object->fk_user_cancel);
947 //$emailFrom = $expediteur->email; Email of user can be an email into another company. Sending will fails, we must use the generic email.
948 $emailFrom = getDolGlobalString('MAIN_MAIL_EMAIL_FROM');
949
950 // Subject
951 $societeName = getDolGlobalString('MAIN_INFO_SOCIETE_NOM');
952 if (getDolGlobalString('MAIN_APPLICATION_TITLE')) {
953 $societeName = getDolGlobalString('MAIN_APPLICATION_TITLE');
954 }
955
956 $subject = $societeName." - ".$langs->transnoentitiesnoconv("HolidaysCanceled");
957
958 // Content
959 $message = "<p>".$langs->transnoentitiesnoconv("Hello")." ".$destinataire->firstname.",</p>\n";
960
961 $message .= "<p>".$langs->transnoentities("HolidaysCanceledBody", dol_print_date($object->date_debut, 'day'), dol_print_date($object->date_fin, 'day'))."</p>\n";
962
963 $link = dol_buildpath('/holiday/card.php', 3).'?id='.$object->id;
964
965 $message .= "<ul>\n";
966 $message .= "<li>".$langs->transnoentitiesnoconv("ModifiedBy")." : ".dolGetFirstLastname($expediteur->firstname, $expediteur->lastname)."</li>\n";
967 $message .= "<li>".$langs->transnoentitiesnoconv("Link").' : <a href="'.$link.'" target="_blank">'.$link."</a></li>\n";
968 $message .= "</ul>\n";
969
970 $trackid = 'leav'.$object->id;
971
972 $sendtobcc = getDolGlobalString('MAIN_MAIL_AUTOCOPY_HOLIDAY_TO');
973
974 $mail = new CMailFile($subject, $emailTo, $emailFrom, $message, array(), array(), array(), '', $sendtobcc, 0, 1, '', '', $trackid);
975
976 // sending email
977 $result = $mail->sendfile();
978
979 if (!$result) {
980 setEventMessages($mail->error, $mail->errors, 'warnings');
981 $action = '';
982 } else {
983 header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
984 exit;
985 }
986 }
987 }
988 }
989
990 /*
991 // Actions when printing a doc from card
992 include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
993
994 // Actions to send emails
995 $triggersendname = 'HOLIDAY_SENTBYMAIL';
996 $autocopy='MAIN_MAIL_AUTOCOPY_HOLIDAY_TO';
997 $trackid='leav'.$object->id;
998 include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
999
1000 // Actions to build doc
1001 $upload_dir = $conf->holiday->dir_output;
1002 $permissiontoadd = $user->rights->holiday->creer;
1003 include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
1004 */
1005}
1006
1007
1008
1009/*
1010 * View
1011 */
1012
1013$form = new Form($db);
1014$formfile = new FormFile($db);
1015$object = new Holiday($db);
1016
1017$listhalfday = array('morning' => $langs->trans("Morning"), "afternoon" => $langs->trans("Afternoon"));
1018
1019$title = $langs->trans('Leave');
1020$help_url = 'EN:Module_Holiday';
1021
1022llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-holiday page-card');
1023
1024$edit = false;
1025
1026if ((empty($id) && empty($ref)) || $action == 'create' || $action == 'add') {
1027 // If user has no permission to create a leave
1028 if ((in_array($fuserid, $childids) && !$user->hasRight('holiday', 'write')) || (!in_array($fuserid, $childids) && ((getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && !$user->hasRight('holiday', 'writeall_advance') || !$user->hasRight('holiday', 'writeall'))))) {
1029 $errors[] = $langs->trans('CantCreateCP');
1030 } else {
1031 // Form to add a leave request
1032 print load_fiche_titre($langs->trans('MenuAddCP'), '', 'title_hrm.png');
1033
1034 // Error management
1035 if (GETPOST('error')) {
1036 switch (GETPOST('error')) {
1037 case 'datefin':
1038 $errors[] = $langs->trans('ErrorEndDateCP');
1039 break;
1040 case 'SQL_Create':
1041 $errors[] = $langs->trans('ErrorSQLCreateCP');
1042 break;
1043 case 'CantCreate':
1044 $errors[] = $langs->trans('CantCreateCP');
1045 break;
1046 case 'Valideur':
1047 $errors[] = $langs->trans('InvalidValidatorCP');
1048 break;
1049 case 'nodatedebut':
1050 $errors[] = $langs->trans('NoDateDebut');
1051 break;
1052 case 'nodatefin':
1053 $errors[] = $langs->trans('NoDateFin');
1054 break;
1055 case 'DureeHoliday':
1056 $errors[] = $langs->trans('ErrorDureeCP');
1057 break;
1058 case 'alreadyCP':
1059 $errors[] = $langs->trans('alreadyCPexist');
1060 break;
1061 }
1062
1063 setEventMessages(null, $errors, 'errors');
1064 }
1065
1066
1067 print '<script type="text/javascript">
1068 $( document ).ready(function() {
1069 $("input.button-save").click("submit", function(e) {
1070 console.log("Call valider()");
1071 if (document.demandeCP.date_debut_.value != "")
1072 {
1073 if(document.demandeCP.date_fin_.value != "")
1074 {
1075 if(document.demandeCP.valideur.value != "-1") {
1076 return true;
1077 }
1078 else {
1079 alert("'.dol_escape_js($langs->transnoentities('InvalidValidatorCP')).'");
1080 return false;
1081 }
1082 }
1083 else
1084 {
1085 alert("'.dol_escape_js($langs->transnoentities('NoDateFin')).'");
1086 return false;
1087 }
1088 }
1089 else
1090 {
1091 alert("'.dol_escape_js($langs->transnoentities('NoDateDebut')).'");
1092 return false;
1093 }
1094 });
1095 });
1096 </script>'."\n";
1097
1098
1099 // Formulaire de demande
1100 print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'" name="demandeCP">'."\n";
1101 print '<input type="hidden" name="token" value="'.newToken().'" />'."\n";
1102 print '<input type="hidden" name="action" value="add" />'."\n";
1103
1104 print dol_get_fiche_head();
1105
1106 //print '<span>'.$langs->trans('DelayToRequestCP',$object->getConfCP('delayForRequest')).'</span><br><br>';
1107
1108 print '<table class="border centpercent">';
1109 print '<tbody>';
1110
1111 // User for leave request
1112 print '<tr>';
1113 print '<td class="titlefield fieldrequired tdtop">'.$langs->trans("User").'</td>';
1114 print '<td><div class="inline-block">';
1115 if ($permissiontoadd && !$permissiontoaddall) {
1116 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');
1117 //print '<input type="hidden" name="fuserid" value="'.($fuserid?$fuserid:$user->id).'">';
1118 } else {
1119 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');
1120 }
1121 print '</div>';
1122
1123 if (!getDolGlobalString('HOLIDAY_HIDE_BALANCE')) {
1124 print '<div class="leaveuserbalance paddingtop inline-block floatright badge badge-status0 badge-status margintoponsmartphone">';
1125
1126 $out = '';
1127 $nb_holiday = 0;
1128 $typeleaves = $object->getTypes(1, 1);
1129 foreach ($typeleaves as $key => $val) {
1130 $nb_type = $object->getCPforUser(($fuserid ? $fuserid : $user->id), $val['rowid']);
1131 $nb_holiday += $nb_type;
1132
1133 $out .= ' - '.($langs->trans($val['code']) != $val['code'] ? $langs->trans($val['code']) : $val['label']).': <strong>'.($nb_type ? price2num($nb_type) : 0).'</strong>';
1134 if ($val['newbymonth'] > 0) {
1135 $out .= ' &nbsp; <span class="opacitymedium">+'.$val['newbymonth'].' / '.$langs->trans("Month").'</span>';
1136 }
1137 $out .= '';
1138 $out .= '<br>';
1139 }
1140 print ' &nbsp; &nbsp; ';
1141
1142 $htmltooltip = $langs->trans("Detail").'<br>';
1143 $htmltooltip .= $out;
1144
1145 print $form->textwithtooltip($langs->trans('SoldeCPUser', (string) round($nb_holiday, 5)).' '.img_picto('', 'help'), $htmltooltip);
1146
1147 print '</div>';
1148 if (!empty($conf->use_javascript_ajax)) {
1149 print '<script>';
1150 print '$( document ).ready(function() {
1151 jQuery("#fuserid").change(function() {
1152 console.log("We change to user id "+jQuery("#fuserid").val());
1153 if (jQuery("#fuserid").val() == '.((int) $user->id).') {
1154 jQuery(".leaveuserbalance").show();
1155 } else {
1156 jQuery(".leaveuserbalance").hide();
1157 }
1158 });
1159 });';
1160 print '</script>';
1161 }
1162 } elseif (!is_numeric(getDolGlobalString('HOLIDAY_HIDE_BALANCE'))) {
1163 print '<div class="leaveuserbalance paddingtop">';
1164 print $langs->trans(getDolGlobalString('HOLIDAY_HIDE_BALANCE'));
1165 print '</div>';
1166 }
1167
1168 print '</td>';
1169 print '</tr>';
1170
1171 // Type
1172 print '<tr>';
1173 print '<td class="fieldrequired">'.$langs->trans("Type").'</td>';
1174 print '<td>';
1175 $typeleaves = $object->getTypes(1, -1);
1176 $arraytypeleaves = array();
1177 foreach ($typeleaves as $key => $val) {
1178 $labeltoshow = ($langs->trans($val['code']) != $val['code'] ? $langs->trans($val['code']) : $val['label']);
1179 $labeltoshow .= ($val['delay'] > 0 ? ' ('.$langs->trans("NoticePeriod").': '.$val['delay'].' '.$langs->trans("days").')' : '');
1180 $arraytypeleaves[$val['rowid']] = $labeltoshow;
1181 }
1182 if (empty($typeleaves)) {
1183 print $langs->trans("PleaseDefineSomeTypeOfHolidayFirst");
1184 } else {
1185 print $form->selectarray('type', $arraytypeleaves, (GETPOST('type', 'alpha') ? GETPOST('type', 'alpha') : ''), 1, 0, 0, '', 0, 0, 0, '', '', 1);
1186 if ($user->admin) {
1187 print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
1188 }
1189 }
1190 print '</td>';
1191 print '</tr>';
1192
1193 // Date start
1194 print '<tr>';
1195 print '<td class="fieldrequired">';
1196 print $form->textwithpicto($langs->trans("DateDebCP"), $langs->trans("FirstDayOfHoliday"));
1197 print '</td>';
1198 print '<td>'.img_picto('', 'action', 'class="pictofixedwidth"');
1199 if (!GETPOST('date_debut_')) { // If visitor does not come from agenda
1200 print $form->selectDate(-1, 'date_debut_', 0, 0, 0, '', 1, 1);
1201 } else {
1202 $tmpdate = GETPOSTDATE('date_debut_', '00:00:00');
1203 print $form->selectDate($tmpdate, 'date_debut_', 0, 0, 0, '', 1, 1);
1204 }
1205 print ' &nbsp; &nbsp; ';
1206 print $form->selectarray('starthalfday', $listhalfday, (GETPOST('starthalfday', 'alpha') ? GETPOST('starthalfday', 'alpha') : 'morning'));
1207 print '</td>';
1208 print '</tr>';
1209
1210 // Date end
1211 print '<tr>';
1212 print '<td class="fieldrequired">';
1213 print $form->textwithpicto($langs->trans("DateFinCP"), $langs->trans("LastDayOfHoliday"));
1214 print '</td>';
1215 print '<td>'.img_picto('', 'action', 'class="pictofixedwidth"');
1216 if (!GETPOST('date_fin_')) {
1217 print $form->selectDate(-1, 'date_fin_', 0, 0, 0, '', 1, 1);
1218 } else {
1219 $tmpdate = GETPOSTDATE('date_fin_', '00:00:00');
1220 print $form->selectDate($tmpdate, 'date_fin_', 0, 0, 0, '', 1, 1);
1221 }
1222 print ' &nbsp; &nbsp; ';
1223 print $form->selectarray('endhalfday', $listhalfday, (GETPOST('endhalfday', 'alpha') ? GETPOST('endhalfday', 'alpha') : 'afternoon'));
1224 print '</td>';
1225 print '</tr>';
1226
1227 // Approver
1228 print '<tr>';
1229 print '<td class="fieldrequired">'.$langs->trans("ReviewedByCP").'</td>';
1230 print '<td>';
1231
1232 $object = new Holiday($db);
1233 $include_users = $object->fetch_users_approver_holiday();
1234 if (empty($include_users)) {
1235 print img_warning().' '.$langs->trans("NobodyHasPermissionToValidateHolidays");
1236 } else {
1237 // Defined default approver (the forced approver of edited user or the supervisor of user if no forced value defined)
1238 // Note: This user will be set only if the defined approver has permission to approve so is inside include_users
1239 $defaultselectuser = (empty($user->fk_user_holiday_validator) ? $user->fk_user : $user->fk_user_holiday_validator);
1240 if ($fuserid != $user->id) {
1241 $fuser = new User($db);
1242 $fuser->fetch($fuserid);
1243 $defaultselectuser = (empty($fuser->fk_user_holiday_validator) ? $fuser->fk_user : $fuser->fk_user_holiday_validator);
1244 }
1245
1246 if (getDolGlobalString('HOLIDAY_DEFAULT_VALIDATOR')) {
1247 $defaultselectuser = getDolGlobalString('HOLIDAY_DEFAULT_VALIDATOR'); // Can force default approver
1248 }
1249 if (GETPOSTINT('valideur') > 0) {
1250 $defaultselectuser = GETPOSTINT('valideur');
1251 }
1252 $s = $form->select_dolusers($defaultselectuser, "valideur", 1, null, 0, $include_users, '', '0,'.$conf->entity, 0, 0, '', 0, '', 'minwidth200 maxwidth500');
1253 print img_picto('', 'user', 'class="pictofixedwidth"').$form->textwithpicto($s, $langs->trans("AnyOtherInThisListCanValidate"));
1254 }
1255
1256 //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
1257 print '</td>';
1258 print '</tr>';
1259
1260 // Description
1261 print '<tr>';
1262 print '<td>'.$langs->trans("DescCP").'</td>';
1263 print '<td class="tdtop">';
1264 $doleditor = new DolEditor('description', GETPOST('description', 'restricthtml'), '', 80, 'dolibarr_notes', 'In', false, false, isModEnabled('fckeditor'), ROWS_3, '90%');
1265 print $doleditor->Create(1);
1266 print '</td></tr>';
1267
1268 // Other attributes
1269 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php';
1270
1271 print '</tbody>';
1272 print '</table>';
1273
1274 print dol_get_fiche_end();
1275
1276 print $form->buttonsSaveCancel("SendRequestCP");
1277
1278 print '</from>'."\n";
1279 }
1280} else {
1281 if ($error && $action != 'edit') {
1282 print '<div class="tabBar">';
1283 print '<br><br><input type="button" value="'.$langs->trans("ReturnCP").'" class="button" onclick="history.go(-1)" />';
1284 print '</div>';
1285 } else {
1286 // Show page in view or edit mode
1287 if (($id > 0) || $ref) {
1288 $result = $object->fetch($id, $ref);
1289
1290 $approverexpected = new User($db);
1291 $approverexpected->fetch($object->fk_validator); // Use that should be the approver
1292
1293 $userRequest = new User($db);
1294 $userRequest->fetch($object->fk_user);
1295
1296 //print load_fiche_titre($langs->trans('TitreRequestCP'));
1297
1298 // Si il y a une erreur
1299 if (GETPOST('error')) {
1300 switch (GETPOST('error')) {
1301 case 'datefin':
1302 $errors[] = $langs->transnoentitiesnoconv('ErrorEndDateCP');
1303 break;
1304 case 'SQL_Create':
1305 $errors[] = $langs->transnoentitiesnoconv('ErrorSQLCreateCP');
1306 break;
1307 case 'CantCreate':
1308 $errors[] = $langs->transnoentitiesnoconv('CantCreateCP');
1309 break;
1310 case 'Valideur':
1311 $errors[] = $langs->transnoentitiesnoconv('InvalidValidatorCP');
1312 break;
1313 case 'nodatedebut':
1314 $errors[] = $langs->transnoentitiesnoconv('NoDateDebut');
1315 break;
1316 case 'nodatefin':
1317 $errors[] = $langs->transnoentitiesnoconv('NoDateFin');
1318 break;
1319 case 'DureeHoliday':
1320 $errors[] = $langs->transnoentitiesnoconv('ErrorDureeCP');
1321 break;
1322 case 'NoMotifRefuse':
1323 $errors[] = $langs->transnoentitiesnoconv('NoMotifRefuseCP');
1324 break;
1325 case 'mail':
1326 $errors[] = $langs->transnoentitiesnoconv('ErrorMailNotSend');
1327 break;
1328 }
1329
1330 setEventMessages(null, $errors, 'errors');
1331 }
1332
1333 // check if the user has the right to read this request
1334 if ($canread) {
1335 $head = holiday_prepare_head($object);
1336
1337 if (($action == 'edit' && $object->status == Holiday::STATUS_DRAFT) || ($action == 'editvalidator')) {
1338 if ($action == 'edit' && $object->status == Holiday::STATUS_DRAFT) {
1339 $edit = true;
1340 }
1341
1342 print '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">'."\n";
1343 print '<input type="hidden" name="token" value="'.newToken().'" />'."\n";
1344 print '<input type="hidden" name="action" value="update"/>'."\n";
1345 print '<input type="hidden" name="id" value="'.$object->id.'" />'."\n";
1346 }
1347
1348 print dol_get_fiche_head($head, 'card', $langs->trans("CPTitreMenu"), -1, 'holiday');
1349
1350 $linkback = '<a href="'.DOL_URL_ROOT.'/holiday/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
1351
1352 dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref');
1353
1354
1355 print '<div class="fichecenter">';
1356 print '<div class="fichehalfleft">';
1357 print '<div class="underbanner clearboth"></div>';
1358
1359 print '<table class="border tableforfield centpercent">';
1360 print '<tbody>';
1361
1362 // User
1363 print '<tr>';
1364 print '<td class="titlefield">'.$langs->trans("User").'</td>';
1365 print '<td>';
1366 print $userRequest->getNomUrl(-1, 'leave');
1367 print '</td></tr>';
1368
1369 // Type
1370 print '<tr>';
1371 print '<td>'.$langs->trans("Type").'</td>';
1372 print '<td>';
1373 $typeleaves = $object->getTypes(1, -1);
1374 if (empty($typeleaves[$object->fk_type])) {
1375 $labeltoshow = $langs->trans("TypeWasDisabledOrRemoved", $object->fk_type);
1376 } else {
1377 $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']);
1378 }
1379 print $labeltoshow;
1380 print '</td>';
1381 print '</tr>';
1382
1383 $starthalfday = ($object->halfday == -1 || $object->halfday == 2) ? 'afternoon' : 'morning';
1384 $endhalfday = ($object->halfday == 1 || $object->halfday == 2) ? 'morning' : 'afternoon';
1385
1386 if (!$edit) {
1387 print '<tr>';
1388 print '<td class="nowrap">';
1389 print $form->textwithpicto($langs->trans('DateDebCP'), $langs->trans("FirstDayOfHoliday"));
1390 print '</td>';
1391 print '<td>'.dol_print_date($object->date_debut, 'day');
1392 print ' &nbsp; &nbsp; ';
1393 print '<span class="opacitymedium">'.$langs->trans($listhalfday[$starthalfday]).'</span>';
1394 print '</td>';
1395 print '</tr>';
1396 } else {
1397 print '<tr>';
1398 print '<td class="nowrap">';
1399 print $form->textwithpicto($langs->trans('DateDebCP'), $langs->trans("FirstDayOfHoliday"));
1400 print '</td>';
1401 print '<td>';
1402 $tmpdate = GETPOSTDATE('date_debut_', '00:00:00');
1403 print $form->selectDate($tmpdate ? $tmpdate : $object->date_debut, 'date_debut_');
1404 print ' &nbsp; &nbsp; ';
1405 print $form->selectarray('starthalfday', $listhalfday, (GETPOST('starthalfday') ? GETPOST('starthalfday') : $starthalfday));
1406 print '</td>';
1407 print '</tr>';
1408 }
1409
1410 if (!$edit) {
1411 print '<tr>';
1412 print '<td class="nowrap">';
1413 print $form->textwithpicto($langs->trans('DateFinCP'), $langs->trans("LastDayOfHoliday"));
1414 print '</td>';
1415 print '<td>'.dol_print_date($object->date_fin, 'day');
1416 print ' &nbsp; &nbsp; ';
1417 print '<span class="opacitymedium">'.$langs->trans($listhalfday[$endhalfday]).'</span>';
1418 print '</td>';
1419 print '</tr>';
1420 } else {
1421 print '<tr>';
1422 print '<td class="nowrap">';
1423 print $form->textwithpicto($langs->trans('DateFinCP'), $langs->trans("LastDayOfHoliday"));
1424 print '</td>';
1425 print '<td>';
1426 print $form->selectDate($object->date_fin, 'date_fin_');
1427 print ' &nbsp; &nbsp; ';
1428 print $form->selectarray('endhalfday', $listhalfday, (GETPOST('endhalfday') ? GETPOST('endhalfday') : $endhalfday));
1429 print '</td>';
1430 print '</tr>';
1431 }
1432
1433 // Nb of days
1434 print '<tr>';
1435 print '<td>';
1436 $htmlhelp = $langs->trans('NbUseDaysCPHelp');
1437 $includesaturday = getDolGlobalInt('MAIN_NON_WORKING_DAYS_INCLUDE_SATURDAY', 1);
1438 $includesunday = getDolGlobalInt('MAIN_NON_WORKING_DAYS_INCLUDE_SUNDAY', 1);
1439 if ($includesaturday) {
1440 $htmlhelp .= '<br>'.$langs->trans("DayIsANonWorkingDay", $langs->trans("Saturday"));
1441 }
1442 if ($includesunday) {
1443 $htmlhelp .= '<br>'.$langs->trans("DayIsANonWorkingDay", $langs->trans("Sunday"));
1444 }
1445 print $form->textwithpicto($langs->trans('NbUseDaysCP'), $htmlhelp);
1446 print '</td>';
1447 print '<td>';
1448 print num_open_day($object->date_debut_gmt, $object->date_fin_gmt, 0, 1, (int) $object->halfday, $userRequest->country_id, $object->fk_user);
1449 print '</td>';
1450 print '</tr>';
1451
1452 if ($object->status == Holiday::STATUS_REFUSED) {
1453 print '<tr>';
1454 print '<td>'.$langs->trans('DetailRefusCP').'</td>';
1455 print '<td>'.$object->detail_refuse.'</td>';
1456 print '</tr>';
1457 }
1458
1459 // Description
1460 if (!$edit) {
1461 print '<tr>';
1462 print '<td>'.$langs->trans('DescCP').'</td>';
1463 print '<td>'.nl2br($object->description).'</td>';
1464 print '</tr>';
1465 } else {
1466 print '<tr>';
1467 print '<td>'.$langs->trans('DescCP').'</td>';
1468 print '<td class="tdtop">';
1469 $doleditor = new DolEditor('description', $object->description, '', 80, 'dolibarr_notes', 'In', false, false, isModEnabled('fckeditor'), ROWS_3, '90%');
1470 print $doleditor->Create(1);
1471 print '</td></tr>';
1472 }
1473
1474 // Other attributes
1475 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
1476
1477 print '</tbody>';
1478 print '</table>'."\n";
1479
1480 print '</div>';
1481 print '<div class="fichehalfright">';
1482
1483 print '<div class="underbanner clearboth"></div>';
1484
1485 // Info workflow
1486 print '<table class="border tableforfield centpercent">'."\n";
1487 print '<tbody>';
1488
1489 if (!empty($object->fk_user_create)) {
1490 $userCreate = new User($db);
1491 $userCreate->fetch($object->fk_user_create);
1492 print '<tr>';
1493 print '<td class="titlefield">'.$langs->trans('RequestByCP').'</td>';
1494 print '<td>'.$userCreate->getNomUrl(-1).'</td>';
1495 print '</tr>';
1496 }
1497
1498 // Approver
1499 if (!$edit && $action != 'editvalidator') {
1500 print '<tr>';
1501 print '<td class="titlefield">';
1503 print $langs->trans('ApprovedBy');
1504 } else {
1505 print $langs->trans('ReviewedByCP');
1506 }
1507 print '</td>';
1508 print '<td>';
1510 if ($object->fk_user_approve > 0) {
1511 $approverdone = new User($db);
1512 $approverdone->fetch($object->fk_user_approve);
1513 print $approverdone->getNomUrl(-1);
1514 }
1515 } else {
1516 print $approverexpected->getNomUrl(-1);
1517 }
1518 $include_users = $object->fetch_users_approver_holiday();
1519 if (is_array($include_users) && in_array($user->id, $include_users) && $object->status == Holiday::STATUS_VALIDATED) {
1520 print '<a class="editfielda paddingleft" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=editvalidator">'.img_edit($langs->trans("Edit")).'</a>';
1521 }
1522 print '</td>';
1523 print '</tr>';
1524 } else {
1525 print '<tr>';
1526 print '<td class="titlefield">'.$langs->trans('ReviewedByCP').'</td>'; // Will be approved by
1527 print '<td>';
1528 $include_users = $object->fetch_users_approver_holiday();
1529 if (!in_array($object->fk_validator, $include_users)) { // Add the current validator to the list to not lose it when editing.
1530 $include_users[] = $object->fk_validator;
1531 }
1532 if (empty($include_users)) {
1533 print img_warning().' '.$langs->trans("NobodyHasPermissionToValidateHolidays");
1534 } else {
1535 $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
1536 $s = $form->select_dolusers($object->fk_validator, "valideur", (($action == 'editvalidator') ? 0 : 1), $arrayofvalidatorstoexclude, 0, $include_users);
1537 print $form->textwithpicto($s, $langs->trans("AnyOtherInThisListCanValidate"));
1538 }
1539 if ($action == 'editvalidator') {
1540 print '<input type="submit" class="button button-save" name="savevalidator" value="'.$langs->trans("Save").'">';
1541 print '<input type="submit" class="button button-cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
1542 }
1543 print '</td>';
1544 print '</tr>';
1545 }
1546
1547 print '<tr>';
1548 print '<td>'.$langs->trans('DateCreation').'</td>';
1549 print '<td>'.dol_print_date($object->date_create, 'dayhour', 'tzuser').'</td>';
1550 print '</tr>';
1552 print '<tr>';
1553 print '<td>'.$langs->trans('DateValidCP').'</td>';
1554 print '<td>'.dol_print_date($object->date_approval, 'dayhour', 'tzuser').'</td>'; // warning: date_valid is approval date on holiday module
1555 print '</tr>';
1556 }
1557 if ($object->status == Holiday::STATUS_CANCELED) {
1558 print '<tr>';
1559 print '<td>'.$langs->trans('DateCancelCP').'</td>';
1560 print '<td>'.dol_print_date($object->date_cancel, 'dayhour', 'tzuser').'</td>';
1561 print '</tr>';
1562 }
1563 if ($object->status == Holiday::STATUS_REFUSED) {
1564 print '<tr>';
1565 print '<td>'.$langs->trans('DateRefusCP').'</td>';
1566 print '<td>'.dol_print_date($object->date_refuse, 'dayhour', 'tzuser').'</td>';
1567 print '</tr>';
1568 }
1569 print '</tbody>';
1570 print '</table>';
1571
1572 print '</div>';
1573 print '</div>';
1574
1575 print '<div class="clearboth"></div>';
1576
1577 print dol_get_fiche_end();
1578
1579
1580 // Confirmation messages
1581 if ($action == 'delete') {
1582 if ($candelete) {
1583 print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans("TitleDeleteCP"), $langs->trans("ConfirmDeleteCP"), "confirm_delete", '', 0, 1);
1584 }
1585 }
1586
1587 // Si envoi en validation
1588 if ($action == 'sendToValidate' && $object->status == Holiday::STATUS_DRAFT) {
1589 print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans("TitleToValidCP"), $langs->trans("ConfirmToValidCP"), "confirm_send", '', 1, 1);
1590 }
1591
1592 // Si validation de la demande
1593 if ($action == 'valid') {
1594 print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans("TitleValidCP"), $langs->trans("ConfirmValidCP"), "confirm_valid", '', 1, 1);
1595 }
1596
1597 // Si refus de la demande
1598 if ($action == 'refuse') {
1599 $array_input = array(array('type' => "text", 'label' => $langs->trans('DetailRefusCP'), 'name' => "detail_refuse", 'size' => "50", 'value' => ""));
1600 print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id."&action=confirm_refuse", $langs->trans("TitleRefuseCP"), $langs->trans('ConfirmRefuseCP'), "confirm_refuse", $array_input, 1, 0);
1601 }
1602
1603 // Si annulation de la demande
1604 if ($action == 'cancel') {
1605 print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans("TitleCancelCP"), $langs->trans("ConfirmCancelCP"), "confirm_cancel", '', 1, 1);
1606 }
1607
1608 // Si back to draft
1609 if ($action == 'backtodraft') {
1610 print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans("TitleSetToDraft"), $langs->trans("ConfirmSetToDraft"), "confirm_draft", '', 1, 1);
1611 }
1612
1613 if (($action == 'edit' && $object->status == Holiday::STATUS_DRAFT) || ($action == 'editvalidator')) {
1614 if ($action == 'edit' && $object->status == Holiday::STATUS_DRAFT) {
1615 if ($permissiontoadd && $object->status == Holiday::STATUS_DRAFT) {
1616 print $form->buttonsSaveCancel();
1617 }
1618 }
1619
1620 print '</form>';
1621 }
1622
1623 if (!$edit) {
1624 // Buttons for actions
1625
1626 print '<div class="tabsAction">';
1627
1628 if ($permissiontoadd && $object->status == Holiday::STATUS_DRAFT) {
1629 print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=edit&token='.newToken().'" class="butAction">'.$langs->trans("EditCP").'</a>';
1630 }
1631
1632 if ($permissiontoadd && $object->status == Holiday::STATUS_DRAFT) { // If draft
1633 print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=sendToValidate&token='.newToken().'" class="butAction">'.$langs->trans("Validate").'</a>';
1634 }
1635
1636 if ($object->status == Holiday::STATUS_VALIDATED) { // If validated
1637 // Button Approve / Refuse
1638 if (($user->id == $object->fk_validator || $permissiontoaddall) && $permissiontoapprove) {
1639 print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=valid&token='.newToken().'" class="butAction">'.$langs->trans("Approve").'</a>';
1640 print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=refuse&token='.newToken().'" class="butAction">'.$langs->trans("ActionRefuseCP").'</a>';
1641 } else {
1642 print '<a href="#" class="butActionRefused classfortooltip" title="'.$langs->trans("NotTheAssignedApprover").'">'.$langs->trans("Approve").'</a>';
1643 print '<a href="#" class="butActionRefused classfortooltip" title="'.$langs->trans("NotTheAssignedApprover").'">'.$langs->trans("ActionRefuseCP").'</a>';
1644
1645 // Button Cancel (because we can't approve)
1646 if ($permissiontoadd || $permissiontoaddall) {
1647 if (($object->date_fin > dol_now()) || !empty($user->admin)) {
1648 print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=cancel&token='.newToken().'" class="butAction">'.$langs->trans("ActionCancelCP").'</a>';
1649 } else {
1650 print '<a href="#" class="butActionRefused classfortooltip" title="'.$langs->trans("HolidayStarted").' - '.$langs->trans("NotAllowed").'">'.$langs->trans("ActionCancelCP").'</a>';
1651 }
1652 }
1653 }
1654 }
1655 if ($object->status == Holiday::STATUS_APPROVED) { // If validated and approved
1656 if ($user->id == $object->fk_validator || $user->id == $object->fk_user_approve || $permissiontoadd || $permissiontoaddall || $permissiontoapprove) {
1657 if ((($object->date_fin > dol_now()) && $permissiontoapprove) || $user->id == $object->fk_user_approve) {
1658 print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=cancel&token='.newToken().'" class="butAction">'.$langs->trans("ActionCancelCP").'</a>';
1659 } else {
1660 if ($object->date_fin <= dol_now() && $permissiontoapprove) {
1661 print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=cancel&token='.newToken().'" class="butAction">'.$langs->trans("ActionCancelCP").'</a>';
1662 } else {
1663 print '<a href="#" class="butActionRefused classfortooltip" title="'.$langs->trans("HolidayStarted").' - '.$langs->trans("NotAllowed").'">'.$langs->trans("ActionCancelCP").'</a>';
1664 }
1665 }
1666 } else { // I have no rights on the user of the holiday.
1667 print '<a href="#" class="butActionRefused classfortooltip" title="'.$langs->trans("NotAllowed").'">'.$langs->trans("ActionCancelCP").'</a>';
1668 }
1669 }
1670
1671 if (($permissiontoadd || $permissiontoaddall) && $object->status == Holiday::STATUS_CANCELED) {
1672 print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=backtodraft" class="butAction">'.$langs->trans("SetToDraft").'</a>';
1673 }
1674 if ($candelete) { // If draft or canceled or refused
1675 print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken().'" class="butActionDelete">'.$langs->trans("DeleteCP").'</a>';
1676 }
1677
1678 print '</div>';
1679 }
1680 } else {
1681 print '<div class="tabBar">';
1682 print $langs->trans('ErrorUserViewCP');
1683 print '<br><br><input type="button" value="'.$langs->trans("ReturnCP").'" class="button" onclick="history.go(-1)" />';
1684 print '</div>';
1685 }
1686 } else {
1687 print '<div class="tabBar">';
1688 print $langs->trans('ErrorIDFicheCP');
1689 print '<br><br><input type="button" value="'.$langs->trans("ReturnCP").'" class="button" onclick="history.go(-1)" />';
1690 print '</div>';
1691 }
1692
1693
1694 // Select mail models is same action as presend
1695 if (GETPOST('modelselected')) {
1696 $action = 'presend';
1697 }
1698
1699 if ($action != 'presend' && $action != 'edit') {
1700 print '<div class="fichecenter"><div class="fichehalfleft">';
1701 print '<a name="builddoc"></a>'; // ancre
1702
1703 // Documents
1704 /* $includedocgeneration = 0;
1705 if ($includedocgeneration) {
1706 $objref = dol_sanitizeFileName($object->ref);
1707 $relativepath = $objref.'/'.$objref.'.pdf';
1708 $filedir = $conf->holiday->dir_output.'/'.$object->element.'/'.$objref;
1709 $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
1710 $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
1711 $delallowed = ($user->hasRight('holiday', 'write') && $object->fk_user == $user->id) || $user->hasRight('holiday', 'writeall_advance'); // If you can create/edit, you can remove a file on card
1712 print $formfile->showdocuments('holiday:Holiday', $object->element.'/'.$objref, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', '', '', $langs->defaultlang);
1713 } */
1714
1715 // Show links to link elements
1716 //$tmparray = $form->showLinkToObjectBlock($object, null, array('myobject'), 1);
1717 //$somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
1718
1719
1720 print '</div><div class="fichehalfright">';
1721
1722 $MAXEVENT = 10;
1723
1724 // TODO Add the page holiday_agenda.php
1725 //$morehtmlcenter = dolGetButtonTitle($langs->trans('SeeAll'), '', 'fa fa-bars imgforviewmode', DOL_URL_ROOT.'/holiday/holiday_agenda.php?id='.$object->id);
1726 $morehtmlcenter = '';
1727
1728 // List of actions on element
1729 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
1730 $formactions = new FormActions($db);
1731 $somethingshown = $formactions->showactions($object, $object->element, (is_object($object->thirdparty) ? $object->thirdparty->id : 0), 1, '', $MAXEVENT, '', $morehtmlcenter);
1732
1733 print '</div></div>';
1734 }
1735 }
1736}
1737
1738// End of page
1739llxFooter();
1740
1741if (is_object($db)) {
1742 $db->close();
1743}
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
Class to send emails (with attachments or not) Usage: $mailfile = new CMailFile($subject,...
Class to manage a WYSIWYG editor.
Class to manage building of HTML components.
Class to offer components to list and upload files.
Class to manage generation of HTML components Only common components must be here.
Class of the module paid holiday.
const STATUS_VALIDATED
Validated status.
const STATUS_DRAFT
Draft status.
const STATUS_REFUSED
Refused.
const STATUS_CANCELED
Canceled.
const STATUS_APPROVED
Approved.
Class to manage Dolibarr users.
num_open_day($timestampStart, $timestampEnd, $inhour=0, $lastday=0, $halfday=0, $countryCodeOrId='', $user_id=0)
Function to return number of working days (and text of units) between two dates (working days)
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
Definition date.lib.php:126
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
dol_now($mode='gmt')
Return date for now.
getDolGlobalFloat($key, $default=0)
Return a Dolibarr global constant float value.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
GETPOSTDATE($prefix, $hourTime='', $gm='auto', $saverestore='')
Helper function that combines values of a dolibarr DatePicker (such as Form\selectDate) for year,...
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='', $textonpictotooltip='')
Show information in HTML for admin users or standard users.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_eval($s, $returnvalue=1, $hideerrors=1, $onlysimplestring='1')
Replace eval function to add more security.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_escape_js($stringtoescape, $mode=0, $noescapebackslashn=0)
Returns text escaped for inclusion into JavaScript code.
dolGetFirstLastname($firstname, $lastname, $nameorder=-1)
Return firstname and lastname in correct order.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_clone($srcobject, $native=2)
Create a clone of instance of object (new instance with same value for each properties) With native =...
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
img_edit($titlealt='default', $float=0, $other='')
Show logo edit/modify fiche.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
holiday_prepare_head($object)
Return array head with list of tabs to view object information.
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:487
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.