81 public function create($user, $notrigger = 0)
88 if (isset($this->
id)) {
89 $this->
id = trim($this->
id);
91 if (isset($this->code)) {
92 $this->code = trim($this->code);
94 if (isset($this->libelle)) {
95 $this->libelle = trim($this->libelle);
97 if (isset($this->active)) {
98 $this->active = trim($this->active);
100 if (isset($this->module)) {
101 $this->module = trim($this->module);
108 $sql =
"INSERT INTO ".$this->db->prefix().
"c_typent(";
114 $sql .=
") VALUES (";
115 $sql .=
" ".(!isset($this->
id) ?
'NULL' :
"'".$this->db->escape($this->
id).
"'").
",";
116 $sql .=
" ".(!isset($this->code) ?
'NULL' :
"'".$this->db->escape($this->code).
"'").
",";
117 $sql .=
" ".(!isset($this->libelle) ?
'NULL' :
"'".$this->db->escape($this->libelle).
"'").
",";
118 $sql .=
" ".(!isset($this->active) ?
'NULL' :
"'".$this->db->escape($this->active).
"'").
",";
119 $sql .=
" ".(!isset($this->module) ?
'NULL' :
"'".$this->db->escape($this->module).
"'");
124 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
125 $resql = $this->db->query($sql);
128 $this->errors[] =
"Error ".$this->db->lasterror();
132 $this->
id = $this->db->last_insert_id($this->db->prefix().
"c_typent");
137 foreach ($this->errors as $errmsg) {
138 dol_syslog(get_class($this).
"::create ".$errmsg, LOG_ERR);
139 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
141 $this->db->rollback();
158 public function fetch($id, $code =
'', $label =
'')
163 $sql .=
" t.libelle as label,";
164 $sql .=
" t.fk_country as country_id,";
165 $sql .=
" t.active,";
167 $sql .=
" FROM ".$this->db->prefix().
"c_typent as t";
169 $sql .=
" WHERE t.id = ".((int) $id);
171 $sql .=
" WHERE t.code = '".$this->db->escape($code).
"'";
173 $sql .=
" WHERE t.libelle = '".$this->db->escape($label).
"'";
176 $resql = $this->db->query($sql);
178 if ($this->db->num_rows($resql)) {
179 $obj = $this->db->fetch_object($resql);
181 $this->
id = $obj->id;
182 $this->code = $obj->code;
183 $this->libelle = $obj->label;
184 $this->country_id = $obj->country_id;
185 $this->active = $obj->active;
186 $this->module = $obj->module;
188 $this->db->free($resql);
192 $this->error =
"Error ".$this->db->lasterror();
205 public function update($user =
null, $notrigger = 0)
207 global $conf, $langs;
211 if (isset($this->code)) {
212 $this->code = trim($this->code);
214 if (isset($this->libelle)) {
215 $this->libelle = trim($this->libelle);
217 if (isset($this->active)) {
218 $this->active = trim($this->active);
220 if (isset($this->module)) {
221 $this->module = trim($this->module);
229 $sql =
"UPDATE ".$this->db->prefix().
"c_typent SET";
230 $sql .=
" code=".(isset($this->code) ?
"'".$this->db->escape($this->code).
"'" :
"null").
",";
231 $sql .=
" libelle=".(isset($this->libelle) ?
"'".$this->db->escape($this->libelle).
"'" :
"null").
",";
232 $sql .=
" active=".(isset($this->active) ? ((int) $this->active) :
"null").
",";
233 $sql .=
" module=".(isset($this->module) ?
"'".$this->db->escape($this->module).
"'" :
"null");
234 $sql .=
" WHERE id=".$this->id;
238 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
239 $resql = $this->db->query($sql);
242 $this->errors[] =
"Error ".$this->db->lasterror();
247 foreach ($this->errors as $errmsg) {
248 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
249 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
251 $this->db->rollback();