48 public $errors = array();
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)
97 if (isset($this->code)) {
98 $this->code = trim($this->code);
100 if (isset($this->code_iso)) {
101 $this->code_iso = trim($this->code_iso);
103 if (isset($this->label)) {
104 $this->label = trim($this->label);
106 if (isset($this->active)) {
107 $this->active = trim($this->active);
114 $sql =
"INSERT INTO ".$this->db->prefix().
"c_country(";
120 $sql .=
") VALUES (";
121 $sql .=
" ".(!isset($this->
rowid) ?
'NULL' :
"'".$this->db->escape($this->
rowid).
"'").
",";
122 $sql .=
" ".(!isset($this->code) ?
'NULL' :
"'".$this->db->escape($this->code).
"'").
",";
123 $sql .=
" ".(!isset($this->code_iso) ?
'NULL' :
"'".$this->db->escape($this->code_iso).
"'").
",";
124 $sql .=
" ".(!isset($this->label) ?
'NULL' :
"'".$this->db->escape($this->label).
"'").
",";
125 $sql .=
" ".(!isset($this->active) ?
'NULL' :
"'".$this->db->escape($this->active).
"'");
130 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
131 $resql = $this->db->query($sql);
134 $this->errors[] =
"Error ".$this->db->lasterror();
138 $this->
id = $this->db->last_insert_id($this->db->prefix().
"c_country");
143 foreach ($this->errors as $errmsg) {
144 dol_syslog(get_class($this).
"::create ".$errmsg, LOG_ERR);
145 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
147 $this->db->rollback();
164 public function fetch($id, $code =
'', $code_iso =
'')
169 $sql .=
" t.code_iso,";
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);
182 $resql = $this->db->query($sql);
184 if ($this->db->num_rows($resql)) {
185 $obj = $this->db->fetch_object($resql);
188 $this->
id = $obj->rowid;
189 $this->code = $obj->code;
190 $this->code_iso = $obj->code_iso;
191 $this->label = $obj->label;
192 $this->active = $obj->active;
195 $this->db->free($resql);
201 $this->error =
"Error ".$this->db->lasterror();
214 public function update($user =
null, $notrigger = 0)
216 global $conf, $langs;
220 if (isset($this->code)) {
221 $this->code = trim($this->code);
223 if (isset($this->code_iso)) {
224 $this->code_iso = trim($this->code_iso);
226 if (isset($this->label)) {
227 $this->label = trim($this->label);
229 if (isset($this->active)) {
230 $this->active = trim($this->active);
238 $sql =
"UPDATE ".$this->db->prefix().
"c_country SET";
239 $sql .=
" code=".(isset($this->code) ?
"'".$this->db->escape($this->code).
"'" :
"null").
",";
240 $sql .=
" code_iso=".(isset($this->code_iso) ?
"'".$this->db->escape($this->code_iso).
"'" :
"null").
",";
241 $sql .=
" label=".(isset($this->label) ?
"'".$this->db->escape($this->label).
"'" :
"null").
",";
242 $sql .=
" active=".(isset($this->active) ? $this->active :
"null");
243 $sql .=
" WHERE rowid=".((int) $this->
id);
247 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
248 $resql = $this->db->query($sql);
251 $this->errors[] =
"Error ".$this->db->lasterror();
256 foreach ($this->errors as $errmsg) {
257 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
258 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
260 $this->db->rollback();
276 public function delete($user, $notrigger = 0)
278 global $conf, $langs;
281 $sql =
"DELETE FROM ".$this->db->prefix().
"c_country";
282 $sql .=
" WHERE rowid=".((int) $this->
id);
286 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
287 $resql = $this->db->query($sql);
290 $this->errors[] =
"Error ".$this->db->lasterror();
295 foreach ($this->errors as $errmsg) {
296 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
297 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
299 $this->db->rollback();
317 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
320 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.
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