dolibarr 21.0.3
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-2024 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';
34require_once DOL_DOCUMENT_ROOT.'/holiday/class/holiday.class.php';
35require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
36require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
37require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
38require_once DOL_DOCUMENT_ROOT.'/core/lib/holiday.lib.php';
39require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
40
49// Load translation files required by the page
50$langs->loadLangs(array('other', 'holiday', 'companies'));
51
52$id = GETPOSTINT('id');
53$ref = GETPOST('ref', 'alpha');
54$action = GETPOST('action', 'aZ09');
55$confirm = GETPOST('confirm', 'alpha');
56
57// Get parameters
58$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
59$sortfield = GETPOST('sortfield', 'aZ09comma');
60$sortorder = GETPOST('sortorder', 'aZ09comma');
61$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
62if (empty($page) || $page == -1) {
63 $page = 0;
64} // If $page is not defined, or '' or -1
65$offset = $limit * $page;
66$pageprev = $page - 1;
67$pagenext = $page + 1;
68if (!$sortorder) {
69 $sortorder = "ASC";
70}
71if (!$sortfield) {
72 $sortfield = "position_name";
73}
74
75
76$childids = $user->getAllChildIds(1);
77
78$morefilter = '';
79if (getDolGlobalString('HOLIDAY_HIDE_FOR_NON_SALARIES')) {
80 $morefilter = 'AND employee = 1';
81}
82
83$object = new Holiday($db);
84
85$extrafields = new ExtraFields($db);
86
87// fetch optionals attributes and labels
88$extrafields->fetch_name_optionals_label($object->table_element);
89
90$permissiontoapprove = $user->hasRight('holiday', 'approve');
91
92if (($id > 0) || $ref) {
93 $object->fetch($id, $ref);
94
95 // Check current user can read this leave request
96 $canread = 0;
97 if ($user->hasRight('holiday', 'readall')) {
98 $canread = 1;
99 }
100 if ($user->hasRight('holiday', 'read') && in_array($object->fk_user, $childids)) {
101 $canread = 1;
102 }
103 if ($permissiontoapprove && $object->fk_validator == $user->id && !getDolGlobalString('HOLIDAY_CAN_APPROVE_ONLY_THE_SUBORDINATES')) { // TODO HOLIDAY_CAN_APPROVE_ONLY_THE_SUBORDINATES not completely implemented
104 $canread = 1;
105 }
106 if (!$canread) {
108 }
109}
110
111
112$upload_dir = $conf->holiday->multidir_output[$object->entity].'/'.get_exdir(0, 0, 0, 1, $object, '');
113$modulepart = 'holiday';
114
115// Protection if external user
116if ($user->socid) {
117 $socid = $user->socid;
118}
119$result = restrictedArea($user, 'holiday', $object->id, 'holiday');
120
121$permissiontoadd = $user->hasRight('holiday', 'write'); // Used by the include of actions_setnotes.inc.php
122
123
124/*
125 * Actions
126 */
127
128include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php';
129
130
131/*
132 * View
133 */
134
135$form = new Form($db);
136
137$listhalfday = array('morning'=>$langs->trans("Morning"), "afternoon"=>$langs->trans("Afternoon"));
138$title = $langs->trans("Leave").' - '.$langs->trans("Files");
139$help_url = 'EN:Module_Holiday';
140
141llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-holiday page-card_documents');
142
143if ($object->id) {
144 $valideur = new User($db);
145 $valideur->fetch($object->fk_validator);
146
147 $userRequest = new User($db);
148 $userRequest->fetch($object->fk_user);
149
150 $head = holiday_prepare_head($object);
151
152 print dol_get_fiche_head($head, 'documents', $langs->trans("CPTitreMenu"), -1, 'holiday');
153
154
155 // Build file list
156 $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ? SORT_DESC : SORT_ASC), 1);
157 $totalsize = 0;
158 foreach ($filearray as $key => $file) {
159 $totalsize += $file['size'];
160 }
161
162
163 $linkback = '<a href="'.DOL_URL_ROOT.'/holiday/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
164
165 dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref');
166
167
168 print '<div class="fichecenter">';
169 //print '<div class="fichehalfleft">';
170 print '<div class="underbanner clearboth"></div>';
171
172 print '<table class="border tableforfield centpercent">';
173
174 print '<tr>';
175 print '<td class="titlefield">'.$langs->trans("User").'</td>';
176 print '<td>';
177 print $userRequest->getNomUrl(-1, 'leave');
178 print '</td></tr>';
179
180 // Type
181 print '<tr>';
182 print '<td>'.$langs->trans("Type").'</td>';
183 print '<td>';
184 $typeleaves = $object->getTypes(1, -1);
185 if (empty($typeleaves[$object->fk_type])) {
186 $labeltoshow = $langs->trans("TypeWasDisabledOrRemoved", $object->fk_type);
187 } else {
188 $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']);
189 }
190 print $labeltoshow;
191 print '</td>';
192 print '</tr>';
193
194 $starthalfday = ($object->halfday == -1 || $object->halfday == 2) ? 'afternoon' : 'morning';
195 $endhalfday = ($object->halfday == 1 || $object->halfday == 2) ? 'morning' : 'afternoon';
196
197 print '<tr>';
198 print '<td>';
199 print $form->textwithpicto($langs->trans('DateDebCP'), $langs->trans("FirstDayOfHoliday"));
200 print '</td>';
201 print '<td>'.dol_print_date($object->date_debut, 'day');
202 print ' &nbsp; &nbsp; ';
203 print '<span class="opacitymedium">'.$langs->trans($listhalfday[$starthalfday]).'</span>';
204 print '</td>';
205 print '</tr>';
206
207 print '<tr>';
208 print '<td>';
209 print $form->textwithpicto($langs->trans('DateFinCP'), $langs->trans("LastDayOfHoliday"));
210 print '</td>';
211 print '<td>'.dol_print_date($object->date_fin, 'day');
212 print ' &nbsp; &nbsp; ';
213 print '<span class="opacitymedium">'.$langs->trans($listhalfday[$endhalfday]).'</span>';
214 print '</td>';
215 print '</tr>';
216
217 // Nb days consumed
218 print '<tr>';
219 print '<td>';
220 $htmlhelp = $langs->trans('NbUseDaysCPHelp');
221 $includesaturday = (isset($conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_SATURDAY) ? $conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_SATURDAY : 1);
222 $includesunday = (isset($conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_SUNDAY) ? $conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_SUNDAY : 1);
223 if ($includesaturday) {
224 $htmlhelp .= '<br>'.$langs->trans("DayIsANonWorkingDay", $langs->trans("Saturday"));
225 }
226 if ($includesunday) {
227 $htmlhelp .= '<br>'.$langs->trans("DayIsANonWorkingDay", $langs->trans("Sunday"));
228 }
229 print $form->textwithpicto($langs->trans('NbUseDaysCP'), $htmlhelp);
230 print '</td>';
231 print '<td>'.num_open_day($object->date_debut_gmt, $object->date_fin_gmt, 0, 1, $object->halfday).'</td>';
232 print '</tr>';
233
234 if ($object->status == Holiday::STATUS_REFUSED) {
235 print '<tr>';
236 print '<td>'.$langs->trans('DetailRefusCP').'</td>';
237 print '<td>'.$object->detail_refuse.'</td>';
238 print '</tr>';
239 }
240
241 // Description
242 print '<tr>';
243 print '<td>'.$langs->trans('DescCP').'</td>';
244 print '<td>'.nl2br($object->description).'</td>';
245 print '</tr>';
246
247 print '<tr><td>'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.count($filearray).'</td></tr>';
248 print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.dol_print_size($totalsize, 1, 1).'</td></tr>';
249
250 print '</tbody>';
251 print '</table>'."\n";
252 /*
253 print '</div>';
254 print '<div class="fichehalfright">';
255
256 print '<div class="underbanner clearboth"></div>';
257
258 // Info workflow
259 print '<table class="border tableforfield centpercent">'."\n";
260 print '<tbody>';
261
262 if (!empty($object->fk_user_create)) {
263 $userCreate=new User($db);
264 $userCreate->fetch($object->fk_user_create);
265 print '<tr>';
266 print '<td class="titlefield">'.$langs->trans('RequestByCP').'</td>';
267 print '<td>'.$userCreate->getNomUrl(-1).'</td>';
268 print '</tr>';
269 }
270
271 print '<tr>';
272 print '<td class="titlefield">'.$langs->trans('ReviewedByCP').'</td>';
273 print '<td>'.$valideur->getNomUrl(-1).'</td>';
274 print '</tr>';
275
276 print '<tr>';
277 print '<td>'.$langs->trans('DateCreation').'</td>';
278 print '<td>'.dol_print_date($object->date_create,'dayhour').'</td>';
279 print '</tr>';
280 if ($object->status == 3) {
281 print '<tr>';
282 print '<td>'.$langs->trans('DateValidCP').'</td>';
283 print '<td>'.dol_print_date($object->date_valid,'dayhour').'</td>';
284 print '</tr>';
285 }
286 if ($object->status == 4) {
287 print '<tr>';
288 print '<td>'.$langs->trans('DateCancelCP').'</td>';
289 print '<td>'.dol_print_date($object->date_cancel,'dayhour').'</td>';
290 print '</tr>';
291 }
292 if ($object->status == 5) {
293 print '<tr>';
294 print '<td>'.$langs->trans('DateRefusCP').'</td>';
295 print '<td>'.dol_print_date($object->date_refuse,'dayhour').'</td>';
296 print '</tr>';
297 }
298 print '</tbody>';
299 print '</table>';
300
301 print '</div>'; */
302 print '</div>';
303
304 print '<div class="clearboth"></div>';
305
306 print dol_get_fiche_end();
307
308 $permissiontoadd = $user->hasRight('holiday', 'write');
309 $permtoedit = $user->hasRight('holiday', 'write');
310 $param = '&id='.$object->id;
311 $relativepathwithnofile = get_exdir(0, 0, 0, 1, $object, '').'/';
312 $savingdocmask = dol_sanitizeFileName($object->ref).'-__file__';
313
314 include DOL_DOCUMENT_ROOT.'/core/tpl/document_actions_post_headers.tpl.php';
315} else {
316 print $langs->trans("ErrorUnknown");
317}
318
319// End of page
320llxFooter();
321$db->close();
$id
Definition account.php:48
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:87
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:71
Class to manage standard extra fields.
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.
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_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)
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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.
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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
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.