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