27require_once DOL_DOCUMENT_ROOT.
'/core/class/commondict.class.php';
68 public $fields = array(
69 'label' => array(
'type' =>
'varchar(250)',
'label' =>
'Label',
'enabled' => 1,
'visible' => 1,
'position' => 15,
'notnull' => -1,
'showoncombobox' => 1)
91 public function create($user, $notrigger = 0)
96 if (isset($this->code)) {
97 $this->code = trim($this->code);
99 if (isset($this->code_iso)) {
100 $this->code_iso = trim($this->code_iso);
102 if (isset($this->label)) {
103 $this->label = trim($this->label);
105 if (isset($this->active)) {
106 $this->active = (int) $this->active;
113 $sql =
"INSERT INTO ".$this->db->prefix().
"c_country(";
119 $sql .=
") VALUES (";
120 $sql .=
" ".(!isset($this->rowid) ?
'NULL' :
"'".$this->db->escape($this->rowid).
"'").
",";
121 $sql .=
" ".(!isset($this->code) ?
'NULL' :
"'".$this->db->escape($this->code).
"'").
",";
122 $sql .=
" ".(!isset($this->code_iso) ?
'NULL' :
"'".$this->db->escape($this->code_iso).
"'").
",";
123 $sql .=
" ".(!isset($this->label) ?
'NULL' :
"'".$this->db->escape($this->label).
"'").
",";
124 $sql .=
" ".(!isset($this->active) ?
'NULL' :
"'".$this->db->escape((
string) $this->active).
"'");
129 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
130 $resql = $this->db->query($sql);
133 $this->errors[] =
"Error ".$this->db->lasterror();
137 $this->
id = $this->db->last_insert_id($this->db->prefix().
"c_country");
142 foreach ($this->errors as $errmsg) {
143 dol_syslog(get_class($this).
"::create ".$errmsg, LOG_ERR);
144 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
146 $this->db->rollback();
163 public function fetch($id, $code =
'', $code_iso =
'')
168 $sql .=
" t.code_iso,";
171 $sql .=
" t.active,";
172 $sql .=
" t.favorite,";
173 $sql .=
" t.numeric_code";
174 $sql .=
" FROM ".$this->db->prefix().
"c_country as t";
176 $sql .=
" WHERE t.rowid = ".((int) $id);
178 $sql .=
" WHERE t.code = '".$this->db->escape(strtoupper($code)).
"'";
179 } elseif ($code_iso) {
180 $sql .=
" WHERE t.code_iso = '".$this->db->escape(strtoupper($code_iso)).
"'";
183 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
185 $resql = $this->db->query($sql);
187 if ($this->db->num_rows($resql)) {
188 $obj = $this->db->fetch_object($resql);
191 $this->
id = $obj->rowid;
192 $this->code = $obj->code;
193 $this->code_iso = $obj->code_iso;
194 $this->label = $obj->label;
195 $this->eec = $obj->eec;
196 $this->active = $obj->active;
197 $this->favorite = $obj->favorite;
198 $this->numeric_code = $obj->numeric_code;
201 $this->db->free($resql);
207 $this->error =
"Error ".$this->db->lasterror();
220 public function update($user =
null, $notrigger = 0)
225 if (isset($this->code)) {
226 $this->code = trim($this->code);
228 if (isset($this->code_iso)) {
229 $this->code_iso = trim($this->code_iso);
231 if (isset($this->label)) {
232 $this->label = trim($this->label);
234 if (isset($this->active)) {
235 $this->active = (int) $this->active;
243 $sql =
"UPDATE ".$this->db->prefix().
"c_country SET";
244 $sql .=
" code=".(isset($this->code) ?
"'".$this->db->escape($this->code).
"'" :
"null").
",";
245 $sql .=
" code_iso=".(isset($this->code_iso) ?
"'".$this->db->escape($this->code_iso).
"'" :
"null").
",";
246 $sql .=
" label=".(isset($this->label) ?
"'".$this->db->escape($this->label).
"'" :
"null").
",";
247 $sql .=
" active=".(isset($this->active) ? $this->active :
"null");
248 $sql .=
" WHERE rowid=".((int) $this->
id);
252 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
253 $resql = $this->db->query($sql);
256 $this->errors[] =
"Error ".$this->db->lasterror();
261 foreach ($this->errors as $errmsg) {
262 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
263 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
265 $this->db->rollback();
281 public function delete($user, $notrigger = 0)
285 $sql =
"DELETE FROM ".$this->db->prefix().
"c_country";
286 $sql .=
" WHERE rowid=".((int) $this->
id);
290 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
291 $resql = $this->db->query($sql);
294 $this->errors[] =
"Error ".$this->db->lasterror();
299 foreach ($this->errors as $errmsg) {
300 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
301 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
303 $this->db->rollback();
321 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
324 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.