From b7b4c9d7518d6688ed31667e10a98f2ea01b29fc Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 23 Oct 2004 21:34:49 +0000 Subject: [PATCH] Fix: Correction bug #9821 --- htdocs/product.class.php | 46 +++++++++++++++++++++++++--------------- htdocs/product/fiche.php | 30 ++++++++++++++++++-------- 2 files changed, 50 insertions(+), 26 deletions(-) diff --git a/htdocs/product.class.php b/htdocs/product.class.php index 9d6c1b0eda9..54888754a68 100644 --- a/htdocs/product.class.php +++ b/htdocs/product.class.php @@ -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; + } + } } /** diff --git a/htdocs/product/fiche.php b/htdocs/product/fiche.php index 035f5ef66f1..830d29c373b 100644 --- a/htdocs/product/fiche.php +++ b/htdocs/product/fiche.php @@ -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 !' . "
" . $product->mesg_error; + $_GET["id"] = $_POST["id"]; + $mesg = $product->mesg_error; } } else { $_GET["action"] = 're-edit'; - $mesg = 'Fiche non mise à jour !' . "
" . $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 '
'.$mesg.'

'; + } + print "
\n"; print ''; print '';