dolibarr  7.0.0-beta
define_holiday.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2007-2016 Laurent Destailleur <eldy@users.sourceforge.net>
3  * Copyright (C) 2011 Dimitri Mouillard <dmouillard@teclib.com>
4  * Copyright (C) 2013 Marcos García <marcosgdf@gmail.com>
5  * Copyright (C) 2016 Regis Houssin <regis.houssin@capnetworks.com>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
29 require('../main.inc.php');
30 require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/holiday/common.inc.php';
32 
33 $langs->load('users');
34 $langs->load('hrm');
35 
36 $action=GETPOST('action','aZ09');
37 
38 $search_name=GETPOST('search_name', 'alpha');
39 $search_supervisor=GETPOST('search_supervisor', 'int');
40 
41 // Load variable for pagination
42 $limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit;
43 $sortfield = GETPOST('sortfield','alpha');
44 $sortorder = GETPOST('sortorder','alpha');
45 $page = GETPOST('page','int');
46 if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
47 $offset = $limit * $page;
48 $pageprev = $page - 1;
49 $pagenext = $page + 1;
50 if (! $sortfield) $sortfield="t.rowid"; // Set here default search field
51 if (! $sortorder) $sortorder="ASC";
52 
53 
54 // Protection if external user
55 if ($user->societe_id > 0) accessforbidden();
56 
57 // If the user does not have perm to read the page
58 if (!$user->rights->holiday->read) accessforbidden();
59 
60 
61 // Initialize technical object to manage context to save list fields
62 $contextpage=GETPOST('contextpage','aZ')?GETPOST('contextpage','aZ'):'defineholidaylist';
63 
64 // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array
65 $hookmanager->initHooks(array('defineholidaylist'));
66 $extrafields = new ExtraFields($db);
67 
68 $holiday = new Holiday($db);
69 
70 
71 /*
72  * Actions
73  */
74 
75 if (GETPOST('cancel','alpha')) { $action='list'; $massaction=''; }
76 if (! GETPOST('confirmmassaction','alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { $massaction=''; }
77 
78 $parameters=array();
79 $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
80 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
81 
82 if (empty($reshook))
83 {
84  // Selection of new fields
85  include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
86 
87  // Purge search criteria
88  if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x','alpha') ||GETPOST('button_removefilter','alpha')) // All tests are required to be compatible with all browsers
89  {
90  $search_name='';
91  $search_supervisor='';
92  $toselect='';
93  $search_array_options=array();
94  }
95 
96  // Mass actions
97  /*
98  $objectclass='Skeleton';
99  $objectlabel='Skeleton';
100  $permtoread = $user->rights->skeleton->read;
101  $permtodelete = $user->rights->skeleton->delete;
102  $uploaddir = $conf->skeleton->dir_output;
103  include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
104  */
105 
106  // Si il y a une action de mise à jour
107  if ($action == 'update' && isset($_POST['update_cp']))
108  {
109  $error = 0;
110 
111  $typeleaves=$holiday->getTypes(1,1);
112 
113  $userID = array_keys($_POST['update_cp']);
114  $userID = $userID[0];
115 
116  foreach($typeleaves as $key => $val)
117  {
118  $userValue = $_POST['nb_holiday_'.$val['rowid']];
119  $userValue = $userValue[$userID];
120 
121  if (!empty($userValue))
122  {
123  $userValue = price2num($userValue,5);
124  } else {
125  $userValue = '';
126  }
127 
128  //If the user set a comment, we add it to the log comment
129  $comment = ((isset($_POST['note_holiday'][$userID]) && !empty($_POST['note_holiday'][$userID])) ? ' ('.$_POST['note_holiday'][$userID].')' : '');
130 
131  //print 'eee'.$val['rowid'].'-'.$userValue;
132  if ($userValue != '')
133  {
134  // We add the modification to the log (must be before update of sold because we read current value of sold)
135  $result=$holiday->addLogCP($user->id, $userID, $langs->transnoentitiesnoconv('ManualUpdate').$comment, $userValue, $val['rowid']);
136  if ($result < 0)
137  {
138  setEventMessages($holiday->error, $holiday->errors, 'errors');
139  $error++;
140  }
141 
142  // Update of the days of the employee
143  $result = $holiday->updateSoldeCP($userID, $userValue, $val['rowid']);
144  if ($result < 0)
145  {
146  setEventMessages($holiday->error, $holiday->errors, 'errors');
147  $error++;
148  }
149 
150  // If it first update of balance, we set date to avoid to have sold incremented by new month
151  /*
152  $now=dol_now();
153  $sql = "UPDATE ".MAIN_DB_PREFIX."holiday_config SET";
154  $sql.= " value = '".dol_print_date($now,'%Y%m%d%H%M%S')."'";
155  $sql.= " WHERE name = 'lastUpdate' and value IS NULL"; // Add value IS NULL to be sure to update only at init.
156  dol_syslog('define_holiday update lastUpdate entry', LOG_DEBUG);
157  $result = $db->query($sql);
158  */
159  }
160  }
161 
162  if (! $error) setEventMessages('UpdateConfCPOK', '', 'mesgs');
163  }
164 }
165 
166 
167 /*
168  * View
169  */
170 
171 $form = new Form($db);
172 $userstatic=new User($db);
173 
174 llxHeader('', $langs->trans('CPTitreMenu'));
175 
176 
177 print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
178 if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
179 print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
180 print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
181 print '<input type="hidden" name="action" value="list">';
182 print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
183 print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
184 print '<input type="hidden" name="page" value="'.$page.'">';
185 print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
186 
187 print load_fiche_titre($langs->trans('MenuConfCP'), '', 'title_hrm.png');
188 
189 print '<div class="info">'.$langs->trans('LastUpdateCP').': '."\n";
190 $lastUpdate = $holiday->getConfCP('lastUpdate');
191 if ($lastUpdate)
192 {
193  $monthLastUpdate = $lastUpdate[4].$lastUpdate[5];
194  $yearLastUpdate = $lastUpdate[0].$lastUpdate[1].$lastUpdate[2].$lastUpdate[3];
195  print '<strong>'.dol_print_date($db->jdate($holiday->getConfCP('lastUpdate')),'dayhour','tzuser').'</strong>';
196  print '<br>'.$langs->trans("MonthOfLastMonthlyUpdate").': <strong>'.$yearLastUpdate.'-'.$monthLastUpdate.'</strong>'."\n";
197 }
198 else print $langs->trans('None');
199 print "</div><br>\n";
200 
201 $result = $holiday->updateBalance(); // Create users into table holiday if they don't exists. TODO Remove this whif we use field into table user.
202 if ($result < 0)
203 {
204  setEventMessages($holiday->error, $holiday->errors, 'errors');
205 }
206 
207 $filters = '';
208 
209 // Filter on array of ids of all childs
210 $userchilds=array();
211 if (empty($user->rights->holiday->read_all))
212 {
213  $userchilds=$user->getAllChildIds(1);
214  $filters.=' AND u.rowid IN ('.join(', ',$userchilds).')';
215 }
216 
217 $filters.=natural_search(array('u.firstname','u.lastname'), $search_name);
218 if ($search_supervisor > 0) $filters.=natural_search(array('u.fk_user'), $search_supervisor, 2);
219 
220 $listUsers = $holiday->fetchUsers(false, true, $filters);
221 if (is_numeric($listUsers) && $listUsers < 0)
222 {
223  setEventMessages($holiday->error, $holiday->errors, 'errors');
224 }
225 
226 $var=true;
227 $i = 0;
228 
229 $typeleaves=$holiday->getTypes(1,1);
230 
231 if (count($typeleaves) == 0)
232 {
233  //print '<div class="info">';
234  print $langs->trans("NoLeaveWithCounterDefined")."<br>\n";
235  print $langs->trans("GoIntoDictionaryHolidayTypes");
236  //print '</div>';
237 }
238 else
239 {
240  $canedit=0;
241  if (! empty($user->rights->holiday->define_holiday)) $canedit=1;
242 
243  print '<input type="hidden" name="action" value="update" />';
244 
245  $moreforfilter='';
246 
247  print '<div class="div-table-responsive">';
248  print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"").'" id="tablelines3">'."\n";
249 
250  print '<tr class="liste_titre_filter">';
251 
252  // User
253  print '<td class="liste_titre"><input type="text" name="search_name" value="'.dol_escape_htmltag($search_name).'"></td>';
254 
255  // Supervisor
256  print '<td class="liste_titre">';
257  print $form->select_dolusers($search_supervisor, 'search_supervisor', 1, null, 0, null, null, 0, 0, 0, '', 0, '', 'maxwidth200');
258  print '</td>';
259 
260  // Type of leave request
261  if (count($typeleaves))
262  {
263  foreach($typeleaves as $key => $val)
264  {
265  print '<td class="liste_titre" style="text-align:center"></td>';
266  }
267  }
268  else
269  {
270  print '<td class="liste_titre"></td>';
271  }
272  print '<td class="liste_titre"></td>';
273 
274  // Action column
275  print '<td class="liste_titre" align="right">';
276  $searchpicto=$form->showFilterButtons();
277  print $searchpicto;
278  print '</td>';
279 
280  print '</tr>';
281 
282  print '<tr class="liste_titre">';
283  print_liste_field_titre('Employee', $_SERVER["PHP_SELF"]);
284  print_liste_field_titre('Supervisor', $_SERVER["PHP_SELF"]);
285  if (count($typeleaves))
286  {
287  foreach($typeleaves as $key => $val)
288  {
289  print_liste_field_titre($val['label'], $_SERVER["PHP_SELF"], '', '', '', 'align="center"');
290  }
291  }
292  else
293  {
294  print_liste_field_titre('NoLeaveWithCounterDefined', $_SERVER["PHP_SELF"], '', '', '', '');
295  }
296  print_liste_field_titre((empty($user->rights->holiday->define_holiday) ? '' : 'Note'), $_SERVER["PHP_SELF"]);
298  print '</tr>';
299 
300  $usersupervisor = new User($db);
301 
302  foreach($listUsers as $users)
303  {
304  // If user has not permission to edit/read all, we must see only subordinates
305  if (empty($user->rights->holiday->read_all))
306  {
307  if (($users['rowid'] != $user->id) && (! in_array($users['rowid'], $userchilds))) continue; // This user is not into hierarchy of current user, we hide it.
308  }
309 
310  $userstatic->id=$users['rowid'];
311  $userstatic->lastname=$users['lastname'];
312  $userstatic->firstname=$users['firstname'];
313  $userstatic->gender=$users['gender'];
314  $userstatic->photo=$users['photo'];
315  $userstatic->statut=$users['status'];
316  $userstatic->employee=$users['employee'];
317  $userstatic->fk_user=$users['fk_user'];
318 
319  if ($userstatic->fk_user > 0) $usersupervisor->fetch($userstatic->fk_user);
320 
321  print '<tr class="oddeven">';
322 
323  // User
324  print '<td>';
325  print $userstatic->getNomUrl(-1);
326  print '</td>';
327 
328  // Supervisor
329  print '<td>';
330  if ($userstatic->fk_user > 0) print $usersupervisor->getNomUrl(-1);
331  print '</td>';
332 
333  // Amount for each type
334  if (count($typeleaves))
335  {
336  foreach($typeleaves as $key => $val)
337  {
338  $nbtoshow='';
339  if ($holiday->getCPforUser($users['rowid'], $val['rowid']) != '') $nbtoshow=price2num($holiday->getCPforUser($users['rowid'], $val['rowid']), 5);
340 
341  //var_dump($users['rowid'].' - '.$val['rowid']);
342  print '<td style="text-align:center">';
343  if ($canedit) print '<input type="text"'.($canedit?'':' disabled="disabled"').' value="'.$nbtoshow.'" name="nb_holiday_'.$val['rowid'].'['.$users['rowid'].']" size="5" style="text-align: center;"/>';
344  else print $nbtoshow;
345  //print ' '.$langs->trans('days');
346  print '</td>'."\n";
347  }
348  }
349  else
350  {
351  print '<td></td>';
352  }
353 
354  // Note
355  print '<td>';
356  if ($canedit) print '<input type="text"'.($canedit?'':' disabled="disabled"').' class="maxwidthonsmartphone" value="" name="note_holiday['.$users['rowid'].']" size="30"/>';
357  print '</td>';
358  print '<td>';
359  if (! empty($user->rights->holiday->define_holiday))
360  {
361  print '<input type="submit" name="update_cp['.$users['rowid'].']" value="'.dol_escape_htmltag($langs->trans("Update")).'" class="button"/>';
362  }
363  print '</td>'."\n";
364  print '</tr>';
365 
366  $i++;
367  }
368 
369  print '</table>';
370  print '</div>';
371 }
372 
373 print '</form>';
374 
375 llxFooter();
376 
377 $db->close();
Class of the module paid holiday.
llxFooter()
Empty footer.
Definition: wrapper.php:58
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
Class to manage Dolibarr users.
Definition: user.class.php:39
if(empty($reshook)) $form
View.
Definition: perms.php:103
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields...
GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
Return value of a param into GET or POST supervariable.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Class to manage standard extra fields.
Class to manage generation of HTML components Only common components must be here.
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id=0, $morecssontable='', $morehtmlcenter='')
Load a title with picto.
llxHeader()
Empty header.
Definition: wrapper.php:46
natural_search($fields, $value, $mode=0, $nofirstand=0)
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
print
Draft customers invoices.
Definition: index.php:91
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="")
Show title line of an array.
price2num($amount, $rounding='', $alreadysqlnb=0)
Function that return a number with universal decimal format (decimal separator is '...