dolibarr  17.0.4
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  if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID) && isset($this->fields['rowid'])) {
186  $this->fields['rowid']['visible'] = 0;
187  }
188  if (empty($conf->multicompany->enabled) && isset($this->fields['entity'])) {
189  $this->fields['entity']['enabled'] = 0;
190  }
191 
192  // Example to show how to set values of fields definition dynamically
193  /*if ($user->rights->workstation->workstation->read) {
194  $this->fields['myfield']['visible'] = 1;
195  $this->fields['myfield']['noteditable'] = 0;
196  }*/
197 
198  // Unset fields that are disabled
199  foreach ($this->fields as $key => $val) {
200  if (isset($val['enabled']) && empty($val['enabled'])) {
201  unset($this->fields[$key]);
202  }
203  }
204 
205  // Translate some data of arrayofkeyval
206  if (is_object($langs)) {
207  foreach ($this->fields as $key => $val) {
208  if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
209  foreach ($val['arrayofkeyval'] as $key2 => $val2) {
210  $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
211  }
212  }
213  }
214  }
215  }
216 
224  public function create(User $user, $notrigger = false)
225  {
226  global $db;
227 
228  $id = $this->createCommon($user, $notrigger);
229 
230  // Usergroups
231  $groups = GETPOST('groups', 'array:int');
232  if (empty($groups)) {
233  $groups = $this->usergroups; // createFromClone
234  }
235  if (!empty($groups)) {
236  foreach ($groups as $id_group) {
237  $ws_usergroup = new WorkstationUserGroup($db);
238  $ws_usergroup->fk_workstation = $id;
239  $ws_usergroup->fk_usergroup = $id_group;
240  $ws_usergroup->createCommon($user);
241  $this->usergroups[] = $id_group;
242  }
243  }
244 
245  // Resources
246  $resources = GETPOST('resources', 'array:int');
247  if (empty($resources)) {
248  $resources = $this->resources; // createFromClone
249  }
250  if (!empty($resources)) {
251  foreach ($resources as $id_resource) {
252  $ws_resource = new WorkstationResource($db);
253  $ws_resource->fk_workstation = $id;
254  $ws_resource->fk_resource = $id_resource;
255  $ws_resource->createCommon($user);
256  $this->resources[] = $id_resource;
257  }
258  }
259 
260  return $id;
261  }
262 
270  public function createFromClone(User $user, $fromid)
271  {
272  global $langs, $extrafields;
273  $error = 0;
274 
275  dol_syslog(__METHOD__, LOG_DEBUG);
276 
277  $object = new self($this->db);
278 
279  $this->db->begin();
280 
281  // Load source object
282  $result = $object->fetch($fromid);
283  if ($result > 0 && !empty($object->table_element_line)) {
284  $object->fetchLines();
285  }
286 
287  // get lines so they will be clone
288  //foreach($this->lines as $line)
289  // $line->fetch_optionals();
290 
291  // Reset some properties
292  unset($object->id);
293  unset($object->fk_user_creat);
294  unset($object->import_key);
295 
296  // Clear fields
297  if (property_exists($object, 'ref')) {
298  $object->ref = empty($this->fields['ref']['default']) ? "Copy_Of_".$object->ref : $this->fields['ref']['default'];
299  }
300  if (property_exists($object, 'label')) {
301  $object->label = empty($this->fields['label']['default']) ? $langs->trans("CopyOf")." ".$object->label : $this->fields['label']['default'];
302  }
303  if (property_exists($object, 'status')) {
304  $object->status = self::STATUS_DISABLED;
305  }
306  if (property_exists($object, 'date_creation')) {
307  $object->date_creation = dol_now();
308  }
309  if (property_exists($object, 'date_modification')) {
310  $object->date_modification = null;
311  }
312  // ...
313  // Clear extrafields that are unique
314  if (is_array($object->array_options) && count($object->array_options) > 0) {
315  $extrafields->fetch_name_optionals_label($this->table_element);
316  foreach ($object->array_options as $key => $option) {
317  $shortkey = preg_replace('/options_/', '', $key);
318  if (!empty($extrafields->attributes[$this->table_element]['unique'][$shortkey])) {
319  //var_dump($key);
320  //var_dump($clonedObj->array_options[$key]); exit;
321  unset($object->array_options[$key]);
322  }
323  }
324  }
325 
326  // Create clone
327  $object->context['createfromclone'] = 'createfromclone';
328  $result = $object->create($user);
329  if ($result < 0) {
330  $error++;
331  $this->error = $object->error;
332  $this->errors = $object->errors;
333  }
334 
335  if (!$error) {
336  // copy internal contacts
337  if ($this->copy_linked_contact($object, 'internal') < 0) {
338  $error++;
339  }
340  }
341 
342  if (!$error) {
343  // copy external contacts if same company
344  if (property_exists($this, 'socid') && $this->socid == $object->socid) {
345  if ($this->copy_linked_contact($object, 'external') < 0) {
346  $error++;
347  }
348  }
349  }
350 
351  unset($object->context['createfromclone']);
352 
353  // End
354  if (!$error) {
355  $this->db->commit();
356  return $object;
357  } else {
358  $this->db->rollback();
359  return -1;
360  }
361  }
362 
370  public function fetch($id, $ref = null)
371  {
372  $result = $this->fetchCommon($id, $ref);
373 
374  $this->usergroups = WorkstationUserGroup::getAllGroupsOfWorkstation($this->id);
375  $this->resources = WorkstationResource::getAllResourcesOfWorkstation($this->id);
376 
377  if ($result > 0 && !empty($this->table_element_line)) {
378  $this->fetchLines();
379  }
380  return $result;
381  }
382 
388  public function fetchLines()
389  {
390  $this->lines = array();
391 
392  $result = $this->fetchLinesCommon();
393  return $result;
394  }
395 
396 
408  public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND')
409  {
410  global $conf;
411 
412  dol_syslog(__METHOD__, LOG_DEBUG);
413 
414  $records = array();
415 
416  $sql = 'SELECT ';
417  $sql .= $this->getFieldList();
418  $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
419  if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
420  $sql .= ' WHERE t.entity IN ('.getEntity($this->element).')';
421  } else {
422  $sql .= ' WHERE 1 = 1';
423  }
424  // Manage filter
425  $sqlwhere = array();
426  if (count($filter) > 0) {
427  foreach ($filter as $key => $value) {
428  if ($key == 't.rowid') {
429  $sqlwhere[] = $key." = ".((int) $value);
430  } elseif (in_array($this->fields[$key]['type'], array('date', 'datetime', 'timestamp'))) {
431  $sqlwhere[] = $key." = '".$this->db->idate($value)."'";
432  } elseif ($key == 'customsql') {
433  $sqlwhere[] = $value;
434  } elseif (strpos($value, '%') === false) {
435  $sqlwhere[] = $key." IN (".$this->db->sanitize($this->db->escape($value)).")";
436  } else {
437  $sqlwhere[] = $key." LIKE '%".$this->db->escape($value)."%'";
438  }
439  }
440  }
441  if (count($sqlwhere) > 0) {
442  $sql .= ' AND ('.implode(' '.$this->db->escape($filtermode).' ', $sqlwhere).')';
443  }
444 
445  if (!empty($sortfield)) {
446  $sql .= $this->db->order($sortfield, $sortorder);
447  }
448  if (!empty($limit)) {
449  $sql .= $this->db->plimit($limit, $offset);
450  }
451 
452  $resql = $this->db->query($sql);
453  if ($resql) {
454  $num = $this->db->num_rows($resql);
455  $i = 0;
456  while ($i < ($limit ? min($limit, $num) : $num)) {
457  $obj = $this->db->fetch_object($resql);
458 
459  $record = new self($this->db);
460  $record->setVarsFromFetchObj($obj);
461 
462  $records[$record->id] = $record;
463 
464  $i++;
465  }
466  $this->db->free($resql);
467 
468  return $records;
469  } else {
470  $this->errors[] = 'Error '.$this->db->lasterror();
471  dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
472 
473  return -1;
474  }
475  }
476 
484  public function update(User $user, $notrigger = false)
485  {
486 
487  // Usergroups
488  $groups = GETPOST('groups', 'array:int');
490  $this->usergroups=array();
491 
492  foreach ($groups as $id_group) {
493  $ws_usergroup = new WorkstationUserGroup($this->db);
494  $ws_usergroup->fk_workstation = $this->id;
495  $ws_usergroup->fk_usergroup = $id_group;
496  $ws_usergroup->createCommon($user);
497  $this->usergroups[] = $id_group;
498  }
499 
500  // Resources
501  $resources = GETPOST('resources', 'array:int');
503  $this->resources=array();
504  if (!empty($resources)) {
505  foreach ($resources as $id_resource) {
506  $ws_resource = new WorkstationResource($this->db);
507  $ws_resource->fk_workstation = $this->id;
508  $ws_resource->fk_resource = $id_resource;
509  $ws_resource->createCommon($user);
510  $this->resources[] = $id_resource;
511  }
512  }
513 
514  return $this->updateCommon($user, $notrigger);
515  }
516 
524  public function delete(User $user, $notrigger = false)
525  {
526  return $this->deleteCommon($user, $notrigger);
527  //return $this->deleteCommon($user, $notrigger, 1);
528  }
529 
538  public function deleteLine(User $user, $idline, $notrigger = false)
539  {
540  if ($this->status < 0) {
541  $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
542  return -2;
543  }
544 
545  return $this->deleteLineCommon($user, $idline, $notrigger);
546  }
547 
548 
556  public function validate($user, $notrigger = 0)
557  {
558  global $conf, $langs;
559 
560  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
561 
562  $error = 0;
563 
564  // Protection
565  if ($this->status == self::STATUS_VALIDATED) {
566  dol_syslog(get_class($this)."::validate action abandonned: already validated", LOG_WARNING);
567  return 0;
568  }
569 
570  /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->workstation->workstation->write))
571  || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->workstation->workstation->workstation_advance->validate))))
572  {
573  $this->error='NotEnoughPermissions';
574  dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR);
575  return -1;
576  }*/
577 
578  $now = dol_now();
579 
580  $this->db->begin();
581 
582  // Define new ref
583  if (!$error && (preg_match('/^[\‍(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life
584  $num = $this->getNextNumRef();
585  } else {
586  $num = $this->ref;
587  }
588  $this->newref = $num;
589 
590  if (!empty($num)) {
591  // Validate
592  $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
593  $sql .= " SET ref = '".$this->db->escape($num)."',";
594  $sql .= " status = ".self::STATUS_VALIDATED;
595  if (!empty($this->fields['date_validation'])) {
596  $sql .= ", date_validation = '".$this->db->idate($now)."'";
597  }
598  if (!empty($this->fields['fk_user_valid'])) {
599  $sql .= ", fk_user_valid = ".$user->id;
600  }
601  $sql .= " WHERE rowid = ".((int) $this->id);
602 
603  dol_syslog(get_class($this)."::validate()", LOG_DEBUG);
604  $resql = $this->db->query($sql);
605  if (!$resql) {
606  dol_print_error($this->db);
607  $this->error = $this->db->lasterror();
608  $error++;
609  }
610 
611  if (!$error && !$notrigger) {
612  // Call trigger
613  $result = $this->call_trigger('WORKSTATION_VALIDATE', $user);
614  if ($result < 0) {
615  $error++;
616  }
617  // End call triggers
618  }
619  }
620 
621  if (!$error) {
622  $this->oldref = $this->ref;
623 
624  // Rename directory if dir was a temporary ref
625  if (preg_match('/^[\‍(]?PROV/i', $this->ref)) {
626  // Now we rename also files into index
627  $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)."'";
628  $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'workstation/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
629  $resql = $this->db->query($sql);
630  if (!$resql) {
631  $error++; $this->error = $this->db->lasterror();
632  }
633 
634  // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
635  $oldref = dol_sanitizeFileName($this->ref);
636  $newref = dol_sanitizeFileName($num);
637  $dirsource = $conf->workstation->dir_output.'/workstation/'.$oldref;
638  $dirdest = $conf->workstation->dir_output.'/workstation/'.$newref;
639  if (!$error && file_exists($dirsource)) {
640  dol_syslog(get_class($this)."::validate() rename dir ".$dirsource." into ".$dirdest);
641 
642  if (@rename($dirsource, $dirdest)) {
643  dol_syslog("Rename ok");
644  // Rename docs starting with $oldref with $newref
645  $listoffiles = dol_dir_list($conf->workstation->dir_output.'/workstation/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
646  foreach ($listoffiles as $fileentry) {
647  $dirsource = $fileentry['name'];
648  $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
649  $dirsource = $fileentry['path'].'/'.$dirsource;
650  $dirdest = $fileentry['path'].'/'.$dirdest;
651  @rename($dirsource, $dirdest);
652  }
653  }
654  }
655  }
656  }
657 
658  // Set new ref and current status
659  if (!$error) {
660  $this->ref = $num;
661  $this->status = self::STATUS_VALIDATED;
662  }
663 
664  if (!$error) {
665  $this->db->commit();
666  return 1;
667  } else {
668  $this->db->rollback();
669  return -1;
670  }
671  }
672 
673 
681  public function setStatus($status, $notrigger = 0)
682  {
683  global $user;
684 
685  $this->status = $status;
686 
687  if (empty($status)) {
688  return $this->setDisabled($user, $notrigger);
689  } else {
690  return $this->setEnabled($user, $notrigger);
691  }
692  }
693 
694 
702  public function setEnabled($user, $notrigger = 0)
703  {
704  return $this->setStatusCommon($user, self::STATUS_ENABLED, $notrigger, 'WORKSTATION_ENABLED');
705  }
706 
707 
715  public function setDisabled($user, $notrigger = 0)
716  {
717  return $this->setStatusCommon($user, self::STATUS_DISABLED, $notrigger, 'WORKSTATION_DISABLED');
718  }
719 
730  public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
731  {
732  global $conf, $langs, $hookmanager;
733 
734  if (!empty($conf->dol_no_mouse_hover)) {
735  $notooltip = 1; // Force disable tooltips
736  }
737 
738  $result = '';
739 
740  $label = img_picto('', $this->picto).' <u>'.$langs->trans("Workstation").'</u>';
741  $label .= '<br>';
742  $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
743  if (isset($this->status)) {
744  $label .= '<br><b>'.$langs->trans("Status").":</b> ".$this->getLibStatut(5);
745  }
746 
747  $url = dol_buildpath('/workstation/workstation_card.php', 1).'?id='.$this->id;
748 
749  if ($option != 'nolink') {
750  // Add param to save lastsearch_values or not
751  $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
752  if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
753  $add_save_lastsearch_values = 1;
754  }
755  if ($add_save_lastsearch_values) {
756  $url .= '&save_lastsearch_values=1';
757  }
758  }
759 
760  $linkclose = '';
761  if (empty($notooltip)) {
762  if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
763  $label = $langs->trans("ShowWorkstation");
764  $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
765  }
766  $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
767  $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
768  } else {
769  $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
770  }
771 
772  $linkstart = '<a href="'.$url.'"';
773  $linkstart .= $linkclose.'>';
774  $linkend = '</a>';
775 
776  $result .= $linkstart;
777 
778  if (empty($this->showphoto_on_popup)) {
779  if ($withpicto) {
780  $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);
781  }
782  } else {
783  if ($withpicto) {
784  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
785 
786  list($class, $module) = explode('@', $this->picto);
787  $upload_dir = $conf->$module->multidir_output[$conf->entity]."/$class/".dol_sanitizeFileName($this->ref);
788  $filearray = dol_dir_list($upload_dir, "files");
789  $filename = $filearray[0]['name'];
790  if (!empty($filename)) {
791  $pospoint = strpos($filearray[0]['name'], '.');
792 
793  $pathtophoto = $class.'/'.$this->ref.'/thumbs/'.substr($filename, 0, $pospoint).'_mini'.substr($filename, $pospoint);
794  if (empty($conf->global->{strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS'})) {
795  $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>';
796  } else {
797  $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>';
798  }
799 
800  $result .= '</div>';
801  } else {
802  $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);
803  }
804  }
805  }
806 
807  if ($withpicto != 2) {
808  $result .= $this->ref;
809  }
810 
811  $result .= $linkend;
812  //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
813 
814  global $action, $hookmanager;
815  $hookmanager->initHooks(array('workstationdao'));
816  $parameters = array('id'=>$this->id, 'getnomurl' => &$result);
817  $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
818  if ($reshook > 0) {
819  $result = $hookmanager->resPrint;
820  } else {
821  $result .= $hookmanager->resPrint;
822  }
823 
824  return $result;
825  }
826 
833  public function getLibStatut($mode = 0)
834  {
835  return $this->LibStatut($this->status, $mode);
836  }
837 
838  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
846  public function LibStatut($status, $mode = 0)
847  {
848  // phpcs:enable
849  if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
850  global $langs;
851  //$langs->load("workstation");
852  $this->labelStatus[self::STATUS_DISABLED] = $langs->transnoentitiesnoconv('Disabled');
853  $this->labelStatus[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv('Enabled');
854  $this->labelStatusShort[self::STATUS_DISABLED] = $langs->transnoentitiesnoconv('Disabled');
855  $this->labelStatusShort[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv('Enabled');
856  }
857 
858  $statusType = 'status'.$status;
859  //if ($status == self::STATUS_DISABLED) $statusType = 'status6';
860  if ($status == self::STATUS_ENABLED) $statusType = 'status4';
861 
862  return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
863  }
864 
871  public function info($id)
872  {
873  $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
874  $sql .= ' fk_user_creat, fk_user_modif';
875  $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
876  $sql .= ' WHERE t.rowid = '.((int) $id);
877  $result = $this->db->query($sql);
878  if ($result) {
879  if ($this->db->num_rows($result)) {
880  $obj = $this->db->fetch_object($result);
881  $this->id = $obj->rowid;
882 
883  $this->user_creation_id = $obj->fk_user_creat;
884  $this->user_modification_id = $obj->fk_user_modif;
885  $this->date_creation = $this->db->jdate($obj->datec);
886  $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
887  }
888 
889  $this->db->free($result);
890  } else {
891  dol_print_error($this->db);
892  }
893  }
894 
901  public function initAsSpecimen()
902  {
903  $this->initAsSpecimenCommon();
904  }
905 
911  public function getLinesArray()
912  {
913  $this->lines = array();
914 
915  /*
916  $objectline = new WorkstationLine($this->db);
917  $result = $objectline->fetchAll('ASC', 'position', 0, 0, array('customsql'=>'fk_workstation = '.((int) $this->id)));
918 
919  if (is_numeric($result)) {
920  $this->error = $objectline->error;
921  $this->errors = $objectline->errors;
922  return $result;
923  }
924 
925  $this->lines = $result;
926  */
927 
928  return $this->lines;
929  }
930 
936  public function getNextNumRef()
937  {
938  global $langs, $conf;
939  $langs->load("workstation");
940 
941  if (empty($conf->global->WORKSTATION_WORKSTATION_ADDON)) {
942  $conf->global->WORKSTATION_WORKSTATION_ADDON = 'mod_workstation_standard';
943  }
944 
945  if (!empty($conf->global->WORKSTATION_WORKSTATION_ADDON)) {
946  $mybool = false;
947 
948  $file = $conf->global->WORKSTATION_WORKSTATION_ADDON.".php";
949  $classname = $conf->global->WORKSTATION_WORKSTATION_ADDON;
950 
951  // Include file with class
952  $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
953  foreach ($dirmodels as $reldir) {
954  $dir = dol_buildpath($reldir."core/modules/workstation/");
955 
956  // Load file with numbering class (if found)
957  $mybool |= @include_once $dir.$file;
958  }
959 
960  if ($mybool === false) {
961  dol_print_error('', "Failed to include file ".$file);
962  return '';
963  }
964 
965  if (class_exists($classname)) {
966  $obj = new $classname();
967  $numref = $obj->getNextValue($this);
968 
969  if ($numref != '' && $numref != '-1') {
970  return $numref;
971  } else {
972  $this->error = $obj->error;
973  //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
974  return "";
975  }
976  } else {
977  print $langs->trans("Error")." ".$langs->trans("ClassNotFound").' '.$classname;
978  return "";
979  }
980  } else {
981  print $langs->trans("ErrorNumberingModuleNotSetup", $this->element);
982  return "";
983  }
984  }
985 
997  public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
998  {
999  global $conf, $langs;
1000 
1001  $result = 0;
1002  $includedocgeneration = 0;
1003 
1004  $langs->load("workstation");
1005 
1006  if (!dol_strlen($modele)) {
1007  $modele = 'standard_workstation';
1008 
1009  if ($this->model_pdf) {
1010  $modele = $this->model_pdf;
1011  } elseif (!empty($conf->global->WORKSTATION_ADDON_PDF)) {
1012  $modele = $conf->global->WORKSTATION_ADDON_PDF;
1013  }
1014  }
1015 
1016  $modelpath = "core/modules/workstation/doc/";
1017 
1018  if ($includedocgeneration) {
1019  $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1020  }
1021 
1022  return $result;
1023  }
1024 
1032  public function doScheduledJob()
1033  {
1034  global $conf, $langs;
1035 
1036  //$conf->global->SYSLOG_FILE = 'DOL_DATA_ROOT/dolibarr_mydedicatedlofile.log';
1037 
1038  $error = 0;
1039  $this->output = '';
1040  $this->error = '';
1041 
1042  dol_syslog(__METHOD__, LOG_DEBUG);
1043 
1044  $now = dol_now();
1045 
1046  $this->db->begin();
1047 
1048  // ...
1049 
1050  $this->db->commit();
1051 
1052  return $error;
1053  }
1054 }
$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.
getFieldList($alias='')
Function to concat keys of fields.
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.
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.
call_trigger($triggerName, $user)
Call trigger based on this instance.
Class to manage Dolibarr database access.
Class to manage Dolibarr users.
Definition: user.class.php:47
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.
doScheduledJob()
Action executed by scheduler CAN BE A CRON TASK.
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.
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return a link to the object card (with optionaly the picto)
validate($user, $notrigger=0)
Validate object.
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.
getLinesArray()
Create an array of lines.
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.
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)) $resql
Social contributions to pay.
Definition: index.php:745
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:61
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.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
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.
$conf db
API class for accounts.
Definition: inc.php:41