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       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
25/**
26 *       \file       htdocs/holiday/document.php
27 *       \ingroup    fichinter
28 *       \brief      Page des documents joints sur les contrats
29 */
30
31require '../main.inc.php';
32require_once DOL_DOCUMENT_ROOT.'/holiday/class/holiday.class.php';
33require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
34require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
35require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
36require_once DOL_DOCUMENT_ROOT.'/core/lib/holiday.lib.php';
37require_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');
52if (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;
58if (!$sortorder) {
59	$sortorder = "ASC";
60}
61if (!$sortfield) {
62	$sortfield = "position_name";
63}
64
65
66$childids = $user->getAllChildIds(1);
67
68$morefilter = '';
69if (!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
80if (($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) {
92		accessforbidden();
93	}
94}
95
96/*$cancreate = 0;
97
98if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->holiday->writeall_advance)) {
99	$cancreate = 1;
100}
101if (!empty($user->rights->holiday->write) && in_array($fuserid, $childids)) {
102	$cancreate = 1;
103}
104
105$candelete = 0;
106if (!empty($user->rights->holiday->delete)) {
107	$candelete = 1;
108}
109if ($object->statut == Holiday::STATUS_DRAFT && $user->rights->holiday->write && in_array($object->fk_user, $childids)) {
110	$candelete = 1;
111}
112*/
113
114$upload_dir = $conf->holiday->dir_output.'/'.get_exdir(0, 0, 0, 1, $object, '');
115$modulepart = 'holiday';
116
117// Protection if external user
118if ($user->socid) {
119	$socid = $user->socid;
120}
121$result = restrictedArea($user, 'holiday', $object->id, 'holiday');
122
123
124
125/*
126 * Actions
127 */
128
129include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php';
130
131
132/*
133 * View
134 */
135
136$form = new Form($db);
137
138$listhalfday = array('morning'=>$langs->trans("Morning"), "afternoon"=>$langs->trans("Afternoon"));
139
140$title = $langs->trans('InterventionCard');
141
142llxHeader('', $title);
143
144
145if ($object->id) {
146	$valideur = new User($db);
147	$valideur->fetch($object->fk_validator);
148
149	$userRequest = new User($db);
150	$userRequest->fetch($object->fk_user);
151
152	$head = holiday_prepare_head($object);
153
154	print dol_get_fiche_head($head, 'documents', $langs->trans("CPTitreMenu"), -1, 'holiday');
155
156
157	// Build file list
158	$filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ?SORT_DESC:SORT_ASC), 1);
159	$totalsize = 0;
160	foreach ($filearray as $key => $file) {
161		$totalsize += $file['size'];
162	}
163
164
165	$linkback = '<a href="'.DOL_URL_ROOT.'/holiday/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
166
167	dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref');
168
169
170	print '<div class="fichecenter">';
171	//print '<div class="fichehalfleft">';
172	print '<div class="underbanner clearboth"></div>';
173
174	print '<table class="border tableforfield centpercent">';
175
176	print '<tr>';
177	print '<td class="titlefield">'.$langs->trans("User").'</td>';
178	print '<td>';
179	print $userRequest->getNomUrl(-1, 'leave');
180	print '</td></tr>';
181
182	// Type
183	print '<tr>';
184	print '<td>'.$langs->trans("Type").'</td>';
185	print '<td>';
186	$typeleaves = $object->getTypes(1, -1);
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	print empty($labeltoshow) ? $langs->trans("TypeWasDisabledOrRemoved", $object->fk_type) : $labeltoshow;
189	print '</td>';
190	print '</tr>';
191
192	$starthalfday = ($object->halfday == -1 || $object->halfday == 2) ? 'afternoon' : 'morning';
193	$endhalfday = ($object->halfday == 1 || $object->halfday == 2) ? 'morning' : 'afternoon';
194
195	if (!$edit) {
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	} else {
206		print '<tr>';
207		print '<td>';
208		print $form->textwithpicto($langs->trans('DateDebCP'), $langs->trans("FirstDayOfHoliday"));
209		print '</td>';
210		print '<td>';
211		print $form->selectDate($object->date_debut, 'date_debut_');
212		print ' &nbsp; &nbsp; ';
213		print $form->selectarray('starthalfday', $listhalfday, (GETPOST('starthalfday') ?GETPOST('starthalfday') : $starthalfday));
214		print '</td>';
215		print '</tr>';
216	}
217
218	if (!$edit) {
219		print '<tr>';
220		print '<td>';
221		print $form->textwithpicto($langs->trans('DateFinCP'), $langs->trans("LastDayOfHoliday"));
222		print '</td>';
223		print '<td>'.dol_print_date($object->date_fin, 'day');
224		print ' &nbsp; &nbsp; ';
225		print '<span class="opacitymedium">'.$langs->trans($listhalfday[$endhalfday]).'</span>';
226		print '</td>';
227		print '</tr>';
228	} else {
229		print '<tr>';
230		print '<td>';
231		print $form->textwithpicto($langs->trans('DateFinCP'), $langs->trans("LastDayOfHoliday"));
232		print '</td>';
233		print '<td>';
234		print $form->selectDate($object->date_fin, 'date_fin_');
235		print ' &nbsp; &nbsp; ';
236		print $form->selectarray('endhalfday', $listhalfday, (GETPOST('endhalfday') ?GETPOST('endhalfday') : $endhalfday));
237		print '</td>';
238		print '</tr>';
239	}
240
241	// Nb days consumed
242	print '<tr>';
243	print '<td>';
244	$htmlhelp = $langs->trans('NbUseDaysCPHelp');
245	$includesaturday = (isset($conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_SATURDAY) ? $conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_SATURDAY : 1);
246	$includesunday   = (isset($conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_SUNDAY) ? $conf->global->MAIN_NON_WORKING_DAYS_INCLUDE_SUNDAY : 1);
247	if ($includesaturday) {
248		$htmlhelp .= '<br>'.$langs->trans("DayIsANonWorkingDay", $langs->trans("Saturday"));
249	}
250	if ($includesunday) {
251		$htmlhelp .= '<br>'.$langs->trans("DayIsANonWorkingDay", $langs->trans("Sunday"));
252	}
253	print $form->textwithpicto($langs->trans('NbUseDaysCP'), $htmlhelp);
254	print '</td>';
255	print '<td>'.num_open_day($object->date_debut_gmt, $object->date_fin_gmt, 0, 1, $object->halfday).'</td>';
256	print '</tr>';
257
258	if ($object->statut == 5) {
259		print '<tr>';
260		print '<td>'.$langs->trans('DetailRefusCP').'</td>';
261		print '<td>'.$object->detail_refuse.'</td>';
262		print '</tr>';
263	}
264
265	// Description
266	if (!$edit) {
267		print '<tr>';
268		print '<td>'.$langs->trans('DescCP').'</td>';
269		print '<td>'.nl2br($object->description).'</td>';
270		print '</tr>';
271	} else {
272		print '<tr>';
273		print '<td>'.$langs->trans('DescCP').'</td>';
274		print '<td><textarea name="description" class="flat" rows="'.ROWS_3.'" cols="70">'.$object->description.'</textarea></td>';
275		print '</tr>';
276	}
277
278	print '<tr><td>'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.count($filearray).'</td></tr>';
279	print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.dol_print_size($totalsize, 1, 1).'</td></tr>';
280
281	print '</tbody>';
282	print '</table>'."\n";
283	/*
284	print '</div>';
285	print '<div class="fichehalfright">';
286	print '<div class="ficheaddleft">';
287
288	print '<div class="underbanner clearboth"></div>';
289
290	// Info workflow
291	print '<table class="border tableforfield centpercent">'."\n";
292	print '<tbody>';
293
294	if (! empty($object->fk_user_create))
295	{
296		$userCreate=new User($db);
297		$userCreate->fetch($object->fk_user_create);
298		print '<tr>';
299		print '<td class="titlefield">'.$langs->trans('RequestByCP').'</td>';
300		print '<td>'.$userCreate->getNomUrl(-1).'</td>';
301		print '</tr>';
302	}
303
304	if (!$edit) {
305		print '<tr>';
306		print '<td class="titlefield">'.$langs->trans('ReviewedByCP').'</td>';
307		print '<td>'.$valideur->getNomUrl(-1).'</td>';
308		print '</tr>';
309	} else {
310		print '<tr>';
311		print '<td class="titlefield">'.$langs->trans('ReviewedByCP').'</td>';
312		print '<td>';
313		print $form->select_dolusers($object->fk_user, "valideur", 1, ($user->admin ? '' : array($user->id)));	// By default, hierarchical parent
314		print '</td>';
315		print '</tr>';
316	}
317
318	print '<tr>';
319	print '<td>'.$langs->trans('DateCreation').'</td>';
320	print '<td>'.dol_print_date($object->date_create,'dayhour').'</td>';
321	print '</tr>';
322	if ($object->statut == 3) {
323		print '<tr>';
324		print '<td>'.$langs->trans('DateValidCP').'</td>';
325		print '<td>'.dol_print_date($object->date_valid,'dayhour').'</td>';
326		print '</tr>';
327	}
328	if ($object->statut == 4) {
329		print '<tr>';
330		print '<td>'.$langs->trans('DateCancelCP').'</td>';
331		print '<td>'.dol_print_date($object->date_cancel,'dayhour').'</td>';
332		print '</tr>';
333	}
334	if ($object->statut == 5) {
335		print '<tr>';
336		print '<td>'.$langs->trans('DateRefusCP').'</td>';
337		print '<td>'.dol_print_date($object->date_refuse,'dayhour').'</td>';
338		print '</tr>';
339	}
340	print '</tbody>';
341	print '</table>';
342
343	print '</div>';
344	print '</div>'; */
345	print '</div>';
346
347	print '<div class="clearboth"></div>';
348
349	print dol_get_fiche_end();
350
351
352
353	$modulepart = 'holiday';
354	$permissiontoadd = $user->rights->holiday->write;
355	$permtoedit = $user->rights->holiday->write;
356	$param = '&id='.$object->id;
357	include DOL_DOCUMENT_ROOT.'/core/tpl/document_actions_post_headers.tpl.php';
358} else {
359	print $langs->trans("ErrorUnknown");
360}
361
362// End of page
363llxFooter();
364$db->close();
365