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