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