66 public function create($user, $notrigger = 0)
73 if (isset($this->
id)) {
74 $this->
id = (int) $this->
id;
76 if (isset($this->code)) {
77 $this->code = trim($this->code);
79 if (isset($this->libelle)) {
80 $this->libelle = trim($this->libelle);
82 if (isset($this->active)) {
83 $this->active = (int) $this->active;
85 if (isset($this->module)) {
86 $this->module = trim($this->module);
93 $sql =
"INSERT INTO ".$this->db->prefix().
"c_typent(";
100 $sql .=
" ".(!isset($this->
id) ?
'NULL' :
"'".$this->db->escape($this->
id).
"'").
",";
101 $sql .=
" ".(!isset($this->code) ?
'NULL' :
"'".$this->db->escape($this->code).
"'").
",";
102 $sql .=
" ".(!isset($this->libelle) ?
'NULL' :
"'".$this->db->escape($this->libelle).
"'").
",";
103 $sql .=
" ".(!isset($this->active) ?
'NULL' :
"'".$this->db->escape($this->active).
"'").
",";
104 $sql .=
" ".(!isset($this->module) ?
'NULL' :
"'".$this->db->escape($this->module).
"'");
109 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
110 $resql = $this->db->query($sql);
113 $this->errors[] =
"Error ".$this->db->lasterror();
117 $this->
id = $this->db->last_insert_id($this->db->prefix().
"c_typent");
122 foreach ($this->errors as $errmsg) {
123 dol_syslog(get_class($this).
"::create ".$errmsg, LOG_ERR);
124 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
126 $this->db->rollback();
143 public function fetch($id, $code =
'', $label =
'')
148 $sql .=
" t.libelle as label,";
149 $sql .=
" t.fk_country as country_id,";
150 $sql .=
" t.active,";
152 $sql .=
" FROM ".$this->db->prefix().
"c_typent as t";
154 $sql .=
" WHERE t.id = ".((int) $id);
156 $sql .=
" WHERE t.code = '".$this->db->escape($code).
"'";
158 $sql .=
" WHERE t.libelle = '".$this->db->escape($label).
"'";
161 $resql = $this->db->query($sql);
163 if ($this->db->num_rows($resql)) {
164 $obj = $this->db->fetch_object($resql);
166 $this->
id = $obj->id;
167 $this->code = $obj->code;
168 $this->libelle = $obj->label;
169 $this->country_id = $obj->country_id;
170 $this->active = $obj->active;
171 $this->module = $obj->module;
173 $this->db->free($resql);
177 $this->error =
"Error ".$this->db->lasterror();
190 public function update($user =
null, $notrigger = 0)
192 global
$conf, $langs;
196 if (isset($this->code)) {
197 $this->code = trim($this->code);
199 if (isset($this->libelle)) {
200 $this->libelle = trim($this->libelle);
202 if (isset($this->active)) {
203 $this->active = (int) $this->active;
205 if (isset($this->module)) {
206 $this->module = trim($this->module);
214 $sql =
"UPDATE ".$this->db->prefix().
"c_typent SET";
215 $sql .=
" code=".(isset($this->code) ?
"'".$this->db->escape($this->code).
"'" :
"null").
",";
216 $sql .=
" libelle=".(isset($this->libelle) ?
"'".$this->db->escape($this->libelle).
"'" :
"null").
",";
217 $sql .=
" active=".(isset($this->active) ? ((int) $this->active) :
"null").
",";
218 $sql .=
" module=".(isset($this->module) ?
"'".$this->db->escape($this->module).
"'" :
"null");
219 $sql .=
" WHERE id=".$this->id;
223 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
224 $resql = $this->db->query($sql);
227 $this->errors[] =
"Error ".$this->db->lasterror();
232 foreach ($this->errors as $errmsg) {
233 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
234 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
236 $this->db->rollback();