* Copyright (C) 2021 Gauthier VERDOL * Copyright (C) 2021 Greg Rastklan * Copyright (C) 2021 Jean-Pascal BOUDET * Copyright (C) 2021 Grégory BLEMAND * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ /** * \file skill_tab.php * \ingroup hrm * \brief Page to add/delete/view skill to jobs/users */ // Load Dolibarr environment require '../main.inc.php'; require_once DOL_DOCUMENT_ROOT . '/core/class/html.formcompany.class.php'; require_once DOL_DOCUMENT_ROOT . '/core/class/html.formfile.class.php'; require_once DOL_DOCUMENT_ROOT . '/core/class/html.formprojet.class.php'; require_once DOL_DOCUMENT_ROOT . '/user/class/user.class.php'; require_once DOL_DOCUMENT_ROOT . '/hrm/class/skill.class.php'; require_once DOL_DOCUMENT_ROOT . '/hrm/class/skillrank.class.php'; require_once DOL_DOCUMENT_ROOT . '/hrm/lib/hrm_skill.lib.php'; // Load translation files required by the page $langs->loadLangs(array("hrm", "other")); $id = GETPOST('id', 'int'); $TSkillsToAdd = GETPOST('fk_skill', 'array'); $objecttype = GETPOST('objecttype', 'alpha'); $TNote = GETPOST('TNote', 'array'); $lineid = GETPOST('lineid', 'int'); $action = GETPOST('action', 'aZ09'); $confirm = GETPOST('confirm', 'alpha'); $cancel = GETPOST('cancel', 'aZ09'); $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'skillcard'; // To manage different context of search $backtopage = GETPOST('backtopage', 'alpha'); $backtopageforcancel = GETPOST('backtopageforcancel', 'alpha'); $TAuthorizedObjects = array('job', 'user'); $skill = new SkillRank($db); // Initialize technical objects if (in_array($objecttype, $TAuthorizedObjects)) { if ($objecttype == 'job') { require_once DOL_DOCUMENT_ROOT . '/hrm/class/job.class.php'; $object = new Job($db); } elseif ($objecttype == "user") { $object = new User($db); } } else accessforbidden($langs->trans('ErrorBadObjectType')); $hookmanager->initHooks(array('skilltab', 'globalcard')); // Note that conf->hooks_modules contains array // Load object include DOL_DOCUMENT_ROOT . '/core/actions_fetchobject.inc.php'; // Must be include, not include_once. $permissiontoread = $user->rights->hrm->all->read; $permissiontoadd = $user->rights->hrm->all->write; // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php // Security check (enable the most restrictive one) if ($user->socid > 0) accessforbidden(); if (empty($conf->hrm->enabled)) accessforbidden(); if (!$permissiontoread) accessforbidden(); /* * Actions */ $parameters = array(); $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks if ($reshook < 0) { setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); } if (empty($reshook)) { $error = 0; $backurlforlist = DOL_URL_ROOT.'/hrm/skill_list.php'; if (empty($backtopage) || ($cancel && empty($id))) { if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) { if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) { $backtopage = $backurlforlist; } else { $backtopage = DOL_URL_ROOT.'/hrm/skill_list.php?id=' . ($id > 0 ? $id : '__ID__'); } } } if ($action == 'addSkill') { $error = 0; if (empty($TSkillsToAdd)) { setEventMessage('ErrNoSkillSelected', 'errors'); $error++; } if (!$error) { foreach ($TSkillsToAdd as $k=>$v) { $skillAdded = new SkillRank($db); $skillAdded->fk_skill = $v; $skillAdded->fk_object = $id; $skillAdded->objecttype = $objecttype; $ret = $skillAdded->create($user); if ($ret < 0) setEventMessage($skillAdded->error, 'errors'); //else unset($TSkillsToAdd); } } } elseif ($action == 'saveSkill') { if (!empty($TNote)) { foreach ($TNote as $skillId => $rank) { $TSkills = $skill->fetchAll('ASC', 't.rowid', 0, 0, array('customsql' => 'fk_object=' . ((int) $id) . " AND objecttype='" . $db->escape($objecttype) . "' AND fk_skill = " . ((int) $skillId))); if (is_array($TSkills) && !empty($TSkills)) { foreach ($TSkills as $tmpObj) { $tmpObj->rankorder = $rank; $tmpObj->update($user); } } } } } elseif ($action == 'confirm_deleteskill' && $confirm == 'yes') { $skillToDelete = new SkillRank($db); $ret = $skillToDelete->fetch($lineid); if ($ret > 0) { $skillToDelete->delete($user); } } } /* * View * * Put here all code to build page */ $form = new Form($db); $formfile = new FormFile($db); $formproject = new FormProjets($db); $title = $langs->trans("RequiredSkills"); $help_url = ''; llxHeader('', $title, $help_url); // Part to show record if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) { $res = $object->fetch_optionals(); // view configuration if ($objecttype == 'job') { require_once DOL_DOCUMENT_ROOT . '/hrm/lib/hrm_job.lib.php'; $head = jobPrepareHead($object); $listLink = dol_buildpath('/hrm/job_list.php', 1); } elseif ($objecttype == "user") { require_once DOL_DOCUMENT_ROOT . "/core/lib/usergroups.lib.php"; $object->getRights(); $head = user_prepare_head($object); $listLink = dol_buildpath('/user/list.php', 1); } print dol_get_fiche_head($head, 'skill_tab', $langs->trans("Workstation"), -1, $object->picto); $formconfirm = ''; // Confirmation to delete /*if ($action == 'delete') { $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteSkill'), $langs->trans('ConfirmDeleteObject'), 'confirm_delete', '', 0, 1); }*/ // Confirmation to delete line if ($action == 'ask_deleteskill') { $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id . '&objecttype=' . $objecttype . '&lineid=' . $lineid, $langs->trans('DeleteLine'), $langs->trans('ConfirmDeleteLine'), 'confirm_deleteskill', '', 0, 1); } // Clone confirmation /*if ($action == 'clone') { // Create an array for form $formquestion = array(); $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneAsk', $object->ref), 'confirm_clone', $formquestion, 'yes', 1); }*/ // Call Hook formConfirm $parameters = array('formConfirm' => $formconfirm, 'lineid' => $lineid); $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook if (empty($reshook)) { $formconfirm .= $hookmanager->resPrint; } elseif ($reshook > 0) { $formconfirm = $hookmanager->resPrint; } // Print form confirm print $formconfirm; // Object card // ------------------------------------------------------------ $linkback = '' . $langs->trans("BackToList") . ''; $morehtmlref = '
'; $morehtmlref.= $object->label; $morehtmlref .= '
'; dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'rowid', $morehtmlref, '&objecttype='.$objecttype); // Get all available skills $static_skill = new Skill($db); $TAllSkills = $static_skill->fetchAll(); // Array format for multiselectarray function $TAllSkillsFormatted=array(); if (!empty($TAllSkills)) { foreach ($TAllSkills as $k=>$v) { $TAllSkillsFormatted[$k] = $v->label; } } // table of skillRank linked to current object $TSkillsJob = $skill->fetchAll('ASC', 't.rowid', 0, 0, array('customsql' => 'fk_object=' . ((int) $id) . " AND objecttype='" . $db->escape($objecttype) . "'")); $TAlreadyUsedSkill = array(); if (is_array($TSkillsJob) && !empty($TSkillsJob)) { foreach ($TSkillsJob as $skillElement) { $TAlreadyUsedSkill[$skillElement->fk_skill] = $skillElement->fk_skill; } } print '
'; print '
'; print '
'; print '' . "\n"; $object->fields['label']['visible']=0; // Already in banner include DOL_DOCUMENT_ROOT . '/core/tpl/commonfields_view.tpl.php'; print '
'; print '
'; print '

'; if ($objecttype != 'user' && $permissiontoadd) { // form pour ajouter des compétences print '
'; print ''; print ''; print ''; print '
'; print ''; print ''; print ''; print ''; print ''; print ''; print '
' . $langs->trans('AddSkill') . '
' . $form->multiselectarray('fk_skill', array_diff_key($TAllSkillsFormatted, $TAlreadyUsedSkill), array(), 0, 0, '', 0, '100%') . '
'; print '
'; print '
'; } print '
'; print '
'; if ($objecttype != 'user' && $permissiontoadd) { print '
'; print ''; print ''; print ''; } print '
'; print ''; print ''; print ''; print ''; print ''; print ''; if ($objecttype === 'job') { print ''; print ''; } print ''; if (!is_array($TSkillsJob) || empty($TSkillsJob)) { print ''; } else { $sk = new Skill($db); foreach ($TSkillsJob as $skillElement) { $sk->fetch($skillElement->fk_skill); print ''; print ''; print ''; if ($objecttype != 'user' && $permissiontoadd) { print ''; print ''; print ''; } } print '
'.$langs->trans('SkillType').''.$langs->trans('Label').''.$langs->trans('Description').''.$langs->trans($objecttype === 'job' ? 'RequiredRank' : 'EmployeeRank').'
' . $langs->trans("NoRecordFound") . '
'; print Skill::typeCodeToLabel($sk->skill_type); print ''; print $sk->getNomUrl(1); print ''; print $sk->description; print ''; print displayRankInfos($skillElement->rankorder, $skillElement->fk_skill, 'TNote', $objecttype == 'job' && $permissiontoadd ? 'edit' : 'view'); print ''; print 'id . '">'; print img_delete(); print ''; } print '
'; if ($objecttype != 'user' && $permissiontoadd) print ''; print '
'; if ($objecttype != 'user' && $permissiontoadd) print '
'; // liste des compétences liées print dol_get_fiche_end(); llxFooter(); }