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)
89 public function create($user, $notrigger = 0)
94 if (isset($this->code)) {
95 $this->code = trim($this->code);
97 if (isset($this->code_iso)) {
98 $this->code_iso = trim($this->code_iso);
100 if (isset($this->label)) {
101 $this->label = trim($this->label);
103 if (isset($this->active)) {
104 $this->active = (int) $this->active;
111 $sql =
"INSERT INTO ".$this->db->prefix().
"c_country(";
117 $sql .=
") VALUES (";
118 $sql .=
" ".(!isset($this->rowid) ?
'NULL' :
"'".$this->db->escape($this->rowid).
"'").
",";
119 $sql .=
" ".(!isset($this->code) ?
'NULL' :
"'".$this->db->escape($this->code).
"'").
",";
120 $sql .=
" ".(!isset($this->code_iso) ?
'NULL' :
"'".$this->db->escape($this->code_iso).
"'").
",";
121 $sql .=
" ".(!isset($this->label) ?
'NULL' :
"'".$this->db->escape($this->label).
"'").
",";
122 $sql .=
" ".(!isset($this->active) ?
'NULL' :
"'".$this->db->escape($this->active).
"'");
127 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
128 $resql = $this->db->query($sql);
131 $this->errors[] =
"Error ".$this->db->lasterror();
135 $this->
id = $this->db->last_insert_id($this->db->prefix().
"c_country");
140 foreach ($this->errors as $errmsg) {
141 dol_syslog(get_class($this).
"::create ".$errmsg, LOG_ERR);
142 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
144 $this->db->rollback();
161 public function fetch($id, $code =
'', $code_iso =
'')
166 $sql .=
" t.code_iso,";
169 $sql .=
" t.active,";
170 $sql .=
" t.favorite,";
171 $sql .=
" t.numeric_code";
172 $sql .=
" FROM ".$this->db->prefix().
"c_country as t";
174 $sql .=
" WHERE t.rowid = ".((int) $id);
176 $sql .=
" WHERE t.code = '".$this->db->escape(strtoupper($code)).
"'";
177 } elseif ($code_iso) {
178 $sql .=
" WHERE t.code_iso = '".$this->db->escape(strtoupper($code_iso)).
"'";
181 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
183 $resql = $this->db->query($sql);
185 if ($this->db->num_rows($resql)) {
186 $obj = $this->db->fetch_object($resql);
189 $this->
id = $obj->rowid;
190 $this->code = $obj->code;
191 $this->code_iso = $obj->code_iso;
192 $this->label = $obj->label;
193 $this->active = $obj->active;
194 $this->favorite = $obj->favorite;
195 $this->eec = $obj->eec;
196 $this->numeric_code = $obj->numeric_code;
199 $this->db->free($resql);
205 $this->error =
"Error ".$this->db->lasterror();
218 public function update($user =
null, $notrigger = 0)
223 if (isset($this->code)) {
224 $this->code = trim($this->code);
226 if (isset($this->code_iso)) {
227 $this->code_iso = trim($this->code_iso);
229 if (isset($this->label)) {
230 $this->label = trim($this->label);
232 if (isset($this->active)) {
233 $this->active = (int) $this->active;
241 $sql =
"UPDATE ".$this->db->prefix().
"c_country SET";
242 $sql .=
" code=".(isset($this->code) ?
"'".$this->db->escape($this->code).
"'" :
"null").
",";
243 $sql .=
" code_iso=".(isset($this->code_iso) ?
"'".$this->db->escape($this->code_iso).
"'" :
"null").
",";
244 $sql .=
" label=".(isset($this->label) ?
"'".$this->db->escape($this->label).
"'" :
"null").
",";
245 $sql .=
" active=".(isset($this->active) ? $this->active :
"null");
246 $sql .=
" WHERE rowid=".((int) $this->
id);
250 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
251 $resql = $this->db->query($sql);
254 $this->errors[] =
"Error ".$this->db->lasterror();
259 foreach ($this->errors as $errmsg) {
260 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
261 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
263 $this->db->rollback();
279 public function delete($user, $notrigger = 0)
283 $sql =
"DELETE FROM ".$this->db->prefix().
"c_country";
284 $sql .=
" WHERE rowid=".((int) $this->
id);
288 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
289 $resql = $this->db->query($sql);
292 $this->errors[] =
"Error ".$this->db->lasterror();
297 foreach ($this->errors as $errmsg) {
298 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
299 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
301 $this->db->rollback();
319 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
322 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.