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