dolibarr  16.0.5
skill_tab.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2021 grégory Blémand <contact@atm-consulting.fr>
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 
30 // Load Dolibarr environment
31 require '../main.inc.php';
32 
33 require_once DOL_DOCUMENT_ROOT . '/core/class/html.formcompany.class.php';
34 require_once DOL_DOCUMENT_ROOT . '/core/class/html.formfile.class.php';
35 require_once DOL_DOCUMENT_ROOT . '/core/class/html.formprojet.class.php';
36 require_once DOL_DOCUMENT_ROOT . '/user/class/user.class.php';
37 require_once DOL_DOCUMENT_ROOT . '/hrm/class/skill.class.php';
38 require_once DOL_DOCUMENT_ROOT . '/hrm/class/skillrank.class.php';
39 require_once DOL_DOCUMENT_ROOT . '/hrm/lib/hrm_skill.lib.php';
40 
41 // Load translation files required by the page
42 $langs->loadLangs(array("hrm", "other"));
43 
44 $id = GETPOST('id', 'int');
45 $TSkillsToAdd = GETPOST('fk_skill', 'array');
46 $objecttype = GETPOST('objecttype', 'alpha');
47 $TNote = GETPOST('TNote', 'array');
48 $lineid = GETPOST('lineid', 'int');
49 $action = GETPOST('action', 'aZ09');
50 $confirm = GETPOST('confirm', 'alpha');
51 $cancel = GETPOST('cancel', 'aZ09');
52 $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'skillcard'; // To manage different context of search
53 $backtopage = GETPOST('backtopage', 'alpha');
54 $backtopageforcancel = GETPOST('backtopageforcancel', 'alpha');
55 
56 $TAuthorizedObjects = array('job', 'user');
57 $skill = new SkillRank($db);
58 
59 // Initialize technical objects
60 if (in_array($objecttype, $TAuthorizedObjects)) {
61  if ($objecttype == 'job') {
62  require_once DOL_DOCUMENT_ROOT . '/hrm/class/job.class.php';
63  $object = new Job($db);
64  } elseif ($objecttype == "user") {
65  $object = new User($db);
66  }
67 } else accessforbidden($langs->trans('ErrorBadObjectType'));
68 
69 $hookmanager->initHooks(array('skilltab', 'globalcard')); // Note that conf->hooks_modules contains array
70 
71 // Load object
72 include DOL_DOCUMENT_ROOT . '/core/actions_fetchobject.inc.php'; // Must be include, not include_once.
73 
74 $permissiontoread = $user->rights->hrm->all->read;
75 $permissiontoadd = $user->rights->hrm->all->write; // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
76 
77 // Security check (enable the most restrictive one)
78 if ($user->socid > 0) accessforbidden();
79 if (empty($conf->hrm->enabled)) accessforbidden();
80 if (!$permissiontoread) accessforbidden();
81 
82 
83 /*
84  * Actions
85  */
86 
87 $parameters = array();
88 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
89 if ($reshook < 0) {
90  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
91 }
92 
93 if (empty($reshook)) {
94  $error = 0;
95 
96  $backurlforlist = DOL_URL_ROOT.'/hrm/skill_list.php';
97 
98  if (empty($backtopage) || ($cancel && empty($id))) {
99  if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) {
100  if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) {
101  $backtopage = $backurlforlist;
102  } else {
103  $backtopage = DOL_URL_ROOT.'/hrm/skill_list.php?id=' . ($id > 0 ? $id : '__ID__');
104  }
105  }
106  }
107 
108  if ($action == 'addSkill') {
109  $error = 0;
110 
111  if (empty($TSkillsToAdd)) {
112  setEventMessage('ErrNoSkillSelected', 'errors');
113  $error++;
114  }
115 
116  if (!$error) {
117  foreach ($TSkillsToAdd as $k=>$v) {
118  $skillAdded = new SkillRank($db);
119  $skillAdded->fk_skill = $v;
120  $skillAdded->fk_object = $id;
121  $skillAdded->objecttype = $objecttype;
122  $ret = $skillAdded->create($user);
123  if ($ret < 0) setEventMessages($skillAdded->error, null, 'errors');
124  //else unset($TSkillsToAdd);
125  }
126  if ($ret > 0) setEventMessages($langs->trans("SaveAddSkill"), null);
127  }
128  } elseif ($action == 'saveSkill') {
129  if (!empty($TNote)) {
130  foreach ($TNote as $skillId => $rank) {
131  $TSkills = $skill->fetchAll('ASC', 't.rowid', 0, 0, array('customsql' => 'fk_object=' . ((int) $id) . " AND objecttype='" . $db->escape($objecttype) . "' AND fk_skill = " . ((int) $skillId)));
132  if (is_array($TSkills) && !empty($TSkills)) {
133  foreach ($TSkills as $tmpObj) {
134  $tmpObj->rankorder = $rank;
135  $tmpObj->update($user);
136  }
137  }
138  }
139  setEventMessages($langs->trans("SaveLevelSkill"), null);
140  header("Location: " . DOL_URL_ROOT.'/hrm/skill_tab.php?id=' . $id. '&objecttype=job');
141  exit;
142  }
143  } elseif ($action == 'confirm_deleteskill' && $confirm == 'yes') {
144  $skillToDelete = new SkillRank($db);
145  $ret = $skillToDelete->fetch($lineid);
146  setEventMessages($langs->trans("DeleteSkill"), null);
147  if ($ret > 0) {
148  $skillToDelete->delete($user);
149  }
150  }
151 }
152 
153 /*
154  * View
155  */
156 
157 $form = new Form($db);
158 $formfile = new FormFile($db);
159 $formproject = new FormProjets($db);
160 
161 $title = $langs->trans("RequiredSkills");
162 $help_url = '';
163 llxHeader('', $title, $help_url);
164 
165 // Part to show record
166 if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) {
167  $res = $object->fetch_optionals();
168 
169  // view configuration
170  if ($objecttype == 'job') {
171  require_once DOL_DOCUMENT_ROOT . '/hrm/lib/hrm_job.lib.php';
172  $head = jobPrepareHead($object);
173  $listLink = dol_buildpath('/hrm/job_list.php', 1);
174  } elseif ($objecttype == "user") {
175  require_once DOL_DOCUMENT_ROOT . "/core/lib/usergroups.lib.php";
176  $object->getRights();
177  $head = user_prepare_head($object);
178  $listLink = dol_buildpath('/user/list.php', 1);
179  }
180 
181  print dol_get_fiche_head($head, 'skill_tab', $langs->trans("Workstation"), -1, $object->picto);
182 
183  $formconfirm = '';
184 
185  // Confirmation to delete
186  /*if ($action == 'delete') {
187  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteSkill'), $langs->trans('ConfirmDeleteObject'), 'confirm_delete', '', 0, 1);
188  }*/
189  // Confirmation to delete line
190  if ($action == 'ask_deleteskill') {
191  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id . '&objecttype=' . $objecttype . '&lineid=' . $lineid, $langs->trans('DeleteLine'), $langs->trans('ConfirmDeleteLine'), 'confirm_deleteskill', '', 0, 1);
192  }
193  // Clone confirmation
194  /*if ($action == 'clone') {
195  // Create an array for form
196  $formquestion = array();
197  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneAsk', $object->ref), 'confirm_clone', $formquestion, 'yes', 1);
198  }*/
199 
200  // Call Hook formConfirm
201  $parameters = array('formConfirm' => $formconfirm, 'lineid' => $lineid);
202  $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
203  if (empty($reshook)) {
204  $formconfirm .= $hookmanager->resPrint;
205  } elseif ($reshook > 0) {
206  $formconfirm = $hookmanager->resPrint;
207  }
208 
209  // Print form confirm
210  print $formconfirm;
211 
212 
213  // Object card
214  // ------------------------------------------------------------
215  $linkback = '<a href="' . $listLink . '?restore_lastsearch_values=1' . (!empty($socid) ? '&socid=' . $socid : '') . '">' . $langs->trans("BackToList") . '</a>';
216 
217  $morehtmlref = '<a href="'.DOL_URL_ROOT.'/user/vcard.php?id='.$object->id.'" class="refid">';
218  $morehtmlref .= img_picto($langs->trans("Download").' '.$langs->trans("VCard"), 'vcard.png', 'class="valignmiddle marginleftonly paddingrightonly"');
219  $morehtmlref .= '</a>';
220 
221  dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'rowid', $morehtmlref, '&objecttype='.$objecttype);
222 
223 
224  // Get all available skills
225  $static_skill = new Skill($db);
226  $TAllSkills = $static_skill->fetchAll();
227 
228  // Array format for multiselectarray function
229  $TAllSkillsFormatted=array();
230  if (!empty($TAllSkills)) {
231  foreach ($TAllSkills as $k=>$v) {
232  $TAllSkillsFormatted[$k] = $v->label;
233  }
234  }
235 
236  // table of skillRank linked to current object
237  $TSkillsJob = $skill->fetchAll('ASC', 't.rowid', 0, 0, array('customsql' => 'fk_object=' . ((int) $id) . " AND objecttype='" . $db->escape($objecttype) . "'"));
238 
239  $TAlreadyUsedSkill = array();
240  if (is_array($TSkillsJob) && !empty($TSkillsJob)) {
241  foreach ($TSkillsJob as $skillElement) {
242  $TAlreadyUsedSkill[$skillElement->fk_skill] = $skillElement->fk_skill;
243  }
244  }
245 
246  print '<div class="fichecenter">';
247  print '<div class="fichehalfleft">';
248 
249  print '<div class="underbanner clearboth"></div>';
250  print '<table class="border centpercent tableforfield">';
251 
252  // Login
253  print '<tr><td class="titlefield">'.$langs->trans("Login").'</td>';
254  if (!empty($object->ldap_sid) && $object->statut == 0) {
255  print '<td class="error">';
256  print $langs->trans("LoginAccountDisableInDolibarr");
257  print '</td>';
258  } else {
259  print '<td>';
260  $addadmin = '';
261  if (property_exists($object, 'admin')) {
262  if (!empty($conf->multicompany->enabled) && !empty($object->admin) && empty($object->entity)) {
263  $addadmin .= img_picto($langs->trans("SuperAdministratorDesc"), "redstar", 'class="paddingleft"');
264  } elseif (!empty($object->admin)) {
265  $addadmin .= img_picto($langs->trans("AdministratorDesc"), "star", 'class="paddingleft"');
266  }
267  }
268  print showValueWithClipboardCPButton($object->login).$addadmin;
269  print '</td>';
270  }
271  print '</tr>'."\n";
272 
273  $object->fields['label']['visible']=0; // Already in banner
274  $object->fields['firstname']['visible']=0; // Already in banner
275  $object->fields['lastname']['visible']=0; // Already in banner
276  //include DOL_DOCUMENT_ROOT . '/core/tpl/commonfields_view.tpl.php';
277 
278  // Ref employee
279  print '<tr><td class="titlefield">'.$langs->trans("RefEmployee").'</td>';
280  print '<td class="error">';
281  print showValueWithClipboardCPButton($object->ref_employee);
282  print '</td>';
283  print '</tr>'."\n";
284 
285  // National Registration Number
286  print '<tr><td class="titlefield">'.$langs->trans("NationalRegistrationNumber").'</td>';
287  print '<td class="error">';
288  print showValueWithClipboardCPButton($object->national_registration_number);
289  print '</td>';
290  print '</tr>'."\n";
291 
292  /*print '<tr><td class="titlefield">'.$langs->trans("NbOfActiveNotifications").'</td>'; // Notification for this thirdparty
293  print '<td colspan="3">';
294  $nbofrecipientemails=0;
295  $notify=new Notify($db);
296  $tmparray = $notify->getNotificationsArray('', 0, null, $object->id, array('user'));
297  foreach($tmparray as $tmpkey => $tmpval)
298  {
299  $nbofrecipientemails++;
300  }
301  print $nbofrecipientemails;
302  print '</td></tr>';*/
303 
304  print '</table>';
305 
306  print '</div>';
307  print '</div>';
308 
309 
310  print '<div class="clearboth"></div><br>';
311 
312  if ($objecttype != 'user' && $permissiontoadd) {
313  // form pour ajouter des compétences
314  print '<form name="addSkill" method="post" action="' . $_SERVER['PHP_SELF'] . '">';
315  print '<input type="hidden" name="objecttype" value="' . $objecttype . '">';
316  print '<input type="hidden" name="id" value="' . $id . '">';
317  print '<input type="hidden" name="action" value="addSkill">';
318  print '<input type="hidden" name="token" value="'.newToken().'">';
319  print '<div class="div-table-responsive-no-min">';
320  print '<table id="tablelines" class="noborder noshadow" width="100%">';
321  print '<tr><td style="width:90%">' . $langs->trans('AddSkill') . '</td><td style="width:10%"></td></tr>';
322  print '<tr>';
323  print '<td>' . $form->multiselectarray('fk_skill', array_diff_key($TAllSkillsFormatted, $TAlreadyUsedSkill), array(), 0, 0, '', 0, '100%') . '</td>';
324  print '<td><input class="button reposition" type="submit" value="' . $langs->trans('Add') . '"></td>';
325  print '</tr>';
326  print '</table>';
327  print '</div>';
328  print '</form>';
329  }
330  print '<br>';
331 
332  print '<div class="clearboth"></div>';
333 
334  if ($objecttype != 'user' && $permissiontoadd) {
335  print '<form name="saveSkill" method="post" action="' . $_SERVER['PHP_SELF'] . '">';
336  print '<input type="hidden" name="objecttype" value="' . $objecttype . '">';
337  print '<input type="hidden" name="id" value="' . $id . '">';
338  print '<input type="hidden" name="token" value="'.newToken().'">';
339  print '<input type="hidden" name="action" value="saveSkill">';
340  }
341  print '<div class="div-table-responsive-no-min">';
342  print '<table id="tablelines" class="noborder centpercent" width="100%">';
343  print '<tr class="liste_titre">';
344  print '<th>'.$langs->trans('SkillType').'</th>';
345  print '<th>'.$langs->trans('Label').'</th>';
346  print '<th>'.$langs->trans('Description').'</th>';
347  print '<th>'.$langs->trans($objecttype === 'job' ? 'RequiredRank' : 'EmployeeRank').'</th>';
348  if ($objecttype === 'job') {
349  print '<th class="linecoledit"></th>';
350  print '<th class="linecoldelete"></th>';
351  }
352  print '</tr>';
353  if (!is_array($TSkillsJob) || empty($TSkillsJob)) {
354  print '<tr><td><span class="opacitymedium">' . $langs->trans("NoRecordFound") . '</span></td></tr>';
355  } else {
356  $sk = new Skill($db);
357  foreach ($TSkillsJob as $skillElement) {
358  $sk->fetch($skillElement->fk_skill);
359  print '<tr>';
360  print '<td>';
361  print Skill::typeCodeToLabel($sk->skill_type);
362  print '</td><td class="linecolfk_skill">';
363  print $sk->getNomUrl(1);
364  print '</td>';
365  print '<td>';
366  print $sk->description;
367  print '</td><td class="linecolrank">';
368  print displayRankInfos($skillElement->rankorder, $skillElement->fk_skill, 'TNote', $objecttype == 'job' && $permissiontoadd ? 'edit' : 'view');
369  print '</td>';
370  if ($objecttype != 'user' && $permissiontoadd) {
371  print '<td class="linecoledit"></td>';
372  print '<td class="linecoldelete">';
373  print '<a class="reposition" href="' . $_SERVER["PHP_SELF"] . '?id=' . $skillElement->fk_object . '&amp;objecttype=' . $objecttype . '&amp;action=ask_deleteskill&amp;lineid=' . $skillElement->id . '">';
374  print img_delete();
375  print '</a>';
376  }
377  print '</td>';
378  print '</tr>';
379  }
380  }
381 
382  print '</table>';
383  if ($objecttype != 'user' && $permissiontoadd) print '<td><input class="button pull-right" type="submit" value="' . $langs->trans('SaveRank') . '"></td>';
384  print '</div>';
385  if ($objecttype != 'user' && $permissiontoadd) print '</form>';
386 
387 
388  // liste des compétences liées
389 
390  print dol_get_fiche_end();
391 
392  llxFooter();
393 }
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
user_prepare_head
user_prepare_head(User $object)
Prepare array with list of tabs.
Definition: usergroups.lib.php:35
jobPrepareHead
jobPrepareHead($object)
Prepare array of tabs for Job.
Definition: hrm_job.lib.php:33
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
dol_buildpath
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
Definition: functions.lib.php:1062
FormProjets
Class to manage building of HTML components.
Definition: html.formprojet.class.php:30
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
dol_banner_tab
dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='rowid', $fieldref='ref', $morehtmlref='', $moreparam='', $nodbprefix=0, $morehtmlleft='', $morehtmlstatus='', $onlybanner=0, $morehtmlright='')
Show tab footer of a card.
Definition: functions.lib.php:2046
$help_url
if(GETPOST('button_removefilter_x', 'alpha')||GETPOST('button_removefilter.x', 'alpha')||GETPOST('button_removefilter', 'alpha')) if(GETPOST('button_search_x', 'alpha')||GETPOST('button_search.x', 'alpha')||GETPOST('button_search', 'alpha')) if($action=="save" &&empty($cancel)) $help_url
View.
Definition: agenda.php:116
img_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:3880
img_delete
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
Definition: functions.lib.php:4429
$formconfirm
$formconfirm
if ($action == 'delbookkeepingyear') {
Definition: listbyaccount.php:576
Skill\typeCodeToLabel
static typeCodeToLabel($code)
Definition: skill.class.php:1105
FormFile
Class to offer components to list and upload files.
Definition: html.formfile.class.php:36
showValueWithClipboardCPButton
showValueWithClipboardCPButton($valuetocopy, $showonlyonhover=1, $texttoshow='')
Create a button to copy $valuetocopy in the clipboard (for copy and paste feature).
Definition: functions.lib.php:11087
setEventMessage
setEventMessage($mesgs, $style='mesgs')
Set event message in dol_events session object.
Definition: functions.lib.php:8108
Skill
Class for Skill.
Definition: skill.class.php:36
dol_get_fiche_head
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
Definition: functions.lib.php:1822
dol_get_fiche_end
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition: functions.lib.php:2018
User
Class to manage Dolibarr users.
Definition: user.class.php:44
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8137
accessforbidden
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Definition: security.lib.php:933
Job
Class for Job.
Definition: job.class.php:36
SkillRank
Class for SkillRank.
Definition: skillrank.class.php:35
displayRankInfos
displayRankInfos($selected_rank, $fk_skill, $inputname='TNote', $mode='view')
Used to print ranks of a skill into several case, view or edit pour js necessary to select a rank.
Definition: hrm_skillrank.lib.php:107
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59