42 public $errors = array();
57 public $code_departement;
97 public function create($user, $notrigger = 0)
102 if (isset($this->code_departement)) {
103 $this->code_departement = trim($this->code_departement);
105 if (isset($this->nom)) {
106 $this->nom = trim($this->nom);
108 if (isset($this->active)) {
109 $this->active = trim($this->active);
116 $sql =
"INSERT INTO ".$this->db->prefix().
"c_departements(";
118 $sql .=
"code_departement,";
121 $sql .=
") VALUES (";
122 $sql .=
" ".(!isset($this->
rowid) ?
'NULL' :
"'".$this->db->escape($this->
rowid).
"'").
",";
123 $sql .=
" ".(!isset($this->code_departement) ?
'NULL' :
"'".$this->db->escape($this->code_departement).
"'").
",";
124 $sql .=
" ".(!isset($this->nom) ?
'NULL' :
"'".$this->db->escape($this->nom).
"'").
",";
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_departements");
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();
163 public function fetch($id, $code =
'')
167 $sql .=
" t.code_departement,";
170 $sql .=
" FROM ".$this->db->prefix().
"c_departements as t";
172 $sql .=
" WHERE t.rowid = ".((int) $id);
174 $sql .=
" WHERE t.code_departement = '".$this->db->escape($code).
"'";
177 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
178 $resql = $this->db->query($sql);
180 if ($this->db->num_rows($resql)) {
181 $obj = $this->db->fetch_object($resql);
183 $this->
id = $obj->rowid;
184 $this->code_departement = $obj->code_departement;
185 $this->code = $obj->code_departement;
186 $this->nom = $obj->nom;
187 $this->
name = $obj->nom;
188 $this->active = $obj->active;
190 $this->db->free($resql);
194 $this->error =
"Error ".$this->db->lasterror();
207 public function update($user =
null, $notrigger = 0)
209 global $conf, $langs;
213 if (isset($this->code_departement)) {
214 $this->code_departement = trim($this->code_departement);
216 if (isset($this->
name)) {
219 if (isset($this->active)) {
220 $this->active = trim($this->active);
224 if (empty($this->
name) && !empty($this->nom)) {
225 $this->
name = $this->nom;
229 $sql =
"UPDATE ".$this->db->prefix().
"c_departements SET";
230 $sql .=
" code_departement=".(isset($this->code_departement) ?
"'".$this->db->escape($this->code_departement).
"'" :
"null").
",";
231 $sql .=
" nom=".(isset($this->
name) ?
"'".$this->db->escape($this->
name).
"'" :
"null").
",";
232 $sql .=
" active=".(isset($this->active) ? ((int) $this->active) :
"null");
233 $sql .=
" WHERE rowid=".((int) $this->
id);
237 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
238 $resql = $this->db->query($sql);
241 $this->errors[] =
"Error ".$this->db->lasterror();
246 foreach ($this->errors as $errmsg) {
247 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
248 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
250 $this->db->rollback();
265 public function delete($user, $notrigger = 0)
267 global $conf, $langs;
270 $sql =
"DELETE FROM ".$this->db->prefix().
"c_departements";
271 $sql .=
" WHERE rowid=".((int) $this->
id);
275 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
276 $resql = $this->db->query($sql);
279 $this->errors[] =
"Error ".$this->db->lasterror();
284 foreach ($this->errors as $errmsg) {
285 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
286 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
288 $this->db->rollback();
306 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
309 return $langs->trans($this->
name);
Class to manage dictionary States (used by imports)
fetch($id, $code='')
Load object in memory from database.
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.
__construct($db)
Constructor.
update($user=null, $notrigger=0)
Update object into 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
$conf db name
Only used if Module[ID]Name translation string is not found.