position_card.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  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/position_card.php
  23. * \ingroup hrm
  24. * \brief Page to create/edit/view job position
  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/position.class.php';
  32. require_once DOL_DOCUMENT_ROOT . '/hrm/class/job.class.php';
  33. require_once DOL_DOCUMENT_ROOT . '/hrm/lib/hrm_position.lib.php';
  34. //dol_include_once('/hrm/position.php');
  35. // Get Parameters
  36. $action = GETPOST('action', 'aZ09') ? GETPOST('action', 'aZ09') : 'view'; // The action 'add', 'create', 'edit', 'update', 'view', ...
  37. $backtopage = GETPOST('backtopage', 'alpha');
  38. $backtopageforcancel = GETPOST('backtopageforcancel', 'alpha');
  39. $id = GETPOST('id', 'int');
  40. // Initialize technical objects
  41. $form = new Form($db);
  42. $object = new Position($db);
  43. $res = $object->fetch($id);
  44. if ($res < 0) {
  45. dol_print_error($db, $object->error);
  46. }
  47. // Permissions
  48. $permissiontoread = $user->rights->hrm->all->read;
  49. $permissiontoadd = $user->rights->hrm->all->write; // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
  50. $permissiontodelete = $user->rights->hrm->all->delete;
  51. $permissiondellink = $user->rights->hrm->all->write; // Used by the include of actions_dellink.inc.php
  52. $upload_dir = $conf->hrm->multidir_output[isset($object->entity) ? $object->entity : 1] . '/position';
  53. // Security check (enable the most restrictive one)
  54. //if ($user->socid > 0) accessforbidden();
  55. //if ($user->socid > 0) $socid = $user->socid;
  56. //$isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
  57. //restrictedArea($user, $object->element, $object->id, $object->table_element, '', 'fk_soc', 'rowid', $isdraft);
  58. if (empty($conf->hrm->enabled)) accessforbidden();
  59. if (!$permissiontoread || ($action === 'create' && !$permissiontoadd)) accessforbidden();
  60. $langs->loadLangs(array("hrm", "other"));
  61. // Get parameters
  62. $id = GETPOST('id', 'int');
  63. $fk_job = GETPOST('fk_job', 'int');
  64. $ref = GETPOST('ref', 'alpha');
  65. $action = GETPOST('action', 'aZ09');
  66. $confirm = GETPOST('confirm', 'alpha');
  67. $cancel = GETPOST('cancel', 'aZ09');
  68. $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'positioncard'; // To manage different context of search
  69. $backtopage = GETPOST('backtopage', 'alpha');
  70. $backtopageforcancel = GETPOST('backtopageforcancel', 'alpha');
  71. // $lineid = GETPOST('lineid', 'int');
  72. // Initialize technical objects
  73. //$object = new Position($db);
  74. //$res = $object->fetch($id);
  75. /*if ($res < 0) {
  76. dol_print_error($db, &$object->error);
  77. }*/
  78. $extrafields = new ExtraFields($db);
  79. $diroutputmassaction = $conf->hrm->dir_output . '/temp/massgeneration/' . $user->id;
  80. $hookmanager->initHooks(array('positioncard', 'globalcard')); // Note that conf->hooks_modules contains array
  81. // Fetch optionals attributes and labels
  82. $extrafields->fetch_name_optionals_label($object->table_element);
  83. $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
  84. // Initialize array of search criterias
  85. $search_all = GETPOST("search_all", 'alpha');
  86. $search = array();
  87. foreach ($object->fields as $key => $val) {
  88. if (GETPOST('search_' . $key, 'alpha')) {
  89. $search[$key] = GETPOST('search_' . $key, 'alpha');
  90. }
  91. }
  92. if (empty($action) && empty($id) && empty($ref)) {
  93. $action = 'view';
  94. }
  95. // Load object
  96. include DOL_DOCUMENT_ROOT . '/core/actions_fetchobject.inc.php'; // Must be include, not include_once.
  97. /*
  98. * Actions
  99. */
  100. $parameters = array();
  101. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  102. if ($reshook < 0) {
  103. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  104. }
  105. if (empty($reshook)) {
  106. $error = 0;
  107. $backurlforlist = dol_buildpath('/hrm/position_list.php', 1);
  108. if (empty($backtopage) || ($cancel && empty($fk_job))) {
  109. if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) {
  110. if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) {
  111. $backtopage = $backurlforlist;
  112. } else {
  113. $backtopage = dol_buildpath('/hrm/position_card.php', 1) . '?id=' . ($id > 0 ? $id : '__ID__');
  114. }
  115. }
  116. }
  117. $triggermodname = 'hrm_POSITION_MODIFY'; // Name of trigger action code to execute when we modify record
  118. // Actions cancel, add, update, update_extras, confirm_validate, confirm_delete, confirm_deleteline, confirm_clone, confirm_close, confirm_setdraft, confirm_reopen
  119. include DOL_DOCUMENT_ROOT . '/core/actions_addupdatedelete.inc.php';
  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_POSITION_SENTBYMAIL';
  136. $autocopy = 'MAIN_MAIL_AUTOCOPY_POSITION_TO';
  137. $trackid = 'position' . $object->id;
  138. include DOL_DOCUMENT_ROOT . '/core/actions_sendmails.inc.php';
  139. }
  140. /*
  141. * View
  142. */
  143. displayPositionCard($object);
  144. /**
  145. * Show the card of a position
  146. *
  147. * @param Position $object Position object
  148. * @return void
  149. */
  150. function displayPositionCard(&$object)
  151. {
  152. global $user, $langs, $db, $conf, $extrafields, $hookmanager, $action, $permissiontoadd, $permissiontodelete;
  153. $id = $object->id;
  154. /*
  155. * View
  156. *
  157. * Put here all code to build page
  158. */
  159. $form = new Form($db);
  160. $formfile = new FormFile($db);
  161. $formproject = new FormProjets($db);
  162. $backtopage = GETPOST('backtopage', 'alpha');
  163. $backtopageforcancel = GETPOST('backtopageforcancel', 'alpha');
  164. $title = $langs->trans("Position");
  165. $help_url = '';
  166. llxHeader('', $title, $help_url);
  167. // Part to edit record
  168. if (($id || $ref) && $action == 'edit') {
  169. print load_fiche_titre($langs->trans("Position"), '', 'object_' . $object->picto);
  170. print '<form method="POST" action="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '">';
  171. print '<input type="hidden" name="token" value="' . newToken() . '">';
  172. print '<input type="hidden" name="action" value="update">';
  173. print '<input type="hidden" name="id" value="' . $object->id . '">';
  174. if ($backtopage) {
  175. print '<input type="hidden" name="backtopage" value="' . $backtopage . '">';
  176. }
  177. if ($backtopageforcancel) {
  178. print '<input type="hidden" name="backtopageforcancel" value="' . $backtopageforcancel . '">';
  179. }
  180. print dol_get_fiche_head();
  181. print '<table class="border centpercent tableforfieldedit">' . "\n";
  182. // Common attributes
  183. include DOL_DOCUMENT_ROOT . '/core/tpl/commonfields_edit.tpl.php';
  184. // Other attributes
  185. include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_edit.tpl.php';
  186. print '</table>';
  187. print dol_get_fiche_end();
  188. print '<div class="center"><input type="submit" class="button button-save" name="save" value="' . $langs->trans("Save") . '">';
  189. print ' &nbsp; <input type="submit" class="button button-cancel" name="cancel" value="' . $langs->trans("Cancel") . '">';
  190. print '</div>';
  191. print '</form>';
  192. }
  193. // Part to show record
  194. if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) {
  195. $res = $object->fetch_optionals();
  196. $head = positionCardPrepareHead($object);
  197. print dol_get_fiche_head($head, 'position', $langs->trans("Workstation"), -1, $object->picto);
  198. $formconfirm = '';
  199. // Confirmation to delete
  200. if ($action == 'delete') {
  201. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('DeletePosition'), $langs->trans('ConfirmDeleteObject'), 'confirm_delete', '', 0, 1);
  202. }
  203. // Call Hook formConfirm
  204. $parameters = array('formConfirm' => $formconfirm/*, 'lineid' => $lineid*/);
  205. $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  206. if (empty($reshook)) {
  207. $formconfirm .= $hookmanager->resPrint;
  208. } elseif ($reshook > 0) {
  209. $formconfirm = $hookmanager->resPrint;
  210. }
  211. // Print form confirm
  212. print $formconfirm;
  213. // Object card
  214. // ------------------------------------------------------------
  215. $linkback = '<a href="'.DOL_URL_ROOT.'/hrm/position_list.php">'.$langs->trans("BackToList").'</a>';
  216. $morehtmlref = '<div class="refidno">';
  217. $u_position = new User(($db));
  218. $u_position->fetch($object->fk_user);
  219. $morehtmlref .= ($u_position->id > 0 ? $u_position->getNomUrl(1) : $langs->trans('Employee').' : ');
  220. $job = new Job($db);
  221. $job->fetch($object->fk_job);
  222. $morehtmlref .= '<br>'.$langs->trans('JobProfile').' : '.$job->getNomUrl(1);
  223. $morehtmlref .= '</div>';
  224. dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'rowid', $morehtmlref);
  225. print '<div class="fichecenter">';
  226. print '<div class="fichehalfleft">';
  227. print '<div class="underbanner clearboth"></div>';
  228. print '<table class="border centpercent tableforfield">' . "\n";
  229. // Common attributes
  230. //$keyforbreak='fieldkeytoswitchonsecondcolumn'; // We change column just before this field
  231. //unset($object->fields['fk_project']); // Hide field already shown in banner
  232. //unset($object->fields['fk_soc']); // Hide field already shown in banner
  233. $object->fields['fk_user']['visible']=0; // Already in banner
  234. $object->fields['fk_job']['visible']=0; // Already in banner
  235. include DOL_DOCUMENT_ROOT . '/core/tpl/commonfields_view.tpl.php';
  236. // Other attributes. Fields from hook formObjectOptions and Extrafields.
  237. include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
  238. print '</table>';
  239. print '</div>';
  240. print '</div>';
  241. print '<div class="clearboth"></div>';
  242. print dol_get_fiche_end();
  243. /*
  244. * Action bar
  245. */
  246. print '<div class="tabsAction">';
  247. $parameters = array();
  248. $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  249. print dolGetButtonAction($langs->trans('Modify'), '', 'default', $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&action=edit&token=' . newToken(), '', $permissiontoadd);
  250. // Delete (need delete permission, or if draft, just need create/modify permission)
  251. print dolGetButtonAction($langs->trans('Delete'), '', 'delete', $_SERVER['PHP_SELF'] . '?id=' . $object->id . '&action=delete&token=' . newToken(), '', $permissiontodelete);
  252. }
  253. }
  254. //if ($action != 'presend') {
  255. // $formfile = new FormFile($db);
  256. // print '<div class="fichecenter"><div class="fichehalfleft">';
  257. //
  258. // if (empty($conf->global->SOCIETE_DISABLE_BUILDDOC)) {
  259. // print '<a name="builddoc"></a>'; // ancre
  260. //
  261. // /*
  262. // * Generated documents
  263. // */
  264. // $filedir = $conf->societe->multidir_output[$object->entity].'/'.$object->id;
  265. // $urlsource = $_SERVER["PHP_SELF"]."?socid=".$object->id;
  266. // $genallowed = $user->hasRight('societe', 'lire');
  267. // $delallowed = $user->hasRight('societe', 'creer');
  268. //
  269. // print $formfile->showdocuments('company', $object->id, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 0, 0, 0, 28, 0, 'entity='.$object->entity, 0, '', $object->default_lang);
  270. // }
  271. //
  272. //
  273. // print '</div><div class="fichehalfright">';
  274. //
  275. // $MAXEVENT = 10;
  276. //
  277. // $morehtmlright = dolGetButtonTitle($langs->trans('SeeAll'), '', 'fa fa-bars imgforviewmode', DOL_URL_ROOT.'/societe/agenda.php?socid='.$object->id);
  278. //
  279. // // List of actions on element
  280. // include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
  281. // $formactions = new FormActions($db);
  282. // $somethingshown = $formactions->showactions($object, '', $object->id, 1, '', $MAXEVENT, '', $morehtmlright); // Show all action for thirdparty
  283. //
  284. // print '</div></div>';
  285. //}
  286. print '</table>' . "\n";
  287. print '</div>' . "\n";
  288. print '</form>' . "\n";
  289. if ($action !== 'edit' && $action !== 'create') {
  290. print '<div class="fichecenter"><div class="fichehalfleft">';
  291. // Show links to link elements
  292. $linktoelem = $form->showLinkToObjectBlock($object, null, array('position'));
  293. $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
  294. print '</div><div class="fichehalfright">';
  295. $MAXEVENT = 10;
  296. $morehtmlcenter = dolGetButtonTitle($langs->trans('SeeAll'), '', 'fa fa-bars imgforviewmode', DOL_URL_ROOT.'/hrm/position_agenda.php?id='.$object->id);
  297. // List of actions on element
  298. include_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php';
  299. $formactions = new FormActions($db);
  300. $somethingshown = $formactions->showactions($object, $object->element . '@' . $object->module, (is_object($object->thirdparty) ? $object->thirdparty->id : 0), 1, '', $MAXEVENT, '', $morehtmlcenter);
  301. print '</div></div>';
  302. }
  303. // End of page
  304. llxFooter();
  305. $db->close();