26require_once DOL_DOCUMENT_ROOT.
'/core/class/commondict.class.php';
51 public $fields = array(
52 'label' => array(
'type' =>
'varchar(250)',
'label' =>
'Label',
'enabled' => 1,
'visible' => 1,
'position' => 15,
'notnull' => -1,
'showoncombobox' => 1)
74 public function create($user, $notrigger = 0)
79 if (isset($this->code)) {
80 $this->code = trim($this->code);
82 if (isset($this->code_iso)) {
83 $this->code_iso = trim($this->code_iso);
85 if (isset($this->label)) {
86 $this->label = trim($this->label);
88 if (isset($this->active)) {
89 $this->active = (int) $this->active;
96 $sql =
"INSERT INTO ".$this->db->prefix().
"c_country(";
102 $sql .=
") VALUES (";
103 $sql .=
" ".(!isset($this->rowid) ?
'NULL' :
"'".$this->db->escape($this->rowid).
"'").
",";
104 $sql .=
" ".(!isset($this->code) ?
'NULL' :
"'".$this->db->escape($this->code).
"'").
",";
105 $sql .=
" ".(!isset($this->code_iso) ?
'NULL' :
"'".$this->db->escape($this->code_iso).
"'").
",";
106 $sql .=
" ".(!isset($this->label) ?
'NULL' :
"'".$this->db->escape($this->label).
"'").
",";
107 $sql .=
" ".(!isset($this->active) ?
'NULL' :
"'".$this->db->escape($this->active).
"'");
112 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
113 $resql = $this->db->query($sql);
116 $this->errors[] =
"Error ".$this->db->lasterror();
120 $this->
id = $this->db->last_insert_id($this->db->prefix().
"c_country");
125 foreach ($this->errors as $errmsg) {
126 dol_syslog(get_class($this).
"::create ".$errmsg, LOG_ERR);
127 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
129 $this->db->rollback();
146 public function fetch($id, $code =
'', $code_iso =
'')
151 $sql .=
" t.code_iso,";
154 $sql .=
" FROM ".$this->db->prefix().
"c_country as t";
156 $sql .=
" WHERE t.rowid = ".((int) $id);
158 $sql .=
" WHERE t.code = '".$this->db->escape(strtoupper($code)).
"'";
159 } elseif ($code_iso) {
160 $sql .=
" WHERE t.code_iso = '".$this->db->escape(strtoupper($code_iso)).
"'";
163 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
164 $resql = $this->db->query($sql);
166 if ($this->db->num_rows($resql)) {
167 $obj = $this->db->fetch_object($resql);
170 $this->
id = $obj->rowid;
171 $this->code = $obj->code;
172 $this->code_iso = $obj->code_iso;
173 $this->label = $obj->label;
174 $this->active = $obj->active;
177 $this->db->free($resql);
183 $this->error =
"Error ".$this->db->lasterror();
196 public function update($user =
null, $notrigger = 0)
201 if (isset($this->code)) {
202 $this->code = trim($this->code);
204 if (isset($this->code_iso)) {
205 $this->code_iso = trim($this->code_iso);
207 if (isset($this->label)) {
208 $this->label = trim($this->label);
210 if (isset($this->active)) {
211 $this->active = (int) $this->active;
219 $sql =
"UPDATE ".$this->db->prefix().
"c_country SET";
220 $sql .=
" code=".(isset($this->code) ?
"'".$this->db->escape($this->code).
"'" :
"null").
",";
221 $sql .=
" code_iso=".(isset($this->code_iso) ?
"'".$this->db->escape($this->code_iso).
"'" :
"null").
",";
222 $sql .=
" label=".(isset($this->label) ?
"'".$this->db->escape($this->label).
"'" :
"null").
",";
223 $sql .=
" active=".(isset($this->active) ? $this->active :
"null");
224 $sql .=
" WHERE rowid=".((int) $this->
id);
228 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
229 $resql = $this->db->query($sql);
232 $this->errors[] =
"Error ".$this->db->lasterror();
237 foreach ($this->errors as $errmsg) {
238 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
239 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
241 $this->db->rollback();
257 public function delete($user, $notrigger = 0)
261 $sql =
"DELETE FROM ".$this->db->prefix().
"c_country";
262 $sql .=
" WHERE rowid=".((int) $this->
id);
266 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
267 $resql = $this->db->query($sql);
270 $this->errors[] =
"Error ".$this->db->lasterror();
275 foreach ($this->errors as $errmsg) {
276 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
277 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
279 $this->db->rollback();
297 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
300 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.