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 * \return int 1 si ok, 0 sinon
*/ */
@ -152,10 +152,15 @@ class Product
* \brief Mise à jour du produit en base * \brief Mise à jour du produit en base
* \param id id du produit * \param id id du produit
* \param user utilisateur qui effectue l'insertion * \param user utilisateur qui effectue l'insertion
* \return int 1 si ok, -1 si ref deja existante, -2 autre erreur
*/ */
function update($id, $user) 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));
$this->ref = ereg_replace("'","",stripslashes($this->ref)); $this->ref = ereg_replace("'","",stripslashes($this->ref));
@ -184,7 +189,14 @@ class Product
} }
else 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[0] = $langs->trans("Product");
$types[1] = $langs->trans("Service"); $types[1] = $langs->trans("Service");
// Action ajout d'un produit ou service
if ($_POST["action"] == 'add' && $user->rights->produit->creer) if ($_POST["action"] == 'add' && $user->rights->produit->creer)
{ {
$product = new Product($db); $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' && if ($_POST["action"] == 'update' &&
$_POST["cancel"] <> $langs->trans("Cancel") && $_POST["cancel"] <> $langs->trans("Cancel") &&
( $user->rights->produit->modifier || $user->rights->produit->creer)) ( $user->rights->produit->modifier || $user->rights->produit->creer))
@ -90,7 +91,6 @@ if ($_POST["action"] == 'update' &&
$product = new Product($db); $product = new Product($db);
if ($product->fetch($_POST["id"])) if ($product->fetch($_POST["id"]))
{ {
$product->ref = $_POST["ref"]; $product->ref = $_POST["ref"];
$product->libelle = $_POST["libelle"]; $product->libelle = $_POST["libelle"];
$product->price = $_POST["price"]; $product->price = $_POST["price"];
@ -103,24 +103,25 @@ if ($_POST["action"] == 'update' &&
if ($product->check()) if ($product->check())
{ {
if ($product->update($product->id, $user)) if ($product->update($product->id, $user) > 0)
{ {
$_GET["action"] = ''; $_GET["action"] = '';
$mesg = 'Fiche mise à jour'; $_GET["id"] = $_POST["id"];
} }
else else
{ {
$_GET["action"] = 're-edit'; $_GET["action"] = 're-edit';
$mesg = 'Fiche non mise à jour !' . "<br>" . $product->mesg_error; $_GET["id"] = $_POST["id"];
$mesg = $product->mesg_error;
} }
} }
else else
{ {
$_GET["action"] = 're-edit'; $_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)); llxHeader("","",$langs->trans("CardProduct".$product->type));
@ -300,8 +303,12 @@ if ($_GET["action"] == 'create')
} }
else else
{ {
/*
* Fiche produit
*/
if ($_GET["id"]) if ($_GET["id"])
{ {
if ($_GET["action"] <> 're-edit') if ($_GET["action"] <> 're-edit')
{ {
$product = new Product($db); $product = new Product($db);
@ -314,7 +321,7 @@ else
if ($_GET["action"] <> 'edit' && $_GET["action"] <> 're-edit') if ($_GET["action"] <> 'edit' && $_GET["action"] <> 're-edit')
{ {
/* /*
* Fiche en visu * En mode visu
*/ */
// Zone recherche // Zone recherche
@ -514,7 +521,12 @@ else
*/ */
if (($_GET["action"] == 'edit' || $_GET["action"] == 're-edit') && $user->rights->produit->creer) 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 "<form action=\"fiche.php\" method=\"post\">\n";
print '<input type="hidden" name="action" value="update">'; print '<input type="hidden" name="action" value="update">';