diff --git a/htdocs/categories/edit.php b/htdocs/categories/edit.php index 5903b5d88af..3f0f0d91bd6 100644 --- a/htdocs/categories/edit.php +++ b/htdocs/categories/edit.php @@ -17,12 +17,11 @@ */ require "./pre.inc.php"; +$user->getrights(); - -if (false && (!isset ($_REQUEST['id']) || !$user->rights->categories->lire)) +if (!$user->rights->categorie->lire) accessforbidden(); -// toujours pas trouvé comment mettre les droits qui vont bien - + llxHeader("","",$langs->trans("Categories")); print_titre($langs->trans("ModifCat")); @@ -31,152 +30,73 @@ print '
| ';
+$categorie = new Categorie ($db, $_REQUEST['id']);
+$html = new Form($db);
-$c = new Categorie ($db, $_REQUEST['id']);
-if (isset ($_REQUEST['cats_meres']))
+// Action mise à jour d'une catégorie
+if ($_POST["action"] == 'update' && $user->rights->categorie->creer)
{
- $cats_meres = $_REQUEST['cats_meres'];
-}
-else
-{
- $cats_meres = array ();
- foreach ($c->get_meres () as $mere)
- {
- $cats_meres[] = $mere->id;
- }
-}
-$label = isset ($_REQUEST['nom']) ? $_REQUEST['nom'] : $c->label;
-$description = isset ($_REQUEST['description']) ? $_REQUEST['description'] : $c->description;
-$nbcats = isset ($_REQUEST['choix']) ? $_REQUEST['choix'] : sizeof ($cats_meres);
+ $categorie->label = stripslashes($_POST["nom"]);
+ $categorie->description = stripslashes($_POST["description"]);
+ if($_POST['catMere'] != "-1")
+ $categorie->id_mere = stripslashes($_POST['catMere']);
+
+
+ if (!$categorie->label || !$categorie->description)
+ {
+ $_GET["action"] = 'create';
+ $categorie->error = "Le libellé ou la description n'a pas été renseigné";
+ }
+ if ($categorie->error =="")
+ {
+ if ($categorie->update() > 0)
+ {
+ $_GET["action"] = 'confirmed';
+ $_POST["addcat"] = '';
+ }
+ }
+}
+if($categorie->error != "")
+{
+ print ' ';
+ print $categorie->error;
+ print ' ';
+}
print ' |
| ';
?>
1 && sizeof (array_unique ($cats_meres)) != sizeof ($cats_meres))
- { // alors il y a des valeurs en double
- echo " ".$langs->trans ("ErrSameCatSelected")." "; - $OK = false; - } - - // vérification des champs renseignés par l'utilisateur: si il y a un problème, on affiche un message d'erreur - if (sizeof ($cats_meres) > 0) foreach ($cats_meres as $nb => $cat_mere) - { - if ($cat_mere == -1) - { - echo "".$langs->trans ("ErrForgotCat")." "; - $OK = false; - } - } - - // si les champs de description sont mal renseignés - if ($label == '') - { - echo "".$langs->trans ("ErrForgotField")." "; - $OK = false; - } - - // vérification pour savoir si tous les champs sont corrects - if ($OK) - { - // creation de champs caches pour etre appele dans la classe de traitement - ?> - - |
'.$langs->trans("ErrSameCatSelected").'
'; - $_GET["action"] = 'create'; - $ok = false; + $_GET["action"] = 'confirmed'; + $_POST["addcat"] = ''; } } + /* + * Action confirmation de création de la catégorie + */ - if ($ok) - { - $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; - } - else - { - $_GET["action"] = 'confirmed'; - $_POST["addcat"] = ''; - } - } - } - } + if ($_GET["action"] == 'confirmed') + { + print_titre($langs->trans("CatCreated")); + print '| ';
+ if ($_error == 3)
+ {
+ print ' '.$langs->trans("ImpossibleAddCat").' '.$categorie->label.' '; + } + else + { + print ''.$langs->trans("TheCategorie").' '.$categorie->label.' '.$langs->trans("WasAddedSuccessfully").' '; + if ($_error == 2) + { + print ''.$langs->trans("TheCategorie").' '.$mere->label.' ('.$res.'). '; + } + } + print ' |