dolibarr 18.0.6
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 = 0;
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 '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"),
103 'label' => array('type'=>'varchar(255)', 'label'=>'Label', 'enabled'=>'1', 'position'=>30, 'notnull'=>1, 'visible'=>1, 'searchall'=>1, 'css'=>'minwidth300', 'csslist'=>'tdoverflowmax125', 'showoncombobox'=>'2',),
104 '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'),),
105 'note_public' => array('type'=>'html', 'label'=>'NotePublic', 'enabled'=>'1', 'position'=>61, 'notnull'=>0, 'visible'=>0,),
106 'note_private' => array('type'=>'html', 'label'=>'NotePrivate', 'enabled'=>'1', 'position'=>62, 'notnull'=>0, 'visible'=>0,),
107 'date_creation' => array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>'1', 'position'=>500, 'notnull'=>1, 'visible'=>-2, 'csslist'=>'nowraponall'),
108 'tms' => array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>'1', 'position'=>501, 'notnull'=>0, 'visible'=>-2, 'csslist'=>'nowraponall'),
109 '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',),
110 'fk_user_modif' => array('type'=>'integer:User:user/class/user.class.php', 'label'=>'UserModif', 'enabled'=>'1', 'position'=>511, 'notnull'=>-1, 'visible'=>-2,),
111 'import_key' => array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>'1', 'position'=>512, 'notnull'=>-1, 'visible'=>-2,),
112 'nb_operators_required' => array('type'=>'integer', 'label'=>'NbOperatorsRequired', 'enabled'=>'1', 'position'=>50, 'notnull'=>0, 'visible'=>1,),
113 'thm_operator_estimated' => array('type'=>'double', 'help'=>'THMOperatorEstimatedHelp','label'=>'THMOperatorEstimated', 'enabled'=>'1', 'position'=>50, 'notnull'=>0, 'visible'=>1, 'css'=>'right'),
114 'thm_machine_estimated' => array('type'=>'double', 'help'=>'THMMachineEstimatedHelp', 'label'=>'THMMachineEstimated', 'enabled'=>'1', 'position'=>50, 'notnull'=>0, 'visible'=>1, 'css'=>'right'),
115 'status' => array('type'=>'smallint', 'label'=>'Status', 'enabled'=>'1', 'position'=>1000, 'default'=>1, 'notnull'=>1, 'visible'=>1, 'index'=>1, 'arrayofkeyval'=>array('0'=>'Disabled', '1'=>'Enabled'),),
116 );
117 public $rowid;
118 public $ref;
119 public $label;
120 public $type; // HUMAN, MACHINE, ...
121
122 public $date_creation;
123 public $tms;
124 public $fk_user_creat;
125 public $fk_user_modif;
126
130 public $status;
131 public $nb_operators_required;
132 public $thm_operator_estimated;
133 public $thm_machine_estimated;
134 // END MODULEBUILDER PROPERTIES
135
139 public $resources;
140
144 public $usergroups;
145
151 public function __construct(DoliDB $db)
152 {
153 global $conf, $langs;
154
155 require_once DOL_DOCUMENT_ROOT.'/workstation/class/workstationusergroup.class.php';
156 require_once DOL_DOCUMENT_ROOT.'/workstation/class/workstationresource.class.php';
157
158 $this->db = $db;
159
160 if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID) && isset($this->fields['rowid'])) {
161 $this->fields['rowid']['visible'] = 0;
162 }
163 if (empty($conf->multicompany->enabled) && isset($this->fields['entity'])) {
164 $this->fields['entity']['enabled'] = 0;
165 }
166
167 // Unset fields that are disabled
168 foreach ($this->fields as $key => $val) {
169 if (isset($val['enabled']) && empty($val['enabled'])) {
170 unset($this->fields[$key]);
171 }
172 }
173
174 // Translate some data of arrayofkeyval
175 if (is_object($langs)) {
176 foreach ($this->fields as $key => $val) {
177 if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
178 foreach ($val['arrayofkeyval'] as $key2 => $val2) {
179 $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
180 }
181 }
182 }
183 }
184 }
185
193 public function create(User $user, $notrigger = false)
194 {
195 global $db;
196
197 $id = $this->createCommon($user, $notrigger);
198
199 // Usergroups
200 $groups = GETPOST('groups', 'array:int');
201 if (empty($groups)) {
202 $groups = $this->usergroups; // createFromClone
203 }
204 if (!empty($groups)) {
205 foreach ($groups as $id_group) {
206 $ws_usergroup = new WorkstationUserGroup($db);
207 $ws_usergroup->fk_workstation = $id;
208 $ws_usergroup->fk_usergroup = $id_group;
209 $ws_usergroup->createCommon($user);
210 $this->usergroups[] = $id_group;
211 }
212 }
213
214 // Resources
215 $resources = GETPOST('resources', 'array:int');
216 if (empty($resources)) {
217 $resources = $this->resources; // createFromClone
218 }
219 if (!empty($resources)) {
220 foreach ($resources as $id_resource) {
221 $ws_resource = new WorkstationResource($db);
222 $ws_resource->fk_workstation = $id;
223 $ws_resource->fk_resource = $id_resource;
224 $ws_resource->createCommon($user);
225 $this->resources[] = $id_resource;
226 }
227 }
228
229 return $id;
230 }
231
239 public function createFromClone(User $user, $fromid)
240 {
241 global $langs, $extrafields;
242 $error = 0;
243
244 dol_syslog(__METHOD__, LOG_DEBUG);
245
246 $object = new self($this->db);
247
248 $this->db->begin();
249
250 // Load source object
251 $result = $object->fetch($fromid);
252 if ($result > 0 && !empty($object->table_element_line)) {
253 $object->fetchLines();
254 }
255
256 // get lines so they will be clone
257 //foreach($this->lines as $line)
258 // $line->fetch_optionals();
259
260 // Reset some properties
261 unset($object->id);
262 unset($object->fk_user_creat);
263 unset($object->import_key);
264
265 // Clear fields
266 if (property_exists($object, 'ref')) {
267 $object->ref = empty($this->fields['ref']['default']) ? "Copy_Of_".$object->ref : $this->fields['ref']['default'];
268 }
269 if (property_exists($object, 'label')) {
270 $object->label = empty($this->fields['label']['default']) ? $langs->trans("CopyOf")." ".$object->label : $this->fields['label']['default'];
271 }
272 if (property_exists($object, 'status')) {
273 $object->status = self::STATUS_DISABLED;
274 }
275 if (property_exists($object, 'date_creation')) {
276 $object->date_creation = dol_now();
277 }
278 if (property_exists($object, 'date_modification')) {
279 $object->date_modification = null;
280 }
281 // ...
282 // Clear extrafields that are unique
283 if (is_array($object->array_options) && count($object->array_options) > 0) {
284 $extrafields->fetch_name_optionals_label($this->table_element);
285 foreach ($object->array_options as $key => $option) {
286 $shortkey = preg_replace('/options_/', '', $key);
287 if (!empty($extrafields->attributes[$this->table_element]['unique'][$shortkey])) {
288 //var_dump($key);
289 //var_dump($clonedObj->array_options[$key]); exit;
290 unset($object->array_options[$key]);
291 }
292 }
293 }
294
295 // Create clone
296 $object->context['createfromclone'] = 'createfromclone';
297 $result = $object->create($user);
298 if ($result < 0) {
299 $error++;
300 $this->error = $object->error;
301 $this->errors = $object->errors;
302 }
303
304 if (!$error) {
305 // copy internal contacts
306 if ($this->copy_linked_contact($object, 'internal') < 0) {
307 $error++;
308 }
309 }
310
311 if (!$error) {
312 // copy external contacts if same company
313 if (property_exists($this, 'socid') && $this->socid == $object->socid) {
314 if ($this->copy_linked_contact($object, 'external') < 0) {
315 $error++;
316 }
317 }
318 }
319
320 unset($object->context['createfromclone']);
321
322 // End
323 if (!$error) {
324 $this->db->commit();
325 return $object;
326 } else {
327 $this->db->rollback();
328 return -1;
329 }
330 }
331
339 public function fetch($id, $ref = null)
340 {
341 $result = $this->fetchCommon($id, $ref);
342
343 $this->usergroups = WorkstationUserGroup::getAllGroupsOfWorkstation($this->id);
344 $this->resources = WorkstationResource::getAllResourcesOfWorkstation($this->id);
345
346 if ($result > 0 && !empty($this->table_element_line)) {
347 $this->fetchLines();
348 }
349 return $result;
350 }
351
357 public function fetchLines()
358 {
359 $this->lines = array();
360
361 $result = $this->fetchLinesCommon();
362 return $result;
363 }
364
365
377 public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND')
378 {
379 global $conf;
380
381 dol_syslog(__METHOD__, LOG_DEBUG);
382
383 $records = array();
384
385 $sql = 'SELECT ';
386 $sql .= $this->getFieldList();
387 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
388 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
389 $sql .= ' WHERE t.entity IN ('.getEntity($this->element).')';
390 } else {
391 $sql .= ' WHERE 1 = 1';
392 }
393 // Manage filter
394 $sqlwhere = array();
395 if (count($filter) > 0) {
396 foreach ($filter as $key => $value) {
397 if ($key == 't.rowid') {
398 $sqlwhere[] = $key." = ".((int) $value);
399 } elseif (in_array($this->fields[$key]['type'], array('date', 'datetime', 'timestamp'))) {
400 $sqlwhere[] = $key." = '".$this->db->idate($value)."'";
401 } elseif ($key == 'customsql') {
402 $sqlwhere[] = $value;
403 } elseif (strpos($value, '%') === false) {
404 $sqlwhere[] = $key." IN (".$this->db->sanitize($this->db->escape($value)).")";
405 } else {
406 $sqlwhere[] = $key." LIKE '%".$this->db->escape($value)."%'";
407 }
408 }
409 }
410 if (count($sqlwhere) > 0) {
411 $sql .= ' AND ('.implode(' '.$this->db->escape($filtermode).' ', $sqlwhere).')';
412 }
413
414 if (!empty($sortfield)) {
415 $sql .= $this->db->order($sortfield, $sortorder);
416 }
417 if (!empty($limit)) {
418 $sql .= $this->db->plimit($limit, $offset);
419 }
420
421 $resql = $this->db->query($sql);
422 if ($resql) {
423 $num = $this->db->num_rows($resql);
424 $i = 0;
425 while ($i < ($limit ? min($limit, $num) : $num)) {
426 $obj = $this->db->fetch_object($resql);
427
428 $record = new self($this->db);
429 $record->setVarsFromFetchObj($obj);
430
431 $records[$record->id] = $record;
432
433 $i++;
434 }
435 $this->db->free($resql);
436
437 return $records;
438 } else {
439 $this->errors[] = 'Error '.$this->db->lasterror();
440 dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
441
442 return -1;
443 }
444 }
445
453 public function update(User $user, $notrigger = false)
454 {
455
456 // Usergroups
457 $groups = GETPOST('groups', 'array:int');
459 $this->usergroups=array();
460
461 foreach ($groups as $id_group) {
462 $ws_usergroup = new WorkstationUserGroup($this->db);
463 $ws_usergroup->fk_workstation = $this->id;
464 $ws_usergroup->fk_usergroup = $id_group;
465 $ws_usergroup->createCommon($user);
466 $this->usergroups[] = $id_group;
467 }
468
469 // Resources
470 $resources = GETPOST('resources', 'array:int');
472 $this->resources=array();
473 if (!empty($resources)) {
474 foreach ($resources as $id_resource) {
475 $ws_resource = new WorkstationResource($this->db);
476 $ws_resource->fk_workstation = $this->id;
477 $ws_resource->fk_resource = $id_resource;
478 $ws_resource->createCommon($user);
479 $this->resources[] = $id_resource;
480 }
481 }
482
483 return $this->updateCommon($user, $notrigger);
484 }
485
493 public function delete(User $user, $notrigger = false)
494 {
495 return $this->deleteCommon($user, $notrigger);
496 //return $this->deleteCommon($user, $notrigger, 1);
497 }
498
507 public function deleteLine(User $user, $idline, $notrigger = false)
508 {
509 if ($this->status < 0) {
510 $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
511 return -2;
512 }
513
514 return $this->deleteLineCommon($user, $idline, $notrigger);
515 }
516
524 public function setStatus($status, $notrigger = 0)
525 {
526 global $user;
527
528 $this->status = $status;
529
530 if (empty($status)) {
531 return $this->setDisabled($user, $notrigger);
532 } else {
533 return $this->setEnabled($user, $notrigger);
534 }
535 }
536
537
545 public function setEnabled($user, $notrigger = 0)
546 {
547 return $this->setStatusCommon($user, self::STATUS_ENABLED, $notrigger, 'WORKSTATION_ENABLED');
548 }
549
550
558 public function setDisabled($user, $notrigger = 0)
559 {
560 return $this->setStatusCommon($user, self::STATUS_DISABLED, $notrigger, 'WORKSTATION_DISABLED');
561 }
562
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 $url = dol_buildpath('/workstation/workstation_card.php', 1).'?id='.$this->id;
621
622 if ($option != 'nolink') {
623 // Add param to save lastsearch_values or not
624 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
625 if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
626 $add_save_lastsearch_values = 1;
627 }
628 if ($add_save_lastsearch_values) {
629 $url .= '&save_lastsearch_values=1';
630 }
631 }
632
633 $linkclose = '';
634 if (empty($notooltip)) {
635 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
636 $label = $langs->trans("ShowWorkstation");
637 $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
638 }
639 $linkclose .= ($label ? ' title="'.dol_escape_htmltag($label, 1).'"' : ' title="tocomplete"');
640 $linkclose .= $dataparams.' class="'.$classfortooltip.($morecss ? ' '.$morecss : '').'"';
641 } else {
642 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
643 }
644
645 $linkstart = '<a href="'.$url.'"';
646 $linkstart .= $linkclose.'>';
647 $linkend = '</a>';
648
649 $result .= $linkstart;
650
651 if (empty($this->showphoto_on_popup)) {
652 if ($withpicto) {
653 $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'mrp'), (($withpicto != 2) ? 'class="paddingright"' : ''), 0, 0, $notooltip ? 0 : 1);
654 }
655 } else {
656 if ($withpicto) {
657 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
658
659 list($class, $module) = explode('@', $this->picto);
660 $upload_dir = $conf->$module->multidir_output[$conf->entity]."/$class/".dol_sanitizeFileName($this->ref);
661 $filearray = dol_dir_list($upload_dir, "files");
662 $filename = $filearray[0]['name'];
663 if (!empty($filename)) {
664 $pospoint = strpos($filearray[0]['name'], '.');
665
666 $pathtophoto = $class.'/'.$this->ref.'/thumbs/'.substr($filename, 0, $pospoint).'_mini'.substr($filename, $pospoint);
667 if (empty($conf->global->{strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS'})) {
668 $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>';
669 } else {
670 $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>';
671 }
672
673 $result .= '</div>';
674 } else {
675 $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);
676 }
677 }
678 }
679
680 if ($withpicto != 2) {
681 $result .= $this->ref;
682 }
683
684 $result .= $linkend;
685 //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
686
687 global $action, $hookmanager;
688 $hookmanager->initHooks(array('workstationdao'));
689 $parameters = array('id'=>$this->id, 'getnomurl' => &$result);
690 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
691 if ($reshook > 0) {
692 $result = $hookmanager->resPrint;
693 } else {
694 $result .= $hookmanager->resPrint;
695 }
696
697 return $result;
698 }
699
706 public function getLibStatut($mode = 0)
707 {
708 return $this->LibStatut($this->status, $mode);
709 }
710
711 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
719 public function LibStatut($status, $mode = 0)
720 {
721 // phpcs:enable
722 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
723 global $langs;
724 //$langs->load("workstation");
725 $this->labelStatus[self::STATUS_DISABLED] = $langs->transnoentitiesnoconv('Disabled');
726 $this->labelStatus[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv('Enabled');
727 $this->labelStatusShort[self::STATUS_DISABLED] = $langs->transnoentitiesnoconv('Disabled');
728 $this->labelStatusShort[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv('Enabled');
729 }
730
731 $statusType = 'status'.$status;
732 //if ($status == self::STATUS_DISABLED) $statusType = 'status6';
733 if ($status == self::STATUS_ENABLED) $statusType = 'status4';
734
735 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
736 }
737
744 public function info($id)
745 {
746 $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
747 $sql .= ' fk_user_creat, fk_user_modif';
748 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
749 $sql .= ' WHERE t.rowid = '.((int) $id);
750 $result = $this->db->query($sql);
751 if ($result) {
752 if ($this->db->num_rows($result)) {
753 $obj = $this->db->fetch_object($result);
754 $this->id = $obj->rowid;
755
756 $this->user_creation_id = $obj->fk_user_creat;
757 $this->user_modification_id = $obj->fk_user_modif;
758 $this->date_creation = $this->db->jdate($obj->datec);
759 $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
760 }
761
762 $this->db->free($result);
763 } else {
764 dol_print_error($this->db);
765 }
766 }
767
774 public function initAsSpecimen()
775 {
776 $this->initAsSpecimenCommon();
777 }
778
784 public function getNextNumRef()
785 {
786 global $langs, $conf;
787 $langs->load("workstation");
788
789 if (empty($conf->global->WORKSTATION_WORKSTATION_ADDON)) {
790 $conf->global->WORKSTATION_WORKSTATION_ADDON = 'mod_workstation_standard';
791 }
792
793 if (!empty($conf->global->WORKSTATION_WORKSTATION_ADDON)) {
794 $mybool = false;
795
796 $file = $conf->global->WORKSTATION_WORKSTATION_ADDON.".php";
797 $classname = $conf->global->WORKSTATION_WORKSTATION_ADDON;
798
799 // Include file with class
800 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
801 foreach ($dirmodels as $reldir) {
802 $dir = dol_buildpath($reldir."core/modules/workstation/");
803
804 // Load file with numbering class (if found)
805 if (file_exists($dir.$file)) {
806 $mybool |= @include_once $dir.$file;
807 }
808 }
809
810 if ($mybool === false) {
811 dol_print_error('', "Failed to include file ".$file);
812 return '';
813 }
814
815 if (class_exists($classname)) {
816 $obj = new $classname();
817 $numref = $obj->getNextValue($this);
818
819 if ($numref != '' && $numref != '-1') {
820 return $numref;
821 } else {
822 $this->error = $obj->error;
823 //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
824 return "";
825 }
826 } else {
827 print $langs->trans("Error")." ".$langs->trans("ClassNotFound").' '.$classname;
828 return "";
829 }
830 } else {
831 print $langs->trans("ErrorNumberingModuleNotSetup", $this->element);
832 return "";
833 }
834 }
835
847 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
848 {
849 global $conf, $langs;
850
851 $result = 0;
852 $includedocgeneration = 0;
853
854 $langs->load("workstation");
855
856 if (!dol_strlen($modele)) {
857 $modele = 'standard_workstation';
858
859 if ($this->model_pdf) {
860 $modele = $this->model_pdf;
861 } elseif (!empty($conf->global->WORKSTATION_ADDON_PDF)) {
862 $modele = $conf->global->WORKSTATION_ADDON_PDF;
863 }
864 }
865
866 $modelpath = "core/modules/workstation/doc/";
867
868 if ($includedocgeneration) {
869 $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
870 }
871
872 return $result;
873 }
874}
$object ref
Definition info.php:78
Parent class of all other business classes (invoices, contracts, proposals, orders,...
deleteLineCommon(User $user, $idline, $notrigger=false)
Delete a line of object in database.
fetchCommon($id, $ref=null, $morewhere='')
Load object in memory from the 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.
copy_linked_contact($objFrom, $source='internal')
Copy contact from one element to current.
updateCommon(User $user, $notrigger=false)
Update object into database.
fetchLinesCommon($morewhere='')
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)
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 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.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.