From bc6df6bae64ebf79d034f26400b9c174a4dbaad7 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Wed, 22 Feb 2006 19:09:59 +0000 Subject: [PATCH] =?UTF-8?q?d=E9but=20restructuration=20du=20code=20des=20c?= =?UTF-8?q?at=E9gories?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- htdocs/categories/fiche.php | 57 ++++++++++++++++++++++++++----------- 1 file changed, 41 insertions(+), 16 deletions(-) diff --git a/htdocs/categories/fiche.php b/htdocs/categories/fiche.php index eb264ac5f77..e5368919f4e 100644 --- a/htdocs/categories/fiche.php +++ b/htdocs/categories/fiche.php @@ -53,7 +53,32 @@ if ($_POST["action"] == 'add' && $user->rights->produit->creer) $categorie->description = stripslashes($_POST["description"]); $cats_meres = isset($_POST['cats_meres']) ? $_POST['cats_meres'] : array(); - $_GET["action"] = 'confirmed'; + if (!$categorie->label || !$categorie->description) + { + $_GET["action"] = 'create'; + } + else + { + $res = $categorie->create(); + if ($res < 0) + { + $_error = 3 + } + else + { + foreach ($cats_meres as $id) + { + $mere = new Categorie($db, $id); + $res = $mere->add_fille($categorie); + if ($res < 0) + { + $_error = 2 + } + } + } + $_GET["action"] = 'confirmed'; + $_POST["addcat"] = ''; + } } @@ -75,15 +100,15 @@ if ($user->rights->produit->creer) print ''; print ''; - print ''; print ''; print '
'.$langs->trans("Label").''; + print ''.$langs->trans("Label").''; if ($_error == 1) { print $lang->trans("ErrCatAlreadyExists"); } print'
'.$langs->trans("Description").''; - print '
'; print $langs->trans("AddIn").' '; print $html->select_nombre_sous_categorie($nbcats,"choix").' '; @@ -110,16 +135,16 @@ if ($user->rights->produit->creer) print ''; print '
'; - $categorie = new Categorie($db); + //$categorie = new Categorie($db); - $categorie->label = $_REQUEST["nom"]; - $categorie->description = $_REQUEST["description"]; + //$categorie->label = $_REQUEST["nom"]; + //$categorie->description = $_REQUEST["description"]; - $cats_meres = isset($_REQUEST['cats_meres']) ? $_REQUEST['cats_meres'] : array(); + //$cats_meres = isset($_REQUEST['cats_meres']) ? $_REQUEST['cats_meres'] : array(); - $res = $categorie->create(); + //$res = $categorie->create(); - if ($res < 0) + if ($_error == 3) { print '

'.$langs->trans("ImpossibleAddCat").' '.$categorie->label.'

'; } @@ -127,16 +152,16 @@ if ($user->rights->produit->creer) { print '

'.$langs->trans("TheCategorie").' '.$categorie->label.' '.$langs->trans("WasAddedSuccessfully").'

'; - foreach ($cats_meres as $id) - { - $mere = new Categorie($db, $id); - $res = $mere->add_fille($categorie); + //foreach ($cats_meres as $id) + //{ + //$mere = new Categorie($db, $id); + //$res = $mere->add_fille($categorie); - if ($res < 0) + if ($_error == 2) { print '

'.$langs->trans("TheCategorie").' '.$mere->label.' ('.$res.').

'; } - } + //} } print '
'; }