dolibarr  13.0.2
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 <https://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  public $element = 'ccountry';
51  public $table_element = 'c_country';
52 
56  public $id;
57 
58  public $code;
59  public $code_iso;
60 
64  public $label;
65 
66  public $active;
67 
68  public $fields = array(
69  'label' => array('type'=>'varchar(250)', 'label'=>'Label', 'enabled'=>1, 'visible'=>1, 'position'=>15, 'notnull'=>-1, 'showoncombobox'=>'1')
70  );
71 
72 
78  public function __construct($db)
79  {
80  $this->db = $db;
81  }
82 
83 
91  public function create($user, $notrigger = 0)
92  {
93  global $conf, $langs;
94  $error = 0;
95 
96  // Clean parameters
97  if (isset($this->code)) $this->code = trim($this->code);
98  if (isset($this->code_iso)) $this->code_iso = trim($this->code_iso);
99  if (isset($this->label)) $this->label = trim($this->label);
100  if (isset($this->active)) $this->active = trim($this->active);
101 
102  // Check parameters
103  // Put here code to add control on parameters values
104 
105  // Insert request
106  $sql = "INSERT INTO ".MAIN_DB_PREFIX."c_country(";
107  $sql .= "rowid,";
108  $sql .= "code,";
109  $sql .= "code_iso,";
110  $sql .= "label,";
111  $sql .= "active";
112  $sql .= ") VALUES (";
113  $sql .= " ".(!isset($this->rowid) ? 'NULL' : "'".$this->db->escape($this->rowid)."'").",";
114  $sql .= " ".(!isset($this->code) ? 'NULL' : "'".$this->db->escape($this->code)."'").",";
115  $sql .= " ".(!isset($this->code_iso) ? 'NULL' : "'".$this->db->escape($this->code_iso)."'").",";
116  $sql .= " ".(!isset($this->label) ? 'NULL' : "'".$this->db->escape($this->label)."'").",";
117  $sql .= " ".(!isset($this->active) ? 'NULL' : "'".$this->db->escape($this->active)."'")."";
118  $sql .= ")";
119 
120  $this->db->begin();
121 
122  dol_syslog(get_class($this)."::create", LOG_DEBUG);
123  $resql = $this->db->query($sql);
124  if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); }
125 
126  if (!$error)
127  {
128  $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."c_country");
129  }
130 
131  // Commit or rollback
132  if ($error)
133  {
134  foreach ($this->errors as $errmsg)
135  {
136  dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR);
137  $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
138  }
139  $this->db->rollback();
140  return -1 * $error;
141  } else {
142  $this->db->commit();
143  return $this->id;
144  }
145  }
146 
147 
156  public function fetch($id, $code = '', $code_iso = '')
157  {
158  $sql = "SELECT";
159  $sql .= " t.rowid,";
160  $sql .= " t.code,";
161  $sql .= " t.code_iso,";
162  $sql .= " t.label,";
163  $sql .= " t.active";
164  $sql .= " FROM ".MAIN_DB_PREFIX."c_country as t";
165  if ($id) $sql .= " WHERE t.rowid = ".((int) $id);
166  elseif ($code) $sql .= " WHERE t.code = '".$this->db->escape(strtoupper($code))."'";
167  elseif ($code_iso) $sql .= " WHERE t.code_iso = '".$this->db->escape(strtoupper($code_iso))."'";
168 
169  dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
170  $resql = $this->db->query($sql);
171  if ($resql)
172  {
173  if ($this->db->num_rows($resql))
174  {
175  $obj = $this->db->fetch_object($resql);
176 
177  if ($obj) {
178  $this->id = $obj->rowid;
179  $this->code = $obj->code;
180  $this->code_iso = $obj->code_iso;
181  $this->label = $obj->label;
182  $this->active = $obj->active;
183  }
184 
185  $this->db->free($resql);
186  return 1;
187  } else {
188  return 0;
189  }
190  } else {
191  $this->error = "Error ".$this->db->lasterror();
192  return -1;
193  }
194  }
195 
196 
204  public function update($user = null, $notrigger = 0)
205  {
206  global $conf, $langs;
207  $error = 0;
208 
209  // Clean parameters
210  if (isset($this->code)) $this->code = trim($this->code);
211  if (isset($this->code_iso)) $this->code_iso = trim($this->code_iso);
212  if (isset($this->label)) $this->label = trim($this->label);
213  if (isset($this->active)) $this->active = trim($this->active);
214 
215 
216  // Check parameters
217  // Put here code to add control on parameters values
218 
219  // Update request
220  $sql = "UPDATE ".MAIN_DB_PREFIX."c_country SET";
221  $sql .= " code=".(isset($this->code) ? "'".$this->db->escape($this->code)."'" : "null").",";
222  $sql .= " code_iso=".(isset($this->code_iso) ? "'".$this->db->escape($this->code_iso)."'" : "null").",";
223  $sql .= " label=".(isset($this->label) ? "'".$this->db->escape($this->label)."'" : "null").",";
224  $sql .= " active=".(isset($this->active) ? $this->active : "null")."";
225  $sql .= " WHERE rowid=".$this->id;
226 
227  $this->db->begin();
228 
229  dol_syslog(get_class($this)."::update", LOG_DEBUG);
230  $resql = $this->db->query($sql);
231  if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); }
232 
233  // Commit or rollback
234  if ($error)
235  {
236  foreach ($this->errors as $errmsg)
237  {
238  dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
239  $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
240  }
241  $this->db->rollback();
242  return -1 * $error;
243  } else {
244  $this->db->commit();
245  return 1;
246  }
247  }
248 
249 
257  public function delete($user, $notrigger = 0)
258  {
259  global $conf, $langs;
260  $error = 0;
261 
262  $sql = "DELETE FROM ".MAIN_DB_PREFIX."c_country";
263  $sql .= " WHERE rowid=".$this->id;
264 
265  $this->db->begin();
266 
267  dol_syslog(get_class($this)."::delete", LOG_DEBUG);
268  $resql = $this->db->query($sql);
269  if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); }
270 
271  // Commit or rollback
272  if ($error)
273  {
274  foreach ($this->errors as $errmsg)
275  {
276  dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR);
277  $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
278  }
279  $this->db->rollback();
280  return -1 * $error;
281  } else {
282  $this->db->commit();
283  return 1;
284  }
285  }
286 
297  public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
298  {
299  global $langs;
300  return $langs->trans($this->label);
301  }
302 }
getNomUrl($withpicto=0, $option= '', $notooltip=0, $morecss= '', $save_lastsearch_value=-1)
Return a link to the object card (with optionaly the picto)
$element
Id that identify managed objects.
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
update($user=null, $notrigger=0)
Update object into database.
$table_element
Name of table without prefix where object is stored.
__construct($db)
Constructor.
$conf db
API class for accounts.
Definition: inc.php:54
Class to manage dictionary Countries (used by imports)
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
fetch($id, $code= '', $code_iso= '')
Load object in memory from database.
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
create($user, $notrigger=0)
Create object into database.