dolibarr 23.0.3
holiday.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2011 Dimitri Mouillard <dmouillard@teclib.com>
3 * Copyright (C) 2012-2014 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2012-2016 Regis Houssin <regis.houssin@inodbox.com>
5 * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
6 * Copyright (C) 2016 Juanjo Menent <jmenent@2byte.es>
7 * Copyright (C) 2018-2025 Frédéric France <frederic.france@free.fr>
8 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 */
23
29require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
30
31
35class Holiday extends CommonObject
36{
40 public $element = 'holiday';
41
46 public $TRIGGER_PREFIX = 'HOLIDAY';
47
51 public $table_element = 'holiday';
52
56 public $fk_element = 'fk_holiday';
57
61 public $picto = 'holiday';
62
66 public $fk_user;
67
71 public $date_create = '';
72
76 public $description;
77
81 public $date_debut = '';
82
86 public $date_fin = '';
87
91 public $date_debut_gmt = '';
92
96 public $date_fin_gmt = '';
97
101 public $halfday = '';
102
107 public $statut = 0;
108
112 public $fk_validator;
113
117 public $date_valid = 0;
118
122 public $fk_user_valid;
123
127 public $date_approval;
128
132 public $fk_user_approve;
133
137 public $date_refuse = 0;
138
142 public $fk_user_refuse;
143
147 public $date_cancel = 0;
148
152 public $fk_user_cancel;
153
157 public $fk_user_create;
158
162 public $detail_refuse = '';
163
167 public $fk_type;
168
169 public $holiday = array();
170 public $events = array();
171
175 public $logs = array();
176
177
181 const STATUS_DRAFT = 1;
197 const STATUS_REFUSED = 5;
198
199
205 public function __construct($db)
206 {
207 $this->db = $db;
208
209 $this->ismultientitymanaged = 0;
210 }
211
212
220 public function getNextNumRef($objsoc)
221 {
222 global $langs, $conf;
223 $langs->load("order");
224
225 if (!getDolGlobalString('HOLIDAY_ADDON')) {
226 $conf->global->HOLIDAY_ADDON = 'mod_holiday_madonna';
227 }
228
229 if (getDolGlobalString('HOLIDAY_ADDON')) {
230 $mybool = false;
231
232 $file = getDolGlobalString('HOLIDAY_ADDON') . ".php";
233 $classname = getDolGlobalString('HOLIDAY_ADDON');
234
235 // Include file with class
236 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
237 foreach ($dirmodels as $reldir) {
238 $dir = dol_buildpath($reldir."core/modules/holiday/");
239
240 // Load file with numbering class (if found)
241 $mybool = ((bool) @include_once $dir.$file) || $mybool;
242 }
243
244 if (!$mybool) {
245 dol_print_error(null, "Failed to include file ".$file);
246 return '';
247 }
248
249 $obj = new $classname();
250 '@phan-var-force ModelNumRefHolidays $obj';
251 $numref = $obj->getNextValue($objsoc, $this);
252
253 if ($numref != "") {
254 return $numref;
255 } else {
256 $this->error = $obj->error;
257 //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
258 return "";
259 }
260 } else {
261 print $langs->trans("Error")." ".$langs->trans("Error_HOLIDAY_ADDON_NotDefined");
262 return "";
263 }
264 }
265
271 public function updateBalance()
272 {
273 $this->db->begin();
274
275 // Update sold of vocations
276 $result = $this->updateSoldeCP();
277
278 // Check nb of users into table llx_holiday_users and update with empty lines
279 //if ($result > 0) $result = $this->verifNbUsers($this->countActiveUsersWithoutCP(), $this->getConfCP('nbUser'));
280
281 if ($result >= 0) {
282 $this->db->commit();
283 return 0; // for cronjob use (0 is OK, any other value is an error code)
284 } else {
285 $this->db->rollback();
286 return -1;
287 }
288 }
289
297 public function create($user, $notrigger = 0)
298 {
299 global $conf;
300 $error = 0;
301
302 $now = dol_now();
303
304 // Check parameters
305 if (empty($this->fk_user) || !is_numeric($this->fk_user) || $this->fk_user < 0) {
306 $this->error = "ErrorBadParameterFkUser";
307 return -1;
308 }
309 if (empty($this->fk_validator) || !is_numeric($this->fk_validator) || $this->fk_validator < 0) {
310 $this->error = "ErrorBadParameterFkValidator";
311 return -1;
312 }
313 if (empty($this->fk_type) || !is_numeric($this->fk_type) || $this->fk_type < 0) {
314 $this->error = "ErrorBadParameterFkType";
315 return -1;
316 }
317
318 // Insert request
319 $sql = "INSERT INTO ".MAIN_DB_PREFIX."holiday(";
320 $sql .= "ref,";
321 $sql .= "fk_user,";
322 $sql .= "date_create,";
323 $sql .= "description,";
324 $sql .= "date_debut,";
325 $sql .= "date_fin,";
326 $sql .= "halfday,";
327 $sql .= "statut,";
328 $sql .= "fk_validator,";
329 $sql .= "fk_type,";
330 $sql .= "fk_user_create,";
331 $sql .= "entity";
332 $sql .= ") VALUES (";
333 $sql .= "'(PROV)',";
334 $sql .= " ".((int) $this->fk_user).",";
335 $sql .= " '".$this->db->idate($now)."',";
336 $sql .= " '".$this->db->escape($this->description)."',";
337 $sql .= " '".$this->db->idate($this->date_debut)."',";
338 $sql .= " '".$this->db->idate($this->date_fin)."',";
339 $sql .= " ".((int) $this->halfday).",";
340 $sql .= " '1',";
341 $sql .= " ".((int) $this->fk_validator).",";
342 $sql .= " ".((int) $this->fk_type).",";
343 $sql .= " ".((int) $user->id).",";
344 $sql .= " ".((int) $conf->entity);
345 $sql .= ")";
346
347 $this->db->begin();
348
349 dol_syslog(get_class($this)."::create", LOG_DEBUG);
350 $resql = $this->db->query($sql);
351 if (!$resql) {
352 $error++;
353 $this->errors[] = "Error ".$this->db->lasterror();
354 }
355
356 if (!$error) {
357 $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."holiday");
358
359 if ($this->id) {
360 // update ref
361 $initialref = '(PROV'.$this->id.')';
362 if (!empty($this->ref)) {
363 $initialref = $this->ref;
364 }
365
366 $sql = 'UPDATE '.MAIN_DB_PREFIX."holiday SET ref='".$this->db->escape($initialref)."' WHERE rowid=".((int) $this->id);
367 if ($this->db->query($sql)) {
368 $this->ref = $initialref;
369
370 if (!$error) {
371 $result = $this->insertExtraFields();
372 if ($result < 0) {
373 $error++;
374 }
375 }
376
377 if (!$error && !$notrigger) {
378 // Call trigger
379 $result = $this->call_trigger('HOLIDAY_CREATE', $user);
380 if ($result < 0) {
381 $error++;
382 }
383 // End call triggers
384 }
385 }
386 }
387 }
388
389 // Commit or rollback
390 if ($error) {
391 foreach ($this->errors as $errmsg) {
392 dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR);
393 $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
394 }
395 $this->db->rollback();
396 return -1 * $error;
397 } else {
398 $this->db->commit();
399 return $this->id;
400 }
401 }
402
403
411 public function fetch($id, $ref = '')
412 {
413 $sql = "SELECT";
414 $sql .= " cp.rowid,";
415 $sql .= " cp.ref,";
416 $sql .= " cp.fk_user,";
417 $sql .= " cp.date_create,";
418 $sql .= " cp.description,";
419 $sql .= " cp.date_debut,";
420 $sql .= " cp.date_fin,";
421 $sql .= " cp.halfday,";
422 $sql .= " cp.statut as status,";
423 $sql .= " cp.fk_validator,";
424 $sql .= " cp.date_valid,";
425 $sql .= " cp.fk_user_valid,";
426 $sql .= " cp.date_approval,";
427 $sql .= " cp.fk_user_approve,";
428 $sql .= " cp.date_refuse,";
429 $sql .= " cp.fk_user_refuse,";
430 $sql .= " cp.date_cancel,";
431 $sql .= " cp.fk_user_cancel,";
432 $sql .= " cp.detail_refuse,";
433 $sql .= " cp.note_private,";
434 $sql .= " cp.note_public,";
435 $sql .= " cp.fk_user_create,";
436 $sql .= " cp.fk_type,";
437 $sql .= " cp.entity";
438 $sql .= " FROM ".MAIN_DB_PREFIX."holiday as cp";
439 if ($id > 0) {
440 $sql .= " WHERE cp.rowid = ".((int) $id);
441 } else {
442 $sql .= " WHERE cp.ref = '".$this->db->escape($ref)."'";
443 }
444
445 dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
446 $resql = $this->db->query($sql);
447 if ($resql) {
448 if ($this->db->num_rows($resql)) {
449 $obj = $this->db->fetch_object($resql);
450
451 $this->id = $obj->rowid;
452 $this->ref = ($obj->ref ? $obj->ref : $obj->rowid);
453 $this->fk_user = $obj->fk_user;
454 $this->date_create = $this->db->jdate($obj->date_create);
455 $this->description = $obj->description;
456 $this->date_debut = $this->db->jdate($obj->date_debut);
457 $this->date_fin = $this->db->jdate($obj->date_fin);
458 $this->date_debut_gmt = $this->db->jdate($obj->date_debut, 1);
459 $this->date_fin_gmt = $this->db->jdate($obj->date_fin, 1);
460 $this->halfday = $obj->halfday;
461 $this->status = $obj->status;
462 $this->statut = $obj->status; // deprecated
463 $this->fk_validator = $obj->fk_validator;
464 $this->date_valid = $this->db->jdate($obj->date_valid);
465 $this->fk_user_valid = $obj->fk_user_valid;
466 $this->user_validation_id = $obj->fk_user_valid;
467 $this->date_approval = $this->db->jdate($obj->date_approval);
468 $this->fk_user_approve = $obj->fk_user_approve;
469 $this->date_refuse = $this->db->jdate($obj->date_refuse);
470 $this->fk_user_refuse = $obj->fk_user_refuse;
471 $this->date_cancel = $this->db->jdate($obj->date_cancel);
472 $this->fk_user_cancel = $obj->fk_user_cancel;
473 $this->detail_refuse = $obj->detail_refuse;
474 $this->note_private = $obj->note_private;
475 $this->note_public = $obj->note_public;
476 $this->fk_user_create = $obj->fk_user_create;
477 $this->fk_type = $obj->fk_type;
478 $this->entity = $obj->entity;
479
480 $this->fetch_optionals();
481
482 $result = 1;
483 } else {
484 $result = 0;
485 }
486 $this->db->free($resql);
487
488 return $result;
489 } else {
490 $this->error = "Error ".$this->db->lasterror();
491 return -1;
492 }
493 }
494
503 public function fetchByUser($user_id, $order = '', $filter = '')
504 {
505 $this->holiday = [];
506 $sql = "SELECT";
507 $sql .= " cp.rowid,";
508 $sql .= " cp.ref,";
509
510 $sql .= " cp.fk_user,";
511 $sql .= " cp.fk_type,";
512 $sql .= " cp.date_create,";
513 $sql .= " cp.description,";
514 $sql .= " cp.date_debut,";
515 $sql .= " cp.date_fin,";
516 $sql .= " cp.halfday,";
517 $sql .= " cp.statut as status,";
518 $sql .= " cp.fk_validator,";
519 $sql .= " cp.date_valid,";
520 $sql .= " cp.fk_user_valid,";
521 $sql .= " cp.date_approval,";
522 $sql .= " cp.fk_user_approve,";
523 $sql .= " cp.date_refuse,";
524 $sql .= " cp.fk_user_refuse,";
525 $sql .= " cp.date_cancel,";
526 $sql .= " cp.fk_user_cancel,";
527 $sql .= " cp.detail_refuse,";
528
529 $sql .= " uu.lastname as user_lastname,";
530 $sql .= " uu.firstname as user_firstname,";
531 $sql .= " uu.login as user_login,";
532 $sql .= " uu.statut as user_status,";
533 $sql .= " uu.photo as user_photo,";
534
535 $sql .= " ua.lastname as validator_lastname,";
536 $sql .= " ua.firstname as validator_firstname,";
537 $sql .= " ua.login as validator_login,";
538 $sql .= " ua.statut as validator_status,";
539 $sql .= " ua.photo as validator_photo";
540
541 $sql .= " FROM ".MAIN_DB_PREFIX."holiday as cp, ".MAIN_DB_PREFIX."user as uu, ".MAIN_DB_PREFIX."user as ua";
542 $sql .= " WHERE cp.entity IN (".getEntity('holiday').")";
543 $sql .= " AND cp.fk_user = uu.rowid AND cp.fk_validator = ua.rowid"; // Hack pour la recherche sur le tableau
544 $sql .= " AND cp.fk_user IN (".$this->db->sanitize($user_id).")";
545
546 // Selection filter
547 if (!empty($filter)) {
548 $sql .= $filter;
549 }
550
551 // Order of display of the result
552 if (!empty($order)) {
553 $sql .= $order;
554 }
555
556 dol_syslog(get_class($this)."::fetchByUser", LOG_DEBUG);
557 $resql = $this->db->query($sql);
558
559 // If no SQL error
560 if ($resql) {
561 $i = 0;
562 $tab_result = $this->holiday;
563 $num = $this->db->num_rows($resql);
564
565 // If no registration
566 if (!$num) {
567 return 2;
568 }
569
570 // List the records and add them to the table
571 while ($i < $num) {
572 $obj = $this->db->fetch_object($resql);
573
574 $tab_result[$i]['rowid'] = $obj->rowid;
575 $tab_result[$i]['id'] = $obj->rowid;
576 $tab_result[$i]['ref'] = ($obj->ref ? $obj->ref : $obj->rowid);
577
578 $tab_result[$i]['fk_user'] = $obj->fk_user;
579 $tab_result[$i]['fk_type'] = $obj->fk_type;
580 $tab_result[$i]['date_create'] = $this->db->jdate($obj->date_create);
581 $tab_result[$i]['description'] = $obj->description;
582 $tab_result[$i]['date_debut'] = $this->db->jdate($obj->date_debut);
583 $tab_result[$i]['date_fin'] = $this->db->jdate($obj->date_fin);
584 $tab_result[$i]['date_debut_gmt'] = $this->db->jdate($obj->date_debut, 1);
585 $tab_result[$i]['date_fin_gmt'] = $this->db->jdate($obj->date_fin, 1);
586 $tab_result[$i]['halfday'] = $obj->halfday;
587 $tab_result[$i]['statut'] = $obj->status;
588 $tab_result[$i]['status'] = $obj->status;
589 $tab_result[$i]['fk_validator'] = $obj->fk_validator;
590 $tab_result[$i]['date_valid'] = $this->db->jdate($obj->date_valid);
591 $tab_result[$i]['fk_user_valid'] = $obj->fk_user_valid;
592 $tab_result[$i]['date_approval'] = $this->db->jdate($obj->date_approval);
593 $tab_result[$i]['fk_user_approve'] = $obj->fk_user_approve;
594 $tab_result[$i]['date_refuse'] = $this->db->jdate($obj->date_refuse);
595 $tab_result[$i]['fk_user_refuse'] = $obj->fk_user_refuse;
596 $tab_result[$i]['date_cancel'] = $this->db->jdate($obj->date_cancel);
597 $tab_result[$i]['fk_user_cancel'] = $obj->fk_user_cancel;
598 $tab_result[$i]['detail_refuse'] = $obj->detail_refuse;
599
600 $tab_result[$i]['user_firstname'] = $obj->user_firstname;
601 $tab_result[$i]['user_lastname'] = $obj->user_lastname;
602 $tab_result[$i]['user_login'] = $obj->user_login;
603 $tab_result[$i]['user_statut'] = $obj->user_status;
604 $tab_result[$i]['user_status'] = $obj->user_status;
605 $tab_result[$i]['user_photo'] = $obj->user_photo;
606
607 $tab_result[$i]['validator_firstname'] = $obj->validator_firstname;
608 $tab_result[$i]['validator_lastname'] = $obj->validator_lastname;
609 $tab_result[$i]['validator_login'] = $obj->validator_login;
610 $tab_result[$i]['validator_statut'] = $obj->validator_status;
611 $tab_result[$i]['validator_status'] = $obj->validator_status;
612 $tab_result[$i]['validator_photo'] = $obj->validator_photo;
613
614 $i++;
615 }
616
617 // Returns 1 with the filled array
618 $this->holiday = $tab_result;
619 return 1;
620 } else {
621 // SQL Error
622 $this->error = "Error ".$this->db->lasterror();
623 return -1;
624 }
625 }
626
634 public function fetchAll($order, $filter)
635 {
636 $sql = "SELECT";
637 $sql .= " cp.rowid,";
638 $sql .= " cp.ref,";
639 $sql .= " cp.fk_user,";
640 $sql .= " cp.fk_type,";
641 $sql .= " cp.date_create,";
642 $sql .= " cp.tms as date_modification,";
643 $sql .= " cp.description,";
644 $sql .= " cp.date_debut,";
645 $sql .= " cp.date_fin,";
646 $sql .= " cp.halfday,";
647 $sql .= " cp.statut as status,";
648 $sql .= " cp.fk_validator,";
649 $sql .= " cp.date_valid,";
650 $sql .= " cp.fk_user_valid,";
651 $sql .= " cp.date_approval,";
652 $sql .= " cp.fk_user_approve,";
653 $sql .= " cp.date_refuse,";
654 $sql .= " cp.fk_user_refuse,";
655 $sql .= " cp.date_cancel,";
656 $sql .= " cp.fk_user_cancel,";
657 $sql .= " cp.detail_refuse,";
658
659 $sql .= " uu.lastname as user_lastname,";
660 $sql .= " uu.firstname as user_firstname,";
661 $sql .= " uu.login as user_login,";
662 $sql .= " uu.statut as user_status,";
663 $sql .= " uu.photo as user_photo,";
664
665 $sql .= " ua.lastname as validator_lastname,";
666 $sql .= " ua.firstname as validator_firstname,";
667 $sql .= " ua.login as validator_login,";
668 $sql .= " ua.statut as validator_status,";
669 $sql .= " ua.photo as validator_photo";
670
671 $sql .= " FROM ".MAIN_DB_PREFIX."holiday as cp, ".MAIN_DB_PREFIX."user as uu, ".MAIN_DB_PREFIX."user as ua";
672 $sql .= " WHERE cp.entity IN (".getEntity('holiday').")";
673 $sql .= " AND cp.fk_user = uu.rowid AND cp.fk_validator = ua.rowid "; // Hack pour la recherche sur le tableau
674
675 // Selection filtering
676 if (!empty($filter)) {
677 $sql .= $filter;
678 }
679
680 // order of display
681 if (!empty($order)) {
682 $sql .= $order;
683 }
684
685 dol_syslog(get_class($this)."::fetchAll", LOG_DEBUG);
686 $resql = $this->db->query($sql);
687
688 // If no SQL error
689 if ($resql) {
690 $i = 0;
691 $tab_result = $this->holiday;
692 $num = $this->db->num_rows($resql);
693
694 // If no registration
695 if (!$num) {
696 return 2;
697 }
698
699 // List the records and add them to the table
700 while ($i < $num) {
701 $obj = $this->db->fetch_object($resql);
702
703 $tab_result[$i]['rowid'] = $obj->rowid;
704 $tab_result[$i]['id'] = $obj->rowid;
705 $tab_result[$i]['ref'] = ($obj->ref ? $obj->ref : $obj->rowid);
706
707 $tab_result[$i]['fk_user'] = $obj->fk_user;
708 $tab_result[$i]['fk_type'] = $obj->fk_type;
709 $tab_result[$i]['date_create'] = $this->db->jdate($obj->date_create);
710 $tab_result[$i]['date_modification'] = $this->db->jdate($obj->date_modification);
711 $tab_result[$i]['description'] = $obj->description;
712 $tab_result[$i]['date_debut'] = $this->db->jdate($obj->date_debut);
713 $tab_result[$i]['date_fin'] = $this->db->jdate($obj->date_fin);
714 $tab_result[$i]['date_debut_gmt'] = $this->db->jdate($obj->date_debut, 1);
715 $tab_result[$i]['date_fin_gmt'] = $this->db->jdate($obj->date_fin, 1);
716 $tab_result[$i]['halfday'] = $obj->halfday;
717 $tab_result[$i]['statut'] = $obj->status;
718 $tab_result[$i]['status'] = $obj->status;
719 $tab_result[$i]['fk_validator'] = $obj->fk_validator;
720 $tab_result[$i]['date_valid'] = $this->db->jdate($obj->date_valid);
721 $tab_result[$i]['fk_user_valid'] = $obj->fk_user_valid;
722 $tab_result[$i]['date_approval'] = $this->db->jdate($obj->date_approval);
723 $tab_result[$i]['fk_user_approve'] = $obj->fk_user_approve;
724 $tab_result[$i]['date_refuse'] = $obj->date_refuse;
725 $tab_result[$i]['fk_user_refuse'] = $obj->fk_user_refuse;
726 $tab_result[$i]['date_cancel'] = $obj->date_cancel;
727 $tab_result[$i]['fk_user_cancel'] = $obj->fk_user_cancel;
728 $tab_result[$i]['detail_refuse'] = $obj->detail_refuse;
729
730 $tab_result[$i]['user_firstname'] = $obj->user_firstname;
731 $tab_result[$i]['user_lastname'] = $obj->user_lastname;
732 $tab_result[$i]['user_login'] = $obj->user_login;
733 $tab_result[$i]['user_statut'] = $obj->user_status;
734 $tab_result[$i]['user_status'] = $obj->user_status;
735 $tab_result[$i]['user_photo'] = $obj->user_photo;
736
737 $tab_result[$i]['validator_firstname'] = $obj->validator_firstname;
738 $tab_result[$i]['validator_lastname'] = $obj->validator_lastname;
739 $tab_result[$i]['validator_login'] = $obj->validator_login;
740 $tab_result[$i]['validator_statut'] = $obj->validator_status;
741 $tab_result[$i]['validator_status'] = $obj->validator_status;
742 $tab_result[$i]['validator_photo'] = $obj->validator_photo;
743
744 $i++;
745 }
746 // Returns 1 and adds the array to the variable
747 $this->holiday = $tab_result;
748 return 1;
749 } else {
750 // SQL Error
751 $this->error = "Error ".$this->db->lasterror();
752 return -1;
753 }
754 }
755
756
764 public function validate($user = null, $notrigger = 0)
765 {
766 global $conf, $langs;
767 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
768 $error = 0;
769
770
771 $checkBalance = getDictionaryValue('c_holiday_types', 'block_if_negative', $this->fk_type, true);
772
773 if ($checkBalance > 0) {
774 $balance = $this->getCPforUser($this->fk_user, $this->fk_type);
775 $daysAsked = num_open_day($this->date_debut, $this->date_fin, 0, 1);
776
777 if (($balance - $daysAsked) < 0 && getDolGlobalString('HOLIDAY_DISALLOW_NEGATIVE_BALANCE')) {
778 $this->error = 'LeaveRequestCreationBlockedBecauseBalanceIsNegative';
779 return -1;
780 }
781 }
782
783 // Define new ref
784 if (preg_match('/^[\‍(]?PROV/i', $this->ref) || empty($this->ref) || $this->ref == $this->id) {
785 $num = $this->getNextNumRef(null);
786 } else {
787 $num = (string) $this->ref;
788 }
789 $this->newref = dol_sanitizeFileName($num);
790
791 // Update status
792 $sql = "UPDATE ".MAIN_DB_PREFIX."holiday SET";
793 $sql .= " fk_user_valid = ".((int) $user->id).",";
794 $sql .= " date_valid = '".$this->db->idate(dol_now())."',";
795 if (!empty($this->status) && is_numeric($this->status)) {
796 $sql .= " statut = ".((int) $this->status).",";
797 } else {
798 $this->error = 'Property status must be a numeric value';
799 $error++;
800 }
801 $sql .= " ref = '".$this->db->escape($num)."'";
802 $sql .= " WHERE rowid = ".((int) $this->id);
803
804 $this->db->begin();
805
806 dol_syslog(get_class($this)."::validate", LOG_DEBUG);
807 $resql = $this->db->query($sql);
808 if (!$resql) {
809 $error++;
810 $this->errors[] = "Error ".$this->db->lasterror();
811 }
812
813 if (!$error) {
814 if (!$notrigger) {
815 // Call trigger
816 $result = $this->call_trigger('HOLIDAY_VALIDATE', $user);
817 if ($result < 0) {
818 $error++;
819 }
820 // End call triggers
821 }
822 }
823
824 if (!$error) {
825 $this->oldref = $this->ref;
826
827 // Rename directory if dir was a temporary ref
828 if (preg_match('/^[\‍(]?PROV/i', $this->ref)) {
829 // Now we rename also files into index
830 $sql = 'UPDATE ' . MAIN_DB_PREFIX . "ecm_files set filename = CONCAT('" . $this->db->escape($this->newref) . "', SUBSTR(filename, " . (strlen($this->ref) + 1) . ")), filepath = 'holiday/" . $this->db->escape($this->newref) . "'";
831 $sql .= " WHERE filename LIKE '" . $this->db->escape($this->ref) . "%' AND filepath = 'holiday/" . $this->db->escape($this->ref) . "' and entity = " . ((int) $conf->entity);
832 $resql = $this->db->query($sql);
833 if (!$resql) {
834 $error++;
835 $this->error = $this->db->lasterror();
836 }
837 $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filepath = 'holiday/".$this->db->escape($this->newref)."'";
838 $sql .= " WHERE filepath = 'holiday/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
839 $resql = $this->db->query($sql);
840 if (!$resql) {
841 $error++;
842 $this->error = $this->db->lasterror();
843 }
844
845 // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
846 $oldref = dol_sanitizeFileName($this->ref);
847 $newref = dol_sanitizeFileName($num);
848 $dirsource = $conf->holiday->multidir_output[$this->entity] . '/' . $oldref;
849 $dirdest = $conf->holiday->multidir_output[$this->entity] . '/' . $newref;
850 if (!$error && file_exists($dirsource)) {
851 dol_syslog(get_class($this) . "::validate rename dir " . $dirsource . " into " . $dirdest);
852 if (@rename($dirsource, $dirdest)) {
853 dol_syslog("Rename ok");
854 // Rename docs starting with $oldref with $newref
855 $listoffiles = dol_dir_list($dirdest, 'files', 1, '^' . preg_quote($oldref, '/'));
856 foreach ($listoffiles as $fileentry) {
857 $dirsource = $fileentry['name'];
858 $dirdest = preg_replace('/^' . preg_quote($oldref, '/') . '/', $newref, $dirsource);
859 $dirsource = $fileentry['path'] . '/' . $dirsource;
860 $dirdest = $fileentry['path'] . '/' . $dirdest;
861 @rename($dirsource, $dirdest);
862 }
863 }
864 }
865 }
866 }
867
868
869 // Commit or rollback
870 if ($error) {
871 foreach ($this->errors as $errmsg) {
872 dol_syslog(get_class($this)."::validate ".$errmsg, LOG_ERR);
873 $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
874 }
875 $this->db->rollback();
876 return -1 * $error;
877 } else {
878 $this->db->commit();
879 return 1;
880 }
881 }
882
883
891 public function approve($user = null, $notrigger = 0)
892 {
893 $error = 0;
894
895 $checkBalance = getDictionaryValue('c_holiday_types', 'block_if_negative', $this->fk_type, true);
896
897 if ($checkBalance > 0) {
898 $balance = $this->getCPforUser($this->fk_user, $this->fk_type);
899 $daysAsked = num_open_day($this->date_debut, $this->date_fin, 0, 1);
900
901 if (($balance - $daysAsked) < 0 && getDolGlobalString('HOLIDAY_DISALLOW_NEGATIVE_BALANCE')) {
902 $this->error = 'LeaveRequestCreationBlockedBecauseBalanceIsNegative';
903 return -1;
904 }
905 }
906
907 // Update request
908 $sql = "UPDATE ".MAIN_DB_PREFIX."holiday SET";
909 $sql .= " description= '".$this->db->escape($this->description)."',";
910 if (!empty($this->date_debut)) {
911 $sql .= " date_debut = '".$this->db->idate($this->date_debut)."',";
912 } else {
913 $error++;
914 }
915 if (!empty($this->date_fin)) {
916 $sql .= " date_fin = '".$this->db->idate($this->date_fin)."',";
917 } else {
918 $error++;
919 }
920 $sql .= " halfday = ".((int) $this->halfday).",";
921 if (!empty($this->status) && is_numeric($this->status)) {
922 $sql .= " statut = ".((int) $this->status).",";
923 } else {
924 $error++;
925 }
926 if (!empty($this->fk_validator)) {
927 $sql .= " fk_validator = ".((int) $this->fk_validator).",";
928 } else {
929 $error++;
930 }
931 if (!empty($this->date_valid)) {
932 $sql .= " date_valid = '".$this->db->idate($this->date_valid)."',";
933 } else {
934 $sql .= " date_valid = NULL,";
935 }
936 if (!empty($this->fk_user_valid)) {
937 $sql .= " fk_user_valid = ".((int) $this->fk_user_valid).",";
938 } else {
939 $sql .= " fk_user_valid = NULL,";
940 }
941 if (!empty($this->date_approval)) {
942 $sql .= " date_approval = '".$this->db->idate($this->date_approval)."',";
943 } else {
944 $sql .= " date_approval = NULL,";
945 }
946 if (!empty($this->fk_user_approve)) {
947 $sql .= " fk_user_approve = ".((int) $this->fk_user_approve).",";
948 } else {
949 $sql .= " fk_user_approve = NULL,";
950 }
951 if (!empty($this->date_refuse)) {
952 $sql .= " date_refuse = '".$this->db->idate($this->date_refuse)."',";
953 } else {
954 $sql .= " date_refuse = NULL,";
955 }
956 if (!empty($this->fk_user_refuse)) {
957 $sql .= " fk_user_refuse = ".((int) $this->fk_user_refuse).",";
958 } else {
959 $sql .= " fk_user_refuse = NULL,";
960 }
961 if (!empty($this->date_cancel)) {
962 $sql .= " date_cancel = '".$this->db->idate($this->date_cancel)."',";
963 } else {
964 $sql .= " date_cancel = NULL,";
965 }
966 if (!empty($this->fk_user_cancel)) {
967 $sql .= " fk_user_cancel = ".((int) $this->fk_user_cancel).",";
968 } else {
969 $sql .= " fk_user_cancel = NULL,";
970 }
971 if (!empty($this->detail_refuse)) {
972 $sql .= " detail_refuse = '".$this->db->escape($this->detail_refuse)."'";
973 } else {
974 $sql .= " detail_refuse = NULL";
975 }
976 $sql .= " WHERE rowid = ".((int) $this->id);
977
978 $this->db->begin();
979
980 dol_syslog(get_class($this)."::approve", LOG_DEBUG);
981 $resql = $this->db->query($sql);
982 if (!$resql) {
983 $error++;
984 $this->errors[] = "Error ".$this->db->lasterror();
985 }
986
987 if (!$error) {
988 if (!$notrigger) {
989 // Call trigger
990 $result = $this->call_trigger('HOLIDAY_APPROVE', $user);
991 if ($result < 0) {
992 $error++;
993 }
994 // End call triggers
995 }
996 }
997
998 // Commit or rollback
999 if ($error) {
1000 foreach ($this->errors as $errmsg) {
1001 dol_syslog(get_class($this)."::approve ".$errmsg, LOG_ERR);
1002 $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
1003 }
1004 $this->db->rollback();
1005 return -1 * $error;
1006 } else {
1007 $this->db->commit();
1008 return 1;
1009 }
1010 }
1011
1019 public function update($user = null, $notrigger = 0)
1020 {
1021 global $conf, $langs;
1022 $error = 0;
1023
1024 $checkBalance = getDictionaryValue('c_holiday_types', 'block_if_negative', $this->fk_type, true);
1025
1026 if ($checkBalance > 0 && $this->statut != self::STATUS_DRAFT && $this->statut != self::STATUS_CANCELED) {
1027 $balance = $this->getCPforUser($this->fk_user, $this->fk_type);
1028 $daysAsked = num_open_day($this->date_debut, $this->date_fin, 0, 1);
1029
1030 if (($balance - $daysAsked) < 0 && getDolGlobalString('HOLIDAY_DISALLOW_NEGATIVE_BALANCE')) {
1031 $this->error = 'LeaveRequestCreationBlockedBecauseBalanceIsNegative';
1032 return -1;
1033 }
1034 }
1035
1036 // Update request
1037 $sql = "UPDATE ".MAIN_DB_PREFIX."holiday SET";
1038
1039 $sql .= " description= '".$this->db->escape($this->description)."',";
1040
1041 if (!empty($this->date_debut)) {
1042 $sql .= " date_debut = '".$this->db->idate($this->date_debut)."',";
1043 } else {
1044 $error++;
1045 }
1046 if (!empty($this->date_fin)) {
1047 $sql .= " date_fin = '".$this->db->idate($this->date_fin)."',";
1048 } else {
1049 $error++;
1050 }
1051 $sql .= " halfday = ".((int) $this->halfday).",";
1052 if (!empty($this->status) && is_numeric($this->status)) {
1053 $sql .= " statut = ".((int) $this->status).",";
1054 } else {
1055 $error++;
1056 }
1057 if (!empty($this->fk_validator)) {
1058 $sql .= " fk_validator = ".((int) $this->fk_validator).",";
1059 } else {
1060 $error++;
1061 }
1062 if (!empty($this->date_valid)) {
1063 $sql .= " date_valid = '".$this->db->idate($this->date_valid)."',";
1064 } else {
1065 $sql .= " date_valid = NULL,";
1066 }
1067 if (!empty($this->fk_user_valid)) {
1068 $sql .= " fk_user_valid = ".((int) $this->fk_user_valid).",";
1069 } else {
1070 $sql .= " fk_user_valid = NULL,";
1071 }
1072 if (!empty($this->date_approval)) {
1073 $sql .= " date_approval = '".$this->db->idate($this->date_approval)."',";
1074 } else {
1075 $sql .= " date_approval = NULL,";
1076 }
1077 if (!empty($this->fk_user_approve)) {
1078 $sql .= " fk_user_approve = ".((int) $this->fk_user_approve).",";
1079 } else {
1080 $sql .= " fk_user_approve = NULL,";
1081 }
1082 if (!empty($this->date_refuse)) {
1083 $sql .= " date_refuse = '".$this->db->idate($this->date_refuse)."',";
1084 } else {
1085 $sql .= " date_refuse = NULL,";
1086 }
1087 if (!empty($this->fk_user_refuse)) {
1088 $sql .= " fk_user_refuse = ".((int) $this->fk_user_refuse).",";
1089 } else {
1090 $sql .= " fk_user_refuse = NULL,";
1091 }
1092 if (!empty($this->date_cancel)) {
1093 $sql .= " date_cancel = '".$this->db->idate($this->date_cancel)."',";
1094 } else {
1095 $sql .= " date_cancel = NULL,";
1096 }
1097 if (!empty($this->fk_user_cancel)) {
1098 $sql .= " fk_user_cancel = ".((int) $this->fk_user_cancel).",";
1099 } else {
1100 $sql .= " fk_user_cancel = NULL,";
1101 }
1102 if (!empty($this->detail_refuse)) {
1103 $sql .= " detail_refuse = '".$this->db->escape($this->detail_refuse)."'";
1104 } else {
1105 $sql .= " detail_refuse = NULL";
1106 }
1107
1108 $sql .= " WHERE rowid = ".((int) $this->id);
1109
1110 $this->db->begin();
1111
1112 dol_syslog(get_class($this)."::update", LOG_DEBUG);
1113 $resql = $this->db->query($sql);
1114 if (!$resql) {
1115 $error++;
1116 $this->errors[] = "Error ".$this->db->lasterror();
1117 }
1118
1119 if (!$error) {
1120 $result = $this->insertExtraFields();
1121 if ($result < 0) {
1122 $error++;
1123 }
1124 }
1125
1126 if (!$error) {
1127 if (!$notrigger && $user !== null) {
1128 // Call trigger
1129 $result = $this->call_trigger('HOLIDAY_MODIFY', $user);
1130 if ($result < 0) {
1131 $error++;
1132 }
1133 // End call triggers
1134 }
1135 }
1136
1137 // Commit or rollback
1138 if ($error) {
1139 foreach ($this->errors as $errmsg) {
1140 dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
1141 $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
1142 }
1143 $this->db->rollback();
1144 return -1 * $error;
1145 } else {
1146 $this->db->commit();
1147 return 1;
1148 }
1149 }
1150
1151
1159 public function delete($user, $notrigger = 0)
1160 {
1161 global $conf, $langs;
1162 $error = 0;
1163
1164 $sql = "DELETE FROM ".MAIN_DB_PREFIX."holiday";
1165 $sql .= " WHERE rowid=".((int) $this->id);
1166
1167 $this->db->begin();
1168
1169 dol_syslog(get_class($this)."::delete", LOG_DEBUG);
1170 $resql = $this->db->query($sql);
1171 if (!$resql) {
1172 $error++;
1173 $this->errors[] = "Error ".$this->db->lasterror();
1174 }
1175
1176 if (!$error) {
1177 if (!$notrigger) {
1178 // Call trigger
1179 $result = $this->call_trigger('HOLIDAY_DELETE', $user);
1180 if ($result < 0) {
1181 $error++;
1182 }
1183 // End call triggers
1184 }
1185 }
1186
1187 // Commit or rollback
1188 if ($error) {
1189 foreach ($this->errors as $errmsg) {
1190 dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR);
1191 $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
1192 }
1193 $this->db->rollback();
1194 return -1 * $error;
1195 } else {
1196 $this->db->commit();
1197 return 1;
1198 }
1199 }
1200
1214 public function verifDateHolidayCP($fk_user, $dateStart, $dateEnd, $halfday = 0)
1215 {
1216 $this->fetchByUser($fk_user, '', '');
1217
1218 foreach ($this->holiday as $infos_CP) {
1219 if ($infos_CP['statut'] == Holiday::STATUS_CANCELED) {
1220 continue; // ignore not validated holidays
1221 }
1222 if ($infos_CP['statut'] == Holiday::STATUS_REFUSED) {
1223 continue; // ignore refused holidays
1224 }
1225 //var_dump("--");
1226 //var_dump("old: ".dol_print_date($infos_CP['date_debut'],'dayhour').' '.dol_print_date($infos_CP['date_fin'],'dayhour').' '.$infos_CP['halfday']);
1227 //var_dump("new: ".dol_print_date($dateStart,'dayhour').' '.dol_print_date($dateEnd,'dayhour').' '.$halfday);
1228
1229 if ($halfday == 0) {
1230 if ($dateStart >= $infos_CP['date_debut'] && $dateStart <= $infos_CP['date_fin']) {
1231 return false;
1232 }
1233 if ($dateEnd <= $infos_CP['date_fin'] && $dateEnd >= $infos_CP['date_debut']) {
1234 return false;
1235 }
1236 } elseif ($halfday == -1) {
1237 // new start afternoon, new end afternoon
1238 if ($dateStart >= $infos_CP['date_debut'] && $dateStart <= $infos_CP['date_fin']) {
1239 if ($dateStart < $infos_CP['date_fin'] || in_array($infos_CP['halfday'], array(0, -1))) {
1240 return false;
1241 }
1242 }
1243 if ($dateEnd <= $infos_CP['date_fin'] && $dateEnd >= $infos_CP['date_debut']) {
1244 if ($dateStart < $dateEnd) {
1245 return false;
1246 }
1247 if ($dateEnd < $infos_CP['date_fin'] || in_array($infos_CP['halfday'], array(0, -1))) {
1248 return false;
1249 }
1250 }
1251 } elseif ($halfday == 1) {
1252 // new start morning, new end morning
1253 if ($dateStart >= $infos_CP['date_debut'] && $dateStart <= $infos_CP['date_fin']) {
1254 if ($dateStart < $dateEnd) {
1255 return false;
1256 }
1257 if ($dateStart > $infos_CP['date_debut'] || in_array($infos_CP['halfday'], array(0, 1))) {
1258 return false;
1259 }
1260 }
1261 if ($dateEnd <= $infos_CP['date_fin'] && $dateEnd >= $infos_CP['date_debut']) {
1262 if ($dateEnd > $infos_CP['date_debut'] || in_array($infos_CP['halfday'], array(0, 1))) {
1263 return false;
1264 }
1265 }
1266 } elseif ($halfday == 2) {
1267 // new start afternoon, new end morning
1268 if ($dateStart >= $infos_CP['date_debut'] && $dateStart <= $infos_CP['date_fin']) {
1269 if ($dateStart < $infos_CP['date_fin'] || in_array($infos_CP['halfday'], array(0, -1))) {
1270 return false;
1271 }
1272 }
1273 if ($dateEnd <= $infos_CP['date_fin'] && $dateEnd >= $infos_CP['date_debut']) {
1274 if ($dateEnd > $infos_CP['date_debut'] || in_array($infos_CP['halfday'], array(0, 1))) {
1275 return false;
1276 }
1277 }
1278 } else {
1279 dol_print_error(null, 'Bad value of parameter halfday when calling function verifDateHolidayCP');
1280 }
1281 }
1282
1283 return true;
1284 }
1285
1286
1296 public function verifDateHolidayForTimestamp($fk_user, $timestamp, $status = '-1')
1297 {
1298 $isavailablemorning = true;
1299 $isavailableafternoon = true;
1300
1301 // Check into leave requests
1302 $sql = "SELECT cp.rowid, cp.date_debut as date_start, cp.date_fin as date_end, cp.halfday, cp.statut as status";
1303 $sql .= " FROM ".MAIN_DB_PREFIX."holiday as cp";
1304 $sql .= " WHERE cp.entity IN (".getEntity('holiday').")";
1305 $sql .= " AND cp.fk_user = ".(int) $fk_user;
1306 $sql .= " AND cp.date_debut <= '".$this->db->idate($timestamp)."' AND cp.date_fin >= '".$this->db->idate($timestamp)."'";
1307 if ($status != '-1') {
1308 $sql .= " AND cp.statut IN (".$this->db->sanitize($status).")";
1309 }
1310
1311 $resql = $this->db->query($sql);
1312 if ($resql) {
1313 $num_rows = $this->db->num_rows($resql); // Note, we can have 2 records if on is morning and the other one is afternoon
1314 if ($num_rows > 0) {
1315 $arrayofrecord = array();
1316 $i = 0;
1317 while ($i < $num_rows) {
1318 $obj = $this->db->fetch_object($resql);
1319
1320 // Note: $obj->halfday is 0:Full days, 2:Start afternoon end morning, -1:Start afternoon, 1:End morning
1321 $arrayofrecord[$obj->rowid] = array('date_start' => $this->db->jdate($obj->date_start), 'date_end' => $this->db->jdate($obj->date_end), 'halfday' => $obj->halfday, 'status' => $obj->status);
1322 $i++;
1323 }
1324
1325 // We found a record, user is on holiday by default, so is not available is true.
1326 $isavailablemorning = true;
1327 foreach ($arrayofrecord as $record) {
1328 if ($timestamp == $record['date_start'] && $record['halfday'] == 2) {
1329 continue;
1330 }
1331 if ($timestamp == $record['date_start'] && $record['halfday'] == -1) {
1332 continue;
1333 }
1334 $isavailablemorning = false;
1335 break;
1336 }
1337 $isavailableafternoon = true;
1338 foreach ($arrayofrecord as $record) {
1339 if ($timestamp == $record['date_end'] && $record['halfday'] == 2) {
1340 continue;
1341 }
1342 if ($timestamp == $record['date_end'] && $record['halfday'] == 1) {
1343 continue;
1344 }
1345 $isavailableafternoon = false;
1346 break;
1347 }
1348 }
1349 } else {
1350 dol_print_error($this->db);
1351 }
1352
1353 $result = array('morning' => (int) $isavailablemorning, 'afternoon' => (int) $isavailableafternoon);
1354 if (!$isavailablemorning) {
1355 $result['morning_reason'] = 'leave_request';
1356 }
1357 if (!$isavailableafternoon) {
1358 $result['afternoon_reason'] = 'leave_request';
1359 }
1360 return $result;
1361 }
1362
1369 public function getTooltipContentArray($params)
1370 {
1371 global $langs;
1372
1373 $langs->load('holiday');
1374 $nofetch = !empty($params['nofetch']);
1375
1376 $datas = array();
1377 $datas['picto'] = img_picto('', $this->picto).' <u class="paddingrightonly">'.$langs->trans("Holiday").'</u>';
1378 if (isset($this->status)) {
1379 $datas['picto'] .= ' '.$this->getLibStatut(5);
1380 }
1381 $datas['ref'] = '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref;
1382 // show type for this record only in ajax to not overload lists
1383 if (!$nofetch && !empty($this->fk_type)) {
1384 $typeleaves = $this->getTypes(1, -1);
1385 if (empty($typeleaves[$this->fk_type])) {
1386 $labeltoshow = $langs->trans("TypeWasDisabledOrRemoved", $this->fk_type);
1387 } else {
1388 $labeltoshow = (($typeleaves[$this->fk_type]['code'] && $langs->trans($typeleaves[$this->fk_type]['code']) != $typeleaves[$this->fk_type]['code']) ? $langs->trans($typeleaves[$this->fk_type]['code']) : $typeleaves[$this->fk_type]['label']);
1389 }
1390 $datas['type'] = '<br><b>'.$langs->trans("Type") . ':</b> ' . $labeltoshow;
1391 }
1392 if (isset($this->halfday) && !empty($this->date_debut) && !empty($this->date_fin)) {
1393 $listhalfday = array(
1394 'morning' => $langs->trans("Morning"),
1395 "afternoon" => $langs->trans("Afternoon")
1396 );
1397 $starthalfday = ($this->halfday == -1 || $this->halfday == 2) ? 'afternoon' : 'morning';
1398 $endhalfday = ($this->halfday == 1 || $this->halfday == 2) ? 'morning' : 'afternoon';
1399 $datas['date_start'] = '<br><b>'.$langs->trans('DateDebCP') . '</b>: '. dol_print_date($this->date_debut, 'day') . '&nbsp;&nbsp;<span class="opacitymedium">'.$langs->trans($listhalfday[$starthalfday]).'</span>';
1400 $datas['date_end'] = '<br><b>'.$langs->trans('DateFinCP') . '</b>: '. dol_print_date($this->date_fin, 'day') . '&nbsp;&nbsp;<span class="opacitymedium">'.$langs->trans($listhalfday[$endhalfday]).'</span>';
1401 }
1402
1403
1404 return $datas;
1405 }
1406
1416 public function getNomUrl($withpicto = 0, $save_lastsearch_value = -1, $notooltip = 0, $morecss = '')
1417 {
1418 global $conf, $langs, $hookmanager;
1419
1420 if (!empty($conf->dol_no_mouse_hover)) {
1421 $notooltip = 1; // Force disable tooltips
1422 }
1423
1424 $result = '';
1425 $params = [
1426 'id' => $this->id,
1427 'objecttype' => $this->element,
1428 'nofetch' => 1,
1429 ];
1430 $classfortooltip = 'classfortooltip';
1431 $dataparams = '';
1432 if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
1433 $classfortooltip = 'classforajaxtooltip';
1434 $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"';
1435 $label = '';
1436 } else {
1437 $label = implode($this->getTooltipContentArray($params));
1438 }
1439
1440 $url = DOL_URL_ROOT.'/holiday/card.php?id='.$this->id;
1441
1442 //if ($option != 'nolink')
1443 //{
1444 // Add param to save lastsearch_values or not
1445 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1446 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
1447 $add_save_lastsearch_values = 1;
1448 }
1449 if ($add_save_lastsearch_values) {
1450 $url .= '&save_lastsearch_values=1';
1451 }
1452 //}
1453
1454 $linkclose = '';
1455 if (empty($notooltip)) {
1456 if (getDolGlobalInt('MAIN_OPTIMIZEFORTEXTBROWSER')) {
1457 $label = $langs->trans("ShowMyObject");
1458 $linkclose .= ' alt="'.dolPrintHTMLForAttribute($label).'"';
1459 }
1460 $linkclose .= ($label ? ' title="'.dolPrintHTMLForAttribute($label).'"' : ' title="tocomplete"');
1461 $linkclose .= $dataparams.' class="'.$classfortooltip.($morecss ? ' '.$morecss : '').'"';
1462 } else {
1463 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
1464 }
1465
1466 $linkstart = '<a href="'.$url.'"';
1467 $linkstart .= $linkclose.'>';
1468 $linkend = '</a>';
1469
1470 $result .= $linkstart;
1471
1472 if ($withpicto) {
1473 $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'"'), 0, 0, $notooltip ? 0 : 1);
1474 }
1475 if ($withpicto != 2) {
1476 $result .= $this->ref;
1477 }
1478 $result .= $linkend;
1479
1480 global $action;
1481 $hookmanager->initHooks(array($this->element . 'dao'));
1482 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
1483 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
1484 if ($reshook > 0) {
1485 $result = $hookmanager->resPrint;
1486 } else {
1487 $result .= $hookmanager->resPrint;
1488 }
1489 return $result;
1490 }
1491
1492
1499 public function getLibStatut($mode = 0)
1500 {
1501 return $this->LibStatut($this->status, $mode, $this->date_debut);
1502 }
1503
1504 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1513 public function LibStatut($status, $mode = 0, $startdate = '')
1514 {
1515 // phpcs:enable
1516 global $langs;
1517
1518 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
1519 global $langs;
1520 //$langs->load("mymodule");
1521 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('DraftCP');
1522 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('ToReviewCP');
1523 $this->labelStatus[self::STATUS_APPROVED] = $langs->transnoentitiesnoconv('ApprovedCP');
1524 $this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('CancelCP');
1525 $this->labelStatus[self::STATUS_REFUSED] = $langs->transnoentitiesnoconv('RefuseCP');
1526 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('DraftCP');
1527 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('ToReviewCP');
1528 $this->labelStatusShort[self::STATUS_APPROVED] = $langs->transnoentitiesnoconv('ApprovedCP');
1529 $this->labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('CancelCP');
1530 $this->labelStatusShort[self::STATUS_REFUSED] = $langs->transnoentitiesnoconv('RefuseCP');
1531 }
1532
1533 $params = array();
1534 $statusType = 'status6';
1535 if (!empty($startdate) && $startdate >= dol_now()) { // If not yet passed, we use a green "in live" color
1536 $statusType = 'status4';
1537 $params = array('tooltip' => $this->labelStatus[$status].' - '.$langs->trans("Forthcoming"));
1538 }
1539 if ($status == self::STATUS_DRAFT) {
1540 $statusType = 'status0';
1541 }
1542 if ($status == self::STATUS_VALIDATED) {
1543 $statusType = 'status1';
1544 }
1545 if ($status == self::STATUS_CANCELED) {
1546 $statusType = 'status9';
1547 }
1548 if ($status == self::STATUS_REFUSED) {
1549 $statusType = 'status9';
1550 }
1551
1552 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode, '', $params);
1553 }
1554
1555
1564 public function selectStatutCP($selected = 0, $htmlname = 'select_statut', $morecss = 'minwidth125')
1565 {
1566 global $langs;
1567
1568 // List of status label
1569 $name = array('DraftCP', 'ToReviewCP', 'ApprovedCP', 'CancelCP', 'RefuseCP');
1570 $nb = count($name) + 1;
1571
1572 // Select HTML
1573 $out = '<select name="'.$htmlname.'" id="'.$htmlname.'" class="flat'.($morecss ? ' '.$morecss : '').'">'."\n";
1574 $out .= '<option value="-1">&nbsp;</option>'."\n";
1575
1576 // Loop on status
1577 for ($i = 1; $i < $nb; $i++) {
1578 if ($i == $selected) {
1579 $out .= '<option value="'.$i.'" selected>'.$langs->trans($name[$i - 1]).'</option>'."\n";
1580 } else {
1581 $out .= '<option value="'.$i.'">'.$langs->trans($name[$i - 1]).'</option>'."\n";
1582 }
1583 }
1584
1585 $out .= "</select>\n";
1586
1587 $showempty = 0;
1588 $out .= ajax_combobox($htmlname, array(), 0, 0, 'resolve', ($showempty < 0 ? (string) $showempty : '-1'), $morecss);
1589
1590 return $out;
1591 }
1592
1600 public function updateConfCP($name, $value)
1601 {
1602 $sql = "UPDATE ".MAIN_DB_PREFIX."holiday_config SET";
1603 $sql .= " value = '".$this->db->escape($value)."'";
1604 $sql .= " WHERE name = '".$this->db->escape($name)."'";
1605
1606 dol_syslog(get_class($this).'::updateConfCP name='.$name, LOG_DEBUG);
1607 $result = $this->db->query($sql);
1608 if ($result) {
1609 return true;
1610 }
1611
1612 return false;
1613 }
1614
1623 public function getConfCP($name, $createifnotfound = '')
1624 {
1625 $sql = "SELECT value";
1626 $sql .= " FROM ".MAIN_DB_PREFIX."holiday_config";
1627 $sql .= " WHERE name = '".$this->db->escape($name)."'";
1628
1629 dol_syslog(get_class($this).'::getConfCP name='.$name.' createifnotfound='.$createifnotfound, LOG_DEBUG);
1630 $result = $this->db->query($sql);
1631
1632 if ($result) {
1633 $obj = $this->db->fetch_object($result);
1634 // Return value
1635 if (empty($obj)) {
1636 if ($createifnotfound) {
1637 $sql = "INSERT INTO ".MAIN_DB_PREFIX."holiday_config(name, value)";
1638 $sql .= " VALUES('".$this->db->escape($name)."', '".$this->db->escape($createifnotfound)."')";
1639 $result = $this->db->query($sql);
1640 if ($result) {
1641 return $createifnotfound;
1642 } else {
1643 $this->error = $this->db->lasterror();
1644 return -2;
1645 }
1646 } else {
1647 return '';
1648 }
1649 } else {
1650 return $obj->value;
1651 }
1652 } else {
1653 // Erreur SQL
1654 $this->error = $this->db->lasterror();
1655 return -1;
1656 }
1657 }
1658
1667 public function updateSoldeCP($userID = 0, $nbHoliday = 0, $fk_type = 0)
1668 {
1669 global $user, $langs;
1670
1671 $error = 0;
1672
1673 if (empty($userID) && empty($nbHoliday) && empty($fk_type)) {
1674 $langs->load("holiday");
1675
1676 $decrease = getDolGlobalInt('HOLIDAY_DECREASE_AT_END_OF_MONTH');
1677
1678 // Si mise à jour pour tout le monde en début de mois
1679 $now = dol_now();
1680
1681 // Get month of last update
1682 $stringInDBForLastUpdate = $this->getConfCP('lastUpdate', dol_print_date($now, '%Y%m%d%H%M%S')); // Example '20200101120000'
1683 // Protection when $lastUpdate has a not valid value
1684 if ($stringInDBForLastUpdate < '20000101000000') {
1685 $stringInDBForLastUpdate = '20000101000000';
1686 }
1687 $lastUpdate = dol_stringtotime($stringInDBForLastUpdate);
1688 //print 'lastUpdate:'.$lastUpdate;exit;
1689
1690 $yearMonthLastUpdate = dol_print_date($lastUpdate, '%Y%m');
1691 $yearMonthNow = dol_print_date($now, '%Y%m');
1692 //print 'yearMonthLastUpdate='.$yearMonthLastUpdate.' yearMonthNow='.$yearMonthNow;
1693
1694 // If month date is not same than the one of last update (the one we saved in database), then we update the timestamp and balance of each open user,
1695 // catching up to the current month if a gap is detected
1696 while ($yearMonthLastUpdate < $yearMonthNow) {
1697 $this->db->begin();
1698
1699 $year = dol_print_date($lastUpdate, '%Y');
1700 $month = dol_print_date($lastUpdate, '%m');
1701
1702 $users = $this->fetchUsers(false, false, ' AND u.statut > 0');
1703 $nbUser = count($users);
1704
1705 $typeleaves = $this->getTypes(1, 1);
1706
1707 // Update each user counter
1708 foreach ($users as $userCounter) {
1709 $nbDaysToAdd = (isset($typeleaves[$userCounter['type']]['newbymonth']) ? $typeleaves[$userCounter['type']]['newbymonth'] : 0);
1710 if (empty($nbDaysToAdd)) {
1711 continue;
1712 }
1713
1714 dol_syslog("We update leave type id ".$userCounter['type']." for user id ".$userCounter['rowid'], LOG_DEBUG);
1715
1716 $nowHoliday = (float) $userCounter['nb_holiday'];
1717 $newSolde = $nowHoliday + $nbDaysToAdd;
1718
1719 // We add a log for each user when its balance gets increased
1720 $this->addLogCP($user->id, $userCounter['rowid'], $langs->trans('HolidayMonthlyCredit'), $newSolde, $userCounter['type']);
1721
1722 $result = $this->updateSoldeCP($userCounter['rowid'], $newSolde, $userCounter['type']);
1723
1724 if ($result < 0) {
1725 $this->db->rollback();
1726 return -1;
1727 }
1728
1729 if (empty($decrease)) {
1730 continue;
1731 }
1732
1733 // We fetch a user's holiday in the current month and then calculate the number of days to deduct if he has at least one registered
1734 $filter = " AND cp.statut = ".((int) self::STATUS_APPROVED);
1735 $filter .= " AND cp.date_fin >= '".$this->db->idate(dol_stringtotime(dol_print_date($lastUpdate, '%Y-%m-01')))."'";
1736 $filter .= " AND cp.date_debut <= '".$this->db->idate(dol_stringtotime(dol_print_date($lastUpdate, '%Y-%m-t')))."'";
1737 $filter .= " AND cp.fk_type = ".((int) $userCounter['type']);
1738 $this->fetchByUser($userCounter['id'], '', $filter);
1739
1740 if (empty($this->holiday)) {
1741 continue;
1742 }
1743
1744 $startOfMonth = dol_mktime(0, 0, 0, (int) $month, 1, (int) $year, 1);
1745 $endOfMonth = dol_mktime(0, 0, 0, (int) $month, (int) dol_print_date($lastUpdate, 't'), (int) $year, 1);
1746
1747 foreach ($this->holiday as $obj) {
1748 $startDate = $obj['date_debut_gmt'];
1749 $endDate = $obj['date_fin_gmt'];
1750
1751 if ($startDate <= $endOfMonth && $startDate < $startOfMonth) {
1752 $startDate = $startOfMonth;
1753 }
1754
1755 if ($startOfMonth <= $endDate && $endDate > $endOfMonth) {
1756 $endDate = $endOfMonth;
1757 }
1758
1759 $nbDaysToDeduct = (int) num_open_day($startDate, $endDate, 0, 1, $obj['halfday'], $obj['country_id']);
1760
1761 if ($nbDaysToDeduct <= 0) {
1762 continue;
1763 }
1764
1765 $newSolde -= $nbDaysToDeduct;
1766
1767 // We add a log for each user when its balance gets decreased
1768 $this->addLogCP($user->id, $userCounter['rowid'], $obj['ref'].' - '.$langs->trans('HolidayConsumption'), $newSolde, $userCounter['type']);
1769
1770 $result = $this->updateSoldeCP($userCounter['rowid'], $newSolde, $userCounter['type']);
1771
1772 if ($result < 0) {
1773 $this->db->rollback();
1774 return -1;
1775 }
1776 }
1777 }
1778
1779 //updating the date of the last monthly balance update
1780 $newMonth = dol_get_next_month((int) dol_print_date($lastUpdate, '%m'), (int) dol_print_date($lastUpdate, '%Y'));
1781 $lastUpdate = dol_mktime(0, 0, 0, (int) $newMonth['month'], 1, (int) $newMonth['year']);
1782
1783 $sql = "UPDATE ".MAIN_DB_PREFIX."holiday_config SET";
1784 $sql .= " value = '".$this->db->escape(dol_print_date($lastUpdate, '%Y%m%d%H%M%S'))."'";
1785 $sql .= " WHERE name = 'lastUpdate'";
1786 $result = $this->db->query($sql);
1787
1788 if (!$result) {
1789 $this->db->rollback();
1790 return -1;
1791 }
1792
1793 $this->db->commit();
1794
1795 $yearMonthLastUpdate = dol_print_date($lastUpdate, '%Y%m');
1796 }
1797
1798 if (!$error) {
1799 return 1;
1800 } else {
1801 return 0;
1802 }
1803 } else {
1804 // Mise à jour pour un utilisateur
1805 $nbHoliday = price2num($nbHoliday, 5);
1806
1807 $sql = "SELECT nb_holiday FROM ".MAIN_DB_PREFIX."holiday_users";
1808 $sql .= " WHERE fk_user = ".(int) $userID." AND fk_type = ".(int) $fk_type;
1809 $resql = $this->db->query($sql);
1810 if ($resql) {
1811 $num = $this->db->num_rows($resql);
1812
1813 if ($num > 0) {
1814 // Update for user
1815 $sql = "UPDATE ".MAIN_DB_PREFIX."holiday_users SET";
1816 $sql .= " nb_holiday = ".((float) $nbHoliday);
1817 $sql .= " WHERE fk_user = ".(int) $userID." AND fk_type = ".(int) $fk_type;
1818 $result = $this->db->query($sql);
1819 if (!$result) {
1820 $error++;
1821 $this->errors[] = $this->db->lasterror();
1822 }
1823 } else {
1824 // Insert for user
1825 $sql = "INSERT INTO ".MAIN_DB_PREFIX."holiday_users(nb_holiday, fk_user, fk_type) VALUES (";
1826 $sql .= ((float) $nbHoliday);
1827 $sql .= ", ".(int) $userID.", ".(int) $fk_type.")";
1828 $result = $this->db->query($sql);
1829 if (!$result) {
1830 $error++;
1831 $this->errors[] = $this->db->lasterror();
1832 }
1833 }
1834 } else {
1835 $this->errors[] = $this->db->lasterror();
1836 $error++;
1837 }
1838
1839 if (!$error) {
1840 return 1;
1841 } else {
1842 return -1;
1843 }
1844 }
1845 }
1846
1854 public function createCPusers($single = false, $userid = 0)
1855 {
1856 // do we have to add balance for all users ?
1857 if (!$single) {
1858 dol_syslog(get_class($this).'::createCPusers');
1859 $arrayofusers = $this->fetchUsers(false, true);
1860
1861 foreach ($arrayofusers as $users) {
1862 $sql = "INSERT INTO ".MAIN_DB_PREFIX."holiday_users";
1863 $sql .= " (fk_user, nb_holiday)";
1864 $sql .= " VALUES (".((int) $users['rowid'])."', '0')";
1865
1866 $resql = $this->db->query($sql);
1867 if (!$resql) {
1868 dol_print_error($this->db);
1869 }
1870 }
1871 } else {
1872 $sql = "INSERT INTO ".MAIN_DB_PREFIX."holiday_users";
1873 $sql .= " (fk_user, nb_holiday)";
1874 $sql .= " VALUES (".((int) $userid)."', '0')";
1875
1876 $resql = $this->db->query($sql);
1877 if (!$resql) {
1878 dol_print_error($this->db);
1879 }
1880 }
1881 }
1882
1890 public function getCPforUser($user_id, $fk_type = 0)
1891 {
1892 $sql = "SELECT nb_holiday";
1893 $sql .= " FROM ".MAIN_DB_PREFIX."holiday_users";
1894 $sql .= " WHERE fk_user = ".(int) $user_id;
1895 if ($fk_type > 0) {
1896 $sql .= " AND fk_type = ".(int) $fk_type;
1897 }
1898
1899 dol_syslog(get_class($this).'::getCPforUser user_id='.$user_id.' type_id='.$fk_type, LOG_DEBUG);
1900 $result = $this->db->query($sql);
1901 if ($result) {
1902 $obj = $this->db->fetch_object($result);
1903 //return number_format($obj->nb_holiday,2);
1904 if ($obj) {
1905 return $obj->nb_holiday;
1906 } else {
1907 return null;
1908 }
1909 } else {
1910 return null;
1911 }
1912 }
1913
1922 public function fetchUsers($stringlist = true, $type = true, $filters = '')
1923 {
1924 dol_syslog(get_class($this)."::fetchUsers", LOG_DEBUG);
1925
1926 if ($stringlist) {
1927 if ($type) {
1928 // If user of Dolibarr
1929 $sql = "SELECT";
1930 if (isModEnabled('multicompany') && getDolGlobalString('MULTICOMPANY_TRANSVERSE_MODE')) {
1931 $sql .= " DISTINCT";
1932 }
1933 $sql .= " u.rowid";
1934 $sql .= " FROM ".MAIN_DB_PREFIX."user as u";
1935
1936 if (isModEnabled('multicompany') && getDolGlobalString('MULTICOMPANY_TRANSVERSE_MODE')) {
1937 $sql .= ", ".MAIN_DB_PREFIX."usergroup_user as ug";
1938 $sql .= " WHERE ((ug.fk_user = u.rowid";
1939 $sql .= " AND ug.entity IN (".getEntity('usergroup')."))";
1940 $sql .= " OR u.entity = 0)"; // Show always superadmin
1941 } else {
1942 $sql .= " WHERE u.entity IN (".getEntity('user').")";
1943 }
1944 $sql .= " AND u.statut > 0";
1945 $sql .= " AND u.employee = 1"; // We only want employee users for holidays
1946 if ($filters) {
1947 $sql .= $filters;
1948 }
1949
1950 $resql = $this->db->query($sql);
1951
1952 // Si pas d'erreur SQL
1953 if ($resql) {
1954 $i = 0;
1955 $num = $this->db->num_rows($resql);
1956 $stringlist = '';
1957
1958 // Boucles du listage des utilisateurs
1959 while ($i < $num) {
1960 $obj = $this->db->fetch_object($resql);
1961
1962 if ($i == 0) {
1963 $stringlist .= $obj->rowid;
1964 } else {
1965 $stringlist .= ', '.$obj->rowid;
1966 }
1967
1968 $i++;
1969 }
1970 // Retoune le tableau des utilisateurs
1971 return $stringlist;
1972 } else {
1973 // Erreur SQL
1974 $this->error = "Error ".$this->db->lasterror();
1975 return -1;
1976 }
1977 } else {
1978 // We want only list of vacation balance for user ids
1979 $sql = "SELECT DISTINCT cpu.fk_user";
1980 $sql .= " FROM ".MAIN_DB_PREFIX."holiday_users as cpu, ".MAIN_DB_PREFIX."user as u";
1981 $sql .= " WHERE cpu.fk_user = u.rowid";
1982 if ($filters) {
1983 $sql .= $filters;
1984 }
1985
1986 $resql = $this->db->query($sql);
1987
1988 // Si pas d'erreur SQL
1989 if ($resql) {
1990 $i = 0;
1991 $num = $this->db->num_rows($resql);
1992 $stringlist = '';
1993
1994 // Boucles du listage des utilisateurs
1995 while ($i < $num) {
1996 $obj = $this->db->fetch_object($resql);
1997
1998 if ($i == 0) {
1999 $stringlist .= $obj->fk_user;
2000 } else {
2001 $stringlist .= ', '.$obj->fk_user;
2002 }
2003
2004 $i++;
2005 }
2006 // Retoune le tableau des utilisateurs
2007 return $stringlist;
2008 } else {
2009 // Erreur SQL
2010 $this->error = "Error ".$this->db->lasterror();
2011 return -1;
2012 }
2013 }
2014 } else {
2015 // Si faux donc return array
2016 // List for Dolibarr users
2017 if ($type) {
2018 // If we need users of Dolibarr
2019 $sql = "SELECT";
2020 if (isModEnabled('multicompany') && getDolGlobalString('MULTICOMPANY_TRANSVERSE_MODE')) {
2021 $sql .= " DISTINCT";
2022 }
2023 $sql .= " u.rowid, u.lastname, u.firstname, u.gender, u.fk_country as country_id, u.photo, u.employee, u.statut as status, u.fk_user";
2024 $sql .= " FROM ".MAIN_DB_PREFIX."user as u";
2025
2026 if (isModEnabled('multicompany') && getDolGlobalString('MULTICOMPANY_TRANSVERSE_MODE')) {
2027 $sql .= ", ".MAIN_DB_PREFIX."usergroup_user as ug";
2028 $sql .= " WHERE ((ug.fk_user = u.rowid";
2029 $sql .= " AND ug.entity IN (".getEntity('usergroup')."))";
2030 $sql .= " OR u.entity = 0)"; // Show always superadmin
2031 } else {
2032 $sql .= " WHERE u.entity IN (".getEntity('user').")";
2033 }
2034
2035 $sql .= " AND u.statut > 0";
2036 $sql .= " AND u.employee = 1"; // We only want employee users for holidays
2037 if ($filters) {
2038 $sql .= $filters;
2039 }
2040
2041 $resql = $this->db->query($sql);
2042
2043 // Si pas d'erreur SQL
2044 if ($resql) {
2045 $i = 0;
2046 $tab_result = $this->holiday;
2047 $num = $this->db->num_rows($resql);
2048
2049 // Boucles du listage des utilisateurs
2050 while ($i < $num) {
2051 $obj = $this->db->fetch_object($resql);
2052
2053 $tab_result[$i]['rowid'] = (int) $obj->rowid; // rowid of user
2054 $tab_result[$i]['id'] = (int) $obj->rowid; // id of user
2055 $tab_result[$i]['name'] = $obj->lastname; // deprecated
2056 $tab_result[$i]['lastname'] = $obj->lastname;
2057 $tab_result[$i]['firstname'] = $obj->firstname;
2058 $tab_result[$i]['gender'] = $obj->gender;
2059 $tab_result[$i]['status'] = (int) $obj->status;
2060 $tab_result[$i]['employee'] = (int) $obj->employee;
2061 $tab_result[$i]['photo'] = $obj->photo;
2062 $tab_result[$i]['fk_user'] = (int) $obj->fk_user; // rowid of manager
2063 $tab_result[$i]['country_id'] = (int) $obj->country_id; // id of country of user
2064 //$tab_result[$i]['type'] = $obj->type;
2065 //$tab_result[$i]['nb_holiday'] = $obj->nb_holiday;
2066
2067 $i++;
2068 }
2069 // Retoune le tableau des utilisateurs
2070 return $tab_result;
2071 } else {
2072 // Erreur SQL
2073 $this->errors[] = "Error ".$this->db->lasterror();
2074 return -1;
2075 }
2076 } else {
2077 // List of vacation balance users
2078 $sql = "SELECT cpu.fk_type, cpu.nb_holiday, u.rowid, u.lastname, u.firstname, u.gender, u.photo, u.employee, u.statut as status, u.fk_user";
2079 $sql .= " FROM ".MAIN_DB_PREFIX."holiday_users as cpu, ".MAIN_DB_PREFIX."user as u";
2080 $sql .= " WHERE cpu.fk_user = u.rowid";
2081 if ($filters) {
2082 $sql .= $filters;
2083 }
2084
2085 $resql = $this->db->query($sql);
2086
2087 // Si pas d'erreur SQL
2088 if ($resql) {
2089 $i = 0;
2090 $tab_result = $this->holiday;
2091 $num = $this->db->num_rows($resql);
2092
2093 // Boucles du listage des utilisateurs
2094 while ($i < $num) {
2095 $obj = $this->db->fetch_object($resql);
2096
2097 $tab_result[$i]['rowid'] = $obj->rowid; // rowid of user
2098 $tab_result[$i]['id'] = $obj->rowid; // id of user
2099 $tab_result[$i]['name'] = $obj->lastname; // deprecated
2100 $tab_result[$i]['lastname'] = $obj->lastname;
2101 $tab_result[$i]['firstname'] = $obj->firstname;
2102 $tab_result[$i]['gender'] = $obj->gender;
2103 $tab_result[$i]['status'] = $obj->status;
2104 $tab_result[$i]['employee'] = $obj->employee;
2105 $tab_result[$i]['photo'] = $obj->photo;
2106 $tab_result[$i]['fk_user'] = $obj->fk_user; // rowid of manager
2107
2108 $tab_result[$i]['type'] = $obj->fk_type;
2109 $tab_result[$i]['nb_holiday'] = $obj->nb_holiday;
2110
2111 $i++;
2112 }
2113 // Retoune le tableau des utilisateurs
2114 return $tab_result;
2115 } else {
2116 // Erreur SQL
2117 $this->error = "Error ".$this->db->lasterror();
2118 return -1;
2119 }
2120 }
2121 }
2122 }
2123
2124
2125 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2133 {
2134 // phpcs:enable
2135 $users_validator = array();
2136
2137 $sql = "SELECT DISTINCT ur.fk_user";
2138 $sql .= " FROM ".MAIN_DB_PREFIX."user_rights as ur, ".MAIN_DB_PREFIX."rights_def as rd";
2139 $sql .= " WHERE ur.fk_id = rd.id and rd.module = 'holiday' AND rd.perms = 'approve'"; // Permission 'Approve';
2140 $sql .= "UNION";
2141 $sql .= " SELECT DISTINCT ugu.fk_user";
2142 $sql .= " FROM ".MAIN_DB_PREFIX."usergroup_user as ugu, ".MAIN_DB_PREFIX."usergroup_rights as ur, ".MAIN_DB_PREFIX."rights_def as rd";
2143 $sql .= " WHERE ugu.fk_usergroup = ur.fk_usergroup AND ur.fk_id = rd.id and rd.module = 'holiday' AND rd.perms = 'approve'"; // Permission 'Approve';
2144 //print $sql;
2145
2146 dol_syslog(get_class($this)."::fetch_users_approver_holiday sql=".$sql);
2147 $result = $this->db->query($sql);
2148 if ($result) {
2149 $num_rows = $this->db->num_rows($result);
2150 $i = 0;
2151 while ($i < $num_rows) {
2152 $objp = $this->db->fetch_object($result);
2153 array_push($users_validator, $objp->fk_user);
2154 $i++;
2155 }
2156 return $users_validator;
2157 } else {
2158 $this->error = $this->db->lasterror();
2159 dol_syslog(get_class($this)."::fetch_users_approver_holiday Error ".$this->error, LOG_ERR);
2160 return -1;
2161 }
2162 }
2163
2164
2170 public function countActiveUsers()
2171 {
2172 $sql = "SELECT count(u.rowid) as compteur";
2173 $sql .= " FROM ".MAIN_DB_PREFIX."user as u";
2174 $sql .= " WHERE u.statut > 0";
2175
2176 $result = $this->db->query($sql);
2177 $object = $this->db->fetch_object($result);
2178
2179 return $object->compteur;
2180 }
2187 {
2188 $sql = "SELECT count(u.rowid) as compteur";
2189 $sql .= " FROM ".MAIN_DB_PREFIX."user as u LEFT JOIN ".MAIN_DB_PREFIX."holiday_users hu ON (hu.fk_user=u.rowid)";
2190 $sql .= " WHERE u.statut > 0 AND hu.fk_user IS NULL";
2191
2192 $result = $this->db->query($sql);
2193 $object = $this->db->fetch_object($result);
2194
2195 return $object->compteur;
2196 }
2197
2205 public function verifNbUsers($userDolibarrWithoutCP, $userCP)
2206 {
2207 if (empty($userCP)) {
2208 $userCP = 0;
2209 }
2210 dol_syslog(get_class($this).'::verifNbUsers userDolibarr='.$userDolibarrWithoutCP.' userCP='.$userCP);
2211 return 1;
2212 }
2213
2214
2225 public function addLogCP($fk_user_action, $fk_user_update, $label, $new_solde, $fk_type)
2226 {
2227 $error = 0;
2228
2229 $prev_solde = price2num((float) $this->getCPforUser($fk_user_update, $fk_type), 5);
2230 $new_solde = price2num($new_solde, 5);
2231 //print "$prev_solde == $new_solde";
2232
2233 if ($prev_solde == $new_solde) {
2234 return 0;
2235 }
2236
2237 $this->db->begin();
2238
2239 // Insert request
2240 $sql = "INSERT INTO ".MAIN_DB_PREFIX."holiday_logs (";
2241 $sql .= "date_action,";
2242 $sql .= "fk_user_action,";
2243 $sql .= "fk_user_update,";
2244 $sql .= "type_action,";
2245 $sql .= "prev_solde,";
2246 $sql .= "new_solde,";
2247 $sql .= "fk_type";
2248 $sql .= ") VALUES (";
2249 $sql .= " '".$this->db->idate(dol_now())."',";
2250 $sql .= " ".((int) $fk_user_action).",";
2251 $sql .= " ".((int) $fk_user_update).",";
2252 $sql .= " '".$this->db->escape($label)."',";
2253 $sql .= " ".((float) $prev_solde).",";
2254 $sql .= " ".((float) $new_solde).",";
2255 $sql .= " ".((int) $fk_type);
2256 $sql .= ")";
2257
2258 $resql = $this->db->query($sql);
2259 if (!$resql) {
2260 $error++;
2261 $this->errors[] = "Error ".$this->db->lasterror();
2262 }
2263
2264 $optRowid = 0;
2265 if (!$error) {
2266 $optRowid = $this->db->last_insert_id(MAIN_DB_PREFIX."holiday_logs");
2267 }
2268
2269 // Commit or rollback
2270 if ($error) {
2271 foreach ($this->errors as $errmsg) {
2272 dol_syslog(get_class($this)."::addLogCP ".$errmsg, LOG_ERR);
2273 $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
2274 }
2275 $this->db->rollback();
2276 return -1 * $error;
2277 } else {
2278 $this->db->commit();
2279 return $optRowid;
2280 }
2281 }
2282
2290 public function fetchLog($sqlorder, $sqlwhere)
2291 {
2292 $sql = "SELECT";
2293 $sql .= " cpl.rowid,";
2294 $sql .= " cpl.date_action,";
2295 $sql .= " cpl.fk_user_action,";
2296 $sql .= " cpl.fk_user_update,";
2297 $sql .= " cpl.type_action,";
2298 $sql .= " cpl.prev_solde,";
2299 $sql .= " cpl.new_solde,";
2300 $sql .= " cpl.fk_type";
2301 $sql .= " FROM ".MAIN_DB_PREFIX."holiday_logs as cpl";
2302 $sql .= " WHERE cpl.rowid > 0"; // To avoid error with other search and criteria
2303
2304 // Filter
2305 if (!empty($sqlwhere)) {
2306 $sql .= " ".$sqlwhere;
2307 }
2308
2309 // Order
2310 if (!empty($sqlorder)) {
2311 $sql .= " ".$sqlorder;
2312 }
2313
2314 dol_syslog(get_class($this)."::fetchLog", LOG_DEBUG);
2315 $resql = $this->db->query($sql);
2316
2317 // If no error SQL
2318 if ($resql) {
2319 $i = 0;
2320 $tab_result = $this->logs;
2321 $num = $this->db->num_rows($resql);
2322
2323 // If no record
2324 if (!$num) {
2325 return 2;
2326 }
2327
2328 // Loop on result to fill the array
2329 while ($i < $num) {
2330 $obj = $this->db->fetch_object($resql);
2331
2332 $tab_result[$i]['rowid'] = (int) $obj->rowid;
2333 $tab_result[$i]['id'] = (int) $obj->rowid;
2334 $tab_result[$i]['date_action'] = (string) $obj->date_action;
2335 $tab_result[$i]['fk_user_action'] = (int) $obj->fk_user_action;
2336 $tab_result[$i]['fk_user_update'] = (int) $obj->fk_user_update;
2337 $tab_result[$i]['type_action'] = (string) $obj->type_action;
2338 $tab_result[$i]['prev_solde'] = (float) $obj->prev_solde;
2339 $tab_result[$i]['new_solde'] = (float) $obj->new_solde;
2340 $tab_result[$i]['fk_type'] = (int) $obj->fk_type;
2341
2342 $i++;
2343 }
2344 // Retourne 1 et ajoute le tableau à la variable
2345 $this->logs = $tab_result;
2346 return 1;
2347 } else {
2348 // Erreur SQL
2349 $this->error = "Error ".$this->db->lasterror();
2350 return -1;
2351 }
2352 }
2353
2354
2362 public function getTypes($active = -1, $affect = -1)
2363 {
2364 global $mysoc;
2365
2366 $sql = "SELECT rowid, code, label, affect, delay, newbymonth";
2367 $sql .= " FROM ".MAIN_DB_PREFIX."c_holiday_types";
2368 $sql .= " WHERE (fk_country IS NULL OR fk_country = ".((int) $mysoc->country_id).')';
2369 $sql .= " AND entity IN (0, ".getEntity('c_holiday_types').")"; // Need entity 0 (holiday types common to all countries= + current entity).
2370 if ($active >= 0) {
2371 $sql .= " AND active = ".((int) $active);
2372 }
2373 if ($affect >= 0) {
2374 $sql .= " AND affect = ".((int) $affect);
2375 }
2376 $sql .= " ORDER BY sortorder";
2377
2378 $result = $this->db->query($sql);
2379 if ($result) {
2380 $num = $this->db->num_rows($result);
2381 if ($num) {
2382 $types = array();
2383 while ($obj = $this->db->fetch_object($result)) {
2384 $types[$obj->rowid] = array(
2385 'id' => $obj->rowid,
2386 'rowid' => $obj->rowid,
2387 'code' => $obj->code,
2388 'label' => $obj->label,
2389 'affect' => $obj->affect,
2390 'delay' => $obj->delay,
2391 'newbymonth' => $obj->newbymonth
2392 );
2393 }
2394
2395 return $types;
2396 }
2397 } else {
2398 dol_print_error($this->db);
2399 }
2400
2401 return array();
2402 }
2403
2404
2411 public function info($id)
2412 {
2413 global $conf;
2414
2415 $sql = "SELECT f.rowid, f.statut as status,";
2416 $sql .= " f.date_create as datec,";
2417 $sql .= " f.tms as date_modification,";
2418 $sql .= " f.date_valid as datev,";
2419 $sql .= " f.date_approval as datea,";
2420 $sql .= " f.date_refuse as dater,";
2421 $sql .= " f.fk_user_create as fk_user_creation,";
2422 $sql .= " f.fk_user_modif as fk_user_modification,";
2423 $sql .= " f.fk_user_valid as fk_user_validation,";
2424 $sql .= " f.fk_user_approve as fk_user_approval_done,";
2425 $sql .= " f.fk_validator as fk_user_approval_expected,";
2426 $sql .= " f.fk_user_refuse as fk_user_refuse";
2427 $sql .= " FROM ".MAIN_DB_PREFIX."holiday as f";
2428 $sql .= " WHERE f.rowid = ".((int) $id);
2429 $sql .= " AND f.entity = ".$conf->entity;
2430
2431 $resql = $this->db->query($sql);
2432 if ($resql) {
2433 if ($this->db->num_rows($resql)) {
2434 $obj = $this->db->fetch_object($resql);
2435
2436 $this->id = $obj->rowid;
2437
2438 $this->date_creation = $this->db->jdate($obj->datec);
2439 $this->date_modification = $this->db->jdate($obj->date_modification);
2440 $this->date_validation = $this->db->jdate($obj->datev);
2441 $this->date_approval = $this->db->jdate($obj->datea);
2442
2443 $this->user_creation_id = $obj->fk_user_creation;
2444 $this->user_validation_id = $obj->fk_user_validation;
2445 $this->user_modification_id = $obj->fk_user_modification;
2446
2447 if ($obj->status == Holiday::STATUS_APPROVED || $obj->status == Holiday::STATUS_CANCELED) {
2448 if ($obj->fk_user_approval_done) {
2449 $this->fk_user_approve = $obj->fk_user_approval_done;
2450 }
2451 }
2452 }
2453 $this->db->free($resql);
2454 } else {
2455 dol_print_error($this->db);
2456 }
2457 }
2458
2459
2467 public function initAsSpecimen()
2468 {
2469 global $user, $langs;
2470
2471 // Initialise parameters
2472 $this->id = 0;
2473 $this->specimen = 1;
2474
2475 $this->fk_user = $user->id;
2476 $this->description = 'SPECIMEN description';
2477 $this->date_debut = dol_now();
2478 $this->date_fin = dol_now() + (24 * 3600);
2479 $this->date_valid = dol_now();
2480 $this->fk_validator = $user->id;
2481 $this->halfday = 0;
2482 $this->fk_type = 1;
2484
2485 return 1;
2486 }
2487
2493 public function loadStateBoard()
2494 {
2495 global $user;
2496
2497 $this->nb = array();
2498
2499 $sql = "SELECT count(h.rowid) as nb";
2500 $sql .= " FROM ".MAIN_DB_PREFIX."holiday as h";
2501 $sql .= " WHERE h.statut > 1";
2502 $sql .= " AND h.entity IN (".getEntity('holiday').")";
2503 if (!$user->hasRight('holiday', 'readall')) {
2504 $userchildids = $user->getAllChildIds(1);
2505 $sql .= " AND (h.fk_user IN (".$this->db->sanitize(implode(',', $userchildids)).")";
2506 $sql .= " OR h.fk_validator IN (".$this->db->sanitize(implode(',', $userchildids))."))";
2507 }
2508
2509 $resql = $this->db->query($sql);
2510 if ($resql) {
2511 while ($obj = $this->db->fetch_object($resql)) {
2512 $this->nb["holidays"] = $obj->nb;
2513 }
2514 $this->db->free($resql);
2515 return 1;
2516 } else {
2517 dol_print_error($this->db);
2518 $this->error = $this->db->error();
2519 return -1;
2520 }
2521 }
2522
2523 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2530 public function load_board($user)
2531 {
2532 // phpcs:enable
2533 global $conf, $langs;
2534
2535 if ($user->socid) {
2536 return -1; // protection pour eviter appel par utilisateur externe
2537 }
2538
2539 $now = dol_now();
2540
2541 $sql = "SELECT h.rowid, h.date_debut";
2542 $sql .= " FROM ".MAIN_DB_PREFIX."holiday as h";
2543 $sql .= " WHERE h.statut = 2";
2544 $sql .= " AND h.entity IN (".getEntity('holiday').")";
2545 if (!$user->hasRight('holiday', 'read_all')) {
2546 $userchildids = $user->getAllChildIds(1);
2547 $sql .= " AND (h.fk_user IN (".$this->db->sanitize(implode(',', $userchildids)).")";
2548 $sql .= " OR h.fk_validator IN (".$this->db->sanitize(implode(',', $userchildids))."))";
2549 }
2550
2551 $resql = $this->db->query($sql);
2552 if ($resql) {
2553 $langs->load("members");
2554
2555 $response = new WorkboardResponse();
2556 $response->warning_delay = $conf->holiday->approve->warning_delay / 60 / 60 / 24;
2557 $response->label = $langs->trans("HolidaysToApprove");
2558 $response->labelShort = $langs->trans("ToApprove");
2559 $response->url = DOL_URL_ROOT.'/holiday/list.php?search_status=2&amp;mainmenu=hrm&amp;leftmenu=holiday';
2560 $response->img = img_object('', "holiday");
2561
2562 while ($obj = $this->db->fetch_object($resql)) {
2563 $response->nbtodo++;
2564
2565 if ($this->db->jdate($obj->date_debut) < ($now - $conf->holiday->approve->warning_delay)) {
2566 $response->nbtodolate++;
2567 }
2568 }
2569
2570 return $response;
2571 } else {
2572 dol_print_error($this->db);
2573 $this->error = $this->db->error();
2574 return -1;
2575 }
2576 }
2584 public function getKanbanView($option = '', $arraydata = null)
2585 {
2586 global $langs;
2587
2588 $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
2589
2590 $return = '<div class="box-flex-item box-flex-grow-zero">';
2591 $return .= '<div class="info-box info-box-sm">';
2592 $return .= '<span class="info-box-icon bg-infobox-action">';
2593 $return .= img_picto('', $this->picto);
2594 $return .= '</span>';
2595 $return .= '<div class="info-box-content">';
2596 $return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.$this->getNomUrl().'</span>';
2597 if ($selected >= 0) {
2598 $return .= '<input id="cb'.$this->id.'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
2599 }
2600 if (property_exists($this, 'fk_type')) {
2601 $return .= '<br>';
2602 //$return .= '<span class="opacitymedium">'.$langs->trans("Type").'</span> : ';
2603 $return .= '<div class="info_box-label tdoverflowmax100" title="'.dol_escape_htmltag($arraydata['labeltype']).'">'.dol_escape_htmltag($arraydata['labeltype']).'</div>';
2604 }
2605 if (property_exists($this, 'date_debut') && property_exists($this, 'date_fin')) {
2606 $return .= '<span class="info-box-label small">'.dol_print_date($this->date_debut, 'day').'</span>';
2607 $return .= ' <span class="opacitymedium small">'.$langs->trans("To").'</span> ';
2608 $return .= '<span class="info-box-label small">'.dol_print_date($this->date_fin, 'day').'</span>';
2609 if (!empty($arraydata['nbopenedday'])) {
2610 $return .= ' ('.$arraydata['nbopenedday'].')';
2611 }
2612 }
2613 if (method_exists($this, 'getLibStatut')) {
2614 $return .= '<div class="info-box-status">'.$this->getLibStatut(3).'</div>';
2615 }
2616 $return .= '</div>';
2617 $return .= '</div>';
2618 $return .= '</div>';
2619 return $return;
2620 }
2621}
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve', $idforemptyvalue='-1', $morecss='')
Convert a html select field into an ajax combobox.
Definition ajax.lib.php:475
$object ref
Definition info.php:90
Parent class of all other business classes (invoices, contracts, proposals, orders,...
fetch_optionals($rowid=null, $optionsArray=null)
Function to get extra fields of an object into $this->array_options This method is in most cases call...
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
Class of the module paid holiday.
getTypes($active=-1, $affect=-1)
Return array with list of types.
getNomUrl($withpicto=0, $save_lastsearch_value=-1, $notooltip=0, $morecss='')
Return clickable name (with picto eventually)
verifDateHolidayCP($fk_user, $dateStart, $dateEnd, $halfday=0)
Check if a user is on holiday (partially or completely) into a period.
validate($user=null, $notrigger=0)
Validate leave request.
info($id)
Load information on object.
updateBalance()
Update balance of vacations and check table of users for holidays is complete.
updateConfCP($name, $value)
Met à jour une option du module Holiday Payés.
const STATUS_VALIDATED
Validated status.
const STATUS_DRAFT
Draft status.
fetch($id, $ref='')
Load object in memory from database.
addLogCP($fk_user_action, $fk_user_update, $label, $new_solde, $fk_type)
addLogCP
verifNbUsers($userDolibarrWithoutCP, $userCP)
Compare le nombre d'utilisateur actif de Dolibarr à celui des utilisateurs des congés payés.
verifDateHolidayForTimestamp($fk_user, $timestamp, $status='-1')
Check that a user is not on holiday for a particular timestamp.
approve($user=null, $notrigger=0)
Approve leave request.
getNextNumRef($objsoc)
Returns the reference to the following non used Order depending on the active numbering module define...
const STATUS_REFUSED
Refused.
getConfCP($name, $createifnotfound='')
Return value of a conf parameter for leave module TODO Move this into llx_const table.
load_board($user)
Load indicators for dashboard (this->nbtodo and this->nbtodolate)
initAsSpecimen()
Initialise an instance with random values.
create($user, $notrigger=0)
Créer un congés payés dans la base de données.
selectStatutCP($selected=0, $htmlname='select_statut', $morecss='minwidth125')
Show select with list of leave status.
countActiveUsersWithoutCP()
Compte le nombre d'utilisateur actifs dans Dolibarr sans CP.
updateSoldeCP($userID=0, $nbHoliday=0, $fk_type=0)
Met à jour le timestamp de la dernière mise à jour du solde des CP.
update($user=null, $notrigger=0)
Update database.
getCPforUser($user_id, $fk_type=0)
Return the balance of annual leave of a user.
fetch_users_approver_holiday()
Return list of people with permission to validate leave requests.
__construct($db)
Constructor.
loadStateBoard()
Load this->nb for dashboard.
getLibStatut($mode=0)
Returns the label status.
createCPusers($single=false, $userid=0)
Create entries for each user at setup step.
fetchAll($order, $filter)
List all holidays of all users.
const STATUS_CANCELED
Canceled.
fetchLog($sqlorder, $sqlwhere)
List log of leaves.
countActiveUsers()
Compte le nombre d'utilisateur actifs dans Dolibarr.
fetchByUser($user_id, $order='', $filter='')
List holidays for a particular user or list of users.
const STATUS_APPROVED
Approved.
getTooltipContentArray($params)
getTooltipContentArray
fetchUsers($stringlist=true, $type=true, $filters='')
Get list of Users or list of vacation balance.
getKanbanView($option='', $arraydata=null)
Return clickable link of object (with eventually picto)
LibStatut($status, $mode=0, $startdate='')
Returns the label of a status.
print $langs trans("Ref").' m titre as m m statut as status
Or an array listing all the potential status of the object: array: int of the status => translated la...
Definition index.php:171
global $mysoc
dol_get_next_month($month, $year)
Return next month.
Definition date.lib.php:541
num_open_day($timestampStart, $timestampEnd, $inhour=0, $lastday=0, $halfday=0, $countryCodeOrId='')
Function to return number of working days (and text of units) between two dates (working days)
dol_stringtotime($string, $gm=1)
Convert a string date into a GM Timestamps date Warning: YYYY-MM-DDTHH:MM:SS+02:00 (RFC3339) is not s...
Definition date.lib.php:434
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
Definition files.lib.php:64
dol_now($mode='gmt')
Return date for now.
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...
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
getDictionaryValue($tablename, $field, $id, $checkentity=false, $rowidfield='rowid')
Return the value of a filed into a dictionary for the record $id.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...