job_card.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475
  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/job_card.php
  23. * \ingroup hrm
  24. * \brief Page to create/edit/view job
  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/job.class.php';
  32. require_once DOL_DOCUMENT_ROOT . '/hrm/lib/hrm_job.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') : 'jobcard'; // 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 Job($db);
  47. $extrafields = new ExtraFields($db);
  48. $diroutputmassaction = $conf->hrm->dir_output . '/temp/massgeneration/' . $user->id;
  49. $hookmanager->initHooks(array('jobcard', '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] . '/job';
  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. /*
  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_buildpath('/hrm/job_list.php', 1);
  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_buildpath('/hrm/job_card.php', 1) . '?id=' . ($id > 0 ? $id : '__ID__');
  95. }
  96. }
  97. }
  98. $triggermodname = 'hrm_JOB_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. // Actions when linking object each other
  102. include DOL_DOCUMENT_ROOT . '/core/actions_dellink.inc.php';
  103. // Actions when printing a doc from card
  104. include DOL_DOCUMENT_ROOT . '/core/actions_printing.inc.php';
  105. // Action to move up and down lines of object
  106. //include DOL_DOCUMENT_ROOT.'/core/actions_lineupdown.inc.php';
  107. // Action to build doc
  108. include DOL_DOCUMENT_ROOT . '/core/actions_builddoc.inc.php';
  109. if ($action == 'set_thirdparty' && $permissiontoadd) {
  110. $object->setValueFrom('fk_soc', GETPOST('fk_soc', 'int'), '', '', 'date', '', $user, $triggermodname);
  111. }
  112. if ($action == 'classin' && $permissiontoadd) {
  113. $object->setProject(GETPOST('projectid', 'int'));
  114. }
  115. // Actions to send emails
  116. $triggersendname = 'hrm_JOB_SENTBYMAIL';
  117. $autocopy = 'MAIN_MAIL_AUTOCOPY_JOB_TO';
  118. $trackid = 'job' . $object->id;
  119. include DOL_DOCUMENT_ROOT . '/core/actions_sendmails.inc.php';
  120. }
  121. /*
  122. * View
  123. *
  124. * Put here all code to build page
  125. */
  126. $form = new Form($db);
  127. $formfile = new FormFile($db);
  128. $formproject = new FormProjets($db);
  129. $title = $langs->trans("Job");
  130. $help_url = '';
  131. llxHeader('', $title, $help_url);
  132. // Example : Adding jquery code
  133. // print '<script type="text/javascript" language="javascript">
  134. // jQuery(document).ready(function() {
  135. // function init_myfunc()
  136. // {
  137. // jQuery("#myid").removeAttr(\'disabled\');
  138. // jQuery("#myid").attr(\'disabled\',\'disabled\');
  139. // }
  140. // init_myfunc();
  141. // jQuery("#mybutton").click(function() {
  142. // init_myfunc();
  143. // });
  144. // });
  145. // </script>';
  146. // Part to create
  147. if ($action == 'create') {
  148. print load_fiche_titre($langs->trans("NewObject", $langs->transnoentities('Job')), '', 'object_' . $object->picto);
  149. print '<form method="POST" action="' . $_SERVER["PHP_SELF"] . '">';
  150. print '<input type="hidden" name="token" value="' . newToken() . '">';
  151. print '<input type="hidden" name="action" value="add">';
  152. if ($backtopage) {
  153. print '<input type="hidden" name="backtopage" value="' . $backtopage . '">';
  154. }
  155. if ($backtopageforcancel) {
  156. print '<input type="hidden" name="backtopageforcancel" value="' . $backtopageforcancel . '">';
  157. }
  158. print dol_get_fiche_head(array(), '');
  159. print '<table class="border centpercent tableforfieldcreate">' . "\n";
  160. // Common attributes
  161. include DOL_DOCUMENT_ROOT . '/core/tpl/commonfields_add.tpl.php';
  162. // Other attributes
  163. include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_add.tpl.php';
  164. print '</table>' . "\n";
  165. print dol_get_fiche_end();
  166. print '<div class="center">';
  167. print '<input type="submit" class="button" name="add" value="' . dol_escape_htmltag($langs->trans("Create")) . '">';
  168. print '&nbsp; ';
  169. print '<input type="' . ($backtopage ? "submit" : "button") . '" class="button button-cancel" name="cancel" value="' . dol_escape_htmltag($langs->trans("Cancel")) . '"' . ($backtopage ? '' : ' onclick="history.go(-1)"') . '>'; // Cancel for create does not post form if we don't know the backtopage
  170. print '</div>';
  171. print '</form>';
  172. //dol_set_focus('input[name="ref"]');
  173. }
  174. // Part to edit record
  175. if (($id || $ref) && $action == 'edit') {
  176. print load_fiche_titre($langs->trans("Job"), '', 'object_' . $object->picto);
  177. print '<form method="POST" action="' . $_SERVER["PHP_SELF"] . '">';
  178. print '<input type="hidden" name="token" value="' . newToken() . '">';
  179. print '<input type="hidden" name="action" value="update">';
  180. print '<input type="hidden" name="id" value="' . $object->id . '">';
  181. if ($backtopage) {
  182. print '<input type="hidden" name="backtopage" value="' . $backtopage . '">';
  183. }
  184. if ($backtopageforcancel) {
  185. print '<input type="hidden" name="backtopageforcancel" value="' . $backtopageforcancel . '">';
  186. }
  187. print dol_get_fiche_head();
  188. print '<table class="border centpercent tableforfieldedit">' . "\n";
  189. // Common attributes
  190. include DOL_DOCUMENT_ROOT . '/core/tpl/commonfields_edit.tpl.php';
  191. // Other attributes
  192. include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_edit.tpl.php';
  193. print '</table>';
  194. print dol_get_fiche_end();
  195. print '<div class="center"><input type="submit" class="button button-save" name="save" value="' . $langs->trans("Save") . '">';
  196. print ' &nbsp; <input type="submit" class="button button-cancel" name="cancel" value="' . $langs->trans("Cancel") . '">';
  197. print '</div>';
  198. print '</form>';
  199. }
  200. // Part to show record
  201. if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) {
  202. $res = $object->fetch_optionals();
  203. $head = jobPrepareHead($object);
  204. $picto = 'company.png';
  205. print dol_get_fiche_head($head, 'job_card', $langs->trans("Workstation"), -1, $object->picto);
  206. $formconfirm = '';
  207. // Confirmation to delete
  208. if ($action == 'delete') {
  209. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('DeleteJob'), $langs->trans('ConfirmDeleteObject'), 'confirm_delete', '', 0, 1);
  210. }
  211. // Confirmation to delete line
  212. if ($action == 'deleteline') {
  213. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id . '&lineid=' . $lineid, $langs->trans('DeleteLine'), $langs->trans('ConfirmDeleteLine'), 'confirm_deleteline', '', 0, 1);
  214. }
  215. // Clone confirmation
  216. if ($action == 'clone') {
  217. // Create an array for form
  218. $formquestion = array();
  219. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneAsk', $object->ref), 'confirm_clone', $formquestion, 'yes', 1);
  220. }
  221. // Confirmation of action xxxx
  222. if ($action == 'xxx') {
  223. $formquestion = array();
  224. /*
  225. $forcecombo=0;
  226. if ($conf->browser->name == 'ie') $forcecombo = 1; // There is a bug in IE10 that make combo inside popup crazy
  227. $formquestion = array(
  228. // 'text' => $langs->trans("ConfirmClone"),
  229. // array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1),
  230. // array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' => 1),
  231. // array('type' => 'other', 'name' => 'idwarehouse', 'label' => $langs->trans("SelectWarehouseForStockDecrease"), 'value' => $formproduct->selectWarehouses(GETPOST('idwarehouse')?GETPOST('idwarehouse'):'ifone', 'idwarehouse', '', 1, 0, 0, '', 0, $forcecombo))
  232. );
  233. */
  234. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('XXX'), $text, 'confirm_xxx', $formquestion, 0, 1, 220);
  235. }
  236. // Call Hook formConfirm
  237. $parameters = array('formConfirm' => $formconfirm, 'lineid' => $lineid);
  238. $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  239. if (empty($reshook)) {
  240. $formconfirm .= $hookmanager->resPrint;
  241. } elseif ($reshook > 0) {
  242. $formconfirm = $hookmanager->resPrint;
  243. }
  244. // Print form confirm
  245. print $formconfirm;
  246. // Object card
  247. // ------------------------------------------------------------
  248. $linkback = '<a href="' . dol_buildpath('/hrm/job_list.php', 1) . '?restore_lastsearch_values=1' . (!empty($socid) ? '&socid=' . $socid : '') . '">' . $langs->trans("BackToList") . '</a>';
  249. $morehtmlref = '<div class="refid">';
  250. $morehtmlref.= $object->label;
  251. $morehtmlref .= '</div>';
  252. dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'rowid', $morehtmlref);
  253. print '<div class="fichecenter">';
  254. print '<div class="fichehalfleft">';
  255. print '<div class="underbanner clearboth"></div>';
  256. print '<table class="border centpercent tableforfield">'."\n";
  257. // Common attributes
  258. //$keyforbreak='fieldkeytoswitchonsecondcolumn'; // We change column just before this field
  259. //unset($object->fields['fk_project']); // Hide field already shown in banner
  260. //unset($object->fields['fk_soc']); // Hide field already shown in banner
  261. $object->fields['label']['visible']=0; // Already in banner
  262. include DOL_DOCUMENT_ROOT . '/core/tpl/commonfields_view.tpl.php';
  263. // Other attributes. Fields from hook formObjectOptions and Extrafields.
  264. include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
  265. print '</table>';
  266. print '</div>';
  267. print '</div>';
  268. print '<div class="clearboth"></div>';
  269. print dol_get_fiche_end();
  270. /*
  271. * Lines
  272. */
  273. if (!empty($object->table_element_line)) {
  274. // Show object lines
  275. $result = $object->getLinesArray();
  276. print ' <form name="addproduct" id="addproduct" action="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . (($action != 'editline') ? '' : '#line_' . GETPOST('lineid', 'int')) . '" method="POST">
  277. <input type="hidden" name="token" value="' . newToken() . '">
  278. <input type="hidden" name="action" value="' . (($action != 'editline') ? 'addline' : 'updateline') . '">
  279. <input type="hidden" name="mode" value="">
  280. <input type="hidden" name="page_y" value="">
  281. <input type="hidden" name="id" value="' . $object->id . '">
  282. ';
  283. if (!empty($conf->use_javascript_ajax) && $object->status == 0) {
  284. include DOL_DOCUMENT_ROOT . '/core/tpl/ajaxrow.tpl.php';
  285. }
  286. print '<div class="div-table-responsive-no-min">';
  287. if (!empty($object->lines) || ($object->status == $object::STATUS_DRAFT && $permissiontoadd && $action != 'selectlines' && $action != 'editline')) {
  288. print '<table id="tablelines" class="noborder noshadow" width="100%">';
  289. }
  290. if (!empty($object->lines)) {
  291. $object->printObjectLines($action, $mysoc, null, GETPOST('lineid', 'int'), 1);
  292. }
  293. // Form to add new line
  294. if ($object->status == 0 && $permissiontoadd && $action != 'selectlines') {
  295. if ($action != 'editline') {
  296. // Add products/services form
  297. $parameters = array();
  298. $reshook = $hookmanager->executeHooks('formAddObjectLine', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  299. if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  300. if (empty($reshook))
  301. $object->formAddObjectLine(1, $mysoc, $soc);
  302. }
  303. }
  304. if (!empty($object->lines) || ($object->status == $object::STATUS_DRAFT && $permissiontoadd && $action != 'selectlines' && $action != 'editline')) {
  305. print '</table>';
  306. }
  307. print '</div>';
  308. print "</form>\n";
  309. }
  310. // Buttons for actions
  311. if ($action != 'presend' && $action != 'editline') {
  312. print '<div class="tabsAction">' . "\n";
  313. $parameters = array();
  314. $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  315. if ($reshook < 0) {
  316. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  317. }
  318. if (empty($reshook)) {
  319. // Back to draft
  320. if ($object->status == $object::STATUS_VALIDATED) {
  321. print dolGetButtonAction($langs->trans('SetToDraft'), '', 'default', $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&action=confirm_setdraft&confirm=yes&token=' . newToken(), '', $permissiontoadd);
  322. }
  323. print dolGetButtonAction($langs->trans('Modify'), '', 'default', $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&action=edit&token=' . newToken(), '', $permissiontoadd);
  324. // Delete (need delete permission, or if draft, just need create/modify permission)
  325. print dolGetButtonAction($langs->trans('Delete'), '', 'delete', $_SERVER['PHP_SELF'] . '?id=' . $object->id . '&action=delete&token=' . newToken(), '', $permissiontodelete);
  326. }
  327. print '</div>' . "\n";
  328. }
  329. // Select mail models is same action as presend
  330. if (GETPOST('modelselected')) {
  331. $action = 'presend';
  332. }
  333. if ($action != 'presend') {
  334. print '<div class="fichecenter"><div class="fichehalfleft">';
  335. print '<a name="builddoc"></a>'; // ancre
  336. $includedocgeneration = 0;
  337. // Documents
  338. if ($includedocgeneration) {
  339. $objref = dol_sanitizeFileName($object->ref);
  340. $relativepath = $objref . '/' . $objref . '.pdf';
  341. $filedir = $conf->hrm->dir_output . '/' . $object->element . '/' . $objref;
  342. $urlsource = $_SERVER["PHP_SELF"] . "?id=" . $object->id;
  343. $genallowed = $user->rights->hrm->job->read; // If you can read, you can build the PDF to read content
  344. $delallowed = $user->rights->hrm->job->write; // If you can create/edit, you can remove a file on card
  345. print $formfile->showdocuments('hrm:Job', $object->element . '/' . $objref, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', '', '', $langs->defaultlang);
  346. }
  347. // Show links to link elements
  348. $linktoelem = $form->showLinkToObjectBlock($object, null, array('job'));
  349. $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
  350. print '</div><div class="fichehalfright">';
  351. $MAXEVENT = 10;
  352. $morehtmlcenter = dolGetButtonTitle($langs->trans('SeeAll'), '', 'fa fa-bars imgforviewmode', DOL_URL_ROOT.'/hrm/job_agenda.php?id='.$object->id);
  353. // List of actions on element
  354. include_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php';
  355. $formactions = new FormActions($db);
  356. $somethingshown = $formactions->showactions($object, $object->element . '@' . $object->module, (is_object($object->thirdparty) ? $object->thirdparty->id : 0), 1, '', $MAXEVENT, '', $morehtmlcenter);
  357. print '</div></div>';
  358. }
  359. // Presend form
  360. $modelmail = 'job';
  361. $defaulttopic = 'InformationMessage';
  362. $diroutput = $conf->hrm->dir_output;
  363. $trackid = 'job' . $object->id;
  364. include DOL_DOCUMENT_ROOT . '/core/tpl/card_presend.tpl.php';
  365. }
  366. // End of page
  367. llxFooter();
  368. $db->close();