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