dolibarr  9.0.0
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@inodbox.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 // Load translation files required by the page
34 $langs->loadlangs(array('users', 'hrm'));
35 
36 $action=GETPOST('action','aZ09');
37 $contextpage=GETPOST('contextpage','aZ')?GETPOST('contextpage','aZ'):'defineholidaylist';
38 
39 $search_name=GETPOST('search_name', 'alpha');
40 $search_supervisor=GETPOST('search_supervisor', 'int');
41 
42 // Load variable for pagination
43 $limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit;
44 $sortfield = GETPOST('sortfield','alpha');
45 $sortorder = GETPOST('sortorder','alpha');
46 $page = GETPOST('page','int');
47 if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
48 $offset = $limit * $page;
49 $pageprev = $page - 1;
50 $pagenext = $page + 1;
51 if (! $sortfield) $sortfield="t.rowid"; // Set here default search field
52 if (! $sortorder) $sortorder="ASC";
53 
54 
55 // Protection if external user
56 if ($user->societe_id > 0) accessforbidden();
57 
58 // If the user does not have perm to read the page
59 if (!$user->rights->holiday->read) accessforbidden();
60 
61 
62 // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array
63 $hookmanager->initHooks(array('defineholidaylist'));
64 $extrafields = new ExtraFields($db);
65 
66 $holiday = new Holiday($db);
67 
68 
69 /*
70  * Actions
71  */
72 
73 if (GETPOST('cancel','alpha')) { $action='list'; $massaction=''; }
74 if (! GETPOST('confirmmassaction','alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { $massaction=''; }
75 
76 $parameters=array();
77 $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
78 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
79 
80 if (empty($reshook))
81 {
82  // Selection of new fields
83  include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
84 
85  // Purge search criteria
86  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
87  {
88  $search_name='';
89  $search_supervisor='';
90  $toselect='';
91  $search_array_options=array();
92  }
93 
94  // Mass actions
95  /*
96  $objectclass='Skeleton';
97  $objectlabel='Skeleton';
98  $permtoread = $user->rights->skeleton->read;
99  $permtodelete = $user->rights->skeleton->delete;
100  $uploaddir = $conf->skeleton->dir_output;
101  include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
102  */
103 
104  // Si il y a une action de mise à jour
105  if ($action == 'update' && isset($_POST['update_cp']))
106  {
107  $error = 0;
108 
109  $typeleaves=$holiday->getTypes(1,1);
110 
111  $userID = array_keys($_POST['update_cp']);
112  $userID = $userID[0];
113 
114  foreach($typeleaves as $key => $val)
115  {
116  $userValue = $_POST['nb_holiday_'.$val['rowid']];
117  $userValue = $userValue[$userID];
118 
119  if (!empty($userValue) || (string) $userValue == '0')
120  {
121  $userValue = price2num($userValue,5);
122  } else {
123  $userValue = '';
124  }
125 
126  //If the user set a comment, we add it to the log comment
127  $comment = ((isset($_POST['note_holiday'][$userID]) && !empty($_POST['note_holiday'][$userID])) ? ' ('.$_POST['note_holiday'][$userID].')' : '');
128 
129  //print 'holiday: '.$val['rowid'].'-'.$userValue;
130  if ($userValue != '')
131  {
132  // We add the modification to the log (must be before update of sold because we read current value of sold)
133  $result=$holiday->addLogCP($user->id, $userID, $langs->transnoentitiesnoconv('ManualUpdate').$comment, $userValue, $val['rowid']);
134  if ($result < 0)
135  {
136  setEventMessages($holiday->error, $holiday->errors, 'errors');
137  $error++;
138  }
139 
140  // Update of the days of the employee
141  $result = $holiday->updateSoldeCP($userID, $userValue, $val['rowid']);
142  if ($result < 0)
143  {
144  setEventMessages($holiday->error, $holiday->errors, 'errors');
145  $error++;
146  }
147 
148  // If it first update of balance, we set date to avoid to have sold incremented by new month
149  /*
150  $now=dol_now();
151  $sql = "UPDATE ".MAIN_DB_PREFIX."holiday_config SET";
152  $sql.= " value = '".dol_print_date($now,'%Y%m%d%H%M%S')."'";
153  $sql.= " WHERE name = 'lastUpdate' and value IS NULL"; // Add value IS NULL to be sure to update only at init.
154  dol_syslog('define_holiday update lastUpdate entry', LOG_DEBUG);
155  $result = $db->query($sql);
156  */
157  }
158  }
159 
160  if (! $error) setEventMessages('UpdateConfCPOK', '', 'mesgs');
161  }
162 }
163 
164 
165 /*
166  * View
167  */
168 
169 $form = new Form($db);
170 $userstatic=new User($db);
171 
172 llxHeader('', $langs->trans('CPTitreMenu'));
173 
174 
175 $typeleaves=$holiday->getTypes(1,1);
176 
177 
178 print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
179 if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
180 print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
181 print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
182 print '<input type="hidden" name="action" value="update">';
183 print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
184 print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
185 print '<input type="hidden" name="page" value="'.$page.'">';
186 print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
187 
188 print load_fiche_titre($langs->trans('MenuConfCP'), '', 'title_hrm.png');
189 
190 print '<div class="info">'.$langs->trans('LastUpdateCP').': '."\n";
191 $lastUpdate = $holiday->getConfCP('lastUpdate');
192 if ($lastUpdate)
193 {
194  $monthLastUpdate = $lastUpdate[4].$lastUpdate[5];
195  $yearLastUpdate = $lastUpdate[0].$lastUpdate[1].$lastUpdate[2].$lastUpdate[3];
196  print '<strong>'.dol_print_date($db->jdate($holiday->getConfCP('lastUpdate')),'dayhour','tzuser').'</strong>';
197  print '<br>'.$langs->trans("MonthOfLastMonthlyUpdate").': <strong>'.$yearLastUpdate.'-'.$monthLastUpdate.'</strong>'."\n";
198 }
199 else print $langs->trans('None');
200 print "</div><br>\n";
201 
202 $result = $holiday->updateBalance(); // Create users into table holiday if they don't exists. TODO Remove this whif we use field into table user.
203 if ($result < 0)
204 {
205  setEventMessages($holiday->error, $holiday->errors, 'errors');
206 }
207 
208 $filters = '';
209 
210 // Filter on array of ids of all childs
211 $userchilds=array();
212 if (empty($user->rights->holiday->read_all))
213 {
214  $userchilds=$user->getAllChildIds(1);
215  $filters.=' AND u.rowid IN ('.join(', ',$userchilds).')';
216 }
217 if (!empty($search_name)) {
218  $filters.=natural_search(array('u.firstname','u.lastname'), $search_name);
219 }
220 if ($search_supervisor > 0) $filters.=natural_search(array('u.fk_user'), $search_supervisor, 2);
221 $filters.= ' AND employee = 1'; // Only employee users are visible
222 
223 $listUsers = $holiday->fetchUsers(false, true, $filters);
224 if (is_numeric($listUsers) && $listUsers < 0)
225 {
226  setEventMessages($holiday->error, $holiday->errors, 'errors');
227 }
228 
229 $i = 0;
230 
231 
232 if (count($typeleaves) == 0)
233 {
234  //print '<div class="info">';
235  print $langs->trans("NoLeaveWithCounterDefined")."<br>\n";
236  print $langs->trans("GoIntoDictionaryHolidayTypes");
237  //print '</div>';
238 }
239 else
240 {
241  $canedit=0;
242  if (! empty($user->rights->holiday->define_holiday)) $canedit=1;
243 
244  $moreforfilter='';
245 
246  print '<div class="div-table-responsive">';
247  print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"").'" id="tablelines3">'."\n";
248 
249  print '<tr class="liste_titre_filter">';
250 
251  // User
252  print '<td class="liste_titre"><input type="text" name="search_name" value="'.dol_escape_htmltag($search_name).'"></td>';
253 
254  // Supervisor
255  print '<td class="liste_titre">';
256  print $form->select_dolusers($search_supervisor, 'search_supervisor', 1, null, 0, null, null, 0, 0, 0, '', 0, '', 'maxwidth200');
257  print '</td>';
258 
259  // Type of leave request
260  if (count($typeleaves))
261  {
262  foreach($typeleaves as $key => $val)
263  {
264  print '<td class="liste_titre" style="text-align:center"></td>';
265  }
266  }
267  else
268  {
269  print '<td class="liste_titre"></td>';
270  }
271  print '<td class="liste_titre"></td>';
272 
273  // Action column
274  print '<td class="liste_titre" align="right">';
275  $searchpicto=$form->showFilterButtons();
276  print $searchpicto;
277  print '</td>';
278 
279  print '</tr>';
280 
281  print '<tr class="liste_titre">';
282  print_liste_field_titre('Employee', $_SERVER["PHP_SELF"]);
283  print_liste_field_titre('Supervisor', $_SERVER["PHP_SELF"]);
284  if (count($typeleaves))
285  {
286  foreach($typeleaves as $key => $val)
287  {
288  $labeltype = ($langs->trans($val['code'])!=$val['code']) ? $langs->trans($val['code']) : $langs->trans($val['label']);
289  print_liste_field_titre($labeltype, $_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 
359  // Button modify
360  print '<td>';
361  if (! empty($user->rights->holiday->define_holiday)) // Allowed to set the balance of any user
362  {
363  print '<input type="submit" name="update_cp['.$users['rowid'].']" value="'.dol_escape_htmltag($langs->trans("Update")).'" class="button"/>';
364  }
365  print '</td>'."\n";
366  print '</tr>';
367 
368  $i++;
369  }
370 
371  print '</table>';
372  print '</div>';
373 }
374 
375 print '</form>';
376 
377 // End of page
378 llxFooter();
379 $db->close();
Class of the module paid holiday.
llxFooter()
Empty footer.
Definition: wrapper.php:56
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
GETPOST($paramname, $check='none', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
print
Draft customers invoices.
Definition: index.php:91
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
Class to manage Dolibarr users.
Definition: user.class.php:41
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...
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.
llxHeader()
Empty header.
Definition: wrapper.php:44
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_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 &#39;...