dolibarr  17.0.4
index.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2011 Dimitri Mouillard <dmouillard@teclib.com>
3  * Copyright (C) 2013-2015 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2012-2014 Regis Houssin <regis.houssin@inodbox.com>
5  * Copyright (C) 2015-2016 Alexandre Spangaro <aspangaro@open-dsi.fr>
6  * Copyright (C) 2019 Nicolas ZABOURI <info@inovea-conseil.com>
7  * Copyright (C) 2021 Frédéric France <frederic.france@netlogic.fr>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <https://www.gnu.org/licenses/>.
21  */
22 
30 // Load Dolibarr environment
31 require '../main.inc.php';
32 require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
33 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
34 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
35 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
36 require_once DOL_DOCUMENT_ROOT.'/core/lib/usergroups.lib.php';
37 require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
38 require_once DOL_DOCUMENT_ROOT.'/user/class/usergroup.class.php';
39 
40 if (isModEnabled('deplacement')) {
41  require_once DOL_DOCUMENT_ROOT.'/compta/deplacement/class/deplacement.class.php';
42 }
43 if (isModEnabled('expensereport')) {
44  require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php';
45 }
46 if (isModEnabled('recruitment')) {
47  require_once DOL_DOCUMENT_ROOT.'/recruitment/class/recruitmentcandidature.class.php';
48  require_once DOL_DOCUMENT_ROOT.'/recruitment/class/recruitmentjobposition.class.php';
49 }
50 if (isModEnabled('holiday')) {
51  require_once DOL_DOCUMENT_ROOT.'/holiday/class/holiday.class.php';
52 }
53 
54 
55 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
56 $hookmanager = new HookManager($db);
57 $hookmanager->initHooks('hrmindex');
58 
59 // Load translation files required by the page
60 $langs->loadLangs(array('users', 'holiday', 'trips', 'boxes'));
61 
62 // Get Parameters
63 $socid = GETPOST("socid", "int");
64 
65 // Protection if external user
66 if ($user->socid > 0) {
68 }
69 
70 if (empty($conf->global->MAIN_INFO_SOCIETE_NOM) || empty($conf->global->MAIN_INFO_SOCIETE_COUNTRY)) {
71  $setupcompanynotcomplete = 1;
72 }
73 
74 $max = $conf->global->MAIN_SIZE_SHORTLIST_LIMIT;
75 
76 
77 /*
78  * Actions
79  */
80 
81 // Update sold
82 if (isModEnabled('holiday') && !empty($setupcompanynotcomplete)) {
83  $holidaystatic = new Holiday($db);
84  $result = $holidaystatic->updateBalance();
85 }
86 
87 
88 /*
89  * View
90  */
91 
92 $childids = $user->getAllChildIds();
93 $childids[] = $user->id;
94 
95 $title = $langs->trans('HRMArea');
96 
97 llxHeader('', $title, '');
98 
99 print load_fiche_titre($langs->trans("HRMArea"), '', 'hrm');
100 
101 
102 if (!empty($setupcompanynotcomplete)) {
103  $langs->load("errors");
104  $warnpicto = img_warning($langs->trans("WarningMandatorySetupNotComplete"));
105  print '<br><div class="warning"><a href="'.DOL_URL_ROOT.'/admin/company.php?mainmenu=home'.(empty($setupcompanynotcomplete) ? '' : '&action=edit&token='.newToken()).'">'.$warnpicto.' '.$langs->trans("WarningMandatorySetupNotComplete").'</a></div>';
106 
107  llxFooter();
108  exit;
109 }
110 
111 
112 print '<div class="fichecenter"><div class="fichethirdleft">';
113 
114 if (!empty($conf->global->MAIN_SEARCH_FORM_ON_HOME_AREAS)) { // This is useless due to the global search combo
115  if (isModEnabled('holiday') && $user->rights->holiday->read) {
116  $langs->load("holiday");
117  $listofsearchfields['search_holiday'] = array('text'=>'TitreRequestCP');
118  }
119  if (isModEnabled('deplacement') && $user->rights->deplacement->lire) {
120  $langs->load("trips");
121  $listofsearchfields['search_deplacement'] = array('text'=>'ExpenseReport');
122  }
123  if (isModEnabled('expensereport') && $user->rights->expensereport->lire) {
124  $langs->load("trips");
125  $listofsearchfields['search_expensereport'] = array('text'=>'ExpenseReport');
126  }
127  if (count($listofsearchfields)) {
128  print '<form method="post" action="'.DOL_URL_ROOT.'/core/search.php">';
129  print '<input type="hidden" name="token" value="'.newToken().'">';
130  print '<div class="div-table-responsive-no-min">';
131  print '<table class="noborder nohover centpercent">';
132  $i = 0;
133  foreach ($listofsearchfields as $key => $value) {
134  if ($i == 0) {
135  print '<tr class="liste_titre"><td colspan="3">'.$langs->trans("Search").'</td></tr>';
136  }
137  print '<tr '.$bc[false].'>';
138  print '<td class="nowrap"><label for="'.$key.'">'.$langs->trans($value["text"]).'</label></td><td><input type="text" class="flat inputsearch" name="'.$key.'" id="'.$key.'" size="18"></td>';
139  if ($i == 0) {
140  print '<td rowspan="'.count($listofsearchfields).'"><input type="submit" value="'.$langs->trans("Search").'" class="button"></td>';
141  }
142  print '</tr>';
143  $i++;
144  }
145  print '</table>';
146  print '</div>';
147  print '</form>';
148  print '<br>';
149  }
150 }
151 
152 
153 if (isModEnabled('holiday')) {
154  if (empty($conf->global->HOLIDAY_HIDE_BALANCE)) {
155  $holidaystatic = new Holiday($db);
156  $user_id = $user->id;
157 
158  print '<div class="div-table-responsive-no-min">';
159  print '<table class="noborder nohover centpercent">';
160  print '<tr class="liste_titre"><th colspan="3">'.$langs->trans("Holidays").'</th></tr>';
161  print '<tr class="oddeven">';
162  print '<td>';
163 
164  $out = '';
165  $nb_holiday = 0;
166  $typeleaves = $holidaystatic->getTypes(1, 1);
167  foreach ($typeleaves as $key => $val) {
168  $nb_type = $holidaystatic->getCPforUser($user->id, $val['rowid']);
169  $nb_holiday += $nb_type;
170  $out .= ' - '.($langs->trans($val['code']) != $val['code'] ? $langs->trans($val['code']) : $val['label']).': <strong>'.($nb_type ? price2num($nb_type) : 0).'</strong><br>';
171  }
172  $balancetoshow = $langs->trans('SoldeCPUser', '{s1}');
173  print '<div class="valignmiddle div-balanceofleave">'.str_replace('{s1}', img_picto('', 'holiday', 'class="paddingleft pictofixedwidth"').'<span class="balanceofleave valignmiddle'.($nb_holiday > 0 ? ' amountpaymentcomplete' : ($nb_holiday < 0 ? ' amountremaintopay' : ' amountpaymentneutral')).'">'.round($nb_holiday, 5).'</span>', $balancetoshow).'</div>';
174  print '<span class="opacitymedium">'.$out.'</span>';
175 
176  print '</td>';
177  print '</tr>';
178  print '</table></div><br>';
179  } elseif (!is_numeric($conf->global->HOLIDAY_HIDE_BALANCE)) {
180  print $langs->trans($conf->global->HOLIDAY_HIDE_BALANCE).'<br>';
181  }
182 }
183 
184 
185 print '</div><div class="fichetwothirdright">';
186 
187 
188 
189 // Latest leave requests
190 if (isModEnabled('holiday') && $user->hasRight('holiday', 'read')) {
191  $sql = "SELECT u.rowid as uid, u.lastname, u.firstname, u.login, u.email, u.photo, u.statut as user_status,";
192  $sql .= " x.rowid, x.ref, x.fk_type, x.date_debut as date_start, x.date_fin as date_end, x.halfday, x.tms as dm, x.statut as status";
193  $sql .= " FROM ".MAIN_DB_PREFIX."holiday as x, ".MAIN_DB_PREFIX."user as u";
194  $sql .= " WHERE u.rowid = x.fk_user";
195  $sql .= " AND x.entity = ".$conf->entity;
196  if (empty($user->rights->holiday->readall)) {
197  $sql .= ' AND x.fk_user IN ('.$db->sanitize(join(',', $childids)).')';
198  }
199  //if (empty($user->rights->societe->client->voir) && !$user->socid) $sql.= " AND x.fk_soc = s. rowid AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
200  //if (!empty($socid)) $sql.= " AND x.fk_soc = ".((int) $socid);
201  $sql .= $db->order("x.tms", "DESC");
202  $sql .= $db->plimit($max, 0);
203 
204  $result = $db->query($sql);
205  if ($result) {
206  $var = false;
207  $num = $db->num_rows($result);
208 
209  $holidaystatic = new Holiday($db);
210  $userstatic = new User($db);
211 
212  $listhalfday = array('morning'=>$langs->trans("Morning"), "afternoon"=>$langs->trans("Afternoon"));
213  $typeleaves = $holidaystatic->getTypes(1, -1);
214 
215  $i = 0;
216 
217  print '<div class="div-table-responsive-no-min">';
218  print '<table class="noborder centpercent">';
219  print '<tr class="liste_titre">';
220  print '<th colspan="3">'.$langs->trans("BoxTitleLastLeaveRequests", min($max, $num)).'</th>';
221  print '<th>'.$langs->trans("from").'</th>';
222  print '<th>'.$langs->trans("to").'</th>';
223  print '<th class="right" colspan="2"><a href="'.DOL_URL_ROOT.'/holiday/list.php?sortfield=cp.tms&sortorder=DESC">'.$langs->trans("FullList").'</th>';
224  print '</tr>';
225  if ($num) {
226  while ($i < $num && $i < $max) {
227  $obj = $db->fetch_object($result);
228 
229  $holidaystatic->id = $obj->rowid;
230  $holidaystatic->ref = $obj->ref;
231  $holidaystatic->statut = $obj->status;
232  $holidaystatic->date_debut = $db->jdate($obj->date_start);
233 
234  $userstatic->id = $obj->uid;
235  $userstatic->lastname = $obj->lastname;
236  $userstatic->firstname = $obj->firstname;
237  $userstatic->login = $obj->login;
238  $userstatic->photo = $obj->photo;
239  $userstatic->email = $obj->email;
240  $userstatic->statut = $obj->user_status;
241 
242  print '<tr class="oddeven">';
243  print '<td class="nowraponall">'.$holidaystatic->getNomUrl(1).'</td>';
244  print '<td class="tdoverflowmax100">'.$userstatic->getNomUrl(-1, 'leave').'</td>';
245 
246  $leavecode = empty($typeleaves[$obj->fk_type]) ? 'Undefined' : $typeleaves[$obj->fk_type]['code'];
247  print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($langs->trans($leavecode)).'">'.dol_escape_htmltag($langs->trans($leavecode)).'</td>';
248 
249  $starthalfday = ($obj->halfday == -1 || $obj->halfday == 2) ? 'afternoon' : 'morning';
250  $endhalfday = ($obj->halfday == 1 || $obj->halfday == 2) ? 'morning' : 'afternoon';
251 
252  print '<td>'.dol_print_date($db->jdate($obj->date_start), 'day').' <span class="opacitymedium">'.$langs->trans($listhalfday[$starthalfday]).'</span>';
253  print '<td>'.dol_print_date($db->jdate($obj->date_end), 'day').' <span class="opacitymedium">'.$langs->trans($listhalfday[$endhalfday]).'</span>';
254  print '<td class="right">'.dol_print_date($db->jdate($obj->dm), 'day').'</td>';
255  print '<td class="right nowrap" width="16">'.$holidaystatic->LibStatut($obj->status, 3, $holidaystatic->date_debut).'</td>';
256  print '</tr>';
257 
258  $i++;
259  }
260  } else {
261  print '<tr class="oddeven"><td colspan="7" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
262  }
263  print '</table>';
264  print '</div>';
265  print '<br>';
266  } else {
267  dol_print_error($db);
268  }
269 }
270 
271 
272 // Latest expense report
273 if (isModEnabled('expensereport') && $user->hasRight('expensereport', 'read')) {
274  $sql = "SELECT u.rowid as uid, u.lastname, u.firstname, u.login, u.email, u.statut as user_status, u.photo,";
275  $sql .= " x.rowid, x.ref, x.date_debut as date, x.tms as dm, x.total_ttc, x.fk_statut as status";
276  $sql .= " FROM ".MAIN_DB_PREFIX."expensereport as x, ".MAIN_DB_PREFIX."user as u";
277  //if (empty($user->rights->societe->client->voir) && !$user->socid) $sql.= ", ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."societe_commerciaux as sc";
278  $sql .= " WHERE u.rowid = x.fk_user_author";
279  $sql .= " AND x.entity = ".$conf->entity;
280  if (empty($user->rights->expensereport->readall) && empty($user->rights->expensereport->lire_tous)) {
281  $sql .= ' AND x.fk_user_author IN ('.$db->sanitize(join(',', $childids)).')';
282  }
283  //if (empty($user->rights->societe->client->voir) && !$user->socid) $sql.= " AND x.fk_soc = s. rowid AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
284  //if (!empty($socid)) $sql.= " AND x.fk_soc = ".((int) $socid);
285  $sql .= $db->order("x.tms", "DESC");
286  $sql .= $db->plimit($max, 0);
287 
288  $result = $db->query($sql);
289  if ($result) {
290  $num = $db->num_rows($result);
291 
292  $i = 0;
293 
294  print '<div class="div-table-responsive-no-min">';
295  print '<table class="noborder centpercent">';
296  print '<tr class="liste_titre">';
297  print '<th colspan="2">'.$langs->trans("BoxTitleLastModifiedExpenses", min($max, $num)).'</th>';
298  print '<th class="right">'.$langs->trans("TotalTTC").'</th>';
299  print '<th class="right" colspan="2"><a href="'.DOL_URL_ROOT.'/expensereport/list.php?sortfield=d.tms&sortorder=DESC">'.$langs->trans("FullList").'</th>';
300  print '</tr>';
301  if ($num) {
302  $total_ttc = $totalam = $total = 0;
303 
304  $expensereportstatic = new ExpenseReport($db);
305  $userstatic = new User($db);
306  while ($i < $num && $i < $max) {
307  $obj = $db->fetch_object($result);
308 
309  $expensereportstatic->id = $obj->rowid;
310  $expensereportstatic->ref = $obj->ref;
311  $expensereportstatic->statut = $obj->status;
312  $expensereportstatic->status = $obj->status;
313 
314  $userstatic->id = $obj->uid;
315  $userstatic->lastname = $obj->lastname;
316  $userstatic->firstname = $obj->firstname;
317  $userstatic->email = $obj->email;
318  $userstatic->login = $obj->login;
319  $userstatic->statut = $obj->user_status;
320  $userstatic->photo = $obj->photo;
321 
322  print '<tr class="oddeven">';
323  print '<td class="tdoverflowmax200">'.$expensereportstatic->getNomUrl(1).'</td>';
324  print '<td class="tdoverflowmax150">'.$userstatic->getNomUrl(-1).'</td>';
325  print '<td class="right amount">'.price($obj->total_ttc).'</td>';
326  print '<td class="right">'.dol_print_date($db->jdate($obj->dm), 'day').'</td>';
327  print '<td class="right nowraponall" width="16">'.$expensereportstatic->LibStatut($obj->status, 3).'</td>';
328  print '</tr>';
329 
330  $i++;
331  }
332  } else {
333  print '<tr class="oddeven"><td colspan="5" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
334  }
335  print '</table>';
336  print '</div>';
337  print '<br>';
338  } else {
339  dol_print_error($db);
340  }
341 }
342 
343 
344 // Last modified job position
345 if (isModEnabled('recruitment') && $user->hasRight('recruitment', 'recruitmentjobposition', 'read')) {
346  $staticrecruitmentcandidature = new RecruitmentCandidature($db);
347  $staticrecruitmentjobposition = new RecruitmentJobPosition($db);
348  $sql = "SELECT rc.rowid, rc.ref, rc.email, rc.lastname, rc.firstname, rc.date_creation, rc.tms, rc.status,";
349  $sql.= " rp.rowid as jobid, rp.ref as jobref, rp.label";
350  $sql .= " FROM ".MAIN_DB_PREFIX."recruitment_recruitmentcandidature as rc";
351  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."recruitment_recruitmentjobposition as rp ON rc.fk_recruitmentjobposition = rp.rowid";
352  if (isModEnabled('societe') && empty($user->rights->societe->client->voir) && !$socid) {
353  $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
354  }
355  $sql .= " WHERE rc.entity IN (".getEntity($staticrecruitmentcandidature->element).")";
356  if (isModEnabled('societe') && empty($user->rights->societe->client->voir) && !$socid) {
357  $sql .= " AND rp.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
358  }
359  if ($socid) {
360  $sql .= " AND rp.fk_soc = $socid";
361  }
362  $sql .= $db->order("rc.tms", "DESC");
363  $sql .= $db->plimit($max, 0);
364 
365  $resql = $db->query($sql);
366  if ($resql) {
367  $num = $db->num_rows($resql);
368  $i = 0;
369 
370  print '<div class="div-table-responsive-no-min">';
371  print '<table class="noborder centpercent">';
372  print '<tr class="liste_titre">';
373  print '<th colspan="3">';
374  print $langs->trans("BoxTitleLatestModifiedCandidatures", min($max, $num));
375  print '</th>';
376  print '<th class="right" colspan="2"><a href="'.DOL_URL_ROOT.'/recruitment/recruitmentcandidature_list.php?sortfield=t.tms&sortorder=DESC">'.$langs->trans("FullList").'</th>';
377  print '</tr>';
378  if ($num) {
379  while ($i < $num) {
380  $objp = $db->fetch_object($resql);
381  $staticrecruitmentcandidature->id = $objp->rowid;
382  $staticrecruitmentcandidature->ref = $objp->ref;
383  $staticrecruitmentcandidature->email = $objp->email;
384  $staticrecruitmentcandidature->status = $objp->status;
385  $staticrecruitmentcandidature->date_creation = $objp->date_creation;
386  $staticrecruitmentcandidature->firstname = $objp->firstname;
387  $staticrecruitmentcandidature->lastname = $objp->lastname;
388 
389  $staticrecruitmentjobposition->id = $objp->jobid;
390  $staticrecruitmentjobposition->ref = $objp->jobref;
391  $staticrecruitmentjobposition->label = $objp->label;
392 
393  print '<tr class="oddeven">';
394  print '<td class="nowraponall">'.$staticrecruitmentcandidature->getNomUrl(1, '').'</td>';
395  print '<td class="tdoverflowmax150">'.$staticrecruitmentcandidature->getFullName($langs).'</td>';
396  print '<td class="nowraponall">'.$staticrecruitmentjobposition->getNomUrl(1).'</td>';
397  print '<td class="right nowrap">'.dol_print_date($db->jdate($objp->tms), 'day').'</td>';
398  print '<td class="right nowrap" width="16">';
399  print $staticrecruitmentcandidature->getLibStatut(3);
400  print "</td>";
401  print '</tr>';
402  $i++;
403  }
404 
405  $db->free($resql);
406  } else {
407  print '<tr class="oddeven"><td colspan="4" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
408  }
409  print "</table>";
410  print "</div>";
411  print "<br>";
412  } else {
413  dol_print_error($db);
414  }
415 }
416 
417 print '</div></div>';
418 
419 // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array
420 $parameters = array('user' => $user);
421 $reshook = $hookmanager->executeHooks('dashboardHRM', $parameters, $object); // Note that $action and $object may have been modified by hook
422 
423 // End of page
424 llxFooter();
425 $db->close();
Class to manage Trips and Expenses.
Class of the module paid holiday.
Class to manage hooks.
Class for RecruitmentCandidature.
Class for RecruitmentJobPosition.
Class to manage Dolibarr users.
Definition: user.class.php:47
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:745
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
isModEnabled($module)
Is Dolibarr module enabled.
llxFooter()
Footer empty.
Definition: index.php:71
if(!defined('NOTOKENRENEWAL')) if(!defined('NOLOGIN')) if(!defined('NOCSRFCHECK')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) if(!defined('NOIPCHECK')) if(!defined('NOBROWSERNOTIF')) llxHeader()
Header empty.
Definition: index.php:63
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.