Fix: Gestion erreur

This commit is contained in:
Laurent Destailleur 2008-06-19 17:25:15 +00:00
parent 064785e926
commit 46c7aa71dd
2 changed files with 87 additions and 64 deletions

View File

@ -179,6 +179,13 @@ class Product extends CommonObject
}
}
// Check parameters
if (empty($this->libelle))
{
$this->error='ErrorWrongParameters';
return -1;
}
dolibarr_syslog("Product::Create ref=".$this->ref." price=".$this->price." tva_tx=".$this->tva_tx." Categorie : ".$this->catid);
if ($this->ref)
@ -198,11 +205,11 @@ class Product extends CommonObject
$sql = "INSERT INTO ".MAIN_DB_PREFIX."product";
$sql.= " (datec, ";
if ($this->ref) $sql.= "ref, ";
if ($this->libelle) $sql.= "label, ";
$sql.= "label, ";
$sql.= "fk_user_author, fk_product_type, price, price_ttc, price_base_type, canvas)";
$sql.= " VALUES (now(), ";
if ($this->ref) $sql.= "'".$this->ref."', ";
if ($this->libelle) $sql.= "'".addslashes($this->libelle)."', ";
if ($this->ref) $sql.= "'".$this->ref."',";
$sql.= " ".($this->libelle?"'".addslashes($this->libelle)."'":"null").",";
$sql.= $user->id.",";
$sql.= " ".$this->type.",";
$sql.= price2num($price_ht).",";
@ -241,7 +248,8 @@ class Product extends CommonObject
}
else
{
$this->_setErrNo("Create",264);
$this->error=$this->db->error();
$this->_setErrNo("Create",264,$this->error);
}
}
else
@ -251,7 +259,8 @@ class Product extends CommonObject
}
else
{
$this->_setErrNo("Create",258);
$this->error=$this->db->error();
$this->_setErrNo("Create",258,$this->error);
}
}
else

View File

@ -59,70 +59,84 @@ if ($_GET["action"] == 'fastappro')
// Action ajout d'un produit ou service
if ($_POST["action"] == 'add' && $user->rights->produit->creer)
{
if ($_POST["canvas"] <> '' && file_exists('canvas/product.'.$_POST["canvas"].'.class.php') )
{
$class = 'Product'.ucfirst($_POST["canvas"]);
include_once('canvas/product.'.$_POST["canvas"].'.class.php');
$product = new $class($db);
}
else
{
$product = new Product($db);
}
$product->ref = $_POST["ref"];
$product->libelle = $_POST["libelle"];
$product->price = $_POST["price"];
$product->price_base_type = $_POST["price_base_type"];
$product->tva_tx = $_POST["tva_tx"];
$product->type = $_POST["type"];
$product->status = $_POST["statut"];
$product->description = $_POST["desc"];
$product->note = $_POST["note"];
$product->duration_value = $_POST["duration_value"];
$product->duration_unit = $_POST["duration_unit"];
$product->seuil_stock_alerte = $_POST["seuil_stock_alerte"];
$product->canvas = $_POST["canvas"];
$product->weight = $_POST["weight"];
$product->weight_units = $_POST["weight_units"];
$product->volume = $_POST["volume"];
$product->volume_units = $_POST["volume_units"];
// MultiPrix
if($conf->global->PRODUIT_MULTIPRICES == 1)
{
for($i=2;$i<=$conf->global->PRODUIT_MULTIPRICES_LIMIT;$i++)
{
if($_POST["price_".$i])
{
$price = price2num($_POST["price_".$i]);
$product->multiprices["$i"] = $price;
$product->multiprices_base_type["$i"] = $_POST["multiprices_base_type_".$i];
}
else
{
$product->multiprices["$i"] = "";
}
}
}
if ( $value != $current_lang ) $e_product = $product;
// Produit spécifique
// $_POST n'est pas utilise dans la classe Product
// mais dans des classes qui hérite de Product
$id = $product->create($user, $_POST);
$error=0;
if ($id > 0)
if (empty($_POST["libelle"]))
{
Header("Location: fiche.php?id=".$id);
exit;
}
else
{
$mesg='<div class="error">'.$langs->trans($product->error).'</div>';
$mesg='<div class="error">'.$langs->trans('ErrorFieldRequired',$langs->transnoentities('Label')).'</div>';
$_GET["action"] = "create";
$_GET["canvas"] = $product->canvas;
$_GET["type"] = $_POST["type"];
$error++;
}
if (! $error)
{
if ($_POST["canvas"] <> '' && file_exists('canvas/product.'.$_POST["canvas"].'.class.php') )
{
$class = 'Product'.ucfirst($_POST["canvas"]);
include_once('canvas/product.'.$_POST["canvas"].'.class.php');
$product = new $class($db);
}
else
{
$product = new Product($db);
}
$product->ref = $_POST["ref"];
$product->libelle = $_POST["libelle"];
$product->price = $_POST["price"];
$product->price_base_type = $_POST["price_base_type"];
$product->tva_tx = $_POST["tva_tx"];
$product->type = $_POST["type"];
$product->status = $_POST["statut"];
$product->description = $_POST["desc"];
$product->note = $_POST["note"];
$product->duration_value = $_POST["duration_value"];
$product->duration_unit = $_POST["duration_unit"];
$product->seuil_stock_alerte = $_POST["seuil_stock_alerte"];
$product->canvas = $_POST["canvas"];
$product->weight = $_POST["weight"];
$product->weight_units = $_POST["weight_units"];
$product->volume = $_POST["volume"];
$product->volume_units = $_POST["volume_units"];
// MultiPrix
if($conf->global->PRODUIT_MULTIPRICES == 1)
{
for($i=2;$i<=$conf->global->PRODUIT_MULTIPRICES_LIMIT;$i++)
{
if($_POST["price_".$i])
{
$price = price2num($_POST["price_".$i]);
$product->multiprices["$i"] = $price;
$product->multiprices_base_type["$i"] = $_POST["multiprices_base_type_".$i];
}
else
{
$product->multiprices["$i"] = "";
}
}
}
if ( $value != $current_lang ) $e_product = $product;
// Produit spécifique
// $_POST n'est pas utilise dans la classe Product
// mais dans des classes qui hérite de Product
$id = $product->create($user, $_POST);
if ($id > 0)
{
Header("Location: fiche.php?id=".$id);
exit;
}
else
{
$mesg='<div class="error">'.$langs->trans($product->error).'</div>';
$_GET["action"] = "create";
$_GET["canvas"] = $product->canvas;
$_GET["type"] = $_POST["type"];
}
}
}