dolibarr 24.0.0-beta
document.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2003-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
5 * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
6 * Copyright (C) 2005 Simon TOSSER <simon@kornog-computing.com>
7 * Copyright (C) 2011-2012 Juanjo Menent <jmenent@2byte.es>
8 * Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
9 * Copyright (C) 2018-2026 Frédéric France <frederic.france@free.fr>
10 * Copyright (C) 2024 Alexandre Spangaro <alexandre@inovea-conseil.com>
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 3 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program. If not, see <https://www.gnu.org/licenses/>.
24 */
25
32// Load Dolibarr environment
33require '../main.inc.php';
42require_once DOL_DOCUMENT_ROOT.'/holiday/class/holiday.class.php';
43require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
44require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
45require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
46require_once DOL_DOCUMENT_ROOT.'/core/lib/holiday.lib.php';
47require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
48
49
50// Load translation files required by the page
51$langs->loadLangs(array('other', 'holiday', 'companies'));
52
53$id = GETPOSTINT('id');
54$ref = GETPOST('ref', 'alpha');
55$action = GETPOST('action', 'aZ09');
56$confirm = GETPOST('confirm', 'alpha');
57
58// Get parameters
59$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
60$sortfield = GETPOST('sortfield', 'aZ09comma');
61$sortorder = GETPOST('sortorder', 'aZ09comma');
62$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
63if (empty($page) || $page == -1) {
64 $page = 0;
65} // If $page is not defined, or '' or -1
66$offset = $limit * $page;
67$pageprev = $page - 1;
68$pagenext = $page + 1;
69if (!$sortorder) {
70 $sortorder = "ASC";
71}
72if (!$sortfield) {
73 $sortfield = "position_name";
74}
75
76
77$childids = $user->getAllChildIds(1);
78
79$morefilter = '';
80if (getDolGlobalString('HOLIDAY_HIDE_FOR_NON_SALARIES')) {
81 $morefilter = 'AND employee = 1';
82}
83
84$object = new Holiday($db);
85
86// fetch optionals attributes and labels
87$extrafields->fetch_name_optionals_label($object->table_element);
88
89$permissiontoapprove = $user->hasRight('holiday', 'approve');
90
91if (($id > 0) || $ref) {
92 $object->fetch($id, $ref);
93
94 // Check current user can read this leave request
95 $canread = 0;
96 if ($user->hasRight('holiday', 'readall')) {
97 $canread = 1;
98 }
99 if ($user->hasRight('holiday', 'read') && in_array($object->fk_user, $childids)) {
100 $canread = 1;
101 }
102 if ($permissiontoapprove && $object->fk_validator == $user->id && !getDolGlobalString('HOLIDAY_CAN_APPROVE_ONLY_THE_SUBORDINATES')) { // TODO HOLIDAY_CAN_APPROVE_ONLY_THE_SUBORDINATES not completely implemented
103 $canread = 1;
104 }
105 if (!$canread) {
107 }
108}
109
110
111$upload_dir = $conf->holiday->multidir_output[$object->entity ?? $conf->entity].'/'.get_exdir(0, 0, 0, 1, $object, '');
112$modulepart = 'holiday';
113
114// Protection if external user
115if ($user->socid) {
116 $socid = $user->socid;
117}
118$result = restrictedArea($user, 'holiday', $object->id, 'holiday');
119
120$permissiontoadd = $user->hasRight('holiday', 'write'); // Used by the include of actions_setnotes.inc.php
121
122
123/*
124 * Actions
125 */
126
127include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php';
128
129
130/*
131 * View
132 */
133
134$form = new Form($db);
135
136$listhalfday = array('morning'=>$langs->trans("Morning"), "afternoon"=>$langs->trans("Afternoon"));
137$title = $langs->trans("Leave").' - '.$langs->trans("Files");
138$help_url = 'EN:Module_Holiday';
139
140llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-holiday page-card_documents');
141
142if ($object->id) {
143 $valideur = new User($db);
144 $valideur->fetch($object->fk_validator);
145
146 $userRequest = new User($db);
147 $userRequest->fetch($object->fk_user);
148
149 $head = holiday_prepare_head($object);
150
151 print dol_get_fiche_head($head, 'documents', $langs->trans("CPTitreMenu"), -1, 'holiday');
152
153
154 // Build file list
155 $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ? SORT_DESC : SORT_ASC), 1);
156 $totalsize = 0;
157 foreach ($filearray as $key => $file) {
158 $totalsize += $file['size'];
159 }
160
161
162 $linkback = '<a href="'.DOL_URL_ROOT.'/holiday/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
163
164 dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref');
165
166
167 print '<div class="fichecenter">';
168 //print '<div class="fichehalfleft">';
169 print '<div class="underbanner clearboth"></div>';
170
171 print '<table class="border tableforfield centpercent">';
172
173 print '<tr>';
174 print '<td class="titlefield">'.$langs->trans("User").'</td>';
175 print '<td>';
176 print $userRequest->getNomUrl(-1, 'leave');
177 print '</td></tr>';
178
179 // Type
180 print '<tr>';
181 print '<td>'.$langs->trans("Type").'</td>';
182 print '<td>';
183 $typeleaves = $object->getTypes(1, -1);
184 if (empty($typeleaves[$object->fk_type])) {
185 $labeltoshow = $langs->trans("TypeWasDisabledOrRemoved", $object->fk_type);
186 } else {
187 $labeltoshow = (($typeleaves[$object->fk_type]['code'] && $langs->trans($typeleaves[$object->fk_type]['code']) != $typeleaves[$object->fk_type]['code']) ? $langs->trans($typeleaves[$object->fk_type]['code']) : $typeleaves[$object->fk_type]['label']);
188 }
189 print $labeltoshow;
190 print '</td>';
191 print '</tr>';
192
193 $starthalfday = ($object->halfday == -1 || $object->halfday == 2) ? 'afternoon' : 'morning';
194 $endhalfday = ($object->halfday == 1 || $object->halfday == 2) ? 'morning' : 'afternoon';
195
196 print '<tr>';
197 print '<td>';
198 print $form->textwithpicto($langs->trans('DateDebCP'), $langs->trans("FirstDayOfHoliday"));
199 print '</td>';
200 print '<td>'.dol_print_date($object->date_debut, 'day');
201 print ' &nbsp; &nbsp; ';
202 print '<span class="opacitymedium">'.$langs->trans($listhalfday[$starthalfday]).'</span>';
203 print '</td>';
204 print '</tr>';
205
206 print '<tr>';
207 print '<td>';
208 print $form->textwithpicto($langs->trans('DateFinCP'), $langs->trans("LastDayOfHoliday"));
209 print '</td>';
210 print '<td>'.dol_print_date($object->date_fin, 'day');
211 print ' &nbsp; &nbsp; ';
212 print '<span class="opacitymedium">'.$langs->trans($listhalfday[$endhalfday]).'</span>';
213 print '</td>';
214 print '</tr>';
215
216 // Nb days consumed
217 print '<tr>';
218 print '<td>';
219 $htmlhelp = $langs->trans('NbUseDaysCPHelp');
220 $includesaturday = getDolGlobalInt('MAIN_NON_WORKING_DAYS_INCLUDE_SATURDAY', 1);
221 $includesunday = getDolGlobalInt('MAIN_NON_WORKING_DAYS_INCLUDE_SUNDAY', 1);
222 if ($includesaturday) {
223 $htmlhelp .= '<br>'.$langs->trans("DayIsANonWorkingDay", $langs->trans("Saturday"));
224 }
225 if ($includesunday) {
226 $htmlhelp .= '<br>'.$langs->trans("DayIsANonWorkingDay", $langs->trans("Sunday"));
227 }
228 print $form->textwithpicto($langs->trans('NbUseDaysCP'), $htmlhelp);
229 print '</td>';
230 print '<td>'.num_open_day($object->date_debut_gmt, $object->date_fin_gmt, 0, 1, $object->halfday, $userRequest->country_id, $object->fk_user).'</td>';
231 print '</tr>';
232
233 if ($object->status == Holiday::STATUS_REFUSED) {
234 print '<tr>';
235 print '<td>'.$langs->trans('DetailRefusCP').'</td>';
236 print '<td>'.$object->detail_refuse.'</td>';
237 print '</tr>';
238 }
239
240 // Description
241 print '<tr>';
242 print '<td>'.$langs->trans('DescCP').'</td>';
243 print '<td>'.nl2br($object->description).'</td>';
244 print '</tr>';
245
246 print '<tr><td>'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.count($filearray).'</td></tr>';
247 print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.dol_print_size($totalsize, 1, 1).'</td></tr>';
248
249 print '</tbody>';
250 print '</table>'."\n";
251 /*
252 print '</div>';
253 print '<div class="fichehalfright">';
254
255 print '<div class="underbanner clearboth"></div>';
256
257 // Info workflow
258 print '<table class="border tableforfield centpercent">'."\n";
259 print '<tbody>';
260
261 if (!empty($object->fk_user_create)) {
262 $userCreate=new User($db);
263 $userCreate->fetch($object->fk_user_create);
264 print '<tr>';
265 print '<td class="titlefield">'.$langs->trans('RequestByCP').'</td>';
266 print '<td>'.$userCreate->getNomUrl(-1).'</td>';
267 print '</tr>';
268 }
269
270 print '<tr>';
271 print '<td class="titlefield">'.$langs->trans('ReviewedByCP').'</td>';
272 print '<td>'.$valideur->getNomUrl(-1).'</td>';
273 print '</tr>';
274
275 print '<tr>';
276 print '<td>'.$langs->trans('DateCreation').'</td>';
277 print '<td>'.dol_print_date($object->date_create,'dayhour').'</td>';
278 print '</tr>';
279 if ($object->status == 3) {
280 print '<tr>';
281 print '<td>'.$langs->trans('DateValidCP').'</td>';
282 print '<td>'.dol_print_date($object->date_valid,'dayhour').'</td>';
283 print '</tr>';
284 }
285 if ($object->status == 4) {
286 print '<tr>';
287 print '<td>'.$langs->trans('DateCancelCP').'</td>';
288 print '<td>'.dol_print_date($object->date_cancel,'dayhour').'</td>';
289 print '</tr>';
290 }
291 if ($object->status == 5) {
292 print '<tr>';
293 print '<td>'.$langs->trans('DateRefusCP').'</td>';
294 print '<td>'.dol_print_date($object->date_refuse,'dayhour').'</td>';
295 print '</tr>';
296 }
297 print '</tbody>';
298 print '</table>';
299
300 print '</div>'; */
301 print '</div>';
302
303 print '<div class="clearboth"></div>';
304
305 print dol_get_fiche_end();
306
307 $permissiontoadd = $user->hasRight('holiday', 'write');
308 $permtoedit = $user->hasRight('holiday', 'write');
309 $param = '&id='.$object->id;
310 $relativepathwithnofile = get_exdir(0, 0, 0, 1, $object, '').'/';
311 $savingdocmask = dol_sanitizeFileName($object->ref).'-__file__';
312
313 include DOL_DOCUMENT_ROOT.'/core/tpl/document_actions_post_headers.tpl.php';
314} else {
315 print $langs->trans("ErrorUnknown");
316}
317
318// End of page
319llxFooter();
320$db->close();
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
Class to manage generation of HTML components Only common components must be here.
Class of the module paid holiday.
const STATUS_REFUSED
Refused.
Class to manage Dolibarr users.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
Definition files.lib.php:64
dol_print_size($size, $shortvalue=0, $shortunit=0)
Return string with formatted size.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart='')
Return a path to have a the directory according to object where files are stored.
holiday_prepare_head($object)
Return array head with list of tabs to view object information.
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.