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 ''; 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 '
'; ?>
+ - - - - - get_all_categories ();//on récupère toutes les catégories et leurs attributs - - for ($i = 0 ; $i < $nbcats ; $i++) - { - print "\n"; - } - - ?> + trans("In"); ?> + select_all_categories($categorie->id_mere);?> + + - +
trans("Label"); ?> :
trans("Description"); ?> :
- trans("In"); ?> - - trans("categories"); ?> - - " name="ok" id="ok" /> -
"; - print $langs->trans("Categorie")." ".($i+1)."
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 - ?> -
-

trans("ValidateFields"); ?> ?

- - - - - $cat_mere) - { - echo ""; - } - ?> -
-
'; diff --git a/htdocs/categories/fiche.php b/htdocs/categories/fiche.php index f5d677afd32..33a91350d0a 100644 --- a/htdocs/categories/fiche.php +++ b/htdocs/categories/fiche.php @@ -46,213 +46,95 @@ $html = new Form($db); -// Action ajout d'un produit ou service -if ($_POST["action"] == 'add' && $user->rights->produit->creer) +// Action ajout d'une catégorie +if ($_POST["action"] == 'add' && $user->rights->categorie->creer) { $categorie = new Categorie($db); $categorie->label = stripslashes($_POST["nom"]); $categorie->description = stripslashes($_POST["description"]); - $cats_meres = isset($_POST['catsMeres']) ? $_POST['catsMeres'] : array(); - $ok = true; + if($_POST['catMere'] != "-1") + $categorie->id_mere = stripslashes($_POST['catMere']); + if (!$categorie->label || !$categorie->description) { $_GET["action"] = 'create'; - $ok = false; + $categorie->error = "Le libellé ou la description n'a pas été renseigné"; } - - if ($ok) + if ($categorie->error =="") { - if (sizeof($cats_meres) > 1 && sizeof(array_unique($cats_meres)) != sizeof($cats_meres)) + if ($categorie->create() > 0) { - // alors il y a des valeurs en double - print '

'.$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 ''; + 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 '
'; + } } -/* - * Fiche en mode création - */ - if ($user->rights->produit->creer) { + /* + * Fiche en mode création + */ if ($_GET["action"] == 'create' || $_POST["addcat"] == 'addcat') { + if($categorie->error != "") + { + print '
'; + print $categorie->error; + print '
'; + } print '
'; print ''; print ''; print ''; print ''; - - $catsMeres = isset($_POST['catsMeres']) ? $_POST['catsMeres'] : array(); - foreach ($catsMeres as $id => $cat_mere) - { - print ''; - } - print_fiche_titre($langs->trans("CreateCat")); print ''; print ''; print ''; print ''; - print ''; - print $html->select_all_categories($nbcats); + print $html->select_all_categories(); print ''; } - - - /* - * Action confirmation de création de la catégorie - */ - - if ($_GET["action"] == 'confirmed') - { - print_titre($langs->trans("CatCreated")); - - 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").' '; - print $langs->trans("categories"); - print ''; - print ''; - print '
'; print ''; print '
'; - 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 '
'; - } } - - - 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 -foreach ($cats_meres as $nb => $cat_mere) -{ -if ($cat_mere == -1) -{ -echo "

".$langs->trans ("ErrForgotCat")." ".($nb+1)."

"; -$OK = false; -} -} - -// si les champs de description sont mal renseignés -if ($_POST["nom"] == '') -{ -echo "

".$langs->trans ("ErrForgotField")." \"".$langs->trans ("Label")."\"

"; -$OK = false; -} -else if ($categorie->already_exists($_POST["nom"],$cat_mere)) // on regarde si le nom n'existe pas déjà en tant que catégorie ou sous-catégorie -{ -echo "

".$langs->trans ("ErrCatAlreadyExists")."

"; -$OK = false; -} - -if ($_POST["description"] == '') -{ -echo "

".$langs->trans ("ErrForgotField")." \"".$langs->trans ("Description")."\"

"; -$OK = false; -} - -// vérification pour savoir si tous les champs sont corrects -if ($OK) -{ -$nom = htmlspecialchars(stripslashes($_REQUEST['nom']) ,ENT_QUOTES); -$description = htmlspecialchars(stripslashes($_REQUEST['description']),ENT_QUOTES); -// creation de champs caches pour etre appele dans la classe de traitement -?> -
-
-

trans ("ValidateFields"); ?> ? - - - - - $cat_mere) -{ -echo ""; -} -?> -

-
-close(); llxFooter('$Date$ - $Revision$');