dolibarr  18.0.0-alpha
workstation.class.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net>
3  * Copyright (C) 2020 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
4  * Copyright (C) 2023 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
27 require_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 
121  public $date_creation;
122  public $tms;
123  public $fk_user_creat;
124  public $fk_user_modif;
125 
129  public $status;
130  public $nb_operators_required;
131  public $thm_operator_estimated;
132  public $thm_machine_estimated;
133  // END MODULEBUILDER PROPERTIES
134 
138  public $resources;
139 
143  public $usergroups;
144 
150  public function __construct(DoliDB $db)
151  {
152  global $conf, $langs;
153 
154  require_once DOL_DOCUMENT_ROOT.'/workstation/class/workstationusergroup.class.php';
155  require_once DOL_DOCUMENT_ROOT.'/workstation/class/workstationresource.class.php';
156 
157  $this->db = $db;
158 
159  if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID) && isset($this->fields['rowid'])) {
160  $this->fields['rowid']['visible'] = 0;
161  }
162  if (empty($conf->multicompany->enabled) && isset($this->fields['entity'])) {
163  $this->fields['entity']['enabled'] = 0;
164  }
165 
166  // Unset fields that are disabled
167  foreach ($this->fields as $key => $val) {
168  if (isset($val['enabled']) && empty($val['enabled'])) {
169  unset($this->fields[$key]);
170  }
171  }
172 
173  // Translate some data of arrayofkeyval
174  if (is_object($langs)) {
175  foreach ($this->fields as $key => $val) {
176  if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
177  foreach ($val['arrayofkeyval'] as $key2 => $val2) {
178  $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
179  }
180  }
181  }
182  }
183  }
184 
192  public function create(User $user, $notrigger = false)
193  {
194  global $db;
195 
196  $id = $this->createCommon($user, $notrigger);
197 
198  // Usergroups
199  $groups = GETPOST('groups', 'array:int');
200  if (empty($groups)) {
201  $groups = $this->usergroups; // createFromClone
202  }
203  if (!empty($groups)) {
204  foreach ($groups as $id_group) {
205  $ws_usergroup = new WorkstationUserGroup($db);
206  $ws_usergroup->fk_workstation = $id;
207  $ws_usergroup->fk_usergroup = $id_group;
208  $ws_usergroup->createCommon($user);
209  $this->usergroups[] = $id_group;
210  }
211  }
212 
213  // Resources
214  $resources = GETPOST('resources', 'array:int');
215  if (empty($resources)) {
216  $resources = $this->resources; // createFromClone
217  }
218  if (!empty($resources)) {
219  foreach ($resources as $id_resource) {
220  $ws_resource = new WorkstationResource($db);
221  $ws_resource->fk_workstation = $id;
222  $ws_resource->fk_resource = $id_resource;
223  $ws_resource->createCommon($user);
224  $this->resources[] = $id_resource;
225  }
226  }
227 
228  return $id;
229  }
230 
238  public function createFromClone(User $user, $fromid)
239  {
240  global $langs, $extrafields;
241  $error = 0;
242 
243  dol_syslog(__METHOD__, LOG_DEBUG);
244 
245  $object = new self($this->db);
246 
247  $this->db->begin();
248 
249  // Load source object
250  $result = $object->fetch($fromid);
251  if ($result > 0 && !empty($object->table_element_line)) {
252  $object->fetchLines();
253  }
254 
255  // get lines so they will be clone
256  //foreach($this->lines as $line)
257  // $line->fetch_optionals();
258 
259  // Reset some properties
260  unset($object->id);
261  unset($object->fk_user_creat);
262  unset($object->import_key);
263 
264  // Clear fields
265  if (property_exists($object, 'ref')) {
266  $object->ref = empty($this->fields['ref']['default']) ? "Copy_Of_".$object->ref : $this->fields['ref']['default'];
267  }
268  if (property_exists($object, 'label')) {
269  $object->label = empty($this->fields['label']['default']) ? $langs->trans("CopyOf")." ".$object->label : $this->fields['label']['default'];
270  }
271  if (property_exists($object, 'status')) {
272  $object->status = self::STATUS_DISABLED;
273  }
274  if (property_exists($object, 'date_creation')) {
275  $object->date_creation = dol_now();
276  }
277  if (property_exists($object, 'date_modification')) {
278  $object->date_modification = null;
279  }
280  // ...
281  // Clear extrafields that are unique
282  if (is_array($object->array_options) && count($object->array_options) > 0) {
283  $extrafields->fetch_name_optionals_label($this->table_element);
284  foreach ($object->array_options as $key => $option) {
285  $shortkey = preg_replace('/options_/', '', $key);
286  if (!empty($extrafields->attributes[$this->table_element]['unique'][$shortkey])) {
287  //var_dump($key);
288  //var_dump($clonedObj->array_options[$key]); exit;
289  unset($object->array_options[$key]);
290  }
291  }
292  }
293 
294  // Create clone
295  $object->context['createfromclone'] = 'createfromclone';
296  $result = $object->create($user);
297  if ($result < 0) {
298  $error++;
299  $this->error = $object->error;
300  $this->errors = $object->errors;
301  }
302 
303  if (!$error) {
304  // copy internal contacts
305  if ($this->copy_linked_contact($object, 'internal') < 0) {
306  $error++;
307  }
308  }
309 
310  if (!$error) {
311  // copy external contacts if same company
312  if (property_exists($this, 'socid') && $this->socid == $object->socid) {
313  if ($this->copy_linked_contact($object, 'external') < 0) {
314  $error++;
315  }
316  }
317  }
318 
319  unset($object->context['createfromclone']);
320 
321  // End
322  if (!$error) {
323  $this->db->commit();
324  return $object;
325  } else {
326  $this->db->rollback();
327  return -1;
328  }
329  }
330 
338  public function fetch($id, $ref = null)
339  {
340  $result = $this->fetchCommon($id, $ref);
341 
342  $this->usergroups = WorkstationUserGroup::getAllGroupsOfWorkstation($this->id);
343  $this->resources = WorkstationResource::getAllResourcesOfWorkstation($this->id);
344 
345  if ($result > 0 && !empty($this->table_element_line)) {
346  $this->fetchLines();
347  }
348  return $result;
349  }
350 
356  public function fetchLines()
357  {
358  $this->lines = array();
359 
360  $result = $this->fetchLinesCommon();
361  return $result;
362  }
363 
364 
376  public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND')
377  {
378  global $conf;
379 
380  dol_syslog(__METHOD__, LOG_DEBUG);
381 
382  $records = array();
383 
384  $sql = 'SELECT ';
385  $sql .= $this->getFieldList();
386  $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
387  if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
388  $sql .= ' WHERE t.entity IN ('.getEntity($this->element).')';
389  } else {
390  $sql .= ' WHERE 1 = 1';
391  }
392  // Manage filter
393  $sqlwhere = array();
394  if (count($filter) > 0) {
395  foreach ($filter as $key => $value) {
396  if ($key == 't.rowid') {
397  $sqlwhere[] = $key." = ".((int) $value);
398  } elseif (in_array($this->fields[$key]['type'], array('date', 'datetime', 'timestamp'))) {
399  $sqlwhere[] = $key." = '".$this->db->idate($value)."'";
400  } elseif ($key == 'customsql') {
401  $sqlwhere[] = $value;
402  } elseif (strpos($value, '%') === false) {
403  $sqlwhere[] = $key." IN (".$this->db->sanitize($this->db->escape($value)).")";
404  } else {
405  $sqlwhere[] = $key." LIKE '%".$this->db->escape($value)."%'";
406  }
407  }
408  }
409  if (count($sqlwhere) > 0) {
410  $sql .= ' AND ('.implode(' '.$this->db->escape($filtermode).' ', $sqlwhere).')';
411  }
412 
413  if (!empty($sortfield)) {
414  $sql .= $this->db->order($sortfield, $sortorder);
415  }
416  if (!empty($limit)) {
417  $sql .= $this->db->plimit($limit, $offset);
418  }
419 
420  $resql = $this->db->query($sql);
421  if ($resql) {
422  $num = $this->db->num_rows($resql);
423  $i = 0;
424  while ($i < ($limit ? min($limit, $num) : $num)) {
425  $obj = $this->db->fetch_object($resql);
426 
427  $record = new self($this->db);
428  $record->setVarsFromFetchObj($obj);
429 
430  $records[$record->id] = $record;
431 
432  $i++;
433  }
434  $this->db->free($resql);
435 
436  return $records;
437  } else {
438  $this->errors[] = 'Error '.$this->db->lasterror();
439  dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
440 
441  return -1;
442  }
443  }
444 
452  public function update(User $user, $notrigger = false)
453  {
454 
455  // Usergroups
456  $groups = GETPOST('groups', 'array:int');
458  $this->usergroups=array();
459 
460  foreach ($groups as $id_group) {
461  $ws_usergroup = new WorkstationUserGroup($this->db);
462  $ws_usergroup->fk_workstation = $this->id;
463  $ws_usergroup->fk_usergroup = $id_group;
464  $ws_usergroup->createCommon($user);
465  $this->usergroups[] = $id_group;
466  }
467 
468  // Resources
469  $resources = GETPOST('resources', 'array:int');
471  $this->resources=array();
472  if (!empty($resources)) {
473  foreach ($resources as $id_resource) {
474  $ws_resource = new WorkstationResource($this->db);
475  $ws_resource->fk_workstation = $this->id;
476  $ws_resource->fk_resource = $id_resource;
477  $ws_resource->createCommon($user);
478  $this->resources[] = $id_resource;
479  }
480  }
481 
482  return $this->updateCommon($user, $notrigger);
483  }
484 
492  public function delete(User $user, $notrigger = false)
493  {
494  return $this->deleteCommon($user, $notrigger);
495  //return $this->deleteCommon($user, $notrigger, 1);
496  }
497 
506  public function deleteLine(User $user, $idline, $notrigger = false)
507  {
508  if ($this->status < 0) {
509  $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
510  return -2;
511  }
512 
513  return $this->deleteLineCommon($user, $idline, $notrigger);
514  }
515 
523  public function setStatus($status, $notrigger = 0)
524  {
525  global $user;
526 
527  $this->status = $status;
528 
529  if (empty($status)) {
530  return $this->setDisabled($user, $notrigger);
531  } else {
532  return $this->setEnabled($user, $notrigger);
533  }
534  }
535 
536 
544  public function setEnabled($user, $notrigger = 0)
545  {
546  return $this->setStatusCommon($user, self::STATUS_ENABLED, $notrigger, 'WORKSTATION_ENABLED');
547  }
548 
549 
557  public function setDisabled($user, $notrigger = 0)
558  {
559  return $this->setStatusCommon($user, self::STATUS_DISABLED, $notrigger, 'WORKSTATION_DISABLED');
560  }
561 
569  public function getTooltipContentArray($params)
570  {
571  global $conf, $langs;
572 
573  $langs->load('mrp');
574 
575  $datas = [];
576  $datas['picto'] = img_picto('', $this->picto).' <u>'.$langs->trans("Workstation").'</u>';
577  $datas['ref'] = '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref;
578  if (isset($this->status)) {
579  $datas['status'] = '<br><b>'.$langs->trans("Status").":</b> ".$this->getLibStatut(5);
580  }
581 
582  return $datas;
583  }
584 
595  public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
596  {
597  global $conf, $langs, $hookmanager;
598 
599  if (!empty($conf->dol_no_mouse_hover)) {
600  $notooltip = 1; // Force disable tooltips
601  }
602 
603  $result = '';
604 
605  $params = [
606  'id' => $this->id,
607  'objecttype' => $this->element,
608  ];
609  $classfortooltip = 'classfortooltip';
610  $dataparams = '';
611  if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
612  $classfortooltip = 'classforajaxtooltip';
613  $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"';
614  $label = '';
615  } else {
616  $label = implode($this->getTooltipContentArray($params));
617  }
618 
619  $url = dol_buildpath('/workstation/workstation_card.php', 1).'?id='.$this->id;
620 
621  if ($option != 'nolink') {
622  // Add param to save lastsearch_values or not
623  $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
624  if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
625  $add_save_lastsearch_values = 1;
626  }
627  if ($add_save_lastsearch_values) {
628  $url .= '&save_lastsearch_values=1';
629  }
630  }
631 
632  $linkclose = '';
633  if (empty($notooltip)) {
634  if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
635  $label = $langs->trans("ShowWorkstation");
636  $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
637  }
638  $linkclose .= ($label ? ' title="'.dol_escape_htmltag($label, 1).'"' : ' title="tocomplete"');
639  $linkclose .= $dataparams.' class="'.$classfortooltip.($morecss ? ' '.$morecss : '').'"';
640  } else {
641  $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
642  }
643 
644  $linkstart = '<a href="'.$url.'"';
645  $linkstart .= $linkclose.'>';
646  $linkend = '</a>';
647 
648  $result .= $linkstart;
649 
650  if (empty($this->showphoto_on_popup)) {
651  if ($withpicto) {
652  $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'mrp'), (($withpicto != 2) ? 'class="paddingright"' : ''), 0, 0, $notooltip ? 0 : 1);
653  }
654  } else {
655  if ($withpicto) {
656  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
657 
658  list($class, $module) = explode('@', $this->picto);
659  $upload_dir = $conf->$module->multidir_output[$conf->entity]."/$class/".dol_sanitizeFileName($this->ref);
660  $filearray = dol_dir_list($upload_dir, "files");
661  $filename = $filearray[0]['name'];
662  if (!empty($filename)) {
663  $pospoint = strpos($filearray[0]['name'], '.');
664 
665  $pathtophoto = $class.'/'.$this->ref.'/thumbs/'.substr($filename, 0, $pospoint).'_mini'.substr($filename, $pospoint);
666  if (empty($conf->global->{strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS'})) {
667  $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>';
668  } else {
669  $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>';
670  }
671 
672  $result .= '</div>';
673  } else {
674  $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);
675  }
676  }
677  }
678 
679  if ($withpicto != 2) {
680  $result .= $this->ref;
681  }
682 
683  $result .= $linkend;
684  //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
685 
686  global $action, $hookmanager;
687  $hookmanager->initHooks(array('workstationdao'));
688  $parameters = array('id'=>$this->id, 'getnomurl' => &$result);
689  $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
690  if ($reshook > 0) {
691  $result = $hookmanager->resPrint;
692  } else {
693  $result .= $hookmanager->resPrint;
694  }
695 
696  return $result;
697  }
698 
705  public function getLibStatut($mode = 0)
706  {
707  return $this->LibStatut($this->status, $mode);
708  }
709 
710  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
718  public function LibStatut($status, $mode = 0)
719  {
720  // phpcs:enable
721  if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
722  global $langs;
723  //$langs->load("workstation");
724  $this->labelStatus[self::STATUS_DISABLED] = $langs->transnoentitiesnoconv('Disabled');
725  $this->labelStatus[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv('Enabled');
726  $this->labelStatusShort[self::STATUS_DISABLED] = $langs->transnoentitiesnoconv('Disabled');
727  $this->labelStatusShort[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv('Enabled');
728  }
729 
730  $statusType = 'status'.$status;
731  //if ($status == self::STATUS_DISABLED) $statusType = 'status6';
732  if ($status == self::STATUS_ENABLED) $statusType = 'status4';
733 
734  return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
735  }
736 
743  public function info($id)
744  {
745  $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
746  $sql .= ' fk_user_creat, fk_user_modif';
747  $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
748  $sql .= ' WHERE t.rowid = '.((int) $id);
749  $result = $this->db->query($sql);
750  if ($result) {
751  if ($this->db->num_rows($result)) {
752  $obj = $this->db->fetch_object($result);
753  $this->id = $obj->rowid;
754 
755  $this->user_creation_id = $obj->fk_user_creat;
756  $this->user_modification_id = $obj->fk_user_modif;
757  $this->date_creation = $this->db->jdate($obj->datec);
758  $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
759  }
760 
761  $this->db->free($result);
762  } else {
763  dol_print_error($this->db);
764  }
765  }
766 
773  public function initAsSpecimen()
774  {
775  $this->initAsSpecimenCommon();
776  }
777 
783  public function getNextNumRef()
784  {
785  global $langs, $conf;
786  $langs->load("workstation");
787 
788  if (empty($conf->global->WORKSTATION_WORKSTATION_ADDON)) {
789  $conf->global->WORKSTATION_WORKSTATION_ADDON = 'mod_workstation_standard';
790  }
791 
792  if (!empty($conf->global->WORKSTATION_WORKSTATION_ADDON)) {
793  $mybool = false;
794 
795  $file = $conf->global->WORKSTATION_WORKSTATION_ADDON.".php";
796  $classname = $conf->global->WORKSTATION_WORKSTATION_ADDON;
797 
798  // Include file with class
799  $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
800  foreach ($dirmodels as $reldir) {
801  $dir = dol_buildpath($reldir."core/modules/workstation/");
802 
803  // Load file with numbering class (if found)
804  $mybool |= @include_once $dir.$file;
805  }
806 
807  if ($mybool === false) {
808  dol_print_error('', "Failed to include file ".$file);
809  return '';
810  }
811 
812  if (class_exists($classname)) {
813  $obj = new $classname();
814  $numref = $obj->getNextValue($this);
815 
816  if ($numref != '' && $numref != '-1') {
817  return $numref;
818  } else {
819  $this->error = $obj->error;
820  //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
821  return "";
822  }
823  } else {
824  print $langs->trans("Error")." ".$langs->trans("ClassNotFound").' '.$classname;
825  return "";
826  }
827  } else {
828  print $langs->trans("ErrorNumberingModuleNotSetup", $this->element);
829  return "";
830  }
831  }
832 
844  public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
845  {
846  global $conf, $langs;
847 
848  $result = 0;
849  $includedocgeneration = 0;
850 
851  $langs->load("workstation");
852 
853  if (!dol_strlen($modele)) {
854  $modele = 'standard_workstation';
855 
856  if ($this->model_pdf) {
857  $modele = $this->model_pdf;
858  } elseif (!empty($conf->global->WORKSTATION_ADDON_PDF)) {
859  $modele = $conf->global->WORKSTATION_ADDON_PDF;
860  }
861  }
862 
863  $modelpath = "core/modules/workstation/doc/";
864 
865  if ($includedocgeneration) {
866  $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
867  }
868 
869  return $result;
870  }
871 }
Workstation\setEnabled
setEnabled($user, $notrigger=0)
Set draft status.
Definition: workstation.class.php:544
CommonObject\deleteCommon
deleteCommon(User $user, $notrigger=false, $forcechilddeletion=0)
Delete object in database.
Definition: commonobject.class.php:9776
Workstation\getTooltipContentArray
getTooltipContentArray($params)
getTooltipContentArray
Definition: workstation.class.php:569
CommonObject\setStatusCommon
setStatusCommon($user, $status, $notrigger=0, $triggercode='')
Set to a status.
Definition: commonobject.class.php:10054
CommonObject\fetchCommon
fetchCommon($id, $ref=null, $morewhere='')
Load object in memory from the database.
Definition: commonobject.class.php:9566
Workstation\fetch
fetch($id, $ref=null)
Load object in memory from the database.
Definition: workstation.class.php:338
Workstation\create
create(User $user, $notrigger=false)
Create object into database.
Definition: workstation.class.php:192
dol_sanitizeFileName
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
Definition: functions.lib.php:1282
CommonObject\copy_linked_contact
copy_linked_contact($objFrom, $source='internal')
Copy contact from one element to current.
Definition: commonobject.class.php:1337
Workstation\fetchLines
fetchLines()
Load object lines in memory from the database.
Definition: workstation.class.php:356
DoliDB
Class to manage Dolibarr database access.
Definition: DoliDB.class.php:30
Workstation\fetchAll
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, array $filter=array(), $filtermode='AND')
Load list of objects in memory from the database.
Definition: workstation.class.php:376
Workstation
Class for Workstation.
Definition: workstation.class.php:32
$sql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $sql
Social contributions to pay.
Definition: index.php:745
Workstation\getLibStatut
getLibStatut($mode=0)
Return the label of the status.
Definition: workstation.class.php:705
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:567
WorkstationUserGroup
Class to link User groups and Workstations.
Definition: workstationusergroup.class.php:28
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:5052
dol_buildpath
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
Definition: functions.lib.php:1117
dol_dir_list
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
CommonObject\fetchLinesCommon
fetchLinesCommon($morewhere='')
Load object in memory from the database.
Definition: commonobject.class.php:9622
Workstation\__construct
__construct(DoliDB $db)
Constructor.
Definition: workstation.class.php:150
Workstation\generateDocument
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk according to template module.
Definition: workstation.class.php:844
Workstation\getNomUrl
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return a link to the object card (with optionaly the picto)
Definition: workstation.class.php:595
Workstation\getNextNumRef
getNextNumRef()
Returns the reference to the following non used object depending on the active numbering module.
Definition: workstation.class.php:783
CommonObject
Parent class of all other business classes (invoices, contracts, proposals, orders,...
Definition: commonobject.class.php:45
Workstation\deleteLine
deleteLine(User $user, $idline, $notrigger=false)
Delete a line of object in database.
Definition: workstation.class.php:506
Workstation\initAsSpecimen
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
Definition: workstation.class.php:773
img_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:4082
CommonObject\createCommon
createCommon(User $user, $notrigger=false)
Create object into database.
Definition: commonobject.class.php:9399
Workstation\setDisabled
setDisabled($user, $notrigger=0)
Set draft status.
Definition: workstation.class.php:557
WorkstationResource\deleteAllResourcesOfWorkstation
static deleteAllResourcesOfWorkstation($fk_workstation)
Function used to remove all resources linked to a workstation.
Definition: workstationresource.class.php:105
Workstation\info
info($id)
Load the info information in the object.
Definition: workstation.class.php:743
Workstation\LibStatut
LibStatut($status, $mode=0)
Return the status.
Definition: workstation.class.php:718
WorkstationUserGroup\getAllGroupsOfWorkstation
static getAllGroupsOfWorkstation($fk_workstation)
Function used to get an array with all usergroups linked to a workstation.
Definition: workstationusergroup.class.php:91
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1689
WorkstationResource
Class to link resource with Workstations.
Definition: workstationresource.class.php:29
Workstation\update
update(User $user, $notrigger=false)
Update object into database.
Definition: workstation.class.php:452
CommonObject\updateCommon
updateCommon(User $user, $notrigger=false)
Update object into database.
Definition: commonobject.class.php:9672
WorkstationResource\getAllResourcesOfWorkstation
static getAllResourcesOfWorkstation($fk_workstation)
Function used to get an array with all resources linked to a workstation.
Definition: workstationresource.class.php:92
WorkstationUserGroup\deleteAllGroupsOfWorkstation
static deleteAllGroupsOfWorkstation($fk_workstation)
Function used to remove all usergroups linked to a workstation.
Definition: workstationusergroup.class.php:105
Workstation\createFromClone
createFromClone(User $user, $fromid)
Clone an object into another one.
Definition: workstation.class.php:238
dol_strlen
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
Definition: functions.lib.php:3944
ref
$object ref
Definition: info.php:78
User
Class to manage Dolibarr users.
Definition: user.class.php:46
Workstation\setStatus
setStatus($status, $notrigger=0)
Set draft status.
Definition: workstation.class.php:523
dolGetStatus
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
Definition: functions.lib.php:10863
img_object
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
Definition: functions.lib.php:4419
dol_now
dol_now($mode='auto')
Return date for now.
Definition: functions.lib.php:3003
CommonObject\deleteLineCommon
deleteLineCommon(User $user, $idline, $notrigger=false)
Delete a line of object in database.
Definition: commonobject.class.php:9992
getDolGlobalInt
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
Definition: functions.lib.php:116
CommonObject\getFieldList
getFieldList($alias='')
Function to concat keys of fields.
Definition: commonobject.class.php:9351