27require_once DOL_DOCUMENT_ROOT.
'/core/class/commondict.class.php';
79 public function create($user, $notrigger = 0)
85 if (isset($this->code_region)) {
86 $this->code_region = (int) $this->code_region;
88 if (isset($this->fk_pays)) {
89 $this->fk_pays = (int) $this->fk_pays;
91 if (isset($this->
name)) {
94 if (isset($this->cheflieu)) {
95 $this->cheflieu = trim($this->cheflieu);
97 if (isset($this->active)) {
98 $this->active = (int) $this->active;
105 $sql =
"INSERT INTO ".$this->db->prefix().
"c_regions(";
107 $sql .=
"code_region,";
112 $sql .=
") VALUES (";
113 $sql .=
" ".(!isset($this->
id) ?
'NULL' : (int) $this->
id).
",";
114 $sql .=
" ".(!isset($this->code_region) ?
'NULL' : (int) $this->code_region).
",";
115 $sql .=
" ".(!isset($this->fk_pays) ?
'NULL' : (int) $this->fk_pays).
",";
116 $sql .=
" ".(!isset($this->
name) ?
'NULL' :
"'".$this->db->escape($this->
name).
"'").
",";
117 $sql .=
" ".(!isset($this->cheflieu) ?
'NULL' :
"'".$this->db->escape($this->cheflieu).
"'").
",";
118 $sql .=
" ".(!isset($this->active) ?
'NULL' :
"'".$this->db->escape($this->active).
"'");
123 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
124 $resql = $this->db->query($sql);
127 $this->errors[] =
"Error ".$this->db->lasterror();
131 $this->
id = $this->db->last_insert_id($this->db->prefix().
"c_regions");
136 foreach ($this->errors as $errmsg) {
137 dol_syslog(get_class($this).
"::create ".$errmsg, LOG_ERR);
138 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
140 $this->db->rollback();
157 public function fetch($id, $code_region = 0, $fk_pays = 0)
161 $sql .=
" t.code_region,";
162 $sql .=
" t.fk_pays,";
164 $sql .=
" t.cheflieu,";
166 $sql .=
" FROM ".$this->db->prefix().
"c_regions as t";
168 $sql .=
" WHERE t.rowid = ".((int) $id);
169 } elseif ($code_region) {
170 $sql .=
" WHERE t.code_region = ".((int) $code_region);
171 } elseif ($fk_pays) {
172 $sql .=
" WHERE t.fk_pays = ".((int) $fk_pays);
175 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
176 $resql = $this->db->query($sql);
178 if ($this->db->num_rows($resql)) {
179 $obj = $this->db->fetch_object($resql);
182 $this->
id = $obj->rowid;
183 $this->code_region = (int) $obj->code_region;
184 $this->fk_pays = (int) $obj->fk_pays;
185 $this->
name = $obj->nom;
186 $this->cheflieu = $obj->cheflieu;
187 $this->active = $obj->active;
190 $this->db->free($resql);
196 $this->error =
"Error ".$this->db->lasterror();
209 public function update($user =
null, $notrigger = 0)
211 global
$conf, $langs;
215 if (isset($this->code_region)) {
216 $this->code_region = (int) $this->code_region;
218 if (isset($this->fk_pays)) {
219 $this->fk_pays = (int) $this->fk_pays;
221 if (isset($this->
name)) {
224 if (isset($this->cheflieu)) {
225 $this->cheflieu = trim($this->cheflieu);
227 if (isset($this->active)) {
228 $this->active = (int) $this->active;
236 $sql =
"UPDATE ".$this->db->prefix().
"c_regions SET";
237 $sql .=
" code_region=".(isset($this->code_region) ? ((int) $this->code_region) :
"null").
",";
238 $sql .=
" fk_pays=".(isset($this->fk_pays) ? ((int) $this->fk_pays) :
"null").
",";
239 $sql .=
" nom=".(isset($this->
name) ?
"'".$this->db->escape($this->
name).
"'" :
"null").
",";
240 $sql .=
" cheflieu=".(isset($this->cheflieu) ?
"'".$this->db->escape($this->cheflieu).
"'" :
"null").
",";
241 $sql .=
" active=".(isset($this->active) ? $this->active :
"null");
242 $sql .=
" WHERE rowid=".((int) $this->
id);
246 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
247 $resql = $this->db->query($sql);
250 $this->errors[] =
"Error ".$this->db->lasterror();
255 foreach ($this->errors as $errmsg) {
256 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
257 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
259 $this->db->rollback();
275 public function delete($user, $notrigger = 0)
277 global
$conf, $langs;
280 $sql =
"DELETE FROM ".$this->db->prefix().
"c_regions";
281 $sql .=
" WHERE rowid=".((int) $this->
id);
285 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
286 $resql = $this->db->query($sql);
289 $this->errors[] =
"Error ".$this->db->lasterror();
294 foreach ($this->errors as $errmsg) {
295 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
296 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
298 $this->db->rollback();
316 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
319 return $langs->trans($this->
name);
Parent class of all other dictionary classes.
Class to manage dictionary Regions.
create($user, $notrigger=0)
Create object into database.
update($user=null, $notrigger=0)
Update object into database.
fetch($id, $code_region=0, $fk_pays=0)
Load object in memory from database.
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return a link to the object card (with optionally the picto)
__construct($db)
Constructor.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
$conf db name
Only used if Module[ID]Name translation string is not found.