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