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