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 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 } else {
710 $db->rollback();
711 $action = '';
712 }
713
714 header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
715 exit;
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 approver of edited user or the supervisor of user if no forced value defined)
1201 // Note: This user will be set only if the defined approver 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 ($fuserid != $user->id) {
1204 $fuser = new User($db);
1205 $fuser->fetch($fuserid);
1206 $defaultselectuser = (empty($fuser->fk_user_holiday_validator) ? $fuser->fk_user : $fuser->fk_user_holiday_validator);
1207 }
1208
1209 if (getDolGlobalString('HOLIDAY_DEFAULT_VALIDATOR')) {
1210 $defaultselectuser = getDolGlobalString('HOLIDAY_DEFAULT_VALIDATOR'); // Can force default approver
1211 }
1212 if (GETPOSTINT('valideur') > 0) {
1213 $defaultselectuser = GETPOSTINT('valideur');
1214 }
1215 $s = $form->select_dolusers($defaultselectuser, "valideur", 1, '', 0, $include_users, '', '0,'.$conf->entity, 0, 0, '', 0, '', 'minwidth200 maxwidth500');
1216 print img_picto('', 'user', 'class="pictofixedwidth"').$form->textwithpicto($s, $langs->trans("AnyOtherInThisListCanValidate"));
1217 }
1218
1219 //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
1220 print '</td>';
1221 print '</tr>';
1222
1223 // Description
1224 print '<tr>';
1225 print '<td>'.$langs->trans("DescCP").'</td>';
1226 print '<td class="tdtop">';
1227 $doleditor = new DolEditor('description', GETPOST('description', 'restricthtml'), '', 80, 'dolibarr_notes', 'In', false, false, isModEnabled('fckeditor'), ROWS_3, '90%');
1228 print $doleditor->Create(1);
1229 print '</td></tr>';
1230
1231 // Other attributes
1232 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php';
1233
1234 print '</tbody>';
1235 print '</table>';
1236
1237 print dol_get_fiche_end();
1238
1239 print $form->buttonsSaveCancel("SendRequestCP");
1240
1241 print '</from>'."\n";
1242 }
1243} else {
1244 if ($error && $action != 'edit') {
1245 print '<div class="tabBar">';
1246 print $error;
1247 print '<br><br><input type="button" value="'.$langs->trans("ReturnCP").'" class="button" onclick="history.go(-1)" />';
1248 print '</div>';
1249 } else {
1250 // Show page in view or edit mode
1251 if (($id > 0) || $ref) {
1252 $result = $object->fetch($id, $ref);
1253
1254 $approverexpected = new User($db);
1255 $approverexpected->fetch($object->fk_validator); // Use that should be the approver
1256
1257 $userRequest = new User($db);
1258 $userRequest->fetch($object->fk_user);
1259
1260 //print load_fiche_titre($langs->trans('TitreRequestCP'));
1261
1262 // Si il y a une erreur
1263 if (GETPOST('error')) {
1264 switch (GETPOST('error')) {
1265 case 'datefin':
1266 $errors[] = $langs->transnoentitiesnoconv('ErrorEndDateCP');
1267 break;
1268 case 'SQL_Create':
1269 $errors[] = $langs->transnoentitiesnoconv('ErrorSQLCreateCP');
1270 break;
1271 case 'CantCreate':
1272 $errors[] = $langs->transnoentitiesnoconv('CantCreateCP');
1273 break;
1274 case 'Valideur':
1275 $errors[] = $langs->transnoentitiesnoconv('InvalidValidatorCP');
1276 break;
1277 case 'nodatedebut':
1278 $errors[] = $langs->transnoentitiesnoconv('NoDateDebut');
1279 break;
1280 case 'nodatefin':
1281 $errors[] = $langs->transnoentitiesnoconv('NoDateFin');
1282 break;
1283 case 'DureeHoliday':
1284 $errors[] = $langs->transnoentitiesnoconv('ErrorDureeCP');
1285 break;
1286 case 'NoMotifRefuse':
1287 $errors[] = $langs->transnoentitiesnoconv('NoMotifRefuseCP');
1288 break;
1289 case 'mail':
1290 $errors[] = $langs->transnoentitiesnoconv('ErrorMailNotSend');
1291 break;
1292 }
1293
1294 setEventMessages(null, $errors, 'errors');
1295 }
1296
1297 // check if the user has the right to read this request
1298 if ($canread) {
1300
1301 if (($action == 'edit' && $object->status == Holiday::STATUS_DRAFT) || ($action == 'editvalidator')) {
1302 if ($action == 'edit' && $object->status == Holiday::STATUS_DRAFT) {
1303 $edit = true;
1304 }
1305
1306 print '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">'."\n";
1307 print '<input type="hidden" name="token" value="'.newToken().'" />'."\n";
1308 print '<input type="hidden" name="action" value="update"/>'."\n";
1309 print '<input type="hidden" name="id" value="'.$object->id.'" />'."\n";
1310 }
1311
1312 print dol_get_fiche_head($head, 'card', $langs->trans("CPTitreMenu"), -1, 'holiday');
1313
1314 $linkback = '<a href="'.DOL_URL_ROOT.'/holiday/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
1315
1316 dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref');
1317
1318
1319 print '<div class="fichecenter">';
1320 print '<div class="fichehalfleft">';
1321 print '<div class="underbanner clearboth"></div>';
1322
1323 print '<table class="border tableforfield centpercent">';
1324 print '<tbody>';
1325
1326 // User
1327 print '<tr>';
1328 print '<td class="titlefield">'.$langs->trans("User").'</td>';
1329 print '<td>';
1330 print $userRequest->getNomUrl(-1, 'leave');
1331 print '</td></tr>';
1332
1333 // Type
1334 print '<tr>';
1335 print '<td>'.$langs->trans("Type").'</td>';
1336 print '<td>';
1337 $typeleaves = $object->getTypes(1, -1);
1338 if (empty($typeleaves[$object->fk_type])) {
1339 $labeltoshow = $langs->trans("TypeWasDisabledOrRemoved", $object->fk_type);
1340 } else {
1341 $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']);
1342 }
1343 print $labeltoshow;
1344 print '</td>';
1345 print '</tr>';
1346
1347 $starthalfday = ($object->halfday == -1 || $object->halfday == 2) ? 'afternoon' : 'morning';
1348 $endhalfday = ($object->halfday == 1 || $object->halfday == 2) ? 'morning' : 'afternoon';
1349
1350 if (!$edit) {
1351 print '<tr>';
1352 print '<td class="nowrap">';
1353 print $form->textwithpicto($langs->trans('DateDebCP'), $langs->trans("FirstDayOfHoliday"));
1354 print '</td>';
1355 print '<td>'.dol_print_date($object->date_debut, 'day');
1356 print ' &nbsp; &nbsp; ';
1357 print '<span class="opacitymedium">'.$langs->trans($listhalfday[$starthalfday]).'</span>';
1358 print '</td>';
1359 print '</tr>';
1360 } else {
1361 print '<tr>';
1362 print '<td class="nowrap">';
1363 print $form->textwithpicto($langs->trans('DateDebCP'), $langs->trans("FirstDayOfHoliday"));
1364 print '</td>';
1365 print '<td>';
1366 $tmpdate = GETPOSTDATE('date_debut_', '00:00:00');
1367 print $form->selectDate($tmpdate ? $tmpdate : $object->date_debut, 'date_debut_');
1368 print ' &nbsp; &nbsp; ';
1369 print $form->selectarray('starthalfday', $listhalfday, (GETPOST('starthalfday') ? GETPOST('starthalfday') : $starthalfday));
1370 print '</td>';
1371 print '</tr>';
1372 }
1373
1374 if (!$edit) {
1375 print '<tr>';
1376 print '<td class="nowrap">';
1377 print $form->textwithpicto($langs->trans('DateFinCP'), $langs->trans("LastDayOfHoliday"));
1378 print '</td>';
1379 print '<td>'.dol_print_date($object->date_fin, 'day');
1380 print ' &nbsp; &nbsp; ';
1381 print '<span class="opacitymedium">'.$langs->trans($listhalfday[$endhalfday]).'</span>';
1382 print '</td>';
1383 print '</tr>';
1384 } else {
1385 print '<tr>';
1386 print '<td class="nowrap">';
1387 print $form->textwithpicto($langs->trans('DateFinCP'), $langs->trans("LastDayOfHoliday"));
1388 print '</td>';
1389 print '<td>';
1390 print $form->selectDate($object->date_fin, 'date_fin_');
1391 print ' &nbsp; &nbsp; ';
1392 print $form->selectarray('endhalfday', $listhalfday, (GETPOST('endhalfday') ? GETPOST('endhalfday') : $endhalfday));
1393 print '</td>';
1394 print '</tr>';
1395 }
1396
1397 // Nb of days
1398 print '<tr>';
1399 print '<td>';
1400 $htmlhelp = $langs->trans('NbUseDaysCPHelp');
1401 $includesaturday = getDolGlobalInt('MAIN_NON_WORKING_DAYS_INCLUDE_SATURDAY', 1);
1402 $includesunday = getDolGlobalInt('MAIN_NON_WORKING_DAYS_INCLUDE_SUNDAY', 1);
1403 if ($includesaturday) {
1404 $htmlhelp .= '<br>'.$langs->trans("DayIsANonWorkingDay", $langs->trans("Saturday"));
1405 }
1406 if ($includesunday) {
1407 $htmlhelp .= '<br>'.$langs->trans("DayIsANonWorkingDay", $langs->trans("Sunday"));
1408 }
1409 print $form->textwithpicto($langs->trans('NbUseDaysCP'), $htmlhelp);
1410 print '</td>';
1411 print '<td>';
1412 print num_open_day($object->date_debut_gmt, $object->date_fin_gmt, 0, 1, $object->halfday);
1413 print '</td>';
1414 print '</tr>';
1415
1416 if ($object->status == Holiday::STATUS_REFUSED) {
1417 print '<tr>';
1418 print '<td>'.$langs->trans('DetailRefusCP').'</td>';
1419 print '<td>'.$object->detail_refuse.'</td>';
1420 print '</tr>';
1421 }
1422
1423 // Description
1424 if (!$edit) {
1425 print '<tr>';
1426 print '<td>'.$langs->trans('DescCP').'</td>';
1427 print '<td>'.nl2br($object->description).'</td>';
1428 print '</tr>';
1429 } else {
1430 print '<tr>';
1431 print '<td>'.$langs->trans('DescCP').'</td>';
1432 print '<td class="tdtop">';
1433 $doleditor = new DolEditor('description', $object->description, '', 80, 'dolibarr_notes', 'In', false, false, isModEnabled('fckeditor'), ROWS_3, '90%');
1434 print $doleditor->Create(1);
1435 print '</td></tr>';
1436 }
1437
1438 // Other attributes
1439 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
1440
1441 print '</tbody>';
1442 print '</table>'."\n";
1443
1444 print '</div>';
1445 print '<div class="fichehalfright">';
1446
1447 print '<div class="underbanner clearboth"></div>';
1448
1449 // Info workflow
1450 print '<table class="border tableforfield centpercent">'."\n";
1451 print '<tbody>';
1452
1453 if (!empty($object->fk_user_create)) {
1454 $userCreate = new User($db);
1455 $userCreate->fetch($object->fk_user_create);
1456 print '<tr>';
1457 print '<td class="titlefield">'.$langs->trans('RequestByCP').'</td>';
1458 print '<td>'.$userCreate->getNomUrl(-1).'</td>';
1459 print '</tr>';
1460 }
1461
1462 // Approver
1463 if (!$edit && $action != 'editvalidator') {
1464 print '<tr>';
1465 print '<td class="titlefield">';
1467 print $langs->trans('ApprovedBy');
1468 } else {
1469 print $langs->trans('ReviewedByCP');
1470 }
1471 print '</td>';
1472 print '<td>';
1474 if ($object->fk_user_approve > 0) {
1475 $approverdone = new User($db);
1476 $approverdone->fetch($object->fk_user_approve);
1477 print $approverdone->getNomUrl(-1);
1478 }
1479 } else {
1480 print $approverexpected->getNomUrl(-1);
1481 }
1482 $include_users = $object->fetch_users_approver_holiday();
1483 if (is_array($include_users) && in_array($user->id, $include_users) && $object->status == Holiday::STATUS_VALIDATED) {
1484 print '<a class="editfielda paddingleft" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=editvalidator">'.img_edit($langs->trans("Edit")).'</a>';
1485 }
1486 print '</td>';
1487 print '</tr>';
1488 } else {
1489 print '<tr>';
1490 print '<td class="titlefield">'.$langs->trans('ReviewedByCP').'</td>'; // Will be approved by
1491 print '<td>';
1492 $include_users = $object->fetch_users_approver_holiday();
1493 if (!in_array($object->fk_validator, $include_users)) { // Add the current validator to the list to not lose it when editing.
1494 $include_users[] = $object->fk_validator;
1495 }
1496 if (empty($include_users)) {
1497 print img_warning().' '.$langs->trans("NobodyHasPermissionToValidateHolidays");
1498 } else {
1499 $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.
1500 $s = $form->select_dolusers($object->fk_validator, "valideur", (($action == 'editvalidator') ? 0 : 1), $arrayofvalidatorstoexclude, 0, $include_users);
1501 print $form->textwithpicto($s, $langs->trans("AnyOtherInThisListCanValidate"));
1502 }
1503 if ($action == 'editvalidator') {
1504 print '<input type="submit" class="button button-save" name="savevalidator" value="'.$langs->trans("Save").'">';
1505 print '<input type="submit" class="button button-cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
1506 }
1507 print '</td>';
1508 print '</tr>';
1509 }
1510
1511 print '<tr>';
1512 print '<td>'.$langs->trans('DateCreation').'</td>';
1513 print '<td>'.dol_print_date($object->date_create, 'dayhour', 'tzuser').'</td>';
1514 print '</tr>';
1516 print '<tr>';
1517 print '<td>'.$langs->trans('DateValidCP').'</td>';
1518 print '<td>'.dol_print_date($object->date_approval, 'dayhour', 'tzuser').'</td>'; // warning: date_valid is approval date on holiday module
1519 print '</tr>';
1520 }
1521 if ($object->status == Holiday::STATUS_CANCELED) {
1522 print '<tr>';
1523 print '<td>'.$langs->trans('DateCancelCP').'</td>';
1524 print '<td>'.dol_print_date($object->date_cancel, 'dayhour', 'tzuser').'</td>';
1525 print '</tr>';
1526 }
1527 if ($object->status == Holiday::STATUS_REFUSED) {
1528 print '<tr>';
1529 print '<td>'.$langs->trans('DateRefusCP').'</td>';
1530 print '<td>'.dol_print_date($object->date_refuse, 'dayhour', 'tzuser').'</td>';
1531 print '</tr>';
1532 }
1533 print '</tbody>';
1534 print '</table>';
1535
1536 print '</div>';
1537 print '</div>';
1538
1539 print '<div class="clearboth"></div>';
1540
1541 print dol_get_fiche_end();
1542
1543
1544 // Confirmation messages
1545 if ($action == 'delete') {
1546 if ($candelete) {
1547 print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans("TitleDeleteCP"), $langs->trans("ConfirmDeleteCP"), "confirm_delete", '', 0, 1);
1548 }
1549 }
1550
1551 // Si envoi en validation
1552 if ($action == 'sendToValidate' && $object->status == Holiday::STATUS_DRAFT) {
1553 print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans("TitleToValidCP"), $langs->trans("ConfirmToValidCP"), "confirm_send", '', 1, 1);
1554 }
1555
1556 // Si validation de la demande
1557 if ($action == 'valid') {
1558 print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans("TitleValidCP"), $langs->trans("ConfirmValidCP"), "confirm_valid", '', 1, 1);
1559 }
1560
1561 // Si refus de la demande
1562 if ($action == 'refuse') {
1563 $array_input = array(array('type'=>"text", 'label'=> $langs->trans('DetailRefusCP'), 'name'=>"detail_refuse", 'size'=>"50", 'value'=>""));
1564 print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id."&action=confirm_refuse", $langs->trans("TitleRefuseCP"), $langs->trans('ConfirmRefuseCP'), "confirm_refuse", $array_input, 1, 0);
1565 }
1566
1567 // Si annulation de la demande
1568 if ($action == 'cancel') {
1569 print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans("TitleCancelCP"), $langs->trans("ConfirmCancelCP"), "confirm_cancel", '', 1, 1);
1570 }
1571
1572 // Si back to draft
1573 if ($action == 'backtodraft') {
1574 print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans("TitleSetToDraft"), $langs->trans("ConfirmSetToDraft"), "confirm_draft", '', 1, 1);
1575 }
1576
1577 if (($action == 'edit' && $object->status == Holiday::STATUS_DRAFT) || ($action == 'editvalidator')) {
1578 if ($action == 'edit' && $object->status == Holiday::STATUS_DRAFT) {
1579 if ($permissiontoadd && $object->status == Holiday::STATUS_DRAFT) {
1580 print $form->buttonsSaveCancel();
1581 }
1582 }
1583
1584 print '</form>';
1585 }
1586
1587 if (!$edit) {
1588 // Buttons for actions
1589
1590 print '<div class="tabsAction">';
1591
1592 if ($permissiontoadd && $object->status == Holiday::STATUS_DRAFT) {
1593 print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=edit&token='.newToken().'" class="butAction">'.$langs->trans("EditCP").'</a>';
1594 }
1595
1596 if ($permissiontoadd && $object->status == Holiday::STATUS_DRAFT) { // If draft
1597 print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=sendToValidate&token='.newToken().'" class="butAction">'.$langs->trans("Validate").'</a>';
1598 }
1599
1600 if ($object->status == Holiday::STATUS_VALIDATED) { // If validated
1601 // Button Approve / Refuse
1602 if (($user->id == $object->fk_validator || $permissiontoaddall) && $user->hasRight('holiday', 'approve')) {
1603 print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=valid&token='.newToken().'" class="butAction">'.$langs->trans("Approve").'</a>';
1604 print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=refuse&token='.newToken().'" class="butAction">'.$langs->trans("ActionRefuseCP").'</a>';
1605 } else {
1606 print '<a href="#" class="butActionRefused classfortooltip" title="'.$langs->trans("NotTheAssignedApprover").'">'.$langs->trans("Approve").'</a>';
1607 print '<a href="#" class="butActionRefused classfortooltip" title="'.$langs->trans("NotTheAssignedApprover").'">'.$langs->trans("ActionRefuseCP").'</a>';
1608
1609 // Button Cancel (because we can't approve)
1610 if ($permissiontoadd || $permissiontoaddall) {
1611 if (($object->date_fin > dol_now()) || !empty($user->admin)) {
1612 print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=cancel&token='.newToken().'" class="butAction">'.$langs->trans("ActionCancelCP").'</a>';
1613 } else {
1614 print '<a href="#" class="butActionRefused classfortooltip" title="'.$langs->trans("HolidayStarted").'-'.$langs->trans("NotAllowed").'">'.$langs->trans("ActionCancelCP").'</a>';
1615 }
1616 }
1617 }
1618 }
1619 if ($object->status == Holiday::STATUS_APPROVED) { // If validated and approved
1620 if ($user->id == $object->fk_validator || $user->id == $object->fk_user_approve || $permissiontoadd || $permissiontoaddall) {
1621 if (($object->date_fin > dol_now()) || !empty($user->admin) || $user->id == $object->fk_user_approve) {
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("HolidayStarted").'-'.$langs->trans("NotAllowed").'">'.$langs->trans("ActionCancelCP").'</a>';
1625 }
1626 } else { // I have no rights on the user of the holiday.
1627 if (!empty($user->admin)) { // If current approver can't cancel an approved leave, we allow admin user
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("NotAllowed").'">'.$langs->trans("ActionCancelCP").'</a>';
1631 }
1632 }
1633 }
1634
1635 if (($permissiontoadd || $permissiontoaddall) && $object->status == Holiday::STATUS_CANCELED) {
1636 print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=backtodraft" class="butAction">'.$langs->trans("SetToDraft").'</a>';
1637 }
1638 if ($candelete && ($object->status == Holiday::STATUS_DRAFT || $object->status == Holiday::STATUS_CANCELED || $object->status == Holiday::STATUS_REFUSED)) { // If draft or canceled or refused
1639 print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken().'" class="butActionDelete">'.$langs->trans("DeleteCP").'</a>';
1640 }
1641
1642 print '</div>';
1643 }
1644 } else {
1645 print '<div class="tabBar">';
1646 print $langs->trans('ErrorUserViewCP');
1647 print '<br><br><input type="button" value="'.$langs->trans("ReturnCP").'" class="button" onclick="history.go(-1)" />';
1648 print '</div>';
1649 }
1650 } else {
1651 print '<div class="tabBar">';
1652 print $langs->trans('ErrorIDFicheCP');
1653 print '<br><br><input type="button" value="'.$langs->trans("ReturnCP").'" class="button" onclick="history.go(-1)" />';
1654 print '</div>';
1655 }
1656
1657
1658 // Select mail models is same action as presend
1659 if (GETPOST('modelselected')) {
1660 $action = 'presend';
1661 }
1662
1663 if ($action != 'presend' && $action != 'edit') {
1664 print '<div class="fichecenter"><div class="fichehalfleft">';
1665 print '<a name="builddoc"></a>'; // ancre
1666
1667 // Documents
1668 /* $includedocgeneration = 0;
1669 if ($includedocgeneration) {
1670 $objref = dol_sanitizeFileName($object->ref);
1671 $relativepath = $objref.'/'.$objref.'.pdf';
1672 $filedir = $conf->holiday->dir_output.'/'.$object->element.'/'.$objref;
1673 $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
1674 $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
1675 $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
1676 print $formfile->showdocuments('holiday:Holiday', $object->element.'/'.$objref, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', '', '', $langs->defaultlang);
1677 } */
1678
1679 // Show links to link elements
1680 //$tmparray = $form->showLinkToObjectBlock($object, null, array('myobject'), 1);
1681 //$somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
1682
1683
1684 print '</div><div class="fichehalfright">';
1685
1686 $MAXEVENT = 10;
1687
1688 // TODO Add the page holiday_agenda.php
1689 //$morehtmlcenter = dolGetButtonTitle($langs->trans('SeeAll'), '', 'fa fa-bars imgforviewmode', DOL_URL_ROOT.'/holiday/holiday_agenda.php?id='.$object->id);
1690 $morehtmlcenter = '';
1691
1692 // List of actions on element
1693 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
1694 $formactions = new FormActions($db);
1695 $somethingshown = $formactions->showactions($object, $object->element, (is_object($object->thirdparty) ? $object->thirdparty->id : 0), 1, '', $MAXEVENT, '', $morehtmlcenter);
1696
1697 print '</div></div>';
1698 }
1699 }
1700}
1701
1702// End of page
1703llxFooter();
1704
1705if (is_object($db)) {
1706 $db->close();
1707}
$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.