workstation_card.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476
  1. <?php
  2. /* Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  16. */
  17. /**
  18. * \file htdocs/workstation/workstation_card.php
  19. * \ingroup workstation
  20. * \brief Page to create/edit/view workstation
  21. */
  22. // Load Dolibarr environment
  23. require '../main.inc.php';
  24. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  25. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  26. require_once DOL_DOCUMENT_ROOT.'/resource/class/html.formresource.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/resource/class/dolresource.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/workstation/class/workstation.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/workstation/class/workstationusergroup.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/workstation/lib/workstation_workstation.lib.php';
  31. // Load translation files required by the page
  32. $langs->loadLangs(array('mrp', 'other'));
  33. // Get parameters
  34. $id = GETPOST('id', 'int');
  35. $ref = GETPOST('ref', 'alpha');
  36. $action = GETPOST('action', 'aZ09');
  37. $confirm = GETPOST('confirm', 'alpha');
  38. $cancel = GETPOST('cancel', 'aZ09');
  39. $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'workstationcard'; // To manage different context of search
  40. $backtopage = GETPOST('backtopage', 'alpha');
  41. $backtopageforcancel = GETPOST('backtopageforcancel', 'alpha');
  42. $groups = GETPOST('groups', 'array:int');
  43. $resources = GETPOST('resources', 'array:int');
  44. //$lineid = GETPOST('lineid', 'int');
  45. // Initialize technical objects
  46. $object = new Workstation($db);
  47. //$extrafields = new ExtraFields($db);
  48. $diroutputmassaction = $conf->workstation->dir_output.'/temp/massgeneration/'.$user->id;
  49. $hookmanager->initHooks(array('workstationcard', '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->workstation->workstation->read;
  68. $permissiontoadd = $user->rights->workstation->workstation->write; // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
  69. $permissiontodelete = $user->rights->workstation->workstation->delete || ($permissiontoadd && isset($object->status) && $object->status == $object::STATUS_DRAFT);
  70. $permissionnote = $user->rights->workstation->workstation->write; // Used by the include of actions_setnotes.inc.php
  71. $permissiondellink = $user->rights->workstation->workstation->write; // Used by the include of actions_dellink.inc.php
  72. $upload_dir = $conf->workstation->multidir_output[isset($object->entity) ? $object->entity : 1];
  73. // Security check
  74. $isdraft = 0;
  75. restrictedArea($user, $object->element, $object->id, $object->table_element, 'workstation', 'fk_soc', 'rowid', $isdraft);
  76. /*
  77. * Actions
  78. */
  79. $parameters = array();
  80. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  81. if ($reshook < 0) {
  82. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  83. }
  84. if (empty($reshook)) {
  85. $error = 0;
  86. $backurlforlist = dol_buildpath('/workstation/workstation_list.php', 1);
  87. if (empty($backtopage) || ($cancel && empty($id))) {
  88. if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) {
  89. if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) {
  90. $backtopage = $backurlforlist;
  91. } else {
  92. $backtopage = dol_buildpath('/workstation/workstation_card.php', 1).'?id='.($id > 0 ? $id : '__ID__');
  93. }
  94. }
  95. }
  96. $triggermodname = 'WORKSTATION_WORKSTATION_MODIFY'; // Name of trigger action code to execute when we modify record
  97. // Actions cancel, add, update, update_extras, confirm_validate, confirm_delete, confirm_deleteline, confirm_clone, confirm_close, confirm_setdraft, confirm_reopen
  98. include DOL_DOCUMENT_ROOT.'/core/actions_addupdatedelete.inc.php';
  99. // Actions when linking object each other
  100. include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php';
  101. // Actions when printing a doc from card
  102. include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
  103. // Action to move up and down lines of object
  104. //include DOL_DOCUMENT_ROOT.'/core/actions_lineupdown.inc.php';
  105. // Action to build doc
  106. include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
  107. if ($action == 'confirm_enable' && $confirm == "yes" && $permissiontoadd) {
  108. if (!empty($object->id)) {
  109. $object->setStatus(1);
  110. }
  111. } elseif ($action == 'confirm_disable' && $confirm == "yes" && $permissiontoadd) {
  112. if (!empty($object->id)) {
  113. $object->setStatus(0);
  114. }
  115. }
  116. }
  117. /*
  118. * View
  119. */
  120. $form = new Form($db);
  121. $formfile = new FormFile($db);
  122. $formresource = new FormResource($db);
  123. $title = $langs->trans("Workstation");
  124. $help_url = 'EN:Module_Workstation';
  125. llxHeader('', $title, $help_url);
  126. // jquery code
  127. ?>
  128. <script type="text/javascript">
  129. jQuery(document).ready(function() {
  130. jQuery("#type").change(function() {
  131. if($(this).val() === 'MACHINE') {
  132. $('#usergroups').hide();
  133. $('#nb_operators_required').parent('td').parent('tr').hide();
  134. $('#wsresources').show();
  135. } else if($(this).val() === 'HUMAN') {
  136. $('#wsresources').hide();
  137. $('#nb_operators_required').parent('td').parent('tr').show();
  138. $('#usergroups').show();
  139. }
  140. else {
  141. $('#usergroups').show();
  142. $('#wsresources').show();
  143. $('#nb_operators_required').parent('td').parent('tr').show();
  144. }
  145. });
  146. jQuery("#type").trigger('change');
  147. });
  148. </script>
  149. <?php
  150. // Part to create
  151. if ($action == 'create') {
  152. // Set default value of the property ref
  153. $object->fields['ref']['default'] = $object->getNextNumRef();
  154. print load_fiche_titre($langs->trans("NewObject", $langs->transnoentitiesnoconv("Workstation")), '', 'object_'.$object->picto);
  155. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  156. print '<input type="hidden" name="token" value="'.newToken().'">';
  157. print '<input type="hidden" name="action" value="add">';
  158. if ($backtopage) {
  159. print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
  160. }
  161. if ($backtopageforcancel) {
  162. print '<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.'">';
  163. }
  164. print dol_get_fiche_head(array(), '');
  165. print '<table class="border centpercent tableforfieldcreate">'."\n";
  166. // Common attributes
  167. include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_add.tpl.php';
  168. print '<tr id="usergroups"';
  169. print ' ><td>';
  170. print $langs->trans('Groups');
  171. print '</td>';
  172. print '<td>';
  173. print img_picto('', 'group');
  174. print $form->select_dolgroups($groups, 'groups', 1, '', 0, '', '', $object->entity, true, 'quatrevingtpercent widthcentpercentminusx');
  175. print '</td></tr>';
  176. print '<tr id="wsresources"><td>';
  177. print $langs->trans('Machines');
  178. print '</td>';
  179. print '<td>';
  180. print img_picto('', 'resource');
  181. print $formresource->select_resource_list($resources, 'resources', '', '', 0, '', '', $object->entity, true, 0, 'quatrevingtpercent widthcentpercentminusx', true);
  182. print '</td></tr>';
  183. // Other attributes
  184. //include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php';
  185. print '</table>'."\n";
  186. print dol_get_fiche_end();
  187. print $form->buttonsSaveCancel("Create");
  188. print '</form>';
  189. //dol_set_focus('input[name="ref"]');
  190. }
  191. // Part to edit record
  192. if (($id || $ref) && $action == 'edit') {
  193. print load_fiche_titre($langs->trans("Workstation"), '', 'object_'.$object->picto);
  194. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  195. print '<input type="hidden" name="token" value="'.newToken().'">';
  196. print '<input type="hidden" name="action" value="update">';
  197. print '<input type="hidden" name="id" value="'.$object->id.'">';
  198. if ($backtopage) {
  199. print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
  200. }
  201. if ($backtopageforcancel) {
  202. print '<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.'">';
  203. }
  204. print dol_get_fiche_head();
  205. print '<table class="border centpercent tableforfieldedit">'."\n";
  206. // Common attributes
  207. include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_edit.tpl.php';
  208. print '<tr id="usergroups"';
  209. print '><td>';
  210. print $langs->trans('Groups');
  211. print '</td>';
  212. print '<td>';
  213. print img_picto('', 'group');
  214. print $form->select_dolgroups(empty($groups) ? $object->usergroups : $groups, 'groups', 1, '', 0, '', '', $object->entity, true, 'quatrevingtpercent widthcentpercentminusx');
  215. print '</td></tr>';
  216. print '<tr id="wsresources"><td>';
  217. print $langs->trans('Machines');
  218. print '</td>';
  219. print '<td>';
  220. print img_picto('', 'resource');
  221. print $formresource->select_resource_list(empty($resources) ? $object->resources : $resources, 'resources', '', '', 0, '', '', $object->entity, true, 0, 'quatrevingtpercent widthcentpercentminusx', true);
  222. print '</td></tr>';
  223. // Other attributes
  224. //include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_edit.tpl.php';
  225. print '</table>';
  226. print dol_get_fiche_end();
  227. print $form->buttonsSaveCancel();
  228. print '</form>';
  229. }
  230. // Part to show record
  231. if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) {
  232. $res = $object->fetch_optionals();
  233. $head = workstationPrepareHead($object);
  234. print dol_get_fiche_head($head, 'card', $langs->trans("Workstation"), -1, $object->picto);
  235. $formconfirm = '';
  236. // Confirmation to delete
  237. if ($action == 'delete') {
  238. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteWorkstation'), $langs->trans('ConfirmDeleteObject'), 'confirm_delete', '', 0, 1);
  239. }
  240. // Clone confirmation
  241. if ($action == 'clone') {
  242. // Create an array for form
  243. $formquestion = array();
  244. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneAsk', $object->ref), 'confirm_clone', $formquestion, 'yes', 1);
  245. }
  246. // Confirmation of action xxxx
  247. if ($action == 'enable') {
  248. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('EnableAWorkstation'), $langs->trans("ConfirmEnableWorkstation", $object->ref), 'confirm_enable', $formquestion, 0, 1, 220);
  249. } elseif ($action == 'disable') {
  250. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DisableAWorkstation'), $langs->trans("ConfirmDisableWorkstation", $object->ref), 'confirm_disable', $formquestion, 0, 1, 220);
  251. }
  252. // Call Hook formConfirm
  253. $parameters = array('formConfirm' => $formconfirm, 'lineid' => $lineid);
  254. $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  255. if (empty($reshook)) {
  256. $formconfirm .= $hookmanager->resPrint;
  257. } elseif ($reshook > 0) {
  258. $formconfirm = $hookmanager->resPrint;
  259. }
  260. // Print form confirm
  261. print $formconfirm;
  262. // Object card
  263. // ------------------------------------------------------------
  264. $linkback = '<a href="'.dol_buildpath('/workstation/workstation_list.php', 1).'?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  265. $morehtmlref = '<div class="refidno">';
  266. /*
  267. // Ref customer
  268. $morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1);
  269. $morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1);
  270. // Thirdparty
  271. $morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . (is_object($object->thirdparty) ? $object->thirdparty->getNomUrl(1) : '');
  272. // Project
  273. if (isModEnabled('project')) {
  274. $langs->load("projects");
  275. $morehtmlref .= '<br>'.$langs->trans('Project') . ' ';
  276. if ($permissiontoadd) {
  277. //if ($action != 'classify') $morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&token='.newToken().'&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> ';
  278. $morehtmlref .= ' : ';
  279. if ($action == 'classify') {
  280. //$morehtmlref .= $form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 0, 1, '', 'maxwidth300');
  281. $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
  282. $morehtmlref .= '<input type="hidden" name="action" value="classin">';
  283. $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
  284. $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
  285. $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
  286. $morehtmlref .= '</form>';
  287. } else {
  288. $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1, '', 'maxwidth300');
  289. }
  290. } else {
  291. if (! empty($object->fk_project)) {
  292. $proj = new Project($db);
  293. $proj->fetch($object->fk_project);
  294. $morehtmlref .= ': '.$proj->getNomUrl();
  295. } else {
  296. $morehtmlref .= '';
  297. }
  298. }
  299. }*/
  300. $morehtmlref .= '</div>';
  301. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
  302. print '<div class="fichecenter">';
  303. print '<div class="fichehalfleft">';
  304. print '<div class="underbanner clearboth"></div>';
  305. print '<table class="border centpercent tableforfield">'."\n";
  306. // Common attributes
  307. //$keyforbreak='fieldkeytoswitchonsecondcolumn'; // We change column just before this field
  308. //unset($object->fields['fk_project']); // Hide field already shown in banner
  309. //unset($object->fields['fk_soc']); // Hide field already shown in banner
  310. if ($object->type === 'MACHINE') {
  311. $object->fields['nb_operators_required']['visible'] = 0;
  312. }
  313. include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_view.tpl.php';
  314. // Groups
  315. if ($object->type !== 'MACHINE') {
  316. $toprint = array();
  317. $g = new UserGroup($db);
  318. foreach ($object->usergroups as $id_group) {
  319. $g->fetch($id_group);
  320. $toprint[] = '<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #bbb">' . $g->getNomUrl(1, '', 0, 'categtextwhite') . '</li>';
  321. }
  322. print '<tr><td>' . $langs->trans('Groups') . '</td><td>';
  323. print '<div class="select2-container-multi-dolibarr"><ul class="select2-choices-dolibarr">' . implode(' ', $toprint) . '</ul></div>';
  324. print '</td></tr>';
  325. }
  326. // Resources
  327. if ($object->type !== 'HUMAN') {
  328. $toprint = array();
  329. $r = new Dolresource($db);
  330. foreach ($object->resources as $id_resource) {
  331. $r->fetch($id_resource);
  332. $toprint[] = '<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #bbb">' . $r->getNomUrl(1, '', '', 0, 'categtextwhite') . '</li>';
  333. }
  334. print '<tr><td>' . $langs->trans('Machines') . '</td><td>';
  335. print '<div class="select2-container-multi-dolibarr"><ul class="select2-choices-dolibarr">' . implode(' ', $toprint) . '</ul></div>';
  336. print '</td></tr>';
  337. }
  338. // Other attributes. Fields from hook formObjectOptions and Extrafields.
  339. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
  340. print '</table>';
  341. print '</div>';
  342. print '</div>';
  343. print '<div class="clearboth"></div>';
  344. print dol_get_fiche_end();
  345. // Buttons for actions
  346. if ($action != 'presend' && $action != 'editline') {
  347. print '<div class="tabsAction">'."\n";
  348. $parameters = array();
  349. $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  350. if ($reshook < 0) {
  351. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  352. }
  353. if (empty($reshook)) {
  354. // Modify
  355. if ($permissiontoadd) {
  356. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=edit&token='.newToken().'">'.$langs->trans("Modify").'</a>'."\n";
  357. } else {
  358. print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans('Modify').'</a>'."\n";
  359. }
  360. // Clone
  361. if ($permissiontoadd) {
  362. print dolGetButtonAction($langs->trans("ToClone"), '', 'default', $_SERVER['PHP_SELF'].'?id='.$object->id.'&socid='.$object->socid.'&action=clone&object=workstation', 'clone', $permissiontoadd);
  363. }
  364. // Disable / Enable
  365. if ($permissiontoadd) {
  366. if ($object->status == $object::STATUS_ENABLED) {
  367. print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=disable&token='.newToken().'">'.$langs->trans("Disable").'</a>'."\n";
  368. } else {
  369. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=enable&token='.newToken().'">'.$langs->trans("Enable").'</a>'."\n";
  370. }
  371. }
  372. // Delete
  373. print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', $permissiontodelete);
  374. }
  375. print '</div>'."\n";
  376. }
  377. }
  378. // End of page
  379. llxFooter();
  380. $db->close();