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