dolibarr  x.y.z
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/skill.class.php';
37 require_once DOL_DOCUMENT_ROOT . '/hrm/class/skillrank.class.php';
38 require_once DOL_DOCUMENT_ROOT . '/hrm/lib/hrm_skill.lib.php';
39 
40 // Load translation files required by the page
41 $langs->loadLangs(array('hrm', 'other'));
42 
43 // Get Parameters
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 {
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  $linkback = '<a href="' . $listLink . '?restore_lastsearch_values=1' . (!empty($socid) ? '&socid=' . $socid : '') . '">' . $langs->trans("BackToList") . '</a>';
219 
220  $morehtmlref = '<a href="'.DOL_URL_ROOT.'/user/vcard.php?id='.$object->id.'" class="refid">';
221  $morehtmlref .= img_picto($langs->trans("Download").' '.$langs->trans("VCard"), 'vcard.png', 'class="valignmiddle marginleftonly paddingrightonly"');
222  $morehtmlref .= '</a>';
223 
224  dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'rowid', $morehtmlref, '&objecttype='.$objecttype);
225 
226 
227  // Get all available skills
228  $static_skill = new Skill($db);
229  $TAllSkills = $static_skill->fetchAll();
230 
231  // Array format for multiselectarray function
232  $TAllSkillsFormatted=array();
233  if (!empty($TAllSkills)) {
234  foreach ($TAllSkills as $k=>$v) {
235  $TAllSkillsFormatted[$k] = $v->label;
236  }
237  }
238 
239  // table of skillRank linked to current object
240  $TSkillsJob = $skill->fetchAll('ASC', 't.rowid', 0, 0, array('customsql' => 'fk_object=' . ((int) $id) . " AND objecttype='" . $db->escape($objecttype) . "'"));
241 
242  $TAlreadyUsedSkill = array();
243  if (is_array($TSkillsJob) && !empty($TSkillsJob)) {
244  foreach ($TSkillsJob as $skillElement) {
245  $TAlreadyUsedSkill[$skillElement->fk_skill] = $skillElement->fk_skill;
246  }
247  }
248 
249  print '<div class="fichecenter">';
250  print '<div class="fichehalfleft">';
251 
252  print '<div class="underbanner clearboth"></div>';
253  print '<table class="border centpercent tableforfield">';
254 
255  // Login
256  print '<tr><td class="titlefield">'.$langs->trans("Login").'</td>';
257  if (!empty($object->ldap_sid) && $object->statut == 0) {
258  print '<td class="error">';
259  print $langs->trans("LoginAccountDisableInDolibarr");
260  print '</td>';
261  } else {
262  print '<td>';
263  $addadmin = '';
264  if (property_exists($object, 'admin')) {
265  if (isModEnabled('multicompany') && !empty($object->admin) && empty($object->entity)) {
266  $addadmin .= img_picto($langs->trans("SuperAdministratorDesc"), "redstar", 'class="paddingleft"');
267  } elseif (!empty($object->admin)) {
268  $addadmin .= img_picto($langs->trans("AdministratorDesc"), "star", 'class="paddingleft"');
269  }
270  }
271  print showValueWithClipboardCPButton(!empty($object->login) ? $object->login : '').$addadmin;
272  print '</td>';
273  }
274  print '</tr>'."\n";
275 
276  $object->fields['label']['visible']=0; // Already in banner
277  $object->fields['firstname']['visible']=0; // Already in banner
278  $object->fields['lastname']['visible']=0; // Already in banner
279  //include DOL_DOCUMENT_ROOT . '/core/tpl/commonfields_view.tpl.php';
280 
281  // Ref employee
282  print '<tr><td class="titlefield">'.$langs->trans("RefEmployee").'</td>';
283  print '<td class="error">';
284  print showValueWithClipboardCPButton(!empty($object->ref_employee) ? $object->ref_employee : '');
285  print '</td>';
286  print '</tr>'."\n";
287 
288  // National Registration Number
289  print '<tr><td class="titlefield">'.$langs->trans("NationalRegistrationNumber").'</td>';
290  print '<td class="error">';
291  print showValueWithClipboardCPButton(!empty($object->national_registration_number) ? $object->national_registration_number : '');
292  print '</td>';
293  print '</tr>'."\n";
294 
295  /*print '<tr><td class="titlefield">'.$langs->trans("NbOfActiveNotifications").'</td>'; // Notification for this thirdparty
296  print '<td colspan="3">';
297  $nbofrecipientemails=0;
298  $notify=new Notify($db);
299  $tmparray = $notify->getNotificationsArray('', 0, null, $object->id, array('user'));
300  foreach($tmparray as $tmpkey => $tmpval)
301  {
302  $nbofrecipientemails++;
303  }
304  print $nbofrecipientemails;
305  print '</td></tr>';*/
306 
307  print '</table>';
308 
309  print '</div>';
310  print '</div>';
311 
312 
313  print '<div class="clearboth"></div><br>';
314 
315  if ($objecttype != 'user' && $permissiontoadd) {
316  // form pour ajouter des compétences
317  print '<form name="addSkill" method="post" action="' . $_SERVER['PHP_SELF'] . '">';
318  print '<input type="hidden" name="objecttype" value="' . $objecttype . '">';
319  print '<input type="hidden" name="id" value="' . $id . '">';
320  print '<input type="hidden" name="action" value="addSkill">';
321  print '<input type="hidden" name="token" value="'.newToken().'">';
322  print '<div class="div-table-responsive-no-min">';
323  print '<table id="tablelines" class="noborder noshadow" width="100%">';
324  print '<tr><td style="width:90%">' . $langs->trans('AddSkill') . '</td><td style="width:10%"></td></tr>';
325  print '<tr>';
326  print '<td>' . $form->multiselectarray('fk_skill', array_diff_key($TAllSkillsFormatted, $TAlreadyUsedSkill), array(), 0, 0, '', 0, '100%') . '</td>';
327  print '<td><input class="button reposition" type="submit" value="' . $langs->trans('Add') . '"></td>';
328  print '</tr>';
329  print '</table>';
330  print '</div>';
331  print '</form>';
332  }
333  print '<br>';
334 
335  print '<div class="clearboth"></div>';
336 
337  if ($objecttype != 'user' && $permissiontoadd) {
338  print '<form name="saveSkill" method="post" action="' . $_SERVER['PHP_SELF'] . '">';
339  print '<input type="hidden" name="objecttype" value="' . $objecttype . '">';
340  print '<input type="hidden" name="id" value="' . $id . '">';
341  print '<input type="hidden" name="token" value="'.newToken().'">';
342  print '<input type="hidden" name="action" value="saveSkill">';
343  }
344  print '<div class="div-table-responsive-no-min">';
345  print '<table id="tablelines" class="noborder centpercent" width="100%">';
346  print '<tr class="liste_titre">';
347  print '<th>'.$langs->trans('SkillType').'</th>';
348  print '<th>'.$langs->trans('Label').'</th>';
349  print '<th>'.$langs->trans('Description').'</th>';
350  print '<th>'.$langs->trans($objecttype === 'job' ? 'RequiredRank' : 'EmployeeRank').'</th>';
351  if ($objecttype === 'job') {
352  print '<th class="linecoledit"></th>';
353  print '<th class="linecoldelete"></th>';
354  }
355  print '</tr>';
356  if (!is_array($TSkillsJob) || empty($TSkillsJob)) {
357  print '<tr><td><span class="opacitymedium">' . $langs->trans("NoRecordFound") . '</span></td></tr>';
358  } else {
359  $sk = new Skill($db);
360  foreach ($TSkillsJob as $skillElement) {
361  $sk->fetch($skillElement->fk_skill);
362  print '<tr>';
363  print '<td>';
364  print Skill::typeCodeToLabel($sk->skill_type);
365  print '</td><td class="linecolfk_skill">';
366  print $sk->getNomUrl(1);
367  print '</td>';
368  print '<td>';
369  print $sk->description;
370  print '</td><td class="linecolrank">';
371  print displayRankInfos($skillElement->rankorder, $skillElement->fk_skill, 'TNote', $objecttype == 'job' && $permissiontoadd ? 'edit' : 'view');
372  print '</td>';
373  if ($objecttype != 'user' && $permissiontoadd) {
374  print '<td class="linecoledit"></td>';
375  print '<td class="linecoldelete">';
376  print '<a class="reposition" href="' . $_SERVER["PHP_SELF"] . '?id=' . $skillElement->fk_object . '&amp;objecttype=' . $objecttype . '&amp;action=ask_deleteskill&amp;lineid=' . $skillElement->id . '">';
377  print img_delete();
378  print '</a>';
379  }
380  print '</td>';
381  print '</tr>';
382  }
383  }
384 
385  print '</table>';
386  if ($objecttype != 'user' && $permissiontoadd) print '<td><input class="button pull-right" type="submit" value="' . $langs->trans('SaveRank') . '"></td>';
387  print '</div>';
388  if ($objecttype != 'user' && $permissiontoadd) print '</form>';
389 
390 
391  // liste des compétences liées
392 
393  print dol_get_fiche_end();
394 
395  llxFooter();
396 }
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:45
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.