26require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
36 public $element =
'establishment';
41 public $table_element =
'establishment';
46 public $table_element_line =
'';
51 public $fk_element =
'fk_establishment';
56 public $picto =
'establishment';
116 public $fk_user_author;
123 const STATUS_OPEN = 1;
124 const STATUS_CLOSED = 0;
127 public $fields = array(
128 'rowid' => array(
'type' =>
'integer',
'label' =>
'TechnicalID',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 10),
129 'entity' => array(
'type' =>
'integer',
'label' =>
'Entity',
'default' =>
'1',
'enabled' => 1,
'visible' => -2,
'notnull' => 1,
'position' => 15,
'index' => 1),
130 'ref' => array(
'type' =>
'varchar(30)',
'label' =>
'Ref',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'showoncombobox' => 1,
'position' => 20),
131 'label' => array(
'type' =>
'varchar(128)',
'label' =>
'Label',
'enabled' => 1,
'visible' => -1,
'showoncombobox' => 2,
'position' => 22),
132 'address' => array(
'type' =>
'varchar(255)',
'label' =>
'Address',
'enabled' => 1,
'visible' => -1,
'position' => 25),
133 'zip' => array(
'type' =>
'varchar(25)',
'label' =>
'Zip',
'enabled' => 1,
'visible' => -1,
'position' => 30),
134 'town' => array(
'type' =>
'varchar(50)',
'label' =>
'Town',
'enabled' => 1,
'visible' => -1,
'position' => 35),
135 'fk_state' => array(
'type' =>
'integer',
'label' =>
'Fkstate',
'enabled' => 1,
'visible' => -1,
'position' => 40),
136 'fk_country' => array(
'type' =>
'integer',
'label' =>
'Fkcountry',
'enabled' => 1,
'visible' => -1,
'position' => 45),
137 'profid1' => array(
'type' =>
'varchar(20)',
'label' =>
'Profid1',
'enabled' => 1,
'visible' => -1,
'position' => 50),
138 'profid2' => array(
'type' =>
'varchar(20)',
'label' =>
'Profid2',
'enabled' => 1,
'visible' => -1,
'position' => 55),
139 'profid3' => array(
'type' =>
'varchar(20)',
'label' =>
'Profid3',
'enabled' => 1,
'visible' => -1,
'position' => 60),
140 'phone' => array(
'type' =>
'varchar(20)',
'label' =>
'Phone',
'enabled' => 1,
'visible' => -1,
'position' => 65),
141 'fk_user_author' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'Fkuserauthor',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 70),
142 'fk_user_mod' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'Fkusermod',
'enabled' => 1,
'visible' => -1,
'position' => 75),
143 'datec' => array(
'type' =>
'datetime',
'label' =>
'DateCreation',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 80),
144 'tms' => array(
'type' =>
'timestamp',
'label' =>
'DateModification',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 85),
145 'status' => array(
'type' =>
'integer',
'label' =>
'Status',
'enabled' => 1,
'visible' => -1,
'position' => 500),
158 $this->ismultientitymanaged = 1;
169 global $conf, $langs;
175 $this->label = trim($this->label);
176 $this->address = trim($this->address);
177 $this->zip = trim($this->zip);
178 $this->town = trim($this->town);
180 if (empty($this->
ref)) {
181 $this->
ref =
'(PROV)';
186 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"establishment (";
192 $sql .=
", fk_country";
196 $sql .=
", fk_user_author";
197 $sql .=
", fk_user_mod";
198 $sql .=
") VALUES (";
199 $sql .=
"'".$this->db->escape($this->
ref).
"'";
200 $sql .=
", '".$this->db->escape($this->label).
"'";
201 $sql .=
", '".$this->db->escape($this->address).
"'";
202 $sql .=
", '".$this->db->escape($this->zip).
"'";
203 $sql .=
", '".$this->db->escape($this->town).
"'";
204 $sql .=
", ".((int) $this->country_id);
205 $sql .=
", ".((int) $this->
status);
206 $sql .=
", ".((int) $conf->entity);
207 $sql .=
", '".$this->db->idate($now).
"'";
208 $sql .=
", ".((int) $user->id);
209 $sql .=
", ".((int) $user->id);
212 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
213 $resql = $this->db->query($sql);
216 $this->errors[] =
"Error ".$this->db->lasterror();
221 foreach ($this->errors as $errmsg) {
222 dol_syslog(get_class($this).
"::create ".$errmsg, LOG_ERR);
223 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
225 $this->db->rollback();
228 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
'establishment');
230 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"establishment SET ref = '".$this->db->escape($this->
id).
"'";
231 $sql .=
" WHERE rowid = ".((int) $this->
id);
232 $this->db->query($sql);
250 if (empty($this->label)) {
251 $this->error =
'ErrorBadParameter';
257 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"establishment";
258 $sql .=
" SET ref = '".$this->db->escape($this->
ref).
"'";
259 $sql .=
", label = '".$this->db->escape($this->label).
"'";
260 $sql .=
", address = '".$this->db->escape($this->address).
"'";
261 $sql .=
", zip = '".$this->db->escape($this->zip).
"'";
262 $sql .=
", town = '".$this->db->escape($this->town).
"'";
263 $sql .=
", fk_country = ".($this->country_id > 0 ? $this->country_id :
'null');
264 $sql .=
", status = ".((int) $this->
status);
265 $sql .=
", fk_user_mod = ".((int) $user->id);
266 $sql .=
", entity = ".((int) $this->entity);
267 $sql .=
" WHERE rowid = ".((int) $this->
id);
269 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
270 $result = $this->db->query($sql);
275 $this->error = $this->db->lasterror();
276 $this->db->rollback();
289 $sql =
"SELECT e.rowid, e.ref, e.label, e.address, e.zip, e.town, e.status, e.fk_country as country_id, e.entity,";
290 $sql .=
' c.code as country_code, c.label as country';
291 $sql .=
" FROM ".MAIN_DB_PREFIX.
"establishment as e";
292 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_country as c ON e.fk_country = c.rowid';
293 $sql .=
" WHERE e.rowid = ".((int) $id);
295 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
296 $result = $this->db->query($sql);
298 $obj = $this->db->fetch_object($result);
300 $this->
id = $obj->rowid;
301 $this->
ref = $obj->ref;
302 $this->label = $obj->label;
303 $this->address = $obj->address;
304 $this->zip = $obj->zip;
305 $this->town = $obj->town;
306 $this->
status = $obj->status;
307 $this->entity = $obj->entity;
309 $this->country_id = $obj->country_id;
310 $this->country_code = $obj->country_code;
311 $this->country = $obj->country;
318 $this->error = $this->db->lasterror();
329 public function delete($user)
333 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"establishment WHERE rowid = ".((int) $user->id);
335 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
337 $result = $this->db->query($sql);
342 $this->error = $this->db->lasterror();
343 $this->db->rollback();
370 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
373 $this->labelStatus[self::STATUS_OPEN] = $langs->transnoentitiesnoconv(
'Open');
374 $this->labelStatus[self::STATUS_CLOSED] = $langs->transnoentitiesnoconv(
'Closed');
375 $this->labelStatusShort[self::STATUS_OPEN] = $langs->transnoentitiesnoconv(
'Open');
376 $this->labelStatusShort[self::STATUS_CLOSED] = $langs->transnoentitiesnoconv(
'Closed');
379 $statusType =
'status'.$status;
380 if ($status == self::STATUS_OPEN) {
381 $statusType =
'status4';
383 if ($status == self::STATUS_CLOSED) {
384 $statusType =
'status6';
387 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
399 $sql =
'SELECT e.rowid, e.ref, e.datec, e.fk_user_author, e.tms as datem, e.fk_user_mod, e.entity';
400 $sql .=
' FROM '.MAIN_DB_PREFIX.
'establishment as e';
401 $sql .=
' WHERE e.rowid = '.((int) $id);
403 dol_syslog(get_class($this).
"::fetch info", LOG_DEBUG);
404 $result = $this->db->query($sql);
407 if ($this->db->num_rows($result)) {
408 $obj = $this->db->fetch_object($result);
410 $this->
id = $obj->rowid;
412 $this->user_creation_id = $obj->fk_user_author;
413 $this->user_modification_id = $obj->fk_user_mod;
414 $this->date_creation = $this->db->jdate($obj->datec);
415 $this->date_modification = empty($obj->datem) ?
'' : $this->db->jdate($obj->datem);
417 $this->db->free($result);
433 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
435 global $conf, $langs, $hookmanager;
437 if (!empty($conf->dol_no_mouse_hover)) {
443 $label =
img_picto(
'', $this->picto).
' <u>'.$langs->trans(
"Establishment").
'</u>';
444 if (isset($this->
status)) {
445 $label .=
' '.$this->getLibStatut(5);
448 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
451 $label .=
'<b>'.$langs->trans(
'Residence').
':</b> '.$this->address.
', '.$this->zip.
' '.$this->town;
453 $url = DOL_URL_ROOT.
'/hrm/establishment/card.php?id='.$this->id;
455 if ($option !=
'nolink') {
457 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
458 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
459 $add_save_lastsearch_values = 1;
461 if ($add_save_lastsearch_values) {
462 $url .=
'&save_lastsearch_values=1';
467 if (empty($notooltip)) {
469 $label = $langs->trans(
"Establishment");
470 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
472 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
473 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
475 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
478 if ($option ==
'nolink') {
479 $linkstart =
'<span';
481 $linkstart =
'<a href="'.$url.
'"';
483 $linkstart .= $linkclose.
'>';
484 if ($option ==
'nolink') {
485 $linkend =
'</span>';
490 $result .= $linkstart;
493 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
496 if ($withpicto != 2) {
497 $result .= $this->label;
503 global $action, $hookmanager;
504 $hookmanager->initHooks(array(
'establishmentdao'));
505 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
506 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
508 $result = $hookmanager->resPrint;
510 $result .= $hookmanager->resPrint;
526 if (!empty($this->country_code)) {
527 return $this->country_code;
531 if (!empty($mysoc->country_code)) {
532 return $mysoc->country_code;
548 $this->label =
'Department AAA';
print $langs trans("AuditedSecurityEvents").'</strong >< span class="opacitymedium"></span >< br > status
Or an array listing all the potential status of the object: array: int of the status => translated la...
Parent class of all other business classes (invoices, contracts, proposals, orders,...
Class to manage establishments.
__construct($db)
Constructor.
getCountryCode()
Return account country code.
update($user)
Update record.
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
LibStatut($status, $mode=0)
Return the status.
getLibStatut($mode=0)
Give a label from a status.
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return a link to the object card (with optionally the picto)
fetch($id)
Load an object from database.
create($user)
Create object in database.
info($id)
Information on record.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_now($mode='auto')
Return date for now.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.