skill_card.php 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871
  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 skill_card.php
  23. * \ingroup hrm
  24. * \brief Page to create/edit/view skill
  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/skill.class.php';
  32. require_once DOL_DOCUMENT_ROOT . '/hrm/lib/hrm_skill.lib.php';
  33. // Load translation files required by the page
  34. $langs->loadLangs(array("hrm", "other", 'products'));
  35. // Get parameters
  36. $id = GETPOST('id', 'int');
  37. $ref = GETPOST('ref', 'alpha');
  38. $action = GETPOST('action', 'aZ09');
  39. $confirm = GETPOST('confirm', 'alpha');
  40. $cancel = GETPOST('cancel', 'aZ09');
  41. $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'skillcard'; // To manage different context of search
  42. $backtopage = GETPOST('backtopage', 'alpha');
  43. $backtopageforcancel = GETPOST('backtopageforcancel', 'alpha');
  44. //$lineid = GETPOST('lineid', 'int');
  45. // Initialize technical objects
  46. $object = new Skill($db);
  47. $extrafields = new ExtraFields($db);
  48. //$diroutputmassaction = $conf->hrm->dir_output.'/temp/massgeneration/'.$user->id;
  49. $hookmanager->initHooks(array('skillcard', 'globalcard')); // Note that conf->hooks_modules contains array
  50. // Fetch optionals attributes and labels
  51. $extrafields->fetch_name_optionals_label($object->table_element);
  52. $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
  53. // Initialize array of search criterias
  54. $search_all = GETPOST("search_all", 'alpha');
  55. $search = array();
  56. foreach ($object->fields as $key => $val) {
  57. if (GETPOST('search_' . $key, 'alpha')) {
  58. $search[$key] = GETPOST('search_' . $key, 'alpha');
  59. }
  60. }
  61. if (empty($action) && empty($id) && empty($ref)) {
  62. $action = 'view';
  63. }
  64. // Load object
  65. include DOL_DOCUMENT_ROOT . '/core/actions_fetchobject.inc.php'; // Must be include, not include_once.
  66. $permissiontoread = $user->rights->hrm->all->read;
  67. $permissiontoadd = $user->rights->hrm->all->write; // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
  68. $permissiontodelete = $user->rights->hrm->all->delete;
  69. $upload_dir = $conf->hrm->multidir_output[isset($object->entity) ? $object->entity : 1] . '/skill';
  70. // Security check (enable the most restrictive one)
  71. //if ($user->socid > 0) accessforbidden();
  72. //if ($user->socid > 0) $socid = $user->socid;
  73. //$isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
  74. //restrictedArea($user, $object->element, $object->id, $object->table_element, '', 'fk_soc', 'rowid', $isdraft);
  75. if (empty($conf->hrm->enabled)) accessforbidden();
  76. if (!$permissiontoread || ($action === 'create' && !$permissiontoadd)) accessforbidden();
  77. $MaxNumberSkill = isset($conf->global->HRM_MAXRANK) ? $conf->global->HRM_MAXRANK : Skill::DEFAULT_MAX_RANK_PER_SKILL;
  78. /*
  79. * Actions
  80. */
  81. $parameters = array();
  82. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  83. if ($reshook < 0) {
  84. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  85. }
  86. if (empty($reshook)) {
  87. $error = 0;
  88. $backurlforlist = DOL_URL_ROOT.'/hrm/skill_list.php';
  89. if (empty($backtopage) || ($cancel && empty($id))) {
  90. if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) {
  91. if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) {
  92. $backtopage = $backurlforlist;
  93. } else {
  94. $backtopage = DOL_URL_ROOT.'/hrm/skill_card.php?id=' . ($id > 0 ? $id : '__ID__');
  95. }
  96. }
  97. }
  98. $triggermodname = 'hrm_SKILL_MODIFY'; // Name of trigger action code to execute when we modify record
  99. // Actions cancel, add, update, update_extras, confirm_validate, confirm_delete, confirm_deleteline, confirm_clone, confirm_close, confirm_setdraft, confirm_reopen
  100. $noback = 1;
  101. include DOL_DOCUMENT_ROOT.'/core/actions_addupdatedelete.inc.php';
  102. // action update on Skilldet
  103. $skilldetArray = GETPOST("descriptionline", "array:alphanohtml");
  104. if (!$error) {
  105. if (is_array($skilldetArray) && count($skilldetArray) > 0) {
  106. foreach ($skilldetArray as $key => $SkValueToUpdate) {
  107. $skilldetObj = new Skilldet($object->db);
  108. $res = $skilldetObj->fetch($key);
  109. if ($res > 0) {
  110. $skilldetObj->description = $SkValueToUpdate;
  111. $resupd = $skilldetObj->update($user);
  112. if ($resupd <= 0) {
  113. setEventMessage($langs->trans('errorUpdateSkilldet'));
  114. }
  115. }
  116. }
  117. }
  118. }
  119. // Actions when linking object each other
  120. include DOL_DOCUMENT_ROOT . '/core/actions_dellink.inc.php';
  121. // Actions when printing a doc from card
  122. include DOL_DOCUMENT_ROOT . '/core/actions_printing.inc.php';
  123. // Action to move up and down lines of object
  124. //include DOL_DOCUMENT_ROOT.'/core/actions_lineupdown.inc.php';
  125. // Action to build doc
  126. include DOL_DOCUMENT_ROOT . '/core/actions_builddoc.inc.php';
  127. if ($action == 'set_thirdparty' && $permissiontoadd) {
  128. $object->setValueFrom('fk_soc', GETPOST('fk_soc', 'int'), '', '', 'date', '', $user, $triggermodname);
  129. }
  130. if ($action == 'classin' && $permissiontoadd) {
  131. $object->setProject(GETPOST('projectid', 'int'));
  132. }
  133. // Actions to send emails
  134. $triggersendname = 'hrm_SKILL_SENTBYMAIL';
  135. $autocopy = 'MAIN_MAIL_AUTOCOPY_SKILL_TO';
  136. $trackid = 'skill' . $object->id;
  137. include DOL_DOCUMENT_ROOT . '/core/actions_sendmails.inc.php';
  138. }
  139. /*
  140. * View
  141. */
  142. $form = new Form($db);
  143. $formfile = new FormFile($db);
  144. $formproject = new FormProjets($db);
  145. $title = $langs->trans("skill");
  146. $help_url = '';
  147. llxHeader('', $title, $help_url);
  148. // Part to create
  149. if ($action == 'create') {
  150. print load_fiche_titre($langs->trans("NewSkill"), '', 'object_' . $object->picto);
  151. print '<form method="POST" action="' . $_SERVER["PHP_SELF"] . '">';
  152. print '<input type="hidden" name="token" value="' . newToken() . '">';
  153. print '<input type="hidden" name="action" value="add">';
  154. $backtopage .= (strpos($backtopage, '?') > 0 ? '&' : '?' ) ."objecttype=job";
  155. if ($backtopage) {
  156. print '<input type="hidden" name="backtopage" value="' . $backtopage . '">';
  157. }
  158. if ($backtopageforcancel) {
  159. print '<input type="hidden" name="backtopageforcancel" value="' . $backtopageforcancel . '">';
  160. }
  161. print dol_get_fiche_head(array(), '');
  162. print '<table class="border centpercent tableforfieldcreate">' . "\n";
  163. // Common attributes
  164. include DOL_DOCUMENT_ROOT . '/core/tpl/commonfields_add.tpl.php';
  165. // Other attributes
  166. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php';
  167. // SKILLDET ADD
  168. //@todo je stop ici ... à continuer (affichage des 5 skilled input pour create action
  169. //print $object->showInputField($val, $key, $value, '', '['']', '', 0);
  170. print '</table>' . "\n";
  171. print dol_get_fiche_end();
  172. print '<div class="center">';
  173. print '<input type="submit" class="button" name="add" value="' . dol_escape_htmltag($langs->trans("Create")) . '">';
  174. print '&nbsp; ';
  175. print '<input type="' . ($backtopage ? "submit" : "button") . '" class="button button-cancel" name="cancel" value="' . dol_escape_htmltag($langs->trans("Cancel")) . '"' . ($backtopage ? '' : ' onclick="javascript:history.go(-1)"') . '>'; // Cancel for create does not post form if we don't know the backtopage
  176. print '</div>';
  177. print '</form>';
  178. //dol_set_focus('input[name="ref"]');
  179. }
  180. // Part to edit record
  181. // and skilldet edition
  182. if (($id || $ref) && $action == 'edit') {
  183. print load_fiche_titre($langs->trans("Skill"), '', 'object_' . $object->picto);
  184. print '<form method="POST" action="' . $_SERVER["PHP_SELF"] . '">';
  185. print '<input type="hidden" name="token" value="' . newToken() . '">';
  186. print '<input type="hidden" name="action" value="update">';
  187. print '<input type="hidden" name="id" value="' . $object->id . '">';
  188. if ($backtopage) {
  189. print '<input type="hidden" name="backtopage" value="' . $backtopage . '">';
  190. }
  191. if ($backtopageforcancel) {
  192. print '<input type="hidden" name="backtopageforcancel" value="' . $backtopageforcancel . '">';
  193. }
  194. print dol_get_fiche_head();
  195. print '<table class="border centpercent tableforfieldedit">' . "\n";
  196. // Common attributes
  197. include DOL_DOCUMENT_ROOT . '/core/tpl/commonfields_edit.tpl.php';
  198. print '</table>';
  199. // Other attributes
  200. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_edit.tpl.php';
  201. // SKILLDET
  202. print dol_get_fiche_head(array(), '');
  203. $SkilldetRecords = $object->fetchLines();
  204. if (is_array($SkilldetRecords) && count($SkilldetRecords) == 0) {
  205. $object->createSkills(1);
  206. }
  207. if (is_array($SkilldetRecords) && count($SkilldetRecords) > 0) {
  208. print '<table>';
  209. foreach ($SkilldetRecords as $sk) {
  210. if ($sk->rankorder > $MaxNumberSkill) {
  211. continue;
  212. }
  213. print '<table class="border centpercent =">' . "\n";
  214. $sk->fields = dol_sort_array($sk->fields, 'position');
  215. foreach ($sk->fields as $key => $val) {
  216. if (abs($val['visible']) != 1 && abs($val['visible']) != 3 && abs($val['visible']) != 4) {
  217. continue;
  218. }
  219. if (array_key_exists('enabled', $val) && isset($val['enabled']) && !verifCond($val['enabled'])) {
  220. continue; // We don't want this field
  221. }
  222. print '<tr class="field_' . $key . '"><td';
  223. print ' class="titlefieldcreate';
  224. if (isset($val['notnull']) && $val['notnull'] > 0) {
  225. print ' fieldrequired';
  226. }
  227. if (preg_match('/^(text|html)/', $val['type'])) {
  228. print ' tdtop';
  229. }
  230. print '">';
  231. // if (!empty($val['help'])) {
  232. // print $form->textwithpicto($langs->trans($val['label']), $langs->trans($val['help']));
  233. // } else {
  234. print $langs->trans($val['label']).'&nbsp;'.$langs->trans('rank').'&nbsp;'.$sk->rankorder;
  235. // }
  236. print '</td>';
  237. print '<td class="valuefieldcreate">';
  238. // if (!empty($val['picto'])) {
  239. // print img_picto('', $val['picto'], '', false, 0, 0, '', 'pictofixedwidth');
  240. // }
  241. // if (in_array($val['type'], array('int', 'integer'))) {
  242. // $value = GETPOSTISSET($key) ? GETPOST($key, 'int') : $sk->$key;
  243. // } elseif ($val['type'] == 'double') {
  244. // $value = GETPOSTISSET($key) ? price2num(GETPOST($key, 'alphanohtml')) : $sk->$key;
  245. // } elseif (preg_match('/^(text|html)/', $val['type'])) {
  246. // $tmparray = explode(':', $val['type']);
  247. if (!empty($tmparray[1])) {
  248. $check = $tmparray[1];
  249. } else {
  250. $check = 'restricthtml';
  251. }
  252. $skilldetArray = GETPOST("descriptionline", "array");
  253. if (empty($skilldetArray)) {
  254. $value = GETPOSTISSET($key) ? GETPOST($key, $check) : $sk->$key;
  255. } else {
  256. $value=$skilldetArray[$sk->id];
  257. }
  258. //
  259. // } elseif ($val['type'] == 'price') {
  260. // $value = GETPOSTISSET($key) ? price2num(GETPOST($key)) : price2num($sk->$key);
  261. // } else {
  262. // $value = GETPOSTISSET($key) ? GETPOST($key, 'alpha') : $sk->$key;
  263. // }
  264. //var_dump($val.' '.$key.' '.$value);
  265. if ($val['noteditable']) {
  266. print $sk->showOutputField($val, $key, $value, '', '', '', 0);
  267. } else {
  268. /** @var Skilldet $sk */
  269. print $sk->showInputField($val, $key, $value, "", "line[" . $sk->id . "]", "", "");
  270. }
  271. print '</td>';
  272. print '</tr>';
  273. }
  274. }
  275. print '</table>';
  276. }
  277. print dol_get_fiche_end();
  278. print '<div class="center"><input type="submit" class="button button-save" name="save" value="' . $langs->trans("Save") . '">';
  279. print ' &nbsp; <input type="submit" class="button button-cancel" name="cancel" value="' . $langs->trans("Cancel") . '">';
  280. print '</div>';
  281. print '</form>';
  282. }
  283. // Part to show record
  284. if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) {
  285. $res = $object->fetch_optionals();
  286. $head = skillPrepareHead($object);
  287. print dol_get_fiche_head($head, 'card', $langs->trans("Workstation"), -1, $object->picto);
  288. $formconfirm = '';
  289. // Confirmation to delete
  290. if ($action == 'delete') {
  291. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('DeleteSkill'), $langs->trans('ConfirmDeleteObject'), 'confirm_delete', '', 0, 1);
  292. }
  293. // Confirmation to delete line
  294. if ($action == 'deleteline') {
  295. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id . '&lineid=' . $lineid, $langs->trans('DeleteLine'), $langs->trans('ConfirmDeleteLine'), 'confirm_deleteline', '', 0, 1);
  296. }
  297. // Clone confirmation
  298. if ($action == 'clone') {
  299. // Create an array for form
  300. $formquestion = array();
  301. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneAsk', $object->ref), 'confirm_clone', $formquestion, 'yes', 1);
  302. }
  303. // Confirmation of action xxxx
  304. if ($action == 'xxx') {
  305. $formquestion = array();
  306. /*
  307. $forcecombo=0;
  308. if ($conf->browser->name == 'ie') $forcecombo = 1; // There is a bug in IE10 that make combo inside popup crazy
  309. $formquestion = array(
  310. // 'text' => $langs->trans("ConfirmClone"),
  311. // array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1),
  312. // array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' => 1),
  313. // array('type' => 'other', 'name' => 'idwarehouse', 'label' => $langs->trans("SelectWarehouseForStockDecrease"), 'value' => $formproduct->selectWarehouses(GETPOST('idwarehouse')?GETPOST('idwarehouse'):'ifone', 'idwarehouse', '', 1, 0, 0, '', 0, $forcecombo))
  314. );
  315. */
  316. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('XXX'), $text, 'confirm_xxx', $formquestion, 0, 1, 220);
  317. }
  318. // Call Hook formConfirm
  319. $parameters = array('formConfirm' => $formconfirm, 'lineid' => $lineid);
  320. $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  321. if (empty($reshook)) {
  322. $formconfirm .= $hookmanager->resPrint;
  323. } elseif ($reshook > 0) {
  324. $formconfirm = $hookmanager->resPrint;
  325. }
  326. // Print form confirm
  327. print $formconfirm;
  328. // Object card
  329. // ------------------------------------------------------------
  330. $linkback = '<a href="' . DOL_URL_ROOT.'/hrm/skill_list.php?restore_lastsearch_values=1' . (!empty($socid) ? '&socid=' . $socid : '') . '">' . $langs->trans("BackToList") . '</a>';
  331. $morehtmlref = '<div class="refid">';
  332. $morehtmlref.= $object->label;
  333. $morehtmlref .= '</div>';
  334. dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'rowid', $morehtmlref);
  335. print '<div class="fichecenter">';
  336. print '<div class="fichehalfleft">';
  337. print '<div class="underbanner clearboth"></div>';
  338. print '<table class="border centpercent tableforfield">' . "\n";
  339. $object->fields['label']['visible']=0; // Already in banner
  340. include DOL_DOCUMENT_ROOT . '/core/tpl/commonfields_view.tpl.php';
  341. // Other attributes. Fields from hook formObjectOptions and Extrafields.
  342. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
  343. print '</table>';
  344. print '</div>';
  345. print '</div>';
  346. print '<div class="clearboth"></div>';
  347. print dol_get_fiche_end();
  348. //dol_include_once('/hrm/tpl/hrm_skillde.fiche.tpl.php');
  349. // Buttons for actions
  350. if ($action != 'presend' && $action != 'editline') {
  351. print '<div class="tabsAction">' . "\n";
  352. $parameters = array();
  353. $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  354. if ($reshook < 0) {
  355. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  356. }
  357. if (empty($reshook)) {
  358. // Back to draft
  359. if ($object->status == $object::STATUS_VALIDATED) {
  360. print dolGetButtonAction($langs->trans('SetToDraft'), '', 'default', $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&action=confirm_setdraft&confirm=yes&token=' . newToken(), '', $permissiontoadd);
  361. }
  362. print dolGetButtonAction($langs->trans('Modify'), '', 'default', $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&action=edit&token=' . newToken(), '', $permissiontoadd);
  363. // Delete (need delete permission, or if draft, just need create/modify permission)
  364. print dolGetButtonAction($langs->trans('Delete'), '', 'delete', $_SERVER['PHP_SELF'] . '?id=' . $object->id . '&action=delete&token=' . newToken(), '', $permissiontodelete);
  365. }
  366. print '</div>' . "\n";
  367. }
  368. }
  369. //*----------------------------------------------------------------------------
  370. //*----------------------------------------------------------------------------
  371. //*---------------------------------------------------------------------------
  372. if ($action != "create" && $action != "edit") {
  373. require_once DOL_DOCUMENT_ROOT . '/core/class/html.formcompany.class.php';
  374. require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php';
  375. require_once DOL_DOCUMENT_ROOT . '/core/lib/company.lib.php';
  376. // load hrm libraries
  377. require_once __DIR__ . '/class/skilldet.class.php';
  378. // for other modules
  379. //dol_include_once('/othermodule/class/otherobject.class.php');
  380. $action = GETPOST('action', 'aZ09') ? GETPOST('action', 'aZ09') : 'view'; // The action 'add', 'create', 'edit', 'update', 'view', ...
  381. $massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists)
  382. $show_files = GETPOST('show_files', 'int'); // Show files area generated by bulk actions ?
  383. $confirm = GETPOST('confirm', 'alpha'); // Result of a confirmation
  384. $cancel = GETPOST('cancel', 'alpha'); // We click on a Cancel button
  385. $toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list
  386. $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'skilldetlist'; // To manage different context of search
  387. $backtopage = GETPOST('backtopage', 'alpha'); // Go back to a dedicated page
  388. $optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
  389. $id = GETPOST('id', 'int');
  390. // Load variable for pagination
  391. $limit = 0;
  392. $sortfield = GETPOST('sortfield', 'aZ09comma');
  393. $sortorder = GETPOST('sortorder', 'aZ09comma');
  394. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  395. if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
  396. // If $page is not defined, or '' or -1 or if we click on clear filters
  397. $page = 0;
  398. }
  399. $offset = $limit * $page;
  400. $pageprev = $page - 1;
  401. $pagenext = $page + 1;
  402. // Initialize technical objects
  403. $objectline = new Skilldet($db);
  404. // $diroutputmassaction = $conf->hrm->dir_output . '/temp/massgeneration/' . $user->id;
  405. // $hookmanager->initHooks(array('skilldetlist')); // Note that conf->hooks_modules contains array
  406. // Default sort order (if not yet defined by previous GETPOST)
  407. if (!$sortfield) {
  408. reset($objectline->fields); // Reset is required to avoid key() to return null.
  409. $sortfield = "t." . key($objectline->fields); // Set here default search field. By default 1st field in definition.
  410. }
  411. if (!$sortorder) {
  412. $sortorder = "ASC";
  413. }
  414. // Initialize array of search criterias
  415. $search_all = GETPOST('search_all', 'alphanohtml') ? GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml');
  416. $search = array();
  417. foreach ($objectline->fields as $key => $val) {
  418. if (GETPOST('search_' . $key, 'alpha') !== '') {
  419. $search[$key] = GETPOST('search_' . $key, 'alpha');
  420. }
  421. if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
  422. $search[$key . '_dtstart'] = dol_mktime(0, 0, 0, GETPOST('search_' . $key . '_dtstartmonth', 'int'), GETPOST('search_' . $key . '_dtstartday', 'int'), GETPOST('search_' . $key . '_dtstartyear', 'int'));
  423. $search[$key . '_dtend'] = dol_mktime(23, 59, 59, GETPOST('search_' . $key . '_dtendmonth', 'int'), GETPOST('search_' . $key . '_dtendday', 'int'), GETPOST('search_' . $key . '_dtendyear', 'int'));
  424. }
  425. }
  426. // List of fields to search into when doing a "search in all"
  427. $fieldstosearchall = array();
  428. foreach ($objectline->fields as $key => $val) {
  429. if (!empty($val['searchall'])) {
  430. $fieldstosearchall['t.' . $key] = $val['label'];
  431. }
  432. }
  433. // Definition of array of fields for columns
  434. $arrayfields = array();
  435. foreach ($objectline->fields as $key => $val) {
  436. // If $val['visible']==0, then we never show the field
  437. if (!empty($val['visible'])) {
  438. $visible = (int) dol_eval($val['visible'], 1, 1, '1');
  439. $arrayfields['t.' . $key] = array(
  440. 'label' => $val['label'],
  441. 'checked' => (($visible < 0) ? 0 : 1),
  442. 'enabled' => ($visible != 3 && dol_eval($val['enabled'], 1, 1, '1')),
  443. 'position' => $val['position'],
  444. 'help' => isset($val['help']) ? $val['help'] : ''
  445. );
  446. }
  447. }
  448. $objectline->fields = dol_sort_array($objectline->fields, 'position');
  449. $arrayfields = dol_sort_array($arrayfields, 'position');
  450. /*
  451. * View
  452. */
  453. $form = new Form($db);
  454. $now = dol_now();
  455. $help_url = '';
  456. $title = $langs->transnoentitiesnoconv("Skilldets");
  457. $morejs = array();
  458. $morecss = array();
  459. // Build and execute select
  460. // --------------------------------------------------------------------
  461. $sql = 'SELECT ';
  462. $sql .= $objectline->getFieldList('t');
  463. $sql .= " FROM " . MAIN_DB_PREFIX . $objectline->table_element . " as t";
  464. if ($objectline->ismultientitymanaged == 1) {
  465. $sql .= " WHERE t.entity IN (" . getEntity($objectline->element) . ")";
  466. } else {
  467. $sql .= " WHERE 1 = 1 ";
  468. }
  469. if (!empty($id)) {
  470. $sql .= " AND fk_skill = " . ((int) $id) . " ";
  471. }
  472. // if total of record found is smaller than limit, no need to do paging and to restart another select with limits set.
  473. if (is_numeric($nbtotalofrecords) && ($limit > $nbtotalofrecords || empty($limit))) {
  474. $num = $nbtotalofrecords;
  475. } else {
  476. if ($limit) {
  477. $sql .= $db->plimit($limit + 1, $offset);
  478. }
  479. $resql = $db->query($sql);
  480. if (!$resql) {
  481. dol_print_error($db);
  482. exit;
  483. }
  484. $num = $db->num_rows($resql);
  485. }
  486. print '<form method="POST" id="searchFormList" action="' . $_SERVER["PHP_SELF"] . '">' . "\n";
  487. if ($optioncss != '') {
  488. print '<input type="hidden" name="optioncss" value="' . $optioncss . '">';
  489. }
  490. print '<input type="hidden" name="token" value="' . newToken() . '">';
  491. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  492. print '<input type="hidden" name="action" value="list">';
  493. print '<input type="hidden" name="sortfield" value="' . $sortfield . '">';
  494. print '<input type="hidden" name="sortorder" value="' . $sortorder . '">';
  495. print '<input type="hidden" name="page" value="' . $page . '">';
  496. print '<input type="hidden" name="contextpage" value="' . $contextpage . '">';
  497. if (!empty($id)) {
  498. print '<input type="hidden" name="id" value="' . $id . '">';
  499. }
  500. $param_fk = "&fk_skill=" . $id . "&fk_user_creat=" . $user->rowid;
  501. $backtopage = dol_buildpath('/hrm/skill_card.php', 1) . '?id=' . $id;
  502. //$newcardbutton = dolGetButtonTitle($langs->trans('New'), '', 'fa fa-plus-circle', dol_buildpath('/hrm/skilldet_card.php', 1) . '?action=create&backtopage=' . urlencode($_SERVER['PHP_SELF']) . $param_fk . '&backtopage=' . $backtopage, '', $permissiontoadd);
  503. print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'object_' . $object->picto, 0, "", '', '', 0, 0, 1);
  504. // Add code for pre mass action (confirmation or email presend form)
  505. $topicmail = "SendSkilldetRef";
  506. $modelmail = "skilldet";
  507. $objecttmp = new Skilldet($db);
  508. $trackid = 'xxxx' . $object->id;
  509. //include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
  510. if ($search_all) {
  511. foreach ($fieldstosearchall as $key => $val) {
  512. $fieldstosearchall[$key] = $langs->trans($val);
  513. }
  514. print '<div class="divsearchfieldfilter">' . $langs->trans("FilterOnInto", $search_all) . join(', ', $fieldstosearchall) . '</div>';
  515. }
  516. $moreforfilter = '';
  517. /*$moreforfilter.='<div class="divsearchfield">';
  518. $moreforfilter.= $langs->trans('MyFilter') . ': <input type="text" name="search_myfield" value="'.dol_escape_htmltag($search_myfield).'">';
  519. $moreforfilter.= '</div>';*/
  520. $parameters = array();
  521. $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $objectline); // Note that $action and $objectline may have been modified by hook
  522. if (empty($reshook)) {
  523. $moreforfilter .= $hookmanager->resPrint;
  524. } else {
  525. $moreforfilter = $hookmanager->resPrint;
  526. }
  527. if (!empty($moreforfilter)) {
  528. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  529. print $moreforfilter;
  530. print '</div>';
  531. }
  532. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  533. // $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
  534. // $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
  535. print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
  536. print '<table class="tagtable nobottomiftotal liste' . ($moreforfilter ? " listwithfilterbefore" : "") . '">' . "\n";
  537. // Fields title label
  538. // --------------------------------------------------------------------
  539. print '<tr class="liste_titre">';
  540. foreach ($objectline->fields as $key => $val) {
  541. // $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
  542. // if ($key == 'status') {
  543. // $cssforfield .= ($cssforfield ? ' ' : '') . 'center';
  544. // } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  545. // $cssforfield .= ($cssforfield ? ' ' : '') . 'center';
  546. // } elseif (in_array($val['type'], array('timestamp'))) {
  547. // $cssforfield .= ($cssforfield ? ' ' : '') . 'nowrap';
  548. // } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID' && empty($val['arrayofkeyval'])) {
  549. // $cssforfield .= ($cssforfield ? ' ' : '') . 'right';
  550. // }
  551. if (!empty($arrayfields['t.' . $key]['checked'])) {
  552. print getTitleFieldOfList($arrayfields['t.' . $key]['label'], 0, $_SERVER['PHP_SELF'], 't.' . $key, '', $param, ($cssforfield ? 'class="' . $cssforfield . '"' : ''), $sortfield, $sortorder, ($cssforfield ? $cssforfield . ' ' : '')) . "\n";
  553. }
  554. }
  555. print '<td></td>';
  556. print '<td></td>';
  557. print '</tr>' . "\n";
  558. // Display all ranks of skill
  559. // --------------------------------------------------------------------
  560. $i = 0;
  561. $totalarray = array();
  562. $totalarray['nbfield'] = 0;
  563. while ($i < ($limit ? min($num, $limit) : $num)) {
  564. $obj = $db->fetch_object($resql);
  565. if (empty($obj)) {
  566. break; // Should not happen
  567. }
  568. if ($obj->rankorder > $MaxNumberSkill) {
  569. continue;
  570. }
  571. // Store properties in $objectline
  572. $objectline->setVarsFromFetchObj($obj);
  573. // Show here line of result
  574. print '<tr class="oddeven">';
  575. foreach ($objectline->fields as $key => $val) {
  576. // $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
  577. // if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  578. // $cssforfield .= ($cssforfield ? ' ' : '') . 'center';
  579. // } elseif ($key == 'status') {
  580. // $cssforfield .= ($cssforfield ? ' ' : '') . 'center';
  581. // }
  582. //
  583. // if (in_array($val['type'], array('timestamp'))) {
  584. // $cssforfield .= ($cssforfield ? ' ' : '') . 'nowrap';
  585. // } elseif ($key == 'ref') {
  586. // $cssforfield .= ($cssforfield ? ' ' : '') . 'nowrap';
  587. // }
  588. //
  589. // if (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && !in_array($key, array('rowid', 'status')) && empty($val['arrayofkeyval'])) {
  590. // $cssforfield .= ($cssforfield ? ' ' : '') . 'right';
  591. // }
  592. //if (in_array($key, array('fk_soc', 'fk_user', 'fk_warehouse'))) $cssforfield = 'tdoverflowmax100';
  593. if (!empty($arrayfields['t.' . $key]['checked'])) {
  594. print '<td' . ($cssforfield ? ' class="' . $cssforfield . '"' : '') . '>';
  595. if ($key == 'status') {
  596. print $objectline->getLibStatut(5);
  597. } elseif ($key == 'rowid') {
  598. print $objectline->showOutputField($val, $key, $objectline->id, '');
  599. // ajout pencil
  600. print '<a class="timeline-btn" href="' . DOL_MAIN_URL_ROOT . '/comm/action/skilldet_card.php?action=edit&id=' . $objectline->id . '"><i class="fa fa-pencil" title="' . $langs->trans("Modify") . '" ></i></a>';
  601. } else {
  602. print $objectline->showOutputField($val, $key, $objectline->$key, '');
  603. }
  604. print '</td>';
  605. if (!$i) {
  606. $totalarray['nbfield']++;
  607. }
  608. if (!empty($val['isameasure']) && $val['isameasure'] == 1) {
  609. if (!$i) {
  610. $totalarray['pos'][$totalarray['nbfield']] = 't.' . $key;
  611. }
  612. if (!isset($totalarray['val'])) {
  613. $totalarray['val'] = array();
  614. }
  615. if (!isset($totalarray['val']['t.' . $key])) {
  616. $totalarray['val']['t.' . $key] = 0;
  617. }
  618. $totalarray['val']['t.' . $key] += $objectline->$key;
  619. }
  620. }
  621. }
  622. // LINE EDITION | SUPPRESSION
  623. print '<td>';
  624. print '</td>';
  625. print '<td>';
  626. // add pencil
  627. //@todo change to proper call dol_
  628. //print '<a class="timeline-btn" href="' . dol_buildpath("custom/hrm/skilldet_card.php?action=edit&id=" . $objectline->id, 1) . '"><i class="fa fa-pencil" title="' . $langs->trans("Modify") . '" ></i></a>';
  629. // add trash
  630. //@todo change to proper call dol_
  631. //print '<a class="timeline-btn" href="'.dol_buildpath("custom/hrm/skilldet_card.php?action=delete&id=".$objectline->id,1) .'"><i class="fa fa-trash" title="'.$langs->trans("Delete").'" ></i></a>';
  632. //print '</td>';
  633. // Fields from hook
  634. $parameters = array('arrayfields' => $arrayfields, 'object' => $objectline, 'obj' => $obj, 'i' => $i, 'totalarray' => &$totalarray);
  635. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $objectline); // Note that $action and $objectline may have been modified by hook
  636. print $hookmanager->resPrint;
  637. /*// Action column
  638. print '<td class="nowrap center">';
  639. print '</td>';*/
  640. if (!$i) {
  641. $totalarray['nbfield']++;
  642. }
  643. print '</tr>' . "\n";
  644. $i++;
  645. }
  646. // If no record found
  647. if ($num == 0) {
  648. $colspan = 1;
  649. foreach ($arrayfields as $key => $val) {
  650. if (!empty($val['checked'])) {
  651. $colspan++;
  652. }
  653. }
  654. print '<tr><td colspan="' . $colspan . '" class="opacitymedium">' . $langs->trans("NoRecordFound") . '</td></tr>';
  655. }
  656. $db->free($resql);
  657. $parameters = array('arrayfields' => $arrayfields, 'sql' => $sql);
  658. $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $objectline); // Note that $action and $objectline may have been modified by hook
  659. print $hookmanager->resPrint;
  660. print '</table>' . "\n";
  661. print '</div>' . "\n";
  662. print '</form>' . "\n";
  663. // if (in_array('builddoc', $arrayofmassactions) && ($nbtotalofrecords === '' || $nbtotalofrecords)) {
  664. // $hidegeneratedfilelistifempty = 1;
  665. // if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
  666. // $hidegeneratedfilelistifempty = 0;
  667. // }
  668. //
  669. // require_once DOL_DOCUMENT_ROOT . '/core/class/html.formfile.class.php';
  670. // $formfile = new FormFile($db);
  671. //
  672. // // Show list of available documents
  673. // $urlsource = $_SERVER['PHP_SELF'] . '?sortfield=' . $sortfield . '&sortorder=' . $sortorder;
  674. // $urlsource .= str_replace('&amp;', '&', $param);
  675. //
  676. // $filedir = $diroutputmassaction;
  677. // $genallowed = $permissiontoread;
  678. // $delallowed = $permissiontoadd;
  679. //
  680. // print $formfile->showdocuments('massfilesarea_hrm', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
  681. // }
  682. print '<div class="fichecenter"><div class="fichehalfleft">';
  683. // Show links to link elements
  684. $linktoelem = $form->showLinkToObjectBlock($object, null, array('skill'));
  685. $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
  686. print '</div><div class="fichehalfright">';
  687. $MAXEVENT = 10;
  688. $morehtmlcenter = dolGetButtonTitle($langs->trans('SeeAll'), '', 'fa fa-bars imgforviewmode', DOL_URL_ROOT.'/hrm/skill_agenda.php?id='.$object->id);
  689. // List of actions on element
  690. include_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php';
  691. $formactions = new FormActions($db);
  692. $somethingshown = $formactions->showactions($object, $object->element . '@' . $object->module, (is_object($object->thirdparty) ? $object->thirdparty->id : 0), 1, '', $MAXEVENT, '', $morehtmlcenter);
  693. print '</div></div>';
  694. }
  695. // End of page
  696. llxFooter();
  697. $db->close();