28require_once DOL_DOCUMENT_ROOT.
'/core/class/commondict.class.php';
69 public $fields = array(
70 'label' => array(
'type' =>
'varchar(250)',
'label' =>
'Label',
'enabled' => 1,
'visible' => 1,
'position' => 15,
'notnull' => -1,
'showoncombobox' => 1)
92 public function create($user, $notrigger = 0)
95 if (empty($this->
id)) {
99 if (isset($this->code)) {
100 $this->code = trim($this->code);
102 if (isset($this->code_iso)) {
103 $this->code_iso = trim($this->code_iso);
105 if (isset($this->label)) {
106 $this->label = trim($this->label);
108 if (isset($this->
active)) {
116 $sql =
"INSERT INTO ".$this->db->prefix().
"c_country(";
122 $sql .=
") VALUES (";
123 $sql .= (int) $this->
id;
124 $sql .=
", ".(!isset($this->code) ?
'NULL' :
"'".$this->db->escape($this->code).
"'");
125 $sql .=
", ".(!isset($this->code_iso) ?
'NULL' :
"'".$this->db->escape($this->code_iso).
"'");
126 $sql .=
", ".(!isset($this->label) ?
'NULL' :
"'".$this->db->escape($this->label).
"'");
127 $sql .=
", ".(!isset($this->
active) ?
'NULL' :
"'".$this->db->escape((
string) $this->
active).
"'");
132 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
133 $resql = $this->db->query($sql);
136 $this->errors[] =
"Error ".$this->db->lasterror();
140 $this->
id = $this->db->last_insert_id($this->db->prefix().
"c_country");
145 foreach ($this->errors as $errmsg) {
146 dol_syslog(get_class($this).
"::create ".$errmsg, LOG_ERR);
147 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
149 $this->db->rollback();
166 public function fetch($id, $code =
'', $code_iso =
'')
171 $sql .=
" t.code_iso,";
174 $sql .=
" t.active,";
175 $sql .=
" t.favorite,";
176 $sql .=
" t.numeric_code";
177 $sql .=
" FROM ".$this->db->prefix().
"c_country as t";
179 $sql .=
" WHERE t.rowid = ".((int) $id);
181 $sql .=
" WHERE t.code = '".$this->db->escape(strtoupper($code)).
"'";
182 } elseif ($code_iso) {
183 $sql .=
" WHERE t.code_iso = '".$this->db->escape(strtoupper($code_iso)).
"'";
186 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
188 $resql = $this->db->query($sql);
190 if ($this->db->num_rows($resql)) {
191 $obj = $this->db->fetch_object($resql);
194 $this->
id = (int) $obj->rowid;
195 $this->code = $obj->code;
196 $this->code_iso = $obj->code_iso;
197 $this->label = $obj->label;
198 $this->eec = $obj->eec;
199 $this->
active = (int) $obj->active;
200 $this->favorite = $obj->favorite;
201 $this->numeric_code = $obj->numeric_code;
204 $this->db->free($resql);
210 $this->error =
"Error ".$this->db->lasterror();
223 public function update($user =
null, $notrigger = 0)
228 if (isset($this->code)) {
229 $this->code = trim($this->code);
231 if (isset($this->code_iso)) {
232 $this->code_iso = trim($this->code_iso);
234 if (isset($this->label)) {
235 $this->label = trim($this->label);
237 if (isset($this->
active)) {
246 $sql =
"UPDATE ".$this->db->prefix().
"c_country SET";
247 $sql .=
" code=".(isset($this->code) ?
"'".$this->db->escape($this->code).
"'" :
"null").
",";
248 $sql .=
" code_iso=".(isset($this->code_iso) ?
"'".$this->db->escape($this->code_iso).
"'" :
"null").
",";
249 $sql .=
" label=".(isset($this->label) ?
"'".$this->db->escape($this->label).
"'" :
"null").
",";
250 $sql .=
" active=".(isset($this->
active) ? $this->
active :
"null");
251 $sql .=
" WHERE rowid=".((int) $this->
id);
255 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
256 $resql = $this->db->query($sql);
259 $this->errors[] =
"Error ".$this->db->lasterror();
264 foreach ($this->errors as $errmsg) {
265 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
266 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
268 $this->db->rollback();
284 public function delete($user, $notrigger = 0)
288 $sql =
"DELETE FROM ".$this->db->prefix().
"c_country";
289 $sql .=
" WHERE rowid=".((int) $this->
id);
293 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
294 $resql = $this->db->query($sql);
297 $this->errors[] =
"Error ".$this->db->lasterror();
302 foreach ($this->errors as $errmsg) {
303 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
304 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
306 $this->db->rollback();
324 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
327 return $langs->trans($this->label);
Class to manage dictionary Countries (used by imports)
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return a link to the object card (with optionally the picto)
create($user, $notrigger=0)
Create object into database.
$table_element
Name of table without prefix where object is stored.
__construct($db)
Constructor.
update($user=null, $notrigger=0)
Update object into database.
$element
Id that identify managed objects.
fetch($id, $code='', $code_iso='')
Load object in memory from database.
Parent class of all other dictionary classes.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.