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