dolibarr 20.0.0
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 $date_creation;
144
148 public $fk_user_creat;
149
153 public $fk_user_modif;
154
158 public $status;
159
163 public $nb_operators_required;
164
168 public $thm_operator_estimated;
169
173 public $thm_machine_estimated;
174
175 // END MODULEBUILDER PROPERTIES
176
180 public $resources;
181
185 public $usergroups;
186
192 public function __construct(DoliDB $db)
193 {
194 global $conf, $langs;
195
196 require_once DOL_DOCUMENT_ROOT.'/workstation/class/workstationusergroup.class.php';
197 require_once DOL_DOCUMENT_ROOT.'/workstation/class/workstationresource.class.php';
198
199 $this->db = $db;
200
201 $this->ismultientitymanaged = 1;
202 $this->isextrafieldmanaged = 0;
203
204 if (!getDolGlobalString('MAIN_SHOW_TECHNICAL_ID') && isset($this->fields['rowid'])) {
205 $this->fields['rowid']['visible'] = 0;
206 }
207 if (empty($conf->multicompany->enabled) && isset($this->fields['entity'])) {
208 $this->fields['entity']['enabled'] = 0;
209 }
210
211 // Unset fields that are disabled
212 foreach ($this->fields as $key => $val) {
213 if (isset($val['enabled']) && empty($val['enabled'])) {
214 unset($this->fields[$key]);
215 }
216 }
217
218 // Translate some data of arrayofkeyval
219 if (is_object($langs)) {
220 foreach ($this->fields as $key => $val) {
221 if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
222 foreach ($val['arrayofkeyval'] as $key2 => $val2) {
223 $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
224 }
225 }
226 }
227 }
228 }
229
237 public function create(User $user, $notrigger = 0)
238 {
239 global $db;
240
241 $id = $this->createCommon($user, $notrigger);
242
243 // Usergroups
244 $groups = GETPOST('groups', 'array:int'); // FIXME We should not GETPOST but receive array as parameter
245 if (empty($groups)) {
246 $groups = $this->usergroups; // createFromClone
247 }
248 if (!empty($groups)) {
249 foreach ($groups as $id_group) {
250 $ws_usergroup = new WorkstationUserGroup($db);
251 $ws_usergroup->fk_workstation = $id;
252 $ws_usergroup->fk_usergroup = $id_group;
253 $ws_usergroup->createCommon($user);
254 $this->usergroups[] = $id_group;
255 }
256 }
257
258 // Resources
259 $resources = GETPOST('resources', 'array:int'); // FIXME We should not GETPOST but receive array as parameter
260 if (empty($resources)) {
261 $resources = $this->resources; // createFromClone
262 }
263 if (!empty($resources)) {
264 foreach ($resources as $id_resource) {
265 $ws_resource = new WorkstationResource($db);
266 $ws_resource->fk_workstation = $id;
267 $ws_resource->fk_resource = $id_resource;
268 $ws_resource->createCommon($user);
269 $this->resources[] = $id_resource;
270 }
271 }
272
273 return $id;
274 }
275
283 public function createFromClone(User $user, $fromid)
284 {
285 global $langs, $extrafields;
286 $error = 0;
287
288 dol_syslog(__METHOD__, LOG_DEBUG);
289
290 $object = new self($this->db);
291
292 $this->db->begin();
293
294 // Load source object
295 $result = $object->fetch($fromid);
296 if ($result > 0 && !empty($object->table_element_line)) {
297 $object->fetchLines();
298 }
299
300 // get lines so they will be clone
301 //foreach($this->lines as $line)
302 // $line->fetch_optionals();
303
304 // Reset some properties
305 unset($object->id);
306 unset($object->fk_user_creat);
307 unset($object->import_key);
308
309 // Clear fields
310 if (property_exists($object, 'ref')) {
311 $object->ref = empty($this->fields['ref']['default']) ? "Copy_Of_".$object->ref : $this->fields['ref']['default'];
312 }
313 if (property_exists($object, 'label')) {
314 $object->label = empty($this->fields['label']['default']) ? $langs->trans("CopyOf")." ".$object->label : $this->fields['label']['default'];
315 }
316 if (property_exists($object, 'status')) {
317 $object->status = self::STATUS_DISABLED;
318 }
319 if (property_exists($object, 'date_creation')) {
320 $object->date_creation = dol_now();
321 }
322 if (property_exists($object, 'date_modification')) {
323 $object->date_modification = null;
324 }
325 // ...
326 // Clear extrafields that are unique
327 if (is_array($object->array_options) && count($object->array_options) > 0) {
328 $extrafields->fetch_name_optionals_label($this->table_element);
329 foreach ($object->array_options as $key => $option) {
330 $shortkey = preg_replace('/options_/', '', $key);
331 if (!empty($extrafields->attributes[$this->table_element]['unique'][$shortkey])) {
332 //var_dump($key);
333 //var_dump($clonedObj->array_options[$key]); exit;
334 unset($object->array_options[$key]);
335 }
336 }
337 }
338
339 // Create clone
340 $object->context['createfromclone'] = 'createfromclone';
341 $result = $object->create($user);
342 if ($result < 0) {
343 $error++;
344 $this->error = $object->error;
345 $this->errors = $object->errors;
346 }
347
348 if (!$error) {
349 // copy internal contacts
350 if ($this->copy_linked_contact($object, 'internal') < 0) {
351 $error++;
352 }
353 }
354
355 if (!$error) {
356 // copy external contacts if same company
357 if (property_exists($this, 'socid') && $this->socid == $object->socid) {
358 if ($this->copy_linked_contact($object, 'external') < 0) {
359 $error++;
360 }
361 }
362 }
363
364 unset($object->context['createfromclone']);
365
366 // End
367 if (!$error) {
368 $this->db->commit();
369 return $object;
370 } else {
371 $this->db->rollback();
372 return -1;
373 }
374 }
375
383 public function fetch($id, $ref = null)
384 {
385 $result = $this->fetchCommon($id, $ref);
386
387 $this->usergroups = WorkstationUserGroup::getAllGroupsOfWorkstation($this->id);
388 $this->resources = WorkstationResource::getAllResourcesOfWorkstation($this->id);
389
390 if ($result > 0 && !empty($this->table_element_line)) {
391 $this->fetchLines();
392 }
393 return $result;
394 }
395
401 public function fetchLines()
402 {
403 $this->lines = array();
404
405 $result = $this->fetchLinesCommon();
406 return $result;
407 }
408
409
422 public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND')
423 {
424 dol_syslog(__METHOD__, LOG_DEBUG);
425
426 $records = array();
427
428 $sql = 'SELECT ';
429 $sql .= $this->getFieldList();
430 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
431 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
432 $sql .= ' WHERE t.entity IN ('.getEntity($this->element).')';
433 } else {
434 $sql .= ' WHERE 1 = 1';
435 }
436
437 // Manage filter
438 $errormessage = '';
439 $sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage);
440 if ($errormessage) {
441 $this->errors[] = $errormessage;
442 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
443 return -1;
444 }
445
446 if (!empty($sortfield)) {
447 $sql .= $this->db->order($sortfield, $sortorder);
448 }
449 if (!empty($limit)) {
450 $sql .= $this->db->plimit($limit, $offset);
451 }
452
453 $resql = $this->db->query($sql);
454 if ($resql) {
455 $num = $this->db->num_rows($resql);
456 $i = 0;
457 while ($i < ($limit ? min($limit, $num) : $num)) {
458 $obj = $this->db->fetch_object($resql);
459
460 $record = new self($this->db);
461 $record->setVarsFromFetchObj($obj);
462
463 $records[$record->id] = $record;
464
465 $i++;
466 }
467 $this->db->free($resql);
468
469 return $records;
470 } else {
471 $this->errors[] = 'Error '.$this->db->lasterror();
472 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
473
474 return -1;
475 }
476 }
477
485 public function update(User $user, $notrigger = 0)
486 {
487
488 // Usergroups
489 $groups = GETPOST('groups', 'array:int');
491 $this->usergroups = array();
492
493 foreach ($groups as $id_group) {
494 $ws_usergroup = new WorkstationUserGroup($this->db);
495 $ws_usergroup->fk_workstation = $this->id;
496 $ws_usergroup->fk_usergroup = $id_group;
497 $ws_usergroup->createCommon($user);
498 $this->usergroups[] = $id_group;
499 }
500
501 // Resources
502 $resources = GETPOST('resources', 'array:int');
504 $this->resources = array();
505 if (!empty($resources)) {
506 foreach ($resources as $id_resource) {
507 $ws_resource = new WorkstationResource($this->db);
508 $ws_resource->fk_workstation = $this->id;
509 $ws_resource->fk_resource = $id_resource;
510 $ws_resource->createCommon($user);
511 $this->resources[] = $id_resource;
512 }
513 }
514
515 return $this->updateCommon($user, $notrigger);
516 }
517
525 public function delete(User $user, $notrigger = 0)
526 {
527 return $this->deleteCommon($user, $notrigger);
528 //return $this->deleteCommon($user, $notrigger, 1);
529 }
530
539 public function deleteLine(User $user, $idline, $notrigger = 0)
540 {
541 if ($this->status < 0) {
542 $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
543 return -2;
544 }
545
546 return $this->deleteLineCommon($user, $idline, $notrigger);
547 }
548
556 public function setStatus($status, $notrigger = 0)
557 {
558 global $user;
559
560 $this->status = $status;
561
562 if (empty($status)) {
563 return $this->setDisabled($user, $notrigger);
564 } else {
565 return $this->setEnabled($user, $notrigger);
566 }
567 }
568
569
577 public function setEnabled($user, $notrigger = 0)
578 {
579 return $this->setStatusCommon($user, self::STATUS_ENABLED, $notrigger, 'WORKSTATION_ENABLED');
580 }
581
582
590 public function setDisabled($user, $notrigger = 0)
591 {
592 return $this->setStatusCommon($user, self::STATUS_DISABLED, $notrigger, 'WORKSTATION_DISABLED');
593 }
594
602 public function getTooltipContentArray($params)
603 {
604 global $conf, $langs;
605
606 $langs->load('mrp');
607
608 $datas = [];
609 $datas['picto'] = img_picto('', $this->picto).' <u>'.$langs->trans("Workstation").'</u>';
610 $datas['ref'] = '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref;
611 if (isset($this->status)) {
612 $datas['status'] = '<br><b>'.$langs->trans("Status").":</b> ".$this->getLibStatut(5);
613 }
614
615 return $datas;
616 }
617
628 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
629 {
630 global $conf, $langs, $hookmanager;
631
632 if (!empty($conf->dol_no_mouse_hover)) {
633 $notooltip = 1; // Force disable tooltips
634 }
635
636 $result = '';
637
638 $params = [
639 'id' => $this->id,
640 'objecttype' => $this->element,
641 ];
642 $classfortooltip = 'classfortooltip';
643 $dataparams = '';
644 if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
645 $classfortooltip = 'classforajaxtooltip';
646 $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"';
647 $label = '';
648 } else {
649 $label = implode($this->getTooltipContentArray($params));
650 }
651
652 $url = dol_buildpath('/workstation/workstation_card.php', 1).'?id='.$this->id;
653
654 if ($option != 'nolink') {
655 // Add param to save lastsearch_values or not
656 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
657 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
658 $add_save_lastsearch_values = 1;
659 }
660 if ($add_save_lastsearch_values) {
661 $url .= '&save_lastsearch_values=1';
662 }
663 }
664
665 $linkclose = '';
666 if (empty($notooltip)) {
667 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
668 $label = $langs->trans("ShowWorkstation");
669 $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
670 }
671 $linkclose .= ($label ? ' title="'.dol_escape_htmltag($label, 1).'"' : ' title="tocomplete"');
672 $linkclose .= $dataparams.' class="'.$classfortooltip.($morecss ? ' '.$morecss : '').'"';
673 } else {
674 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
675 }
676
677 $linkstart = '<a href="'.$url.'"';
678 $linkstart .= $linkclose.'>';
679 $linkend = '</a>';
680
681 $result .= $linkstart;
682
683 if (empty($this->showphoto_on_popup)) {
684 if ($withpicto) {
685 $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'mrp'), (($withpicto != 2) ? 'class="paddingright"' : ''), 0, 0, $notooltip ? 0 : 1);
686 }
687 } else {
688 if ($withpicto) {
689 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
690
691 list($class, $module) = explode('@', $this->picto);
692 $upload_dir = $conf->$module->multidir_output[$conf->entity]."/$class/".dol_sanitizeFileName($this->ref);
693 $filearray = dol_dir_list($upload_dir, "files");
694 $filename = $filearray[0]['name'];
695 if (!empty($filename)) {
696 $pospoint = strpos($filearray[0]['name'], '.');
697
698 $pathtophoto = $class.'/'.$this->ref.'/thumbs/'.substr($filename, 0, $pospoint).'_mini'.substr($filename, $pospoint);
699 if (!getDolGlobalString(strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS')) {
700 $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>';
701 } else {
702 $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>';
703 }
704
705 $result .= '</div>';
706 } else {
707 $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);
708 }
709 }
710 }
711
712 if ($withpicto != 2) {
713 $result .= $this->ref;
714 }
715
716 $result .= $linkend;
717 //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
718
719 global $action, $hookmanager;
720 $hookmanager->initHooks(array('workstationdao'));
721 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
722 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
723 if ($reshook > 0) {
724 $result = $hookmanager->resPrint;
725 } else {
726 $result .= $hookmanager->resPrint;
727 }
728
729 return $result;
730 }
731
739 public function getKanbanView($option = '', $arraydata = null)
740 {
741 global $conf, $langs;
742
743 $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
744
745 $return = '<div class="box-flex-item box-flex-grow-zero">';
746 $return .= '<div class="info-box info-box-sm">';
747 $return .= '<span class="info-box-icon bg-infobox-action">';
748 $return .= img_picto('', $this->picto);
749 $return .= '</span>';
750 $return .= '<div class="info-box-content">';
751 $return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this, 'getNomUrl') ? $this->getNomUrl() : $this->ref).'</span>';
752 if ($selected >= 0) {
753 $return .= '<input id="cb'.$this->id.'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
754 }
755 if (property_exists($this, 'label')) {
756 $return .= ' <div class="inline-block opacitymedium valignmiddle tdoverflowmax100">'.$this->label.'</div>';
757 }
758 if (property_exists($this, 'thirdparty') && is_object($this->thirdparty)) {
759 $return .= '<br><div class="info-box-ref tdoverflowmax150">'.$this->thirdparty->getNomUrl(1).'</div>';
760 }
761 if (property_exists($this, 'amount')) {
762 $return .= '<br>';
763 $return .= '<span class="info-box-label amount">'.price($this->amount, 0, $langs, 1, -1, -1, $conf->currency).'</span>';
764 }
765 if (method_exists($this, 'getLibStatut')) {
766 $return .= '<br><div class="info-box-status">'.$this->getLibStatut(3).'</div>';
767 }
768 $return .= '</div>';
769 $return .= '</div>';
770 $return .= '</div>';
771
772 return $return;
773 }
774
781 public function getLibStatut($mode = 0)
782 {
783 return $this->LibStatut($this->status, $mode);
784 }
785
786 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
794 public function LibStatut($status, $mode = 0)
795 {
796 // phpcs:enable
797 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
798 global $langs;
799 //$langs->load("workstation");
800 $this->labelStatus[self::STATUS_DISABLED] = $langs->transnoentitiesnoconv('Disabled');
801 $this->labelStatus[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv('Enabled');
802 $this->labelStatusShort[self::STATUS_DISABLED] = $langs->transnoentitiesnoconv('Disabled');
803 $this->labelStatusShort[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv('Enabled');
804 }
805
806 $statusType = 'status'.$status;
807 //if ($status == self::STATUS_DISABLED) $statusType = 'status6';
808 if ($status == self::STATUS_ENABLED) {
809 $statusType = 'status4';
810 }
811
812 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
813 }
814
821 public function info($id)
822 {
823 $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
824 $sql .= ' fk_user_creat, fk_user_modif';
825 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
826 $sql .= ' WHERE t.rowid = '.((int) $id);
827 $result = $this->db->query($sql);
828 if ($result) {
829 if ($this->db->num_rows($result)) {
830 $obj = $this->db->fetch_object($result);
831
832 $this->id = $obj->rowid;
833
834 $this->user_creation_id = $obj->fk_user_creat;
835 $this->user_modification_id = $obj->fk_user_modif;
836 $this->date_creation = $this->db->jdate($obj->datec);
837 $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
838 }
839
840 $this->db->free($result);
841 } else {
842 dol_print_error($this->db);
843 }
844 }
845
852 public function initAsSpecimen()
853 {
854 return $this->initAsSpecimenCommon();
855 }
856
862 public function getNextNumRef()
863 {
864 global $langs, $conf;
865 $langs->load("workstation");
866
867 if (!getDolGlobalString('WORKSTATION_WORKSTATION_ADDON')) {
868 $conf->global->WORKSTATION_WORKSTATION_ADDON = 'mod_workstation_standard';
869 }
870
871 if (getDolGlobalString('WORKSTATION_WORKSTATION_ADDON')) {
872 $mybool = false;
873
874 $file = getDolGlobalString('WORKSTATION_WORKSTATION_ADDON') . ".php";
875 $classname = getDolGlobalString('WORKSTATION_WORKSTATION_ADDON');
876
877 // Include file with class
878 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
879 foreach ($dirmodels as $reldir) {
880 $dir = dol_buildpath($reldir."core/modules/workstation/");
881
882 // Load file with numbering class (if found)
883 if (file_exists($dir.$file)) {
884 $mybool = ((bool) @include_once $dir.$file) || $mybool;
885 }
886 }
887
888 if ($mybool === false) {
889 dol_print_error(null, "Failed to include file ".$file);
890 return '';
891 }
892
893 if (class_exists($classname)) {
894 $obj = new $classname();
895 $numref = $obj->getNextValue($this);
896
897 if ($numref != '' && $numref != '-1') {
898 return $numref;
899 } else {
900 $this->error = $obj->error;
901 //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
902 return "";
903 }
904 } else {
905 print $langs->trans("Error")." ".$langs->trans("ClassNotFound").' '.$classname;
906 return "";
907 }
908 } else {
909 print $langs->trans("ErrorNumberingModuleNotSetup", $this->element);
910 return "";
911 }
912 }
913
925 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
926 {
927 global $conf, $langs;
928
929 $result = 0;
930 $includedocgeneration = 0;
931
932 $langs->load("workstation");
933
934 if (!dol_strlen($modele)) {
935 $modele = 'standard_workstation';
936
937 if ($this->model_pdf) {
938 $modele = $this->model_pdf;
939 } elseif (getDolGlobalString('WORKSTATION_ADDON_PDF')) {
940 $modele = getDolGlobalString('WORKSTATION_ADDON_PDF');
941 }
942 }
943
944 $modelpath = "core/modules/workstation/doc/";
945
946 if ($includedocgeneration) {
947 $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
948 }
949
950 return $result;
951 }
952}
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:637
$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.