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