dolibarr  16.0.5
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  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <https://www.gnu.org/licenses/>.
17  */
18 
25 // Put here all includes required by your class file
26 require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
27 //require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php';
28 //require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
29 
34 {
38  public $module = 'workstation';
39 
43  public $element = 'workstation';
44 
48  public $table_element = 'workstation_workstation';
49 
54  public $ismultientitymanaged = 0;
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  '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"),
104  'label' => array('type'=>'varchar(255)', 'label'=>'Label', 'enabled'=>'1', 'position'=>30, 'notnull'=>1, 'visible'=>1, 'searchall'=>1, 'css'=>'minwidth300', 'csslist'=>'tdoverflowmax125', 'showoncombobox'=>'2',),
105  'type' => array('type'=>'varchar(8)', 'label'=>'Type', 'enabled'=>'1', 'position'=>32, 'default'=>1, 'notnull'=>1, 'visible'=>1, 'arrayofkeyval'=>array('HUMAN'=>'Human', 'MACHINE'=>'Machine', 'BOTH'=>'HumanMachine'),),
106  'note_public' => array('type'=>'html', 'label'=>'NotePublic', 'enabled'=>'1', 'position'=>61, 'notnull'=>0, 'visible'=>0,),
107  'note_private' => array('type'=>'html', 'label'=>'NotePrivate', 'enabled'=>'1', 'position'=>62, 'notnull'=>0, 'visible'=>0,),
108  'date_creation' => array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>'1', 'position'=>500, 'notnull'=>1, 'visible'=>-2, 'csslist'=>'nowraponall'),
109  'tms' => array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>'1', 'position'=>501, 'notnull'=>0, 'visible'=>-2, 'csslist'=>'nowraponall'),
110  'fk_user_creat' => array('type'=>'integer:User:user/class/user.class.php', 'label'=>'UserAuthor', 'enabled'=>'1', 'position'=>510, 'notnull'=>1, 'visible'=>-2, 'foreignkey'=>'user.rowid',),
111  'fk_user_modif' => array('type'=>'integer:User:user/class/user.class.php', 'label'=>'UserModif', 'enabled'=>'1', 'position'=>511, 'notnull'=>-1, 'visible'=>-2,),
112  'import_key' => array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>'1', 'position'=>512, 'notnull'=>-1, 'visible'=>-2,),
113  'nb_operators_required' => array('type'=>'integer', 'label'=>'NbOperatorsRequired', 'enabled'=>'1', 'position'=>50, 'notnull'=>0, 'visible'=>1,),
114  'thm_operator_estimated' => array('type'=>'double', 'help'=>'THMOperatorEstimatedHelp','label'=>'THMOperatorEstimated', 'enabled'=>'1', 'position'=>50, 'notnull'=>0, 'visible'=>1, 'css'=>'right'),
115  'thm_machine_estimated' => array('type'=>'double', 'help'=>'THMMachineEstimatedHelp', 'label'=>'THMMachineEstimated', 'enabled'=>'1', 'position'=>50, 'notnull'=>0, 'visible'=>1, 'css'=>'right'),
116  'status' => array('type'=>'smallint', 'label'=>'Status', 'enabled'=>'1', 'position'=>1000, 'default'=>1, 'notnull'=>1, 'visible'=>1, 'index'=>1, 'arrayofkeyval'=>array('0'=>'Disabled', '1'=>'Enabled'),),
117  );
118  public $rowid;
119  public $ref;
120  public $label;
121  public $note_public;
122  public $note_private;
123  public $date_creation;
124  public $tms;
125  public $fk_user_creat;
126  public $fk_user_modif;
127  public $import_key;
128  public $status;
129  public $nb_operators_required;
130  public $thm_operator_estimated;
131  public $thm_machine_estimated;
132  // END MODULEBUILDER PROPERTIES
133 
134 
135  // If this object has a subtable with lines
136 
140  //public $table_element_line = 'workstation_workstationline';
141 
145  //public $fk_element = 'fk_workstation';
146 
150  //public $class_element_line = 'Workstationline';
151 
155  //protected $childtables = array();
156 
162  //protected $childtablesoncascade = array('workstation_workstationdet');
163 
167  //public $lines = array();
168 
169 
170 
176  public function __construct(DoliDB $db)
177  {
178  global $conf, $langs;
179 
180  require_once DOL_DOCUMENT_ROOT.'/workstation/class/workstationusergroup.class.php';
181  require_once DOL_DOCUMENT_ROOT.'/workstation/class/workstationresource.class.php';
182 
183  $this->db = $db;
184 
185  $this->fields['ref']['default'] = $this->getNextNumRef();
186 
187  if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID) && isset($this->fields['rowid'])) {
188  $this->fields['rowid']['visible'] = 0;
189  }
190  if (empty($conf->multicompany->enabled) && isset($this->fields['entity'])) {
191  $this->fields['entity']['enabled'] = 0;
192  }
193 
194  // Example to show how to set values of fields definition dynamically
195  /*if ($user->rights->workstation->workstation->read) {
196  $this->fields['myfield']['visible'] = 1;
197  $this->fields['myfield']['noteditable'] = 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 = false)
227  {
228  global $db;
229 
230  $id = $this->createCommon($user, $notrigger);
231 
232  // Usergroups
233  $groups = GETPOST('groups', 'array:int');
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');
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  if (property_exists($object, 'ref')) {
300  $object->ref = empty($this->fields['ref']['default']) ? "Copy_Of_".$object->ref : $this->fields['ref']['default'];
301  }
302  if (property_exists($object, 'label')) {
303  $object->label = empty($this->fields['label']['default']) ? $langs->trans("CopyOf")." ".$object->label : $this->fields['label']['default'];
304  }
305  if (property_exists($object, 'status')) {
306  $object->status = self::STATUS_DISABLED;
307  }
308  if (property_exists($object, 'date_creation')) {
309  $object->date_creation = dol_now();
310  }
311  if (property_exists($object, 'date_modification')) {
312  $object->date_modification = null;
313  }
314  // ...
315  // Clear extrafields that are unique
316  if (is_array($object->array_options) && count($object->array_options) > 0) {
317  $extrafields->fetch_name_optionals_label($this->table_element);
318  foreach ($object->array_options as $key => $option) {
319  $shortkey = preg_replace('/options_/', '', $key);
320  if (!empty($extrafields->attributes[$this->table_element]['unique'][$shortkey])) {
321  //var_dump($key);
322  //var_dump($clonedObj->array_options[$key]); exit;
323  unset($object->array_options[$key]);
324  }
325  }
326  }
327 
328  // Create clone
329  $object->context['createfromclone'] = 'createfromclone';
330  $result = $object->create($user);
331  if ($result < 0) {
332  $error++;
333  $this->error = $object->error;
334  $this->errors = $object->errors;
335  }
336 
337  if (!$error) {
338  // copy internal contacts
339  if ($this->copy_linked_contact($object, 'internal') < 0) {
340  $error++;
341  }
342  }
343 
344  if (!$error) {
345  // copy external contacts if same company
346  if (property_exists($this, 'socid') && $this->socid == $object->socid) {
347  if ($this->copy_linked_contact($object, 'external') < 0) {
348  $error++;
349  }
350  }
351  }
352 
353  unset($object->context['createfromclone']);
354 
355  // End
356  if (!$error) {
357  $this->db->commit();
358  return $object;
359  } else {
360  $this->db->rollback();
361  return -1;
362  }
363  }
364 
372  public function fetch($id, $ref = null)
373  {
374  $result = $this->fetchCommon($id, $ref);
375 
376  $this->usergroups = WorkstationUserGroup::getAllGroupsOfWorkstation($this->id);
377  $this->resources = WorkstationResource::getAllResourcesOfWorkstation($this->id);
378 
379  if ($result > 0 && !empty($this->table_element_line)) {
380  $this->fetchLines();
381  }
382  return $result;
383  }
384 
390  public function fetchLines()
391  {
392  $this->lines = array();
393 
394  $result = $this->fetchLinesCommon();
395  return $result;
396  }
397 
398 
410  public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND')
411  {
412  global $conf;
413 
414  dol_syslog(__METHOD__, LOG_DEBUG);
415 
416  $records = array();
417 
418  $sql = 'SELECT ';
419  $sql .= $this->getFieldList();
420  $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
421  if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
422  $sql .= ' WHERE t.entity IN ('.getEntity($this->table_element).')';
423  } else {
424  $sql .= ' WHERE 1 = 1';
425  }
426  // Manage filter
427  $sqlwhere = array();
428  if (count($filter) > 0) {
429  foreach ($filter as $key => $value) {
430  if ($key == 't.rowid') {
431  $sqlwhere[] = $key." = ".((int) $value);
432  } elseif (in_array($this->fields[$key]['type'], array('date', 'datetime', 'timestamp'))) {
433  $sqlwhere[] = $key." = '".$this->db->idate($value)."'";
434  } elseif ($key == 'customsql') {
435  $sqlwhere[] = $value;
436  } elseif (strpos($value, '%') === false) {
437  $sqlwhere[] = $key." IN (".$this->db->sanitize($this->db->escape($value)).")";
438  } else {
439  $sqlwhere[] = $key." LIKE '%".$this->db->escape($value)."%'";
440  }
441  }
442  }
443  if (count($sqlwhere) > 0) {
444  $sql .= ' AND ('.implode(' '.$this->db->escape($filtermode).' ', $sqlwhere).')';
445  }
446 
447  if (!empty($sortfield)) {
448  $sql .= $this->db->order($sortfield, $sortorder);
449  }
450  if (!empty($limit)) {
451  $sql .= $this->db->plimit($limit, $offset);
452  }
453 
454  $resql = $this->db->query($sql);
455  if ($resql) {
456  $num = $this->db->num_rows($resql);
457  $i = 0;
458  while ($i < ($limit ? min($limit, $num) : $num)) {
459  $obj = $this->db->fetch_object($resql);
460 
461  $record = new self($this->db);
462  $record->setVarsFromFetchObj($obj);
463 
464  $records[$record->id] = $record;
465 
466  $i++;
467  }
468  $this->db->free($resql);
469 
470  return $records;
471  } else {
472  $this->errors[] = 'Error '.$this->db->lasterror();
473  dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
474 
475  return -1;
476  }
477  }
478 
486  public function update(User $user, $notrigger = false)
487  {
488 
489  // Usergroups
490  $groups = GETPOST('groups', 'array:int');
492  $this->usergroups=array();
493 
494  foreach ($groups as $id_group) {
495  $ws_usergroup = new WorkstationUserGroup($this->db);
496  $ws_usergroup->fk_workstation = $this->id;
497  $ws_usergroup->fk_usergroup = $id_group;
498  $ws_usergroup->createCommon($user);
499  $this->usergroups[] = $id_group;
500  }
501 
502  // Resources
503  $resources = GETPOST('resources', 'array:int');
505  $this->resources=array();
506  if (!empty($resources)) {
507  foreach ($resources as $id_resource) {
508  $ws_resource = new WorkstationResource($this->db);
509  $ws_resource->fk_workstation = $this->id;
510  $ws_resource->fk_resource = $id_resource;
511  $ws_resource->createCommon($user);
512  $this->resources[] = $id_resource;
513  }
514  }
515 
516  return $this->updateCommon($user, $notrigger);
517  }
518 
526  public function delete(User $user, $notrigger = false)
527  {
528  return $this->deleteCommon($user, $notrigger);
529  //return $this->deleteCommon($user, $notrigger, 1);
530  }
531 
540  public function deleteLine(User $user, $idline, $notrigger = false)
541  {
542  if ($this->status < 0) {
543  $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
544  return -2;
545  }
546 
547  return $this->deleteLineCommon($user, $idline, $notrigger);
548  }
549 
550 
558  public function validate($user, $notrigger = 0)
559  {
560  global $conf, $langs;
561 
562  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
563 
564  $error = 0;
565 
566  // Protection
567  if ($this->status == self::STATUS_VALIDATED) {
568  dol_syslog(get_class($this)."::validate action abandonned: already validated", LOG_WARNING);
569  return 0;
570  }
571 
572  /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->workstation->workstation->write))
573  || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->workstation->workstation->workstation_advance->validate))))
574  {
575  $this->error='NotEnoughPermissions';
576  dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR);
577  return -1;
578  }*/
579 
580  $now = dol_now();
581 
582  $this->db->begin();
583 
584  // Define new ref
585  if (!$error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life
586  $num = $this->getNextNumRef();
587  } else {
588  $num = $this->ref;
589  }
590  $this->newref = $num;
591 
592  if (!empty($num)) {
593  // Validate
594  $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
595  $sql .= " SET ref = '".$this->db->escape($num)."',";
596  $sql .= " status = ".self::STATUS_VALIDATED;
597  if (!empty($this->fields['date_validation'])) {
598  $sql .= ", date_validation = '".$this->db->idate($now)."'";
599  }
600  if (!empty($this->fields['fk_user_valid'])) {
601  $sql .= ", fk_user_valid = ".$user->id;
602  }
603  $sql .= " WHERE rowid = ".((int) $this->id);
604 
605  dol_syslog(get_class($this)."::validate()", LOG_DEBUG);
606  $resql = $this->db->query($sql);
607  if (!$resql) {
608  dol_print_error($this->db);
609  $this->error = $this->db->lasterror();
610  $error++;
611  }
612 
613  if (!$error && !$notrigger) {
614  // Call trigger
615  $result = $this->call_trigger('WORKSTATION_VALIDATE', $user);
616  if ($result < 0) {
617  $error++;
618  }
619  // End call triggers
620  }
621  }
622 
623  if (!$error) {
624  $this->oldref = $this->ref;
625 
626  // Rename directory if dir was a temporary ref
627  if (preg_match('/^[\(]?PROV/i', $this->ref)) {
628  // Now we rename also files into index
629  $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filename = CONCAT('".$this->db->escape($this->newref)."', SUBSTR(filename, ".(strlen($this->ref) + 1).")), filepath = 'workstation/".$this->db->escape($this->newref)."'";
630  $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'workstation/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
631  $resql = $this->db->query($sql);
632  if (!$resql) {
633  $error++; $this->error = $this->db->lasterror();
634  }
635 
636  // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
637  $oldref = dol_sanitizeFileName($this->ref);
638  $newref = dol_sanitizeFileName($num);
639  $dirsource = $conf->workstation->dir_output.'/workstation/'.$oldref;
640  $dirdest = $conf->workstation->dir_output.'/workstation/'.$newref;
641  if (!$error && file_exists($dirsource)) {
642  dol_syslog(get_class($this)."::validate() rename dir ".$dirsource." into ".$dirdest);
643 
644  if (@rename($dirsource, $dirdest)) {
645  dol_syslog("Rename ok");
646  // Rename docs starting with $oldref with $newref
647  $listoffiles = dol_dir_list($conf->workstation->dir_output.'/workstation/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
648  foreach ($listoffiles as $fileentry) {
649  $dirsource = $fileentry['name'];
650  $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
651  $dirsource = $fileentry['path'].'/'.$dirsource;
652  $dirdest = $fileentry['path'].'/'.$dirdest;
653  @rename($dirsource, $dirdest);
654  }
655  }
656  }
657  }
658  }
659 
660  // Set new ref and current status
661  if (!$error) {
662  $this->ref = $num;
663  $this->status = self::STATUS_VALIDATED;
664  }
665 
666  if (!$error) {
667  $this->db->commit();
668  return 1;
669  } else {
670  $this->db->rollback();
671  return -1;
672  }
673  }
674 
675 
683  public function setStatus($status, $notrigger = 0)
684  {
685  global $user;
686 
687  $this->status = $status;
688 
689  if (empty($status)) {
690  return $this->setDisabled($user, $notrigger);
691  } else {
692  return $this->setEnabled($user, $notrigger);
693  }
694  }
695 
696 
704  public function setEnabled($user, $notrigger = 0)
705  {
706  return $this->setStatusCommon($user, self::STATUS_ENABLED, $notrigger, 'WORKSTATION_ENABLED');
707  }
708 
709 
717  public function setDisabled($user, $notrigger = 0)
718  {
719  return $this->setStatusCommon($user, self::STATUS_DISABLED, $notrigger, 'WORKSTATION_DISABLED');
720  }
721 
732  public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
733  {
734  global $conf, $langs, $hookmanager;
735 
736  if (!empty($conf->dol_no_mouse_hover)) {
737  $notooltip = 1; // Force disable tooltips
738  }
739 
740  $result = '';
741 
742  $label = img_picto('', $this->picto).' <u>'.$langs->trans("Workstation").'</u>';
743  $label .= '<br>';
744  $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
745  if (isset($this->status)) {
746  $label .= '<br><b>'.$langs->trans("Status").":</b> ".$this->getLibStatut(5);
747  }
748 
749  $url = dol_buildpath('/workstation/workstation_card.php', 1).'?id='.$this->id;
750 
751  if ($option != 'nolink') {
752  // Add param to save lastsearch_values or not
753  $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
754  if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
755  $add_save_lastsearch_values = 1;
756  }
757  if ($add_save_lastsearch_values) {
758  $url .= '&save_lastsearch_values=1';
759  }
760  }
761 
762  $linkclose = '';
763  if (empty($notooltip)) {
764  if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
765  $label = $langs->trans("ShowWorkstation");
766  $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
767  }
768  $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
769  $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
770  } else {
771  $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
772  }
773 
774  $linkstart = '<a href="'.$url.'"';
775  $linkstart .= $linkclose.'>';
776  $linkend = '</a>';
777 
778  $result .= $linkstart;
779 
780  if (empty($this->showphoto_on_popup)) {
781  if ($withpicto) {
782  $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);
783  }
784  } else {
785  if ($withpicto) {
786  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
787 
788  list($class, $module) = explode('@', $this->picto);
789  $upload_dir = $conf->$module->multidir_output[$conf->entity]."/$class/".dol_sanitizeFileName($this->ref);
790  $filearray = dol_dir_list($upload_dir, "files");
791  $filename = $filearray[0]['name'];
792  if (!empty($filename)) {
793  $pospoint = strpos($filearray[0]['name'], '.');
794 
795  $pathtophoto = $class.'/'.$this->ref.'/thumbs/'.substr($filename, 0, $pospoint).'_mini'.substr($filename, $pospoint);
796  if (empty($conf->global->{strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS'})) {
797  $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>';
798  } else {
799  $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>';
800  }
801 
802  $result .= '</div>';
803  } else {
804  $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);
805  }
806  }
807  }
808 
809  if ($withpicto != 2) {
810  $result .= $this->ref;
811  }
812 
813  $result .= $linkend;
814  //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
815 
816  global $action, $hookmanager;
817  $hookmanager->initHooks(array('workstationdao'));
818  $parameters = array('id'=>$this->id, 'getnomurl' => &$result);
819  $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
820  if ($reshook > 0) {
821  $result = $hookmanager->resPrint;
822  } else {
823  $result .= $hookmanager->resPrint;
824  }
825 
826  return $result;
827  }
828 
835  public function getLibStatut($mode = 0)
836  {
837  return $this->LibStatut($this->status, $mode);
838  }
839 
840  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
848  public function LibStatut($status, $mode = 0)
849  {
850  // phpcs:enable
851  if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
852  global $langs;
853  //$langs->load("workstation");
854  $this->labelStatus[self::STATUS_DISABLED] = $langs->transnoentitiesnoconv('Disabled');
855  $this->labelStatus[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv('Enabled');
856  $this->labelStatusShort[self::STATUS_DISABLED] = $langs->transnoentitiesnoconv('Disabled');
857  $this->labelStatusShort[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv('Enabled');
858  }
859 
860  $statusType = 'status'.$status;
861  //if ($status == self::STATUS_DISABLED) $statusType = 'status6';
862  if ($status == self::STATUS_ENABLED) $statusType = 'status4';
863 
864  return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
865  }
866 
873  public function info($id)
874  {
875  $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
876  $sql .= ' fk_user_creat, fk_user_modif';
877  $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
878  $sql .= ' WHERE t.rowid = '.((int) $id);
879  $result = $this->db->query($sql);
880  if ($result) {
881  if ($this->db->num_rows($result)) {
882  $obj = $this->db->fetch_object($result);
883  $this->id = $obj->rowid;
884 
885  $this->user_creation_id = $obj->fk_user_creat;
886  $this->user_modification_id = $obj->fk_user_modif;
887  $this->date_creation = $this->db->jdate($obj->datec);
888  $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
889  }
890 
891  $this->db->free($result);
892  } else {
893  dol_print_error($this->db);
894  }
895  }
896 
903  public function initAsSpecimen()
904  {
905  $this->initAsSpecimenCommon();
906  }
907 
913  public function getLinesArray()
914  {
915  $this->lines = array();
916 
917  /*
918  $objectline = new WorkstationLine($this->db);
919  $result = $objectline->fetchAll('ASC', 'position', 0, 0, array('customsql'=>'fk_workstation = '.((int) $this->id)));
920 
921  if (is_numeric($result)) {
922  $this->error = $this->error;
923  $this->errors = $this->errors;
924  return $result;
925  }
926 
927  $this->lines = $result;
928  */
929 
930  return $this->lines;
931  }
932 
938  public function getNextNumRef()
939  {
940  global $langs, $conf;
941  $langs->load("workstation");
942 
943  if (empty($conf->global->WORKSTATION_WORKSTATION_ADDON)) {
944  $conf->global->WORKSTATION_WORKSTATION_ADDON = 'mod_workstation_standard';
945  }
946 
947  if (!empty($conf->global->WORKSTATION_WORKSTATION_ADDON)) {
948  $mybool = false;
949 
950  $file = $conf->global->WORKSTATION_WORKSTATION_ADDON.".php";
951  $classname = $conf->global->WORKSTATION_WORKSTATION_ADDON;
952 
953  // Include file with class
954  $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
955  foreach ($dirmodels as $reldir) {
956  $dir = dol_buildpath($reldir."core/modules/workstation/");
957 
958  // Load file with numbering class (if found)
959  $mybool |= @include_once $dir.$file;
960  }
961 
962  if ($mybool === false) {
963  dol_print_error('', "Failed to include file ".$file);
964  return '';
965  }
966 
967  if (class_exists($classname)) {
968  $obj = new $classname();
969  $numref = $obj->getNextValue($this);
970 
971  if ($numref != '' && $numref != '-1') {
972  return $numref;
973  } else {
974  $this->error = $obj->error;
975  //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
976  return "";
977  }
978  } else {
979  print $langs->trans("Error")." ".$langs->trans("ClassNotFound").' '.$classname;
980  return "";
981  }
982  } else {
983  print $langs->trans("ErrorNumberingModuleNotSetup", $this->element);
984  return "";
985  }
986  }
987 
999  public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
1000  {
1001  global $conf, $langs;
1002 
1003  $result = 0;
1004  $includedocgeneration = 0;
1005 
1006  $langs->load("workstation");
1007 
1008  if (!dol_strlen($modele)) {
1009  $modele = 'standard_workstation';
1010 
1011  if ($this->model_pdf) {
1012  $modele = $this->model_pdf;
1013  } elseif (!empty($conf->global->WORKSTATION_ADDON_PDF)) {
1014  $modele = $conf->global->WORKSTATION_ADDON_PDF;
1015  }
1016  }
1017 
1018  $modelpath = "core/modules/workstation/doc/";
1019 
1020  if ($includedocgeneration) {
1021  $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1022  }
1023 
1024  return $result;
1025  }
1026 
1034  public function doScheduledJob()
1035  {
1036  global $conf, $langs;
1037 
1038  //$conf->global->SYSLOG_FILE = 'DOL_DATA_ROOT/dolibarr_mydedicatedlofile.log';
1039 
1040  $error = 0;
1041  $this->output = '';
1042  $this->error = '';
1043 
1044  dol_syslog(__METHOD__, LOG_DEBUG);
1045 
1046  $now = dol_now();
1047 
1048  $this->db->begin();
1049 
1050  // ...
1051 
1052  $this->db->commit();
1053 
1054  return $error;
1055  }
1056 }
Workstation\setEnabled
setEnabled($user, $notrigger=0)
Set draft status.
Definition: workstation.class.php:704
CommonObject\deleteCommon
deleteCommon(User $user, $notrigger=false, $forcechilddeletion=0)
Delete object in database.
Definition: commonobject.class.php:9406
CommonObject\setStatusCommon
setStatusCommon($user, $status, $notrigger=0, $triggercode='')
Set to a status.
Definition: commonobject.class.php:9683
db
$conf db
API class for accounts.
Definition: inc.php:41
CommonObject\fetchCommon
fetchCommon($id, $ref=null, $morewhere='')
Load object in memory from the database.
Definition: commonobject.class.php:9202
Workstation\fetch
fetch($id, $ref=null)
Load object in memory from the database.
Definition: workstation.class.php:372
Workstation\create
create(User $user, $notrigger=false)
Create object into database.
Definition: workstation.class.php:226
dol_sanitizeFileName
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
Definition: functions.lib.php:1226
CommonObject\copy_linked_contact
copy_linked_contact($objFrom, $source='internal')
Copy contact from one element to current.
Definition: commonobject.class.php:1217
Workstation\fetchLines
fetchLines()
Load object lines in memory from the database.
Definition: workstation.class.php:390
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:410
Workstation
Class for Workstation.
Definition: workstation.class.php:33
Workstation\getLibStatut
getLibStatut($mode=0)
Return the label of the status.
Definition: workstation.class.php:835
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:484
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:4844
dol_buildpath
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
Definition: functions.lib.php:1062
CommonObject\fetchLinesCommon
fetchLinesCommon($morewhere='')
Load object in memory from the database.
Definition: commonobject.class.php:9258
Workstation\__construct
__construct(DoliDB $db)
Constructor.
Definition: workstation.class.php:176
ref
$object ref
Definition: info.php:77
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:999
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:732
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)
Scan a directory and return a list of files/directories.
Definition: files.lib.php:60
Workstation\getNextNumRef
getNextNumRef()
Returns the reference to the following non used object depending on the active numbering module.
Definition: workstation.class.php:938
CommonObject
Parent class of all other business classes (invoices, contracts, proposals, orders,...
Definition: commonobject.class.php:44
Workstation\deleteLine
deleteLine(User $user, $idline, $notrigger=false)
Delete a line of object in database.
Definition: workstation.class.php:540
Workstation\validate
validate($user, $notrigger=0)
Validate object.
Definition: workstation.class.php:558
Workstation\initAsSpecimen
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
Definition: workstation.class.php:903
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:3880
CommonObject\createCommon
createCommon(User $user, $notrigger=false)
Create object into database.
Definition: commonobject.class.php:9035
Workstation\setDisabled
setDisabled($user, $notrigger=0)
Set draft status.
Definition: workstation.class.php:717
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:873
Workstation\doScheduledJob
doScheduledJob()
Action executed by scheduler CAN BE A CRON TASK.
Definition: workstation.class.php:1034
Workstation\getLinesArray
getLinesArray()
Create an array of lines.
Definition: workstation.class.php:913
Workstation\LibStatut
LibStatut($status, $mode=0)
Return the status.
Definition: workstation.class.php:848
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:1603
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:486
CommonObject\updateCommon
updateCommon(User $user, $notrigger=false)
Update object into database.
Definition: commonobject.class.php:9308
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:272
dol_strlen
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
Definition: functions.lib.php:3747
User
Class to manage Dolibarr users.
Definition: user.class.php:44
Workstation\setStatus
setStatus($status, $notrigger=0)
Set draft status.
Definition: workstation.class.php:683
dolGetStatus
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
Definition: functions.lib.php:10338
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:4211
dol_now
dol_now($mode='auto')
Return date for now.
Definition: functions.lib.php:2845
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice') && $user->rights->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->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:742
CommonObject\deleteLineCommon
deleteLineCommon(User $user, $idline, $notrigger=false)
Delete a line of object in database.
Definition: commonobject.class.php:9622
CommonObject\call_trigger
call_trigger($triggerName, $user)
Call trigger based on this instance.
Definition: commonobject.class.php:5791
CommonObject\getFieldList
getFieldList($alias='')
Function to concat keys of fields.
Definition: commonobject.class.php:8987