Fix: Correction bug #9821

This commit is contained in:
Laurent Destailleur 2004-10-23 21:34:49 +00:00
parent f5e9d7c6b7
commit b7b4c9d751
2 changed files with 50 additions and 26 deletions

View File

@ -61,7 +61,7 @@ class Product
}
/**
* \brief Vérifie que la référence produit est non null
* \brief Vérifie que la référence et libellé du produit est non null
* \return int 1 si ok, 0 sinon
*/
@ -149,27 +149,32 @@ class Product
}
/**
* \brief Mise à jour du produit en base
* \param id id du produit
* \param user utilisateur qui effectue l'insertion
* \brief Mise à jour du produit en base
* \param id id du produit
* \param user utilisateur qui effectue l'insertion
* \return int 1 si ok, -1 si ref deja existante, -2 autre erreur
*/
function update($id, $user)
{
global $langs;
$langs->load("main");
$langs->load("products");
$this->ref = ereg_replace("\"","",stripslashes($this->ref));
$this->ref = ereg_replace("'","",stripslashes($this->ref));
if (strlen(trim($this->libelle)) == 0)
{
$this->libelle = 'LIBELLE MANQUANT';
}
{
$this->libelle = 'LIBELLE MANQUANT';
}
$sql = "UPDATE ".MAIN_DB_PREFIX."product ";
$sql .= " SET label = '" . trim($this->libelle) ."'";
if (strlen(trim($this->ref)))
{
$sql .= ",ref = '" . trim($this->ref) ."'";
}
{
$sql .= ",ref = '" . trim($this->ref) ."'";
}
$sql .= ",tva_tx = " . $this->tva_tx ;
$sql .= ",envente = " . $this->envente ;
$sql .= ",seuil_stock_alerte = " . $this->seuil_stock_alerte ;
@ -179,13 +184,20 @@ class Product
$sql .= " WHERE rowid = " . $id;
if ( $this->db->query($sql) )
{
return 1;
}
{
return 1;
}
else
{
dolibarr_print_error($this->db);
}
{
if ($this->db->errno() == $this->db->ERROR_DUPLICATE) {
$this->mesg_error=$langs->trans("Error")." : ".$langs->trans("ErrorProductAlreadyExists",$this->ref);
return -1;
}
else {
$this->mesg_error=$langs->trans("Error")." : ".$this->db->error();
return -2;
}
}
}
/**

View File

@ -48,7 +48,7 @@ if (!$user->rights->produit->lire)
$types[0] = $langs->trans("Product");
$types[1] = $langs->trans("Service");
// Action ajout d'un produit ou service
if ($_POST["action"] == 'add' && $user->rights->produit->creer)
{
$product = new Product($db);
@ -83,6 +83,7 @@ if ($_POST["action"] == 'add' && $user->rights->produit->creer)
}
}
// Action mise a jour d'un produit ou service
if ($_POST["action"] == 'update' &&
$_POST["cancel"] <> $langs->trans("Cancel") &&
( $user->rights->produit->modifier || $user->rights->produit->creer))
@ -90,7 +91,6 @@ if ($_POST["action"] == 'update' &&
$product = new Product($db);
if ($product->fetch($_POST["id"]))
{
$product->ref = $_POST["ref"];
$product->libelle = $_POST["libelle"];
$product->price = $_POST["price"];
@ -103,24 +103,25 @@ if ($_POST["action"] == 'update' &&
if ($product->check())
{
if ($product->update($product->id, $user))
if ($product->update($product->id, $user) > 0)
{
$_GET["action"] = '';
$mesg = 'Fiche mise à jour';
$_GET["id"] = $_POST["id"];
}
else
{
$_GET["action"] = 're-edit';
$mesg = 'Fiche non mise à jour !' . "<br>" . $product->mesg_error;
$_GET["id"] = $_POST["id"];
$mesg = $product->mesg_error;
}
}
else
{
$_GET["action"] = 're-edit';
$mesg = 'Fiche non mise à jour !' . "<br>" . $product->mesg_error;
$_GET["id"] = $_POST["id"];
$mesg = $langs->trans("ErrorProductBadRefOrLabel");
}
}
Header("Location: fiche.php?id=".$product->id);
}
@ -224,6 +225,8 @@ if ($_POST["cancel"] == $langs->trans("Cancel"))
}
llxHeader("","",$langs->trans("CardProduct".$product->type));
@ -300,8 +303,12 @@ if ($_GET["action"] == 'create')
}
else
{
/*
* Fiche produit
*/
if ($_GET["id"])
{
if ($_GET["action"] <> 're-edit')
{
$product = new Product($db);
@ -314,7 +321,7 @@ else
if ($_GET["action"] <> 'edit' && $_GET["action"] <> 're-edit')
{
/*
* Fiche en visu
* En mode visu
*/
// Zone recherche
@ -514,8 +521,13 @@ else
*/
if (($_GET["action"] == 'edit' || $_GET["action"] == 're-edit') && $user->rights->produit->creer)
{
print_fiche_titre('Edition de la fiche '.$types[$product->type].' : '.$product->ref, $mesg);
print_fiche_titre('Edition de la fiche '.$types[$product->type].' : '.$product->ref, "");
if ($mesg) {
print '<br><div class="error">'.$mesg.'</div><br>';
}
print "<form action=\"fiche.php\" method=\"post\">\n";
print '<input type="hidden" name="action" value="update">';
print '<input type="hidden" name="id" value="'.$product->id.'">';