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