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