dolibarr  16.0.5
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-2022 Frédéric France <frederic.france@netlogic.fr>
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 3 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program. If not, see <https://www.gnu.org/licenses/>.
23  */
24 
31 require '../main.inc.php';
32 require_once DOL_DOCUMENT_ROOT.'/holiday/class/holiday.class.php';
33 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
34 require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
35 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
36 require_once DOL_DOCUMENT_ROOT.'/core/lib/holiday.lib.php';
37 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
38 
39 // Load translation files required by the page
40 $langs->loadLangs(array('other', 'holiday', 'companies'));
41 
42 $id = GETPOST('id', 'int');
43 $ref = GETPOST('ref', 'alpha');
44 $action = GETPOST('action', 'aZ09');
45 $confirm = GETPOST('confirm', 'alpha');
46 
47 // Get parameters
48 $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
49 $sortfield = GETPOST('sortfield', 'aZ09comma');
50 $sortorder = GETPOST('sortorder', 'aZ09comma');
51 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
52 if (empty($page) || $page == -1) {
53  $page = 0;
54 } // If $page is not defined, or '' or -1
55 $offset = $limit * $page;
56 $pageprev = $page - 1;
57 $pagenext = $page + 1;
58 if (!$sortorder) {
59  $sortorder = "ASC";
60 }
61 if (!$sortfield) {
62  $sortfield = "position_name";
63 }
64 
65 
66 $childids = $user->getAllChildIds(1);
67 
68 $morefilter = '';
69 if (!empty($conf->global->HOLIDAY_HIDE_FOR_NON_SALARIES)) {
70  $morefilter = 'AND employee = 1';
71 }
72 
73 $object = new Holiday($db);
74 
75 $extrafields = new ExtraFields($db);
76 
77 // fetch optionals attributes and labels
78 $extrafields->fetch_name_optionals_label($object->table_element);
79 
80 if (($id > 0) || $ref) {
81  $object->fetch($id, $ref);
82 
83  // Check current user can read this leave request
84  $canread = 0;
85  if (!empty($user->rights->holiday->readall)) {
86  $canread = 1;
87  }
88  if (!empty($user->rights->holiday->read) && in_array($object->fk_user, $childids)) {
89  $canread = 1;
90  }
91  if (!$canread) {
93  }
94 }
95 
96 
97 $upload_dir = $conf->holiday->dir_output.'/'.get_exdir(0, 0, 0, 1, $object, '');
98 $modulepart = 'holiday';
99 
100 // Protection if external user
101 if ($user->socid) {
102  $socid = $user->socid;
103 }
104 $result = restrictedArea($user, 'holiday', $object->id, 'holiday');
105 
106 $permissiontoadd = $user->rights->holiday->write; // Used by the include of actions_setnotes.inc.php
107 
108 
109 /*
110  * Actions
111  */
112 
113 include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php';
114 
115 
116 /*
117  * View
118  */
119 
120 $form = new Form($db);
121 
122 $listhalfday = array('morning'=>$langs->trans("Morning"), "afternoon"=>$langs->trans("Afternoon"));
123 $title = $langs->trans("Leave").' - '.$langs->trans("Files");
124 
125 llxHeader('', $title);
126 
127 if ($object->id) {
128  $valideur = new User($db);
129  $valideur->fetch($object->fk_validator);
130 
131  $userRequest = new User($db);
132  $userRequest->fetch($object->fk_user);
133 
134  $head = holiday_prepare_head($object);
135 
136  print dol_get_fiche_head($head, 'documents', $langs->trans("CPTitreMenu"), -1, 'holiday');
137 
138 
139  // Build file list
140  $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ?SORT_DESC:SORT_ASC), 1);
141  $totalsize = 0;
142  foreach ($filearray as $key => $file) {
143  $totalsize += $file['size'];
144  }
145 
146 
147  $linkback = '<a href="'.DOL_URL_ROOT.'/holiday/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
148 
149  dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref');
150 
151 
152  print '<div class="fichecenter">';
153  //print '<div class="fichehalfleft">';
154  print '<div class="underbanner clearboth"></div>';
155 
156  print '<table class="border tableforfield centpercent">';
157 
158  print '<tr>';
159  print '<td class="titlefield">'.$langs->trans("User").'</td>';
160  print '<td>';
161  print $userRequest->getNomUrl(-1, 'leave');
162  print '</td></tr>';
163 
164  // Type
165  print '<tr>';
166  print '<td>'.$langs->trans("Type").'</td>';
167  print '<td>';
168  $typeleaves = $object->getTypes(1, -1);
169  $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']);
170  print empty($labeltoshow) ? $langs->trans("TypeWasDisabledOrRemoved", $object->fk_type) : $labeltoshow;
171  print '</td>';
172  print '</tr>';
173 
174  $starthalfday = ($object->halfday == -1 || $object->halfday == 2) ? 'afternoon' : 'morning';
175  $endhalfday = ($object->halfday == 1 || $object->halfday == 2) ? 'morning' : 'afternoon';
176 
177  print '<tr>';
178  print '<td>';
179  print $form->textwithpicto($langs->trans('DateDebCP'), $langs->trans("FirstDayOfHoliday"));
180  print '</td>';
181  print '<td>'.dol_print_date($object->date_debut, 'day');
182  print ' &nbsp; &nbsp; ';
183  print '<span class="opacitymedium">'.$langs->trans($listhalfday[$starthalfday]).'</span>';
184  print '</td>';
185  print '</tr>';
186 
187  print '<tr>';
188  print '<td>';
189  print $form->textwithpicto($langs->trans('DateFinCP'), $langs->trans("LastDayOfHoliday"));
190  print '</td>';
191  print '<td>'.dol_print_date($object->date_fin, 'day');
192  print ' &nbsp; &nbsp; ';
193  print '<span class="opacitymedium">'.$langs->trans($listhalfday[$endhalfday]).'</span>';
194  print '</td>';
195  print '</tr>';
196 
197  // Nb days consumed
198  print '<tr>';
199  print '<td>';
200  $htmlhelp = $langs->trans('NbUseDaysCPHelp');
201  $includesaturday = (isset($conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_SATURDAY) ? $conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_SATURDAY : 1);
202  $includesunday = (isset($conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_SUNDAY) ? $conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_SUNDAY : 1);
203  if ($includesaturday) {
204  $htmlhelp .= '<br>'.$langs->trans("DayIsANonWorkingDay", $langs->trans("Saturday"));
205  }
206  if ($includesunday) {
207  $htmlhelp .= '<br>'.$langs->trans("DayIsANonWorkingDay", $langs->trans("Sunday"));
208  }
209  print $form->textwithpicto($langs->trans('NbUseDaysCP'), $htmlhelp);
210  print '</td>';
211  print '<td>'.num_open_day($object->date_debut_gmt, $object->date_fin_gmt, 0, 1, $object->halfday).'</td>';
212  print '</tr>';
213 
214  if ($object->statut == 5) {
215  print '<tr>';
216  print '<td>'.$langs->trans('DetailRefusCP').'</td>';
217  print '<td>'.$object->detail_refuse.'</td>';
218  print '</tr>';
219  }
220 
221  // Description
222  print '<tr>';
223  print '<td>'.$langs->trans('DescCP').'</td>';
224  print '<td>'.nl2br($object->description).'</td>';
225  print '</tr>';
226 
227  print '<tr><td>'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.count($filearray).'</td></tr>';
228  print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.dol_print_size($totalsize, 1, 1).'</td></tr>';
229 
230  print '</tbody>';
231  print '</table>'."\n";
232  /*
233  print '</div>';
234  print '<div class="fichehalfright">';
235 
236  print '<div class="underbanner clearboth"></div>';
237 
238  // Info workflow
239  print '<table class="border tableforfield centpercent">'."\n";
240  print '<tbody>';
241 
242  if (! empty($object->fk_user_create)) {
243  $userCreate=new User($db);
244  $userCreate->fetch($object->fk_user_create);
245  print '<tr>';
246  print '<td class="titlefield">'.$langs->trans('RequestByCP').'</td>';
247  print '<td>'.$userCreate->getNomUrl(-1).'</td>';
248  print '</tr>';
249  }
250 
251  print '<tr>';
252  print '<td class="titlefield">'.$langs->trans('ReviewedByCP').'</td>';
253  print '<td>'.$valideur->getNomUrl(-1).'</td>';
254  print '</tr>';
255 
256  print '<tr>';
257  print '<td>'.$langs->trans('DateCreation').'</td>';
258  print '<td>'.dol_print_date($object->date_create,'dayhour').'</td>';
259  print '</tr>';
260  if ($object->statut == 3) {
261  print '<tr>';
262  print '<td>'.$langs->trans('DateValidCP').'</td>';
263  print '<td>'.dol_print_date($object->date_valid,'dayhour').'</td>';
264  print '</tr>';
265  }
266  if ($object->statut == 4) {
267  print '<tr>';
268  print '<td>'.$langs->trans('DateCancelCP').'</td>';
269  print '<td>'.dol_print_date($object->date_cancel,'dayhour').'</td>';
270  print '</tr>';
271  }
272  if ($object->statut == 5) {
273  print '<tr>';
274  print '<td>'.$langs->trans('DateRefusCP').'</td>';
275  print '<td>'.dol_print_date($object->date_refuse,'dayhour').'</td>';
276  print '</tr>';
277  }
278  print '</tbody>';
279  print '</table>';
280 
281  print '</div>'; */
282  print '</div>';
283 
284  print '<div class="clearboth"></div>';
285 
286  print dol_get_fiche_end();
287 
288  $permissiontoadd = $user->rights->holiday->write;
289  $permtoedit = $user->rights->holiday->write;
290  $param = '&id='.$object->id;
291  $relativepathwithnofile = dol_sanitizeFileName($object->ref).'/';
292  $savingdocmask = dol_sanitizeFileName($object->ref).'-__file__';
293 
294  include DOL_DOCUMENT_ROOT.'/core/tpl/document_actions_post_headers.tpl.php';
295 } else {
296  print $langs->trans("ErrorUnknown");
297 }
298 
299 // End of page
300 llxFooter();
301 $db->close();
dol_sanitizeFileName
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
Definition: functions.lib.php:1226
restrictedArea
restrictedArea($user, $features, $objectid=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.
Definition: security.lib.php:234
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
llxFooter
llxFooter()
Footer empty.
Definition: document.php:89
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
dol_dir_list
dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0)
Scan a directory and return a list of files/directories.
Definition: files.lib.php:60
dol_banner_tab
dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='rowid', $fieldref='ref', $morehtmlref='', $moreparam='', $nodbprefix=0, $morehtmlleft='', $morehtmlstatus='', $onlybanner=0, $morehtmlright='')
Show tab footer of a card.
Definition: functions.lib.php:2046
llxHeader
if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) if(isset($_GET["hashp"]) &&!defined("NOLOGIN")) if((isset($_GET["modulepart"]) && $_GET["modulepart"]=='medias')) llxHeader()
Header empty.
Definition: document.php:80
get_exdir
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart='')
Return a path to have a the directory according to object where files are stored.
Definition: functions.lib.php:6549
Holiday
Class of the module paid holiday.
Definition: holiday.class.php:34
dol_print_size
dol_print_size($size, $shortvalue=0, $shortunit=0)
Return string with formated size.
Definition: functions.lib.php:2884
dol_get_fiche_head
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
Definition: functions.lib.php:1822
dol_get_fiche_end
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition: functions.lib.php:2018
User
Class to manage Dolibarr users.
Definition: user.class.php:44
GETPOSTISSET
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
Definition: functions.lib.php:386
ExtraFields
Class to manage standard extra fields.
Definition: extrafields.class.php:39
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
accessforbidden
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Definition: security.lib.php:933
holiday_prepare_head
holiday_prepare_head($object)
Return array head with list of tabs to view object informations.
Definition: holiday.lib.php:30