skill_card.php 33 KB

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