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