dolibarr 21.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-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 $checkBalance = getDictionaryValue('c_holiday_types', 'block_if_negative', $this->fk_type, true);
774
775 if ($checkBalance > 0) {
776 $balance = $this->getCPforUser($this->fk_user, $this->fk_type);
777
778 if ($balance < 0) {
779 $this->error = 'LeaveRequestCreationBlockedBecauseBalanceIsNegative';
780 return -1;
781 }
782 }
783
784 // Define new ref
785 if (!$error && (preg_match('/^[\‍(]?PROV/i', $this->ref) || empty($this->ref) || $this->ref == $this->id)) {
786 $num = $this->getNextNumRef(null);
787 } else {
788 $num = $this->ref;
789 }
790 $this->newref = dol_sanitizeFileName($num);
791
792 // Update status
793 $sql = "UPDATE ".MAIN_DB_PREFIX."holiday SET";
794 $sql .= " fk_user_valid = ".((int) $user->id).",";
795 $sql .= " date_valid = '".$this->db->idate(dol_now())."',";
796 if (!empty($this->status) && is_numeric($this->status)) {
797 $sql .= " statut = ".((int) $this->status).",";
798 } else {
799 $this->error = 'Property status must be a numeric value';
800 $error++;
801 }
802 $sql .= " ref = '".$this->db->escape($num)."'";
803 $sql .= " WHERE rowid = ".((int) $this->id);
804
805 $this->db->begin();
806
807 dol_syslog(get_class($this)."::validate", LOG_DEBUG);
808 $resql = $this->db->query($sql);
809 if (!$resql) {
810 $error++;
811 $this->errors[] = "Error ".$this->db->lasterror();
812 }
813
814 if (!$error) {
815 if (!$notrigger) {
816 // Call trigger
817 $result = $this->call_trigger('HOLIDAY_VALIDATE', $user);
818 if ($result < 0) {
819 $error++;
820 }
821 // End call triggers
822 }
823 }
824
825 if (!$error) {
826 $this->oldref = $this->ref;
827
828 // Rename directory if dir was a temporary ref
829 if (preg_match('/^[\‍(]?PROV/i', $this->ref)) {
830 // Now we rename also files into index
831 $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) . "'";
832 $sql .= " WHERE filename LIKE '" . $this->db->escape($this->ref) . "%' AND filepath = 'holiday/" . $this->db->escape($this->ref) . "' and entity = " . ((int) $conf->entity);
833 $resql = $this->db->query($sql);
834 if (!$resql) {
835 $error++;
836 $this->error = $this->db->lasterror();
837 }
838 $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filepath = 'holiday/".$this->db->escape($this->newref)."'";
839 $sql .= " WHERE filepath = 'holiday/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
840 $resql = $this->db->query($sql);
841 if (!$resql) {
842 $error++;
843 $this->error = $this->db->lasterror();
844 }
845
846 // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
847 $oldref = dol_sanitizeFileName($this->ref);
848 $newref = dol_sanitizeFileName($num);
849 $dirsource = $conf->holiday->multidir_output[$this->entity] . '/' . $oldref;
850 $dirdest = $conf->holiday->multidir_output[$this->entity] . '/' . $newref;
851 if (!$error && file_exists($dirsource)) {
852 dol_syslog(get_class($this) . "::validate rename dir " . $dirsource . " into " . $dirdest);
853 if (@rename($dirsource, $dirdest)) {
854 dol_syslog("Rename ok");
855 // Rename docs starting with $oldref with $newref
856 $listoffiles = dol_dir_list($dirdest, 'files', 1, '^' . preg_quote($oldref, '/'));
857 foreach ($listoffiles as $fileentry) {
858 $dirsource = $fileentry['name'];
859 $dirdest = preg_replace('/^' . preg_quote($oldref, '/') . '/', $newref, $dirsource);
860 $dirsource = $fileentry['path'] . '/' . $dirsource;
861 $dirdest = $fileentry['path'] . '/' . $dirdest;
862 @rename($dirsource, $dirdest);
863 }
864 }
865 }
866 }
867 }
868
869
870 // Commit or rollback
871 if ($error) {
872 foreach ($this->errors as $errmsg) {
873 dol_syslog(get_class($this)."::validate ".$errmsg, LOG_ERR);
874 $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
875 }
876 $this->db->rollback();
877 return -1 * $error;
878 } else {
879 $this->db->commit();
880 return 1;
881 }
882 }
883
884
892 public function approve($user = null, $notrigger = 0)
893 {
894 $error = 0;
895
896 $checkBalance = getDictionaryValue('c_holiday_types', 'block_if_negative', $this->fk_type, true);
897
898 if ($checkBalance > 0) {
899 $balance = $this->getCPforUser($this->fk_user, $this->fk_type);
900
901 if ($balance < 0) {
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->status != self::STATUS_DRAFT) {
1027 $balance = $this->getCPforUser($this->fk_user, $this->fk_type);
1028
1029 if ($balance < 0) {
1030 $this->error = 'LeaveRequestCreationBlockedBecauseBalanceIsNegative';
1031 return -1;
1032 }
1033 }
1034
1035 // Update request
1036 $sql = "UPDATE ".MAIN_DB_PREFIX."holiday SET";
1037
1038 $sql .= " description= '".$this->db->escape($this->description)."',";
1039
1040 if (!empty($this->date_debut)) {
1041 $sql .= " date_debut = '".$this->db->idate($this->date_debut)."',";
1042 } else {
1043 $error++;
1044 }
1045 if (!empty($this->date_fin)) {
1046 $sql .= " date_fin = '".$this->db->idate($this->date_fin)."',";
1047 } else {
1048 $error++;
1049 }
1050 $sql .= " halfday = ".((int) $this->halfday).",";
1051 if (!empty($this->status) && is_numeric($this->status)) {
1052 $sql .= " statut = ".((int) $this->status).",";
1053 } else {
1054 $error++;
1055 }
1056 if (!empty($this->fk_validator)) {
1057 $sql .= " fk_validator = '".$this->db->escape($this->fk_validator)."',";
1058 } else {
1059 $error++;
1060 }
1061 if (!empty($this->date_valid)) {
1062 $sql .= " date_valid = '".$this->db->idate($this->date_valid)."',";
1063 } else {
1064 $sql .= " date_valid = NULL,";
1065 }
1066 if (!empty($this->fk_user_valid)) {
1067 $sql .= " fk_user_valid = ".((int) $this->fk_user_valid).",";
1068 } else {
1069 $sql .= " fk_user_valid = NULL,";
1070 }
1071 if (!empty($this->date_approval)) {
1072 $sql .= " date_approval = '".$this->db->idate($this->date_approval)."',";
1073 } else {
1074 $sql .= " date_approval = NULL,";
1075 }
1076 if (!empty($this->fk_user_approve)) {
1077 $sql .= " fk_user_approve = ".((int) $this->fk_user_approve).",";
1078 } else {
1079 $sql .= " fk_user_approve = NULL,";
1080 }
1081 if (!empty($this->date_refuse)) {
1082 $sql .= " date_refuse = '".$this->db->idate($this->date_refuse)."',";
1083 } else {
1084 $sql .= " date_refuse = NULL,";
1085 }
1086 if (!empty($this->fk_user_refuse)) {
1087 $sql .= " fk_user_refuse = ".((int) $this->fk_user_refuse).",";
1088 } else {
1089 $sql .= " fk_user_refuse = NULL,";
1090 }
1091 if (!empty($this->date_cancel)) {
1092 $sql .= " date_cancel = '".$this->db->idate($this->date_cancel)."',";
1093 } else {
1094 $sql .= " date_cancel = NULL,";
1095 }
1096 if (!empty($this->fk_user_cancel)) {
1097 $sql .= " fk_user_cancel = ".((int) $this->fk_user_cancel).",";
1098 } else {
1099 $sql .= " fk_user_cancel = NULL,";
1100 }
1101 if (!empty($this->detail_refuse)) {
1102 $sql .= " detail_refuse = '".$this->db->escape($this->detail_refuse)."'";
1103 } else {
1104 $sql .= " detail_refuse = NULL";
1105 }
1106
1107 $sql .= " WHERE rowid = ".((int) $this->id);
1108
1109 $this->db->begin();
1110
1111 dol_syslog(get_class($this)."::update", LOG_DEBUG);
1112 $resql = $this->db->query($sql);
1113 if (!$resql) {
1114 $error++;
1115 $this->errors[] = "Error ".$this->db->lasterror();
1116 }
1117
1118 if (!$error) {
1119 $result = $this->insertExtraFields();
1120 if ($result < 0) {
1121 $error++;
1122 }
1123 }
1124
1125 if (!$error) {
1126 if (!$notrigger) {
1127 // Call trigger
1128 $result = $this->call_trigger('HOLIDAY_MODIFY', $user);
1129 if ($result < 0) {
1130 $error++;
1131 }
1132 // End call triggers
1133 }
1134 }
1135
1136 // Commit or rollback
1137 if ($error) {
1138 foreach ($this->errors as $errmsg) {
1139 dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
1140 $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
1141 }
1142 $this->db->rollback();
1143 return -1 * $error;
1144 } else {
1145 $this->db->commit();
1146 return 1;
1147 }
1148 }
1149
1150
1158 public function delete($user, $notrigger = 0)
1159 {
1160 global $conf, $langs;
1161 $error = 0;
1162
1163 $sql = "DELETE FROM ".MAIN_DB_PREFIX."holiday";
1164 $sql .= " WHERE rowid=".((int) $this->id);
1165
1166 $this->db->begin();
1167
1168 dol_syslog(get_class($this)."::delete", LOG_DEBUG);
1169 $resql = $this->db->query($sql);
1170 if (!$resql) {
1171 $error++;
1172 $this->errors[] = "Error ".$this->db->lasterror();
1173 }
1174
1175 if (!$error) {
1176 if (!$notrigger) {
1177 // Call trigger
1178 $result = $this->call_trigger('HOLIDAY_DELETE', $user);
1179 if ($result < 0) {
1180 $error++;
1181 }
1182 // End call triggers
1183 }
1184 }
1185
1186 // Commit or rollback
1187 if ($error) {
1188 foreach ($this->errors as $errmsg) {
1189 dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR);
1190 $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
1191 }
1192 $this->db->rollback();
1193 return -1 * $error;
1194 } else {
1195 $this->db->commit();
1196 return 1;
1197 }
1198 }
1199
1213 public function verifDateHolidayCP($fk_user, $dateStart, $dateEnd, $halfday = 0)
1214 {
1215 $this->fetchByUser($fk_user, '', '');
1216
1217 foreach ($this->holiday as $infos_CP) {
1218 if ($infos_CP['statut'] == Holiday::STATUS_CANCELED) {
1219 continue; // ignore not validated holidays
1220 }
1221 if ($infos_CP['statut'] == Holiday::STATUS_REFUSED) {
1222 continue; // ignore refused holidays
1223 }
1224 //var_dump("--");
1225 //var_dump("old: ".dol_print_date($infos_CP['date_debut'],'dayhour').' '.dol_print_date($infos_CP['date_fin'],'dayhour').' '.$infos_CP['halfday']);
1226 //var_dump("new: ".dol_print_date($dateStart,'dayhour').' '.dol_print_date($dateEnd,'dayhour').' '.$halfday);
1227
1228 if ($halfday == 0) {
1229 if ($dateStart >= $infos_CP['date_debut'] && $dateStart <= $infos_CP['date_fin']) {
1230 return false;
1231 }
1232 if ($dateEnd <= $infos_CP['date_fin'] && $dateEnd >= $infos_CP['date_debut']) {
1233 return false;
1234 }
1235 } elseif ($halfday == -1) {
1236 // new start afternoon, new end afternoon
1237 if ($dateStart >= $infos_CP['date_debut'] && $dateStart <= $infos_CP['date_fin']) {
1238 if ($dateStart < $infos_CP['date_fin'] || in_array($infos_CP['halfday'], array(0, -1))) {
1239 return false;
1240 }
1241 }
1242 if ($dateEnd <= $infos_CP['date_fin'] && $dateEnd >= $infos_CP['date_debut']) {
1243 if ($dateStart < $dateEnd) {
1244 return false;
1245 }
1246 if ($dateEnd < $infos_CP['date_fin'] || in_array($infos_CP['halfday'], array(0, -1))) {
1247 return false;
1248 }
1249 }
1250 } elseif ($halfday == 1) {
1251 // new start morning, new end morning
1252 if ($dateStart >= $infos_CP['date_debut'] && $dateStart <= $infos_CP['date_fin']) {
1253 if ($dateStart < $dateEnd) {
1254 return false;
1255 }
1256 if ($dateStart > $infos_CP['date_debut'] || in_array($infos_CP['halfday'], array(0, 1))) {
1257 return false;
1258 }
1259 }
1260 if ($dateEnd <= $infos_CP['date_fin'] && $dateEnd >= $infos_CP['date_debut']) {
1261 if ($dateEnd > $infos_CP['date_debut'] || in_array($infos_CP['halfday'], array(0, 1))) {
1262 return false;
1263 }
1264 }
1265 } elseif ($halfday == 2) {
1266 // new start afternoon, new end morning
1267 if ($dateStart >= $infos_CP['date_debut'] && $dateStart <= $infos_CP['date_fin']) {
1268 if ($dateStart < $infos_CP['date_fin'] || in_array($infos_CP['halfday'], array(0, -1))) {
1269 return false;
1270 }
1271 }
1272 if ($dateEnd <= $infos_CP['date_fin'] && $dateEnd >= $infos_CP['date_debut']) {
1273 if ($dateEnd > $infos_CP['date_debut'] || in_array($infos_CP['halfday'], array(0, 1))) {
1274 return false;
1275 }
1276 }
1277 } else {
1278 dol_print_error(null, 'Bad value of parameter halfday when calling function verifDateHolidayCP');
1279 }
1280 }
1281
1282 return true;
1283 }
1284
1285
1295 public function verifDateHolidayForTimestamp($fk_user, $timestamp, $status = '-1')
1296 {
1297 $isavailablemorning = true;
1298 $isavailableafternoon = true;
1299
1300 // Check into leave requests
1301 $sql = "SELECT cp.rowid, cp.date_debut as date_start, cp.date_fin as date_end, cp.halfday, cp.statut as status";
1302 $sql .= " FROM ".MAIN_DB_PREFIX."holiday as cp";
1303 $sql .= " WHERE cp.entity IN (".getEntity('holiday').")";
1304 $sql .= " AND cp.fk_user = ".(int) $fk_user;
1305 $sql .= " AND cp.date_debut <= '".$this->db->idate($timestamp)."' AND cp.date_fin >= '".$this->db->idate($timestamp)."'";
1306 if ($status != '-1') {
1307 $sql .= " AND cp.statut IN (".$this->db->sanitize($status).")";
1308 }
1309
1310 $resql = $this->db->query($sql);
1311 if ($resql) {
1312 $num_rows = $this->db->num_rows($resql); // Note, we can have 2 records if on is morning and the other one is afternoon
1313 if ($num_rows > 0) {
1314 $arrayofrecord = array();
1315 $i = 0;
1316 while ($i < $num_rows) {
1317 $obj = $this->db->fetch_object($resql);
1318
1319 // Note: $obj->halfday is 0:Full days, 2:Start afternoon end morning, -1:Start afternoon, 1:End morning
1320 $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);
1321 $i++;
1322 }
1323
1324 // We found a record, user is on holiday by default, so is not available is true.
1325 $isavailablemorning = true;
1326 foreach ($arrayofrecord as $record) {
1327 if ($timestamp == $record['date_start'] && $record['halfday'] == 2) {
1328 continue;
1329 }
1330 if ($timestamp == $record['date_start'] && $record['halfday'] == -1) {
1331 continue;
1332 }
1333 $isavailablemorning = false;
1334 break;
1335 }
1336 $isavailableafternoon = true;
1337 foreach ($arrayofrecord as $record) {
1338 if ($timestamp == $record['date_end'] && $record['halfday'] == 2) {
1339 continue;
1340 }
1341 if ($timestamp == $record['date_end'] && $record['halfday'] == 1) {
1342 continue;
1343 }
1344 $isavailableafternoon = false;
1345 break;
1346 }
1347 }
1348 } else {
1349 dol_print_error($this->db);
1350 }
1351
1352 $result = array('morning' => $isavailablemorning, 'afternoon' => $isavailableafternoon);
1353 if (!$isavailablemorning) {
1354 $result['morning_reason'] = 'leave_request';
1355 }
1356 if (!$isavailableafternoon) {
1357 $result['afternoon_reason'] = 'leave_request';
1358 }
1359 return $result;
1360 }
1361
1368 public function getTooltipContentArray($params)
1369 {
1370 global $langs;
1371
1372 $langs->load('holiday');
1373 $nofetch = !empty($params['nofetch']);
1374
1375 $datas = array();
1376 $datas['picto'] = img_picto('', $this->picto).' <u class="paddingrightonly">'.$langs->trans("Holiday").'</u>';
1377 if (isset($this->status)) {
1378 $datas['picto'] .= ' '.$this->getLibStatut(5);
1379 }
1380 $datas['ref'] = '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref;
1381 // show type for this record only in ajax to not overload lists
1382 if (!$nofetch && !empty($this->fk_type)) {
1383 $typeleaves = $this->getTypes(1, -1);
1384 if (empty($typeleaves[$this->fk_type])) {
1385 $labeltoshow = $langs->trans("TypeWasDisabledOrRemoved", $this->fk_type);
1386 } else {
1387 $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']);
1388 }
1389 $datas['type'] = '<br><b>'.$langs->trans("Type") . ':</b> ' . $labeltoshow;
1390 }
1391 if (isset($this->halfday) && !empty($this->date_debut) && !empty($this->date_fin)) {
1392 $listhalfday = array(
1393 'morning' => $langs->trans("Morning"),
1394 "afternoon" => $langs->trans("Afternoon")
1395 );
1396 $starthalfday = ($this->halfday == -1 || $this->halfday == 2) ? 'afternoon' : 'morning';
1397 $endhalfday = ($this->halfday == 1 || $this->halfday == 2) ? 'morning' : 'afternoon';
1398 $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>';
1399 $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>';
1400 }
1401
1402
1403 return $datas;
1404 }
1405
1415 public function getNomUrl($withpicto = 0, $save_lastsearch_value = -1, $notooltip = 0, $morecss = '')
1416 {
1417 global $conf, $langs, $hookmanager;
1418
1419 if (!empty($conf->dol_no_mouse_hover)) {
1420 $notooltip = 1; // Force disable tooltips
1421 }
1422
1423 $result = '';
1424 $params = [
1425 'id' => $this->id,
1426 'objecttype' => $this->element,
1427 'nofetch' => 1,
1428 ];
1429 $classfortooltip = 'classfortooltip';
1430 $dataparams = '';
1431 if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
1432 $classfortooltip = 'classforajaxtooltip';
1433 $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"';
1434 $label = '';
1435 } else {
1436 $label = implode($this->getTooltipContentArray($params));
1437 }
1438
1439 $url = DOL_URL_ROOT.'/holiday/card.php?id='.$this->id;
1440
1441 //if ($option != 'nolink')
1442 //{
1443 // Add param to save lastsearch_values or not
1444 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1445 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
1446 $add_save_lastsearch_values = 1;
1447 }
1448 if ($add_save_lastsearch_values) {
1449 $url .= '&save_lastsearch_values=1';
1450 }
1451 //}
1452
1453 $linkclose = '';
1454 if (empty($notooltip)) {
1455 if (getDolGlobalInt('MAIN_OPTIMIZEFORTEXTBROWSER')) {
1456 $label = $langs->trans("ShowMyObject");
1457 $linkclose .= ' alt="'.dolPrintHTMLForAttribute($label).'"';
1458 }
1459 $linkclose .= ($label ? ' title="'.dolPrintHTMLForAttribute($label).'"' : ' title="tocomplete"');
1460 $linkclose .= $dataparams.' class="'.$classfortooltip.($morecss ? ' '.$morecss : '').'"';
1461 } else {
1462 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
1463 }
1464
1465 $linkstart = '<a href="'.$url.'"';
1466 $linkstart .= $linkclose.'>';
1467 $linkend = '</a>';
1468
1469 $result .= $linkstart;
1470
1471 if ($withpicto) {
1472 $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'"'), 0, 0, $notooltip ? 0 : 1);
1473 }
1474 if ($withpicto != 2) {
1475 $result .= $this->ref;
1476 }
1477 $result .= $linkend;
1478
1479 global $action;
1480 $hookmanager->initHooks(array($this->element . 'dao'));
1481 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
1482 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
1483 if ($reshook > 0) {
1484 $result = $hookmanager->resPrint;
1485 } else {
1486 $result .= $hookmanager->resPrint;
1487 }
1488 return $result;
1489 }
1490
1491
1498 public function getLibStatut($mode = 0)
1499 {
1500 return $this->LibStatut($this->status, $mode, $this->date_debut);
1501 }
1502
1503 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1512 public function LibStatut($status, $mode = 0, $startdate = '')
1513 {
1514 // phpcs:enable
1515 global $langs;
1516
1517 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
1518 global $langs;
1519 //$langs->load("mymodule");
1520 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('DraftCP');
1521 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('ToReviewCP');
1522 $this->labelStatus[self::STATUS_APPROVED] = $langs->transnoentitiesnoconv('ApprovedCP');
1523 $this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('CancelCP');
1524 $this->labelStatus[self::STATUS_REFUSED] = $langs->transnoentitiesnoconv('RefuseCP');
1525 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('DraftCP');
1526 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('ToReviewCP');
1527 $this->labelStatusShort[self::STATUS_APPROVED] = $langs->transnoentitiesnoconv('ApprovedCP');
1528 $this->labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('CancelCP');
1529 $this->labelStatusShort[self::STATUS_REFUSED] = $langs->transnoentitiesnoconv('RefuseCP');
1530 }
1531
1532 $params = array();
1533 $statusType = 'status6';
1534 if (!empty($startdate) && $startdate >= dol_now()) { // If not yet passed, we use a green "in live" color
1535 $statusType = 'status4';
1536 $params = array('tooltip' => $this->labelStatus[$status].' - '.$langs->trans("Forthcoming"));
1537 }
1538 if ($status == self::STATUS_DRAFT) {
1539 $statusType = 'status0';
1540 }
1541 if ($status == self::STATUS_VALIDATED) {
1542 $statusType = 'status1';
1543 }
1544 if ($status == self::STATUS_CANCELED) {
1545 $statusType = 'status9';
1546 }
1547 if ($status == self::STATUS_REFUSED) {
1548 $statusType = 'status9';
1549 }
1550
1551 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode, '', $params);
1552 }
1553
1554
1563 public function selectStatutCP($selected = 0, $htmlname = 'select_statut', $morecss = 'minwidth125')
1564 {
1565 global $langs;
1566
1567 // List of status label
1568 $name = array('DraftCP', 'ToReviewCP', 'ApprovedCP', 'CancelCP', 'RefuseCP');
1569 $nb = count($name) + 1;
1570
1571 // Select HTML
1572 $out = '<select name="'.$htmlname.'" id="'.$htmlname.'" class="flat'.($morecss ? ' '.$morecss : '').'">'."\n";
1573 $out .= '<option value="-1">&nbsp;</option>'."\n";
1574
1575 // Loop on status
1576 for ($i = 1; $i < $nb; $i++) {
1577 if ($i == $selected) {
1578 $out .= '<option value="'.$i.'" selected>'.$langs->trans($name[$i - 1]).'</option>'."\n";
1579 } else {
1580 $out .= '<option value="'.$i.'">'.$langs->trans($name[$i - 1]).'</option>'."\n";
1581 }
1582 }
1583
1584 $out .= "</select>\n";
1585
1586 $showempty = 0;
1587 $out .= ajax_combobox($htmlname, array(), 0, 0, 'resolve', ($showempty < 0 ? (string) $showempty : '-1'), $morecss);
1588
1589 return $out;
1590 }
1591
1599 public function updateConfCP($name, $value)
1600 {
1601 $sql = "UPDATE ".MAIN_DB_PREFIX."holiday_config SET";
1602 $sql .= " value = '".$this->db->escape($value)."'";
1603 $sql .= " WHERE name = '".$this->db->escape($name)."'";
1604
1605 dol_syslog(get_class($this).'::updateConfCP name='.$name, LOG_DEBUG);
1606 $result = $this->db->query($sql);
1607 if ($result) {
1608 return true;
1609 }
1610
1611 return false;
1612 }
1613
1622 public function getConfCP($name, $createifnotfound = '')
1623 {
1624 $sql = "SELECT value";
1625 $sql .= " FROM ".MAIN_DB_PREFIX."holiday_config";
1626 $sql .= " WHERE name = '".$this->db->escape($name)."'";
1627
1628 dol_syslog(get_class($this).'::getConfCP name='.$name.' createifnotfound='.$createifnotfound, LOG_DEBUG);
1629 $result = $this->db->query($sql);
1630
1631 if ($result) {
1632 $obj = $this->db->fetch_object($result);
1633 // Return value
1634 if (empty($obj)) {
1635 if ($createifnotfound) {
1636 $sql = "INSERT INTO ".MAIN_DB_PREFIX."holiday_config(name, value)";
1637 $sql .= " VALUES('".$this->db->escape($name)."', '".$this->db->escape($createifnotfound)."')";
1638 $result = $this->db->query($sql);
1639 if ($result) {
1640 return $createifnotfound;
1641 } else {
1642 $this->error = $this->db->lasterror();
1643 return -2;
1644 }
1645 } else {
1646 return '';
1647 }
1648 } else {
1649 return $obj->value;
1650 }
1651 } else {
1652 // Erreur SQL
1653 $this->error = $this->db->lasterror();
1654 return -1;
1655 }
1656 }
1657
1666 public function updateSoldeCP($userID = 0, $nbHoliday = 0, $fk_type = 0)
1667 {
1668 global $user, $langs;
1669
1670 $error = 0;
1671
1672 if (empty($userID) && empty($nbHoliday) && empty($fk_type)) {
1673 $langs->load("holiday");
1674
1675 $decrease = getDolGlobalInt('HOLIDAY_DECREASE_AT_END_OF_MONTH');
1676
1677 // Si mise à jour pour tout le monde en début de mois
1678 $now = dol_now();
1679
1680 // Get month of last update
1681 $stringInDBForLastUpdate = $this->getConfCP('lastUpdate', dol_print_date($now, '%Y%m%d%H%M%S')); // Example '20200101120000'
1682 // Protection when $lastUpdate has a not valid value
1683 if ($stringInDBForLastUpdate < '20000101000000') {
1684 $stringInDBForLastUpdate = '20000101000000';
1685 }
1686 $lastUpdate = dol_stringtotime($stringInDBForLastUpdate);
1687 //print 'lastUpdate:'.$lastUpdate;exit;
1688
1689 $yearMonthLastUpdate = dol_print_date($lastUpdate, '%Y%m');
1690 $yearMonthNow = dol_print_date($now, '%Y%m');
1691 //print 'yearMonthLastUpdate='.$yearMonthLastUpdate.' yearMonthNow='.$yearMonthNow;
1692
1693 // 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,
1694 // catching up to the current month if a gap is detected
1695 while ($yearMonthLastUpdate < $yearMonthNow) {
1696 $this->db->begin();
1697
1698 $year = dol_print_date($lastUpdate, '%Y');
1699 $month = dol_print_date($lastUpdate, '%m');
1700
1701 $users = $this->fetchUsers(false, false, ' AND u.statut > 0');
1702 $nbUser = count($users);
1703
1704 $typeleaves = $this->getTypes(1, 1);
1705
1706 // Update each user counter
1707 foreach ($users as $userCounter) {
1708 $nbDaysToAdd = (isset($typeleaves[$userCounter['type']]['newbymonth']) ? $typeleaves[$userCounter['type']]['newbymonth'] : 0);
1709 if (empty($nbDaysToAdd)) {
1710 continue;
1711 }
1712
1713 dol_syslog("We update leave type id ".$userCounter['type']." for user id ".$userCounter['rowid'], LOG_DEBUG);
1714
1715 $nowHoliday = (float) $userCounter['nb_holiday'];
1716 $newSolde = $nowHoliday + $nbDaysToAdd;
1717
1718 // We add a log for each user when its balance gets increased
1719 $this->addLogCP($user->id, $userCounter['rowid'], $langs->trans('HolidayMonthlyCredit'), $newSolde, $userCounter['type']);
1720
1721 $result = $this->updateSoldeCP($userCounter['rowid'], $newSolde, $userCounter['type']);
1722
1723 if ($result < 0) {
1724 $this->db->rollback();
1725 return -1;
1726 }
1727
1728 if (empty($decrease)) {
1729 continue;
1730 }
1731
1732 // 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
1733 $filter = " AND cp.statut = ".((int) self::STATUS_APPROVED);
1734 $filter .= " AND cp.date_fin >= '".$this->db->idate(dol_stringtotime(dol_print_date($lastUpdate, '%Y-%m-01')))."'";
1735 $filter .= " AND cp.date_debut <= '".$this->db->idate(dol_stringtotime(dol_print_date($lastUpdate, '%Y-%m-t')))."'";
1736 $filter .= " AND cp.fk_type = ".((int) $userCounter['type']);
1737 $this->fetchByUser($userCounter['id'], '', $filter);
1738
1739 if (empty($this->holiday)) {
1740 continue;
1741 }
1742
1743 $startOfMonth = dol_mktime(0, 0, 0, (int) $month, 1, (int) $year, 1);
1744 $endOfMonth = dol_mktime(0, 0, 0, (int) $month, (int) dol_print_date($lastUpdate, 't'), (int) $year, 1);
1745
1746 foreach ($this->holiday as $obj) {
1747 $startDate = $obj['date_debut_gmt'];
1748 $endDate = $obj['date_fin_gmt'];
1749
1750 if ($startDate <= $endOfMonth && $startDate < $startOfMonth) {
1751 $startDate = $startOfMonth;
1752 }
1753
1754 if ($startOfMonth <= $endDate && $endDate > $endOfMonth) {
1755 $endDate = $endOfMonth;
1756 }
1757
1758 $nbDaysToDeduct = (int) num_open_day($startDate, $endDate, 0, 1, $obj['halfday']);
1759
1760 if ($nbDaysToDeduct <= 0) {
1761 continue;
1762 }
1763
1764 $newSolde -= $nbDaysToDeduct;
1765
1766 // We add a log for each user when its balance gets decreased
1767 $this->addLogCP($user->id, $userCounter['rowid'], $obj['ref'].' - '.$langs->trans('HolidayConsumption'), $newSolde, $userCounter['type']);
1768
1769 $result = $this->updateSoldeCP($userCounter['rowid'], $newSolde, $userCounter['type']);
1770
1771 if ($result < 0) {
1772 $this->db->rollback();
1773 return -1;
1774 }
1775 }
1776 }
1777
1778 //updating the date of the last monthly balance update
1779 $newMonth = dol_get_next_month((int) dol_print_date($lastUpdate, '%m'), (int) dol_print_date($lastUpdate, '%Y'));
1780 $lastUpdate = dol_mktime(0, 0, 0, (int) $newMonth['month'], 1, (int) $newMonth['year']);
1781
1782 $sql = "UPDATE ".MAIN_DB_PREFIX."holiday_config SET";
1783 $sql .= " value = '".$this->db->escape(dol_print_date($lastUpdate, '%Y%m%d%H%M%S'))."'";
1784 $sql .= " WHERE name = 'lastUpdate'";
1785 $result = $this->db->query($sql);
1786
1787 if (!$result) {
1788 $this->db->rollback();
1789 return -1;
1790 }
1791
1792 $this->db->commit();
1793
1794 $yearMonthLastUpdate = dol_print_date($lastUpdate, '%Y%m');
1795 }
1796
1797 if (!$error) {
1798 return 1;
1799 } else {
1800 return 0;
1801 }
1802 } else {
1803 // Mise à jour pour un utilisateur
1804 $nbHoliday = price2num($nbHoliday, 5);
1805
1806 $sql = "SELECT nb_holiday FROM ".MAIN_DB_PREFIX."holiday_users";
1807 $sql .= " WHERE fk_user = ".(int) $userID." AND fk_type = ".(int) $fk_type;
1808 $resql = $this->db->query($sql);
1809 if ($resql) {
1810 $num = $this->db->num_rows($resql);
1811
1812 if ($num > 0) {
1813 // Update for user
1814 $sql = "UPDATE ".MAIN_DB_PREFIX."holiday_users SET";
1815 $sql .= " nb_holiday = ".((float) $nbHoliday);
1816 $sql .= " WHERE fk_user = ".(int) $userID." AND fk_type = ".(int) $fk_type;
1817 $result = $this->db->query($sql);
1818 if (!$result) {
1819 $error++;
1820 $this->errors[] = $this->db->lasterror();
1821 }
1822 } else {
1823 // Insert for user
1824 $sql = "INSERT INTO ".MAIN_DB_PREFIX."holiday_users(nb_holiday, fk_user, fk_type) VALUES (";
1825 $sql .= ((float) $nbHoliday);
1826 $sql .= ", ".(int) $userID.", ".(int) $fk_type.")";
1827 $result = $this->db->query($sql);
1828 if (!$result) {
1829 $error++;
1830 $this->errors[] = $this->db->lasterror();
1831 }
1832 }
1833 } else {
1834 $this->errors[] = $this->db->lasterror();
1835 $error++;
1836 }
1837
1838 if (!$error) {
1839 return 1;
1840 } else {
1841 return -1;
1842 }
1843 }
1844 }
1845
1853 public function createCPusers($single = false, $userid = 0)
1854 {
1855 // do we have to add balance for all users ?
1856 if (!$single) {
1857 dol_syslog(get_class($this).'::createCPusers');
1858 $arrayofusers = $this->fetchUsers(false, true);
1859
1860 foreach ($arrayofusers as $users) {
1861 $sql = "INSERT INTO ".MAIN_DB_PREFIX."holiday_users";
1862 $sql .= " (fk_user, nb_holiday)";
1863 $sql .= " VALUES (".((int) $users['rowid'])."', '0')";
1864
1865 $resql = $this->db->query($sql);
1866 if (!$resql) {
1867 dol_print_error($this->db);
1868 }
1869 }
1870 } else {
1871 $sql = "INSERT INTO ".MAIN_DB_PREFIX."holiday_users";
1872 $sql .= " (fk_user, nb_holiday)";
1873 $sql .= " VALUES (".((int) $userid)."', '0')";
1874
1875 $resql = $this->db->query($sql);
1876 if (!$resql) {
1877 dol_print_error($this->db);
1878 }
1879 }
1880 }
1881
1889 public function getCPforUser($user_id, $fk_type = 0)
1890 {
1891 $sql = "SELECT nb_holiday";
1892 $sql .= " FROM ".MAIN_DB_PREFIX."holiday_users";
1893 $sql .= " WHERE fk_user = ".(int) $user_id;
1894 if ($fk_type > 0) {
1895 $sql .= " AND fk_type = ".(int) $fk_type;
1896 }
1897
1898 dol_syslog(get_class($this).'::getCPforUser user_id='.$user_id.' type_id='.$fk_type, LOG_DEBUG);
1899 $result = $this->db->query($sql);
1900 if ($result) {
1901 $obj = $this->db->fetch_object($result);
1902 //return number_format($obj->nb_holiday,2);
1903 if ($obj) {
1904 return $obj->nb_holiday;
1905 } else {
1906 return null;
1907 }
1908 } else {
1909 return null;
1910 }
1911 }
1912
1921 public function fetchUsers($stringlist = true, $type = true, $filters = '')
1922 {
1923 global $conf;
1924
1925 dol_syslog(get_class($this)."::fetchUsers", LOG_DEBUG);
1926
1927 if ($stringlist) {
1928 if ($type) {
1929 // If user of Dolibarr
1930 $sql = "SELECT";
1931 if (isModEnabled('multicompany') && getDolGlobalString('MULTICOMPANY_TRANSVERSE_MODE')) {
1932 $sql .= " DISTINCT";
1933 }
1934 $sql .= " u.rowid";
1935 $sql .= " FROM ".MAIN_DB_PREFIX."user as u";
1936
1937 if (isModEnabled('multicompany') && getDolGlobalString('MULTICOMPANY_TRANSVERSE_MODE')) {
1938 $sql .= ", ".MAIN_DB_PREFIX."usergroup_user as ug";
1939 $sql .= " WHERE ((ug.fk_user = u.rowid";
1940 $sql .= " AND ug.entity IN (".getEntity('usergroup')."))";
1941 $sql .= " OR u.entity = 0)"; // Show always superadmin
1942 } else {
1943 $sql .= " WHERE u.entity IN (".getEntity('user').")";
1944 }
1945 $sql .= " AND u.statut > 0";
1946 $sql .= " AND u.employee = 1"; // We only want employee users for holidays
1947 if ($filters) {
1948 $sql .= $filters;
1949 }
1950
1951 $resql = $this->db->query($sql);
1952
1953 // Si pas d'erreur SQL
1954 if ($resql) {
1955 $i = 0;
1956 $num = $this->db->num_rows($resql);
1957 $stringlist = '';
1958
1959 // Boucles du listage des utilisateurs
1960 while ($i < $num) {
1961 $obj = $this->db->fetch_object($resql);
1962
1963 if ($i == 0) {
1964 $stringlist .= $obj->rowid;
1965 } else {
1966 $stringlist .= ', '.$obj->rowid;
1967 }
1968
1969 $i++;
1970 }
1971 // Retoune le tableau des utilisateurs
1972 return $stringlist;
1973 } else {
1974 // Erreur SQL
1975 $this->error = "Error ".$this->db->lasterror();
1976 return -1;
1977 }
1978 } else {
1979 // We want only list of vacation balance for user ids
1980 $sql = "SELECT DISTINCT cpu.fk_user";
1981 $sql .= " FROM ".MAIN_DB_PREFIX."holiday_users as cpu, ".MAIN_DB_PREFIX."user as u";
1982 $sql .= " WHERE cpu.fk_user = u.rowid";
1983 if ($filters) {
1984 $sql .= $filters;
1985 }
1986
1987 $resql = $this->db->query($sql);
1988
1989 // Si pas d'erreur SQL
1990 if ($resql) {
1991 $i = 0;
1992 $num = $this->db->num_rows($resql);
1993 $stringlist = '';
1994
1995 // Boucles du listage des utilisateurs
1996 while ($i < $num) {
1997 $obj = $this->db->fetch_object($resql);
1998
1999 if ($i == 0) {
2000 $stringlist .= $obj->fk_user;
2001 } else {
2002 $stringlist .= ', '.$obj->fk_user;
2003 }
2004
2005 $i++;
2006 }
2007 // Retoune le tableau des utilisateurs
2008 return $stringlist;
2009 } else {
2010 // Erreur SQL
2011 $this->error = "Error ".$this->db->lasterror();
2012 return -1;
2013 }
2014 }
2015 } else {
2016 // Si faux donc return array
2017 // List for Dolibarr users
2018 if ($type) {
2019 // If we need users of Dolibarr
2020 $sql = "SELECT";
2021 if (isModEnabled('multicompany') && getDolGlobalString('MULTICOMPANY_TRANSVERSE_MODE')) {
2022 $sql .= " DISTINCT";
2023 }
2024 $sql .= " u.rowid, u.lastname, u.firstname, u.gender, u.photo, u.employee, u.statut as status, u.fk_user";
2025 $sql .= " FROM ".MAIN_DB_PREFIX."user as u";
2026
2027 if (isModEnabled('multicompany') && getDolGlobalString('MULTICOMPANY_TRANSVERSE_MODE')) {
2028 $sql .= ", ".MAIN_DB_PREFIX."usergroup_user as ug";
2029 $sql .= " WHERE ((ug.fk_user = u.rowid";
2030 $sql .= " AND ug.entity IN (".getEntity('usergroup')."))";
2031 $sql .= " OR u.entity = 0)"; // Show always superadmin
2032 } else {
2033 $sql .= " WHERE u.entity IN (".getEntity('user').")";
2034 }
2035
2036 $sql .= " AND u.statut > 0";
2037 $sql .= " AND u.employee = 1"; // We only want employee users for holidays
2038 if ($filters) {
2039 $sql .= $filters;
2040 }
2041
2042 $resql = $this->db->query($sql);
2043
2044 // Si pas d'erreur SQL
2045 if ($resql) {
2046 $i = 0;
2047 $tab_result = $this->holiday;
2048 $num = $this->db->num_rows($resql);
2049
2050 // Boucles du listage des utilisateurs
2051 while ($i < $num) {
2052 $obj = $this->db->fetch_object($resql);
2053
2054 $tab_result[$i]['rowid'] = (int) $obj->rowid; // rowid of user
2055 $tab_result[$i]['id'] = (int) $obj->rowid; // id of user
2056 $tab_result[$i]['name'] = $obj->lastname; // deprecated
2057 $tab_result[$i]['lastname'] = $obj->lastname;
2058 $tab_result[$i]['firstname'] = $obj->firstname;
2059 $tab_result[$i]['gender'] = $obj->gender;
2060 $tab_result[$i]['status'] = (int) $obj->status;
2061 $tab_result[$i]['employee'] = (int) $obj->employee;
2062 $tab_result[$i]['photo'] = $obj->photo;
2063 $tab_result[$i]['fk_user'] = (int) $obj->fk_user; // rowid of manager
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 OUTER 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 global $conf, $langs;
2228
2229 $error = 0;
2230
2231 $prev_solde = price2num($this->getCPforUser($fk_user_update, $fk_type), 5);
2232 $new_solde = price2num($new_solde, 5);
2233 //print "$prev_solde == $new_solde";
2234
2235 if ($prev_solde == $new_solde) {
2236 return 0;
2237 }
2238
2239 $this->db->begin();
2240
2241 // Insert request
2242 $sql = "INSERT INTO ".MAIN_DB_PREFIX."holiday_logs (";
2243 $sql .= "date_action,";
2244 $sql .= "fk_user_action,";
2245 $sql .= "fk_user_update,";
2246 $sql .= "type_action,";
2247 $sql .= "prev_solde,";
2248 $sql .= "new_solde,";
2249 $sql .= "fk_type";
2250 $sql .= ") VALUES (";
2251 $sql .= " '".$this->db->idate(dol_now())."',";
2252 $sql .= " ".((int) $fk_user_action).",";
2253 $sql .= " ".((int) $fk_user_update).",";
2254 $sql .= " '".$this->db->escape($label)."',";
2255 $sql .= " ".((float) $prev_solde).",";
2256 $sql .= " ".((float) $new_solde).",";
2257 $sql .= " ".((int) $fk_type);
2258 $sql .= ")";
2259
2260 $resql = $this->db->query($sql);
2261 if (!$resql) {
2262 $error++;
2263 $this->errors[] = "Error ".$this->db->lasterror();
2264 }
2265
2266 if (!$error) {
2267 $this->optRowid = $this->db->last_insert_id(MAIN_DB_PREFIX."holiday_logs");
2268 }
2269
2270 // Commit or rollback
2271 if ($error) {
2272 foreach ($this->errors as $errmsg) {
2273 dol_syslog(get_class($this)."::addLogCP ".$errmsg, LOG_ERR);
2274 $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
2275 }
2276 $this->db->rollback();
2277 return -1 * $error;
2278 } else {
2279 $this->db->commit();
2280 return $this->optRowid;
2281 }
2282 }
2283
2291 public function fetchLog($sqlorder, $sqlwhere)
2292 {
2293 $sql = "SELECT";
2294 $sql .= " cpl.rowid,";
2295 $sql .= " cpl.date_action,";
2296 $sql .= " cpl.fk_user_action,";
2297 $sql .= " cpl.fk_user_update,";
2298 $sql .= " cpl.type_action,";
2299 $sql .= " cpl.prev_solde,";
2300 $sql .= " cpl.new_solde,";
2301 $sql .= " cpl.fk_type";
2302 $sql .= " FROM ".MAIN_DB_PREFIX."holiday_logs as cpl";
2303 $sql .= " WHERE cpl.rowid > 0"; // To avoid error with other search and criteria
2304
2305 // Filter
2306 if (!empty($sqlwhere)) {
2307 $sql .= " ".$sqlwhere;
2308 }
2309
2310 // Order
2311 if (!empty($sqlorder)) {
2312 $sql .= " ".$sqlorder;
2313 }
2314
2315 dol_syslog(get_class($this)."::fetchLog", LOG_DEBUG);
2316 $resql = $this->db->query($sql);
2317
2318 // If no error SQL
2319 if ($resql) {
2320 $i = 0;
2321 $tab_result = $this->logs;
2322 $num = $this->db->num_rows($resql);
2323
2324 // If no record
2325 if (!$num) {
2326 return 2;
2327 }
2328
2329 // Loop on result to fill the array
2330 while ($i < $num) {
2331 $obj = $this->db->fetch_object($resql);
2332
2333 $tab_result[$i]['rowid'] = $obj->rowid;
2334 $tab_result[$i]['id'] = $obj->rowid;
2335 $tab_result[$i]['date_action'] = $obj->date_action;
2336 $tab_result[$i]['fk_user_action'] = $obj->fk_user_action;
2337 $tab_result[$i]['fk_user_update'] = $obj->fk_user_update;
2338 $tab_result[$i]['type_action'] = $obj->type_action;
2339 $tab_result[$i]['prev_solde'] = $obj->prev_solde;
2340 $tab_result[$i]['new_solde'] = $obj->new_solde;
2341 $tab_result[$i]['fk_type'] = $obj->fk_type;
2342
2343 $i++;
2344 }
2345 // Retourne 1 et ajoute le tableau à la variable
2346 $this->logs = $tab_result;
2347 return 1;
2348 } else {
2349 // Erreur SQL
2350 $this->error = "Error ".$this->db->lasterror();
2351 return -1;
2352 }
2353 }
2354
2355
2363 public function getTypes($active = -1, $affect = -1)
2364 {
2365 global $mysoc;
2366
2367 $sql = "SELECT rowid, code, label, affect, delay, newbymonth";
2368 $sql .= " FROM ".MAIN_DB_PREFIX."c_holiday_types";
2369 $sql .= " WHERE (fk_country IS NULL OR fk_country = ".((int) $mysoc->country_id).')';
2370 $sql .= " AND entity IN (".getEntity('c_holiday_types').")";
2371 if ($active >= 0) {
2372 $sql .= " AND active = ".((int) $active);
2373 }
2374 if ($affect >= 0) {
2375 $sql .= " AND affect = ".((int) $affect);
2376 }
2377 $sql .= " ORDER BY sortorder";
2378
2379 $result = $this->db->query($sql);
2380 if ($result) {
2381 $num = $this->db->num_rows($result);
2382 if ($num) {
2383 $types = array();
2384 while ($obj = $this->db->fetch_object($result)) {
2385 $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);
2386 }
2387
2388 return $types;
2389 }
2390 } else {
2391 dol_print_error($this->db);
2392 }
2393
2394 return array();
2395 }
2396
2397
2404 public function info($id)
2405 {
2406 global $conf;
2407
2408 $sql = "SELECT f.rowid, f.statut as status,";
2409 $sql .= " f.date_create as datec,";
2410 $sql .= " f.tms as date_modification,";
2411 $sql .= " f.date_valid as datev,";
2412 $sql .= " f.date_approval as datea,";
2413 $sql .= " f.date_refuse as dater,";
2414 $sql .= " f.fk_user_create as fk_user_creation,";
2415 $sql .= " f.fk_user_modif as fk_user_modification,";
2416 $sql .= " f.fk_user_valid as fk_user_validation,";
2417 $sql .= " f.fk_user_approve as fk_user_approval_done,";
2418 $sql .= " f.fk_validator as fk_user_approval_expected,";
2419 $sql .= " f.fk_user_refuse as fk_user_refuse";
2420 $sql .= " FROM ".MAIN_DB_PREFIX."holiday as f";
2421 $sql .= " WHERE f.rowid = ".((int) $id);
2422 $sql .= " AND f.entity = ".$conf->entity;
2423
2424 $resql = $this->db->query($sql);
2425 if ($resql) {
2426 if ($this->db->num_rows($resql)) {
2427 $obj = $this->db->fetch_object($resql);
2428
2429 $this->id = $obj->rowid;
2430
2431 $this->date_creation = $this->db->jdate($obj->datec);
2432 $this->date_modification = $this->db->jdate($obj->date_modification);
2433 $this->date_validation = $this->db->jdate($obj->datev);
2434 $this->date_approval = $this->db->jdate($obj->datea);
2435
2436 $this->user_creation_id = $obj->fk_user_creation;
2437 $this->user_validation_id = $obj->fk_user_validation;
2438 $this->user_modification_id = $obj->fk_user_modification;
2439
2440 if ($obj->status == Holiday::STATUS_APPROVED || $obj->status == Holiday::STATUS_CANCELED) {
2441 if ($obj->fk_user_approval_done) {
2442 $this->fk_user_approve = $obj->fk_user_approval_done;
2443 }
2444 }
2445 }
2446 $this->db->free($resql);
2447 } else {
2448 dol_print_error($this->db);
2449 }
2450 }
2451
2452
2460 public function initAsSpecimen()
2461 {
2462 global $user, $langs;
2463
2464 // Initialise parameters
2465 $this->id = 0;
2466 $this->specimen = 1;
2467
2468 $this->fk_user = $user->id;
2469 $this->description = 'SPECIMEN description';
2470 $this->date_debut = dol_now();
2471 $this->date_fin = dol_now() + (24 * 3600);
2472 $this->date_valid = dol_now();
2473 $this->fk_validator = $user->id;
2474 $this->halfday = 0;
2475 $this->fk_type = 1;
2477
2478 return 1;
2479 }
2480
2486 public function loadStateBoard()
2487 {
2488 global $user;
2489
2490 $this->nb = array();
2491
2492 $sql = "SELECT count(h.rowid) as nb";
2493 $sql .= " FROM ".MAIN_DB_PREFIX."holiday as h";
2494 $sql .= " WHERE h.statut > 1";
2495 $sql .= " AND h.entity IN (".getEntity('holiday').")";
2496 if (!$user->hasRight('expensereport', 'readall')) {
2497 $userchildids = $user->getAllChildIds(1);
2498 $sql .= " AND (h.fk_user IN (".$this->db->sanitize(implode(',', $userchildids)).")";
2499 $sql .= " OR h.fk_validator IN (".$this->db->sanitize(implode(',', $userchildids))."))";
2500 }
2501
2502 $resql = $this->db->query($sql);
2503 if ($resql) {
2504 while ($obj = $this->db->fetch_object($resql)) {
2505 $this->nb["holidays"] = $obj->nb;
2506 }
2507 $this->db->free($resql);
2508 return 1;
2509 } else {
2510 dol_print_error($this->db);
2511 $this->error = $this->db->error();
2512 return -1;
2513 }
2514 }
2515
2516 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2523 public function load_board($user)
2524 {
2525 // phpcs:enable
2526 global $conf, $langs;
2527
2528 if ($user->socid) {
2529 return -1; // protection pour eviter appel par utilisateur externe
2530 }
2531
2532 $now = dol_now();
2533
2534 $sql = "SELECT h.rowid, h.date_debut";
2535 $sql .= " FROM ".MAIN_DB_PREFIX."holiday as h";
2536 $sql .= " WHERE h.statut = 2";
2537 $sql .= " AND h.entity IN (".getEntity('holiday').")";
2538 if (!$user->hasRight('expensereport', 'read_all')) {
2539 $userchildids = $user->getAllChildIds(1);
2540 $sql .= " AND (h.fk_user IN (".$this->db->sanitize(implode(',', $userchildids)).")";
2541 $sql .= " OR h.fk_validator IN (".$this->db->sanitize(implode(',', $userchildids))."))";
2542 }
2543
2544 $resql = $this->db->query($sql);
2545 if ($resql) {
2546 $langs->load("members");
2547
2548 $response = new WorkboardResponse();
2549 $response->warning_delay = $conf->holiday->approve->warning_delay / 60 / 60 / 24;
2550 $response->label = $langs->trans("HolidaysToApprove");
2551 $response->labelShort = $langs->trans("ToApprove");
2552 $response->url = DOL_URL_ROOT.'/holiday/list.php?search_status=2&amp;mainmenu=hrm&amp;leftmenu=holiday';
2553 $response->img = img_object('', "holiday");
2554
2555 while ($obj = $this->db->fetch_object($resql)) {
2556 $response->nbtodo++;
2557
2558 if ($this->db->jdate($obj->date_debut) < ($now - $conf->holiday->approve->warning_delay)) {
2559 $response->nbtodolate++;
2560 }
2561 }
2562
2563 return $response;
2564 } else {
2565 dol_print_error($this->db);
2566 $this->error = $this->db->error();
2567 return -1;
2568 }
2569 }
2577 public function getKanbanView($option = '', $arraydata = null)
2578 {
2579 global $langs;
2580
2581 $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
2582
2583 $return = '<div class="box-flex-item box-flex-grow-zero">';
2584 $return .= '<div class="info-box info-box-sm">';
2585 $return .= '<span class="info-box-icon bg-infobox-action">';
2586 $return .= img_picto('', $this->picto);
2587 $return .= '</span>';
2588 $return .= '<div class="info-box-content">';
2589 $return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.$this->getNomUrl().'</span>';
2590 if ($selected >= 0) {
2591 $return .= '<input id="cb'.$this->id.'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
2592 }
2593 if (property_exists($this, 'fk_type')) {
2594 $return .= '<br>';
2595 //$return .= '<span class="opacitymedium">'.$langs->trans("Type").'</span> : ';
2596 $return .= '<div class="info_box-label tdoverflowmax100" title="'.dol_escape_htmltag($arraydata['labeltype']).'">'.dol_escape_htmltag($arraydata['labeltype']).'</div>';
2597 }
2598 if (property_exists($this, 'date_debut') && property_exists($this, 'date_fin')) {
2599 $return .= '<span class="info-box-label small">'.dol_print_date($this->date_debut, 'day').'</span>';
2600 $return .= ' <span class="opacitymedium small">'.$langs->trans("To").'</span> ';
2601 $return .= '<span class="info-box-label small">'.dol_print_date($this->date_fin, 'day').'</span>';
2602 if (!empty($arraydata['nbopenedday'])) {
2603 $return .= ' ('.$arraydata['nbopenedday'].')';
2604 }
2605 }
2606 if (method_exists($this, 'getLibStatut')) {
2607 $return .= '<div class="info-box-status">'.$this->getLibStatut(3).'</div>';
2608 }
2609 $return .= '</div>';
2610 $return .= '</div>';
2611 $return .= '</div>';
2612 return $return;
2613 }
2614}
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