dolibarr 21.0.0-alpha
workstation.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2020 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
4 * Copyright (C) 2023-2024 Frédéric France <frederic.france@free.fr>
5 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
27// Put here all includes required by your class file
28require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
29
34{
38 public $module = 'workstation';
39
43 public $element = 'workstation';
44
48 public $table_element = 'workstation_workstation';
49
54 public $ismultientitymanaged = 1;
55
59 public $isextrafieldmanaged = 0;
60
64 public $picto = 'workstation';
65
66
67 const STATUS_DISABLED = 0;
68 const STATUS_ENABLED = 1;
69
70
97 // BEGIN MODULEBUILDER PROPERTIES
101 public $fields = array(
102 'rowid' => array('type' => 'integer', 'label' => 'TechnicalID', 'enabled' => 1, 'position' => 1, 'notnull' => 1, 'visible' => 0, 'noteditable' => 1, 'index' => 1, 'css' => 'left', 'comment' => "Id"),
103 'entity' => array('type' => 'integer', 'label' => 'Entity', 'enabled' => 1, 'visible' => 0, 'position' => 5, 'notnull' => 1, 'default' => '1', 'index' => 1),
104 'ref' => array('type' => 'varchar(128)', 'label' => 'Ref', 'enabled' => 1, 'position' => 10, 'notnull' => 1, 'visible' => 1, 'noteditable' => 0, 'default' => '', 'index' => 1, 'searchall' => 1, 'showoncombobox' => 1, 'comment' => "Reference of object", 'csslist' => 'nowraponall'),
105 'label' => array('type' => 'varchar(255)', 'label' => 'Label', 'enabled' => 1, 'position' => 30, 'notnull' => 1, 'visible' => 1, 'searchall' => 1, 'css' => 'minwidth300', 'csslist' => 'tdoverflowmax125', 'showoncombobox' => '2',),
106 'type' => array('type' => 'varchar(8)', 'label' => 'Type', 'enabled' => 1, 'position' => 32, 'default' => '1', 'notnull' => 1, 'visible' => 1, 'arrayofkeyval' => array('HUMAN' => 'Human', 'MACHINE' => 'Machine', 'BOTH' => 'HumanMachine'),),
107 'note_public' => array('type' => 'html', 'label' => 'NotePublic', 'enabled' => 1, 'position' => 61, 'notnull' => 0, 'visible' => 0,),
108 'note_private' => array('type' => 'html', 'label' => 'NotePrivate', 'enabled' => 1, 'position' => 62, 'notnull' => 0, 'visible' => 0,),
109 'date_creation' => array('type' => 'datetime', 'label' => 'DateCreation', 'enabled' => 1, 'position' => 500, 'notnull' => 1, 'visible' => -2, 'csslist' => 'nowraponall'),
110 'tms' => array('type' => 'timestamp', 'label' => 'DateModification', 'enabled' => 1, 'position' => 501, 'notnull' => 0, 'visible' => -2, 'csslist' => 'nowraponall'),
111 'fk_user_creat' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'UserAuthor', 'enabled' => 1, 'position' => 510, 'notnull' => 1, 'visible' => -2, 'foreignkey' => 'user.rowid',),
112 'fk_user_modif' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'UserModif', 'enabled' => 1, 'position' => 511, 'notnull' => -1, 'visible' => -2,),
113 'import_key' => array('type' => 'varchar(14)', 'label' => 'ImportId', 'enabled' => 1, 'position' => 512, 'notnull' => -1, 'visible' => -2,),
114 'nb_operators_required' => array('type' => 'integer', 'label' => 'NbOperatorsRequired', 'enabled' => 1, 'position' => 50, 'notnull' => 0, 'visible' => 1, 'css' => 'right', 'csslist' => 'maxwidth75imp'),
115 'thm_operator_estimated' => array('type' => 'double', 'help' => 'THMOperatorEstimatedHelp','label' => 'THMOperatorEstimated', 'enabled' => 1, 'position' => 50, 'notnull' => 0, 'visible' => 1, 'css' => 'right', 'csslist' => 'maxwidth75imp'),
116 'thm_machine_estimated' => array('type' => 'double', 'help' => 'THMMachineEstimatedHelp', 'label' => 'THMMachineEstimated', 'enabled' => 1, 'position' => 50, 'notnull' => 0, 'visible' => 1, 'css' => 'right', 'csslist' => 'maxwidth75imp'),
117 'status' => array('type' => 'smallint', 'label' => 'Status', 'enabled' => 1, 'position' => 1000, 'default' => '1', 'notnull' => 1, 'visible' => 1, 'index' => 1, 'arrayofkeyval' => array('0' => 'Disabled', '1' => 'Enabled'),),
118 );
119
123 public $rowid;
124
128 public $ref;
129
133 public $label;
134
138 public $type; // HUMAN, MACHINE, ...
139
143 public $fk_user_creat;
144
148 public $fk_user_modif;
149
153 public $status;
154
158 public $nb_operators_required;
159
163 public $thm_operator_estimated;
164
168 public $thm_machine_estimated;
169
170 // END MODULEBUILDER PROPERTIES
171
175 public $resources;
176
180 public $usergroups;
181
187 public function __construct(DoliDB $db)
188 {
189 global $conf, $langs;
190
191 require_once DOL_DOCUMENT_ROOT.'/workstation/class/workstationusergroup.class.php';
192 require_once DOL_DOCUMENT_ROOT.'/workstation/class/workstationresource.class.php';
193
194 $this->db = $db;
195
196 $this->ismultientitymanaged = 1;
197 $this->isextrafieldmanaged = 0;
198
199 if (!getDolGlobalString('MAIN_SHOW_TECHNICAL_ID') && isset($this->fields['rowid'])) {
200 $this->fields['rowid']['visible'] = 0;
201 }
202 if (empty($conf->multicompany->enabled) && isset($this->fields['entity'])) {
203 $this->fields['entity']['enabled'] = 0;
204 }
205
206 // Unset fields that are disabled
207 foreach ($this->fields as $key => $val) {
208 if (isset($val['enabled']) && empty($val['enabled'])) {
209 unset($this->fields[$key]);
210 }
211 }
212
213 // Translate some data of arrayofkeyval
214 if (is_object($langs)) {
215 foreach ($this->fields as $key => $val) {
216 if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
217 foreach ($val['arrayofkeyval'] as $key2 => $val2) {
218 $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
219 }
220 }
221 }
222 }
223 }
224
232 public function create(User $user, $notrigger = 0)
233 {
234 global $db;
235
236 $id = $this->createCommon($user, $notrigger);
237
238 // Usergroups
239 $groups = GETPOST('groups', 'array:int');
240 if (empty($groups)) {
241 $groups = $this->usergroups; // createFromClone
242 }
243 if (!empty($groups)) {
244 foreach ($groups as $id_group) {
245 $ws_usergroup = new WorkstationUserGroup($db);
246 $ws_usergroup->fk_workstation = $id;
247 $ws_usergroup->fk_usergroup = $id_group;
248 $ws_usergroup->createCommon($user);
249 $this->usergroups[] = $id_group;
250 }
251 }
252
253 // Resources
254 $resources = GETPOST('resources', 'array:int');
255 if (empty($resources)) {
256 $resources = $this->resources; // createFromClone
257 }
258 if (!empty($resources)) {
259 foreach ($resources as $id_resource) {
260 $ws_resource = new WorkstationResource($db);
261 $ws_resource->fk_workstation = $id;
262 $ws_resource->fk_resource = $id_resource;
263 $ws_resource->createCommon($user);
264 $this->resources[] = $id_resource;
265 }
266 }
267
268 return $id;
269 }
270
278 public function createFromClone(User $user, $fromid)
279 {
280 global $langs, $extrafields;
281 $error = 0;
282
283 dol_syslog(__METHOD__, LOG_DEBUG);
284
285 $object = new self($this->db);
286
287 $this->db->begin();
288
289 // Load source object
290 $result = $object->fetch($fromid);
291 if ($result > 0 && !empty($object->table_element_line)) {
292 $object->fetchLines();
293 }
294
295 // get lines so they will be clone
296 //foreach($this->lines as $line)
297 // $line->fetch_optionals();
298
299 // Reset some properties
300 unset($object->id);
301 unset($object->fk_user_creat);
302 unset($object->import_key);
303
304 // Clear fields
305 if (property_exists($object, 'ref')) {
306 $object->ref = empty($this->fields['ref']['default']) ? "Copy_Of_".$object->ref : $this->fields['ref']['default'];
307 }
308 if (property_exists($object, 'label')) {
309 $object->label = empty($this->fields['label']['default']) ? $langs->trans("CopyOf")." ".$object->label : $this->fields['label']['default'];
310 }
311 if (property_exists($object, 'status')) {
312 $object->status = self::STATUS_DISABLED;
313 }
314 if (property_exists($object, 'date_creation')) {
315 $object->date_creation = dol_now();
316 }
317 if (property_exists($object, 'date_modification')) {
318 $object->date_modification = null;
319 }
320 // ...
321 // Clear extrafields that are unique
322 if (is_array($object->array_options) && count($object->array_options) > 0) {
323 $extrafields->fetch_name_optionals_label($this->table_element);
324 foreach ($object->array_options as $key => $option) {
325 $shortkey = preg_replace('/options_/', '', $key);
326 if (!empty($extrafields->attributes[$this->table_element]['unique'][$shortkey])) {
327 //var_dump($key);
328 //var_dump($clonedObj->array_options[$key]); exit;
329 unset($object->array_options[$key]);
330 }
331 }
332 }
333
334 // Create clone
335 $object->context['createfromclone'] = 'createfromclone';
336 $result = $object->create($user);
337 if ($result < 0) {
338 $error++;
339 $this->error = $object->error;
340 $this->errors = $object->errors;
341 }
342
343 if (!$error) {
344 // copy internal contacts
345 if ($this->copy_linked_contact($object, 'internal') < 0) {
346 $error++;
347 }
348 }
349
350 if (!$error) {
351 // copy external contacts if same company
352 if (property_exists($this, 'socid') && $this->socid == $object->socid) {
353 if ($this->copy_linked_contact($object, 'external') < 0) {
354 $error++;
355 }
356 }
357 }
358
359 unset($object->context['createfromclone']);
360
361 // End
362 if (!$error) {
363 $this->db->commit();
364 return $object;
365 } else {
366 $this->db->rollback();
367 return -1;
368 }
369 }
370
378 public function fetch($id, $ref = null)
379 {
380 $result = $this->fetchCommon($id, $ref);
381
382 $this->usergroups = WorkstationUserGroup::getAllGroupsOfWorkstation($this->id);
383 $this->resources = WorkstationResource::getAllResourcesOfWorkstation($this->id);
384
385 if ($result > 0 && !empty($this->table_element_line)) {
386 $this->fetchLines();
387 }
388 return $result;
389 }
390
396 public function fetchLines()
397 {
398 $this->lines = array();
399
400 $result = $this->fetchLinesCommon();
401 return $result;
402 }
403
404
417 public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND')
418 {
419 dol_syslog(__METHOD__, LOG_DEBUG);
420
421 $records = array();
422
423 $sql = 'SELECT ';
424 $sql .= $this->getFieldList();
425 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
426 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
427 $sql .= ' WHERE t.entity IN ('.getEntity($this->element).')';
428 } else {
429 $sql .= ' WHERE 1 = 1';
430 }
431
432 // Manage filter
433 $errormessage = '';
434 $sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage);
435 if ($errormessage) {
436 $this->errors[] = $errormessage;
437 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
438 return -1;
439 }
440
441 if (!empty($sortfield)) {
442 $sql .= $this->db->order($sortfield, $sortorder);
443 }
444 if (!empty($limit)) {
445 $sql .= $this->db->plimit($limit, $offset);
446 }
447
448 $resql = $this->db->query($sql);
449 if ($resql) {
450 $num = $this->db->num_rows($resql);
451 $i = 0;
452 while ($i < ($limit ? min($limit, $num) : $num)) {
453 $obj = $this->db->fetch_object($resql);
454
455 $record = new self($this->db);
456 $record->setVarsFromFetchObj($obj);
457
458 $records[$record->id] = $record;
459
460 $i++;
461 }
462 $this->db->free($resql);
463
464 return $records;
465 } else {
466 $this->errors[] = 'Error '.$this->db->lasterror();
467 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
468
469 return -1;
470 }
471 }
472
480 public function update(User $user, $notrigger = 0)
481 {
482
483 // Usergroups
484 $groups = GETPOST('groups', 'array:int');
486 $this->usergroups = array();
487
488 foreach ($groups as $id_group) {
489 $ws_usergroup = new WorkstationUserGroup($this->db);
490 $ws_usergroup->fk_workstation = $this->id;
491 $ws_usergroup->fk_usergroup = $id_group;
492 $ws_usergroup->createCommon($user);
493 $this->usergroups[] = $id_group;
494 }
495
496 // Resources
497 $resources = GETPOST('resources', 'array:int');
499 $this->resources = array();
500 if (!empty($resources)) {
501 foreach ($resources as $id_resource) {
502 $ws_resource = new WorkstationResource($this->db);
503 $ws_resource->fk_workstation = $this->id;
504 $ws_resource->fk_resource = $id_resource;
505 $ws_resource->createCommon($user);
506 $this->resources[] = $id_resource;
507 }
508 }
509
510 return $this->updateCommon($user, $notrigger);
511 }
512
520 public function delete(User $user, $notrigger = 0)
521 {
522 return $this->deleteCommon($user, $notrigger);
523 //return $this->deleteCommon($user, $notrigger, 1);
524 }
525
534 public function deleteLine(User $user, $idline, $notrigger = 0)
535 {
536 if ($this->status < 0) {
537 $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
538 return -2;
539 }
540
541 return $this->deleteLineCommon($user, $idline, $notrigger);
542 }
543
551 public function setStatus($status, $notrigger = 0)
552 {
553 global $user;
554
555 $this->status = $status;
556
557 if (empty($status)) {
558 return $this->setDisabled($user, $notrigger);
559 } else {
560 return $this->setEnabled($user, $notrigger);
561 }
562 }
563
564
572 public function setEnabled($user, $notrigger = 0)
573 {
574 return $this->setStatusCommon($user, self::STATUS_ENABLED, $notrigger, 'WORKSTATION_ENABLED');
575 }
576
577
585 public function setDisabled($user, $notrigger = 0)
586 {
587 return $this->setStatusCommon($user, self::STATUS_DISABLED, $notrigger, 'WORKSTATION_DISABLED');
588 }
589
597 public function getTooltipContentArray($params)
598 {
599 global $conf, $langs;
600
601 $langs->load('mrp');
602
603 $datas = [];
604 $datas['picto'] = img_picto('', $this->picto).' <u>'.$langs->trans("Workstation").'</u>';
605 $datas['ref'] = '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref;
606 if (isset($this->status)) {
607 $datas['status'] = '<br><b>'.$langs->trans("Status").":</b> ".$this->getLibStatut(5);
608 }
609
610 return $datas;
611 }
612
623 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
624 {
625 global $conf, $langs, $hookmanager;
626
627 if (!empty($conf->dol_no_mouse_hover)) {
628 $notooltip = 1; // Force disable tooltips
629 }
630
631 $result = '';
632
633 $params = [
634 'id' => $this->id,
635 'objecttype' => $this->element,
636 ];
637 $classfortooltip = 'classfortooltip';
638 $dataparams = '';
639 if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
640 $classfortooltip = 'classforajaxtooltip';
641 $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"';
642 $label = '';
643 } else {
644 $label = implode($this->getTooltipContentArray($params));
645 }
646
647 $url = dol_buildpath('/workstation/workstation_card.php', 1).'?id='.$this->id;
648
649 if ($option != 'nolink') {
650 // Add param to save lastsearch_values or not
651 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
652 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
653 $add_save_lastsearch_values = 1;
654 }
655 if ($add_save_lastsearch_values) {
656 $url .= '&save_lastsearch_values=1';
657 }
658 }
659
660 $linkclose = '';
661 if (empty($notooltip)) {
662 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
663 $label = $langs->trans("ShowWorkstation");
664 $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
665 }
666 $linkclose .= ($label ? ' title="'.dol_escape_htmltag($label, 1).'"' : ' title="tocomplete"');
667 $linkclose .= $dataparams.' class="'.$classfortooltip.($morecss ? ' '.$morecss : '').'"';
668 } else {
669 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
670 }
671
672 $linkstart = '<a href="'.$url.'"';
673 $linkstart .= $linkclose.'>';
674 $linkend = '</a>';
675
676 $result .= $linkstart;
677
678 if (empty($this->showphoto_on_popup)) {
679 if ($withpicto) {
680 $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'mrp'), (($withpicto != 2) ? 'class="paddingright"' : ''), 0, 0, $notooltip ? 0 : 1);
681 }
682 } else {
683 if ($withpicto) {
684 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
685
686 list($class, $module) = explode('@', $this->picto);
687 $upload_dir = $conf->$module->multidir_output[$conf->entity]."/$class/".dol_sanitizeFileName($this->ref);
688 $filearray = dol_dir_list($upload_dir, "files");
689 $filename = $filearray[0]['name'];
690 if (!empty($filename)) {
691 $pospoint = strpos($filearray[0]['name'], '.');
692
693 $pathtophoto = $class.'/'.$this->ref.'/thumbs/'.substr($filename, 0, $pospoint).'_mini'.substr($filename, $pospoint);
694 if (!getDolGlobalString(strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS')) {
695 $result .= '<div class="floatleft inline-block valignmiddle divphotoref"><div class="photoref"><img class="photo'.$module.'" alt="No photo" border="0" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$module.'&entity='.$conf->entity.'&file='.urlencode($pathtophoto).'"></div></div>';
696 } else {
697 $result .= '<div class="floatleft inline-block valignmiddle divphotoref"><img class="photouserphoto userphoto" alt="No photo" border="0" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$module.'&entity='.$conf->entity.'&file='.urlencode($pathtophoto).'"></div>';
698 }
699
700 $result .= '</div>';
701 } else {
702 $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'mrp'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
703 }
704 }
705 }
706
707 if ($withpicto != 2) {
708 $result .= $this->ref;
709 }
710
711 $result .= $linkend;
712 //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
713
714 global $action, $hookmanager;
715 $hookmanager->initHooks(array('workstationdao'));
716 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
717 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
718 if ($reshook > 0) {
719 $result = $hookmanager->resPrint;
720 } else {
721 $result .= $hookmanager->resPrint;
722 }
723
724 return $result;
725 }
726
734 public function getKanbanView($option = '', $arraydata = null)
735 {
736 global $conf, $langs;
737
738 $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
739
740 $return = '<div class="box-flex-item box-flex-grow-zero">';
741 $return .= '<div class="info-box info-box-sm">';
742 $return .= '<span class="info-box-icon bg-infobox-action">';
743 $return .= img_picto('', $this->picto);
744 $return .= '</span>';
745 $return .= '<div class="info-box-content">';
746 $return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this, 'getNomUrl') ? $this->getNomUrl() : $this->ref).'</span>';
747 if ($selected >= 0) {
748 $return .= '<input id="cb'.$this->id.'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
749 }
750 if (property_exists($this, 'label')) {
751 $return .= ' <div class="inline-block opacitymedium valignmiddle tdoverflowmax100">'.$this->label.'</div>';
752 }
753 if (property_exists($this, 'thirdparty') && is_object($this->thirdparty)) {
754 $return .= '<br><div class="info-box-ref tdoverflowmax150">'.$this->thirdparty->getNomUrl(1).'</div>';
755 }
756 if (property_exists($this, 'amount')) {
757 $return .= '<br>';
758 $return .= '<span class="info-box-label amount">'.price($this->amount, 0, $langs, 1, -1, -1, $conf->currency).'</span>';
759 }
760 if (method_exists($this, 'getLibStatut')) {
761 $return .= '<br><div class="info-box-status">'.$this->getLibStatut(3).'</div>';
762 }
763 $return .= '</div>';
764 $return .= '</div>';
765 $return .= '</div>';
766
767 return $return;
768 }
769
776 public function getLibStatut($mode = 0)
777 {
778 return $this->LibStatut($this->status, $mode);
779 }
780
781 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
789 public function LibStatut($status, $mode = 0)
790 {
791 // phpcs:enable
792 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
793 global $langs;
794 //$langs->load("workstation");
795 $this->labelStatus[self::STATUS_DISABLED] = $langs->transnoentitiesnoconv('Disabled');
796 $this->labelStatus[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv('Enabled');
797 $this->labelStatusShort[self::STATUS_DISABLED] = $langs->transnoentitiesnoconv('Disabled');
798 $this->labelStatusShort[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv('Enabled');
799 }
800
801 $statusType = 'status'.$status;
802 //if ($status == self::STATUS_DISABLED) $statusType = 'status6';
803 if ($status == self::STATUS_ENABLED) {
804 $statusType = 'status4';
805 }
806
807 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
808 }
809
816 public function info($id)
817 {
818 $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
819 $sql .= ' fk_user_creat, fk_user_modif';
820 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
821 $sql .= ' WHERE t.rowid = '.((int) $id);
822 $result = $this->db->query($sql);
823 if ($result) {
824 if ($this->db->num_rows($result)) {
825 $obj = $this->db->fetch_object($result);
826
827 $this->id = $obj->rowid;
828
829 $this->user_creation_id = $obj->fk_user_creat;
830 $this->user_modification_id = $obj->fk_user_modif;
831 $this->date_creation = $this->db->jdate($obj->datec);
832 $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
833 }
834
835 $this->db->free($result);
836 } else {
837 dol_print_error($this->db);
838 }
839 }
840
847 public function initAsSpecimen()
848 {
849 return $this->initAsSpecimenCommon();
850 }
851
857 public function getNextNumRef()
858 {
859 global $langs, $conf;
860 $langs->load("workstation");
861
862 if (!getDolGlobalString('WORKSTATION_WORKSTATION_ADDON')) {
863 $conf->global->WORKSTATION_WORKSTATION_ADDON = 'mod_workstation_standard';
864 }
865
866 if (getDolGlobalString('WORKSTATION_WORKSTATION_ADDON')) {
867 $mybool = false;
868
869 $file = getDolGlobalString('WORKSTATION_WORKSTATION_ADDON') . ".php";
870 $classname = getDolGlobalString('WORKSTATION_WORKSTATION_ADDON');
871
872 // Include file with class
873 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
874 foreach ($dirmodels as $reldir) {
875 $dir = dol_buildpath($reldir."core/modules/workstation/");
876
877 // Load file with numbering class (if found)
878 if (file_exists($dir.$file)) {
879 $mybool = ((bool) @include_once $dir.$file) || $mybool;
880 }
881 }
882
883 if ($mybool === false) {
884 dol_print_error(null, "Failed to include file ".$file);
885 return '';
886 }
887
888 if (class_exists($classname)) {
889 $obj = new $classname();
890 $numref = $obj->getNextValue($this);
891
892 if ($numref != '' && $numref != '-1') {
893 return $numref;
894 } else {
895 $this->error = $obj->error;
896 //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
897 return "";
898 }
899 } else {
900 print $langs->trans("Error")." ".$langs->trans("ClassNotFound").' '.$classname;
901 return "";
902 }
903 } else {
904 print $langs->trans("ErrorNumberingModuleNotSetup", $this->element);
905 return "";
906 }
907 }
908
920 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
921 {
922 global $conf, $langs;
923
924 $result = 0;
925 $includedocgeneration = 0;
926
927 $langs->load("workstation");
928
929 if (!dol_strlen($modele)) {
930 $modele = 'standard_workstation';
931
932 if ($this->model_pdf) {
933 $modele = $this->model_pdf;
934 } elseif (getDolGlobalString('WORKSTATION_ADDON_PDF')) {
935 $modele = getDolGlobalString('WORKSTATION_ADDON_PDF');
936 }
937 }
938
939 $modelpath = "core/modules/workstation/doc/";
940
941 if ($includedocgeneration) {
942 $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
943 }
944
945 return $result;
946 }
947}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
print $langs trans("AuditedSecurityEvents").'</strong >< span class="opacitymedium"></span >< br > status
Or an array listing all the potential status of the object: array: int of the status => translated la...
Definition security.php:626
$object ref
Definition info.php:79
Parent class of all other business classes (invoices, contracts, proposals, orders,...
deleteLineCommon(User $user, $idline, $notrigger=0)
Delete a line of object in database.
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
createCommon(User $user, $notrigger=0)
Create object in the database.
getFieldList($alias='', $excludefields=array())
Function to concat keys of fields.
updateCommon(User $user, $notrigger=0)
Update object into database.
setStatusCommon($user, $status, $notrigger=0, $triggercode='')
Set to a status.
initAsSpecimenCommon()
Initialise object with example values Id must be 0 if object instance is a specimen.
copy_linked_contact($objFrom, $source='internal')
Copy contact from one element to current.
fetchLinesCommon($morewhere='', $noextrafields=0)
Load object in memory from the database.
fetchCommon($id, $ref=null, $morewhere='', $noextrafields=0)
Load object in memory from the database.
deleteCommon(User $user, $notrigger=0, $forcechilddeletion=0)
Delete object in database.
Class to manage Dolibarr database access.
Class to manage Dolibarr users.
Class for Workstation.
fetch($id, $ref=null)
Load object in memory from the database.
getNextNumRef()
Returns the reference to the following non used object depending on the active numbering module.
createFromClone(User $user, $fromid)
Clone an object into another one.
fetchLines()
Load object lines in memory from the database.
setEnabled($user, $notrigger=0)
Set draft status.
getTooltipContentArray($params)
getTooltipContentArray
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return a link to the object card (with optionally the picto)
getKanbanView($option='', $arraydata=null)
Return a thumb for kanban views.
create(User $user, $notrigger=0)
Create object into database.
setDisabled($user, $notrigger=0)
Set draft status.
deleteLine(User $user, $idline, $notrigger=0)
Delete a line of object in database.
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, $filter='', $filtermode='AND')
Load list of objects in memory from the database.
update(User $user, $notrigger=0)
Update object into database.
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk according to template module.
info($id)
Load the info information in the object.
getLibStatut($mode=0)
Return the label of the status.
__construct(DoliDB $db)
Constructor.
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
LibStatut($status, $mode=0)
Return the status.
setStatus($status, $notrigger=0)
Set draft status.
Class to link resource with Workstations.
static getAllResourcesOfWorkstation($fk_workstation)
Function used to get an array with all resources linked to a workstation.
static deleteAllResourcesOfWorkstation($fk_workstation)
Function used to remove all resources linked to a workstation.
Class to link User groups and Workstations.
static deleteAllGroupsOfWorkstation($fk_workstation)
Function used to remove all usergroups linked to a workstation.
static getAllGroupsOfWorkstation($fk_workstation)
Function used to get an array with all usergroups linked to a workstation.
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
Definition files.lib.php:63
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0)
forgeSQLFromUniversalSearchCriteria
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.