workstation_card.php 18 KB

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