dolibarr  13.0.2
cstate.class.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2016 Laurent Destailleur <eldy@users.sourceforge.net>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <https://www.gnu.org/licenses/>.
16  */
17 
27 class Cstate // extends CommonObject
28 {
32  public $db;
33 
37  public $error = '';
38 
42  public $errors = array();
43 
44  //var $element='cstate'; //!< Id that identify managed objects
45  //var $table_element='cstate'; //!< Name of table without prefix where object is stored
46 
50  public $id;
51 
52  public $code_departement;
53  public $code;
59  public $nom = '';
60 
64  public $name = '';
65 
66  public $active;
67 
68 
69 
70 
76  public function __construct($db)
77  {
78  $this->db = $db;
79  }
80 
81 
89  public function create($user, $notrigger = 0)
90  {
91  global $conf, $langs;
92  $error = 0;
93 
94  // Clean parameters
95  if (isset($this->code_departement)) $this->code_departement = trim($this->code_departement);
96  if (isset($this->nom)) $this->nom = trim($this->nom);
97  if (isset($this->active)) $this->active = trim($this->active);
98 
99  // Check parameters
100  // Put here code to add control on parameters values
101 
102  // Insert request
103  $sql = "INSERT INTO ".MAIN_DB_PREFIX."c_departements(";
104  $sql .= "rowid,";
105  $sql .= "code_departement,";
106  $sql .= "nom,";
107  $sql .= "active";
108  $sql .= ") VALUES (";
109  $sql .= " ".(!isset($this->rowid) ? 'NULL' : "'".$this->db->escape($this->rowid)."'").",";
110  $sql .= " ".(!isset($this->code_departement) ? 'NULL' : "'".$this->db->escape($this->code_departement)."'").",";
111  $sql .= " ".(!isset($this->nom) ? 'NULL' : "'".$this->db->escape($this->nom)."'").",";
112  $sql .= " ".(!isset($this->active) ? 'NULL' : "'".$this->db->escape($this->active)."'")."";
113  $sql .= ")";
114 
115  $this->db->begin();
116 
117  dol_syslog(get_class($this)."::create", LOG_DEBUG);
118  $resql = $this->db->query($sql);
119  if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); }
120 
121  if (!$error) {
122  $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."c_departements");
123  }
124 
125  // Commit or rollback
126  if ($error)
127  {
128  foreach ($this->errors as $errmsg)
129  {
130  dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR);
131  $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
132  }
133  $this->db->rollback();
134  return -1 * $error;
135  } else {
136  $this->db->commit();
137  return $this->id;
138  }
139  }
140 
141 
149  public function fetch($id, $code = '')
150  {
151  global $langs;
152  $sql = "SELECT";
153  $sql .= " t.rowid,";
154  $sql .= " t.code_departement,";
155  $sql .= " t.nom,";
156  $sql .= " t.active";
157  $sql .= " FROM ".MAIN_DB_PREFIX."c_departements as t";
158  if ($id) $sql .= " WHERE t.rowid = ".$id;
159  elseif ($code) $sql .= " WHERE t.code_departement = '".$this->db->escape($code)."'";
160 
161  dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
162  $resql = $this->db->query($sql);
163  if ($resql)
164  {
165  if ($this->db->num_rows($resql))
166  {
167  $obj = $this->db->fetch_object($resql);
168 
169  $this->id = $obj->rowid;
170  $this->code_departement = $obj->code_departement; //deprecated
171  $this->code = $obj->code_departement;
172  $this->nom = $obj->nom; //deprecated
173  $this->name = $obj->nom;
174  $this->active = $obj->active;
175  }
176  $this->db->free($resql);
177 
178  return 1;
179  } else {
180  $this->error = "Error ".$this->db->lasterror();
181  return -1;
182  }
183  }
184 
185 
193  public function update($user = null, $notrigger = 0)
194  {
195  global $conf, $langs;
196  $error = 0;
197 
198  // Clean parameters
199  if (isset($this->code_departement)) $this->code_departement = trim($this->code_departement);
200  if (isset($this->nom)) $this->nom = trim($this->nom);
201  if (isset($this->active)) $this->active = trim($this->active);
202 
203 
204  // Check parameters
205  // Put here code to add control on parameters values
206 
207  // Update request
208  $sql = "UPDATE ".MAIN_DB_PREFIX."c_departements SET";
209  $sql .= " code_departement=".(isset($this->code_departement) ? "'".$this->db->escape($this->code_departement)."'" : "null").",";
210  $sql .= " nom=".(isset($this->nom) ? "'".$this->db->escape($this->nom)."'" : "null").",";
211  $sql .= " active=".(isset($this->active) ? $this->active : "null")."";
212  $sql .= " WHERE rowid=".$this->id;
213 
214  $this->db->begin();
215 
216  dol_syslog(get_class($this)."::update", LOG_DEBUG);
217  $resql = $this->db->query($sql);
218  if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); }
219 
220  // Commit or rollback
221  if ($error) {
222  foreach ($this->errors as $errmsg) {
223  dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
224  $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
225  }
226  $this->db->rollback();
227  return -1 * $error;
228  } else {
229  $this->db->commit();
230  return 1;
231  }
232  }
233 
241  public function delete($user, $notrigger = 0)
242  {
243  global $conf, $langs;
244  $error = 0;
245 
246  $sql = "DELETE FROM ".MAIN_DB_PREFIX."c_departements";
247  $sql .= " WHERE rowid=".$this->id;
248 
249  $this->db->begin();
250 
251  dol_syslog(get_class($this)."::delete", LOG_DEBUG);
252  $resql = $this->db->query($sql);
253  if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); }
254 
255  // Commit or rollback
256  if ($error)
257  {
258  foreach ($this->errors as $errmsg)
259  {
260  dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR);
261  $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
262  }
263  $this->db->rollback();
264  return -1 * $error;
265  } else {
266  $this->db->commit();
267  return 1;
268  }
269  }
270 }
update($user=null, $notrigger=0)
Update object into database.
if(!empty($arrayfields['country.code_iso']['checked'])) print_liste_field_titre($arrayfields['country.code_iso']['label'] country if(!empty($arrayfields['typent.code']['checked'])) print_liste_field_titre($arrayfields['typent.code']['label'] typent code
Definition: list.php:566
</td >< tdcolspan="3">< spanclass="opacitymedium"></span ></td ></tr >< trclass="liste_total"> CREANCES DETTES< tdcolspan="3"class="right"></td >< tdcolspan="3"class="right"></td ></tr > CREANCES DETTES RECETTES DEPENSES trips CREANCES DETTES Y m expensereport p date_valid Y m expensereport pe datep $db idate($date_start)."' AND $column < p rowid
Class to manage dictionary States (used by imports)
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:108
$conf db
API class for accounts.
Definition: inc.php:54
create($user, $notrigger=0)
Create object into database.
if(!empty($arrayfields['s.nom']['checked'])) print_liste_field_titre($arrayfields['s.nom']['label'] s nom
Definition: list.php:560
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1232
__construct($db)
Constructor.
fetch($id, $code= '')
Load object in memory from database.