dolibarr  13.0.2
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 <https://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/class/holiday.class.php';
32 
33 // Load translation files required by the page
34 $langs->loadlangs(array('users', 'other', 'holiday', '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', 'aZ09comma');
45 $sortorder = GETPOST('sortorder', 'aZ09comma');
46 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : 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->socid > 0) accessforbidden();
57 
58 // If the user does not have perm to read the page
59 if (empty($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 if (empty($conf->holiday->enabled))
69 {
70  llxHeader('', $langs->trans('CPTitreMenu'));
71  print '<div class="tabBar">';
72  print '<span style="color: #FF0000;">'.$langs->trans('NotActiveModCP').'</span>';
73  print '</div>';
74  llxFooter();
75  exit();
76 }
77 
78 
79 
80 /*
81  * Actions
82  */
83 
84 if (GETPOST('cancel', 'alpha')) { $action = 'list'; $massaction = ''; }
85 if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { $massaction = ''; }
86 
87 $parameters = array();
88 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
89 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
90 
91 if (empty($reshook))
92 {
93  // Selection of new fields
94  include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
95 
96  // Purge search criteria
97  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
98  {
99  $search_name = '';
100  $search_supervisor = '';
101  $toselect = '';
102  $search_array_options = array();
103  }
104 
105  // Mass actions
106  /*
107  $objectclass='Skeleton';
108  $objectlabel='Skeleton';
109  $permissiontoread = $user->rights->skeleton->read;
110  $permissiontodelete = $user->rights->skeleton->delete;
111  $uploaddir = $conf->skeleton->dir_output;
112  include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
113  */
114 
115  // Si il y a une action de mise à jour
116  if ($action == 'update' && isset($_POST['update_cp']))
117  {
118  $error = 0;
119 
120  $typeleaves = $holiday->getTypes(1, 1);
121 
122  $userID = array_keys($_POST['update_cp']);
123  $userID = $userID[0];
124 
125  foreach ($typeleaves as $key => $val)
126  {
127  $userValue = $_POST['nb_holiday_'.$val['rowid']];
128  $userValue = $userValue[$userID];
129 
130  if (!empty($userValue) || (string) $userValue == '0')
131  {
132  $userValue = price2num($userValue, 5);
133  } else {
134  $userValue = '';
135  }
136 
137  //If the user set a comment, we add it to the log comment
138  $comment = ((isset($_POST['note_holiday'][$userID]) && !empty($_POST['note_holiday'][$userID])) ? ' ('.$_POST['note_holiday'][$userID].')' : '');
139 
140  //print 'holiday: '.$val['rowid'].'-'.$userValue;
141  if ($userValue != '')
142  {
143  // We add the modification to the log (must be before update of sold because we read current value of sold)
144  $result = $holiday->addLogCP($user->id, $userID, $langs->transnoentitiesnoconv('ManualUpdate').$comment, $userValue, $val['rowid']);
145  if ($result < 0)
146  {
147  setEventMessages($holiday->error, $holiday->errors, 'errors');
148  $error++;
149  }
150 
151  // Update of the days of the employee
152  $result = $holiday->updateSoldeCP($userID, $userValue, $val['rowid']);
153  if ($result < 0)
154  {
155  setEventMessages($holiday->error, $holiday->errors, 'errors');
156  $error++;
157  }
158 
159  // If it first update of balance, we set date to avoid to have sold incremented by new month
160  /*
161  $now=dol_now();
162  $sql = "UPDATE ".MAIN_DB_PREFIX."holiday_config SET";
163  $sql.= " value = '".dol_print_date($now,'%Y%m%d%H%M%S')."'";
164  $sql.= " WHERE name = 'lastUpdate' and value IS NULL"; // Add value IS NULL to be sure to update only at init.
165  dol_syslog('define_holiday update lastUpdate entry', LOG_DEBUG);
166  $result = $db->query($sql);
167  */
168  }
169  }
170 
171  if (!$error) setEventMessages('UpdateConfCPOK', '', 'mesgs');
172  }
173 }
174 
175 
176 /*
177  * View
178  */
179 
180 $form = new Form($db);
181 $userstatic = new User($db);
182 
183 llxHeader('', $langs->trans('CPTitreMenu'));
184 
185 
186 $typeleaves = $holiday->getTypes(1, 1);
187 $result = $holiday->updateBalance(); // Create users into table holiday if they don't exists. TODO Remove this whif we use field into table user.
188 if ($result < 0) {
189  setEventMessages($holiday->error, $holiday->errors, 'errors');
190 }
191 
192 
193 print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
194 if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
195 print '<input type="hidden" name="token" value="'.newToken().'">';
196 print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
197 print '<input type="hidden" name="action" value="update">';
198 print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
199 print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
200 print '<input type="hidden" name="page" value="'.$page.'">';
201 print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
202 
203 print load_fiche_titre($langs->trans('MenuConfCP'), '', 'title_hrm.png');
204 
205 print '<div class="info">'.$langs->trans('LastUpdateCP').': '."\n";
206 $lastUpdate = $holiday->getConfCP('lastUpdate');
207 if ($lastUpdate) {
208  print '<strong>'.dol_print_date($db->jdate($lastUpdate), 'dayhour').'</strong>';
209  print '<br>'.$langs->trans("MonthOfLastMonthlyUpdate").': <strong>'.$langs->trans('Month'.substr($lastUpdate, 4, 2)).' '.substr($lastUpdate, 0, 4).'</strong>'."\n";
210 } else {
211  print $langs->trans('None');
212 }
213 print "</div><br>\n";
214 
215 
216 $filters = '';
217 
218 // Filter on array of ids of all childs
219 $userchilds = array();
220 if (empty($user->rights->holiday->readall))
221 {
222  $userchilds = $user->getAllChildIds(1);
223  $filters .= ' AND u.rowid IN ('.join(', ', $userchilds).')';
224 }
225 if (!empty($search_name)) {
226  $filters .= natural_search(array('u.firstname', 'u.lastname'), $search_name);
227 }
228 if ($search_supervisor > 0) $filters .= natural_search(array('u.fk_user'), $search_supervisor, 2);
229 $filters .= ' AND employee = 1'; // Only employee users are visible
230 
231 $listUsers = $holiday->fetchUsers(false, true, $filters);
232 if (is_numeric($listUsers) && $listUsers < 0)
233 {
234  setEventMessages($holiday->error, $holiday->errors, 'errors');
235 }
236 
237 $i = 0;
238 
239 
240 if (count($typeleaves) == 0)
241 {
242  //print '<div class="info">';
243  print $langs->trans("NoLeaveWithCounterDefined")."<br>\n";
244  print $langs->trans("GoIntoDictionaryHolidayTypes");
245  //print '</div>';
246 } else {
247  $canedit = 0;
248  if (!empty($user->rights->holiday->define_holiday)) $canedit = 1;
249 
250  $moreforfilter = '';
251 
252  print '<div class="div-table-responsive">';
253  print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'" id="tablelines3">'."\n";
254 
255  print '<tr class="liste_titre_filter">';
256 
257  // User
258  print '<td class="liste_titre"><input type="text" name="search_name" value="'.dol_escape_htmltag($search_name).'"></td>';
259 
260  // Supervisor
261  print '<td class="liste_titre">';
262  print $form->select_dolusers($search_supervisor, 'search_supervisor', 1, null, 0, null, null, 0, 0, 0, '', 0, '', 'maxwidth200');
263  print '</td>';
264 
265  // Type of leave request
266  if (count($typeleaves))
267  {
268  foreach ($typeleaves as $key => $val)
269  {
270  print '<td class="liste_titre" style="text-align:center"></td>';
271  }
272  } else {
273  print '<td class="liste_titre"></td>';
274  }
275  print '<td class="liste_titre"></td>';
276 
277  // Action column
278  print '<td class="liste_titre maxwidthsearch center">';
279  $searchpicto = $form->showFilterButtons();
280  print $searchpicto;
281  print '</td>';
282 
283  print '</tr>';
284 
285  print '<tr class="liste_titre">';
286  print_liste_field_titre('Employee', $_SERVER["PHP_SELF"]);
287  print_liste_field_titre('Supervisor', $_SERVER["PHP_SELF"]);
288  if (count($typeleaves))
289  {
290  foreach ($typeleaves as $key => $val)
291  {
292  $labeltype = ($langs->trans($val['code']) != $val['code']) ? $langs->trans($val['code']) : $langs->trans($val['label']);
293  print_liste_field_titre($labeltype, $_SERVER["PHP_SELF"], '', '', '', '', '', '', 'center ');
294  }
295  } else {
296  print_liste_field_titre('NoLeaveWithCounterDefined', $_SERVER["PHP_SELF"], '', '', '', '');
297  }
298  print_liste_field_titre((empty($user->rights->holiday->define_holiday) ? '' : 'Note'), $_SERVER["PHP_SELF"]);
300  print '</tr>';
301 
302  $usersupervisor = new User($db);
303 
304  foreach ($listUsers as $users)
305  {
306  // If user has not permission to edit/read all, we must see only subordinates
307  if (empty($user->rights->holiday->readall))
308  {
309  if (($users['rowid'] != $user->id) && (!in_array($users['rowid'], $userchilds))) continue; // This user is not into hierarchy of current user, we hide it.
310  }
311 
312  $userstatic->id = $users['rowid'];
313  $userstatic->lastname = $users['lastname'];
314  $userstatic->firstname = $users['firstname'];
315  $userstatic->gender = $users['gender'];
316  $userstatic->photo = $users['photo'];
317  $userstatic->statut = $users['status'];
318  $userstatic->employee = $users['employee'];
319  $userstatic->fk_user = $users['fk_user'];
320 
321  if ($userstatic->fk_user > 0) $usersupervisor->fetch($userstatic->fk_user);
322 
323  print '<tr class="oddeven">';
324 
325  // User
326  print '<td>';
327  print $userstatic->getNomUrl(-1);
328  print '</td>';
329 
330  // Supervisor
331  print '<td>';
332  if ($userstatic->fk_user > 0) print $usersupervisor->getNomUrl(-1);
333  print '</td>';
334 
335  // Amount for each type
336  if (count($typeleaves))
337  {
338  foreach ($typeleaves as $key => $val)
339  {
340  $nbtoshow = '';
341  if ($holiday->getCPforUser($users['rowid'], $val['rowid']) != '') $nbtoshow = price2num($holiday->getCPforUser($users['rowid'], $val['rowid']), 5);
342 
343  //var_dump($users['rowid'].' - '.$val['rowid']);
344  print '<td style="text-align:center">';
345  if ($canedit) print '<input type="text"'.($canedit ? '' : ' disabled="disabled"').' value="'.$nbtoshow.'" name="nb_holiday_'.$val['rowid'].'['.$users['rowid'].']" size="5" style="text-align: center;"/>';
346  else print $nbtoshow;
347  //print ' '.$langs->trans('days');
348  print '</td>'."\n";
349  }
350  } else {
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("Save")).'" class="button smallpaddingimp"/>';
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();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Class of the module paid holiday.
Class to manage Dolibarr users.
Definition: user.class.php:44
llxHeader()
Empty header.
Definition: wrapper.php:45
Class to manage standard extra fields.
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
Class to manage generation of HTML components Only common components must be here.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname.
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
price2num($amount, $rounding= '', $option=0)
Function that return a number with universal decimal format (decimal separator is &#39;...
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 ...
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 $_SERVER["PHP_SELF"]
Edit parameters.
print
Draft customers invoices.
Definition: index.php:89
llxFooter()
Empty footer.
Definition: wrapper.php:59
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $keepmoretags= '', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields...