Fix: On fourni le champ ref a la creation du produit

This commit is contained in:
Laurent Destailleur 2005-09-11 17:22:04 +00:00
parent 86811c9e3b
commit 5013f41623

View File

@ -54,7 +54,9 @@ class Product
var $stats_contrat=array(); var $stats_contrat=array();
var $stats_facture=array(); var $stats_facture=array();
var $error;
/** /**
* \brief Constructeur de la classe * \brief Constructeur de la classe
* \param DB Handler accès base de données * \param DB Handler accès base de données
@ -104,8 +106,8 @@ class Product
function create($user) function create($user)
{ {
$this->ref = ereg_replace("'","",$this->ref); $this->ref = trim(sanitize_string($this->ref));
$this->ref = ereg_replace("\"","",$this->ref);
if (strlen($this->tva_tx)==0) $this->tva_tx = 0; if (strlen($this->tva_tx)==0) $this->tva_tx = 0;
if (strlen($this->price)==0) $this->price = 0; if (strlen($this->price)==0) $this->price = 0;
if (strlen($this->envente)==0) $this->envente = 0; if (strlen($this->envente)==0) $this->envente = 0;
@ -116,7 +118,7 @@ class Product
$this->db->begin(); $this->db->begin();
$sql = "SELECT count(*)"; $sql = "SELECT count(*)";
$sql .= " FROM ".MAIN_DB_PREFIX."product WHERE ref = '" .trim($this->ref)."'"; $sql .= " FROM ".MAIN_DB_PREFIX."product WHERE ref = '" .$this->ref."'";
$result = $this->db->query($sql) ; $result = $this->db->query($sql) ;
if ($result) if ($result)
@ -124,9 +126,10 @@ class Product
$row = $this->db->fetch_array($result); $row = $this->db->fetch_array($result);
if ($row[0] == 0) if ($row[0] == 0)
{ {
// Produit non deja existant
$sql = "INSERT INTO ".MAIN_DB_PREFIX."product "; $sql = "INSERT INTO ".MAIN_DB_PREFIX."product ";
$sql .= " (datec, fk_user_author, fk_product_type, price)"; $sql .= " (datec, ref, fk_user_author, fk_product_type, price)";
$sql .= " VALUES (now(),".$user->id.",$this->type, '" . $this->price . "')"; $sql .= " VALUES (now(), '".$this->ref."', ".$user->id.",$this->type, '" . $this->price . "')";
$result = $this->db->query($sql); $result = $this->db->query($sql);
if ( $result ) if ( $result )
{ {
@ -159,6 +162,7 @@ class Product
} }
else else
{ {
$this->error=$this->db->error()." - ".$sql;
$this->db->rollback(); $this->db->rollback();
return -3; return -3;
} }
@ -170,6 +174,7 @@ class Product
} }
} }
$this->error=$this->db->error();
$this->db->rollback(); $this->db->rollback();
return -1; return -1;
} }