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();
340 public function delete($user)
343 $sql =
"SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX.
"user WHERE fk_establishment = ".((int) $this->
id);
344 $resql = $this->db->query($sql);
346 $this->error = $this->db->lasterror();
349 $obj = $this->db->fetch_object($resql);
350 if ($obj && $obj->nb > 0) {
351 $this->error =
'ErrorRecordHasChildren';
357 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"establishment WHERE rowid = ".((int) $this->
id);
359 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
361 $result = $this->db->query($sql);
364 $triggerres = $this->call_trigger(
'ESTABLISHMENT_DELETE', $user);
365 if ($triggerres < 0) {
366 $this->db->rollback();
374 $this->error = $this->db->lasterror();
375 $this->db->rollback();
402 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
405 $this->labelStatus[self::STATUS_OPEN] = $langs->transnoentitiesnoconv(
'Open');
406 $this->labelStatus[self::STATUS_CLOSED] = $langs->transnoentitiesnoconv(
'Closed');
407 $this->labelStatusShort[self::STATUS_OPEN] = $langs->transnoentitiesnoconv(
'Open');
408 $this->labelStatusShort[self::STATUS_CLOSED] = $langs->transnoentitiesnoconv(
'Closed');
411 $statusType =
'status'.$status;
412 if ($status == self::STATUS_OPEN) {
413 $statusType =
'status4';
415 if ($status == self::STATUS_CLOSED) {
416 $statusType =
'status6';
419 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
431 $sql =
'SELECT e.rowid, e.ref, e.datec, e.fk_user_author, e.tms as datem, e.fk_user_mod, e.entity';
432 $sql .=
' FROM '.MAIN_DB_PREFIX.
'establishment as e';
433 $sql .=
' WHERE e.rowid = '.((int) $id);
435 dol_syslog(get_class($this).
"::fetch info", LOG_DEBUG);
436 $result = $this->db->query($sql);
439 if ($this->db->num_rows($result)) {
440 $obj = $this->db->fetch_object($result);
442 $this->
id = $obj->rowid;
444 $this->user_creation_id = $obj->fk_user_author;
445 $this->user_modification_id = $obj->fk_user_mod;
446 $this->date_creation = $this->db->jdate($obj->datec);
447 $this->date_modification = empty($obj->datem) ?
'' : $this->db->jdate($obj->datem);
449 $this->db->free($result);
451 dol_print_error($this->db);
465 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
467 global
$conf, $langs, $hookmanager;
469 if (!empty(
$conf->dol_no_mouse_hover)) {
475 $label = img_picto(
'', $this->picto).
' <u>'.$langs->trans(
"Establishment").
'</u>';
476 if (isset($this->
status)) {
477 $label .=
' '.$this->getLibStatut(5);
480 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
483 $label .=
'<b>'.$langs->trans(
'Residence').
':</b> '.$this->
address.
', '.$this->zip.
' '.$this->town;
485 $url = DOL_URL_ROOT.
'/hrm/establishment/card.php?id='.$this->id;
487 if ($option !=
'nolink') {
489 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
490 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
491 $add_save_lastsearch_values = 1;
493 if ($add_save_lastsearch_values) {
494 $url .=
'&save_lastsearch_values=1';
499 if (empty($notooltip)) {
501 $label = $langs->trans(
"Establishment");
502 $linkclose .=
' alt="'.dolPrintHTMLForAttribute($label).
'"';
504 $linkclose .=
' title="'.dolPrintHTMLForAttribute($label).
'"';
505 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
507 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
510 if ($option ==
'nolink') {
511 $linkstart =
'<span';
513 $linkstart =
'<a href="'.$url.
'"';
515 $linkstart .= $linkclose.
'>';
516 if ($option ==
'nolink') {
517 $linkend =
'</span>';
522 $result .= $linkstart;
525 $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);
528 if ($withpicto != 2) {
529 $result .= $this->label;
535 global $action, $hookmanager;
536 $hookmanager->initHooks(array(
'establishmentdao'));
537 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
538 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
540 $result = $hookmanager->resPrint;
542 $result .= $hookmanager->resPrint;