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 'label' => array(
'type' =>
'varchar(250)',
'label' =>
'Label',
'enabled' => 1,
'visible' => 1,
'position' => 15,
'notnull' => -1,
'showoncombobox' => 1)
104 public function create($user, $notrigger = 0)
107 if (empty($this->
id)) {
111 if (isset($this->code)) {
112 $this->code = trim($this->code);
114 if (isset($this->code_iso)) {
115 $this->code_iso = trim($this->code_iso);
117 if (isset($this->label)) {
118 $this->label = trim($this->label);
120 if (isset($this->
active)) {
128 $sql =
"INSERT INTO ".$this->db->prefix().
"c_country(";
134 $sql .=
") VALUES (";
135 $sql .= (int) $this->
id;
136 $sql .=
", ".(!isset($this->code) ?
'NULL' :
"'".$this->db->escape($this->code).
"'");
137 $sql .=
", ".(!isset($this->code_iso) ?
'NULL' :
"'".$this->db->escape($this->code_iso).
"'");
138 $sql .=
", ".(!isset($this->label) ?
'NULL' :
"'".$this->db->escape($this->label).
"'");
139 $sql .=
", ".(!isset($this->
active) ?
'NULL' :
"'".$this->db->escape((
string) $this->
active).
"'");
144 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
145 $resql = $this->db->query($sql);
148 $this->errors[] =
"Error ".$this->db->lasterror();
152 $this->
id = $this->db->last_insert_id($this->db->prefix().
"c_country");
157 foreach ($this->errors as $errmsg) {
158 dol_syslog(get_class($this).
"::create ".$errmsg, LOG_ERR);
159 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
161 $this->db->rollback();
178 public function fetch($id, $code =
'', $code_iso =
'')
183 $sql .=
" t.code_iso,";
186 $sql .=
" t.active,";
187 $sql .=
" t.favorite,";
188 $sql .=
" t.numeric_code,";
189 $sql .=
" t.phone_code,";
190 $sql .=
" t.trunk_prefix";
191 $sql .=
" FROM ".$this->db->prefix().
"c_country as t";
193 $sql .=
" WHERE t.rowid = ".((int) $id);
195 $sql .=
" WHERE t.code = '".$this->db->escape(strtoupper($code)).
"'";
196 } elseif ($code_iso) {
197 $sql .=
" WHERE t.code_iso = '".$this->db->escape(strtoupper($code_iso)).
"'";
200 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
202 $resql = $this->db->query($sql);
204 if ($this->db->num_rows($resql)) {
205 $obj = $this->db->fetch_object($resql);
208 $this->
id = (int) $obj->rowid;
209 $this->code = $obj->code;
210 $this->code_iso = $obj->code_iso;
211 $this->label = $obj->label;
212 $this->eec = $obj->eec;
213 $this->
active = (int) $obj->active;
214 $this->favorite = $obj->favorite;
215 $this->numeric_code = $obj->numeric_code;
216 $this->phone_code = $obj->phone_code;
217 $this->trunk_prefix = $obj->trunk_prefix;
220 $this->db->free($resql);
226 $this->error =
"Error ".$this->db->lasterror();
239 public function update($user =
null, $notrigger = 0)
244 if (isset($this->code)) {
245 $this->code = trim($this->code);
247 if (isset($this->code_iso)) {
248 $this->code_iso = trim($this->code_iso);
250 if (isset($this->label)) {
251 $this->label = trim($this->label);
253 if (isset($this->
active)) {
262 $sql =
"UPDATE ".$this->db->prefix().
"c_country SET";
263 $sql .=
" code=".(isset($this->code) ?
"'".$this->db->escape($this->code).
"'" :
"null").
",";
264 $sql .=
" code_iso=".(isset($this->code_iso) ?
"'".$this->db->escape($this->code_iso).
"'" :
"null").
",";
265 $sql .=
" label=".(isset($this->label) ?
"'".$this->db->escape($this->label).
"'" :
"null").
",";
266 $sql .=
" active=".(isset($this->
active) ? $this->
active :
"null");
267 $sql .=
" WHERE rowid=".((int) $this->
id);
271 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
272 $resql = $this->db->query($sql);
275 $this->errors[] =
"Error ".$this->db->lasterror();
280 foreach ($this->errors as $errmsg) {
281 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
282 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
284 $this->db->rollback();
300 public function delete($user, $notrigger = 0)
304 $sql =
"DELETE FROM ".$this->db->prefix().
"c_country";
305 $sql .=
" WHERE rowid=".((int) $this->
id);
309 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
310 $resql = $this->db->query($sql);
313 $this->errors[] =
"Error ".$this->db->lasterror();
318 foreach ($this->errors as $errmsg) {
319 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
320 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
322 $this->db->rollback();
340 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
343 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.