164 global
$conf, $langs;
170 $this->label = trim($this->label);
172 $this->zip = trim($this->zip);
173 $this->town = trim($this->town);
175 if (empty($this->
ref)) {
176 $this->
ref =
'(PROV)';
181 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"establishment (";
187 $sql .=
", fk_country";
191 $sql .=
", fk_user_author";
192 $sql .=
", fk_user_mod";
193 $sql .=
") VALUES (";
194 $sql .=
"'".$this->db->escape($this->
ref).
"'";
195 $sql .=
", '".$this->db->escape($this->label).
"'";
196 $sql .=
", '".$this->db->escape($this->
address).
"'";
197 $sql .=
", '".$this->db->escape($this->zip).
"'";
198 $sql .=
", '".$this->db->escape($this->town).
"'";
199 $sql .=
", ".((int) $this->country_id);
200 $sql .=
", ".((int) $this->
status);
201 $sql .=
", ".((int)
$conf->entity);
202 $sql .=
", '".$this->db->idate($now).
"'";
203 $sql .=
", ".((int) $user->id);
204 $sql .=
", ".((int) $user->id);
207 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
208 $resql = $this->db->query($sql);
211 $this->errors[] =
"Error ".$this->db->lasterror();
216 foreach ($this->errors as $errmsg) {
217 dol_syslog(get_class($this).
"::create ".$errmsg, LOG_ERR);
218 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
220 $this->db->rollback();
223 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
'establishment');
225 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"establishment SET ref = '".$this->db->escape((
string) $this->id).
"'";
226 $sql .=
" WHERE rowid = ".((int) $this->
id);
227 $this->db->query($sql);
230 $triggerres = $this->call_trigger(
'ESTABLISHMENT_CREATE', $user);
231 if ($triggerres < 0) {
232 $this->db->rollback();
253 if (empty($this->label)) {
254 $this->error =
'ErrorBadParameter';
260 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"establishment";
261 $sql .=
" SET ref = '".$this->db->escape($this->
ref).
"'";
262 $sql .=
", label = '".$this->db->escape($this->label).
"'";
263 $sql .=
", address = '".$this->db->escape($this->
address).
"'";
264 $sql .=
", zip = '".$this->db->escape($this->zip).
"'";
265 $sql .=
", town = '".$this->db->escape($this->town).
"'";
266 $sql .=
", fk_country = ".($this->country_id > 0 ? ((int) $this->country_id) :
'null');
267 $sql .=
", status = ".((int) $this->
status);
268 $sql .=
", fk_user_mod = ".((int) $user->id);
269 $sql .=
", entity = ".((int) $this->entity);
270 $sql .=
" WHERE rowid = ".((int) $this->
id);
272 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
273 $result = $this->db->query($sql);
276 $triggerres = $this->call_trigger(
'ESTABLISHMENT_MODIFY', $user);
277 if ($triggerres < 0) {
278 $this->db->rollback();
286 $this->error = $this->db->lasterror();
287 $this->db->rollback();
300 $sql =
"SELECT e.rowid, e.ref, e.label, e.address, e.zip, e.town, e.status, e.fk_country as country_id, e.entity,";
301 $sql .=
' c.code as country_code, c.label as country';
302 $sql .=
" FROM ".MAIN_DB_PREFIX.
"establishment as e";
303 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_country as c ON e.fk_country = c.rowid';
304 $sql .=
" WHERE e.rowid = ".((int) $id);
306 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
307 $result = $this->db->query($sql);
309 $obj = $this->db->fetch_object($result);
311 $this->
id = $obj->rowid;
312 $this->
ref = $obj->ref;
313 $this->label = $obj->label;
314 $this->
address = $obj->address;
315 $this->zip = $obj->zip;
316 $this->town = $obj->town;
317 $this->
status = $obj->status;
318 $this->entity = $obj->entity;
320 $this->country_id = $obj->country_id;
321 $this->country_code = $obj->country_code;
322 $this->country = $obj->country;
329 $this->error = $this->db->lasterror();
389 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
392 $this->labelStatus[self::STATUS_OPEN] = $langs->transnoentitiesnoconv(
'Open');
393 $this->labelStatus[self::STATUS_CLOSED] = $langs->transnoentitiesnoconv(
'Closed');
394 $this->labelStatusShort[self::STATUS_OPEN] = $langs->transnoentitiesnoconv(
'Open');
395 $this->labelStatusShort[self::STATUS_CLOSED] = $langs->transnoentitiesnoconv(
'Closed');
398 $statusType =
'status'.$status;
399 if ($status == self::STATUS_OPEN) {
400 $statusType =
'status4';
402 if ($status == self::STATUS_CLOSED) {
403 $statusType =
'status6';
406 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
418 $sql =
'SELECT e.rowid, e.ref, e.datec, e.fk_user_author, e.tms as datem, e.fk_user_mod, e.entity';
419 $sql .=
' FROM '.MAIN_DB_PREFIX.
'establishment as e';
420 $sql .=
' WHERE e.rowid = '.((int) $id);
422 dol_syslog(get_class($this).
"::fetch info", LOG_DEBUG);
423 $result = $this->db->query($sql);
426 if ($this->db->num_rows($result)) {
427 $obj = $this->db->fetch_object($result);
429 $this->
id = $obj->rowid;
431 $this->user_creation_id = $obj->fk_user_author;
432 $this->user_modification_id = $obj->fk_user_mod;
433 $this->date_creation = $this->db->jdate($obj->datec);
434 $this->date_modification = empty($obj->datem) ?
'' : $this->db->jdate($obj->datem);
436 $this->db->free($result);
438 dol_print_error($this->db);
452 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
454 global
$conf, $langs, $hookmanager;
456 if (!empty(
$conf->dol_no_mouse_hover)) {
462 $label = img_picto(
'', $this->picto).
' <u>'.$langs->trans(
"Establishment").
'</u>';
463 if (isset($this->
status)) {
464 $label .=
' '.$this->getLibStatut(5);
467 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
470 $label .=
'<b>'.$langs->trans(
'Residence').
':</b> '.$this->
address.
', '.$this->zip.
' '.$this->town;
472 $url = DOL_URL_ROOT.
'/hrm/establishment/card.php?id='.$this->id;
474 if ($option !=
'nolink') {
476 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
477 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
478 $add_save_lastsearch_values = 1;
480 if ($add_save_lastsearch_values) {
481 $url .=
'&save_lastsearch_values=1';
486 if (empty($notooltip)) {
488 $label = $langs->trans(
"Establishment");
489 $linkclose .=
' alt="'.dolPrintHTMLForAttribute($label).
'"';
491 $linkclose .=
' title="'.dolPrintHTMLForAttribute($label).
'"';
492 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
494 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
497 if ($option ==
'nolink') {
498 $linkstart =
'<span';
500 $linkstart =
'<a href="'.$url.
'"';
502 $linkstart .= $linkclose.
'>';
503 if ($option ==
'nolink') {
504 $linkend =
'</span>';
509 $result .= $linkstart;
512 $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);
515 if ($withpicto != 2) {
516 $result .= $this->label;
522 global $action, $hookmanager;
523 $hookmanager->initHooks(array(
'establishmentdao'));
524 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
525 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
527 $result = $hookmanager->resPrint;
529 $result .= $hookmanager->resPrint;