dolibarr  19.0.0-dev
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 
58 $hookmanager->initHooks('hrmindex');
59 
60 // Load translation files required by the page
61 $langs->loadLangs(array('users', 'holiday', 'trips', 'boxes'));
62 
63 // Get Parameters
64 $socid = GETPOST("socid", "int");
65 
66 // Protection if external user
67 if ($user->socid > 0) {
69 }
70 
71 if (empty($conf->global->MAIN_INFO_SOCIETE_NOM) || empty($conf->global->MAIN_INFO_SOCIETE_COUNTRY)) {
72  $setupcompanynotcomplete = 1;
73 }
74 
75 $max = $conf->global->MAIN_SIZE_SHORTLIST_LIMIT;
76 
77 
78 /*
79  * Actions
80  */
81 
82 // Update sold
83 if (isModEnabled('holiday') && !empty($setupcompanynotcomplete)) {
84  $holidaystatic = new Holiday($db);
85  $result = $holidaystatic->updateBalance();
86 }
87 
88 
89 /*
90  * View
91  */
92 
93 $childids = $user->getAllChildIds();
94 $childids[] = $user->id;
95 
96 $title = $langs->trans('HRMArea');
97 
98 llxHeader('', $title, '');
99 
100 print load_fiche_titre($langs->trans("HRMArea"), '', 'hrm');
101 
102 
103 if (!empty($setupcompanynotcomplete)) {
104  $langs->load("errors");
105  $warnpicto = img_warning($langs->trans("WarningMandatorySetupNotComplete"));
106  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>';
107 
108  llxFooter();
109  exit;
110 }
111 
112 
113 print '<div class="fichecenter"><div class="fichethirdleft">';
114 
115 if (!empty($conf->global->MAIN_SEARCH_FORM_ON_HOME_AREAS)) { // This is useless due to the global search combo
116  if (isModEnabled('holiday') && $user->rights->holiday->read) {
117  $langs->load("holiday");
118  $listofsearchfields['search_holiday'] = array('text'=>'TitreRequestCP');
119  }
120  if (isModEnabled('deplacement') && $user->rights->deplacement->lire) {
121  $langs->load("trips");
122  $listofsearchfields['search_deplacement'] = array('text'=>'ExpenseReport');
123  }
124  if (isModEnabled('expensereport') && $user->rights->expensereport->lire) {
125  $langs->load("trips");
126  $listofsearchfields['search_expensereport'] = array('text'=>'ExpenseReport');
127  }
128  if (count($listofsearchfields)) {
129  print '<form method="post" action="'.DOL_URL_ROOT.'/core/search.php">';
130  print '<input type="hidden" name="token" value="'.newToken().'">';
131  print '<div class="div-table-responsive-no-min">';
132  print '<table class="noborder nohover centpercent">';
133  $i = 0;
134  foreach ($listofsearchfields as $key => $value) {
135  if ($i == 0) {
136  print '<tr class="liste_titre"><td colspan="3">'.$langs->trans("Search").'</td></tr>';
137  }
138  print '<tr>';
139  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>';
140  if ($i == 0) {
141  print '<td rowspan="'.count($listofsearchfields).'"><input type="submit" value="'.$langs->trans("Search").'" class="button"></td>';
142  }
143  print '</tr>';
144  $i++;
145  }
146  print '</table>';
147  print '</div>';
148  print '</form>';
149  print '<br>';
150  }
151 }
152 
153 
154 if (isModEnabled('holiday')) {
155  if (empty($conf->global->HOLIDAY_HIDE_BALANCE)) {
156  $holidaystatic = new Holiday($db);
157  $user_id = $user->id;
158 
159  print '<div class="div-table-responsive-no-min">';
160  print '<table class="noborder nohover centpercent">';
161  print '<tr class="liste_titre"><th colspan="3">'.$langs->trans("Holidays").'</th></tr>';
162  print '<tr class="oddeven">';
163  print '<td>';
164 
165  $out = '';
166  $nb_holiday = 0;
167  $typeleaves = $holidaystatic->getTypes(1, 1);
168  foreach ($typeleaves as $key => $val) {
169  $nb_type = $holidaystatic->getCPforUser($user->id, $val['rowid']);
170  $nb_holiday += $nb_type;
171  $out .= ' - '.($langs->trans($val['code']) != $val['code'] ? $langs->trans($val['code']) : $val['label']).': <strong>'.($nb_type ? price2num($nb_type) : 0).'</strong><br>';
172  }
173  $balancetoshow = $langs->trans('SoldeCPUser', '{s1}');
174  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>';
175  print '<span class="opacitymedium">'.$out.'</span>';
176 
177  print '</td>';
178  print '</tr>';
179  print '</table></div><br>';
180  } elseif (!is_numeric($conf->global->HOLIDAY_HIDE_BALANCE)) {
181  print $langs->trans($conf->global->HOLIDAY_HIDE_BALANCE).'<br>';
182  }
183 }
184 
185 
186 print '</div><div class="fichetwothirdright">';
187 
188 
189 
190 // Latest leave requests
191 if (isModEnabled('holiday') && $user->hasRight('holiday', 'read')) {
192  $sql = "SELECT u.rowid as uid, u.lastname, u.firstname, u.login, u.email, u.photo, u.statut as user_status,";
193  $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";
194  $sql .= " FROM ".MAIN_DB_PREFIX."holiday as x, ".MAIN_DB_PREFIX."user as u";
195  $sql .= " WHERE u.rowid = x.fk_user";
196  $sql .= " AND x.entity = ".$conf->entity;
197  if (empty($user->rights->holiday->readall)) {
198  $sql .= ' AND x.fk_user IN ('.$db->sanitize(join(',', $childids)).')';
199  }
200  //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);
201  //if (!empty($socid)) $sql.= " AND x.fk_soc = ".((int) $socid);
202  $sql .= $db->order("x.tms", "DESC");
203  $sql .= $db->plimit($max, 0);
204 
205  $result = $db->query($sql);
206  if ($result) {
207  $var = false;
208  $num = $db->num_rows($result);
209 
210  $holidaystatic = new Holiday($db);
211  $userstatic = new User($db);
212 
213  $listhalfday = array('morning'=>$langs->trans("Morning"), "afternoon"=>$langs->trans("Afternoon"));
214  $typeleaves = $holidaystatic->getTypes(1, -1);
215 
216  $i = 0;
217 
218  print '<div class="div-table-responsive-no-min">';
219  print '<table class="noborder centpercent">';
220  print '<tr class="liste_titre">';
221  print '<th colspan="3">'.$langs->trans("BoxTitleLastLeaveRequests", min($max, $num)).'</th>';
222  print '<th>'.$langs->trans("from").'</th>';
223  print '<th>'.$langs->trans("to").'</th>';
224  print '<th class="right" colspan="2"><a href="'.DOL_URL_ROOT.'/holiday/list.php?sortfield=cp.tms&sortorder=DESC">'.$langs->trans("FullList").'</th>';
225  print '</tr>';
226  if ($num) {
227  while ($i < $num && $i < $max) {
228  $obj = $db->fetch_object($result);
229 
230  $holidaystatic->id = $obj->rowid;
231  $holidaystatic->ref = $obj->ref;
232  $holidaystatic->statut = $obj->status;
233  $holidaystatic->date_debut = $db->jdate($obj->date_start);
234 
235  $userstatic->id = $obj->uid;
236  $userstatic->lastname = $obj->lastname;
237  $userstatic->firstname = $obj->firstname;
238  $userstatic->login = $obj->login;
239  $userstatic->photo = $obj->photo;
240  $userstatic->email = $obj->email;
241  $userstatic->statut = $obj->user_status;
242 
243  print '<tr class="oddeven">';
244  print '<td class="nowraponall">'.$holidaystatic->getNomUrl(1).'</td>';
245  print '<td class="tdoverflowmax100">'.$userstatic->getNomUrl(-1, 'leave').'</td>';
246 
247  $leavecode = empty($typeleaves[$obj->fk_type]) ? 'Undefined' : $typeleaves[$obj->fk_type]['code'];
248  print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($langs->trans($leavecode)).'">'.dol_escape_htmltag($langs->trans($leavecode)).'</td>';
249 
250  $starthalfday = ($obj->halfday == -1 || $obj->halfday == 2) ? 'afternoon' : 'morning';
251  $endhalfday = ($obj->halfday == 1 || $obj->halfday == 2) ? 'morning' : 'afternoon';
252 
253  print '<td>'.dol_print_date($db->jdate($obj->date_start), 'day').' <span class="opacitymedium">'.$langs->trans($listhalfday[$starthalfday]).'</span>';
254  print '<td>'.dol_print_date($db->jdate($obj->date_end), 'day').' <span class="opacitymedium">'.$langs->trans($listhalfday[$endhalfday]).'</span>';
255  print '<td class="right">'.dol_print_date($db->jdate($obj->dm), 'day').'</td>';
256  print '<td class="right nowrap" width="16">'.$holidaystatic->LibStatut($obj->status, 3, $holidaystatic->date_debut).'</td>';
257  print '</tr>';
258 
259  $i++;
260  }
261  } else {
262  print '<tr class="oddeven"><td colspan="7" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
263  }
264  print '</table>';
265  print '</div>';
266  print '<br>';
267  } else {
268  dol_print_error($db);
269  }
270 }
271 
272 
273 // Latest expense report
274 if (isModEnabled('expensereport') && $user->hasRight('expensereport', 'read')) {
275  $sql = "SELECT u.rowid as uid, u.lastname, u.firstname, u.login, u.email, u.statut as user_status, u.photo,";
276  $sql .= " x.rowid, x.ref, x.date_debut as date, x.tms as dm, x.total_ttc, x.fk_statut as status";
277  $sql .= " FROM ".MAIN_DB_PREFIX."expensereport as x, ".MAIN_DB_PREFIX."user as u";
278  //if (empty($user->rights->societe->client->voir) && !$user->socid) $sql.= ", ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."societe_commerciaux as sc";
279  $sql .= " WHERE u.rowid = x.fk_user_author";
280  $sql .= " AND x.entity = ".$conf->entity;
281  if (empty($user->rights->expensereport->readall) && empty($user->rights->expensereport->lire_tous)) {
282  $sql .= ' AND x.fk_user_author IN ('.$db->sanitize(join(',', $childids)).')';
283  }
284  //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);
285  //if (!empty($socid)) $sql.= " AND x.fk_soc = ".((int) $socid);
286  $sql .= $db->order("x.tms", "DESC");
287  $sql .= $db->plimit($max, 0);
288 
289  $result = $db->query($sql);
290  if ($result) {
291  $num = $db->num_rows($result);
292 
293  $i = 0;
294 
295  print '<div class="div-table-responsive-no-min">';
296  print '<table class="noborder centpercent">';
297  print '<tr class="liste_titre">';
298  print '<th colspan="2">'.$langs->trans("BoxTitleLastModifiedExpenses", min($max, $num)).'</th>';
299  print '<th class="right">'.$langs->trans("TotalTTC").'</th>';
300  print '<th class="right" colspan="2"><a href="'.DOL_URL_ROOT.'/expensereport/list.php?sortfield=d.tms&sortorder=DESC">'.$langs->trans("FullList").'</th>';
301  print '</tr>';
302  if ($num) {
303  $total_ttc = $totalam = $total = 0;
304 
305  $expensereportstatic = new ExpenseReport($db);
306  $userstatic = new User($db);
307  while ($i < $num && $i < $max) {
308  $obj = $db->fetch_object($result);
309 
310  $expensereportstatic->id = $obj->rowid;
311  $expensereportstatic->ref = $obj->ref;
312  $expensereportstatic->statut = $obj->status;
313  $expensereportstatic->status = $obj->status;
314 
315  $userstatic->id = $obj->uid;
316  $userstatic->lastname = $obj->lastname;
317  $userstatic->firstname = $obj->firstname;
318  $userstatic->email = $obj->email;
319  $userstatic->login = $obj->login;
320  $userstatic->statut = $obj->user_status;
321  $userstatic->photo = $obj->photo;
322 
323  print '<tr class="oddeven">';
324  print '<td class="tdoverflowmax200">'.$expensereportstatic->getNomUrl(1).'</td>';
325  print '<td class="tdoverflowmax150">'.$userstatic->getNomUrl(-1).'</td>';
326  print '<td class="right amount">'.price($obj->total_ttc).'</td>';
327  print '<td class="right">'.dol_print_date($db->jdate($obj->dm), 'day').'</td>';
328  print '<td class="right nowraponall" width="16">'.$expensereportstatic->LibStatut($obj->status, 3).'</td>';
329  print '</tr>';
330 
331  $i++;
332  }
333  } else {
334  print '<tr class="oddeven"><td colspan="5" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
335  }
336  print '</table>';
337  print '</div>';
338  print '<br>';
339  } else {
340  dol_print_error($db);
341  }
342 }
343 
344 
345 // Last modified job position
346 if (isModEnabled('recruitment') && $user->hasRight('recruitment', 'recruitmentjobposition', 'read')) {
347  $staticrecruitmentcandidature = new RecruitmentCandidature($db);
348  $staticrecruitmentjobposition = new RecruitmentJobPosition($db);
349  $sql = "SELECT rc.rowid, rc.ref, rc.email, rc.lastname, rc.firstname, rc.date_creation, rc.tms, rc.status,";
350  $sql.= " rp.rowid as jobid, rp.ref as jobref, rp.label";
351  $sql .= " FROM ".MAIN_DB_PREFIX."recruitment_recruitmentcandidature as rc";
352  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."recruitment_recruitmentjobposition as rp ON rc.fk_recruitmentjobposition = rp.rowid";
353  if (isModEnabled('societe') && empty($user->rights->societe->client->voir) && !$socid) {
354  $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
355  }
356  $sql .= " WHERE rc.entity IN (".getEntity($staticrecruitmentcandidature->element).")";
357  if (isModEnabled('societe') && empty($user->rights->societe->client->voir) && !$socid) {
358  $sql .= " AND rp.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
359  }
360  if ($socid) {
361  $sql .= " AND rp.fk_soc = $socid";
362  }
363  $sql .= $db->order("rc.tms", "DESC");
364  $sql .= $db->plimit($max, 0);
365 
366  $resql = $db->query($sql);
367  if ($resql) {
368  $num = $db->num_rows($resql);
369  $i = 0;
370 
371  print '<div class="div-table-responsive-no-min">';
372  print '<table class="noborder centpercent">';
373  print '<tr class="liste_titre">';
374  print '<th colspan="3">';
375  print $langs->trans("BoxTitleLatestModifiedCandidatures", min($max, $num));
376  print '</th>';
377  print '<th class="right" colspan="2"><a href="'.DOL_URL_ROOT.'/recruitment/recruitmentcandidature_list.php?sortfield=t.tms&sortorder=DESC">'.$langs->trans("FullList").'</th>';
378  print '</tr>';
379  if ($num) {
380  while ($i < $num) {
381  $objp = $db->fetch_object($resql);
382  $staticrecruitmentcandidature->id = $objp->rowid;
383  $staticrecruitmentcandidature->ref = $objp->ref;
384  $staticrecruitmentcandidature->email = $objp->email;
385  $staticrecruitmentcandidature->status = $objp->status;
386  $staticrecruitmentcandidature->date_creation = $objp->date_creation;
387  $staticrecruitmentcandidature->firstname = $objp->firstname;
388  $staticrecruitmentcandidature->lastname = $objp->lastname;
389 
390  $staticrecruitmentjobposition->id = $objp->jobid;
391  $staticrecruitmentjobposition->ref = $objp->jobref;
392  $staticrecruitmentjobposition->label = $objp->label;
393 
394  print '<tr class="oddeven">';
395  print '<td class="nowraponall">'.$staticrecruitmentcandidature->getNomUrl(1, '').'</td>';
396  print '<td class="tdoverflowmax150">'.$staticrecruitmentcandidature->getFullName($langs).'</td>';
397  print '<td class="nowraponall">'.$staticrecruitmentjobposition->getNomUrl(1).'</td>';
398  print '<td class="right nowrap">'.dol_print_date($db->jdate($objp->tms), 'day').'</td>';
399  print '<td class="right nowrap" width="16">';
400  print $staticrecruitmentcandidature->getLibStatut(3);
401  print "</td>";
402  print '</tr>';
403  $i++;
404  }
405 
406  $db->free($resql);
407  } else {
408  print '<tr class="oddeven"><td colspan="4" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
409  }
410  print "</table>";
411  print "</div>";
412  print "<br>";
413  } else {
414  dol_print_error($db);
415  }
416 }
417 
418 print '</div></div>';
419 
420 // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array
421 $parameters = array('user' => $user);
422 $reshook = $hookmanager->executeHooks('dashboardHRM', $parameters, $object); // Note that $action and $object may have been modified by hook
423 
424 // End of page
425 llxFooter();
426 $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:48
if(isModEnabled('facture') && $user->hasRight('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') && $user->hasRight('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)) $sql
Social contributions to pay.
Definition: index.php:746
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.
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.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
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.