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