28require_once DOL_DOCUMENT_ROOT.
'/core/class/commondict.class.php';
80 public function create($user, $notrigger = 0)
86 if (isset($this->code_region)) {
87 $this->code_region = (int) $this->code_region;
89 if (isset($this->fk_pays)) {
90 $this->fk_pays = (int) $this->fk_pays;
92 if (isset($this->
name)) {
93 $this->
name = trim((
string) $this->
name);
95 if (isset($this->cheflieu)) {
96 $this->cheflieu = trim((
string) $this->cheflieu);
98 if (isset($this->
active)) {
106 $sql =
"INSERT INTO ".$this->db->prefix().
"c_regions(";
108 $sql .=
"code_region,";
113 $sql .=
") VALUES (";
114 $sql .= (int) $this->
id;
115 $sql .=
", " . (!isset($this->code_region) ?
'NULL' : (int) $this->code_region);
116 $sql .=
", " . (int) $this->fk_pays;
117 $sql .=
", " . (!isset($this->
name) ?
'NULL' :
"'".$this->db->escape($this->
name) .
"'");
118 $sql .=
", " . (!isset($this->cheflieu) ?
'NULL' :
"'".$this->db->escape($this->cheflieu) .
"'");
119 $sql .=
", " . (int) $this->
active;
124 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
125 $resql = $this->db->query($sql);
128 $this->errors[] =
"Error ".$this->db->lasterror();
132 $this->
id = $this->db->last_insert_id($this->db->prefix().
"c_regions");
137 foreach ($this->errors as $errmsg) {
138 dol_syslog(get_class($this).
"::create ".$errmsg, LOG_ERR);
139 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
141 $this->db->rollback();
158 public function fetch($id, $code_region = 0, $fk_pays = 0)
162 $sql .=
" t.code_region,";
163 $sql .=
" t.fk_pays,";
164 $sql .=
" t.nom as name,";
165 $sql .=
" t.cheflieu,";
167 $sql .=
" FROM ".$this->db->prefix().
"c_regions as t";
169 $sql .=
" WHERE t.rowid = ".((int) $id);
170 } elseif ($code_region) {
171 $sql .=
" WHERE t.code_region = ".((int) $code_region);
172 } elseif ($fk_pays) {
173 $sql .=
" WHERE t.fk_pays = ".((int) $fk_pays);
176 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
177 $resql = $this->db->query($sql);
179 if ($this->db->num_rows($resql)) {
180 $obj = $this->db->fetch_object($resql);
183 $this->
id = $obj->rowid;
184 $this->code_region = (int) $obj->code_region;
185 $this->fk_pays = (int) $obj->fk_pays;
186 $this->
name = $obj->name;
187 $this->cheflieu = $obj->cheflieu;
188 $this->
active = (int) $obj->active;
191 $this->db->free($resql);
197 $this->error =
"Error ".$this->db->lasterror();
210 public function update($user =
null, $notrigger = 0)
212 global $conf, $langs;
216 if (isset($this->code_region)) {
217 $this->code_region = (int) $this->code_region;
219 if (isset($this->fk_pays)) {
220 $this->fk_pays = (int) $this->fk_pays;
222 if (isset($this->
name)) {
225 if (isset($this->cheflieu)) {
226 $this->cheflieu = trim($this->cheflieu);
228 if (isset($this->
active)) {
237 $sql =
"UPDATE ".$this->db->prefix().
"c_regions SET";
238 $sql .=
" code_region=".(isset($this->code_region) ? ((int) $this->code_region) :
"null").
",";
239 $sql .=
" fk_pays=".(isset($this->fk_pays) ? ((int) $this->fk_pays) :
"null").
",";
240 $sql .=
" nom=".(isset($this->
name) ?
"'".$this->db->escape($this->
name).
"'" :
"null").
",";
241 $sql .=
" cheflieu=".(isset($this->cheflieu) ?
"'".$this->db->escape($this->cheflieu).
"'" :
"null").
",";
242 $sql .=
" active=".(isset($this->
active) ? $this->
active :
"null");
243 $sql .=
" WHERE rowid=".((int) $this->
id);
247 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
248 $resql = $this->db->query($sql);
251 $this->errors[] =
"Error ".$this->db->lasterror();
256 foreach ($this->errors as $errmsg) {
257 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
258 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
260 $this->db->rollback();
276 public function delete($user, $notrigger = 0)
278 global $conf, $langs;
281 $sql =
"DELETE FROM ".$this->db->prefix().
"c_regions";
282 $sql .=
" WHERE rowid=".((int) $this->
id);
286 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
287 $resql = $this->db->query($sql);
290 $this->errors[] =
"Error ".$this->db->lasterror();
295 foreach ($this->errors as $errmsg) {
296 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
297 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
299 $this->db->rollback();
317 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
320 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.
$conf db name
Only used if Module[ID]Name translation string is not found.