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