dolibarr 20.0.0
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-2024 Frédéric France <frederic.france@free.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 = GETPOSTINT("socid");
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', 5);
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">';
116
117print '<div class="twocolumns">';
118
119print '<div class="firstcolumn fichehalfleft boxhalfleft" id="boxhalfleft">';
120
121
122if (getDolGlobalString('MAIN_SEARCH_FORM_ON_HOME_AREAS')) { // This is useless due to the global search combo
123 if (isModEnabled('holiday') && $user->hasRight('holiday', 'read')) {
124 $langs->load("holiday");
125 $listofsearchfields['search_holiday'] = array('text'=>'TitreRequestCP');
126 }
127 if (isModEnabled('deplacement') && $user->hasRight('deplacement', 'lire')) {
128 $langs->load("trips");
129 $listofsearchfields['search_deplacement'] = array('text'=>'ExpenseReport');
130 }
131 if (isModEnabled('expensereport') && $user->hasRight('expensereport', 'lire')) {
132 $langs->load("trips");
133 $listofsearchfields['search_expensereport'] = array('text'=>'ExpenseReport');
134 }
135 if (count($listofsearchfields)) {
136 print '<form method="post" action="'.DOL_URL_ROOT.'/core/search.php">';
137 print '<input type="hidden" name="token" value="'.newToken().'">';
138 print '<div class="div-table-responsive-no-min">';
139 print '<table class="noborder nohover centpercent">';
140 $i = 0;
141 foreach ($listofsearchfields as $key => $value) {
142 if ($i == 0) {
143 print '<tr class="liste_titre"><td colspan="3">'.$langs->trans("Search").'</td></tr>';
144 }
145 print '<tr>';
146 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>';
147 if ($i == 0) {
148 print '<td rowspan="'.count($listofsearchfields).'"><input type="submit" value="'.$langs->trans("Search").'" class="button"></td>';
149 }
150 print '</tr>';
151 $i++;
152 }
153 print '</table>';
154 print '</div>';
155 print '</form>';
156 print '<br>';
157 }
158}
159
160
161if (isModEnabled('holiday')) {
162 if (!getDolGlobalString('HOLIDAY_HIDE_BALANCE')) {
163 $holidaystatic = new Holiday($db);
164 $user_id = $user->id;
165
166 print '<div class="div-table-responsive-no-min">';
167 print '<table class="noborder nohover centpercent">';
168 print '<tr class="liste_titre"><th colspan="3">'.$langs->trans("Holidays").'</th></tr>';
169 print '<tr class="oddeven">';
170 print '<td>';
171
172 $out = '';
173 $nb_holiday = 0;
174 $typeleaves = $holidaystatic->getTypes(1, 1);
175 foreach ($typeleaves as $key => $val) {
176 $nb_type = $holidaystatic->getCPforUser($user->id, $val['rowid']);
177 $nb_holiday += $nb_type;
178 $out .= ' - '.($langs->trans($val['code']) != $val['code'] ? $langs->trans($val['code']) : $val['label']).': <strong>'.($nb_type ? price2num($nb_type) : 0).'</strong><br>';
179 }
180 $balancetoshow = $langs->trans('SoldeCPUser', '{s1}');
181 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>';
182 print '<span class="opacitymedium">'.$out.'</span>';
183
184 print '</td>';
185 print '</tr>';
186 print '</table></div><br>';
187 } elseif (!is_numeric(getDolGlobalString('HOLIDAY_HIDE_BALANCE'))) {
188 print $langs->trans(getDolGlobalString('HOLIDAY_HIDE_BALANCE')).'<br>';
189 }
190}
191
192
193print '</div><div class="secondcolumn fichehalfright boxhalfright" id="boxhalfright">';
194
195
196// Latest modified leave requests
197if (isModEnabled('holiday') && $user->hasRight('holiday', 'read')) {
198 $sql = "SELECT u.rowid as uid, u.lastname, u.firstname, u.login, u.email, u.photo, u.statut as user_status,";
199 $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";
200 $sql .= " FROM ".MAIN_DB_PREFIX."holiday as x, ".MAIN_DB_PREFIX."user as u";
201 $sql .= " WHERE u.rowid = x.fk_user";
202 $sql .= " AND x.entity = ".$conf->entity;
203 if (!$user->hasRight('holiday', 'readall')) {
204 $sql .= ' AND x.fk_user IN ('.$db->sanitize(implode(',', $childids)).')';
205 }
206 //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);
207 //if (!empty($socid)) $sql.= " AND x.fk_soc = ".((int) $socid);
208 $sql .= $db->order("x.tms", "DESC");
209 $sql .= $db->plimit($max, 0);
210
211 $result = $db->query($sql);
212 if ($result) {
213 $var = false;
214 $num = $db->num_rows($result);
215
216 $holidaystatic = new Holiday($db);
217 $userstatic = new User($db);
218
219 $listhalfday = array('morning'=>$langs->trans("Morning"), "afternoon"=>$langs->trans("Afternoon"));
220 $typeleaves = $holidaystatic->getTypes(1, -1);
221
222 $i = 0;
223
224 print '<div class="div-table-responsive-no-min">';
225 print '<table class="noborder centpercent">';
226 print '<tr class="liste_titre">';
227 print '<th colspan="3">'.$langs->trans("BoxTitleLastLeaveRequests", min($max, $num));
228 print '<a href="'.DOL_URL_ROOT.'/holiday/list.php?sortfield=cp.tms&sortorder=DESC" title="'.$langs->trans("FullList").'">';
229 print '<span class="badge marginleftonlyshort">...</span>';
230 print '</a>';
231 print '</th>';
232 print '<th></th>';
233 print '<th></th>';
234 print '<th></th>';
235 print '<th class="right">';
236 print '</th>';
237 print '</tr>';
238
239 if ($num) {
240 while ($i < $num && $i < $max) {
241 $obj = $db->fetch_object($result);
242
243 $holidaystatic->id = $obj->rowid;
244 $holidaystatic->ref = $obj->ref;
245 $holidaystatic->statut = $obj->status;
246 $holidaystatic->date_debut = $db->jdate($obj->date_start);
247
248 $userstatic->id = $obj->uid;
249 $userstatic->lastname = $obj->lastname;
250 $userstatic->firstname = $obj->firstname;
251 $userstatic->login = $obj->login;
252 $userstatic->photo = $obj->photo;
253 $userstatic->email = $obj->email;
254 $userstatic->statut = $obj->user_status;
255 $userstatic->status = $obj->user_status;
256
257 print '<tr class="oddeven">';
258 print '<td class="nowraponall">'.$holidaystatic->getNomUrl(1).'</td>';
259 print '<td class="tdoverflowmax100">'.$userstatic->getNomUrl(-1, 'leave').'</td>';
260
261 $leavecode = empty($typeleaves[$obj->fk_type]) ? 'Undefined' : $typeleaves[$obj->fk_type]['code'];
262 print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($langs->trans($leavecode)).'">'.dol_escape_htmltag($langs->trans($leavecode)).'</td>';
263
264 $starthalfday = ($obj->halfday == -1 || $obj->halfday == 2) ? 'afternoon' : 'morning';
265 $endhalfday = ($obj->halfday == 1 || $obj->halfday == 2) ? 'morning' : 'afternoon';
266
267 print '<td class="tdoverflowmax125">'.dol_print_date($db->jdate($obj->date_start), 'dayreduceformat').' <span class="opacitymedium">'.$langs->trans($listhalfday[$starthalfday]).'</span>';
268 print '<td class="tdoverflowmax125">'.dol_print_date($db->jdate($obj->date_end), 'dayreduceformat').' <span class="opacitymedium">'.$langs->trans($listhalfday[$endhalfday]).'</span>';
269 print '<td class="right">'.dol_print_date($db->jdate($obj->dm), 'dayreduceformat').'</td>';
270 print '<td class="right nowrap" width="16">'.$holidaystatic->LibStatut($obj->status, 3, $holidaystatic->date_debut).'</td>';
271 print '</tr>';
272
273 $i++;
274 }
275 } else {
276 print '<tr class="oddeven"><td colspan="7"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
277 }
278 print '</table>';
279 print '</div>';
280 print '<br>';
281 } else {
282 dol_print_error($db);
283 }
284}
285
286
287// Latest modified expense report
288if (isModEnabled('expensereport') && $user->hasRight('expensereport', 'read')) {
289 $sql = "SELECT u.rowid as uid, u.lastname, u.firstname, u.login, u.email, u.statut as user_status, u.photo,";
290 $sql .= " x.rowid, x.ref, x.date_debut as date, x.tms as dm, x.total_ht, x.total_ttc, x.fk_statut as status";
291 $sql .= " FROM ".MAIN_DB_PREFIX."expensereport as x, ".MAIN_DB_PREFIX."user as u";
292 //if (empty($user->rights->societe->client->voir) && !$user->socid) $sql.= ", ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."societe_commerciaux as sc";
293 $sql .= " WHERE u.rowid = x.fk_user_author";
294 $sql .= " AND x.entity = ".$conf->entity;
295 if (!$user->hasRight('expensereport', 'readall') && !$user->hasRight('expensereport', 'lire_tous')) {
296 $sql .= ' AND x.fk_user_author IN ('.$db->sanitize(implode(',', $childids)).')';
297 }
298 //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);
299 //if (!empty($socid)) $sql.= " AND x.fk_soc = ".((int) $socid);
300 $sql .= $db->order("x.tms", "DESC");
301 $sql .= $db->plimit($max, 0);
302
303 $result = $db->query($sql);
304 if ($result) {
305 $num = $db->num_rows($result);
306
307 $i = 0;
308
309 print '<div class="div-table-responsive-no-min">';
310 print '<table class="noborder centpercent">';
311 print '<tr class="liste_titre">';
312 print '<th colspan="2">'.$langs->trans("BoxTitleLastModifiedExpenses", min($max, $num));
313 print '<a href="'.DOL_URL_ROOT.'/expensereport/list.php?sortfield=d.tms&sortorder=DESC" title="'.$langs->trans("FullList").'">';
314 print '<span class="badge marginleftonlyshort">...</span>';
315 //print img_picto($langs->trans("FullList"), 'expensereport');
316 print '</a>';
317 print '</th>';
318 print '<th class="right">'.$langs->trans("AmountHT").'</th>';
319 print '<th class="right">'.$langs->trans("AmountTTC").'</th>';
320 print '<th></th>';
321 print '<th class="right">';
322 print '</th>';
323 print '</tr>';
324
325 if ($num) {
326 $expensereportstatic = new ExpenseReport($db);
327 $userstatic = new User($db);
328 while ($i < $num && $i < $max) {
329 $obj = $db->fetch_object($result);
330
331 $expensereportstatic->id = $obj->rowid;
332 $expensereportstatic->ref = $obj->ref;
333 $expensereportstatic->statut = $obj->status;
334 $expensereportstatic->status = $obj->status;
335
336 $userstatic->id = $obj->uid;
337 $userstatic->lastname = $obj->lastname;
338 $userstatic->firstname = $obj->firstname;
339 $userstatic->email = $obj->email;
340 $userstatic->login = $obj->login;
341 $userstatic->status = $obj->user_status;
342 $userstatic->photo = $obj->photo;
343
344 print '<tr class="oddeven">';
345 print '<td class="tdoverflowmax200">'.$expensereportstatic->getNomUrl(1).'</td>';
346 print '<td class="tdoverflowmax150">'.$userstatic->getNomUrl(-1).'</td>';
347 print '<td class="right amount">'.price($obj->total_ht).'</td>';
348 print '<td class="right amount">'.price($obj->total_ttc).'</td>';
349 print '<td class="right">'.dol_print_date($db->jdate($obj->dm), 'dayreduceformat').'</td>';
350 print '<td class="right nowraponall" width="16">'.$expensereportstatic->LibStatut($obj->status, 3).'</td>';
351 print '</tr>';
352
353 $i++;
354 }
355 } else {
356 print '<tr class="oddeven"><td colspan="5"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
357 }
358 print '</table>';
359 print '</div>';
360 print '<br>';
361 } else {
362 dol_print_error($db);
363 }
364}
365
366
367// Last modified job position
368if (isModEnabled('recruitment') && $user->hasRight('recruitment', 'recruitmentjobposition', 'read')) {
369 $staticrecruitmentcandidature = new RecruitmentCandidature($db);
370 $staticrecruitmentjobposition = new RecruitmentJobPosition($db);
371 $sql = "SELECT rc.rowid, rc.ref, rc.email, rc.lastname, rc.firstname, rc.date_creation, rc.tms, rc.status,";
372 $sql.= " rp.rowid as jobid, rp.ref as jobref, rp.label";
373 $sql .= " FROM ".MAIN_DB_PREFIX."recruitment_recruitmentcandidature as rc";
374 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."recruitment_recruitmentjobposition as rp ON rc.fk_recruitmentjobposition = rp.rowid";
375 if (isModEnabled('societe') && !$user->hasRight('societe', 'client', 'voir') && !$socid) {
376 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
377 }
378 $sql .= " WHERE rc.entity IN (".getEntity($staticrecruitmentcandidature->element).")";
379 if (isModEnabled('societe') && !$user->hasRight('societe', 'client', 'voir') && !$socid) {
380 $sql .= " AND rp.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
381 }
382 if ($socid) {
383 $sql .= " AND rp.fk_soc = $socid";
384 }
385 $sql .= $db->order("rc.tms", "DESC");
386 $sql .= $db->plimit($max, 0);
387
388 $resql = $db->query($sql);
389 if ($resql) {
390 $num = $db->num_rows($resql);
391 $i = 0;
392
393 print '<div class="div-table-responsive-no-min">';
394 print '<table class="noborder centpercent">';
395 print '<tr class="liste_titre">';
396 print '<th colspan="3">';
397 print $langs->trans("BoxTitleLatestModifiedCandidatures", min($max, $num));
398 print '<a href="'.DOL_URL_ROOT.'/recruitment/recruitmentcandidature_list.php?sortfield=t.tms&sortorder=DESC" title="'.$langs->trans("FullList").'">';
399 print '<span class="badge marginleftonlyshort">...</span>';
400 //print img_picto($langs->trans("FullList"), 'recruitmentcandidature');
401 print '</a>';
402 print '</th>';
403 print '<th></th>';
404 print '<th class="right">';
405 print '</th>';
406 print '</tr>';
407 if ($num) {
408 while ($i < $num) {
409 $objp = $db->fetch_object($resql);
410 $staticrecruitmentcandidature->id = $objp->rowid;
411 $staticrecruitmentcandidature->ref = $objp->ref;
412 $staticrecruitmentcandidature->email = $objp->email;
413 $staticrecruitmentcandidature->status = $objp->status;
414 $staticrecruitmentcandidature->date_creation = $objp->date_creation;
415 $staticrecruitmentcandidature->firstname = $objp->firstname;
416 $staticrecruitmentcandidature->lastname = $objp->lastname;
417
418 $staticrecruitmentjobposition->id = $objp->jobid;
419 $staticrecruitmentjobposition->ref = $objp->jobref;
420 $staticrecruitmentjobposition->label = $objp->label;
421
422 print '<tr class="oddeven">';
423 print '<td class="nowraponall">'.$staticrecruitmentcandidature->getNomUrl(1, '').'</td>';
424 print '<td class="tdoverflowmax150">'.$staticrecruitmentcandidature->getFullName($langs).'</td>';
425 print '<td class="nowraponall">'.$staticrecruitmentjobposition->getNomUrl(1).'</td>';
426 print '<td class="right nowrap">'.dol_print_date($db->jdate($objp->tms), 'dayreduceformat').'</td>';
427 print '<td class="right nowrap" width="16">';
428 print $staticrecruitmentcandidature->getLibStatut(3);
429 print "</td>";
430 print '</tr>';
431 $i++;
432 }
433
434 $db->free($resql);
435 } else {
436 print '<tr class="oddeven"><td colspan="4"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
437 }
438 print "</table>";
439 print "</div>";
440 print "<br>";
441 } else {
442 dol_print_error($db);
443 }
444}
445
446print '</div></div></div>';
447
448// Initialize technical object to manage hooks. Note that conf->hooks_modules contains array
449$parameters = array('user' => $user);
450$reshook = $hookmanager->executeHooks('dashboardHRM', $parameters, $object); // Note that $action and $object may have been modified by hook
451
452// End of page
453llxFooter();
454$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($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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.