29require_once DOL_DOCUMENT_ROOT.
'/core/class/commondict.class.php';
30require_once DOL_DOCUMENT_ROOT.
'/core/class/cstate.class.php';
31require_once DOL_DOCUMENT_ROOT.
'/core/class/cregion.class.php';
81 public $fields = array(
82 'code' => array(
'type' =>
'varchar(2)',
'label' =>
'CountryCode',
'enabled' => 1,
'visible' => 1,
'position' => 10,
'notnull' => 1),
83 'label' => array(
'type' =>
'varchar(250)',
'label' =>
'Label',
'enabled' => 1,
'visible' => 1,
'position' => 15,
'notnull' => -1,
'showoncombobox' => 1)
105 public function create($user, $notrigger = 0)
108 if (empty($this->
id)) {
112 if (isset($this->code)) {
113 $this->code = trim($this->code);
115 if (isset($this->code_iso)) {
116 $this->code_iso = trim($this->code_iso);
118 if (isset($this->label)) {
119 $this->label = trim($this->label);
121 if (isset($this->
active)) {
129 $sql =
"INSERT INTO ".$this->db->prefix().
"c_country(";
135 $sql .=
") VALUES (";
136 $sql .= (int) $this->
id;
137 $sql .=
", ".(!isset($this->code) ?
'NULL' :
"'".$this->db->escape($this->code).
"'");
138 $sql .=
", ".(!isset($this->code_iso) ?
'NULL' :
"'".$this->db->escape($this->code_iso).
"'");
139 $sql .=
", ".(!isset($this->label) ?
'NULL' :
"'".$this->db->escape($this->label).
"'");
140 $sql .=
", ".(!isset($this->
active) ?
'NULL' :
"'".$this->db->escape((
string) $this->
active).
"'");
145 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
146 $resql = $this->db->query($sql);
149 $this->errors[] =
"Error ".$this->db->lasterror();
156 foreach ($this->errors as $errmsg) {
157 dol_syslog(get_class($this).
"::create ".$errmsg, LOG_ERR);
158 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
160 $this->db->rollback();
177 public function fetch($id, $code =
'', $code_iso =
'')
182 $sql .=
" t.code_iso,";
185 $sql .=
" t.active,";
186 $sql .=
" t.favorite,";
187 $sql .=
" t.numeric_code,";
188 $sql .=
" t.phone_code,";
189 $sql .=
" t.trunk_prefix";
190 $sql .=
" FROM ".$this->db->prefix().
"c_country as t";
192 $sql .=
" WHERE t.rowid = ".((int) $id);
194 $sql .=
" WHERE t.code = '".$this->db->escape(strtoupper($code)).
"'";
195 } elseif ($code_iso) {
196 $sql .=
" WHERE t.code_iso = '".$this->db->escape(strtoupper($code_iso)).
"'";
199 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
201 $resql = $this->db->query($sql);
203 if ($this->db->num_rows($resql)) {
204 $obj = $this->db->fetch_object($resql);
207 $this->
id = (int) $obj->rowid;
208 $this->code = $obj->code;
209 $this->code_iso = $obj->code_iso;
210 $this->label = $obj->label;
211 $this->eec = $obj->eec;
212 $this->
active = (int) $obj->active;
213 $this->favorite = $obj->favorite;
214 $this->numeric_code = $obj->numeric_code;
215 $this->phone_code = $obj->phone_code;
216 $this->trunk_prefix = $obj->trunk_prefix;
219 $this->db->free($resql);
225 $this->error =
"Error ".$this->db->lasterror();
238 public function update($user =
null, $notrigger = 0)
243 if (isset($this->code)) {
244 $this->code = trim($this->code);
246 if (isset($this->code_iso)) {
247 $this->code_iso = trim($this->code_iso);
249 if (isset($this->label)) {
250 $this->label = trim($this->label);
252 if (isset($this->
active)) {
261 $sql =
"UPDATE ".$this->db->prefix().
"c_country SET";
262 $sql .=
" code=".(isset($this->code) ?
"'".$this->db->escape($this->code).
"'" :
"null").
",";
263 $sql .=
" code_iso=".(isset($this->code_iso) ?
"'".$this->db->escape($this->code_iso).
"'" :
"null").
",";
264 $sql .=
" label=".(isset($this->label) ?
"'".$this->db->escape($this->label).
"'" :
"null").
",";
265 $sql .=
" active=".(isset($this->
active) ? ((int) $this->
active) :
"null");
266 $sql .=
" WHERE rowid=".((int) $this->
id);
270 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
271 $resql = $this->db->query($sql);
274 $this->errors[] =
"Error ".$this->db->lasterror();
279 foreach ($this->errors as $errmsg) {
280 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
281 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
283 $this->db->rollback();
299 public function delete($user, $notrigger = 0)
303 $sql =
"DELETE FROM ".$this->db->prefix().
"c_country";
304 $sql .=
" WHERE rowid=".((int) $this->
id);
308 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
309 $resql = $this->db->query($sql);
312 $this->errors[] =
"Error ".$this->db->lasterror();
317 foreach ($this->errors as $errmsg) {
318 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
319 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
321 $this->db->rollback();
339 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
342 return $langs->trans($this->label);
Class to manage dictionary Countries (used by imports)
__construct($db)
Constructor.
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.