dolibarr 18.0.6
compare.php
1<?php
2/* Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2021 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
4 * Copyright (C) 2021 Greg Rastklan <greg.rastklan@atm-consulting.fr>
5 * Copyright (C) 2021 Jean-Pascal BOUDET <jean-pascal.boudet@atm-consulting.fr>
6 * Copyright (C) 2021 Grégory BLEMAND <gregory.blemand@atm-consulting.fr>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20
21 * \file htdocs/hrm/compare.php
22 * \ingroup hrm
23 * \brief This file compares skills of user groups
24 *
25 * Displays a table in three parts.
26 * 1- the left part displays the list of users of the selected group 1.
27 *
28 * 2- the central part displays the skills. display of the maximum score for this group and the number of occurrences.
29 *
30 * 3- the right part displays the members of group 2 or the job to be compared
31 */
32
33
34// Load Dolibarr environment
35require_once '../main.inc.php';
36require_once DOL_DOCUMENT_ROOT . '/core/lib/functions.lib.php';
37require_once DOL_DOCUMENT_ROOT . '/core/lib/functions2.lib.php';
38require_once DOL_DOCUMENT_ROOT . '/hrm/class/skill.class.php';
39require_once DOL_DOCUMENT_ROOT . '/hrm/class/job.class.php';
40require_once DOL_DOCUMENT_ROOT . '/hrm/class/evaluation.class.php';
41require_once DOL_DOCUMENT_ROOT . '/hrm/class/position.class.php';
42require_once DOL_DOCUMENT_ROOT . '/hrm/lib/hrm.lib.php';
43
44
45// Load translation files required by the page
46$langs->load('hrm');
47
48$job = new Job($db);
49
50// Permissions
51$permissiontoread = $user->rights->hrm->evaluation->read || $user->rights->hrm->compare_advance->read;
52$permissiontoadd = 0;
53
54if (empty($conf->hrm->enabled)) accessforbidden();
55if (!$permissiontoread || ($action === 'create' && !$permissiontoadd)) accessforbidden();
56
57
58/*
59 * View
60 */
61
62$css = array('/hrm/css/style.css');
63
64llxHeader('', $langs->trans('SkillComparison'), '', '', 0, 0, '', $css);
65
66$head = array();
67
68$h = 0;
69$head[$h][0] = $_SERVER["PHP_SELF"];
70$head[$h][1] = $langs->trans("SkillComparison");
71$head[$h][2] = 'compare';
72
73print dol_get_fiche_head($head, 'compare', '', 1);
74
75?>
76 <script type="text/javascript">
77
78 $(document).ready(function () {
79
80 $("li[fk_user]").click(function () {
81
82 if ($(this).hasClass('disabled')) {
83 $(this).removeClass('disabled');
84 } else {
85 $(this).addClass('disabled');
86 }
87
88
89 var $userl = $(this).closest('ul');
90 var listname = $userl.attr('name');
91
92 var TId = [];
93
94 $userl.find('li').each(function (i, item) {
95
96 if ($(item).hasClass('disabled')) {
97 TId.push($(item).attr('fk_user'));
98 }
99
100 });
101
102 $('#' + listname + '_excluded_id').val(TId.join(','));
103
104 });
105
106 });
107
108
109 </script>
110
111
112<?php
113
114$fk_usergroup2 = 0;
115$fk_job = (int) GETPOST('fk_job');
116if ($fk_job <= 0) $fk_usergroup2 = GETPOST('fk_usergroup2');
117
118$fk_usergroup1 = GETPOST('fk_usergroup1');
119
120?>
121
122
123 <div class="fichecenter">
124 <form action="<?php echo $_SERVER['PHP_SELF'] ?>">
125
126 <div class="tabBar tabBarWithBottom">
127 <div class="fichehalfleft">
128 <table class="border tableforfield" width="100%">
129 <tr>
130 <td><?php
131 print $langs->trans('group1ToCompare').'</td><td>';
132 print img_picto('', 'group', 'class="pictofixedwidth"');
133 print $form->select_dolgroups($fk_usergroup1, 'fk_usergroup1', 1);
134 ?></td>
135 </tr>
136 <tr><td>&nbsp;</td></tr>
137 <tr>
138 <td><?php
139 print $langs->trans('group2ToCompare').'</td><td>';
140 print img_picto('', 'group', 'class="pictofixedwidth"');
141 print $form->select_dolgroups($fk_usergroup2, 'fk_usergroup2', 1);
142 ?></td>
143 </tr>
144 <tr>
145 <td><STRONG><?php print $langs->trans('or'); ?></STRONG></td>
146 </tr>
147 <tr>
148 <td><?php
149 echo $langs->trans('OrJobToCompare') . '</td><td>';
150 $j = new Job($db);
151 $jobs = $j->fetchAll();
152 $TJobs = array();
153
154 foreach ($jobs as &$j) {
155 $TJobs[$j->id] = $j->label;
156 }
157
158 print img_picto('', 'jobprofile', 'class="pictofixedwidth"').$form->selectarray('fk_job', $TJobs, $fk_job, 1);
159 ?></td>
160 </tr>
161 </table>
162 </div>
163
164 <div style="background:#eee;border-radius:5px 0;margin:0px 0 10px;font-style:italic;padding:5px;" class="fichehalfright">
165 <!--<h4><?php echo $langs->trans('legend'); ?></h4>-->
166 <table class="border" width="100%">
167 <tr>
168 <td><span style="vertical-align:middle" class="toohappy diffnote little"></span>
169 <?php echo $langs->trans('CompetenceAcquiredByOneOrMore'); ?></td>
170 </tr>
171 <tr>
172 <td><span style="vertical-align:middle" class="veryhappy diffnote little"></span>
173 <?php echo $langs->trans('MaxlevelGreaterThan'); ?></td>
174 </tr>
175 <tr>
176 <td><span style="vertical-align:middle" class="happy diffnote little"></span>
177 <?php echo $langs->trans('MaxLevelEqualTo'); ?></td>
178 </tr>
179 <tr>
180 <td><span style="vertical-align:middle" class="sad diffnote little"></span>
181 <?php echo $langs->trans('MaxLevelLowerThan'); ?></td>
182 </tr>
183 <tr>
184 <td><span style="vertical-align:middle" class="toosad diffnote little"></span>
185 <?php echo $langs->trans('SkillNotAcquired'); ?></td>
186 </tr>
187 </table>
188
189 </div>
190
191 <div class="clearboth"></div>
192
193 </div>
194
195 <br><br>
196 <div class="center">
197 <input class="button" type="SUBMIT" name="bt1" VALUE="<?php print $langs->trans('Refresh'); ?>">
198 </div>
199 <br><br>
200
201 <div id="compare" width="100%" style="position:relative;">
202
203 <?php if ($fk_usergroup1 > 0 || $fk_usergroup2 > 0 || $fk_job > 0) { ?>
204 <table width="100%">
205 <tr>
206 <th></th>
207 <th><?php print $langs->trans('skill'); ?></th>
208 <th><?php print $langs->trans('rank'); ?></th>
209 <th><?php print $langs->trans('difference'); ?></th>
210 <th><?php print $langs->trans('rank'); ?></th>
211 <th></th>
212 </tr>
213
214 <?php
215 echo '<tr><td id="list-user-left" style="width:30%" valign="top">';
216
217 $TUser1 = $TUser2 = array();
218
219 $userlist1 = displayUsersListWithPicto($TUser1, $fk_usergroup1, 'list1');
220
221
222 $skill = new Skill($db);
223 $TSkill1 = getSkillForUsers($TUser1);
224
225 if ($fk_job > 0) {
226 $TSkill2 = getSkillForJob($fk_job);
227
228 $job = new Job($db);
229 $job->fetch($fk_job);
230 $userlist2 = '<ul>
231 <li>
232 <h3>' . $job->label . '</h3>
233 <p>' . $job->description . '</p>
234 </li>
235 </ul>';
236 } else {
237 $userlist2 = displayUsersListWithPicto($TUser2, $fk_usergroup2, 'list2');
238 $TSkill2 = getSkillForUsers($TUser2);
239 }
240
241 $TMergedSkills = mergeSkills($TSkill1, $TSkill2);
242
243 echo $userlist1;
244
245 echo '</td>';
246
247 echo '<td id="" style="width:20%" valign="top">' . skillList($TMergedSkills) . '</td>';
248 echo '<td id="" style="width:5%" valign="top">' . rate($TMergedSkills, 'rate1') . '</td>';
249 echo '<td id="" style="width:10%" valign="top">' . diff($TMergedSkills) . '</td>';
250 echo '<td id="" style="width:5%" valign="top">' . rate($TMergedSkills, 'rate2') . '</td>';
251
252 echo '<td id="list-user-right" style="width:30%" valign="top">';
253
254 echo $userlist2;
255
256 echo '</td></tr>';
257
258 ?>
259
260 </table>
261
262 <?php } ?>
263
264 </div>
265
266 </form>
267
268 </div>
269
270<?php
271
272print dol_get_fiche_end();
273
274llxFooter();
275
276
277
285function diff(&$TMergedSkills)
286{
287
288 $out = '<ul class="diff">';
289
290 foreach ($TMergedSkills as $id => &$sk) {
291 $class = 'diffnote';
292
293 if (empty($sk->rate2)) $class .= ' toohappy';
294 elseif (empty($sk->rate1)) $class .= ' toosad';
295 elseif ($sk->rate1 == $sk->rate2) $class .= ' happy';
296 elseif ($sk->rate2 < $sk->rate1) $class .= ' veryhappy';
297 elseif ($sk->rate2 > $sk->rate1) $class .= ' sad';
298
299 $out .= '<li fk_skill="' . $id . '" class="' . $class . '" style="text-align:center;">
300 <span class="' . $class . '">&nbsp;</span>
301 </li>';
302 }
303
304 $out .= '</ul>';
305
306 return $out;
307}
308
315function rate(&$TMergedSkills, $field)
316{
317 global $langs, $fk_job;
318
319 $out = '<ul class="competence">';
320
321 foreach ($TMergedSkills as $id => &$sk) {
322 $class = "note";
323 $how_many = 0;
324 if (empty($sk->$field)) {
325 $note = 'x';
326 $class .= ' none';
327 } else {
328 $note = $sk->$field;
329 $how_many = ($field === 'rate1') ? $sk->how_many_max1 : $sk->how_many_max2;
330 }
331
332 if ($field === 'rate2' && $fk_job > 0) $trad = $langs->trans('RequiredRank');
333 else $trad = $langs->trans('HighestRank');
334
335 $out .= '<li fk_skill="' . $id . '" style="text-align:center;">
336 <p><span class="' . $class . ' classfortooltip" title="' . $trad . '">' . $note . '</span>' . ($how_many > 0 ? '<span class="bubble classfortooltip" title="' . $langs->trans('HowManyUserWithThisMaxNote') . '">' . $how_many . '</span>' : '') . '</p>
337 </li>';
338 }
339
340 $out .= '</ul>';
341
342 return $out;
343}
344
351function skillList(&$TMergedSkills)
352{
353
354 $out = '<ul class="competence">';
355
356 foreach ($TMergedSkills as $id => &$sk) {
357 $out .= '<li fk_skill="' . $id . '">
358 <h3>' . $sk->label . '</h3>
359 <p>' . $sk->description . '</p>
360 </li>';
361 }
362
363 $out .= '</ul>';
364
365 return $out;
366}
367
375function mergeSkills($TSkill1, $TSkill2)
376{
377
378 $Tab = array();
379
380 foreach ($TSkill1 as &$sk) {
381 if (empty($Tab[$sk->fk_skill])) $Tab[$sk->fk_skill] = new stdClass;
382
383 $Tab[$sk->fk_skill]->rate1 = $sk->rankorder;
384 $Tab[$sk->fk_skill]->how_many_max1 = $sk->how_many_max;
385 $Tab[$sk->fk_skill]->label = $sk->label;
386 $Tab[$sk->fk_skill]->description = $sk->description;
387 }
388
389 foreach ($TSkill2 as &$sk) {
390 if (empty($Tab[$sk->fk_skill])) $Tab[$sk->fk_skill] = new stdClass;
391 $Tab[$sk->fk_skill]->rate2 = $sk->rankorder;
392 $Tab[$sk->fk_skill]->label = $sk->label;
393 $Tab[$sk->fk_skill]->description = $sk->description;
394 $Tab[$sk->fk_skill]->how_many_max2 = $sk->how_many_max;
395 }
396
397 return $Tab;
398}
399
408function displayUsersListWithPicto(&$TUser, $fk_usergroup = 0, $namelist = 'list-user')
409{
410 global $db, $langs, $conf, $form;
411
412 $out = '';
413 if ($fk_usergroup > 0) {
414 $list = $namelist . '_excluded_id';
415
416 $excludedIdsList = GETPOST($list);
417
418 $sql = "SELECT u.rowid FROM " . MAIN_DB_PREFIX . "user u
419 LEFT JOIN " . MAIN_DB_PREFIX . "usergroup_user as ugu ON (u.rowid = ugu.fk_user)
420 WHERE u.statut > 0 AND ugu.entity = ".((int) $conf->entity);
421 $sql .= " AND ugu.fk_usergroup=" . ((int) $fk_usergroup);
422
423 $res = $db->query($sql);
424 $out .= '<ul name="' . $namelist . '">';
425
426 $TExcludedId = explode(',', $excludedIdsList);
427
428 $out .= '<input id="'.$list.'" type="hidden" name="'.$list.'" value="'.$excludedIdsList.'"> ';
429
430 $job = new Job($db);
431
432 while ($obj = $db->fetch_object($res)) {
433 $class = '';
434
435 $user = new User($db);
436 $user->fetch($obj->rowid);
437
438 $name = $user->getFullName($langs);
439 if (empty($name)) $name = $user->login;
440
441 if (in_array($user->id, $TExcludedId)) {
442 $class .= ' disabled';
443 } else {
444 if (!in_array($user->id, $TUser)) $TUser[] = $user->id;
445 }
446
447 $desc = '';
448
449 $jobstring = $job->getLastJobForUser($user->id);
450 $desc .= $jobstring;
451
452 $static_eval = new Evaluation($db);
453 $evaluation = $static_eval->getLastEvaluationForUser($user->id);
454
455 if (!empty($evaluation) && !empty($evaluation->date_eval)) {
456 $desc .= $langs->trans('DateLastEval') . ' : ' . dol_print_date($evaluation->date_eval);
457 } else {
458 $desc .= $langs->trans('NoEval');
459 }
460
461 if (!empty($user->array_options['options_DDA'])) $desc .= '<br>' . $langs->trans('Anciennete') . ' : ' . dol_print_date(strtotime($user->array_options['options_DDA']));
462
463 $out .= '<li fk_user="' . $user->id . '" class="' . $class . '">
464 ' . $form->showphoto('userphoto', $user, 0, 0, 0, 'photoref', 'small', 1, 0, 1) . '
465 <h3>' . $name . '</h3>
466 <p>' . $desc . '</p>
467 </li>';
468 }
469
470 $out .= '</ul>';
471 }
472
473 return $out;
474}
475
476
484function getSkillForUsers($TUser)
485{
486 global $db;
487
488 //I go back to the user with the highest score in a given group for all the skills assessed in that group
489 if (empty($TUser)) return array();
490
491 $sql = 'SELECT sk.rowid, sk.label, sk.description, sk.skill_type, sr.fk_object, sr.objecttype, sr.fk_skill, ';
492 $sql.= ' MAX(sr.rankorder) as rankorder';
493 $sql.= ' FROM '.MAIN_DB_PREFIX.'hrm_skill sk';
494 $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'hrm_skillrank sr ON (sk.rowid = sr.fk_skill)';
495 $sql.= " WHERE sr.objecttype = '".$db->escape(SkillRank::SKILLRANK_TYPE_USER)."'";
496 $sql.= ' AND sr.fk_object IN ('.$db->sanitize(implode(',', $TUser)).')';
497 $sql.= " GROUP BY sk.rowid, sk.label, sk.description, sk.skill_type, sr.fk_object, sr.objecttype, sr.fk_skill "; // group par competence
498
499 $resql = $db->query($sql);
500 $Tab = array();
501
502 if ($resql) {
503 //For each skill, we count the number of times that the max score has been reached within a given group
504 $num = 0;
505 while ($obj = $db->fetch_object($resql) ) {
506 $sql1 = "SELECT COUNT(rowid) as how_many_max FROM ".MAIN_DB_PREFIX."hrm_skillrank as sr";
507 $sql1.=" WHERE sr.rankorder = ".((int) $obj->rankorder);
508 $sql1.=" AND sr.objecttype = '".$db->escape(SkillRank::SKILLRANK_TYPE_USER)."'";
509 $sql1.=" AND sr.fk_skill = ".((int) $obj->fk_skill);
510 $sql1.=" AND sr.fk_object IN (".$db->sanitize(implode(',', $TUser)).")";
511 $resql1 = $db->query($sql1);
512
513 $objMax = $db->fetch_object($resql1);
514
515 $Tab[$num] = new stdClass();
516 $Tab[$num]->fk_skill = $obj->fk_skill;
517 $Tab[$num]->label = $obj->label;
518 $Tab[$num]->description = $obj->description;
519 $Tab[$num]->skill_type = $obj->skill_type;
520 $Tab[$num]->fk_object = $obj->fk_object;
521 $Tab[$num]->objectType = SkillRank::SKILLRANK_TYPE_USER;
522 $Tab[$num]->rankorder = $obj->rankorder;
523 $Tab[$num]->how_many_max = $objMax->how_many_max;
524
525 $num++;
526 }
527 } else {
528 dol_print_error($db);
529 }
530
531 return $Tab;
532}
533
540function getSkillForJob($fk_job)
541{
542 global $db;
543
544 if (empty($fk_job)) return array();
545
546 $sql = 'SELECT sk.rowid, sk.label, sk.description, sk.skill_type, sr.fk_object, sr.objecttype, sr.fk_skill,';
547 $sql.= " MAX(sr.rankorder) as rankorder";
548 $sql.=' FROM '.MAIN_DB_PREFIX.'hrm_skill as sk';
549 $sql.=' LEFT JOIN '.MAIN_DB_PREFIX.'hrm_skillrank as sr ON (sk.rowid = sr.fk_skill)';
550 $sql.=" WHERE sr.objecttype = '".SkillRank::SKILLRANK_TYPE_JOB."'";
551 $sql.=' AND sr.fk_object = '.((int) $fk_job);
552 $sql.=' GROUP BY sk.rowid, sk.label, sk.description, sk.skill_type, sr.fk_object, sr.objecttype, sr.fk_skill'; // group par competence*/
553
554 $resql = $db->query($sql);
555 $Tab = array();
556
557 if ($resql) {
558 $num = 0;
559 while ($obj = $db->fetch_object($resql) ) {
560 $Tab[$num] = new stdClass();
561 $Tab[$num]->fk_skill = $obj->fk_skill;
562 $Tab[$num]->label = $obj->label;
563 $Tab[$num]->description = $obj->description;
564 $Tab[$num]->skill_type = $obj->skill_type;
565 //$Tab[$num]->date_start = '';// du poste
566 //$Tab[$num]->date_end = ''; // du poste
567 $Tab[$num]->fk_object = $obj->fk_object;
568 $Tab[$num]->objectType = SkillRank::SKILLRANK_TYPE_JOB;
569 $Tab[$num]->rankorder = $obj->rankorder;
570 $Tab[$num]->how_many_max = $obj->how_many_max;
571
572 $num++;
573 }
574 } else {
575 dol_print_error($db);
576 }
577
578 return $Tab;
579}
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Definition wrapper.php:56
llxFooter()
Empty footer.
Definition wrapper.php:70
Class for Evaluation.
Class for Job.
Definition job.class.php:37
Class for Skill.
Class to manage Dolibarr users.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
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.
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition repair.php:120
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:123
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.