dolibarr  x.y.z
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 
140  public function __construct(DoliDB $db)
141  {
142  global $conf, $langs;
143 
144  require_once DOL_DOCUMENT_ROOT.'/workstation/class/workstationusergroup.class.php';
145  require_once DOL_DOCUMENT_ROOT.'/workstation/class/workstationresource.class.php';
146 
147  $this->db = $db;
148 
149  $this->fields['ref']['default'] = $this->getNextNumRef();
150 
151  if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID) && isset($this->fields['rowid'])) {
152  $this->fields['rowid']['visible'] = 0;
153  }
154  if (empty($conf->multicompany->enabled) && isset($this->fields['entity'])) {
155  $this->fields['entity']['enabled'] = 0;
156  }
157 
158  // Example to show how to set values of fields definition dynamically
159  /*if ($user->rights->workstation->workstation->read) {
160  $this->fields['myfield']['visible'] = 1;
161  $this->fields['myfield']['noteditable'] = 0;
162  }*/
163 
164  // Unset fields that are disabled
165  foreach ($this->fields as $key => $val) {
166  if (isset($val['enabled']) && empty($val['enabled'])) {
167  unset($this->fields[$key]);
168  }
169  }
170 
171  // Translate some data of arrayofkeyval
172  if (is_object($langs)) {
173  foreach ($this->fields as $key => $val) {
174  if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
175  foreach ($val['arrayofkeyval'] as $key2 => $val2) {
176  $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
177  }
178  }
179  }
180  }
181  }
182 
190  public function create(User $user, $notrigger = false)
191  {
192  global $db;
193 
194  $id = $this->createCommon($user, $notrigger);
195 
196  // Usergroups
197  $groups = GETPOST('groups', 'array:int');
198  if (empty($groups)) {
199  $groups = $this->usergroups; // createFromClone
200  }
201  if (!empty($groups)) {
202  foreach ($groups as $id_group) {
203  $ws_usergroup = new WorkstationUserGroup($db);
204  $ws_usergroup->fk_workstation = $id;
205  $ws_usergroup->fk_usergroup = $id_group;
206  $ws_usergroup->createCommon($user);
207  $this->usergroups[] = $id_group;
208  }
209  }
210 
211  // Resources
212  $resources = GETPOST('resources', 'array:int');
213  if (empty($resources)) {
214  $resources = $this->resources; // createFromClone
215  }
216  if (!empty($resources)) {
217  foreach ($resources as $id_resource) {
218  $ws_resource = new WorkstationResource($db);
219  $ws_resource->fk_workstation = $id;
220  $ws_resource->fk_resource = $id_resource;
221  $ws_resource->createCommon($user);
222  $this->resources[] = $id_resource;
223  }
224  }
225 
226  return $id;
227  }
228 
236  public function createFromClone(User $user, $fromid)
237  {
238  global $langs, $extrafields;
239  $error = 0;
240 
241  dol_syslog(__METHOD__, LOG_DEBUG);
242 
243  $object = new self($this->db);
244 
245  $this->db->begin();
246 
247  // Load source object
248  $result = $object->fetch($fromid);
249  if ($result > 0 && !empty($object->table_element_line)) {
250  $object->fetchLines();
251  }
252 
253  // get lines so they will be clone
254  //foreach($this->lines as $line)
255  // $line->fetch_optionals();
256 
257  // Reset some properties
258  unset($object->id);
259  unset($object->fk_user_creat);
260  unset($object->import_key);
261 
262  // Clear fields
263  if (property_exists($object, 'ref')) {
264  $object->ref = empty($this->fields['ref']['default']) ? "Copy_Of_".$object->ref : $this->fields['ref']['default'];
265  }
266  if (property_exists($object, 'label')) {
267  $object->label = empty($this->fields['label']['default']) ? $langs->trans("CopyOf")." ".$object->label : $this->fields['label']['default'];
268  }
269  if (property_exists($object, 'status')) {
270  $object->status = self::STATUS_DISABLED;
271  }
272  if (property_exists($object, 'date_creation')) {
273  $object->date_creation = dol_now();
274  }
275  if (property_exists($object, 'date_modification')) {
276  $object->date_modification = null;
277  }
278  // ...
279  // Clear extrafields that are unique
280  if (is_array($object->array_options) && count($object->array_options) > 0) {
281  $extrafields->fetch_name_optionals_label($this->table_element);
282  foreach ($object->array_options as $key => $option) {
283  $shortkey = preg_replace('/options_/', '', $key);
284  if (!empty($extrafields->attributes[$this->table_element]['unique'][$shortkey])) {
285  //var_dump($key);
286  //var_dump($clonedObj->array_options[$key]); exit;
287  unset($object->array_options[$key]);
288  }
289  }
290  }
291 
292  // Create clone
293  $object->context['createfromclone'] = 'createfromclone';
294  $result = $object->create($user);
295  if ($result < 0) {
296  $error++;
297  $this->error = $object->error;
298  $this->errors = $object->errors;
299  }
300 
301  if (!$error) {
302  // copy internal contacts
303  if ($this->copy_linked_contact($object, 'internal') < 0) {
304  $error++;
305  }
306  }
307 
308  if (!$error) {
309  // copy external contacts if same company
310  if (property_exists($this, 'socid') && $this->socid == $object->socid) {
311  if ($this->copy_linked_contact($object, 'external') < 0) {
312  $error++;
313  }
314  }
315  }
316 
317  unset($object->context['createfromclone']);
318 
319  // End
320  if (!$error) {
321  $this->db->commit();
322  return $object;
323  } else {
324  $this->db->rollback();
325  return -1;
326  }
327  }
328 
336  public function fetch($id, $ref = null)
337  {
338  $result = $this->fetchCommon($id, $ref);
339 
340  $this->usergroups = WorkstationUserGroup::getAllGroupsOfWorkstation($this->id);
341  $this->resources = WorkstationResource::getAllResourcesOfWorkstation($this->id);
342 
343  if ($result > 0 && !empty($this->table_element_line)) {
344  $this->fetchLines();
345  }
346  return $result;
347  }
348 
354  public function fetchLines()
355  {
356  $this->lines = array();
357 
358  $result = $this->fetchLinesCommon();
359  return $result;
360  }
361 
362 
374  public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND')
375  {
376  global $conf;
377 
378  dol_syslog(__METHOD__, LOG_DEBUG);
379 
380  $records = array();
381 
382  $sql = 'SELECT ';
383  $sql .= $this->getFieldList();
384  $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
385  if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
386  $sql .= ' WHERE t.entity IN ('.getEntity($this->table_element).')';
387  } else {
388  $sql .= ' WHERE 1 = 1';
389  }
390  // Manage filter
391  $sqlwhere = array();
392  if (count($filter) > 0) {
393  foreach ($filter as $key => $value) {
394  if ($key == 't.rowid') {
395  $sqlwhere[] = $key." = ".((int) $value);
396  } elseif (in_array($this->fields[$key]['type'], array('date', 'datetime', 'timestamp'))) {
397  $sqlwhere[] = $key." = '".$this->db->idate($value)."'";
398  } elseif ($key == 'customsql') {
399  $sqlwhere[] = $value;
400  } elseif (strpos($value, '%') === false) {
401  $sqlwhere[] = $key." IN (".$this->db->sanitize($this->db->escape($value)).")";
402  } else {
403  $sqlwhere[] = $key." LIKE '%".$this->db->escape($value)."%'";
404  }
405  }
406  }
407  if (count($sqlwhere) > 0) {
408  $sql .= ' AND ('.implode(' '.$this->db->escape($filtermode).' ', $sqlwhere).')';
409  }
410 
411  if (!empty($sortfield)) {
412  $sql .= $this->db->order($sortfield, $sortorder);
413  }
414  if (!empty($limit)) {
415  $sql .= $this->db->plimit($limit, $offset);
416  }
417 
418  $resql = $this->db->query($sql);
419  if ($resql) {
420  $num = $this->db->num_rows($resql);
421  $i = 0;
422  while ($i < ($limit ? min($limit, $num) : $num)) {
423  $obj = $this->db->fetch_object($resql);
424 
425  $record = new self($this->db);
426  $record->setVarsFromFetchObj($obj);
427 
428  $records[$record->id] = $record;
429 
430  $i++;
431  }
432  $this->db->free($resql);
433 
434  return $records;
435  } else {
436  $this->errors[] = 'Error '.$this->db->lasterror();
437  dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
438 
439  return -1;
440  }
441  }
442 
450  public function update(User $user, $notrigger = false)
451  {
452 
453  // Usergroups
454  $groups = GETPOST('groups', 'array:int');
456  $this->usergroups=array();
457 
458  foreach ($groups as $id_group) {
459  $ws_usergroup = new WorkstationUserGroup($this->db);
460  $ws_usergroup->fk_workstation = $this->id;
461  $ws_usergroup->fk_usergroup = $id_group;
462  $ws_usergroup->createCommon($user);
463  $this->usergroups[] = $id_group;
464  }
465 
466  // Resources
467  $resources = GETPOST('resources', 'array:int');
469  $this->resources=array();
470  if (!empty($resources)) {
471  foreach ($resources as $id_resource) {
472  $ws_resource = new WorkstationResource($this->db);
473  $ws_resource->fk_workstation = $this->id;
474  $ws_resource->fk_resource = $id_resource;
475  $ws_resource->createCommon($user);
476  $this->resources[] = $id_resource;
477  }
478  }
479 
480  return $this->updateCommon($user, $notrigger);
481  }
482 
490  public function delete(User $user, $notrigger = false)
491  {
492  return $this->deleteCommon($user, $notrigger);
493  //return $this->deleteCommon($user, $notrigger, 1);
494  }
495 
504  public function deleteLine(User $user, $idline, $notrigger = false)
505  {
506  if ($this->status < 0) {
507  $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
508  return -2;
509  }
510 
511  return $this->deleteLineCommon($user, $idline, $notrigger);
512  }
513 
514 
522  public function validate($user, $notrigger = 0)
523  {
524  global $conf, $langs;
525 
526  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
527 
528  $error = 0;
529 
530  // Protection
531  if ($this->status == self::STATUS_VALIDATED) {
532  dol_syslog(get_class($this)."::validate action abandonned: already validated", LOG_WARNING);
533  return 0;
534  }
535 
536  /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->workstation->workstation->write))
537  || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->workstation->workstation->workstation_advance->validate))))
538  {
539  $this->error='NotEnoughPermissions';
540  dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR);
541  return -1;
542  }*/
543 
544  $now = dol_now();
545 
546  $this->db->begin();
547 
548  // Define new ref
549  if (!$error && (preg_match('/^[\‍(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life
550  $num = $this->getNextNumRef();
551  } else {
552  $num = $this->ref;
553  }
554  $this->newref = $num;
555 
556  if (!empty($num)) {
557  // Validate
558  $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
559  $sql .= " SET ref = '".$this->db->escape($num)."',";
560  $sql .= " status = ".self::STATUS_VALIDATED;
561  if (!empty($this->fields['date_validation'])) {
562  $sql .= ", date_validation = '".$this->db->idate($now)."'";
563  }
564  if (!empty($this->fields['fk_user_valid'])) {
565  $sql .= ", fk_user_valid = ".$user->id;
566  }
567  $sql .= " WHERE rowid = ".((int) $this->id);
568 
569  dol_syslog(get_class($this)."::validate()", LOG_DEBUG);
570  $resql = $this->db->query($sql);
571  if (!$resql) {
572  dol_print_error($this->db);
573  $this->error = $this->db->lasterror();
574  $error++;
575  }
576 
577  if (!$error && !$notrigger) {
578  // Call trigger
579  $result = $this->call_trigger('WORKSTATION_VALIDATE', $user);
580  if ($result < 0) {
581  $error++;
582  }
583  // End call triggers
584  }
585  }
586 
587  if (!$error) {
588  $this->oldref = $this->ref;
589 
590  // Rename directory if dir was a temporary ref
591  if (preg_match('/^[\‍(]?PROV/i', $this->ref)) {
592  // Now we rename also files into index
593  $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)."'";
594  $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'workstation/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
595  $resql = $this->db->query($sql);
596  if (!$resql) {
597  $error++; $this->error = $this->db->lasterror();
598  }
599 
600  // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
601  $oldref = dol_sanitizeFileName($this->ref);
602  $newref = dol_sanitizeFileName($num);
603  $dirsource = $conf->workstation->dir_output.'/workstation/'.$oldref;
604  $dirdest = $conf->workstation->dir_output.'/workstation/'.$newref;
605  if (!$error && file_exists($dirsource)) {
606  dol_syslog(get_class($this)."::validate() rename dir ".$dirsource." into ".$dirdest);
607 
608  if (@rename($dirsource, $dirdest)) {
609  dol_syslog("Rename ok");
610  // Rename docs starting with $oldref with $newref
611  $listoffiles = dol_dir_list($conf->workstation->dir_output.'/workstation/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
612  foreach ($listoffiles as $fileentry) {
613  $dirsource = $fileentry['name'];
614  $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
615  $dirsource = $fileentry['path'].'/'.$dirsource;
616  $dirdest = $fileentry['path'].'/'.$dirdest;
617  @rename($dirsource, $dirdest);
618  }
619  }
620  }
621  }
622  }
623 
624  // Set new ref and current status
625  if (!$error) {
626  $this->ref = $num;
627  $this->status = self::STATUS_VALIDATED;
628  }
629 
630  if (!$error) {
631  $this->db->commit();
632  return 1;
633  } else {
634  $this->db->rollback();
635  return -1;
636  }
637  }
638 
639 
647  public function setStatus($status, $notrigger = 0)
648  {
649  global $user;
650 
651  $this->status = $status;
652 
653  if (empty($status)) {
654  return $this->setDisabled($user, $notrigger);
655  } else {
656  return $this->setEnabled($user, $notrigger);
657  }
658  }
659 
660 
668  public function setEnabled($user, $notrigger = 0)
669  {
670  return $this->setStatusCommon($user, self::STATUS_ENABLED, $notrigger, 'WORKSTATION_ENABLED');
671  }
672 
673 
681  public function setDisabled($user, $notrigger = 0)
682  {
683  return $this->setStatusCommon($user, self::STATUS_DISABLED, $notrigger, 'WORKSTATION_DISABLED');
684  }
685 
696  public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
697  {
698  global $conf, $langs, $hookmanager;
699 
700  if (!empty($conf->dol_no_mouse_hover)) {
701  $notooltip = 1; // Force disable tooltips
702  }
703 
704  $result = '';
705 
706  $label = img_picto('', $this->picto).' <u>'.$langs->trans("Workstation").'</u>';
707  $label .= '<br>';
708  $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
709  if (isset($this->status)) {
710  $label .= '<br><b>'.$langs->trans("Status").":</b> ".$this->getLibStatut(5);
711  }
712 
713  $url = dol_buildpath('/workstation/workstation_card.php', 1).'?id='.$this->id;
714 
715  if ($option != 'nolink') {
716  // Add param to save lastsearch_values or not
717  $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
718  if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
719  $add_save_lastsearch_values = 1;
720  }
721  if ($add_save_lastsearch_values) {
722  $url .= '&save_lastsearch_values=1';
723  }
724  }
725 
726  $linkclose = '';
727  if (empty($notooltip)) {
728  if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
729  $label = $langs->trans("ShowWorkstation");
730  $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
731  }
732  $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
733  $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
734  } else {
735  $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
736  }
737 
738  $linkstart = '<a href="'.$url.'"';
739  $linkstart .= $linkclose.'>';
740  $linkend = '</a>';
741 
742  $result .= $linkstart;
743 
744  if (empty($this->showphoto_on_popup)) {
745  if ($withpicto) {
746  $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);
747  }
748  } else {
749  if ($withpicto) {
750  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
751 
752  list($class, $module) = explode('@', $this->picto);
753  $upload_dir = $conf->$module->multidir_output[$conf->entity]."/$class/".dol_sanitizeFileName($this->ref);
754  $filearray = dol_dir_list($upload_dir, "files");
755  $filename = $filearray[0]['name'];
756  if (!empty($filename)) {
757  $pospoint = strpos($filearray[0]['name'], '.');
758 
759  $pathtophoto = $class.'/'.$this->ref.'/thumbs/'.substr($filename, 0, $pospoint).'_mini'.substr($filename, $pospoint);
760  if (empty($conf->global->{strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS'})) {
761  $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>';
762  } else {
763  $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>';
764  }
765 
766  $result .= '</div>';
767  } else {
768  $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);
769  }
770  }
771  }
772 
773  if ($withpicto != 2) {
774  $result .= $this->ref;
775  }
776 
777  $result .= $linkend;
778  //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
779 
780  global $action, $hookmanager;
781  $hookmanager->initHooks(array('workstationdao'));
782  $parameters = array('id'=>$this->id, 'getnomurl' => &$result);
783  $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
784  if ($reshook > 0) {
785  $result = $hookmanager->resPrint;
786  } else {
787  $result .= $hookmanager->resPrint;
788  }
789 
790  return $result;
791  }
792 
799  public function getLibStatut($mode = 0)
800  {
801  return $this->LibStatut($this->status, $mode);
802  }
803 
804  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
812  public function LibStatut($status, $mode = 0)
813  {
814  // phpcs:enable
815  if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
816  global $langs;
817  //$langs->load("workstation");
818  $this->labelStatus[self::STATUS_DISABLED] = $langs->transnoentitiesnoconv('Disabled');
819  $this->labelStatus[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv('Enabled');
820  $this->labelStatusShort[self::STATUS_DISABLED] = $langs->transnoentitiesnoconv('Disabled');
821  $this->labelStatusShort[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv('Enabled');
822  }
823 
824  $statusType = 'status'.$status;
825  //if ($status == self::STATUS_DISABLED) $statusType = 'status6';
826  if ($status == self::STATUS_ENABLED) $statusType = 'status4';
827 
828  return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
829  }
830 
837  public function info($id)
838  {
839  $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
840  $sql .= ' fk_user_creat, fk_user_modif';
841  $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
842  $sql .= ' WHERE t.rowid = '.((int) $id);
843  $result = $this->db->query($sql);
844  if ($result) {
845  if ($this->db->num_rows($result)) {
846  $obj = $this->db->fetch_object($result);
847  $this->id = $obj->rowid;
848 
849  $this->user_creation_id = $obj->fk_user_creat;
850  $this->user_modification_id = $obj->fk_user_modif;
851  $this->date_creation = $this->db->jdate($obj->datec);
852  $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
853  }
854 
855  $this->db->free($result);
856  } else {
857  dol_print_error($this->db);
858  }
859  }
860 
867  public function initAsSpecimen()
868  {
869  $this->initAsSpecimenCommon();
870  }
871 
877  public function getLinesArray()
878  {
879  $this->lines = array();
880 
881  /*
882  $objectline = new WorkstationLine($this->db);
883  $result = $objectline->fetchAll('ASC', 'position', 0, 0, array('customsql'=>'fk_workstation = '.((int) $this->id)));
884 
885  if (is_numeric($result)) {
886  $this->error = $objectline->error;
887  $this->errors = $objectline->errors;
888  return $result;
889  }
890 
891  $this->lines = $result;
892  */
893 
894  return $this->lines;
895  }
896 
902  public function getNextNumRef()
903  {
904  global $langs, $conf;
905  $langs->load("workstation");
906 
907  if (empty($conf->global->WORKSTATION_WORKSTATION_ADDON)) {
908  $conf->global->WORKSTATION_WORKSTATION_ADDON = 'mod_workstation_standard';
909  }
910 
911  if (!empty($conf->global->WORKSTATION_WORKSTATION_ADDON)) {
912  $mybool = false;
913 
914  $file = $conf->global->WORKSTATION_WORKSTATION_ADDON.".php";
915  $classname = $conf->global->WORKSTATION_WORKSTATION_ADDON;
916 
917  // Include file with class
918  $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
919  foreach ($dirmodels as $reldir) {
920  $dir = dol_buildpath($reldir."core/modules/workstation/");
921 
922  // Load file with numbering class (if found)
923  $mybool |= @include_once $dir.$file;
924  }
925 
926  if ($mybool === false) {
927  dol_print_error('', "Failed to include file ".$file);
928  return '';
929  }
930 
931  if (class_exists($classname)) {
932  $obj = new $classname();
933  $numref = $obj->getNextValue($this);
934 
935  if ($numref != '' && $numref != '-1') {
936  return $numref;
937  } else {
938  $this->error = $obj->error;
939  //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
940  return "";
941  }
942  } else {
943  print $langs->trans("Error")." ".$langs->trans("ClassNotFound").' '.$classname;
944  return "";
945  }
946  } else {
947  print $langs->trans("ErrorNumberingModuleNotSetup", $this->element);
948  return "";
949  }
950  }
951 
963  public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
964  {
965  global $conf, $langs;
966 
967  $result = 0;
968  $includedocgeneration = 0;
969 
970  $langs->load("workstation");
971 
972  if (!dol_strlen($modele)) {
973  $modele = 'standard_workstation';
974 
975  if ($this->model_pdf) {
976  $modele = $this->model_pdf;
977  } elseif (!empty($conf->global->WORKSTATION_ADDON_PDF)) {
978  $modele = $conf->global->WORKSTATION_ADDON_PDF;
979  }
980  }
981 
982  $modelpath = "core/modules/workstation/doc/";
983 
984  if ($includedocgeneration) {
985  $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
986  }
987 
988  return $result;
989  }
990 
998  public function doScheduledJob()
999  {
1000  global $conf, $langs;
1001 
1002  //$conf->global->SYSLOG_FILE = 'DOL_DATA_ROOT/dolibarr_mydedicatedlofile.log';
1003 
1004  $error = 0;
1005  $this->output = '';
1006  $this->error = '';
1007 
1008  dol_syslog(__METHOD__, LOG_DEBUG);
1009 
1010  $now = dol_now();
1011 
1012  $this->db->begin();
1013 
1014  // ...
1015 
1016  $this->db->commit();
1017 
1018  return $error;
1019  }
1020 }
$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:45
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