dolibarr  9.0.0
ccountry.class.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2007-2011 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 <http://www.gnu.org/licenses/>.
16  */
17 
24 // Put here all includes required by your class file
25 //require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
26 //require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
27 //require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
28 
29 
33 class Ccountry // extends CommonObject
34 {
38  public $db;
39 
43  public $error='';
44 
48  public $errors = array();
49 
50  //var $element='ccountry'; //!< Id that identify managed objects
51  //var $table_element='ccountry'; //!< Name of table without prefix where object is stored
52 
56  public $id;
57 
58  public $code;
59  public $code_iso;
60 
64  public $label;
65 
66  public $active;
67 
68 
69 
70 
76  function __construct($db)
77  {
78  $this->db = $db;
79  }
80 
81 
89  function create($user, $notrigger=0)
90  {
91  global $conf, $langs;
92  $error=0;
93 
94  // Clean parameters
95  if (isset($this->code)) $this->code=trim($this->code);
96  if (isset($this->code_iso)) $this->code_iso=trim($this->code_iso);
97  if (isset($this->label)) $this->label=trim($this->label);
98  if (isset($this->active)) $this->active=trim($this->active);
99 
100  // Check parameters
101  // Put here code to add control on parameters values
102 
103  // Insert request
104  $sql = "INSERT INTO ".MAIN_DB_PREFIX."c_country(";
105  $sql.= "rowid,";
106  $sql.= "code,";
107  $sql.= "code_iso,";
108  $sql.= "label,";
109  $sql.= "active";
110  $sql.= ") VALUES (";
111  $sql.= " ".(! isset($this->rowid)?'NULL':"'".$this->db->escape($this->rowid)."'").",";
112  $sql.= " ".(! isset($this->code)?'NULL':"'".$this->db->escape($this->code)."'").",";
113  $sql.= " ".(! isset($this->code_iso)?'NULL':"'".$this->db->escape($this->code_iso)."'").",";
114  $sql.= " ".(! isset($this->label)?'NULL':"'".$this->db->escape($this->label)."'").",";
115  $sql.= " ".(! isset($this->active)?'NULL':"'".$this->db->escape($this->active)."'")."";
116  $sql.= ")";
117 
118  $this->db->begin();
119 
120  dol_syslog(get_class($this)."::create", LOG_DEBUG);
121  $resql=$this->db->query($sql);
122  if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
123 
124  if (! $error)
125  {
126  $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."c_country");
127 
128  if (! $notrigger)
129  {
130  // Uncomment this and change MYOBJECT to your own tag if you
131  // want this action call a trigger.
132 
134  //include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
135  //$interface=new Interfaces($this->db);
136  //$result=$interface->run_triggers('MYOBJECT_CREATE',$this,$user,$langs,$conf);
137  //if ($result < 0) { $error++; $this->errors=$interface->errors; }
139  }
140  }
141 
142  // Commit or rollback
143  if ($error)
144  {
145  foreach($this->errors as $errmsg)
146  {
147  dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR);
148  $this->error.=($this->error?', '.$errmsg:$errmsg);
149  }
150  $this->db->rollback();
151  return -1*$error;
152  }
153  else
154  {
155  $this->db->commit();
156  return $this->id;
157  }
158  }
159 
160 
168  function fetch($id,$code='')
169  {
170  global $langs;
171  $sql = "SELECT";
172  $sql.= " t.rowid,";
173  $sql.= " t.code,";
174  $sql.= " t.code_iso,";
175  $sql.= " t.label,";
176  $sql.= " t.active";
177  $sql.= " FROM ".MAIN_DB_PREFIX."c_country as t";
178  if ($id) $sql.= " WHERE t.rowid = ".$id;
179  elseif ($code) $sql.= " WHERE t.code = '".$this->db->escape($code)."'";
180 
181  dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
182  $resql=$this->db->query($sql);
183  if ($resql)
184  {
185  if ($this->db->num_rows($resql))
186  {
187  $obj = $this->db->fetch_object($resql);
188 
189  $this->id = $obj->rowid;
190  $this->code = $obj->code;
191  $this->code_iso = $obj->code_iso;
192  $this->label = $obj->label;
193  $this->active = $obj->active;
194 
195  $this->db->free($resql);
196  return 1;
197  }
198  else {
199  return 0;
200  }
201  }
202  else
203  {
204  $this->error="Error ".$this->db->lasterror();
205  return -1;
206  }
207  }
208 
209 
217  function update($user=null, $notrigger=0)
218  {
219  global $conf, $langs;
220  $error=0;
221 
222  // Clean parameters
223  if (isset($this->code)) $this->code=trim($this->code);
224  if (isset($this->code_iso)) $this->code_iso=trim($this->code_iso);
225  if (isset($this->label)) $this->label=trim($this->label);
226  if (isset($this->active)) $this->active=trim($this->active);
227 
228 
229  // Check parameters
230  // Put here code to add control on parameters values
231 
232  // Update request
233  $sql = "UPDATE ".MAIN_DB_PREFIX."c_country SET";
234  $sql.= " code=".(isset($this->code)?"'".$this->db->escape($this->code)."'":"null").",";
235  $sql.= " code_iso=".(isset($this->code_iso)?"'".$this->db->escape($this->code_iso)."'":"null").",";
236  $sql.= " label=".(isset($this->label)?"'".$this->db->escape($this->label)."'":"null").",";
237  $sql.= " active=".(isset($this->active)?$this->active:"null")."";
238  $sql.= " WHERE rowid=".$this->id;
239 
240  $this->db->begin();
241 
242  dol_syslog(get_class($this)."::update", LOG_DEBUG);
243  $resql = $this->db->query($sql);
244  if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
245 
246  if (! $error)
247  {
248  if (! $notrigger)
249  {
250  // Uncomment this and change MYOBJECT to your own tag if you
251  // want this action call a trigger.
252 
254  //include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
255  //$interface=new Interfaces($this->db);
256  //$result=$interface->run_triggers('MYOBJECT_MODIFY',$this,$user,$langs,$conf);
257  //if ($result < 0) { $error++; $this->errors=$interface->errors; }
259  }
260  }
261 
262  // Commit or rollback
263  if ($error)
264  {
265  foreach($this->errors as $errmsg)
266  {
267  dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
268  $this->error.=($this->error?', '.$errmsg:$errmsg);
269  }
270  $this->db->rollback();
271  return -1*$error;
272  }
273  else
274  {
275  $this->db->commit();
276  return 1;
277  }
278  }
279 
280 
288  function delete($user, $notrigger=0)
289  {
290  global $conf, $langs;
291  $error=0;
292 
293  $sql = "DELETE FROM ".MAIN_DB_PREFIX."c_country";
294  $sql.= " WHERE rowid=".$this->id;
295 
296  $this->db->begin();
297 
298  dol_syslog(get_class($this)."::delete", LOG_DEBUG);
299  $resql = $this->db->query($sql);
300  if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
301 
302  if (! $error)
303  {
304  if (! $notrigger)
305  {
306  // Uncomment this and change MYOBJECT to your own tag if you
307  // want this action call a trigger.
308 
310  //include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
311  //$interface=new Interfaces($this->db);
312  //$result=$interface->run_triggers('MYOBJECT_DELETE',$this,$user,$langs,$conf);
313  //if ($result < 0) { $error++; $this->errors=$interface->errors; }
315  }
316  }
317 
318  // Commit or rollback
319  if ($error)
320  {
321  foreach($this->errors as $errmsg)
322  {
323  dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR);
324  $this->error.=($this->error?', '.$errmsg:$errmsg);
325  }
326  $this->db->rollback();
327  return -1*$error;
328  }
329  else
330  {
331  $this->db->commit();
332  return 1;
333  }
334  }
335 }
print $object label
hash of file content (md5_file(dol_osencode($destfull))
Definition: edit.php:153
if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) if(! empty($conf->don->enabled) && $user->rights->societe->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) && $user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1053
update($user=null, $notrigger=0)
Update object into database.
__construct($db)
Constructor.
Class to manage dictionary Countries (used by imports)
fetch($id, $code='')
Load object in memory from database.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
create($user, $notrigger=0)
Create object into database.