dolibarr 18.0.6
workstation_card.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 */
18
25// Load Dolibarr environment
26require '../main.inc.php';
27require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
28require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
29require_once DOL_DOCUMENT_ROOT.'/resource/class/html.formresource.class.php';
30require_once DOL_DOCUMENT_ROOT.'/resource/class/dolresource.class.php';
31require_once DOL_DOCUMENT_ROOT.'/workstation/class/workstation.class.php';
32require_once DOL_DOCUMENT_ROOT.'/workstation/class/workstationusergroup.class.php';
33require_once DOL_DOCUMENT_ROOT.'/workstation/lib/workstation_workstation.lib.php';
34
35// Load translation files required by the page
36$langs->loadLangs(array('mrp', 'other'));
37
38// Get parameters
39$id = GETPOST('id', 'int');
40$ref = GETPOST('ref', 'alpha');
41$action = GETPOST('action', 'aZ09');
42$confirm = GETPOST('confirm', 'alpha');
43$cancel = GETPOST('cancel', 'aZ09');
44$contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'workstationcard'; // To manage different context of search
45$backtopage = GETPOST('backtopage', 'alpha');
46$backtopageforcancel = GETPOST('backtopageforcancel', 'alpha');
47
48$groups = GETPOST('groups', 'array:int');
49$resources = GETPOST('resources', 'array:int');
50//$lineid = GETPOST('lineid', 'int');
51
52// Initialize technical objects
53$object = new Workstation($db);
54
55//$extrafields = new ExtraFields($db);
56$diroutputmassaction = $conf->workstation->dir_output.'/temp/massgeneration/'.$user->id;
57$hookmanager->initHooks(array('workstationcard', 'globalcard')); // Note that conf->hooks_modules contains array
58
59// Fetch optionals attributes and labels
60$extrafields->fetch_name_optionals_label($object->table_element);
61
62$search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
63
64// Initialize array of search criterias
65$search_all = GETPOST("search_all", 'alpha');
66$search = array();
67foreach ($object->fields as $key => $val) {
68 if (GETPOST('search_'.$key, 'alpha')) {
69 $search[$key] = GETPOST('search_'.$key, 'alpha');
70 }
71}
72
73if (empty($action) && empty($id) && empty($ref)) {
74 $action = 'view';
75}
76
77// Load object
78include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once.
79
80// Permissions
81$permissiontoread = $user->rights->workstation->workstation->read;
82$permissiontoadd = $user->rights->workstation->workstation->write; // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
83$permissiontodelete = $user->rights->workstation->workstation->delete || ($permissiontoadd && isset($object->status) && $object->status == $object::STATUS_DRAFT);
84$permissionnote = $user->rights->workstation->workstation->write; // Used by the include of actions_setnotes.inc.php
85$permissiondellink = $user->rights->workstation->workstation->write; // Used by the include of actions_dellink.inc.php
86
87$upload_dir = $conf->workstation->multidir_output[isset($object->entity) ? $object->entity : 1];
88
89// Security check
90$isdraft = 0;
91restrictedArea($user, $object->element, $object->id, $object->table_element, 'workstation', 'fk_soc', 'rowid', $isdraft);
92
93
94/*
95 * Actions
96 */
97
98$parameters = array();
99$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
100if ($reshook < 0) {
101 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
102}
103
104if (empty($reshook)) {
105 $error = 0;
106
107 $backurlforlist = dol_buildpath('/workstation/workstation_list.php', 1);
108
109 if (empty($backtopage) || ($cancel && empty($id))) {
110 if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) {
111 if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) {
112 $backtopage = $backurlforlist;
113 } else {
114 $backtopage = dol_buildpath('/workstation/workstation_card.php', 1).'?id='.($id > 0 ? $id : '__ID__');
115 }
116 }
117 }
118
119 $triggermodname = 'WORKSTATION_WORKSTATION_MODIFY'; // Name of trigger action code to execute when we modify record
120
121 // Actions cancel, add, update, update_extras, confirm_validate, confirm_delete, confirm_deleteline, confirm_clone, confirm_close, confirm_setdraft, confirm_reopen
122 include DOL_DOCUMENT_ROOT.'/core/actions_addupdatedelete.inc.php';
123
124 // Actions when linking object each other
125 include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php';
126
127 // Actions when printing a doc from card
128 include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
129
130 // Action to move up and down lines of object
131 //include DOL_DOCUMENT_ROOT.'/core/actions_lineupdown.inc.php';
132
133 // Action to build doc
134 include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
135
136 if ($action == 'confirm_enable' && $confirm == "yes" && $permissiontoadd) {
137 if (!empty($object->id)) {
138 $object->setStatus(1);
139 }
140 } elseif ($action == 'confirm_disable' && $confirm == "yes" && $permissiontoadd) {
141 if (!empty($object->id)) {
142 $object->setStatus(0);
143 }
144 }
145}
146
147
148
149/*
150 * View
151 */
152
153$form = new Form($db);
154$formfile = new FormFile($db);
155$formresource = new FormResource($db);
156
157$title = $langs->trans("Workstation");
158$help_url = 'EN:Module_Workstation';
159
160llxHeader('', $title, $help_url);
161
162// jquery code
163?>
164 <script type="text/javascript">
165
166 jQuery(document).ready(function() {
167 jQuery("#type").change(function() {
168 if($(this).val() === 'MACHINE') {
169 $('#usergroups').hide();
170 $('#nb_operators_required').parent('td').parent('tr').hide();
171 $('#wsresources').show();
172 } else if($(this).val() === 'HUMAN') {
173 $('#wsresources').hide();
174 $('#nb_operators_required').parent('td').parent('tr').show();
175 $('#usergroups').show();
176 }
177 else {
178 $('#usergroups').show();
179 $('#wsresources').show();
180 $('#nb_operators_required').parent('td').parent('tr').show();
181 }
182 });
183 jQuery("#type").trigger('change');
184 });
185
186 </script>
187<?php
188
189// Part to create
190if ($action == 'create') {
191 // Set default value of the property ref
192 $object->fields['ref']['default'] = $object->getNextNumRef();
193
194 print load_fiche_titre($langs->trans("NewObject", $langs->transnoentitiesnoconv("Workstation")), '', 'object_'.$object->picto);
195
196 print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
197 print '<input type="hidden" name="token" value="'.newToken().'">';
198 print '<input type="hidden" name="action" value="add">';
199 if ($backtopage) {
200 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
201 }
202 if ($backtopageforcancel) {
203 print '<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.'">';
204 }
205
206 print dol_get_fiche_head(array(), '');
207
208 print '<table class="border centpercent tableforfieldcreate">'."\n";
209
210 // Common attributes
211 include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_add.tpl.php';
212
213 print '<tr id="usergroups"';
214 print ' ><td>';
215 print $langs->trans('Groups');
216 print '</td>';
217 print '<td>';
218 print img_picto('', 'group');
219 print $form->select_dolgroups($groups, 'groups', 1, '', 0, '', '', $object->entity, true, 'quatrevingtpercent widthcentpercentminusx');
220 print '</td></tr>';
221
222 print '<tr id="wsresources"><td>';
223 print $langs->trans('Machines');
224 print '</td>';
225 print '<td>';
226 print img_picto('', 'resource');
227 print $formresource->select_resource_list($resources, 'resources', '', '', 0, '', '', $object->entity, true, 0, 'quatrevingtpercent widthcentpercentminusx', true);
228 print '</td></tr>';
229
230 // Other attributes
231 //include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php';
232
233 print '</table>'."\n";
234
235 print dol_get_fiche_end();
236
237 print $form->buttonsSaveCancel("Create");
238
239 print '</form>';
240
241 //dol_set_focus('input[name="ref"]');
242}
243
244// Part to edit record
245if (($id || $ref) && $action == 'edit') {
246 print load_fiche_titre($langs->trans("Workstation"), '', 'object_'.$object->picto);
247
248 print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
249 print '<input type="hidden" name="token" value="'.newToken().'">';
250 print '<input type="hidden" name="action" value="update">';
251 print '<input type="hidden" name="id" value="'.$object->id.'">';
252 if ($backtopage) {
253 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
254 }
255 if ($backtopageforcancel) {
256 print '<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.'">';
257 }
258
259 print dol_get_fiche_head();
260
261 print '<table class="border centpercent tableforfieldedit">'."\n";
262
263 // Common attributes
264 include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_edit.tpl.php';
265
266 print '<tr id="usergroups"';
267 print '><td>';
268 print $langs->trans('Groups');
269 print '</td>';
270 print '<td>';
271 print img_picto('', 'group');
272 print $form->select_dolgroups(empty($groups) ? $object->usergroups : $groups, 'groups', 1, '', 0, '', '', $object->entity, true, 'quatrevingtpercent widthcentpercentminusx');
273 print '</td></tr>';
274
275 print '<tr id="wsresources"><td>';
276 print $langs->trans('Machines');
277 print '</td>';
278 print '<td>';
279 print img_picto('', 'resource');
280 print $formresource->select_resource_list(empty($resources) ? $object->resources : $resources, 'resources', '', '', 0, '', '', $object->entity, true, 0, 'quatrevingtpercent widthcentpercentminusx', true);
281 print '</td></tr>';
282
283 // Other attributes
284 //include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_edit.tpl.php';
285
286 print '</table>';
287
288 print dol_get_fiche_end();
289
290 print $form->buttonsSaveCancel();
291
292 print '</form>';
293}
294
295// Part to show record
296if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) {
297 $res = $object->fetch_optionals();
298
299 $head = workstationPrepareHead($object);
300 print dol_get_fiche_head($head, 'card', $langs->trans("Workstation"), -1, $object->picto);
301
302 $formconfirm = '';
303
304 // Confirmation to delete
305 if ($action == 'delete') {
306 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteWorkstation'), $langs->trans('ConfirmDeleteObject'), 'confirm_delete', '', 0, 1);
307 }
308 // Clone confirmation
309 if ($action == 'clone') {
310 // Create an array for form
311 $formquestion = array();
312 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneAsk', $object->ref), 'confirm_clone', $formquestion, 'yes', 1);
313 }
314
315 // Confirmation of action xxxx
316 if ($action == 'enable') {
317 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('EnableAWorkstation'), $langs->trans("ConfirmEnableWorkstation", $object->ref), 'confirm_enable', $formquestion, 0, 1, 220);
318 } elseif ($action == 'disable') {
319 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DisableAWorkstation'), $langs->trans("ConfirmDisableWorkstation", $object->ref), 'confirm_disable', $formquestion, 0, 1, 220);
320 }
321
322 // Call Hook formConfirm
323 $parameters = array('formConfirm' => $formconfirm, 'lineid' => $lineid);
324 $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
325 if (empty($reshook)) {
326 $formconfirm .= $hookmanager->resPrint;
327 } elseif ($reshook > 0) {
328 $formconfirm = $hookmanager->resPrint;
329 }
330
331 // Print form confirm
332 print $formconfirm;
333
334
335 // Object card
336 // ------------------------------------------------------------
337 $linkback = '<a href="'.dol_buildpath('/workstation/workstation_list.php', 1).'?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
338
339 $morehtmlref = '<div class="refidno">';
340 /*
341 // Ref customer
342 $morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1);
343 $morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1);
344 // Thirdparty
345 $morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . (is_object($object->thirdparty) ? $object->thirdparty->getNomUrl(1) : '');
346 // Project
347 if (isModEnabled('project')) {
348 $langs->load("projects");
349 $morehtmlref .= '<br>'.$langs->trans('Project') . ' ';
350 if ($permissiontoadd) {
351 //if ($action != 'classify') $morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&token='.newToken().'&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> ';
352 $morehtmlref .= ' : ';
353 if ($action == 'classify') {
354 //$morehtmlref .= $form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 0, 1, '', 'maxwidth300');
355 $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
356 $morehtmlref .= '<input type="hidden" name="action" value="classin">';
357 $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
358 $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
359 $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
360 $morehtmlref .= '</form>';
361 } else {
362 $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1, '', 'maxwidth300');
363 }
364 } else {
365 if (! empty($object->fk_project)) {
366 $proj = new Project($db);
367 $proj->fetch($object->fk_project);
368 $morehtmlref .= ': '.$proj->getNomUrl();
369 } else {
370 $morehtmlref .= '';
371 }
372 }
373 }*/
374 $morehtmlref .= '</div>';
375
376
377 dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
378
379
380 print '<div class="fichecenter">';
381 print '<div class="fichehalfleft">';
382 print '<div class="underbanner clearboth"></div>';
383 print '<table class="border centpercent tableforfield">'."\n";
384
385 // Common attributes
386 //$keyforbreak='fieldkeytoswitchonsecondcolumn'; // We change column just before this field
387 //unset($object->fields['fk_project']); // Hide field already shown in banner
388 //unset($object->fields['fk_soc']); // Hide field already shown in banner
389 if ($object->type === 'MACHINE') {
390 $object->fields['nb_operators_required']['visible'] = 0;
391 }
392
393 include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_view.tpl.php';
394
395 // Groups
396 if ($object->type !== 'MACHINE') {
397 $toprint = array();
398 $g = new UserGroup($db);
399 foreach ($object->usergroups as $id_group) {
400 $g->fetch($id_group);
401 $toprint[] = '<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #bbb">' . $g->getNomUrl(1, '', 0, 'categtextwhite') . '</li>';
402 }
403
404 print '<tr><td>' . $langs->trans('Groups') . '</td><td>';
405 print '<div class="select2-container-multi-dolibarr"><ul class="select2-choices-dolibarr">' . implode(' ', $toprint) . '</ul></div>';
406 print '</td></tr>';
407 }
408
409 // Resources
410 if ($object->type !== 'HUMAN') {
411 $toprint = array();
412 $r = new Dolresource($db);
413 foreach ($object->resources as $id_resource) {
414 $r->fetch($id_resource);
415 $toprint[] = '<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #bbb">' . $r->getNomUrl(1, '', '', 0, 'categtextwhite') . '</li>';
416 }
417
418 print '<tr><td>' . $langs->trans('Machines') . '</td><td>';
419 print '<div class="select2-container-multi-dolibarr"><ul class="select2-choices-dolibarr">' . implode(' ', $toprint) . '</ul></div>';
420 print '</td></tr>';
421 }
422
423 // Other attributes. Fields from hook formObjectOptions and Extrafields.
424 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
425
426 print '</table>';
427 print '</div>';
428 print '</div>';
429
430 print '<div class="clearboth"></div>';
431
432 print dol_get_fiche_end();
433
434
435 // Buttons for actions
436
437 if ($action != 'presend' && $action != 'editline') {
438 print '<div class="tabsAction">'."\n";
439 $parameters = array();
440 $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
441 if ($reshook < 0) {
442 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
443 }
444
445 if (empty($reshook)) {
446 // Modify
447 if ($permissiontoadd) {
448 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=edit&token='.newToken().'">'.$langs->trans("Modify").'</a>'."\n";
449 } else {
450 print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans('Modify').'</a>'."\n";
451 }
452
453 // Clone
454 if ($permissiontoadd) {
455 print dolGetButtonAction($langs->trans("ToClone"), '', 'default', $_SERVER['PHP_SELF'].'?id='.$object->id.'&socid='.$object->socid.'&action=clone&object=workstation', 'clone', $permissiontoadd);
456 }
457
458 // Disable / Enable
459 if ($permissiontoadd) {
460 if ($object->status == $object::STATUS_ENABLED) {
461 print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=disable&token='.newToken().'">'.$langs->trans("Disable").'</a>'."\n";
462 } else {
463 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=enable&token='.newToken().'">'.$langs->trans("Enable").'</a>'."\n";
464 }
465 }
466
467 // Delete
468 print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', $permissiontodelete);
469 }
470 print '</div>'."\n";
471 }
472}
473
474// End of page
475llxFooter();
476$db->close();
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Definition wrapper.php:56
llxFooter()
Empty footer.
Definition wrapper.php:70
DAO Resource object.
Class to offer components to list and upload files.
Class to manage generation of HTML components Only common components must be here.
Class to manage forms for the module resource.
Class to manage user groups.
Class for Workstation.
dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='rowid', $fieldref='ref', $morehtmlref='', $moreparam='', $nodbprefix=0, $morehtmlleft='', $morehtmlstatus='', $onlybanner=0, $morehtmlright='')
Show tab footer of a card.
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dolGetButtonAction($label, $text='', $actionType='default', $url='', $id='', $userRight=1, $params=array())
Function dolGetButtonAction.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition repair.php:120
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.
workstationPrepareHead($object)
Prepare array of tabs for Workstation.