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