27 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
37 public $module =
'workstation';
42 public $element =
'workstation';
47 public $table_element =
'workstation_workstation';
53 public $ismultientitymanaged = 0;
58 public $isextrafieldmanaged = 0;
63 public $picto =
'workstation';
66 const STATUS_DISABLED = 0;
67 const STATUS_ENABLED = 1;
100 public $fields=array(
101 'rowid' => array(
'type'=>
'integer',
'label'=>
'TechnicalID',
'enabled'=>
'1',
'position'=>1,
'notnull'=>1,
'visible'=>0,
'noteditable'=>
'1',
'index'=>1,
'css'=>
'left',
'comment'=>
"Id"),
102 'ref' => array(
'type'=>
'varchar(128)',
'label'=>
'Ref',
'enabled'=>
'1',
'position'=>10,
'notnull'=>1,
'visible'=>1,
'noteditable'=>
'0',
'default'=>
'',
'index'=>1,
'searchall'=>1,
'showoncombobox'=>
'1',
'comment'=>
"Reference of object"),
103 'label' => array(
'type'=>
'varchar(255)',
'label'=>
'Label',
'enabled'=>
'1',
'position'=>30,
'notnull'=>1,
'visible'=>1,
'searchall'=>1,
'css'=>
'minwidth300',
'csslist'=>
'tdoverflowmax125',
'showoncombobox'=>
'2',),
104 'type' => array(
'type'=>
'varchar(8)',
'label'=>
'Type',
'enabled'=>
'1',
'position'=>32,
'default'=>1,
'notnull'=>1,
'visible'=>1,
'arrayofkeyval'=>array(
'HUMAN'=>
'Human',
'MACHINE'=>
'Machine',
'BOTH'=>
'HumanMachine'),),
105 'note_public' => array(
'type'=>
'html',
'label'=>
'NotePublic',
'enabled'=>
'1',
'position'=>61,
'notnull'=>0,
'visible'=>0,),
106 'note_private' => array(
'type'=>
'html',
'label'=>
'NotePrivate',
'enabled'=>
'1',
'position'=>62,
'notnull'=>0,
'visible'=>0,),
107 'date_creation' => array(
'type'=>
'datetime',
'label'=>
'DateCreation',
'enabled'=>
'1',
'position'=>500,
'notnull'=>1,
'visible'=>-2,
'csslist'=>
'nowraponall'),
108 'tms' => array(
'type'=>
'timestamp',
'label'=>
'DateModification',
'enabled'=>
'1',
'position'=>501,
'notnull'=>0,
'visible'=>-2,
'csslist'=>
'nowraponall'),
109 'fk_user_creat' => array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'UserAuthor',
'enabled'=>
'1',
'position'=>510,
'notnull'=>1,
'visible'=>-2,
'foreignkey'=>
'user.rowid',),
110 'fk_user_modif' => array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'UserModif',
'enabled'=>
'1',
'position'=>511,
'notnull'=>-1,
'visible'=>-2,),
111 'import_key' => array(
'type'=>
'varchar(14)',
'label'=>
'ImportId',
'enabled'=>
'1',
'position'=>512,
'notnull'=>-1,
'visible'=>-2,),
112 'nb_operators_required' => array(
'type'=>
'integer',
'label'=>
'NbOperatorsRequired',
'enabled'=>
'1',
'position'=>50,
'notnull'=>0,
'visible'=>1,),
113 'thm_operator_estimated' => array(
'type'=>
'double',
'help'=>
'THMOperatorEstimatedHelp',
'label'=>
'THMOperatorEstimated',
'enabled'=>
'1',
'position'=>50,
'notnull'=>0,
'visible'=>1,
'css'=>
'right'),
114 'thm_machine_estimated' => array(
'type'=>
'double',
'help'=>
'THMMachineEstimatedHelp',
'label'=>
'THMMachineEstimated',
'enabled'=>
'1',
'position'=>50,
'notnull'=>0,
'visible'=>1,
'css'=>
'right'),
115 'status' => array(
'type'=>
'smallint',
'label'=>
'Status',
'enabled'=>
'1',
'position'=>1000,
'default'=>1,
'notnull'=>1,
'visible'=>1,
'index'=>1,
'arrayofkeyval'=>array(
'0'=>
'Disabled',
'1'=>
'Enabled'),),
121 public $date_creation;
123 public $fk_user_creat;
124 public $fk_user_modif;
130 public $nb_operators_required;
131 public $thm_operator_estimated;
132 public $thm_machine_estimated;
152 global $conf, $langs;
154 require_once DOL_DOCUMENT_ROOT.
'/workstation/class/workstationusergroup.class.php';
155 require_once DOL_DOCUMENT_ROOT.
'/workstation/class/workstationresource.class.php';
159 if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID) && isset($this->fields[
'rowid'])) {
160 $this->fields[
'rowid'][
'visible'] = 0;
162 if (empty($conf->multicompany->enabled) && isset($this->fields[
'entity'])) {
163 $this->fields[
'entity'][
'enabled'] = 0;
167 foreach ($this->fields as $key => $val) {
168 if (isset($val[
'enabled']) && empty($val[
'enabled'])) {
169 unset($this->fields[$key]);
174 if (is_object($langs)) {
175 foreach ($this->fields as $key => $val) {
176 if (!empty($val[
'arrayofkeyval']) && is_array($val[
'arrayofkeyval'])) {
177 foreach ($val[
'arrayofkeyval'] as $key2 => $val2) {
178 $this->fields[$key][
'arrayofkeyval'][$key2] = $langs->trans($val2);
199 $groups =
GETPOST(
'groups',
'array:int');
200 if (empty($groups)) {
201 $groups = $this->usergroups;
203 if (!empty($groups)) {
204 foreach ($groups as $id_group) {
206 $ws_usergroup->fk_workstation = $id;
207 $ws_usergroup->fk_usergroup = $id_group;
208 $ws_usergroup->createCommon($user);
209 $this->usergroups[] = $id_group;
214 $resources =
GETPOST(
'resources',
'array:int');
215 if (empty($resources)) {
216 $resources = $this->resources;
218 if (!empty($resources)) {
219 foreach ($resources as $id_resource) {
221 $ws_resource->fk_workstation = $id;
222 $ws_resource->fk_resource = $id_resource;
223 $ws_resource->createCommon($user);
224 $this->resources[] = $id_resource;
240 global $langs, $extrafields;
245 $object =
new self($this->db);
250 $result = $object->fetch($fromid);
251 if ($result > 0 && !empty($object->table_element_line)) {
252 $object->fetchLines();
261 unset($object->fk_user_creat);
262 unset($object->import_key);
265 if (property_exists($object,
'ref')) {
266 $object->ref = empty($this->fields[
'ref'][
'default']) ?
"Copy_Of_".$object->ref : $this->fields[
'ref'][
'default'];
268 if (property_exists($object,
'label')) {
269 $object->label = empty($this->fields[
'label'][
'default']) ? $langs->trans(
"CopyOf").
" ".$object->label : $this->fields[
'label'][
'default'];
271 if (property_exists($object,
'status')) {
272 $object->status = self::STATUS_DISABLED;
274 if (property_exists($object,
'date_creation')) {
275 $object->date_creation =
dol_now();
277 if (property_exists($object,
'date_modification')) {
278 $object->date_modification =
null;
282 if (is_array($object->array_options) && count($object->array_options) > 0) {
283 $extrafields->fetch_name_optionals_label($this->table_element);
284 foreach ($object->array_options as $key => $option) {
285 $shortkey = preg_replace(
'/options_/',
'', $key);
286 if (!empty($extrafields->attributes[$this->table_element][
'unique'][$shortkey])) {
289 unset($object->array_options[$key]);
295 $object->context[
'createfromclone'] =
'createfromclone';
296 $result = $object->create($user);
299 $this->error = $object->error;
300 $this->errors = $object->errors;
312 if (property_exists($this,
'socid') && $this->socid == $object->socid) {
319 unset($object->context[
'createfromclone']);
326 $this->db->rollback();
338 public function fetch($id, $ref =
null)
345 if ($result > 0 && !empty($this->table_element_line)) {
358 $this->lines = array();
376 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, array $filter = array(), $filtermode =
'AND')
386 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
387 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
388 $sql .=
' WHERE t.entity IN ('.getEntity($this->element).
')';
390 $sql .=
' WHERE 1 = 1';
394 if (count($filter) > 0) {
395 foreach ($filter as $key => $value) {
396 if ($key ==
't.rowid') {
397 $sqlwhere[] = $key.
" = ".((int) $value);
398 } elseif (in_array($this->fields[$key][
'type'], array(
'date',
'datetime',
'timestamp'))) {
399 $sqlwhere[] = $key.
" = '".$this->db->idate($value).
"'";
400 } elseif ($key ==
'customsql') {
401 $sqlwhere[] = $value;
402 } elseif (strpos($value,
'%') ===
false) {
403 $sqlwhere[] = $key.
" IN (".$this->db->sanitize($this->db->escape($value)).
")";
405 $sqlwhere[] = $key.
" LIKE '%".$this->db->escape($value).
"%'";
409 if (count($sqlwhere) > 0) {
410 $sql .=
' AND ('.implode(
' '.$this->db->escape($filtermode).
' ', $sqlwhere).
')';
413 if (!empty($sortfield)) {
414 $sql .= $this->db->order($sortfield, $sortorder);
416 if (!empty($limit)) {
417 $sql .= $this->db->plimit($limit, $offset);
420 $resql = $this->db->query(
$sql);
422 $num = $this->db->num_rows($resql);
424 while ($i < ($limit ? min($limit, $num) : $num)) {
425 $obj = $this->db->fetch_object($resql);
427 $record =
new self($this->db);
428 $record->setVarsFromFetchObj($obj);
430 $records[$record->id] = $record;
434 $this->db->free($resql);
438 $this->errors[] =
'Error '.$this->db->lasterror();
439 dol_syslog(__METHOD__.
' '.join(
',', $this->errors), LOG_ERR);
456 $groups =
GETPOST(
'groups',
'array:int');
458 $this->usergroups=array();
460 foreach ($groups as $id_group) {
462 $ws_usergroup->fk_workstation = $this->id;
463 $ws_usergroup->fk_usergroup = $id_group;
464 $ws_usergroup->createCommon($user);
465 $this->usergroups[] = $id_group;
469 $resources =
GETPOST(
'resources',
'array:int');
471 $this->resources=array();
472 if (!empty($resources)) {
473 foreach ($resources as $id_resource) {
475 $ws_resource->fk_workstation = $this->id;
476 $ws_resource->fk_resource = $id_resource;
477 $ws_resource->createCommon($user);
478 $this->resources[] = $id_resource;
492 public function delete(
User $user, $notrigger =
false)
508 if ($this->status < 0) {
509 $this->error =
'ErrorDeleteLineNotAllowedByObjectStatus';
527 $this->status = $status;
529 if (empty($status)) {
546 return $this->
setStatusCommon($user, self::STATUS_ENABLED, $notrigger,
'WORKSTATION_ENABLED');
559 return $this->
setStatusCommon($user, self::STATUS_DISABLED, $notrigger,
'WORKSTATION_DISABLED');
571 global $conf, $langs;
576 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u>'.$langs->trans(
"Workstation").
'</u>';
577 $datas[
'ref'] =
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
578 if (isset($this->status)) {
579 $datas[
'status'] =
'<br><b>'.$langs->trans(
"Status").
":</b> ".$this->
getLibStatut(5);
595 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
597 global $conf, $langs, $hookmanager;
599 if (!empty($conf->dol_no_mouse_hover)) {
607 'objecttype' => $this->element,
609 $classfortooltip =
'classfortooltip';
612 $classfortooltip =
'classforajaxtooltip';
613 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
619 $url =
dol_buildpath(
'/workstation/workstation_card.php', 1).
'?id='.$this->id;
621 if ($option !=
'nolink') {
623 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
624 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
625 $add_save_lastsearch_values = 1;
627 if ($add_save_lastsearch_values) {
628 $url .=
'&save_lastsearch_values=1';
633 if (empty($notooltip)) {
634 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
635 $label = $langs->trans(
"ShowWorkstation");
636 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
638 $linkclose .= ($label ?
' title="'.dol_escape_htmltag($label, 1).
'"' :
' title="tocomplete"');
639 $linkclose .= $dataparams.
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
641 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
644 $linkstart =
'<a href="'.$url.
'"';
645 $linkstart .= $linkclose.
'>';
648 $result .= $linkstart;
650 if (empty($this->showphoto_on_popup)) {
652 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'mrp'), (($withpicto != 2) ?
'class="paddingright"' :
''), 0, 0, $notooltip ? 0 : 1);
656 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
658 list($class, $module) = explode(
'@', $this->picto);
661 $filename = $filearray[0][
'name'];
662 if (!empty($filename)) {
663 $pospoint = strpos($filearray[0][
'name'],
'.');
665 $pathtophoto = $class.
'/'.$this->
ref.
'/thumbs/'.substr($filename, 0, $pospoint).
'_mini'.substr($filename, $pospoint);
666 if (empty($conf->global->{strtoupper($module.
'_'.$class).
'_FORMATLISTPHOTOSASUSERS'})) {
667 $result .=
'<div class="floatleft inline-block valignmiddle divphotoref"><div class="photoref"><img class="photo'.$module.
'" alt="No photo" border="0" src="'.DOL_URL_ROOT.
'/viewimage.php?modulepart='.$module.
'&entity='.$conf->entity.
'&file='.urlencode($pathtophoto).
'"></div></div>';
669 $result .=
'<div class="floatleft inline-block valignmiddle divphotoref"><img class="photouserphoto userphoto" alt="No photo" border="0" src="'.DOL_URL_ROOT.
'/viewimage.php?modulepart='.$module.
'&entity='.$conf->entity.
'&file='.urlencode($pathtophoto).
'"></div>';
674 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'mrp'), ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
679 if ($withpicto != 2) {
680 $result .= $this->ref;
686 global $action, $hookmanager;
687 $hookmanager->initHooks(array(
'workstationdao'));
688 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
689 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
691 $result = $hookmanager->resPrint;
693 $result .= $hookmanager->resPrint;
707 return $this->LibStatut($this->status, $mode);
721 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
724 $this->labelStatus[self::STATUS_DISABLED] = $langs->transnoentitiesnoconv(
'Disabled');
725 $this->labelStatus[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv(
'Enabled');
726 $this->labelStatusShort[self::STATUS_DISABLED] = $langs->transnoentitiesnoconv(
'Disabled');
727 $this->labelStatusShort[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv(
'Enabled');
730 $statusType =
'status'.$status;
732 if ($status == self::STATUS_ENABLED) $statusType =
'status4';
734 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
745 $sql =
'SELECT rowid, date_creation as datec, tms as datem,';
746 $sql .=
' fk_user_creat, fk_user_modif';
747 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
748 $sql .=
' WHERE t.rowid = '.((int) $id);
749 $result = $this->db->query(
$sql);
751 if ($this->db->num_rows($result)) {
752 $obj = $this->db->fetch_object($result);
753 $this->
id = $obj->rowid;
755 $this->user_creation_id = $obj->fk_user_creat;
756 $this->user_modification_id = $obj->fk_user_modif;
757 $this->date_creation = $this->db->jdate($obj->datec);
758 $this->date_modification = empty($obj->datem) ?
'' : $this->db->jdate($obj->datem);
761 $this->db->free($result);
775 $this->initAsSpecimenCommon();
785 global $langs, $conf;
786 $langs->load(
"workstation");
788 if (empty($conf->global->WORKSTATION_WORKSTATION_ADDON)) {
789 $conf->global->WORKSTATION_WORKSTATION_ADDON =
'mod_workstation_standard';
792 if (!empty($conf->global->WORKSTATION_WORKSTATION_ADDON)) {
795 $file = $conf->global->WORKSTATION_WORKSTATION_ADDON.
".php";
796 $classname = $conf->global->WORKSTATION_WORKSTATION_ADDON;
799 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
800 foreach ($dirmodels as $reldir) {
804 $mybool |= @include_once $dir.$file;
807 if ($mybool ===
false) {
812 if (class_exists($classname)) {
813 $obj =
new $classname();
814 $numref = $obj->getNextValue($this);
816 if ($numref !=
'' && $numref !=
'-1') {
819 $this->error = $obj->error;
824 print $langs->trans(
"Error").
" ".$langs->trans(
"ClassNotFound").
' '.$classname;
828 print $langs->trans(
"ErrorNumberingModuleNotSetup", $this->element);
844 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
846 global $conf, $langs;
849 $includedocgeneration = 0;
851 $langs->load(
"workstation");
854 $modele =
'standard_workstation';
856 if ($this->model_pdf) {
857 $modele = $this->model_pdf;
858 } elseif (!empty($conf->global->WORKSTATION_ADDON_PDF)) {
859 $modele = $conf->global->WORKSTATION_ADDON_PDF;
863 $modelpath =
"core/modules/workstation/doc/";
865 if ($includedocgeneration) {
866 $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);