evaluation_card.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711
  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. *
  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. /**
  22. * \file htdocs/hrm/evaluation_card.php
  23. * \ingroup hrm
  24. * \brief Page to create/edit/view evaluation
  25. */
  26. // Load Dolibarr environment
  27. require '../main.inc.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/hrm/class/evaluation.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/hrm/class/job.class.php';
  33. require_once DOL_DOCUMENT_ROOT.'/hrm/class/skill.class.php';
  34. require_once DOL_DOCUMENT_ROOT.'/hrm/class/skillrank.class.php';
  35. require_once DOL_DOCUMENT_ROOT.'/hrm/lib/hrm_evaluation.lib.php';
  36. require_once DOL_DOCUMENT_ROOT.'/hrm/lib/hrm_skillrank.lib.php';
  37. // Load translation files required by the page
  38. $langs->loadLangs(array('hrm', 'other', 'products')); // why products?
  39. // Get parameters
  40. $id = GETPOST('id', 'int');
  41. $ref = GETPOST('ref', 'alpha');
  42. $action = GETPOST('action', 'aZ09');
  43. $confirm = GETPOST('confirm', 'alpha');
  44. $cancel = GETPOST('cancel', 'aZ09');
  45. $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'evaluationcard'; // To manage different context of search
  46. $backtopage = GETPOST('backtopage', 'alpha');
  47. $backtopageforcancel = GETPOST('backtopageforcancel', 'alpha');
  48. $lineid = GETPOST('lineid', 'int');
  49. // Initialize technical objects
  50. $object = new Evaluation($db);
  51. $extrafields = new ExtraFields($db);
  52. $diroutputmassaction = $conf->hrm->dir_output.'/temp/massgeneration/'.$user->id;
  53. $hookmanager->initHooks(array('evaluationcard', 'globalcard')); // Note that conf->hooks_modules contains array
  54. // Fetch optionals attributes and labels
  55. $extrafields->fetch_name_optionals_label($object->table_element);
  56. $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
  57. // Initialize array of search criterias
  58. $search_all = GETPOST("search_all", 'alpha');
  59. $search = array();
  60. foreach ($object->fields as $key => $val) {
  61. if (GETPOST('search_'.$key, 'alpha')) {
  62. $search[$key] = GETPOST('search_'.$key, 'alpha');
  63. }
  64. }
  65. if (empty($action) && empty($id) && empty($ref)) {
  66. $action = 'view';
  67. }
  68. // Load object
  69. include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once.
  70. // Permissions
  71. $permissiontoread = $user->rights->hrm->evaluation->read;
  72. $permissiontoadd = $user->rights->hrm->evaluation->write; // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
  73. $permissiontovalidate = (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $user->rights->hrm->evaluation_advance->validate) || (empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $permissiontoadd);
  74. $permissiontoClose = $user->rights->hrm->evaluation->write;
  75. $permissiontodelete = $user->rights->hrm->evaluation->delete/* || ($permissiontoadd && isset($object->status) && $object->status == $object::STATUS_DRAFT)*/;
  76. $permissiondellink = $user->rights->hrm->evaluation->write; // Used by the include of actions_dellink.inc.php
  77. $upload_dir = $conf->hrm->multidir_output[isset($object->entity) ? $object->entity : 1].'/evaluation';
  78. // Security check (enable the most restrictive one)
  79. //if ($user->socid > 0) accessforbidden();
  80. //if ($user->socid > 0) $socid = $user->socid;
  81. //$isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
  82. //restrictedArea($user, $object->element, $object->id, $object->table_element, '', 'fk_soc', 'rowid', $isdraft);
  83. if (!isModEnabled("hrm")) {
  84. accessforbidden();
  85. }
  86. if (!$permissiontoread || ($action === 'create' && !$permissiontoadd)) accessforbidden();
  87. /*
  88. * Actions
  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. if (empty($reshook)) {
  96. $error = 0;
  97. $backurlforlist = dol_buildpath('/hrm/evaluation_list.php', 1);
  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_buildpath('/hrm/evaluation_card.php', 1).'?id='.($id > 0 ? $id : '__ID__');
  104. }
  105. }
  106. }
  107. $triggermodname = 'hrm_EVALUATION_MODIFY'; // Name of trigger action code to execute when we modify record
  108. // Actions cancel, add, update, update_extras, confirm_validate, confirm_delete, confirm_deleteline, confirm_clone, confirm_close, confirm_setdraft, confirm_reopen
  109. include DOL_DOCUMENT_ROOT.'/core/actions_addupdatedelete.inc.php';
  110. // Actions when linking object each other
  111. include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php';
  112. // Actions when printing a doc from card
  113. include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
  114. // Action to move up and down lines of object
  115. //include DOL_DOCUMENT_ROOT.'/core/actions_lineupdown.inc.php';
  116. // Action to build doc
  117. include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
  118. if ($action == 'set_thirdparty' && $permissiontoadd) {
  119. $object->setValueFrom('fk_soc', GETPOST('fk_soc', 'int'), '', '', 'date', '', $user, $triggermodname);
  120. }
  121. if ($action == 'classin' && $permissiontoadd) {
  122. $object->setProject(GETPOST('projectid', 'int'));
  123. }
  124. // Actions to send emails
  125. $triggersendname = 'hrm_EVALUATION_SENTBYMAIL';
  126. $autocopy = 'MAIN_MAIL_AUTOCOPY_EVALUATION_TO';
  127. $trackid = 'evaluation'.$object->id;
  128. include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
  129. if ($action == 'saveSkill') {
  130. $TNote = GETPOST('TNote', 'array');
  131. if (!empty($TNote)) {
  132. foreach ($object->lines as $line) {
  133. $line->rankorder = $TNote[$line->fk_skill];
  134. $line->update($user);
  135. }
  136. setEventMessage($langs->trans("SaveLevelSkill"));
  137. }
  138. }
  139. if ($action == 'close') {
  140. // save evaldet lines to user;
  141. $sk = new SkillRank($db);
  142. $SkillrecordsForActiveUser = $sk->fetchAll('ASC', 'fk_skill', 0, 0, array("customsql"=>"fk_object = ".$object->fk_user ." AND objecttype ='".SkillRank::SKILLRANK_TYPE_USER."'"), 'AND');
  143. $errors = 0;
  144. // we go through the evaldets of the eval
  145. foreach ($object->lines as $key => $line) {
  146. // no reference .. we add the line to use it
  147. if (count($SkillrecordsForActiveUser) == 0) {
  148. $newSkill = new SkillRank($db);
  149. $resCreate = $newSkill->cloneFromCurrentSkill($line, $object->fk_user);
  150. if ($resCreate <= 0) {
  151. $errors++;
  152. setEventMessage($langs->trans('ErrorCreateUserSkill'), $line->fk_skill);
  153. }
  154. } else {
  155. //check if the skill is present to use it
  156. $find = false;
  157. $keyFind = 0;
  158. foreach ($SkillrecordsForActiveUser as $k => $sr) {
  159. if ($sr->fk_skill == $line->fk_skill) {
  160. $keyFind = $k;
  161. $find = true;
  162. break;
  163. }
  164. }
  165. //we update the skill user
  166. if ($find) {
  167. $updSkill = $SkillrecordsForActiveUser[$k];
  168. $updSkill->rankorder = $line->rankorder;
  169. $updSkill->update($user);
  170. } else { // sinon on ajoute la skill
  171. $newSkill = new SkillRank($db);
  172. $resCreate = $newSkill->cloneFromCurrentSkill($line, $object->fk_user);
  173. }
  174. }
  175. }
  176. if (empty($errors)) {
  177. $object->setStatut(Evaluation::STATUS_CLOSED);
  178. setEventMessage('EmployeeSkillsUpdated');
  179. }
  180. }
  181. if ($action == 'reopen' ) {
  182. // no update here we just change the evaluation status
  183. $object->setStatut(Evaluation::STATUS_VALIDATED);
  184. }
  185. }
  186. /*
  187. * View
  188. *
  189. * Put here all code to build page
  190. */
  191. $form = new Form($db);
  192. $formfile = new FormFile($db);
  193. $formproject = new FormProjets($db);
  194. $title = $langs->trans("Evaluation");
  195. $help_url = '';
  196. $css = array();
  197. $css[] = '/hrm/css/style.css';
  198. llxHeader('', $title, $help_url, '', 0, 0, '', $css);
  199. print '<script type="text/javascript" language="javascript">
  200. $(document).ready(function() {
  201. $("#btn_valid").click(function(){
  202. var form = $("#form_save_rank");
  203. $.ajax({
  204. type: "POST",
  205. url: form.attr("action"),
  206. data: form.serialize(),
  207. dataType: "json"
  208. }).always(function() {
  209. window.location.href = "'.dol_buildpath('/hrm/evaluation_card.php', 1).'?id='.$id.'&action=validate&token='.newToken().'";
  210. return false;
  211. });
  212. });
  213. });
  214. </script>';
  215. // Part to create
  216. if ($action == 'create') {
  217. print load_fiche_titre($langs->trans("NewEval"), '', 'object_' . $object->picto);
  218. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  219. print '<input type="hidden" name="token" value="'.newToken().'">';
  220. print '<input type="hidden" name="action" value="add">';
  221. if ($backtopage) {
  222. print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
  223. }
  224. if ($backtopageforcancel) {
  225. print '<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.'">';
  226. }
  227. print dol_get_fiche_head(array(), '');
  228. print '<table class="border centpercent tableforfieldcreate">'."\n";
  229. // Common attributes
  230. include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_add.tpl.php';
  231. // Other attributes
  232. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php';
  233. print '</table>'."\n";
  234. print dol_get_fiche_end();
  235. print $form->buttonsSaveCancel("Create", "Cancel");
  236. print '</form>';
  237. }
  238. // Part to edit record
  239. if (($id || $ref) && $action == 'edit') {
  240. print load_fiche_titre($langs->trans("Evaluation"), '', 'object_'.$object->picto);
  241. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  242. print '<input type="hidden" name="token" value="'.newToken().'">';
  243. print '<input type="hidden" name="action" value="update">';
  244. print '<input type="hidden" name="id" value="'.$object->id.'">';
  245. if ($backtopage) {
  246. print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
  247. }
  248. if ($backtopageforcancel) {
  249. print '<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.'">';
  250. }
  251. print dol_get_fiche_head();
  252. print '<table class="border centpercent tableforfieldedit">'."\n";
  253. // Common attributes
  254. include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_edit.tpl.php';
  255. // Other attributes
  256. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_edit.tpl.php';
  257. print '</table>';
  258. print dol_get_fiche_end();
  259. print $form->buttonsSaveCancel();
  260. print '</form>';
  261. }
  262. // Part to show record
  263. if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) {
  264. $res = $object->fetch_optionals();
  265. $head = evaluationPrepareHead($object);
  266. print dol_get_fiche_head($head, 'card', $langs->trans("Workstation"), -1, $object->picto);
  267. $formconfirm = '';
  268. if ($action == 'validate' && $permissiontovalidate) {
  269. // Confirm validate proposal
  270. $error = 0;
  271. // We verify whether the object is provisionally numbering
  272. $ref = substr($object->ref, 1, 4);
  273. if ($ref == 'PROV') {
  274. $numref = $object->getNextNumRef();
  275. if (empty($numref)) {
  276. $error++;
  277. setEventMessages($object->error, $object->errors, 'errors');
  278. }
  279. } else {
  280. $numref = $object->ref;
  281. }
  282. $text = $langs->trans('ConfirmValidateEvaluation', $numref);
  283. if (isModEnabled('notification')) {
  284. require_once DOL_DOCUMENT_ROOT.'/core/class/notify.class.php';
  285. $notify = new Notify($db);
  286. $text .= '<br>';
  287. $text .= $notify->confirmMessage('HRM_EVALUATION_VALIDATE', $object->socid, $object);
  288. }
  289. if (!$error) {
  290. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ValidateEvaluation'), $text, 'confirm_validate', '', 0, 1);
  291. }
  292. }
  293. // Confirmation to delete
  294. if ($action == 'delete') {
  295. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteEvaluation'), $langs->trans('ConfirmDeleteObject'), 'confirm_delete', '', 0, 1);
  296. }
  297. // Confirmation to delete line
  298. if ($action == 'deleteline') {
  299. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&lineid='.$lineid, $langs->trans('DeleteLine'), $langs->trans('ConfirmDeleteLine'), 'confirm_deleteline', '', 0, 1);
  300. }
  301. // Clone confirmation
  302. if ($action == 'clone') {
  303. // Create an array for form
  304. $formquestion = array();
  305. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneAsk', $object->ref), 'confirm_clone', $formquestion, 'yes', 1);
  306. }
  307. // Confirmation of action xxxx (You can use it for xxx = 'close', xxx = 'reopen', ...)
  308. if ($action == 'xxx') {
  309. $text = $langs->trans('ConfirmActionMyObject', $object->ref);
  310. $formquestion = array();
  311. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('XXX'), $text, 'confirm_xxx', $formquestion, 0, 1, 220);
  312. }
  313. // Call Hook formConfirm
  314. $parameters = array('formConfirm' => $formconfirm, 'lineid' => $lineid);
  315. $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  316. if (empty($reshook)) {
  317. $formconfirm .= $hookmanager->resPrint;
  318. } elseif ($reshook > 0) {
  319. $formconfirm = $hookmanager->resPrint;
  320. }
  321. // Print form confirm
  322. print $formconfirm;
  323. // Object card
  324. // ------------------------------------------------------------
  325. $linkback = '<a href="'.dol_buildpath('/hrm/evaluation_list.php', 1).'?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
  326. $morehtmlref = '<div class="refidno">';
  327. $morehtmlref .= $langs->trans('Label').' : '.$object->label;
  328. $u_position = new User(($db));
  329. $u_position->fetch($object->fk_user);
  330. $morehtmlref .= '<br>'.$u_position->getNomUrl(1);
  331. $job = new Job($db);
  332. $job->fetch($object->fk_job);
  333. $morehtmlref .= '<br>'.$langs->trans('JobProfile').' : '.$job->getNomUrl(1);
  334. $morehtmlref .= '</div>';
  335. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
  336. print '<div class="fichecenter">';
  337. print '<div class="fichehalfleft">';
  338. print '<div class="underbanner clearboth"></div>';
  339. print '<table class="border centpercent tableforfield">'."\n";
  340. $object->fields['label']['visible']=0; // Already in banner
  341. $object->fields['fk_user']['visible']=0; // Already in banner
  342. $object->fields['fk_job']['visible']=0; // Already in banner
  343. include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_view.tpl.php';
  344. // Other attributes. Fields from hook formObjectOptions and Extrafields.
  345. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
  346. print '</table>';
  347. print '</div>';
  348. print '</div>';
  349. print '<div class="clearboth"></div>';
  350. print dol_get_fiche_end();
  351. /*
  352. * Lines
  353. */
  354. if (!empty($object->table_element_line) && $object->status == Evaluation::STATUS_DRAFT) {
  355. // Show object lines
  356. $result = $object->getLinesArray();
  357. if ($result < 0) {
  358. dol_print_error($db, $object->error, $object->errors);
  359. }
  360. print '<br>';
  361. print ' <form name="form_save_rank" id="form_save_rank" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.(($action != 'editline') ? '' : '#line_'.GETPOST('lineid', 'int')).'" method="POST">
  362. <input type="hidden" name="token" value="' . newToken().'">
  363. <input type="hidden" name="action" value="saveSkill">
  364. <input type="hidden" name="mode" value="">
  365. <input type="hidden" name="page_y" value="">
  366. <input type="hidden" name="id" value="' . $object->id.'">
  367. ';
  368. if (!empty($conf->use_javascript_ajax) && $object->status == 0) {
  369. include DOL_DOCUMENT_ROOT.'/core/tpl/ajaxrow.tpl.php';
  370. }
  371. $conf->modules_parts['tpl']['hrm']='/hrm/core/tpl/'; // Pour utilisation du tpl hrm sur cet écran
  372. print '<div class="div-table-responsive-no-min">';
  373. if (!empty($object->lines) || ($object->status == $object::STATUS_DRAFT && $permissiontoadd && $action != 'selectlines' && $action != 'editline')) {
  374. print '<table id="tablelines" class="noborder noshadow" width="100%">';
  375. }
  376. //if (!empty($object->lines)) {
  377. $object->printObjectLines($action, $mysoc, null, GETPOST('lineid', 'int'), 1);
  378. //}
  379. // Form to add new line
  380. /*
  381. if ($object->status == 0 && $permissiontoadd && $action != 'selectlines') {
  382. if ($action != 'editline') {
  383. // Add products/services form
  384. $parameters = array();
  385. $reshook = $hookmanager->executeHooks('formAddObjectLine', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  386. if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  387. if (empty($reshook))
  388. $object->formAddObjectLine(1, $mysoc, $soc);
  389. }
  390. }
  391. */
  392. if (!empty($object->lines) || ($object->status == $object::STATUS_DRAFT && $permissiontoadd && $action != 'selectlines' && $action != 'editline')) {
  393. print '</table>';
  394. }
  395. print '</div>';
  396. print "</form>\n";
  397. print "<br>";
  398. }
  399. // list of comparison
  400. if ($object->status != Evaluation::STATUS_DRAFT) {
  401. // Recovery of skills related to this evaluation
  402. $sql = 'select';
  403. $sql .= ' e.ref,';
  404. $sql .= ' e.date_creation,';
  405. $sql .= ' e.fk_job,';
  406. $sql .= ' j.label as "refjob",';
  407. $sql .= ' ed.fk_skill,';
  408. $sql .= ' sk.label as "skilllabel",';
  409. $sql .= ' sk.skill_type,';
  410. $sql .= ' sk.description,';
  411. $sql .= ' ed.rankorder,';
  412. $sql .= ' ed.required_rank,';
  413. $sql .= ' ed.rankorder as "userRankForSkill",';
  414. $sql .= ' skdet_user.description as "userRankForSkillDesc",';
  415. $sql .= ' skdet_required.description as "required_rank_desc"';
  416. $sql .= ' FROM ' . MAIN_DB_PREFIX . 'hrm_evaluation as e';
  417. $sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'hrm_evaluationdet as ed ON e.rowid = ed.fk_evaluation';
  418. $sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'hrm_job as j ON e.fk_job = j.rowid';
  419. $sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'hrm_skill as sk ON ed.fk_skill = sk.rowid';
  420. $sql .= ' INNER JOIN ' . MAIN_DB_PREFIX . 'hrm_skilldet as skdet_user ON (skdet_user.fk_skill = sk.rowid AND skdet_user.rankorder = ed.rankorder)';
  421. //$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "hrm_skillrank as skr ON (j.rowid = skr.fk_object AND skr.fk_skill = ed.fk_skill AND skr.objecttype = 'job')";
  422. $sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'hrm_skilldet as skdet_required ON (skdet_required.fk_skill = sk.rowid AND skdet_required.rankorder = ed.required_rank)';
  423. $sql .= " WHERE e.rowid =" . ((int) $object->id);
  424. // echo $sql;
  425. $resql = $db->query($sql);
  426. $Tab = array();
  427. if ($resql) {
  428. $num = 0;
  429. while ($obj = $db->fetch_object($resql)) {
  430. $Tab[$num] = new stdClass();
  431. $class = '';
  432. $Tab[$num]->skill_type = $obj->skill_type;
  433. $Tab[$num]->skill_id = $obj->fk_skill;
  434. $Tab[$num]->skilllabel = $obj->skilllabel;
  435. $Tab[$num]->description = $obj->description;
  436. $Tab[$num]->userRankForSkill = '<span title="'.$obj->userRankForSkillDesc.'" class="radio_js_bloc_number TNote_1">' . $obj->userRankForSkill . '</span>';
  437. $Tab[$num]->required_rank = '<span title="'.$obj->required_rank_desc.'" class="radio_js_bloc_number TNote_1">' . $obj->required_rank . '</span>';
  438. if ($obj->userRankForSkill > $obj->required_rank) {
  439. $title=$langs->trans('MaxlevelGreaterThanShort');
  440. $class .= 'veryhappy diffnote';
  441. } elseif ($obj->userRankForSkill == $obj->required_rank) {
  442. $title=$langs->trans('MaxLevelEqualToShort');
  443. $class .= 'happy diffnote';
  444. } elseif ($obj->userRankForSkill < $obj->required_rank) {
  445. $title=$langs->trans('MaxLevelLowerThanShort');
  446. $class .= 'sad';
  447. }
  448. $Tab[$num]->result = '<span title="'.$title.'" class="classfortooltip ' . $class . ' note">&nbsp;</span>';
  449. $num++;
  450. }
  451. print '<div class="underbanner clearboth"></div>';
  452. print '<table class="noborder centpercent">';
  453. print '<tr class="liste_titre">';
  454. print '<th style="width:auto;text-align:auto" class="liste_titre">' . $langs->trans("TypeSkill") . ' </th>';
  455. print '<th style="width:auto;text-align:auto" class="liste_titre">' . $langs->trans("Label") . '</th>';
  456. print '<th style="width:auto;text-align:auto" class="liste_titre">' . $langs->trans("Description") . '</th>';
  457. print '<th style="width:auto;text-align:center" class="liste_titre">' . $langs->trans("EmployeeRank") . '</th>';
  458. print '<th style="width:auto;text-align:center" class="liste_titre">' . $langs->trans("RequiredRank") . '</th>';
  459. print '<th style="width:auto;text-align:auto" class="liste_titre">' . $langs->trans("Result") . ' ' .$form->textwithpicto('', GetLegendSkills(), 1) .'</th>';
  460. print '</tr>';
  461. $sk = new Skill($db);
  462. foreach ($Tab as $t) {
  463. $sk->fetch($t->skill_id);
  464. print '<tr>';
  465. print ' <td>' . Skill::typeCodeToLabel($t->skill_type) . '</td>';
  466. print ' <td>' . $sk->getNomUrl(1) . '</td>';
  467. print ' <td>' . $t->description . '</td>';
  468. print ' <td align="center">' . $t->userRankForSkill . '</td>';
  469. print ' <td align="center">' . $t->required_rank . '</td>';
  470. print ' <td>' . $t->result . '</td>';
  471. print '</tr>';
  472. }
  473. print '</table>';
  474. ?>
  475. <script>
  476. $(document).ready(function() {
  477. $(".radio_js_bloc_number").tooltip();
  478. });
  479. </script>
  480. <?php
  481. }
  482. }
  483. // Buttons for actions
  484. if ($action != 'presend' && $action != 'editline') {
  485. print '<div class="tabsAction">'."\n";
  486. $parameters = array();
  487. $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  488. if ($reshook < 0) {
  489. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  490. }
  491. if (empty($reshook)) {
  492. // Send
  493. if (empty($user->socid)) {
  494. print dolGetButtonAction('', $langs->trans('SendMail'), 'default', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=presend&mode=init&token='.newToken().'#formmailbeforetitle');
  495. }
  496. // Back to draft
  497. if ($object->status == $object::STATUS_VALIDATED) {
  498. print dolGetButtonAction('', $langs->trans('SetToDraft'), 'default', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=confirm_setdraft&confirm=yes&token='.newToken(), '', $permissiontoadd);
  499. print dolGetButtonAction('', $langs->trans('Close'), 'close', $_SERVER['PHP_SELF'].'?id='.$object->id.'&action=close&token='.newToken(), '', $permissiontodelete || ($object->status == $object::STATUS_CLOSED && $permissiontoclose));
  500. } elseif ($object->status != $object::STATUS_CLOSED) {
  501. print dolGetButtonAction('', $langs->trans('Modify'), 'default', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=edit&token='.newToken(), '', $permissiontoadd);
  502. }
  503. if ($object->status == $object::STATUS_CLOSED) {
  504. print dolGetButtonAction($langs->trans('ReOpen'), '', 'default', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=reopen&token='.newToken(), '', $permissiontoadd);
  505. }
  506. // Validate
  507. if ($object->status == $object::STATUS_DRAFT) {
  508. if (empty($object->table_element_line) || (is_array($object->lines) && count($object->lines) > 0)) {
  509. print dolGetButtonAction($langs->trans('Save').'&nbsp;'.$langs->trans('and').'&nbsp;'.$langs->trans('Valid'), '', 'default', '#', 'btn_valid', $permissiontovalidate);
  510. } else {
  511. $langs->load("errors");
  512. print dolGetButtonAction($langs->trans("ErrorAddAtLeastOneLineFirst"), $langs->trans("Validate"), 'default', '#', '', 0);
  513. }
  514. }
  515. // Delete (need delete permission, or if draft, just need create/modify permission)
  516. print dolGetButtonAction($langs->trans('Delete'), '', 'delete', $_SERVER['PHP_SELF'].'?id='.$object->id.'&action=delete&token='.newToken(), '', $permissiontodelete);
  517. }
  518. print '</div>'."\n";
  519. }
  520. // Select mail models is same action as presend
  521. if (GETPOST('modelselected')) {
  522. $action = 'presend';
  523. }
  524. if ($action != 'presend') {
  525. print '<div class="fichecenter"><div class="fichehalfleft">';
  526. print '<a name="builddoc"></a>'; // ancre
  527. $includedocgeneration = 0;
  528. // Documents
  529. if ($includedocgeneration) {
  530. $objref = dol_sanitizeFileName($object->ref);
  531. $relativepath = $objref.'/'.$objref.'.pdf';
  532. $filedir = $conf->hrm->dir_output.'/'.$object->element.'/'.$objref;
  533. $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
  534. $genallowed = $user->rights->hrm->evaluation->read; // If you can read, you can build the PDF to read content
  535. $delallowed = $user->rights->hrm->evaluation->write; // If you can create/edit, you can remove a file on card
  536. print $formfile->showdocuments('hrm:Evaluation', $object->element.'/'.$objref, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', '', '', $langs->defaultlang);
  537. }
  538. // Show links to link elements
  539. $linktoelem = $form->showLinkToObjectBlock($object, null, array('evaluation'));
  540. $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
  541. print '</div><div class="fichehalfright">';
  542. $MAXEVENT = 10;
  543. $morehtmlcenter = dolGetButtonTitle($langs->trans('SeeAll'), '', 'fa fa-bars imgforviewmode', DOL_URL_ROOT.'/hrm/evaluation_agenda.php?id='.$object->id);
  544. // List of actions on element
  545. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
  546. $formactions = new FormActions($db);
  547. $somethingshown = $formactions->showactions($object, $object->element.'@'.$object->module, (is_object($object->thirdparty) ? $object->thirdparty->id : 0), 1, '', $MAXEVENT, '', $morehtmlcenter);
  548. print '</div></div>';
  549. }
  550. //Select mail models is same action as presend
  551. if (GETPOST('modelselected')) {
  552. $action = 'presend';
  553. }
  554. // Presend form
  555. $modelmail = 'evaluation';
  556. $defaulttopic = 'InformationMessage';
  557. $diroutput = $conf->hrm->dir_output;
  558. $trackid = 'evaluation'.$object->id;
  559. include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
  560. }
  561. // End of page
  562. llxFooter();
  563. $db->close();