dolibarr 24.0.0-beta
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-2026 Frédéric France <frederic.france@free.fr>
5 * Copyright (C) 2024-2026 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
53 public $picto = 'workstation';
54
59 public $TRIGGER_PREFIX = 'WORKSTATION';
60
61 const STATUS_DISABLED = 0;
62 const STATUS_ENABLED = 1;
63
64
91 // BEGIN MODULEBUILDER PROPERTIES
95 public $fields = array(
96 'rowid' => array('type' => 'integer', 'label' => 'TechnicalID', 'enabled' => 1, 'position' => 1, 'notnull' => 1, 'visible' => 0, 'noteditable' => 1, 'index' => 1, 'css' => 'left', 'comment' => "Id"),
97 'entity' => array('type' => 'integer', 'label' => 'Entity', 'enabled' => 1, 'visible' => 0, 'position' => 5, 'notnull' => 1, 'default' => '1', 'index' => 1),
98 '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'),
99 'label' => array('type' => 'varchar(255)', 'label' => 'Label', 'enabled' => 1, 'position' => 30, 'notnull' => 1, 'visible' => 1, 'searchall' => 1, 'css' => 'minwidth300', 'csslist' => 'tdoverflowmax125', 'showoncombobox' => 2,),
100 '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'),),
101 'note_public' => array('type' => 'html', 'label' => 'NotePublic', 'enabled' => 1, 'position' => 61, 'notnull' => 0, 'visible' => 0,),
102 'note_private' => array('type' => 'html', 'label' => 'NotePrivate', 'enabled' => 1, 'position' => 62, 'notnull' => 0, 'visible' => 0,),
103 'date_creation' => array('type' => 'datetime', 'label' => 'DateCreation', 'enabled' => 1, 'position' => 500, 'notnull' => 1, 'visible' => -2, 'csslist' => 'nowraponall'),
104 'tms' => array('type' => 'timestamp', 'label' => 'DateModification', 'enabled' => 1, 'position' => 501, 'notnull' => 0, 'visible' => -2, 'csslist' => 'nowraponall'),
105 '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',),
106 'fk_user_modif' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'UserModif', 'enabled' => 1, 'position' => 511, 'notnull' => -1, 'visible' => -2,),
107 'import_key' => array('type' => 'varchar(14)', 'label' => 'ImportId', 'enabled' => 1, 'position' => 512, 'notnull' => -1, 'visible' => -2,),
108 'nb_operators_required' => array('type' => 'integer', 'label' => 'NbOperatorsRequired', 'enabled' => 1, 'position' => 50, 'notnull' => 0, 'visible' => 1, 'css' => 'right maxwidth50imp', 'csslist' => 'maxwidth50imp'),
109 'thm_operator_estimated' => array('type' => 'price', 'help' => 'THMOperatorEstimatedHelp','label' => 'THMOperatorEstimated', 'enabled' => 1, 'position' => 50, 'notnull' => 0, 'visible' => 1, 'css' => 'right maxwidth75imp', 'csslist' => 'maxwidth75imp'),
110 'thm_machine_estimated' => array('type' => 'price', 'help' => 'THMMachineEstimatedHelp', 'label' => 'THMMachineEstimated', 'enabled' => 1, 'position' => 50, 'notnull' => 0, 'visible' => 1, 'css' => 'right maxwidth75imp', 'csslist' => 'maxwidth75imp'),
111 'status' => array('type' => 'smallint', 'label' => 'Status', 'enabled' => 1, 'position' => 1000, 'default' => '1', 'notnull' => 1, 'visible' => 1, 'index' => 1, 'arrayofkeyval' => array(0 => 'Disabled', 1 => 'Enabled'),),
112 );
113
117 public $rowid;
118
122 public $ref;
123
127 public $label;
128
132 public $type; // HUMAN, MACHINE, ...
133
137 public $fk_user_creat;
138
142 public $fk_user_modif;
143
147 public $status;
148
152 public $nb_operators_required;
153
157 public $thm_operator_estimated;
158
162 public $thm_machine_estimated;
163
164 // END MODULEBUILDER PROPERTIES
165
169 public $resources;
170
174 public $usergroups;
175
181 public function __construct(DoliDB $db)
182 {
183 global $conf, $langs;
184
185 require_once DOL_DOCUMENT_ROOT.'/workstation/class/workstationusergroup.class.php';
186 require_once DOL_DOCUMENT_ROOT.'/workstation/class/workstationresource.class.php';
187
188 $this->db = $db;
189
190 $this->ismultientitymanaged = 1;
191 $this->isextrafieldmanaged = 1;
192
193 if (!getDolGlobalString('MAIN_SHOW_TECHNICAL_ID') && isset($this->fields['rowid'])) {
194 $this->fields['rowid']['visible'] = 0;
195 }
196 if (!isModEnabled('multicompany') && isset($this->fields['entity'])) {
197 $this->fields['entity']['enabled'] = 0;
198 }
199
200 // Unset fields that are disabled
201 foreach ($this->fields as $key => $val) {
202 if (isset($val['enabled']) && empty($val['enabled'])) {
203 unset($this->fields[$key]);
204 }
205 }
206
207 // Translate some data of arrayofkeyval
208 if (is_object($langs)) {
209 foreach ($this->fields as $key => $val) {
210 if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
211 foreach ($val['arrayofkeyval'] as $key2 => $val2) {
212 $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
213 }
214 }
215 }
216 }
217 }
218
226 public function create(User $user, $notrigger = 0)
227 {
228 global $db;
229
230 $id = $this->createCommon($user, $notrigger);
231
232 // Usergroups
233 $groups = GETPOST('groups', 'array:int'); // FIXME We should not GETPOST but receive array as parameter
234 if (empty($groups)) {
235 $groups = $this->usergroups; // createFromClone
236 }
237 if (!empty($groups)) {
238 foreach ($groups as $id_group) {
239 $ws_usergroup = new WorkstationUserGroup($db);
240 $ws_usergroup->fk_workstation = $id;
241 $ws_usergroup->fk_usergroup = $id_group;
242 $ws_usergroup->createCommon($user);
243 $this->usergroups[] = $id_group;
244 }
245 }
246
247 // Resources
248 $resources = GETPOST('resources', 'array:int'); // FIXME We should not GETPOST but receive array as parameter
249 if (empty($resources)) {
250 $resources = $this->resources; // createFromClone
251 }
252 if (!empty($resources)) {
253 foreach ($resources as $id_resource) {
254 $ws_resource = new WorkstationResource($db);
255 $ws_resource->fk_workstation = $id;
256 $ws_resource->fk_resource = $id_resource;
257 $ws_resource->createCommon($user);
258 $this->resources[] = $id_resource;
259 }
260 }
261
262 return $id;
263 }
264
272 public function createFromClone(User $user, $fromid)
273 {
274 global $langs, $extrafields;
275 $error = 0;
276
277 dol_syslog(__METHOD__, LOG_DEBUG);
278
279 $object = new self($this->db);
280
281 $this->db->begin();
282
283 // Load source object
284 $result = $object->fetch($fromid);
285 if ($result > 0 && !empty($object->table_element_line)) {
286 $object->fetchLines();
287 }
288
289 // get lines so they will be clone
290 //foreach($this->lines as $line)
291 // $line->fetch_optionals();
292
293 // Reset some properties
294 unset($object->id);
295 unset($object->fk_user_creat);
296 unset($object->import_key);
297
298 // Clear fields
299 $object->ref = "Copy_Of_".$object->ref;
300 $object->label = $langs->trans("CopyOf")." ".$object->label;
301 $object->status = self::STATUS_DISABLED;
302 $object->date_creation = dol_now();
303 $object->date_modification = null;
304
305 // Clear extrafields that are unique
306 if (is_array($object->array_options) && count($object->array_options) > 0) {
307 $extrafields->fetch_name_optionals_label($this->table_element);
308 foreach ($object->array_options as $key => $option) {
309 $shortkey = preg_replace('/options_/', '', $key);
310 if (!empty($extrafields->attributes[$this->table_element]['unique'][$shortkey])) {
311 //var_dump($key);
312 //var_dump($clonedObj->array_options[$key]); exit;
313 unset($object->array_options[$key]);
314 }
315 }
316 }
317
318 // Create clone
319 $object->context['createfromclone'] = 'createfromclone';
320 $result = $object->create($user);
321 if ($result < 0) {
322 $error++;
324 }
325
326 if (!$error) {
327 // copy internal contacts
328 if ($this->copy_linked_contact($object, 'internal') < 0) {
329 $error++;
330 }
331 }
332
333 unset($object->context['createfromclone']);
334
335 // End
336 if (!$error) {
337 $this->db->commit();
338 return $object;
339 } else {
340 $this->db->rollback();
341 return -1;
342 }
343 }
344
352 public function fetch($id, $ref = null)
353 {
354 $result = $this->fetchCommon($id, $ref);
355
356 $this->usergroups = WorkstationUserGroup::getAllGroupsOfWorkstation($this->id);
357 $this->resources = WorkstationResource::getAllResourcesOfWorkstation($this->id);
358
359 if ($result > 0 && !empty($this->table_element_line)) {
360 $this->fetchLines();
361 }
362 return $result;
363 }
364
370 public function fetchLines()
371 {
372 $this->lines = array();
373
374 $result = $this->fetchLinesCommon();
375 return $result;
376 }
377
378
391 public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND')
392 {
393 dol_syslog(__METHOD__, LOG_DEBUG);
394
395 $records = array();
396
397 $sql = 'SELECT ';
398 $sql .= $this->getFieldList();
399 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
400 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
401 $sql .= ' WHERE t.entity IN ('.getEntity($this->element).')';
402 } else {
403 $sql .= ' WHERE 1 = 1';
404 }
405
406 // Manage filter
407 $errormessage = '';
408 $sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage);
409 if ($errormessage) {
410 $this->errors[] = $errormessage;
411 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
412 return -1;
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__.' '.implode(',', $this->errors), LOG_ERR);
442
443 return -1;
444 }
445 }
446
454 public function update(User $user, $notrigger = 0)
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 = (int) $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 = (int) $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 = 0)
495 {
496 return $this->deleteCommon($user, $notrigger);
497 //return $this->deleteCommon($user, $notrigger, 1);
498 }
499
508 public function deleteLine(User $user, $idline, $notrigger = 0)
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
570 public function getTooltipContentArray($params)
571 {
572 global $conf, $langs;
573
574 $langs->load('mrp');
575
576 $datas = [];
577 $datas['picto'] = img_picto('', $this->picto).' <u>'.$langs->trans("Workstation").'</u>';
578 $datas['ref'] = '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref;
579 if (isset($this->status)) {
580 $datas['status'] = '<br><b>'.$langs->trans("Status").":</b> ".$this->getLibStatut(5);
581 }
582
583 return $datas;
584 }
585
596 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
597 {
598 global $conf, $langs, $hookmanager;
599
600 if (!empty($conf->dol_no_mouse_hover)) {
601 $notooltip = 1; // Force disable tooltips
602 }
603
604 $result = '';
605
606 $params = [
607 'id' => $this->id,
608 'objecttype' => $this->element,
609 ];
610 $classfortooltip = 'classfortooltip';
611 $dataparams = '';
612 if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
613 $classfortooltip = 'classforajaxtooltip';
614 $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"';
615 $label = '';
616 } else {
617 $label = implode($this->getTooltipContentArray($params));
618 }
619
620 $baseurl = DOL_URL_ROOT . '/workstation/workstation_card.php';
621 $query = ['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 $query = array_merge($query, ['save_lastsearch_values' => 1]);
631 }
632 }
633 $url = dolBuildUrl($baseurl, $query);
634
635 $linkclose = '';
636 if (empty($notooltip)) {
637 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
638 $label = $langs->trans("ShowWorkstation");
639 $linkclose .= ' alt="'.dolPrintHTMLForAttribute($label).'"';
640 }
641 $linkclose .= ($label ? ' title="'.dolPrintHTMLForAttribute($label).'"' : ' title="tocomplete"');
642 $linkclose .= $dataparams.' class="'.$classfortooltip.($morecss ? ' '.$morecss : '').'"';
643 } else {
644 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
645 }
646
647 $linkstart = '<a href="'.$url.'"';
648 $linkstart .= $linkclose.'>';
649 $linkend = '</a>';
650
651 $result .= $linkstart;
652
653 if (empty($this->showphoto_on_popup)) {
654 if ($withpicto) {
655 $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'mrp'), (($withpicto != 2) ? 'class="paddingright"' : ''), 0, 0, $notooltip ? 0 : 1);
656 }
657 } else {
658 if ($withpicto) {
659 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
660
661 list($class, $module) = explode('@', $this->picto);
662 $upload_dir = $conf->$module->multidir_output[$conf->entity]."/$class/".dol_sanitizeFileName($this->ref);
663 $filearray = dol_dir_list($upload_dir, "files");
664 $filename = $filearray[0]['name'];
665 if (!empty($filename)) {
666 $pospoint = strpos($filearray[0]['name'], '.');
667
668 $pathtophoto = $class.'/'.$this->ref.'/thumbs/'.substr($filename, 0, $pospoint).'_mini'.substr($filename, $pospoint);
669 if (!getDolGlobalString(strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS')) {
670 $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>';
671 } else {
672 $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>';
673 }
674
675 $result .= '</div>';
676 } else {
677 $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);
678 }
679 }
680 }
681
682 if ($withpicto != 2) {
683 $result .= $this->ref;
684 }
685
686 $result .= $linkend;
687 //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
688
689 global $action, $hookmanager;
690 $hookmanager->initHooks(array('workstationdao'));
691 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
692 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
693 if ($reshook > 0) {
694 $result = $hookmanager->resPrint;
695 } else {
696 $result .= $hookmanager->resPrint;
697 }
698
699 return $result;
700 }
701
709 public function getKanbanView($option = '', $arraydata = null)
710 {
711 $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
712
713 $return = '<div class="box-flex-item box-flex-grow-zero">';
714 $return .= '<div class="info-box info-box-sm">';
715 $return .= '<span class="info-box-icon bg-infobox-action">';
716 $return .= img_picto('', $this->picto);
717 $return .= '</span>';
718 $return .= '<div class="info-box-content">';
719 $return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">' . $this->getNomUrl() . '</span>';
720 if ($selected >= 0) {
721 $return .= '<input id="cb'.$this->id.'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
722 }
723 if (!empty($this->label)) {
724 $return .= ' <div class="inline-block opacitymedium valignmiddle tdoverflowmax100">'.$this->label.'</div>';
725 }
726 if (isset($this->thirdparty) && is_object($this->thirdparty)) {
727 $return .= '<br><div class="info-box-ref tdoverflowmax150">'.$this->thirdparty->getNomUrl(1).'</div>';
728 }
729 $return .= '<br><div class="info-box-status">'.$this->getLibStatut(3).'</div>';
730 $return .= '</div>';
731 $return .= '</div>';
732 $return .= '</div>';
733
734 return $return;
735 }
736
743 public function getLibStatut($mode = 0)
744 {
745 return $this->LibStatut($this->status, $mode);
746 }
747
748 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
756 public function LibStatut($status, $mode = 0)
757 {
758 // phpcs:enable
759 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
760 global $langs;
761 //$langs->load("workstation");
762 $this->labelStatus[self::STATUS_DISABLED] = $langs->transnoentitiesnoconv('Disabled');
763 $this->labelStatus[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv('Enabled');
764 $this->labelStatusShort[self::STATUS_DISABLED] = $langs->transnoentitiesnoconv('Disabled');
765 $this->labelStatusShort[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv('Enabled');
766 }
767
768 $statusType = 'status'.$status;
769 //if ($status == self::STATUS_DISABLED) $statusType = 'status6';
770 if ($status == self::STATUS_ENABLED) {
771 $statusType = 'status4';
772 }
773
774 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
775 }
776
783 public function info($id)
784 {
785 $sql = 'SELECT t.rowid, t.date_creation as datec, GREATEST(t.tms, tef.tms) as datem,';
786 $sql .= ' t.fk_user_creat, t.fk_user_modif';
787 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
788 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.$this->table_element.'_extrafields as tef ON tef.fk_object=t.rowid';
789 $sql .= ' WHERE t.rowid = '.((int) $id);
790 $result = $this->db->query($sql);
791 if ($result) {
792 if ($this->db->num_rows($result)) {
793 $obj = $this->db->fetch_object($result);
794
795 $this->id = $obj->rowid;
796
797 $this->user_creation_id = $obj->fk_user_creat;
798 $this->user_modification_id = $obj->fk_user_modif;
799 $this->date_creation = $this->db->jdate($obj->datec);
800 $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
801 }
802
803 $this->db->free($result);
804 } else {
805 dol_print_error($this->db);
806 }
807 }
808
815 public function initAsSpecimen()
816 {
817 return $this->initAsSpecimenCommon();
818 }
819
825 public function getNextNumRef()
826 {
827 global $langs, $conf;
828 $langs->load("workstation");
829
830 if (!getDolGlobalString('WORKSTATION_WORKSTATION_ADDON')) {
831 $conf->global->WORKSTATION_WORKSTATION_ADDON = 'mod_workstation_standard';
832 }
833
834 if (getDolGlobalString('WORKSTATION_WORKSTATION_ADDON')) {
835 $mybool = false;
836
837 $file = getDolGlobalString('WORKSTATION_WORKSTATION_ADDON') . ".php";
838 $classname = getDolGlobalString('WORKSTATION_WORKSTATION_ADDON');
839
840 // Include file with class
841 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
842 foreach ($dirmodels as $reldir) {
843 $dir = dol_buildpath($reldir."core/modules/workstation/");
844
845 // Load file with numbering class (if found)
846 if (file_exists($dir.$file)) {
847 $mybool = ((bool) @include_once $dir.$file) || $mybool;
848 }
849 }
850
851 if (!$mybool) {
852 dol_print_error(null, "Failed to include file ".$file);
853 return '';
854 }
855
856 if (class_exists($classname)) {
857 $obj = new $classname();
858 '@phan-var-force ModeleNumRefWorkstation $obj';
859 $numref = $obj->getNextValue($this);
860
861 if ($numref != '' && $numref != '-1') {
862 return $numref;
863 } else {
864 $this->error = $obj->error;
865 //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
866 return "";
867 }
868 } else {
869 print $langs->trans("Error")." ".$langs->trans("ClassNotFound").' '.$classname;
870 return "";
871 }
872 } else {
873 print $langs->trans("ErrorNumberingModuleNotSetup", $this->element);
874 return "";
875 }
876 }
877
889 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
890 {
891 global $conf, $langs;
892
893 $result = 0;
894
895 $langs->load("workstation");
896
897 if (!dol_strlen($modele)) {
898 $modele = 'standard_workstation';
899
900 if ($this->model_pdf) {
901 $modele = $this->model_pdf;
902 } elseif (getDolGlobalString('WORKSTATION_ADDON_PDF')) {
903 $modele = getDolGlobalString('WORKSTATION_ADDON_PDF');
904 }
905 }
906
907 $modelpath = "core/modules/workstation/doc/";
908
909 $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
910
911 return $result;
912 }
913}
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
$object ref
Definition info.php:90
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.
setErrorsFromObject($object)
setErrorsFromObject
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.
print $langs trans("Ref").' m titre as m m statut as status
Or an array listing all the potential status of the object: array: int of the status => translated la...
Definition index.php:168
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
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:64
dol_now($mode='gmt')
Return date for now.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
dolBuildUrl($url, $params=[], $addtoken=false, $anchor='')
Return path of url.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
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_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 a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.