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