25require_once DOL_DOCUMENT_ROOT.
'/core/class/commondict.class.php';
38 public $fields = array(
39 'label' => array(
'type'=>
'varchar(250)',
'label'=>
'Label',
'enabled'=>1,
'visible'=>1,
'position'=>15,
'notnull'=>-1,
'showoncombobox'=>
'1')
61 public function create($user, $notrigger = 0)
66 if (isset($this->code)) {
67 $this->code = trim($this->code);
69 if (isset($this->code_iso)) {
70 $this->code_iso = trim($this->code_iso);
72 if (isset($this->label)) {
73 $this->label = trim($this->label);
75 if (isset($this->active)) {
76 $this->active = trim($this->active);
83 $sql =
"INSERT INTO ".$this->db->prefix().
"c_country(";
90 $sql .=
" ".(!isset($this->
rowid) ?
'NULL' :
"'".$this->db->escape($this->
rowid).
"'").
",";
91 $sql .=
" ".(!isset($this->code) ?
'NULL' :
"'".$this->db->escape($this->code).
"'").
",";
92 $sql .=
" ".(!isset($this->code_iso) ?
'NULL' :
"'".$this->db->escape($this->code_iso).
"'").
",";
93 $sql .=
" ".(!isset($this->label) ?
'NULL' :
"'".$this->db->escape($this->label).
"'").
",";
94 $sql .=
" ".(!isset($this->active) ?
'NULL' :
"'".$this->db->escape($this->active).
"'");
99 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
100 $resql = $this->db->query($sql);
103 $this->errors[] =
"Error ".$this->db->lasterror();
107 $this->
id = $this->db->last_insert_id($this->db->prefix().
"c_country");
112 foreach ($this->errors as $errmsg) {
113 dol_syslog(get_class($this).
"::create ".$errmsg, LOG_ERR);
114 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
116 $this->db->rollback();
133 public function fetch($id, $code =
'', $code_iso =
'')
138 $sql .=
" t.code_iso,";
141 $sql .=
" FROM ".$this->db->prefix().
"c_country as t";
143 $sql .=
" WHERE t.rowid = ".((int) $id);
145 $sql .=
" WHERE t.code = '".$this->db->escape(strtoupper($code)).
"'";
146 } elseif ($code_iso) {
147 $sql .=
" WHERE t.code_iso = '".$this->db->escape(strtoupper($code_iso)).
"'";
150 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
151 $resql = $this->db->query($sql);
153 if ($this->db->num_rows($resql)) {
154 $obj = $this->db->fetch_object($resql);
157 $this->
id = $obj->rowid;
158 $this->code = $obj->code;
159 $this->code_iso = $obj->code_iso;
160 $this->label = $obj->label;
161 $this->active = $obj->active;
164 $this->db->free($resql);
170 $this->error =
"Error ".$this->db->lasterror();
183 public function update($user =
null, $notrigger = 0)
188 if (isset($this->code)) {
189 $this->code = trim($this->code);
191 if (isset($this->code_iso)) {
192 $this->code_iso = trim($this->code_iso);
194 if (isset($this->label)) {
195 $this->label = trim($this->label);
197 if (isset($this->active)) {
198 $this->active = trim($this->active);
206 $sql =
"UPDATE ".$this->db->prefix().
"c_country SET";
207 $sql .=
" code=".(isset($this->code) ?
"'".$this->db->escape($this->code).
"'" :
"null").
",";
208 $sql .=
" code_iso=".(isset($this->code_iso) ?
"'".$this->db->escape($this->code_iso).
"'" :
"null").
",";
209 $sql .=
" label=".(isset($this->label) ?
"'".$this->db->escape($this->label).
"'" :
"null").
",";
210 $sql .=
" active=".(isset($this->active) ? $this->active :
"null");
211 $sql .=
" WHERE rowid=".((int) $this->
id);
215 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
216 $resql = $this->db->query($sql);
219 $this->errors[] =
"Error ".$this->db->lasterror();
224 foreach ($this->errors as $errmsg) {
225 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
226 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
228 $this->db->rollback();
244 public function delete($user, $notrigger = 0)
248 $sql =
"DELETE FROM ".$this->db->prefix().
"c_country";
249 $sql .=
" WHERE rowid=".((int) $this->
id);
253 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
254 $resql = $this->db->query($sql);
257 $this->errors[] =
"Error ".$this->db->lasterror();
262 foreach ($this->errors as $errmsg) {
263 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
264 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
266 $this->db->rollback();
284 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
287 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 optionaly 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.
publicphonebutton2 phonegreen basiclayout basiclayout TotalHT VATCode TotalVAT TotalLT1 TotalLT2 TotalTTC TotalHT clearboth nowraponall right right takeposterminal SELECT e rowid