dolibarr 19.0.3
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 Frédéric France <frederic.france@netlogic.fr>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
26// Put here all includes required by your class file
27require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
28
33{
37 public $module = 'workstation';
38
42 public $element = 'workstation';
43
47 public $table_element = 'workstation_workstation';
48
53 public $ismultientitymanaged = 1;
54
58 public $isextrafieldmanaged = 0;
59
63 public $picto = 'workstation';
64
65
66 const STATUS_DISABLED = 0;
67 const STATUS_ENABLED = 1;
68
69
96 // BEGIN MODULEBUILDER PROPERTIES
100 public $fields=array(
101 'rowid' => array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>'1', 'position'=>1, 'notnull'=>1, 'visible'=>0, 'noteditable'=>'1', 'index'=>1, 'css'=>'left', 'comment'=>"Id"),
102 'entity' => array('type'=>'integer', 'label'=>'Entity', 'enabled'=>1, 'visible'=>0, 'position'=>5, 'notnull'=>1, 'default'=>'1', 'index'=>1),
103 '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'),
104 'label' => array('type'=>'varchar(255)', 'label'=>'Label', 'enabled'=>'1', 'position'=>30, 'notnull'=>1, 'visible'=>1, 'searchall'=>1, 'css'=>'minwidth300', 'csslist'=>'tdoverflowmax125', 'showoncombobox'=>'2',),
105 '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'),),
106 'note_public' => array('type'=>'html', 'label'=>'NotePublic', 'enabled'=>'1', 'position'=>61, 'notnull'=>0, 'visible'=>0,),
107 'note_private' => array('type'=>'html', 'label'=>'NotePrivate', 'enabled'=>'1', 'position'=>62, 'notnull'=>0, 'visible'=>0,),
108 'date_creation' => array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>'1', 'position'=>500, 'notnull'=>1, 'visible'=>-2, 'csslist'=>'nowraponall'),
109 'tms' => array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>'1', 'position'=>501, 'notnull'=>0, 'visible'=>-2, 'csslist'=>'nowraponall'),
110 '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',),
111 'fk_user_modif' => array('type'=>'integer:User:user/class/user.class.php', 'label'=>'UserModif', 'enabled'=>'1', 'position'=>511, 'notnull'=>-1, 'visible'=>-2,),
112 'import_key' => array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>'1', 'position'=>512, 'notnull'=>-1, 'visible'=>-2,),
113 'nb_operators_required' => array('type'=>'integer', 'label'=>'NbOperatorsRequired', 'enabled'=>'1', 'position'=>50, 'notnull'=>0, 'visible'=>1, 'css'=>'right', 'csslist'=>'maxwidth75imp'),
114 'thm_operator_estimated' => array('type'=>'double', 'help'=>'THMOperatorEstimatedHelp','label'=>'THMOperatorEstimated', 'enabled'=>'1', 'position'=>50, 'notnull'=>0, 'visible'=>1, 'css'=>'right', 'csslist'=>'maxwidth75imp'),
115 'thm_machine_estimated' => array('type'=>'double', 'help'=>'THMMachineEstimatedHelp', 'label'=>'THMMachineEstimated', 'enabled'=>'1', 'position'=>50, 'notnull'=>0, 'visible'=>1, 'css'=>'right', 'csslist'=>'maxwidth75imp'),
116 'status' => array('type'=>'smallint', 'label'=>'Status', 'enabled'=>'1', 'position'=>1000, 'default'=>1, 'notnull'=>1, 'visible'=>1, 'index'=>1, 'arrayofkeyval'=>array('0'=>'Disabled', '1'=>'Enabled'),),
117 );
118 public $rowid;
119 public $ref;
120 public $label;
121 public $type; // HUMAN, MACHINE, ...
122
123 public $date_creation;
124 public $tms;
125 public $fk_user_creat;
126 public $fk_user_modif;
127
131 public $status;
132 public $nb_operators_required;
133 public $thm_operator_estimated;
134 public $thm_machine_estimated;
135 // END MODULEBUILDER PROPERTIES
136
140 public $resources;
141
145 public $usergroups;
146
152 public function __construct(DoliDB $db)
153 {
154 global $conf, $langs;
155
156 require_once DOL_DOCUMENT_ROOT.'/workstation/class/workstationusergroup.class.php';
157 require_once DOL_DOCUMENT_ROOT.'/workstation/class/workstationresource.class.php';
158
159 $this->db = $db;
160
161 if (!getDolGlobalString('MAIN_SHOW_TECHNICAL_ID') && isset($this->fields['rowid'])) {
162 $this->fields['rowid']['visible'] = 0;
163 }
164 if (empty($conf->multicompany->enabled) && isset($this->fields['entity'])) {
165 $this->fields['entity']['enabled'] = 0;
166 }
167
168 // Unset fields that are disabled
169 foreach ($this->fields as $key => $val) {
170 if (isset($val['enabled']) && empty($val['enabled'])) {
171 unset($this->fields[$key]);
172 }
173 }
174
175 // Translate some data of arrayofkeyval
176 if (is_object($langs)) {
177 foreach ($this->fields as $key => $val) {
178 if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
179 foreach ($val['arrayofkeyval'] as $key2 => $val2) {
180 $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
181 }
182 }
183 }
184 }
185 }
186
194 public function create(User $user, $notrigger = false)
195 {
196 global $db;
197
198 $id = $this->createCommon($user, $notrigger);
199
200 // Usergroups
201 $groups = GETPOST('groups', 'array:int');
202 if (empty($groups)) {
203 $groups = $this->usergroups; // createFromClone
204 }
205 if (!empty($groups)) {
206 foreach ($groups as $id_group) {
207 $ws_usergroup = new WorkstationUserGroup($db);
208 $ws_usergroup->fk_workstation = $id;
209 $ws_usergroup->fk_usergroup = $id_group;
210 $ws_usergroup->createCommon($user);
211 $this->usergroups[] = $id_group;
212 }
213 }
214
215 // Resources
216 $resources = GETPOST('resources', 'array:int');
217 if (empty($resources)) {
218 $resources = $this->resources; // createFromClone
219 }
220 if (!empty($resources)) {
221 foreach ($resources as $id_resource) {
222 $ws_resource = new WorkstationResource($db);
223 $ws_resource->fk_workstation = $id;
224 $ws_resource->fk_resource = $id_resource;
225 $ws_resource->createCommon($user);
226 $this->resources[] = $id_resource;
227 }
228 }
229
230 return $id;
231 }
232
240 public function createFromClone(User $user, $fromid)
241 {
242 global $langs, $extrafields;
243 $error = 0;
244
245 dol_syslog(__METHOD__, LOG_DEBUG);
246
247 $object = new self($this->db);
248
249 $this->db->begin();
250
251 // Load source object
252 $result = $object->fetch($fromid);
253 if ($result > 0 && !empty($object->table_element_line)) {
254 $object->fetchLines();
255 }
256
257 // get lines so they will be clone
258 //foreach($this->lines as $line)
259 // $line->fetch_optionals();
260
261 // Reset some properties
262 unset($object->id);
263 unset($object->fk_user_creat);
264 unset($object->import_key);
265
266 // Clear fields
267 if (property_exists($object, 'ref')) {
268 $object->ref = empty($this->fields['ref']['default']) ? "Copy_Of_".$object->ref : $this->fields['ref']['default'];
269 }
270 if (property_exists($object, 'label')) {
271 $object->label = empty($this->fields['label']['default']) ? $langs->trans("CopyOf")." ".$object->label : $this->fields['label']['default'];
272 }
273 if (property_exists($object, 'status')) {
274 $object->status = self::STATUS_DISABLED;
275 }
276 if (property_exists($object, 'date_creation')) {
277 $object->date_creation = dol_now();
278 }
279 if (property_exists($object, 'date_modification')) {
280 $object->date_modification = null;
281 }
282 // ...
283 // Clear extrafields that are unique
284 if (is_array($object->array_options) && count($object->array_options) > 0) {
285 $extrafields->fetch_name_optionals_label($this->table_element);
286 foreach ($object->array_options as $key => $option) {
287 $shortkey = preg_replace('/options_/', '', $key);
288 if (!empty($extrafields->attributes[$this->table_element]['unique'][$shortkey])) {
289 //var_dump($key);
290 //var_dump($clonedObj->array_options[$key]); exit;
291 unset($object->array_options[$key]);
292 }
293 }
294 }
295
296 // Create clone
297 $object->context['createfromclone'] = 'createfromclone';
298 $result = $object->create($user);
299 if ($result < 0) {
300 $error++;
301 $this->error = $object->error;
302 $this->errors = $object->errors;
303 }
304
305 if (!$error) {
306 // copy internal contacts
307 if ($this->copy_linked_contact($object, 'internal') < 0) {
308 $error++;
309 }
310 }
311
312 if (!$error) {
313 // copy external contacts if same company
314 if (property_exists($this, 'socid') && $this->socid == $object->socid) {
315 if ($this->copy_linked_contact($object, 'external') < 0) {
316 $error++;
317 }
318 }
319 }
320
321 unset($object->context['createfromclone']);
322
323 // End
324 if (!$error) {
325 $this->db->commit();
326 return $object;
327 } else {
328 $this->db->rollback();
329 return -1;
330 }
331 }
332
340 public function fetch($id, $ref = null)
341 {
342 $result = $this->fetchCommon($id, $ref);
343
344 $this->usergroups = WorkstationUserGroup::getAllGroupsOfWorkstation($this->id);
345 $this->resources = WorkstationResource::getAllResourcesOfWorkstation($this->id);
346
347 if ($result > 0 && !empty($this->table_element_line)) {
348 $this->fetchLines();
349 }
350 return $result;
351 }
352
358 public function fetchLines()
359 {
360 $this->lines = array();
361
362 $result = $this->fetchLinesCommon();
363 return $result;
364 }
365
366
378 public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND')
379 {
380 global $conf;
381
382 dol_syslog(__METHOD__, LOG_DEBUG);
383
384 $records = array();
385
386 $sql = 'SELECT ';
387 $sql .= $this->getFieldList();
388 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
389 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
390 $sql .= ' WHERE t.entity IN ('.getEntity($this->element).')';
391 } else {
392 $sql .= ' WHERE 1 = 1';
393 }
394 // Manage filter
395 $sqlwhere = array();
396 if (count($filter) > 0) {
397 foreach ($filter as $key => $value) {
398 if ($key == 't.rowid') {
399 $sqlwhere[] = $key." = ".((int) $value);
400 } elseif (array_key_exists($key, $this->fields) && in_array($this->fields[$key]['type'], array('date', 'datetime', 'timestamp'))) {
401 $sqlwhere[] = $key." = '".$this->db->idate($value)."'";
402 } elseif ($key == 'customsql') {
403 $sqlwhere[] = $value;
404 } elseif (strpos($value, '%') === false) {
405 $sqlwhere[] = $key." IN (".$this->db->sanitize($this->db->escape($value)).")";
406 } else {
407 $sqlwhere[] = $key." LIKE '%".$this->db->escape($value)."%'";
408 }
409 }
410 }
411 if (count($sqlwhere) > 0) {
412 $sql .= ' AND ('.implode(' '.$this->db->escape($filtermode).' ', $sqlwhere).')';
413 }
414
415 if (!empty($sortfield)) {
416 $sql .= $this->db->order($sortfield, $sortorder);
417 }
418 if (!empty($limit)) {
419 $sql .= $this->db->plimit($limit, $offset);
420 }
421
422 $resql = $this->db->query($sql);
423 if ($resql) {
424 $num = $this->db->num_rows($resql);
425 $i = 0;
426 while ($i < ($limit ? min($limit, $num) : $num)) {
427 $obj = $this->db->fetch_object($resql);
428
429 $record = new self($this->db);
430 $record->setVarsFromFetchObj($obj);
431
432 $records[$record->id] = $record;
433
434 $i++;
435 }
436 $this->db->free($resql);
437
438 return $records;
439 } else {
440 $this->errors[] = 'Error '.$this->db->lasterror();
441 dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
442
443 return -1;
444 }
445 }
446
454 public function update(User $user, $notrigger = false)
455 {
456
457 // Usergroups
458 $groups = GETPOST('groups', 'array:int');
460 $this->usergroups=array();
461
462 foreach ($groups as $id_group) {
463 $ws_usergroup = new WorkstationUserGroup($this->db);
464 $ws_usergroup->fk_workstation = $this->id;
465 $ws_usergroup->fk_usergroup = $id_group;
466 $ws_usergroup->createCommon($user);
467 $this->usergroups[] = $id_group;
468 }
469
470 // Resources
471 $resources = GETPOST('resources', 'array:int');
473 $this->resources=array();
474 if (!empty($resources)) {
475 foreach ($resources as $id_resource) {
476 $ws_resource = new WorkstationResource($this->db);
477 $ws_resource->fk_workstation = $this->id;
478 $ws_resource->fk_resource = $id_resource;
479 $ws_resource->createCommon($user);
480 $this->resources[] = $id_resource;
481 }
482 }
483
484 return $this->updateCommon($user, $notrigger);
485 }
486
494 public function delete(User $user, $notrigger = false)
495 {
496 return $this->deleteCommon($user, $notrigger);
497 //return $this->deleteCommon($user, $notrigger, 1);
498 }
499
508 public function deleteLine(User $user, $idline, $notrigger = false)
509 {
510 if ($this->status < 0) {
511 $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
512 return -2;
513 }
514
515 return $this->deleteLineCommon($user, $idline, $notrigger);
516 }
517
525 public function setStatus($status, $notrigger = 0)
526 {
527 global $user;
528
529 $this->status = $status;
530
531 if (empty($status)) {
532 return $this->setDisabled($user, $notrigger);
533 } else {
534 return $this->setEnabled($user, $notrigger);
535 }
536 }
537
538
546 public function setEnabled($user, $notrigger = 0)
547 {
548 return $this->setStatusCommon($user, self::STATUS_ENABLED, $notrigger, 'WORKSTATION_ENABLED');
549 }
550
551
559 public function setDisabled($user, $notrigger = 0)
560 {
561 return $this->setStatusCommon($user, self::STATUS_DISABLED, $notrigger, 'WORKSTATION_DISABLED');
562 }
563
571 public function getTooltipContentArray($params)
572 {
573 global $conf, $langs;
574
575 $langs->load('mrp');
576
577 $datas = [];
578 $datas['picto'] = img_picto('', $this->picto).' <u>'.$langs->trans("Workstation").'</u>';
579 $datas['ref'] = '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref;
580 if (isset($this->status)) {
581 $datas['status'] = '<br><b>'.$langs->trans("Status").":</b> ".$this->getLibStatut(5);
582 }
583
584 return $datas;
585 }
586
597 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
598 {
599 global $conf, $langs, $hookmanager;
600
601 if (!empty($conf->dol_no_mouse_hover)) {
602 $notooltip = 1; // Force disable tooltips
603 }
604
605 $result = '';
606
607 $params = [
608 'id' => $this->id,
609 'objecttype' => $this->element,
610 ];
611 $classfortooltip = 'classfortooltip';
612 $dataparams = '';
613 if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
614 $classfortooltip = 'classforajaxtooltip';
615 $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"';
616 $label = '';
617 } else {
618 $label = implode($this->getTooltipContentArray($params));
619 }
620
621 $url = dol_buildpath('/workstation/workstation_card.php', 1).'?id='.$this->id;
622
623 if ($option != 'nolink') {
624 // Add param to save lastsearch_values or not
625 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
626 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
627 $add_save_lastsearch_values = 1;
628 }
629 if ($add_save_lastsearch_values) {
630 $url .= '&save_lastsearch_values=1';
631 }
632 }
633
634 $linkclose = '';
635 if (empty($notooltip)) {
636 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
637 $label = $langs->trans("ShowWorkstation");
638 $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
639 }
640 $linkclose .= ($label ? ' title="'.dol_escape_htmltag($label, 1).'"' : ' title="tocomplete"');
641 $linkclose .= $dataparams.' class="'.$classfortooltip.($morecss ? ' '.$morecss : '').'"';
642 } else {
643 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
644 }
645
646 $linkstart = '<a href="'.$url.'"';
647 $linkstart .= $linkclose.'>';
648 $linkend = '</a>';
649
650 $result .= $linkstart;
651
652 if (empty($this->showphoto_on_popup)) {
653 if ($withpicto) {
654 $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'mrp'), (($withpicto != 2) ? 'class="paddingright"' : ''), 0, 0, $notooltip ? 0 : 1);
655 }
656 } else {
657 if ($withpicto) {
658 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
659
660 list($class, $module) = explode('@', $this->picto);
661 $upload_dir = $conf->$module->multidir_output[$conf->entity]."/$class/".dol_sanitizeFileName($this->ref);
662 $filearray = dol_dir_list($upload_dir, "files");
663 $filename = $filearray[0]['name'];
664 if (!empty($filename)) {
665 $pospoint = strpos($filearray[0]['name'], '.');
666
667 $pathtophoto = $class.'/'.$this->ref.'/thumbs/'.substr($filename, 0, $pospoint).'_mini'.substr($filename, $pospoint);
668 if (!getDolGlobalString(strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS')) {
669 $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>';
670 } else {
671 $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>';
672 }
673
674 $result .= '</div>';
675 } else {
676 $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);
677 }
678 }
679 }
680
681 if ($withpicto != 2) {
682 $result .= $this->ref;
683 }
684
685 $result .= $linkend;
686 //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
687
688 global $action, $hookmanager;
689 $hookmanager->initHooks(array('workstationdao'));
690 $parameters = array('id'=>$this->id, 'getnomurl' => &$result);
691 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
692 if ($reshook > 0) {
693 $result = $hookmanager->resPrint;
694 } else {
695 $result .= $hookmanager->resPrint;
696 }
697
698 return $result;
699 }
700
708 public function getKanbanView($option = '', $arraydata = null)
709 {
710 global $conf, $langs;
711
712 $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
713
714 $return = '<div class="box-flex-item box-flex-grow-zero">';
715 $return .= '<div class="info-box info-box-sm">';
716 $return .= '<span class="info-box-icon bg-infobox-action">';
717 $return .= img_picto('', $this->picto);
718 $return .= '</span>';
719 $return .= '<div class="info-box-content">';
720 $return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this, 'getNomUrl') ? $this->getNomUrl() : $this->ref).'</span>';
721 if ($selected >= 0) {
722 $return .= '<input id="cb'.$this->id.'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
723 }
724 if (property_exists($this, 'label')) {
725 $return .= ' <div class="inline-block opacitymedium valignmiddle tdoverflowmax100">'.$this->label.'</div>';
726 }
727 if (property_exists($this, 'thirdparty') && is_object($this->thirdparty)) {
728 $return .= '<br><div class="info-box-ref tdoverflowmax150">'.$this->thirdparty->getNomUrl(1).'</div>';
729 }
730 if (property_exists($this, 'amount')) {
731 $return .= '<br>';
732 $return .= '<span class="info-box-label amount">'.price($this->amount, 0, $langs, 1, -1, -1, $conf->currency).'</span>';
733 }
734 if (method_exists($this, 'getLibStatut')) {
735 $return .= '<br><div class="info-box-status">'.$this->getLibStatut(3).'</div>';
736 }
737 $return .= '</div>';
738 $return .= '</div>';
739 $return .= '</div>';
740
741 return $return;
742 }
743
750 public function getLibStatut($mode = 0)
751 {
752 return $this->LibStatut($this->status, $mode);
753 }
754
755 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
763 public function LibStatut($status, $mode = 0)
764 {
765 // phpcs:enable
766 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
767 global $langs;
768 //$langs->load("workstation");
769 $this->labelStatus[self::STATUS_DISABLED] = $langs->transnoentitiesnoconv('Disabled');
770 $this->labelStatus[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv('Enabled');
771 $this->labelStatusShort[self::STATUS_DISABLED] = $langs->transnoentitiesnoconv('Disabled');
772 $this->labelStatusShort[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv('Enabled');
773 }
774
775 $statusType = 'status'.$status;
776 //if ($status == self::STATUS_DISABLED) $statusType = 'status6';
777 if ($status == self::STATUS_ENABLED) {
778 $statusType = 'status4';
779 }
780
781 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
782 }
783
790 public function info($id)
791 {
792 $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
793 $sql .= ' fk_user_creat, fk_user_modif';
794 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
795 $sql .= ' WHERE t.rowid = '.((int) $id);
796 $result = $this->db->query($sql);
797 if ($result) {
798 if ($this->db->num_rows($result)) {
799 $obj = $this->db->fetch_object($result);
800
801 $this->id = $obj->rowid;
802
803 $this->user_creation_id = $obj->fk_user_creat;
804 $this->user_modification_id = $obj->fk_user_modif;
805 $this->date_creation = $this->db->jdate($obj->datec);
806 $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
807 }
808
809 $this->db->free($result);
810 } else {
811 dol_print_error($this->db);
812 }
813 }
814
821 public function initAsSpecimen()
822 {
823 $this->initAsSpecimenCommon();
824 }
825
831 public function getNextNumRef()
832 {
833 global $langs, $conf;
834 $langs->load("workstation");
835
836 if (!getDolGlobalString('WORKSTATION_WORKSTATION_ADDON')) {
837 $conf->global->WORKSTATION_WORKSTATION_ADDON = 'mod_workstation_standard';
838 }
839
840 if (getDolGlobalString('WORKSTATION_WORKSTATION_ADDON')) {
841 $mybool = false;
842
843 $file = getDolGlobalString('WORKSTATION_WORKSTATION_ADDON') . ".php";
844 $classname = $conf->global->WORKSTATION_WORKSTATION_ADDON;
845
846 // Include file with class
847 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
848 foreach ($dirmodels as $reldir) {
849 $dir = dol_buildpath($reldir."core/modules/workstation/");
850
851 // Load file with numbering class (if found)
852 if (file_exists($dir.$file)) {
853 $mybool |= @include_once $dir.$file;
854 }
855 }
856
857 if ($mybool === false) {
858 dol_print_error('', "Failed to include file ".$file);
859 return '';
860 }
861
862 if (class_exists($classname)) {
863 $obj = new $classname();
864 $numref = $obj->getNextValue($this);
865
866 if ($numref != '' && $numref != '-1') {
867 return $numref;
868 } else {
869 $this->error = $obj->error;
870 //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
871 return "";
872 }
873 } else {
874 print $langs->trans("Error")." ".$langs->trans("ClassNotFound").' '.$classname;
875 return "";
876 }
877 } else {
878 print $langs->trans("ErrorNumberingModuleNotSetup", $this->element);
879 return "";
880 }
881 }
882
894 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
895 {
896 global $conf, $langs;
897
898 $result = 0;
899 $includedocgeneration = 0;
900
901 $langs->load("workstation");
902
903 if (!dol_strlen($modele)) {
904 $modele = 'standard_workstation';
905
906 if ($this->model_pdf) {
907 $modele = $this->model_pdf;
908 } elseif (getDolGlobalString('WORKSTATION_ADDON_PDF')) {
909 $modele = $conf->global->WORKSTATION_ADDON_PDF;
910 }
911 }
912
913 $modelpath = "core/modules/workstation/doc/";
914
915 if ($includedocgeneration) {
916 $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
917 }
918
919 return $result;
920 }
921}
print $langs trans("AuditedSecurityEvents").'</strong >< span class="opacitymedium"></span >< br > status
Definition security.php:604
$object ref
Definition info.php:79
Parent class of all other business classes (invoices, contracts, proposals, orders,...
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
deleteLineCommon(User $user, $idline, $notrigger=false)
Delete a line of object in database.
createCommon(User $user, $notrigger=false)
Create object into database.
deleteCommon(User $user, $notrigger=false, $forcechilddeletion=0)
Delete object in database.
getFieldList($alias='', $excludefields=array())
Function to concat keys of fields.
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.
updateCommon(User $user, $notrigger=false)
Update object into database.
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.
Class to manage Dolibarr database access.
Class to manage Dolibarr users.
Class for Workstation.
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, array $filter=array(), $filtermode='AND')
Load list of objects in memory from the database.
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.
create(User $user, $notrigger=false)
Create object into 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 optionaly the picto)
getKanbanView($option='', $arraydata=null)
Return a thumb for kanban views.
update(User $user, $notrigger=false)
Update object into database.
setDisabled($user, $notrigger=0)
Set draft status.
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.
deleteLine(User $user, $idline, $notrigger=false)
Delete a line of object in database.
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($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:62
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
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.
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.