skill_card.php 33 KB

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