59 public function create($user, $notrigger = 0)
66 if (isset($this->
id)) {
67 $this->
id = (int) $this->
id;
69 if (isset($this->code)) {
70 $this->code = trim($this->code);
72 if (isset($this->libelle)) {
73 $this->libelle = trim($this->libelle);
75 if (isset($this->active)) {
76 $this->active = (int) $this->active;
78 if (isset($this->module)) {
79 $this->module = trim($this->module);
86 $sql =
"INSERT INTO ".$this->db->prefix().
"c_typent(";
93 $sql .=
" ".(!isset($this->
id) ?
'NULL' :
"'".$this->db->escape($this->
id).
"'").
",";
94 $sql .=
" ".(!isset($this->code) ?
'NULL' :
"'".$this->db->escape($this->code).
"'").
",";
95 $sql .=
" ".(!isset($this->libelle) ?
'NULL' :
"'".$this->db->escape($this->libelle).
"'").
",";
96 $sql .=
" ".(!isset($this->active) ?
'NULL' :
"'".$this->db->escape($this->active).
"'").
",";
97 $sql .=
" ".(!isset($this->module) ?
'NULL' :
"'".$this->db->escape($this->module).
"'");
102 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
103 $resql = $this->db->query($sql);
106 $this->errors[] =
"Error ".$this->db->lasterror();
110 $this->
id = $this->db->last_insert_id($this->db->prefix().
"c_typent");
115 foreach ($this->errors as $errmsg) {
116 dol_syslog(get_class($this).
"::create ".$errmsg, LOG_ERR);
117 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
119 $this->db->rollback();
136 public function fetch($id, $code =
'', $label =
'')
141 $sql .=
" t.libelle as label,";
142 $sql .=
" t.fk_country as country_id,";
143 $sql .=
" t.active,";
145 $sql .=
" FROM ".$this->db->prefix().
"c_typent as t";
147 $sql .=
" WHERE t.id = ".((int) $id);
149 $sql .=
" WHERE t.code = '".$this->db->escape($code).
"'";
151 $sql .=
" WHERE t.libelle = '".$this->db->escape($label).
"'";
154 $resql = $this->db->query($sql);
156 if ($this->db->num_rows($resql)) {
157 $obj = $this->db->fetch_object($resql);
159 $this->
id = $obj->id;
160 $this->code = $obj->code;
161 $this->libelle = $obj->label;
162 $this->country_id = $obj->country_id;
163 $this->active = $obj->active;
164 $this->module = $obj->module;
166 $this->db->free($resql);
170 $this->error =
"Error ".$this->db->lasterror();
183 public function update($user =
null, $notrigger = 0)
185 global $conf, $langs;
189 if (isset($this->code)) {
190 $this->code = trim($this->code);
192 if (isset($this->libelle)) {
193 $this->libelle = trim($this->libelle);
195 if (isset($this->active)) {
196 $this->active = (int) $this->active;
198 if (isset($this->module)) {
199 $this->module = trim($this->module);
207 $sql =
"UPDATE ".$this->db->prefix().
"c_typent SET";
208 $sql .=
" code=".(isset($this->code) ?
"'".$this->db->escape($this->code).
"'" :
"null").
",";
209 $sql .=
" libelle=".(isset($this->libelle) ?
"'".$this->db->escape($this->libelle).
"'" :
"null").
",";
210 $sql .=
" active=".(isset($this->active) ? ((int) $this->active) :
"null").
",";
211 $sql .=
" module=".(isset($this->module) ?
"'".$this->db->escape($this->module).
"'" :
"null");
212 $sql .=
" WHERE id=".$this->id;
216 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
217 $resql = $this->db->query($sql);
220 $this->errors[] =
"Error ".$this->db->lasterror();
225 foreach ($this->errors as $errmsg) {
226 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
227 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
229 $this->db->rollback();