27require_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'),),
122 public $date_creation;
124 public $fk_user_creat;
125 public $fk_user_modif;
131 public $nb_operators_required;
132 public $thm_operator_estimated;
133 public $thm_machine_estimated;
153 global $conf, $langs;
155 require_once DOL_DOCUMENT_ROOT.
'/workstation/class/workstationusergroup.class.php';
156 require_once DOL_DOCUMENT_ROOT.
'/workstation/class/workstationresource.class.php';
160 if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID) && isset($this->fields[
'rowid'])) {
161 $this->fields[
'rowid'][
'visible'] = 0;
163 if (empty($conf->multicompany->enabled) && isset($this->fields[
'entity'])) {
164 $this->fields[
'entity'][
'enabled'] = 0;
168 foreach ($this->fields as $key => $val) {
169 if (isset($val[
'enabled']) && empty($val[
'enabled'])) {
170 unset($this->fields[$key]);
175 if (is_object($langs)) {
176 foreach ($this->fields as $key => $val) {
177 if (!empty($val[
'arrayofkeyval']) && is_array($val[
'arrayofkeyval'])) {
178 foreach ($val[
'arrayofkeyval'] as $key2 => $val2) {
179 $this->fields[$key][
'arrayofkeyval'][$key2] = $langs->trans($val2);
200 $groups =
GETPOST(
'groups',
'array:int');
201 if (empty($groups)) {
202 $groups = $this->usergroups;
204 if (!empty($groups)) {
205 foreach ($groups as $id_group) {
207 $ws_usergroup->fk_workstation = $id;
208 $ws_usergroup->fk_usergroup = $id_group;
209 $ws_usergroup->createCommon($user);
210 $this->usergroups[] = $id_group;
215 $resources =
GETPOST(
'resources',
'array:int');
216 if (empty($resources)) {
217 $resources = $this->resources;
219 if (!empty($resources)) {
220 foreach ($resources as $id_resource) {
222 $ws_resource->fk_workstation = $id;
223 $ws_resource->fk_resource = $id_resource;
224 $ws_resource->createCommon($user);
225 $this->resources[] = $id_resource;
241 global $langs, $extrafields;
246 $object =
new self($this->db);
251 $result = $object->fetch($fromid);
252 if ($result > 0 && !empty($object->table_element_line)) {
253 $object->fetchLines();
262 unset($object->fk_user_creat);
263 unset($object->import_key);
266 if (property_exists($object,
'ref')) {
267 $object->ref = empty($this->fields[
'ref'][
'default']) ?
"Copy_Of_".$object->ref : $this->fields[
'ref'][
'default'];
269 if (property_exists($object,
'label')) {
270 $object->label = empty($this->fields[
'label'][
'default']) ? $langs->trans(
"CopyOf").
" ".$object->label : $this->fields[
'label'][
'default'];
272 if (property_exists($object,
'status')) {
273 $object->status = self::STATUS_DISABLED;
275 if (property_exists($object,
'date_creation')) {
276 $object->date_creation =
dol_now();
278 if (property_exists($object,
'date_modification')) {
279 $object->date_modification =
null;
283 if (is_array($object->array_options) && count($object->array_options) > 0) {
284 $extrafields->fetch_name_optionals_label($this->table_element);
285 foreach ($object->array_options as $key => $option) {
286 $shortkey = preg_replace(
'/options_/',
'', $key);
287 if (!empty($extrafields->attributes[$this->table_element][
'unique'][$shortkey])) {
290 unset($object->array_options[$key]);
296 $object->context[
'createfromclone'] =
'createfromclone';
297 $result = $object->create($user);
300 $this->error = $object->error;
301 $this->errors = $object->errors;
313 if (property_exists($this,
'socid') && $this->socid == $object->socid) {
320 unset($object->context[
'createfromclone']);
327 $this->db->rollback();
339 public function fetch($id, $ref =
null)
346 if ($result > 0 && !empty($this->table_element_line)) {
359 $this->lines = array();
377 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, array $filter = array(), $filtermode =
'AND')
387 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
388 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
389 $sql .=
' WHERE t.entity IN ('.getEntity($this->element).
')';
391 $sql .=
' WHERE 1 = 1';
395 if (count($filter) > 0) {
396 foreach ($filter as $key => $value) {
397 if ($key ==
't.rowid') {
398 $sqlwhere[] = $key.
" = ".((int) $value);
399 } elseif (in_array($this->fields[$key][
'type'], array(
'date',
'datetime',
'timestamp'))) {
400 $sqlwhere[] = $key.
" = '".$this->db->idate($value).
"'";
401 } elseif ($key ==
'customsql') {
402 $sqlwhere[] = $value;
403 } elseif (strpos($value,
'%') ===
false) {
404 $sqlwhere[] = $key.
" IN (".$this->db->sanitize($this->db->escape($value)).
")";
406 $sqlwhere[] = $key.
" LIKE '%".$this->db->escape($value).
"%'";
410 if (count($sqlwhere) > 0) {
411 $sql .=
' AND ('.implode(
' '.$this->db->escape($filtermode).
' ', $sqlwhere).
')';
414 if (!empty($sortfield)) {
415 $sql .= $this->db->order($sortfield, $sortorder);
417 if (!empty($limit)) {
418 $sql .= $this->db->plimit($limit, $offset);
421 $resql = $this->db->query($sql);
423 $num = $this->db->num_rows($resql);
425 while ($i < ($limit ? min($limit, $num) : $num)) {
426 $obj = $this->db->fetch_object($resql);
428 $record =
new self($this->db);
429 $record->setVarsFromFetchObj($obj);
431 $records[$record->id] = $record;
435 $this->db->free($resql);
439 $this->errors[] =
'Error '.$this->db->lasterror();
440 dol_syslog(__METHOD__.
' '.join(
',', $this->errors), LOG_ERR);
457 $groups =
GETPOST(
'groups',
'array:int');
459 $this->usergroups=array();
461 foreach ($groups as $id_group) {
463 $ws_usergroup->fk_workstation = $this->id;
464 $ws_usergroup->fk_usergroup = $id_group;
465 $ws_usergroup->createCommon($user);
466 $this->usergroups[] = $id_group;
470 $resources =
GETPOST(
'resources',
'array:int');
472 $this->resources=array();
473 if (!empty($resources)) {
474 foreach ($resources as $id_resource) {
476 $ws_resource->fk_workstation = $this->id;
477 $ws_resource->fk_resource = $id_resource;
478 $ws_resource->createCommon($user);
479 $this->resources[] = $id_resource;
493 public function delete(
User $user, $notrigger =
false)
509 if ($this->status < 0) {
510 $this->error =
'ErrorDeleteLineNotAllowedByObjectStatus';
528 $this->status = $status;
530 if (empty($status)) {
547 return $this->
setStatusCommon($user, self::STATUS_ENABLED, $notrigger,
'WORKSTATION_ENABLED');
560 return $this->
setStatusCommon($user, self::STATUS_DISABLED, $notrigger,
'WORKSTATION_DISABLED');
572 global $conf, $langs;
577 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u>'.$langs->trans(
"Workstation").
'</u>';
578 $datas[
'ref'] =
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
579 if (isset($this->status)) {
580 $datas[
'status'] =
'<br><b>'.$langs->trans(
"Status").
":</b> ".$this->
getLibStatut(5);
596 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
598 global $conf, $langs, $hookmanager;
600 if (!empty($conf->dol_no_mouse_hover)) {
608 'objecttype' => $this->element,
610 $classfortooltip =
'classfortooltip';
613 $classfortooltip =
'classforajaxtooltip';
614 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
620 $url =
dol_buildpath(
'/workstation/workstation_card.php', 1).
'?id='.$this->id;
622 if ($option !=
'nolink') {
624 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
625 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
626 $add_save_lastsearch_values = 1;
628 if ($add_save_lastsearch_values) {
629 $url .=
'&save_lastsearch_values=1';
634 if (empty($notooltip)) {
635 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
636 $label = $langs->trans(
"ShowWorkstation");
637 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
639 $linkclose .= ($label ?
' title="'.dol_escape_htmltag($label, 1).
'"' :
' title="tocomplete"');
640 $linkclose .= $dataparams.
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
642 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
645 $linkstart =
'<a href="'.$url.
'"';
646 $linkstart .= $linkclose.
'>';
649 $result .= $linkstart;
651 if (empty($this->showphoto_on_popup)) {
653 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'mrp'), (($withpicto != 2) ?
'class="paddingright"' :
''), 0, 0, $notooltip ? 0 : 1);
657 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
659 list($class, $module) = explode(
'@', $this->picto);
662 $filename = $filearray[0][
'name'];
663 if (!empty($filename)) {
664 $pospoint = strpos($filearray[0][
'name'],
'.');
666 $pathtophoto = $class.
'/'.$this->
ref.
'/thumbs/'.substr($filename, 0, $pospoint).
'_mini'.substr($filename, $pospoint);
667 if (empty($conf->global->{strtoupper($module.
'_'.$class).
'_FORMATLISTPHOTOSASUSERS'})) {
668 $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>';
670 $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>';
675 $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);
680 if ($withpicto != 2) {
681 $result .= $this->ref;
687 global $action, $hookmanager;
688 $hookmanager->initHooks(array(
'workstationdao'));
689 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
690 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
692 $result = $hookmanager->resPrint;
694 $result .= $hookmanager->resPrint;
708 return $this->LibStatut($this->status, $mode);
722 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
725 $this->labelStatus[self::STATUS_DISABLED] = $langs->transnoentitiesnoconv(
'Disabled');
726 $this->labelStatus[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv(
'Enabled');
727 $this->labelStatusShort[self::STATUS_DISABLED] = $langs->transnoentitiesnoconv(
'Disabled');
728 $this->labelStatusShort[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv(
'Enabled');
731 $statusType =
'status'.$status;
733 if ($status == self::STATUS_ENABLED) $statusType =
'status4';
735 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
746 $sql =
'SELECT rowid, date_creation as datec, tms as datem,';
747 $sql .=
' fk_user_creat, fk_user_modif';
748 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
749 $sql .=
' WHERE t.rowid = '.((int) $id);
750 $result = $this->db->query($sql);
752 if ($this->db->num_rows($result)) {
753 $obj = $this->db->fetch_object($result);
754 $this->
id = $obj->rowid;
756 $this->user_creation_id = $obj->fk_user_creat;
757 $this->user_modification_id = $obj->fk_user_modif;
758 $this->date_creation = $this->db->jdate($obj->datec);
759 $this->date_modification = empty($obj->datem) ?
'' : $this->db->jdate($obj->datem);
762 $this->db->free($result);
776 $this->initAsSpecimenCommon();
786 global $langs, $conf;
787 $langs->load(
"workstation");
789 if (empty($conf->global->WORKSTATION_WORKSTATION_ADDON)) {
790 $conf->global->WORKSTATION_WORKSTATION_ADDON =
'mod_workstation_standard';
793 if (!empty($conf->global->WORKSTATION_WORKSTATION_ADDON)) {
796 $file = $conf->global->WORKSTATION_WORKSTATION_ADDON.
".php";
797 $classname = $conf->global->WORKSTATION_WORKSTATION_ADDON;
800 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
801 foreach ($dirmodels as $reldir) {
805 if (file_exists($dir.$file)) {
806 $mybool |= @include_once $dir.$file;
810 if ($mybool ===
false) {
815 if (class_exists($classname)) {
816 $obj =
new $classname();
817 $numref = $obj->getNextValue($this);
819 if ($numref !=
'' && $numref !=
'-1') {
822 $this->error = $obj->error;
827 print $langs->trans(
"Error").
" ".$langs->trans(
"ClassNotFound").
' '.$classname;
831 print $langs->trans(
"ErrorNumberingModuleNotSetup", $this->element);
847 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
849 global $conf, $langs;
852 $includedocgeneration = 0;
854 $langs->load(
"workstation");
857 $modele =
'standard_workstation';
859 if ($this->model_pdf) {
860 $modele = $this->model_pdf;
861 } elseif (!empty($conf->global->WORKSTATION_ADDON_PDF)) {
862 $modele = $conf->global->WORKSTATION_ADDON_PDF;
866 $modelpath =
"core/modules/workstation/doc/";
868 if ($includedocgeneration) {
869 $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
Parent class of all other business classes (invoices, contracts, proposals, orders,...
deleteLineCommon(User $user, $idline, $notrigger=false)
Delete a line of object in database.
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.
getFieldList($alias='', $excludefields=array())
Function to concat keys of fields.
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.
Class to manage Dolibarr database access.
Class to manage Dolibarr users.
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.
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.
getTooltipContentArray($params)
getTooltipContentArray
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return a link to the object card (with optionaly the picto)
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.
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.
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.
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.
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
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.