dolibarr 25.0.0-alpha
box_holidays_to_approve.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2026 Dolibarr contributors
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17
23include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
24
29{
30 public $boxcode = "holidaystoapprove";
31 public $boximg = "object_holiday";
32 public $boxlabel = "BoxHolidaysToApprove";
33 public $depends = array("holiday");
34
41 public function __construct($db, $param) // @phpstan-ignore constructor.unusedParameter
42 {
43 global $user;
44
45 $this->db = $db;
46
47 $this->hidden = !($user->hasRight('holiday', 'read') && $user->hasRight('holiday', 'approve'));
48 }
49
56 public function loadBox($max = 5)
57 {
58 global $user, $langs;
59 $langs->loadLangs(array("boxes", "holiday"));
60
61 $this->max = $max;
62
63 include_once DOL_DOCUMENT_ROOT.'/holiday/class/holiday.class.php';
64 $holidaystatic = new Holiday($this->db);
65 include_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
66 $userstatic = new User($this->db);
67
68 $this->info_box_head = array('text' => $langs->trans("BoxTitleHolidaysToApprove", $max));
69
70 if ($user->hasRight('holiday', 'read') && $user->hasRight('holiday', 'approve')) {
71 $childids = $user->getAllChildIds(1);
72
73 $sql = "SELECT d.rowid, d.ref, d.date_debut, d.date_fin, d.halfday, d.statut as status";
74 $sql .= ", u.rowid as user_id, u.lastname, u.firstname, u.login, u.photo, u.statut as user_status, u.entity as user_entity";
75 $sql .= " FROM ".MAIN_DB_PREFIX."holiday as d";
76 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user as u ON d.fk_user = u.rowid";
77 $sql .= " WHERE d.statut = ".Holiday::STATUS_VALIDATED;
78 $sql .= " AND d.entity IN (".getEntity('holiday').")";
79 if (!$user->hasRight('holiday', 'readall')) {
80 $sql .= " AND (d.fk_user IN (".$this->db->sanitize(implode(',', $childids)).")";
81 $sql .= " OR d.fk_validator = ".((int) $user->id).")";
82 }
83 $sql .= " ORDER BY d.date_debut ASC";
84 $sql .= $this->db->plimit($max, 0);
85
86 $result = $this->db->query($sql);
87 if ($result) {
88 $num = $this->db->num_rows($result);
89
90 $line = 0;
91 while ($line < $num) {
92 $objp = $this->db->fetch_object($result);
93
94 $holidaystatic->id = $objp->rowid;
95 $holidaystatic->ref = $objp->ref;
96 $holidaystatic->statut = $objp->status;
97 $holidaystatic->status = $objp->status;
98
99 $userstatic->id = $objp->user_id;
100 $userstatic->lastname = $objp->lastname;
101 $userstatic->firstname = $objp->firstname;
102 $userstatic->login = $objp->login;
103 $userstatic->photo = $objp->photo;
104 $userstatic->statut = $objp->user_status;
105 $userstatic->status = $objp->user_status;
106 $userstatic->entity = $objp->user_entity;
107
108 $this->info_box_contents[$line][] = array(
109 'td' => 'class="nowraponall"',
110 'text' => $holidaystatic->getNomUrl(1),
111 'asis' => 1
112 );
113
114 $this->info_box_contents[$line][] = array(
115 'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone"',
116 'text' => $userstatic->getNomUrl(-1),
117 'asis' => 1,
118 );
119
120 $this->info_box_contents[$line][] = array(
121 'td' => 'class="nowraponall right"',
122 'text' => dol_print_date($this->db->jdate($objp->date_debut), 'day').' - '.dol_print_date($this->db->jdate($objp->date_fin), 'day'),
123 );
124
125 $line++;
126 }
127
128 if ($num == 0) {
129 $this->info_box_contents[$line][] = array(
130 'td' => 'class="center"',
131 'text' => '<span class="opacitymedium">'.$langs->trans("NoHolidayToApprove").'</span>',
132 );
133 }
134
135 $this->db->free($result);
136 } else {
137 $this->info_box_contents[0][] = array(
138 'td' => '',
139 'maxlength' => 500,
140 'text' => ($this->db->error().' sql='.$sql),
141 );
142 }
143 } else {
144 $this->info_box_contents[0][] = array(
145 'td' => 'class="nohover left"',
146 'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>'
147 );
148 }
149 }
150
159 public function showBox($head = null, $contents = null, $nooutput = 0)
160 {
161 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
162 }
163}
Class of the module paid holiday.
Class ModeleBoxes.
Class to manage Dolibarr users.
Class to manage the box to show leave requests waiting for approval.
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
__construct($db, $param)
Constructor.
loadBox($max=5)
Load data into info_box_contents array to show array later.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).