dolibarr 22.0.5
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-2025 MDW <mdeweerd@users.noreply.github.com>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 */
23
29require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
30
31
35class Holiday extends CommonObject
36{
40 public $element = 'holiday';
41
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 // Use the GMT variants: num_public_holiday(), called by num_open_day(), refuses a range whose
779 // length is not a whole number of days, and a range spanning a DST transition is 23h or 25h
780 // long in the server timezone. It then returns a string and the subtraction fatals.
781 $datedebutforcount = !empty($this->date_debut_gmt) ? $this->date_debut_gmt : $this->date_debut;
782 $datefinforcount = !empty($this->date_fin_gmt) ? $this->date_fin_gmt : $this->date_fin;
783 $daysAsked = num_open_day($datedebutforcount, $datefinforcount, 0, 1);
784
785 if (($balance - $daysAsked) < 0) {
786 $this->error = 'LeaveRequestCreationBlockedBecauseBalanceIsNegative';
787 return -1;
788 }
789 }
790
791 // Define new ref
792 if (!$error && (preg_match('/^[\‍(]?PROV/i', $this->ref) || empty($this->ref) || $this->ref == $this->id)) {
793 $num = $this->getNextNumRef(null);
794 } else {
795 $num = $this->ref;
796 }
797 $this->newref = dol_sanitizeFileName($num);
798
799 // Update status
800 $sql = "UPDATE ".MAIN_DB_PREFIX."holiday SET";
801 $sql .= " fk_user_valid = ".((int) $user->id).",";
802 $sql .= " date_valid = '".$this->db->idate(dol_now())."',";
803 if (!empty($this->status) && is_numeric($this->status)) {
804 $sql .= " statut = ".((int) $this->status).",";
805 } else {
806 $this->error = 'Property status must be a numeric value';
807 $error++;
808 }
809 $sql .= " ref = '".$this->db->escape($num)."'";
810 $sql .= " WHERE rowid = ".((int) $this->id);
811
812 $this->db->begin();
813
814 dol_syslog(get_class($this)."::validate", LOG_DEBUG);
815 $resql = $this->db->query($sql);
816 if (!$resql) {
817 $error++;
818 $this->errors[] = "Error ".$this->db->lasterror();
819 }
820
821 if (!$error) {
822 if (!$notrigger) {
823 // Call trigger
824 $result = $this->call_trigger('HOLIDAY_VALIDATE', $user);
825 if ($result < 0) {
826 $error++;
827 }
828 // End call triggers
829 }
830 }
831
832 if (!$error) {
833 $this->oldref = $this->ref;
834
835 // Rename directory if dir was a temporary ref
836 if (preg_match('/^[\‍(]?PROV/i', $this->ref)) {
837 // Now we rename also files into index
838 $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) . "'";
839 $sql .= " WHERE filename LIKE '" . $this->db->escape($this->ref) . "%' AND filepath = 'holiday/" . $this->db->escape($this->ref) . "' and entity = " . ((int) $conf->entity);
840 $resql = $this->db->query($sql);
841 if (!$resql) {
842 $error++;
843 $this->error = $this->db->lasterror();
844 }
845 $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filepath = 'holiday/".$this->db->escape($this->newref)."'";
846 $sql .= " WHERE filepath = 'holiday/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
847 $resql = $this->db->query($sql);
848 if (!$resql) {
849 $error++;
850 $this->error = $this->db->lasterror();
851 }
852
853 // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
854 $oldref = dol_sanitizeFileName($this->ref);
855 $newref = dol_sanitizeFileName($num);
856 $dirsource = $conf->holiday->multidir_output[$this->entity] . '/' . $oldref;
857 $dirdest = $conf->holiday->multidir_output[$this->entity] . '/' . $newref;
858 if (!$error && file_exists($dirsource)) {
859 dol_syslog(get_class($this) . "::validate rename dir " . $dirsource . " into " . $dirdest);
860 if (@rename($dirsource, $dirdest)) {
861 dol_syslog("Rename ok");
862 // Rename docs starting with $oldref with $newref
863 $listoffiles = dol_dir_list($dirdest, 'files', 1, '^' . preg_quote($oldref, '/'));
864 foreach ($listoffiles as $fileentry) {
865 $dirsource = $fileentry['name'];
866 $dirdest = preg_replace('/^' . preg_quote($oldref, '/') . '/', $newref, $dirsource);
867 $dirsource = $fileentry['path'] . '/' . $dirsource;
868 $dirdest = $fileentry['path'] . '/' . $dirdest;
869 @rename($dirsource, $dirdest);
870 }
871 }
872 }
873 }
874 }
875
876
877 // Commit or rollback
878 if ($error) {
879 foreach ($this->errors as $errmsg) {
880 dol_syslog(get_class($this)."::validate ".$errmsg, LOG_ERR);
881 $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
882 }
883 $this->db->rollback();
884 return -1 * $error;
885 } else {
886 $this->db->commit();
887 return 1;
888 }
889 }
890
891
899 public function approve($user = null, $notrigger = 0)
900 {
901 $error = 0;
902
903 $checkBalance = getDictionaryValue('c_holiday_types', 'block_if_negative', $this->fk_type, true);
904
905 if ($checkBalance > 0) {
906 $balance = $this->getCPforUser($this->fk_user, $this->fk_type);
907 // Use the GMT variants: num_public_holiday(), called by num_open_day(), refuses a range whose
908 // length is not a whole number of days, and a range spanning a DST transition is 23h or 25h
909 // long in the server timezone. It then returns a string and the subtraction fatals.
910 $datedebutforcount = !empty($this->date_debut_gmt) ? $this->date_debut_gmt : $this->date_debut;
911 $datefinforcount = !empty($this->date_fin_gmt) ? $this->date_fin_gmt : $this->date_fin;
912 $daysAsked = num_open_day($datedebutforcount, $datefinforcount, 0, 1);
913
914 if (($balance - $daysAsked) < 0) {
915 $this->error = 'LeaveRequestCreationBlockedBecauseBalanceIsNegative';
916 return -1;
917 }
918 }
919
920 // Update request
921 $sql = "UPDATE ".MAIN_DB_PREFIX."holiday SET";
922 $sql .= " description= '".$this->db->escape($this->description)."',";
923 if (!empty($this->date_debut)) {
924 $sql .= " date_debut = '".$this->db->idate($this->date_debut)."',";
925 } else {
926 $error++;
927 }
928 if (!empty($this->date_fin)) {
929 $sql .= " date_fin = '".$this->db->idate($this->date_fin)."',";
930 } else {
931 $error++;
932 }
933 $sql .= " halfday = ".((int) $this->halfday).",";
934 if (!empty($this->status) && is_numeric($this->status)) {
935 $sql .= " statut = ".((int) $this->status).",";
936 } else {
937 $error++;
938 }
939 if (!empty($this->fk_validator)) {
940 $sql .= " fk_validator = ".((int) $this->fk_validator).",";
941 } else {
942 $error++;
943 }
944 if (!empty($this->date_valid)) {
945 $sql .= " date_valid = '".$this->db->idate($this->date_valid)."',";
946 } else {
947 $sql .= " date_valid = NULL,";
948 }
949 if (!empty($this->fk_user_valid)) {
950 $sql .= " fk_user_valid = ".((int) $this->fk_user_valid).",";
951 } else {
952 $sql .= " fk_user_valid = NULL,";
953 }
954 if (!empty($this->date_approval)) {
955 $sql .= " date_approval = '".$this->db->idate($this->date_approval)."',";
956 } else {
957 $sql .= " date_approval = NULL,";
958 }
959 if (!empty($this->fk_user_approve)) {
960 $sql .= " fk_user_approve = ".((int) $this->fk_user_approve).",";
961 } else {
962 $sql .= " fk_user_approve = NULL,";
963 }
964 if (!empty($this->date_refuse)) {
965 $sql .= " date_refuse = '".$this->db->idate($this->date_refuse)."',";
966 } else {
967 $sql .= " date_refuse = NULL,";
968 }
969 if (!empty($this->fk_user_refuse)) {
970 $sql .= " fk_user_refuse = ".((int) $this->fk_user_refuse).",";
971 } else {
972 $sql .= " fk_user_refuse = NULL,";
973 }
974 if (!empty($this->date_cancel)) {
975 $sql .= " date_cancel = '".$this->db->idate($this->date_cancel)."',";
976 } else {
977 $sql .= " date_cancel = NULL,";
978 }
979 if (!empty($this->fk_user_cancel)) {
980 $sql .= " fk_user_cancel = ".((int) $this->fk_user_cancel).",";
981 } else {
982 $sql .= " fk_user_cancel = NULL,";
983 }
984 if (!empty($this->detail_refuse)) {
985 $sql .= " detail_refuse = '".$this->db->escape($this->detail_refuse)."'";
986 } else {
987 $sql .= " detail_refuse = NULL";
988 }
989 $sql .= " WHERE rowid = ".((int) $this->id);
990
991 $this->db->begin();
992
993 dol_syslog(get_class($this)."::approve", LOG_DEBUG);
994 $resql = $this->db->query($sql);
995 if (!$resql) {
996 $error++;
997 $this->errors[] = "Error ".$this->db->lasterror();
998 }
999
1000 if (!$error) {
1001 if (!$notrigger) {
1002 // Call trigger
1003 $result = $this->call_trigger('HOLIDAY_APPROVE', $user);
1004 if ($result < 0) {
1005 $error++;
1006 }
1007 // End call triggers
1008 }
1009 }
1010
1011 // Commit or rollback
1012 if ($error) {
1013 foreach ($this->errors as $errmsg) {
1014 dol_syslog(get_class($this)."::approve ".$errmsg, LOG_ERR);
1015 $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
1016 }
1017 $this->db->rollback();
1018 return -1 * $error;
1019 } else {
1020 $this->db->commit();
1021 return 1;
1022 }
1023 }
1024
1032 public function update($user = null, $notrigger = 0)
1033 {
1034 global $conf, $langs;
1035 $error = 0;
1036
1037 $checkBalance = getDictionaryValue('c_holiday_types', 'block_if_negative', $this->fk_type, true);
1038
1039 if ($checkBalance > 0 && $this->statut != self::STATUS_DRAFT && $this->statut != self::STATUS_CANCELED) {
1040 $balance = $this->getCPforUser($this->fk_user, $this->fk_type);
1041 // Use the GMT variants: num_public_holiday(), called by num_open_day(), refuses a range whose
1042 // length is not a whole number of days, and a range spanning a DST transition is 23h or 25h
1043 // long in the server timezone. It then returns a string and the subtraction fatals.
1044 $datedebutforcount = !empty($this->date_debut_gmt) ? $this->date_debut_gmt : $this->date_debut;
1045 $datefinforcount = !empty($this->date_fin_gmt) ? $this->date_fin_gmt : $this->date_fin;
1046 $daysAsked = num_open_day($datedebutforcount, $datefinforcount, 0, 1);
1047
1048 if (($balance - $daysAsked) < 0) {
1049 $this->error = 'LeaveRequestCreationBlockedBecauseBalanceIsNegative';
1050 return -1;
1051 }
1052 }
1053
1054 // Update request
1055 $sql = "UPDATE ".MAIN_DB_PREFIX."holiday SET";
1056
1057 $sql .= " description= '".$this->db->escape($this->description)."',";
1058
1059 if (!empty($this->date_debut)) {
1060 $sql .= " date_debut = '".$this->db->idate($this->date_debut)."',";
1061 } else {
1062 $error++;
1063 }
1064 if (!empty($this->date_fin)) {
1065 $sql .= " date_fin = '".$this->db->idate($this->date_fin)."',";
1066 } else {
1067 $error++;
1068 }
1069 $sql .= " halfday = ".((int) $this->halfday).",";
1070 if (!empty($this->status) && is_numeric($this->status)) {
1071 $sql .= " statut = ".((int) $this->status).",";
1072 } else {
1073 $error++;
1074 }
1075 if (!empty($this->fk_validator)) {
1076 $sql .= " fk_validator = ".((int) $this->fk_validator).",";
1077 } else {
1078 $error++;
1079 }
1080 if (!empty($this->date_valid)) {
1081 $sql .= " date_valid = '".$this->db->idate($this->date_valid)."',";
1082 } else {
1083 $sql .= " date_valid = NULL,";
1084 }
1085 if (!empty($this->fk_user_valid)) {
1086 $sql .= " fk_user_valid = ".((int) $this->fk_user_valid).",";
1087 } else {
1088 $sql .= " fk_user_valid = NULL,";
1089 }
1090 if (!empty($this->date_approval)) {
1091 $sql .= " date_approval = '".$this->db->idate($this->date_approval)."',";
1092 } else {
1093 $sql .= " date_approval = NULL,";
1094 }
1095 if (!empty($this->fk_user_approve)) {
1096 $sql .= " fk_user_approve = ".((int) $this->fk_user_approve).",";
1097 } else {
1098 $sql .= " fk_user_approve = NULL,";
1099 }
1100 if (!empty($this->date_refuse)) {
1101 $sql .= " date_refuse = '".$this->db->idate($this->date_refuse)."',";
1102 } else {
1103 $sql .= " date_refuse = NULL,";
1104 }
1105 if (!empty($this->fk_user_refuse)) {
1106 $sql .= " fk_user_refuse = ".((int) $this->fk_user_refuse).",";
1107 } else {
1108 $sql .= " fk_user_refuse = NULL,";
1109 }
1110 if (!empty($this->date_cancel)) {
1111 $sql .= " date_cancel = '".$this->db->idate($this->date_cancel)."',";
1112 } else {
1113 $sql .= " date_cancel = NULL,";
1114 }
1115 if (!empty($this->fk_user_cancel)) {
1116 $sql .= " fk_user_cancel = ".((int) $this->fk_user_cancel).",";
1117 } else {
1118 $sql .= " fk_user_cancel = NULL,";
1119 }
1120 if (!empty($this->detail_refuse)) {
1121 $sql .= " detail_refuse = '".$this->db->escape($this->detail_refuse)."'";
1122 } else {
1123 $sql .= " detail_refuse = NULL";
1124 }
1125
1126 $sql .= " WHERE rowid = ".((int) $this->id);
1127
1128 $this->db->begin();
1129
1130 dol_syslog(get_class($this)."::update", LOG_DEBUG);
1131 $resql = $this->db->query($sql);
1132 if (!$resql) {
1133 $error++;
1134 $this->errors[] = "Error ".$this->db->lasterror();
1135 }
1136
1137 if (!$error) {
1138 $result = $this->insertExtraFields();
1139 if ($result < 0) {
1140 $error++;
1141 }
1142 }
1143
1144 if (!$error) {
1145 if (!$notrigger && $user !== null) {
1146 // Call trigger
1147 $result = $this->call_trigger('HOLIDAY_MODIFY', $user);
1148 if ($result < 0) {
1149 $error++;
1150 }
1151 // End call triggers
1152 }
1153 }
1154
1155 // Commit or rollback
1156 if ($error) {
1157 foreach ($this->errors as $errmsg) {
1158 dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
1159 $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
1160 }
1161 $this->db->rollback();
1162 return -1 * $error;
1163 } else {
1164 $this->db->commit();
1165 return 1;
1166 }
1167 }
1168
1169
1177 public function delete($user, $notrigger = 0)
1178 {
1179 global $conf, $langs;
1180 $error = 0;
1181
1182 $sql = "DELETE FROM ".MAIN_DB_PREFIX."holiday";
1183 $sql .= " WHERE rowid=".((int) $this->id);
1184
1185 $this->db->begin();
1186
1187 dol_syslog(get_class($this)."::delete", LOG_DEBUG);
1188 $resql = $this->db->query($sql);
1189 if (!$resql) {
1190 $error++;
1191 $this->errors[] = "Error ".$this->db->lasterror();
1192 }
1193
1194 if (!$error) {
1195 if (!$notrigger) {
1196 // Call trigger
1197 $result = $this->call_trigger('HOLIDAY_DELETE', $user);
1198 if ($result < 0) {
1199 $error++;
1200 }
1201 // End call triggers
1202 }
1203 }
1204
1205 // Commit or rollback
1206 if ($error) {
1207 foreach ($this->errors as $errmsg) {
1208 dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR);
1209 $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
1210 }
1211 $this->db->rollback();
1212 return -1 * $error;
1213 } else {
1214 $this->db->commit();
1215 return 1;
1216 }
1217 }
1218
1232 public function verifDateHolidayCP($fk_user, $dateStart, $dateEnd, $halfday = 0)
1233 {
1234 $this->fetchByUser($fk_user, '', '');
1235
1236 foreach ($this->holiday as $infos_CP) {
1237 if ($infos_CP['statut'] == Holiday::STATUS_CANCELED) {
1238 continue; // ignore not validated holidays
1239 }
1240 if ($infos_CP['statut'] == Holiday::STATUS_REFUSED) {
1241 continue; // ignore refused holidays
1242 }
1243 //var_dump("--");
1244 //var_dump("old: ".dol_print_date($infos_CP['date_debut'],'dayhour').' '.dol_print_date($infos_CP['date_fin'],'dayhour').' '.$infos_CP['halfday']);
1245 //var_dump("new: ".dol_print_date($dateStart,'dayhour').' '.dol_print_date($dateEnd,'dayhour').' '.$halfday);
1246
1247 if ($halfday == 0) {
1248 if ($dateStart >= $infos_CP['date_debut'] && $dateStart <= $infos_CP['date_fin']) {
1249 return false;
1250 }
1251 if ($dateEnd <= $infos_CP['date_fin'] && $dateEnd >= $infos_CP['date_debut']) {
1252 return false;
1253 }
1254 } elseif ($halfday == -1) {
1255 // new start afternoon, new end afternoon
1256 if ($dateStart >= $infos_CP['date_debut'] && $dateStart <= $infos_CP['date_fin']) {
1257 if ($dateStart < $infos_CP['date_fin'] || in_array($infos_CP['halfday'], array(0, -1))) {
1258 return false;
1259 }
1260 }
1261 if ($dateEnd <= $infos_CP['date_fin'] && $dateEnd >= $infos_CP['date_debut']) {
1262 if ($dateStart < $dateEnd) {
1263 return false;
1264 }
1265 if ($dateEnd < $infos_CP['date_fin'] || in_array($infos_CP['halfday'], array(0, -1))) {
1266 return false;
1267 }
1268 }
1269 } elseif ($halfday == 1) {
1270 // new start morning, new end morning
1271 if ($dateStart >= $infos_CP['date_debut'] && $dateStart <= $infos_CP['date_fin']) {
1272 if ($dateStart < $dateEnd) {
1273 return false;
1274 }
1275 if ($dateStart > $infos_CP['date_debut'] || in_array($infos_CP['halfday'], array(0, 1))) {
1276 return false;
1277 }
1278 }
1279 if ($dateEnd <= $infos_CP['date_fin'] && $dateEnd >= $infos_CP['date_debut']) {
1280 if ($dateEnd > $infos_CP['date_debut'] || in_array($infos_CP['halfday'], array(0, 1))) {
1281 return false;
1282 }
1283 }
1284 } elseif ($halfday == 2) {
1285 // new start afternoon, new end morning
1286 if ($dateStart >= $infos_CP['date_debut'] && $dateStart <= $infos_CP['date_fin']) {
1287 if ($dateStart < $infos_CP['date_fin'] || in_array($infos_CP['halfday'], array(0, -1))) {
1288 return false;
1289 }
1290 }
1291 if ($dateEnd <= $infos_CP['date_fin'] && $dateEnd >= $infos_CP['date_debut']) {
1292 if ($dateEnd > $infos_CP['date_debut'] || in_array($infos_CP['halfday'], array(0, 1))) {
1293 return false;
1294 }
1295 }
1296 } else {
1297 dol_print_error(null, 'Bad value of parameter halfday when calling function verifDateHolidayCP');
1298 }
1299 }
1300
1301 return true;
1302 }
1303
1304
1314 public function verifDateHolidayForTimestamp($fk_user, $timestamp, $status = '-1')
1315 {
1316 $isavailablemorning = true;
1317 $isavailableafternoon = true;
1318
1319 // Check into leave requests
1320 $sql = "SELECT cp.rowid, cp.date_debut as date_start, cp.date_fin as date_end, cp.halfday, cp.statut as status";
1321 $sql .= " FROM ".MAIN_DB_PREFIX."holiday as cp";
1322 $sql .= " WHERE cp.entity IN (".getEntity('holiday').")";
1323 $sql .= " AND cp.fk_user = ".(int) $fk_user;
1324 $sql .= " AND cp.date_debut <= '".$this->db->idate($timestamp)."' AND cp.date_fin >= '".$this->db->idate($timestamp)."'";
1325 if ($status != '-1') {
1326 $sql .= " AND cp.statut IN (".$this->db->sanitize($status).")";
1327 }
1328
1329 $resql = $this->db->query($sql);
1330 if ($resql) {
1331 $num_rows = $this->db->num_rows($resql); // Note, we can have 2 records if on is morning and the other one is afternoon
1332 if ($num_rows > 0) {
1333 $arrayofrecord = array();
1334 $i = 0;
1335 while ($i < $num_rows) {
1336 $obj = $this->db->fetch_object($resql);
1337
1338 // Note: $obj->halfday is 0:Full days, 2:Start afternoon end morning, -1:Start afternoon, 1:End morning
1339 $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);
1340 $i++;
1341 }
1342
1343 // We found a record, user is on holiday by default, so is not available is true.
1344 $isavailablemorning = true;
1345 foreach ($arrayofrecord as $record) {
1346 if ($timestamp == $record['date_start'] && $record['halfday'] == 2) {
1347 continue;
1348 }
1349 if ($timestamp == $record['date_start'] && $record['halfday'] == -1) {
1350 continue;
1351 }
1352 $isavailablemorning = false;
1353 break;
1354 }
1355 $isavailableafternoon = true;
1356 foreach ($arrayofrecord as $record) {
1357 if ($timestamp == $record['date_end'] && $record['halfday'] == 2) {
1358 continue;
1359 }
1360 if ($timestamp == $record['date_end'] && $record['halfday'] == 1) {
1361 continue;
1362 }
1363 $isavailableafternoon = false;
1364 break;
1365 }
1366 }
1367 } else {
1368 dol_print_error($this->db);
1369 }
1370
1371 $result = array('morning' => (int) $isavailablemorning, 'afternoon' => (int) $isavailableafternoon);
1372 if (!$isavailablemorning) {
1373 $result['morning_reason'] = 'leave_request';
1374 }
1375 if (!$isavailableafternoon) {
1376 $result['afternoon_reason'] = 'leave_request';
1377 }
1378 return $result;
1379 }
1380
1387 public function getTooltipContentArray($params)
1388 {
1389 global $langs;
1390
1391 $langs->load('holiday');
1392 $nofetch = !empty($params['nofetch']);
1393
1394 $datas = array();
1395 $datas['picto'] = img_picto('', $this->picto).' <u class="paddingrightonly">'.$langs->trans("Holiday").'</u>';
1396 if (isset($this->status)) {
1397 $datas['picto'] .= ' '.$this->getLibStatut(5);
1398 }
1399 $datas['ref'] = '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref;
1400 // show type for this record only in ajax to not overload lists
1401 if (!$nofetch && !empty($this->fk_type)) {
1402 $typeleaves = $this->getTypes(1, -1);
1403 if (empty($typeleaves[$this->fk_type])) {
1404 $labeltoshow = $langs->trans("TypeWasDisabledOrRemoved", $this->fk_type);
1405 } else {
1406 $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']);
1407 }
1408 $datas['type'] = '<br><b>'.$langs->trans("Type") . ':</b> ' . $labeltoshow;
1409 }
1410 if (isset($this->halfday) && !empty($this->date_debut) && !empty($this->date_fin)) {
1411 $listhalfday = array(
1412 'morning' => $langs->trans("Morning"),
1413 "afternoon" => $langs->trans("Afternoon")
1414 );
1415 $starthalfday = ($this->halfday == -1 || $this->halfday == 2) ? 'afternoon' : 'morning';
1416 $endhalfday = ($this->halfday == 1 || $this->halfday == 2) ? 'morning' : 'afternoon';
1417 $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>';
1418 $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>';
1419 }
1420
1421
1422 return $datas;
1423 }
1424
1434 public function getNomUrl($withpicto = 0, $save_lastsearch_value = -1, $notooltip = 0, $morecss = '')
1435 {
1436 global $conf, $langs, $hookmanager;
1437
1438 if (!empty($conf->dol_no_mouse_hover)) {
1439 $notooltip = 1; // Force disable tooltips
1440 }
1441
1442 $result = '';
1443 $params = [
1444 'id' => $this->id,
1445 'objecttype' => $this->element,
1446 'nofetch' => 1,
1447 ];
1448 $classfortooltip = 'classfortooltip';
1449 $dataparams = '';
1450 if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
1451 $classfortooltip = 'classforajaxtooltip';
1452 $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"';
1453 $label = '';
1454 } else {
1455 $label = implode($this->getTooltipContentArray($params));
1456 }
1457
1458 $url = DOL_URL_ROOT.'/holiday/card.php?id='.$this->id;
1459
1460 //if ($option != 'nolink')
1461 //{
1462 // Add param to save lastsearch_values or not
1463 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1464 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
1465 $add_save_lastsearch_values = 1;
1466 }
1467 if ($add_save_lastsearch_values) {
1468 $url .= '&save_lastsearch_values=1';
1469 }
1470 //}
1471
1472 $linkclose = '';
1473 if (empty($notooltip)) {
1474 if (getDolGlobalInt('MAIN_OPTIMIZEFORTEXTBROWSER')) {
1475 $label = $langs->trans("ShowMyObject");
1476 $linkclose .= ' alt="'.dolPrintHTMLForAttribute($label).'"';
1477 }
1478 $linkclose .= ($label ? ' title="'.dolPrintHTMLForAttribute($label).'"' : ' title="tocomplete"');
1479 $linkclose .= $dataparams.' class="'.$classfortooltip.($morecss ? ' '.$morecss : '').'"';
1480 } else {
1481 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
1482 }
1483
1484 $linkstart = '<a href="'.$url.'"';
1485 $linkstart .= $linkclose.'>';
1486 $linkend = '</a>';
1487
1488 $result .= $linkstart;
1489
1490 if ($withpicto) {
1491 $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'"'), 0, 0, $notooltip ? 0 : 1);
1492 }
1493 if ($withpicto != 2) {
1494 $result .= $this->ref;
1495 }
1496 $result .= $linkend;
1497
1498 global $action;
1499 $hookmanager->initHooks(array($this->element . 'dao'));
1500 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
1501 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
1502 if ($reshook > 0) {
1503 $result = $hookmanager->resPrint;
1504 } else {
1505 $result .= $hookmanager->resPrint;
1506 }
1507 return $result;
1508 }
1509
1510
1517 public function getLibStatut($mode = 0)
1518 {
1519 return $this->LibStatut($this->status, $mode, $this->date_debut);
1520 }
1521
1522 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1531 public function LibStatut($status, $mode = 0, $startdate = '')
1532 {
1533 // phpcs:enable
1534 global $langs;
1535
1536 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
1537 global $langs;
1538 //$langs->load("mymodule");
1539 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('DraftCP');
1540 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('ToReviewCP');
1541 $this->labelStatus[self::STATUS_APPROVED] = $langs->transnoentitiesnoconv('ApprovedCP');
1542 $this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('CancelCP');
1543 $this->labelStatus[self::STATUS_REFUSED] = $langs->transnoentitiesnoconv('RefuseCP');
1544 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('DraftCP');
1545 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('ToReviewCP');
1546 $this->labelStatusShort[self::STATUS_APPROVED] = $langs->transnoentitiesnoconv('ApprovedCP');
1547 $this->labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('CancelCP');
1548 $this->labelStatusShort[self::STATUS_REFUSED] = $langs->transnoentitiesnoconv('RefuseCP');
1549 }
1550
1551 $params = array();
1552 $statusType = 'status6';
1553 if (!empty($startdate) && $startdate >= dol_now()) { // If not yet passed, we use a green "in live" color
1554 $statusType = 'status4';
1555 $params = array('tooltip' => $this->labelStatus[$status].' - '.$langs->trans("Forthcoming"));
1556 }
1557 if ($status == self::STATUS_DRAFT) {
1558 $statusType = 'status0';
1559 }
1560 if ($status == self::STATUS_VALIDATED) {
1561 $statusType = 'status1';
1562 }
1563 if ($status == self::STATUS_CANCELED) {
1564 $statusType = 'status9';
1565 }
1566 if ($status == self::STATUS_REFUSED) {
1567 $statusType = 'status9';
1568 }
1569
1570 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode, '', $params);
1571 }
1572
1573
1582 public function selectStatutCP($selected = 0, $htmlname = 'select_statut', $morecss = 'minwidth125')
1583 {
1584 global $langs;
1585
1586 // List of status label
1587 $name = array('DraftCP', 'ToReviewCP', 'ApprovedCP', 'CancelCP', 'RefuseCP');
1588 $nb = count($name) + 1;
1589
1590 // Select HTML
1591 $out = '<select name="'.$htmlname.'" id="'.$htmlname.'" class="flat'.($morecss ? ' '.$morecss : '').'">'."\n";
1592 $out .= '<option value="-1">&nbsp;</option>'."\n";
1593
1594 // Loop on status
1595 for ($i = 1; $i < $nb; $i++) {
1596 if ($i == $selected) {
1597 $out .= '<option value="'.$i.'" selected>'.$langs->trans($name[$i - 1]).'</option>'."\n";
1598 } else {
1599 $out .= '<option value="'.$i.'">'.$langs->trans($name[$i - 1]).'</option>'."\n";
1600 }
1601 }
1602
1603 $out .= "</select>\n";
1604
1605 $showempty = 0;
1606 $out .= ajax_combobox($htmlname, array(), 0, 0, 'resolve', ($showempty < 0 ? (string) $showempty : '-1'), $morecss);
1607
1608 return $out;
1609 }
1610
1618 public function updateConfCP($name, $value)
1619 {
1620 $sql = "UPDATE ".MAIN_DB_PREFIX."holiday_config SET";
1621 $sql .= " value = '".$this->db->escape($value)."'";
1622 $sql .= " WHERE name = '".$this->db->escape($name)."'";
1623
1624 dol_syslog(get_class($this).'::updateConfCP name='.$name, LOG_DEBUG);
1625 $result = $this->db->query($sql);
1626 if ($result) {
1627 return true;
1628 }
1629
1630 return false;
1631 }
1632
1641 public function getConfCP($name, $createifnotfound = '')
1642 {
1643 $sql = "SELECT value";
1644 $sql .= " FROM ".MAIN_DB_PREFIX."holiday_config";
1645 $sql .= " WHERE name = '".$this->db->escape($name)."'";
1646
1647 dol_syslog(get_class($this).'::getConfCP name='.$name.' createifnotfound='.$createifnotfound, LOG_DEBUG);
1648 $result = $this->db->query($sql);
1649
1650 if ($result) {
1651 $obj = $this->db->fetch_object($result);
1652 // Return value
1653 if (empty($obj)) {
1654 if ($createifnotfound) {
1655 $sql = "INSERT INTO ".MAIN_DB_PREFIX."holiday_config(name, value)";
1656 $sql .= " VALUES('".$this->db->escape($name)."', '".$this->db->escape($createifnotfound)."')";
1657 $result = $this->db->query($sql);
1658 if ($result) {
1659 return $createifnotfound;
1660 } else {
1661 $this->error = $this->db->lasterror();
1662 return -2;
1663 }
1664 } else {
1665 return '';
1666 }
1667 } else {
1668 return $obj->value;
1669 }
1670 } else {
1671 // Erreur SQL
1672 $this->error = $this->db->lasterror();
1673 return -1;
1674 }
1675 }
1676
1685 public function updateSoldeCP($userID = 0, $nbHoliday = 0, $fk_type = 0)
1686 {
1687 global $user, $langs;
1688
1689 $error = 0;
1690
1691 if (empty($userID) && empty($nbHoliday) && empty($fk_type)) {
1692 $langs->load("holiday");
1693
1694 $decrease = getDolGlobalInt('HOLIDAY_DECREASE_AT_END_OF_MONTH');
1695
1696 // Si mise à jour pour tout le monde en début de mois
1697 $now = dol_now();
1698
1699 // Get month of last update
1700 $stringInDBForLastUpdate = $this->getConfCP('lastUpdate', dol_print_date($now, '%Y%m%d%H%M%S')); // Example '20200101120000'
1701 // The lastUpdate config row is created empty (value NULL) at install, so getConfCP() returns an empty value
1702 // the first time. Treat an empty value as "start from now" (like define_holiday.php does) instead of a very
1703 // old date, otherwise the catch-up loop below would credit every user with years of monthly accrual at once.
1704 if (empty($stringInDBForLastUpdate)) {
1705 $stringInDBForLastUpdate = dol_print_date($now, '%Y%m%d%H%M%S');
1706 }
1707 // Protection when $lastUpdate has a not valid value
1708 if ($stringInDBForLastUpdate < '20000101000000') {
1709 $stringInDBForLastUpdate = '20000101000000';
1710 }
1711 $lastUpdate = dol_stringtotime($stringInDBForLastUpdate);
1712 //print 'lastUpdate:'.$lastUpdate;exit;
1713
1714 $yearMonthLastUpdate = dol_print_date($lastUpdate, '%Y%m');
1715 $yearMonthNow = dol_print_date($now, '%Y%m');
1716 //print 'yearMonthLastUpdate='.$yearMonthLastUpdate.' yearMonthNow='.$yearMonthNow;
1717
1718 // 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,
1719 // catching up to the current month if a gap is detected
1720 while ($yearMonthLastUpdate < $yearMonthNow) {
1721 $this->db->begin();
1722
1723 $year = dol_print_date($lastUpdate, '%Y');
1724 $month = dol_print_date($lastUpdate, '%m');
1725
1726 $users = $this->fetchUsers(false, false, ' AND u.statut > 0');
1727 $nbUser = count($users);
1728
1729 $typeleaves = $this->getTypes(1, 1);
1730
1731 // Update each user counter
1732 foreach ($users as $userCounter) {
1733 $nbDaysToAdd = (isset($typeleaves[$userCounter['type']]['newbymonth']) ? $typeleaves[$userCounter['type']]['newbymonth'] : 0);
1734 if (empty($nbDaysToAdd)) {
1735 continue;
1736 }
1737
1738 dol_syslog("We update leave type id ".$userCounter['type']." for user id ".$userCounter['rowid'], LOG_DEBUG);
1739
1740 $nowHoliday = (float) $userCounter['nb_holiday'];
1741 $newSolde = $nowHoliday + $nbDaysToAdd;
1742
1743 // We add a log for each user when its balance gets increased
1744 $this->addLogCP($user->id, $userCounter['rowid'], $langs->trans('HolidayMonthlyCredit'), $newSolde, $userCounter['type']);
1745
1746 $result = $this->updateSoldeCP($userCounter['rowid'], $newSolde, $userCounter['type']);
1747
1748 if ($result < 0) {
1749 $this->db->rollback();
1750 return -1;
1751 }
1752
1753 if (empty($decrease)) {
1754 continue;
1755 }
1756
1757 // 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
1758 $filter = " AND cp.statut = ".((int) self::STATUS_APPROVED);
1759 $filter .= " AND cp.date_fin >= '".$this->db->idate(dol_stringtotime(dol_print_date($lastUpdate, '%Y-%m-01')))."'";
1760 $filter .= " AND cp.date_debut <= '".$this->db->idate(dol_stringtotime(dol_print_date($lastUpdate, '%Y-%m-t')))."'";
1761 $filter .= " AND cp.fk_type = ".((int) $userCounter['type']);
1762 $this->fetchByUser($userCounter['id'], '', $filter);
1763
1764 if (empty($this->holiday)) {
1765 continue;
1766 }
1767
1768 $startOfMonth = dol_mktime(0, 0, 0, (int) $month, 1, (int) $year, 1);
1769 $endOfMonth = dol_mktime(0, 0, 0, (int) $month, (int) dol_print_date($lastUpdate, 't'), (int) $year, 1);
1770
1771 foreach ($this->holiday as $obj) {
1772 $startDate = $obj['date_debut_gmt'];
1773 $endDate = $obj['date_fin_gmt'];
1774
1775 if ($startDate <= $endOfMonth && $startDate < $startOfMonth) {
1776 $startDate = $startOfMonth;
1777 }
1778
1779 if ($startOfMonth <= $endDate && $endDate > $endOfMonth) {
1780 $endDate = $endOfMonth;
1781 }
1782
1783 $nbDaysToDeduct = (int) num_open_day($startDate, $endDate, 0, 1, $obj['halfday']);
1784
1785 if ($nbDaysToDeduct <= 0) {
1786 continue;
1787 }
1788
1789 $newSolde -= $nbDaysToDeduct;
1790
1791 // We add a log for each user when its balance gets decreased
1792 $this->addLogCP($user->id, $userCounter['rowid'], $obj['ref'].' - '.$langs->trans('HolidayConsumption'), $newSolde, $userCounter['type']);
1793
1794 $result = $this->updateSoldeCP($userCounter['rowid'], $newSolde, $userCounter['type']);
1795
1796 if ($result < 0) {
1797 $this->db->rollback();
1798 return -1;
1799 }
1800 }
1801 }
1802
1803 //updating the date of the last monthly balance update
1804 $newMonth = dol_get_next_month((int) dol_print_date($lastUpdate, '%m'), (int) dol_print_date($lastUpdate, '%Y'));
1805 $lastUpdate = dol_mktime(0, 0, 0, (int) $newMonth['month'], 1, (int) $newMonth['year']);
1806
1807 $sql = "UPDATE ".MAIN_DB_PREFIX."holiday_config SET";
1808 $sql .= " value = '".$this->db->escape(dol_print_date($lastUpdate, '%Y%m%d%H%M%S'))."'";
1809 $sql .= " WHERE name = 'lastUpdate'";
1810 $result = $this->db->query($sql);
1811
1812 if (!$result) {
1813 $this->db->rollback();
1814 return -1;
1815 }
1816
1817 $this->db->commit();
1818
1819 $yearMonthLastUpdate = dol_print_date($lastUpdate, '%Y%m');
1820 }
1821
1822 if (!$error) {
1823 return 1;
1824 } else {
1825 return 0;
1826 }
1827 } else {
1828 // Mise à jour pour un utilisateur
1829 $nbHoliday = price2num($nbHoliday, 5);
1830
1831 $sql = "SELECT nb_holiday FROM ".MAIN_DB_PREFIX."holiday_users";
1832 $sql .= " WHERE fk_user = ".(int) $userID." AND fk_type = ".(int) $fk_type;
1833 $resql = $this->db->query($sql);
1834 if ($resql) {
1835 $num = $this->db->num_rows($resql);
1836
1837 if ($num > 0) {
1838 // Update for user
1839 $sql = "UPDATE ".MAIN_DB_PREFIX."holiday_users SET";
1840 $sql .= " nb_holiday = ".((float) $nbHoliday);
1841 $sql .= " WHERE fk_user = ".(int) $userID." AND fk_type = ".(int) $fk_type;
1842 $result = $this->db->query($sql);
1843 if (!$result) {
1844 $error++;
1845 $this->errors[] = $this->db->lasterror();
1846 }
1847 } else {
1848 // Insert for user
1849 $sql = "INSERT INTO ".MAIN_DB_PREFIX."holiday_users(nb_holiday, fk_user, fk_type) VALUES (";
1850 $sql .= ((float) $nbHoliday);
1851 $sql .= ", ".(int) $userID.", ".(int) $fk_type.")";
1852 $result = $this->db->query($sql);
1853 if (!$result) {
1854 $error++;
1855 $this->errors[] = $this->db->lasterror();
1856 }
1857 }
1858 } else {
1859 $this->errors[] = $this->db->lasterror();
1860 $error++;
1861 }
1862
1863 if (!$error) {
1864 return 1;
1865 } else {
1866 return -1;
1867 }
1868 }
1869 }
1870
1878 public function createCPusers($single = false, $userid = 0)
1879 {
1880 // do we have to add balance for all users ?
1881 if (!$single) {
1882 dol_syslog(get_class($this).'::createCPusers');
1883 $arrayofusers = $this->fetchUsers(false, true);
1884
1885 foreach ($arrayofusers as $users) {
1886 $sql = "INSERT INTO ".MAIN_DB_PREFIX."holiday_users";
1887 $sql .= " (fk_user, nb_holiday)";
1888 $sql .= " VALUES (".((int) $users['rowid'])."', '0')";
1889
1890 $resql = $this->db->query($sql);
1891 if (!$resql) {
1892 dol_print_error($this->db);
1893 }
1894 }
1895 } else {
1896 $sql = "INSERT INTO ".MAIN_DB_PREFIX."holiday_users";
1897 $sql .= " (fk_user, nb_holiday)";
1898 $sql .= " VALUES (".((int) $userid)."', '0')";
1899
1900 $resql = $this->db->query($sql);
1901 if (!$resql) {
1902 dol_print_error($this->db);
1903 }
1904 }
1905 }
1906
1914 public function getCPforUser($user_id, $fk_type = 0)
1915 {
1916 $sql = "SELECT nb_holiday";
1917 $sql .= " FROM ".MAIN_DB_PREFIX."holiday_users";
1918 $sql .= " WHERE fk_user = ".(int) $user_id;
1919 if ($fk_type > 0) {
1920 $sql .= " AND fk_type = ".(int) $fk_type;
1921 }
1922
1923 dol_syslog(get_class($this).'::getCPforUser user_id='.$user_id.' type_id='.$fk_type, LOG_DEBUG);
1924 $result = $this->db->query($sql);
1925 if ($result) {
1926 $obj = $this->db->fetch_object($result);
1927 //return number_format($obj->nb_holiday,2);
1928 if ($obj) {
1929 return $obj->nb_holiday;
1930 } else {
1931 return null;
1932 }
1933 } else {
1934 return null;
1935 }
1936 }
1937
1946 public function fetchUsers($stringlist = true, $type = true, $filters = '')
1947 {
1948 global $conf;
1949
1950 dol_syslog(get_class($this)."::fetchUsers", LOG_DEBUG);
1951
1952 if ($stringlist) {
1953 if ($type) {
1954 // If user of Dolibarr
1955 $sql = "SELECT";
1956 if (isModEnabled('multicompany') && getDolGlobalString('MULTICOMPANY_TRANSVERSE_MODE')) {
1957 $sql .= " DISTINCT";
1958 }
1959 $sql .= " u.rowid";
1960 $sql .= " FROM ".MAIN_DB_PREFIX."user as u";
1961
1962 if (isModEnabled('multicompany') && getDolGlobalString('MULTICOMPANY_TRANSVERSE_MODE')) {
1963 $sql .= ", ".MAIN_DB_PREFIX."usergroup_user as ug";
1964 $sql .= " WHERE ((ug.fk_user = u.rowid";
1965 $sql .= " AND ug.entity IN (".getEntity('usergroup')."))";
1966 $sql .= " OR u.entity = 0)"; // Show always superadmin
1967 } else {
1968 $sql .= " WHERE u.entity IN (".getEntity('user').")";
1969 }
1970 $sql .= " AND u.statut > 0";
1971 $sql .= " AND u.employee = 1"; // We only want employee users for holidays
1972 if ($filters) {
1973 $sql .= $filters;
1974 }
1975
1976 $resql = $this->db->query($sql);
1977
1978 // Si pas d'erreur SQL
1979 if ($resql) {
1980 $i = 0;
1981 $num = $this->db->num_rows($resql);
1982 $stringlist = '';
1983
1984 // Boucles du listage des utilisateurs
1985 while ($i < $num) {
1986 $obj = $this->db->fetch_object($resql);
1987
1988 if ($i == 0) {
1989 $stringlist .= $obj->rowid;
1990 } else {
1991 $stringlist .= ', '.$obj->rowid;
1992 }
1993
1994 $i++;
1995 }
1996 // Retoune le tableau des utilisateurs
1997 return $stringlist;
1998 } else {
1999 // Erreur SQL
2000 $this->error = "Error ".$this->db->lasterror();
2001 return -1;
2002 }
2003 } else {
2004 // We want only list of vacation balance for user ids
2005 $sql = "SELECT DISTINCT cpu.fk_user";
2006 $sql .= " FROM ".MAIN_DB_PREFIX."holiday_users as cpu, ".MAIN_DB_PREFIX."user as u";
2007 $sql .= " WHERE cpu.fk_user = u.rowid";
2008 if ($filters) {
2009 $sql .= $filters;
2010 }
2011
2012 $resql = $this->db->query($sql);
2013
2014 // Si pas d'erreur SQL
2015 if ($resql) {
2016 $i = 0;
2017 $num = $this->db->num_rows($resql);
2018 $stringlist = '';
2019
2020 // Boucles du listage des utilisateurs
2021 while ($i < $num) {
2022 $obj = $this->db->fetch_object($resql);
2023
2024 if ($i == 0) {
2025 $stringlist .= $obj->fk_user;
2026 } else {
2027 $stringlist .= ', '.$obj->fk_user;
2028 }
2029
2030 $i++;
2031 }
2032 // Retoune le tableau des utilisateurs
2033 return $stringlist;
2034 } else {
2035 // Erreur SQL
2036 $this->error = "Error ".$this->db->lasterror();
2037 return -1;
2038 }
2039 }
2040 } else {
2041 // Si faux donc return array
2042 // List for Dolibarr users
2043 if ($type) {
2044 // If we need users of Dolibarr
2045 $sql = "SELECT";
2046 if (isModEnabled('multicompany') && getDolGlobalString('MULTICOMPANY_TRANSVERSE_MODE')) {
2047 $sql .= " DISTINCT";
2048 }
2049 $sql .= " u.rowid, u.lastname, u.firstname, u.gender, u.photo, u.employee, u.statut as status, u.fk_user";
2050 $sql .= " FROM ".MAIN_DB_PREFIX."user as u";
2051
2052 if (isModEnabled('multicompany') && getDolGlobalString('MULTICOMPANY_TRANSVERSE_MODE')) {
2053 $sql .= ", ".MAIN_DB_PREFIX."usergroup_user as ug";
2054 $sql .= " WHERE ((ug.fk_user = u.rowid";
2055 $sql .= " AND ug.entity IN (".getEntity('usergroup')."))";
2056 $sql .= " OR u.entity = 0)"; // Show always superadmin
2057 } else {
2058 $sql .= " WHERE u.entity IN (".getEntity('user').")";
2059 }
2060
2061 $sql .= " AND u.statut > 0";
2062 $sql .= " AND u.employee = 1"; // We only want employee users for holidays
2063 if ($filters) {
2064 $sql .= $filters;
2065 }
2066
2067 $resql = $this->db->query($sql);
2068
2069 // Si pas d'erreur SQL
2070 if ($resql) {
2071 $i = 0;
2072 $tab_result = $this->holiday;
2073 $num = $this->db->num_rows($resql);
2074
2075 // Boucles du listage des utilisateurs
2076 while ($i < $num) {
2077 $obj = $this->db->fetch_object($resql);
2078
2079 $tab_result[$i]['rowid'] = (int) $obj->rowid; // rowid of user
2080 $tab_result[$i]['id'] = (int) $obj->rowid; // id of user
2081 $tab_result[$i]['name'] = $obj->lastname; // deprecated
2082 $tab_result[$i]['lastname'] = $obj->lastname;
2083 $tab_result[$i]['firstname'] = $obj->firstname;
2084 $tab_result[$i]['gender'] = $obj->gender;
2085 $tab_result[$i]['status'] = (int) $obj->status;
2086 $tab_result[$i]['employee'] = (int) $obj->employee;
2087 $tab_result[$i]['photo'] = $obj->photo;
2088 $tab_result[$i]['fk_user'] = (int) $obj->fk_user; // rowid of manager
2089 //$tab_result[$i]['type'] = $obj->type;
2090 //$tab_result[$i]['nb_holiday'] = $obj->nb_holiday;
2091
2092 $i++;
2093 }
2094 // Retoune le tableau des utilisateurs
2095 return $tab_result;
2096 } else {
2097 // Erreur SQL
2098 $this->errors[] = "Error ".$this->db->lasterror();
2099 return -1;
2100 }
2101 } else {
2102 // List of vacation balance users
2103 $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";
2104 $sql .= " FROM ".MAIN_DB_PREFIX."holiday_users as cpu, ".MAIN_DB_PREFIX."user as u";
2105 $sql .= " WHERE cpu.fk_user = u.rowid";
2106 if ($filters) {
2107 $sql .= $filters;
2108 }
2109
2110 $resql = $this->db->query($sql);
2111
2112 // Si pas d'erreur SQL
2113 if ($resql) {
2114 $i = 0;
2115 $tab_result = $this->holiday;
2116 $num = $this->db->num_rows($resql);
2117
2118 // Boucles du listage des utilisateurs
2119 while ($i < $num) {
2120 $obj = $this->db->fetch_object($resql);
2121
2122 $tab_result[$i]['rowid'] = $obj->rowid; // rowid of user
2123 $tab_result[$i]['id'] = $obj->rowid; // id of user
2124 $tab_result[$i]['name'] = $obj->lastname; // deprecated
2125 $tab_result[$i]['lastname'] = $obj->lastname;
2126 $tab_result[$i]['firstname'] = $obj->firstname;
2127 $tab_result[$i]['gender'] = $obj->gender;
2128 $tab_result[$i]['status'] = $obj->status;
2129 $tab_result[$i]['employee'] = $obj->employee;
2130 $tab_result[$i]['photo'] = $obj->photo;
2131 $tab_result[$i]['fk_user'] = $obj->fk_user; // rowid of manager
2132
2133 $tab_result[$i]['type'] = $obj->fk_type;
2134 $tab_result[$i]['nb_holiday'] = $obj->nb_holiday;
2135
2136 $i++;
2137 }
2138 // Retoune le tableau des utilisateurs
2139 return $tab_result;
2140 } else {
2141 // Erreur SQL
2142 $this->error = "Error ".$this->db->lasterror();
2143 return -1;
2144 }
2145 }
2146 }
2147 }
2148
2149
2150 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2158 {
2159 // phpcs:enable
2160 $users_validator = array();
2161
2162 $sql = "SELECT DISTINCT ur.fk_user";
2163 $sql .= " FROM ".MAIN_DB_PREFIX."user_rights as ur, ".MAIN_DB_PREFIX."rights_def as rd";
2164 $sql .= " WHERE ur.fk_id = rd.id and rd.module = 'holiday' AND rd.perms = 'approve'"; // Permission 'Approve';
2165 $sql .= "UNION";
2166 $sql .= " SELECT DISTINCT ugu.fk_user";
2167 $sql .= " FROM ".MAIN_DB_PREFIX."usergroup_user as ugu, ".MAIN_DB_PREFIX."usergroup_rights as ur, ".MAIN_DB_PREFIX."rights_def as rd";
2168 $sql .= " WHERE ugu.fk_usergroup = ur.fk_usergroup AND ur.fk_id = rd.id and rd.module = 'holiday' AND rd.perms = 'approve'"; // Permission 'Approve';
2169 //print $sql;
2170
2171 dol_syslog(get_class($this)."::fetch_users_approver_holiday sql=".$sql);
2172 $result = $this->db->query($sql);
2173 if ($result) {
2174 $num_rows = $this->db->num_rows($result);
2175 $i = 0;
2176 while ($i < $num_rows) {
2177 $objp = $this->db->fetch_object($result);
2178 array_push($users_validator, $objp->fk_user);
2179 $i++;
2180 }
2181 return $users_validator;
2182 } else {
2183 $this->error = $this->db->lasterror();
2184 dol_syslog(get_class($this)."::fetch_users_approver_holiday Error ".$this->error, LOG_ERR);
2185 return -1;
2186 }
2187 }
2188
2189
2195 public function countActiveUsers()
2196 {
2197 $sql = "SELECT count(u.rowid) as compteur";
2198 $sql .= " FROM ".MAIN_DB_PREFIX."user as u";
2199 $sql .= " WHERE u.statut > 0";
2200
2201 $result = $this->db->query($sql);
2202 $object = $this->db->fetch_object($result);
2203
2204 return $object->compteur;
2205 }
2212 {
2213 $sql = "SELECT count(u.rowid) as compteur";
2214 $sql .= " FROM ".MAIN_DB_PREFIX."user as u LEFT JOIN ".MAIN_DB_PREFIX."holiday_users hu ON (hu.fk_user=u.rowid)";
2215 $sql .= " WHERE u.statut > 0 AND hu.fk_user IS NULL";
2216
2217 $result = $this->db->query($sql);
2218 $object = $this->db->fetch_object($result);
2219
2220 return $object->compteur;
2221 }
2222
2230 public function verifNbUsers($userDolibarrWithoutCP, $userCP)
2231 {
2232 if (empty($userCP)) {
2233 $userCP = 0;
2234 }
2235 dol_syslog(get_class($this).'::verifNbUsers userDolibarr='.$userDolibarrWithoutCP.' userCP='.$userCP);
2236 return 1;
2237 }
2238
2239
2250 public function addLogCP($fk_user_action, $fk_user_update, $label, $new_solde, $fk_type)
2251 {
2252 global $conf, $langs;
2253
2254 $error = 0;
2255
2256 $prev_solde = price2num((float) $this->getCPforUser($fk_user_update, $fk_type), 5);
2257 $new_solde = price2num($new_solde, 5);
2258 //print "$prev_solde == $new_solde";
2259
2260 if ($prev_solde == $new_solde) {
2261 return 0;
2262 }
2263
2264 $this->db->begin();
2265
2266 // Insert request
2267 $sql = "INSERT INTO ".MAIN_DB_PREFIX."holiday_logs (";
2268 $sql .= "date_action,";
2269 $sql .= "fk_user_action,";
2270 $sql .= "fk_user_update,";
2271 $sql .= "type_action,";
2272 $sql .= "prev_solde,";
2273 $sql .= "new_solde,";
2274 $sql .= "fk_type";
2275 $sql .= ") VALUES (";
2276 $sql .= " '".$this->db->idate(dol_now())."',";
2277 $sql .= " ".((int) $fk_user_action).",";
2278 $sql .= " ".((int) $fk_user_update).",";
2279 $sql .= " '".$this->db->escape($label)."',";
2280 $sql .= " ".((float) $prev_solde).",";
2281 $sql .= " ".((float) $new_solde).",";
2282 $sql .= " ".((int) $fk_type);
2283 $sql .= ")";
2284
2285 $resql = $this->db->query($sql);
2286 if (!$resql) {
2287 $error++;
2288 $this->errors[] = "Error ".$this->db->lasterror();
2289 }
2290
2291 if (!$error) {
2292 $this->optRowid = $this->db->last_insert_id(MAIN_DB_PREFIX."holiday_logs");
2293 }
2294
2295 // Commit or rollback
2296 if ($error) {
2297 foreach ($this->errors as $errmsg) {
2298 dol_syslog(get_class($this)."::addLogCP ".$errmsg, LOG_ERR);
2299 $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
2300 }
2301 $this->db->rollback();
2302 return -1 * $error;
2303 } else {
2304 $this->db->commit();
2305 return $this->optRowid;
2306 }
2307 }
2308
2316 public function fetchLog($sqlorder, $sqlwhere)
2317 {
2318 $sql = "SELECT";
2319 $sql .= " cpl.rowid,";
2320 $sql .= " cpl.date_action,";
2321 $sql .= " cpl.fk_user_action,";
2322 $sql .= " cpl.fk_user_update,";
2323 $sql .= " cpl.type_action,";
2324 $sql .= " cpl.prev_solde,";
2325 $sql .= " cpl.new_solde,";
2326 $sql .= " cpl.fk_type";
2327 $sql .= " FROM ".MAIN_DB_PREFIX."holiday_logs as cpl";
2328 $sql .= " WHERE cpl.rowid > 0"; // To avoid error with other search and criteria
2329
2330 // Filter
2331 if (!empty($sqlwhere)) {
2332 $sql .= " ".$sqlwhere;
2333 }
2334
2335 // Order
2336 if (!empty($sqlorder)) {
2337 $sql .= " ".$sqlorder;
2338 }
2339
2340 dol_syslog(get_class($this)."::fetchLog", LOG_DEBUG);
2341 $resql = $this->db->query($sql);
2342
2343 // If no error SQL
2344 if ($resql) {
2345 $i = 0;
2346 $tab_result = $this->logs;
2347 $num = $this->db->num_rows($resql);
2348
2349 // If no record
2350 if (!$num) {
2351 return 2;
2352 }
2353
2354 // Loop on result to fill the array
2355 while ($i < $num) {
2356 $obj = $this->db->fetch_object($resql);
2357
2358 $tab_result[$i]['rowid'] = $obj->rowid;
2359 $tab_result[$i]['id'] = $obj->rowid;
2360 $tab_result[$i]['date_action'] = $obj->date_action;
2361 $tab_result[$i]['fk_user_action'] = $obj->fk_user_action;
2362 $tab_result[$i]['fk_user_update'] = $obj->fk_user_update;
2363 $tab_result[$i]['type_action'] = $obj->type_action;
2364 $tab_result[$i]['prev_solde'] = $obj->prev_solde;
2365 $tab_result[$i]['new_solde'] = $obj->new_solde;
2366 $tab_result[$i]['fk_type'] = $obj->fk_type;
2367
2368 $i++;
2369 }
2370 // Retourne 1 et ajoute le tableau à la variable
2371 $this->logs = $tab_result;
2372 return 1;
2373 } else {
2374 // Erreur SQL
2375 $this->error = "Error ".$this->db->lasterror();
2376 return -1;
2377 }
2378 }
2379
2380
2388 public function getTypes($active = -1, $affect = -1)
2389 {
2390 global $mysoc;
2391
2392 $sql = "SELECT rowid, code, label, affect, delay, newbymonth";
2393 $sql .= " FROM ".MAIN_DB_PREFIX."c_holiday_types";
2394 $sql .= " WHERE (fk_country IS NULL OR fk_country = ".((int) $mysoc->country_id).')';
2395 $sql .= " AND entity IN (0, ".getEntity('c_holiday_types').")"; // Need entity 0 (holiday types common to all countries= + current entity).
2396 if ($active >= 0) {
2397 $sql .= " AND active = ".((int) $active);
2398 }
2399 if ($affect >= 0) {
2400 $sql .= " AND affect = ".((int) $affect);
2401 }
2402 $sql .= " ORDER BY sortorder";
2403
2404 $result = $this->db->query($sql);
2405 if ($result) {
2406 $num = $this->db->num_rows($result);
2407 if ($num) {
2408 $types = array();
2409 while ($obj = $this->db->fetch_object($result)) {
2410 $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);
2411 }
2412
2413 return $types;
2414 }
2415 } else {
2416 dol_print_error($this->db);
2417 }
2418
2419 return array();
2420 }
2421
2422
2429 public function info($id)
2430 {
2431 global $conf;
2432
2433 $sql = "SELECT f.rowid, f.statut as status,";
2434 $sql .= " f.date_create as datec,";
2435 $sql .= " f.tms as date_modification,";
2436 $sql .= " f.date_valid as datev,";
2437 $sql .= " f.date_approval as datea,";
2438 $sql .= " f.date_refuse as dater,";
2439 $sql .= " f.fk_user_create as fk_user_creation,";
2440 $sql .= " f.fk_user_modif as fk_user_modification,";
2441 $sql .= " f.fk_user_valid as fk_user_validation,";
2442 $sql .= " f.fk_user_approve as fk_user_approval_done,";
2443 $sql .= " f.fk_validator as fk_user_approval_expected,";
2444 $sql .= " f.fk_user_refuse as fk_user_refuse";
2445 $sql .= " FROM ".MAIN_DB_PREFIX."holiday as f";
2446 $sql .= " WHERE f.rowid = ".((int) $id);
2447 $sql .= " AND f.entity = ".$conf->entity;
2448
2449 $resql = $this->db->query($sql);
2450 if ($resql) {
2451 if ($this->db->num_rows($resql)) {
2452 $obj = $this->db->fetch_object($resql);
2453
2454 $this->id = $obj->rowid;
2455
2456 $this->date_creation = $this->db->jdate($obj->datec);
2457 $this->date_modification = $this->db->jdate($obj->date_modification);
2458 $this->date_validation = $this->db->jdate($obj->datev);
2459 $this->date_approval = $this->db->jdate($obj->datea);
2460
2461 $this->user_creation_id = $obj->fk_user_creation;
2462 $this->user_validation_id = $obj->fk_user_validation;
2463 $this->user_modification_id = $obj->fk_user_modification;
2464
2465 if ($obj->status == Holiday::STATUS_APPROVED || $obj->status == Holiday::STATUS_CANCELED) {
2466 if ($obj->fk_user_approval_done) {
2467 $this->fk_user_approve = $obj->fk_user_approval_done;
2468 }
2469 }
2470 }
2471 $this->db->free($resql);
2472 } else {
2473 dol_print_error($this->db);
2474 }
2475 }
2476
2477
2485 public function initAsSpecimen()
2486 {
2487 global $user, $langs;
2488
2489 // Initialise parameters
2490 $this->id = 0;
2491 $this->specimen = 1;
2492
2493 $this->fk_user = $user->id;
2494 $this->description = 'SPECIMEN description';
2495 $this->date_debut = dol_now();
2496 $this->date_fin = dol_now() + (24 * 3600);
2497 $this->date_valid = dol_now();
2498 $this->fk_validator = $user->id;
2499 $this->halfday = 0;
2500 $this->fk_type = 1;
2502
2503 return 1;
2504 }
2505
2511 public function loadStateBoard()
2512 {
2513 global $user;
2514
2515 $this->nb = array();
2516
2517 $sql = "SELECT count(h.rowid) as nb";
2518 $sql .= " FROM ".MAIN_DB_PREFIX."holiday as h";
2519 $sql .= " WHERE h.statut > 1";
2520 $sql .= " AND h.entity IN (".getEntity('holiday').")";
2521 if (!$user->hasRight('holiday', 'readall')) {
2522 $userchildids = $user->getAllChildIds(1);
2523 $sql .= " AND (h.fk_user IN (".$this->db->sanitize(implode(',', $userchildids)).")";
2524 $sql .= " OR h.fk_validator IN (".$this->db->sanitize(implode(',', $userchildids))."))";
2525 }
2526
2527 $resql = $this->db->query($sql);
2528 if ($resql) {
2529 while ($obj = $this->db->fetch_object($resql)) {
2530 $this->nb["holidays"] = $obj->nb;
2531 }
2532 $this->db->free($resql);
2533 return 1;
2534 } else {
2535 dol_print_error($this->db);
2536 $this->error = $this->db->error();
2537 return -1;
2538 }
2539 }
2540
2541 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2548 public function load_board($user)
2549 {
2550 // phpcs:enable
2551 global $conf, $langs;
2552
2553 if ($user->socid) {
2554 return -1; // protection pour eviter appel par utilisateur externe
2555 }
2556
2557 $now = dol_now();
2558
2559 $sql = "SELECT h.rowid, h.date_debut";
2560 $sql .= " FROM ".MAIN_DB_PREFIX."holiday as h";
2561 $sql .= " WHERE h.statut = 2";
2562 $sql .= " AND h.entity IN (".getEntity('holiday').")";
2563 if (!$user->hasRight('holiday', 'read_all')) {
2564 $userchildids = $user->getAllChildIds(1);
2565 $sql .= " AND (h.fk_user IN (".$this->db->sanitize(implode(',', $userchildids)).")";
2566 $sql .= " OR h.fk_validator IN (".$this->db->sanitize(implode(',', $userchildids))."))";
2567 }
2568
2569 $resql = $this->db->query($sql);
2570 if ($resql) {
2571 $langs->load("members");
2572
2573 $response = new WorkboardResponse();
2574 $response->warning_delay = $conf->holiday->approve->warning_delay / 60 / 60 / 24;
2575 $response->label = $langs->trans("HolidaysToApprove");
2576 $response->labelShort = $langs->trans("ToApprove");
2577 $response->url = DOL_URL_ROOT.'/holiday/list.php?search_status=2&amp;mainmenu=hrm&amp;leftmenu=holiday';
2578 $response->img = img_object('', "holiday");
2579
2580 while ($obj = $this->db->fetch_object($resql)) {
2581 $response->nbtodo++;
2582
2583 if ($this->db->jdate($obj->date_debut) < ($now - $conf->holiday->approve->warning_delay)) {
2584 $response->nbtodolate++;
2585 }
2586 }
2587
2588 return $response;
2589 } else {
2590 dol_print_error($this->db);
2591 $this->error = $this->db->error();
2592 return -1;
2593 }
2594 }
2602 public function getKanbanView($option = '', $arraydata = null)
2603 {
2604 global $langs;
2605
2606 $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
2607
2608 $return = '<div class="box-flex-item box-flex-grow-zero">';
2609 $return .= '<div class="info-box info-box-sm">';
2610 $return .= '<span class="info-box-icon bg-infobox-action">';
2611 $return .= img_picto('', $this->picto);
2612 $return .= '</span>';
2613 $return .= '<div class="info-box-content">';
2614 $return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.$this->getNomUrl().'</span>';
2615 if ($selected >= 0) {
2616 $return .= '<input id="cb'.$this->id.'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
2617 }
2618 if (property_exists($this, 'fk_type')) {
2619 $return .= '<br>';
2620 //$return .= '<span class="opacitymedium">'.$langs->trans("Type").'</span> : ';
2621 $return .= '<div class="info_box-label tdoverflowmax100" title="'.dol_escape_htmltag($arraydata['labeltype']).'">'.dol_escape_htmltag($arraydata['labeltype']).'</div>';
2622 }
2623 if (property_exists($this, 'date_debut') && property_exists($this, 'date_fin')) {
2624 $return .= '<span class="info-box-label small">'.dol_print_date($this->date_debut, 'day').'</span>';
2625 $return .= ' <span class="opacitymedium small">'.$langs->trans("To").'</span> ';
2626 $return .= '<span class="info-box-label small">'.dol_print_date($this->date_fin, 'day').'</span>';
2627 if (!empty($arraydata['nbopenedday'])) {
2628 $return .= ' ('.$arraydata['nbopenedday'].')';
2629 }
2630 }
2631 if (method_exists($this, 'getLibStatut')) {
2632 $return .= '<div class="info-box-status">'.$this->getLibStatut(3).'</div>';
2633 }
2634 $return .= '</div>';
2635 $return .= '</div>';
2636 $return .= '</div>';
2637 return $return;
2638 }
2639}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:67
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve', $idforemptyvalue='-1', $morecss='')
Convert a html select field into an ajax combobox.
Definition ajax.lib.php:475
$object ref
Definition info.php:90
Parent class of all other business classes (invoices, contracts, proposals, orders,...
fetch_optionals($rowid=null, $optionsArray=null)
Function to get extra fields of an object into $this->array_options This method is in most cases call...
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
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