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