26 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
38 public $module =
'workstation';
43 public $element =
'workstation';
48 public $table_element =
'workstation_workstation';
54 public $ismultientitymanaged = 0;
59 public $isextrafieldmanaged = 0;
64 public $picto =
'workstation';
67 const STATUS_DISABLED = 0;
68 const STATUS_ENABLED = 1;
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'),),
122 public $note_private;
123 public $date_creation;
125 public $fk_user_creat;
126 public $fk_user_modif;
129 public $nb_operators_required;
130 public $thm_operator_estimated;
131 public $thm_machine_estimated;
178 global $conf, $langs;
180 require_once DOL_DOCUMENT_ROOT.
'/workstation/class/workstationusergroup.class.php';
181 require_once DOL_DOCUMENT_ROOT.
'/workstation/class/workstationresource.class.php';
187 if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID) && isset($this->fields[
'rowid'])) {
188 $this->fields[
'rowid'][
'visible'] = 0;
190 if (empty($conf->multicompany->enabled) && isset($this->fields[
'entity'])) {
191 $this->fields[
'entity'][
'enabled'] = 0;
201 foreach ($this->fields as $key => $val) {
202 if (isset($val[
'enabled']) && empty($val[
'enabled'])) {
203 unset($this->fields[$key]);
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);
233 $groups =
GETPOST(
'groups',
'array:int');
234 if (empty($groups)) {
235 $groups = $this->usergroups;
237 if (!empty($groups)) {
238 foreach ($groups as $id_group) {
240 $ws_usergroup->fk_workstation = $id;
241 $ws_usergroup->fk_usergroup = $id_group;
242 $ws_usergroup->createCommon($user);
243 $this->usergroups[] = $id_group;
248 $resources =
GETPOST(
'resources',
'array:int');
249 if (empty($resources)) {
250 $resources = $this->resources;
252 if (!empty($resources)) {
253 foreach ($resources as $id_resource) {
255 $ws_resource->fk_workstation = $id;
256 $ws_resource->fk_resource = $id_resource;
257 $ws_resource->createCommon($user);
258 $this->resources[] = $id_resource;
274 global $langs, $extrafields;
279 $object =
new self($this->db);
284 $result = $object->fetch($fromid);
285 if ($result > 0 && !empty($object->table_element_line)) {
286 $object->fetchLines();
295 unset($object->fk_user_creat);
296 unset($object->import_key);
299 if (property_exists($object,
'ref')) {
300 $object->ref = empty($this->fields[
'ref'][
'default']) ?
"Copy_Of_".$object->ref : $this->fields[
'ref'][
'default'];
302 if (property_exists($object,
'label')) {
303 $object->label = empty($this->fields[
'label'][
'default']) ? $langs->trans(
"CopyOf").
" ".$object->label : $this->fields[
'label'][
'default'];
305 if (property_exists($object,
'status')) {
306 $object->status = self::STATUS_DISABLED;
308 if (property_exists($object,
'date_creation')) {
309 $object->date_creation =
dol_now();
311 if (property_exists($object,
'date_modification')) {
312 $object->date_modification =
null;
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])) {
323 unset($object->array_options[$key]);
329 $object->context[
'createfromclone'] =
'createfromclone';
330 $result = $object->create($user);
333 $this->error = $object->error;
334 $this->errors = $object->errors;
346 if (property_exists($this,
'socid') && $this->socid == $object->socid) {
353 unset($object->context[
'createfromclone']);
360 $this->
db->rollback();
372 public function fetch($id, $ref =
null)
379 if ($result > 0 && !empty($this->table_element_line)) {
392 $this->lines = array();
410 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, array $filter = array(), $filtermode =
'AND')
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).
')';
424 $sql .=
' WHERE 1 = 1';
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)).
")";
439 $sqlwhere[] = $key.
" LIKE '%".$this->
db->escape($value).
"%'";
443 if (count($sqlwhere) > 0) {
444 $sql .=
' AND ('.implode(
' '.$this->
db->escape($filtermode).
' ', $sqlwhere).
')';
447 if (!empty($sortfield)) {
448 $sql .= $this->
db->order($sortfield, $sortorder);
450 if (!empty($limit)) {
451 $sql .= $this->
db->plimit($limit, $offset);
458 while ($i < ($limit ? min($limit, $num) : $num)) {
459 $obj = $this->
db->fetch_object(
$resql);
461 $record =
new self($this->db);
462 $record->setVarsFromFetchObj($obj);
464 $records[$record->id] = $record;
472 $this->errors[] =
'Error '.$this->db->lasterror();
473 dol_syslog(__METHOD__.
' '.join(
',', $this->errors), LOG_ERR);
490 $groups =
GETPOST(
'groups',
'array:int');
492 $this->usergroups=array();
494 foreach ($groups as $id_group) {
496 $ws_usergroup->fk_workstation = $this->id;
497 $ws_usergroup->fk_usergroup = $id_group;
498 $ws_usergroup->createCommon($user);
499 $this->usergroups[] = $id_group;
503 $resources =
GETPOST(
'resources',
'array:int');
505 $this->resources=array();
506 if (!empty($resources)) {
507 foreach ($resources as $id_resource) {
509 $ws_resource->fk_workstation = $this->id;
510 $ws_resource->fk_resource = $id_resource;
511 $ws_resource->createCommon($user);
512 $this->resources[] = $id_resource;
526 public function delete(
User $user, $notrigger =
false)
542 if ($this->status < 0) {
543 $this->error =
'ErrorDeleteLineNotAllowedByObjectStatus';
560 global $conf, $langs;
562 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
567 if ($this->status == self::STATUS_VALIDATED) {
568 dol_syslog(get_class($this).
"::validate action abandonned: already validated", LOG_WARNING);
585 if (!$error && (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref))) {
590 $this->newref = $num;
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).
"'";
600 if (!empty($this->fields[
'fk_user_valid'])) {
601 $sql .=
", fk_user_valid = ".$user->id;
603 $sql .=
" WHERE rowid = ".((int) $this->
id);
605 dol_syslog(get_class($this).
"::validate()", LOG_DEBUG);
609 $this->error = $this->
db->lasterror();
613 if (!$error && !$notrigger) {
615 $result = $this->
call_trigger(
'WORKSTATION_VALIDATE', $user);
624 $this->oldref = $this->ref;
627 if (preg_match(
'/^[\(]?PROV/i', $this->
ref)) {
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;
633 $error++; $this->error = $this->
db->lasterror();
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);
644 if (@rename($dirsource, $dirdest)) {
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);
663 $this->status = self::STATUS_VALIDATED;
670 $this->
db->rollback();
687 $this->status = $status;
689 if (empty($status)) {
706 return $this->
setStatusCommon($user, self::STATUS_ENABLED, $notrigger,
'WORKSTATION_ENABLED');
719 return $this->
setStatusCommon($user, self::STATUS_DISABLED, $notrigger,
'WORKSTATION_DISABLED');
732 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
734 global $conf, $langs, $hookmanager;
736 if (!empty($conf->dol_no_mouse_hover)) {
742 $label =
img_picto(
'', $this->picto).
' <u>'.$langs->trans(
"Workstation").
'</u>';
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);
749 $url =
dol_buildpath(
'/workstation/workstation_card.php', 1).
'?id='.$this->id;
751 if ($option !=
'nolink') {
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;
757 if ($add_save_lastsearch_values) {
758 $url .=
'&save_lastsearch_values=1';
763 if (empty($notooltip)) {
764 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
765 $label = $langs->trans(
"ShowWorkstation");
766 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
768 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
769 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
771 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
774 $linkstart =
'<a href="'.$url.
'"';
775 $linkstart .= $linkclose.
'>';
778 $result .= $linkstart;
780 if (empty($this->showphoto_on_popup)) {
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);
786 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
788 list($class, $module) = explode(
'@', $this->picto);
791 $filename = $filearray[0][
'name'];
792 if (!empty($filename)) {
793 $pospoint = strpos($filearray[0][
'name'],
'.');
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>';
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>';
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);
809 if ($withpicto != 2) {
810 $result .= $this->ref;
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);
821 $result = $hookmanager->resPrint;
823 $result .= $hookmanager->resPrint;
837 return $this->LibStatut($this->status, $mode);
851 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
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');
860 $statusType =
'status'.$status;
862 if ($status == self::STATUS_ENABLED) $statusType =
'status4';
864 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
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);
881 if ($this->
db->num_rows($result)) {
882 $obj = $this->
db->fetch_object($result);
883 $this->
id = $obj->rowid;
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);
891 $this->
db->free($result);
905 $this->initAsSpecimenCommon();
915 $this->lines = array();
940 global $langs, $conf;
941 $langs->load(
"workstation");
943 if (empty($conf->global->WORKSTATION_WORKSTATION_ADDON)) {
944 $conf->global->WORKSTATION_WORKSTATION_ADDON =
'mod_workstation_standard';
947 if (!empty($conf->global->WORKSTATION_WORKSTATION_ADDON)) {
950 $file = $conf->global->WORKSTATION_WORKSTATION_ADDON.
".php";
951 $classname = $conf->global->WORKSTATION_WORKSTATION_ADDON;
954 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
955 foreach ($dirmodels as $reldir) {
959 $mybool |= @include_once $dir.$file;
962 if ($mybool ===
false) {
967 if (class_exists($classname)) {
968 $obj =
new $classname();
969 $numref = $obj->getNextValue($this);
971 if ($numref !=
'' && $numref !=
'-1') {
974 $this->error = $obj->error;
979 print $langs->trans(
"Error").
" ".$langs->trans(
"ClassNotFound").
' '.$classname;
983 print $langs->trans(
"ErrorNumberingModuleNotSetup", $this->element);
999 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
1001 global $conf, $langs;
1004 $includedocgeneration = 0;
1006 $langs->load(
"workstation");
1009 $modele =
'standard_workstation';
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;
1018 $modelpath =
"core/modules/workstation/doc/";
1020 if ($includedocgeneration) {
1021 $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1036 global $conf, $langs;
1052 $this->
db->commit();