* Copyright (C) 2006 Laurent Destailleur * Copyright (C) 2006 Regis Houssin * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * $Id$ * $Source$ */ /** \file htdocs/categories/fiche.php \ingroup categorie \brief Page creation nouvelle categorie */ require "./pre.inc.php"; require_once(DOL_DOCUMENT_ROOT."/categories/categorie.class.php"); if (!$user->rights->categorie->lire) accessforbidden(); if (isset ($_REQUEST['choix'])) { $nbcats = $_REQUEST['choix']; } else { // par défault, une nouvelle catégorie sera dans une seule catégorie mère $nbcats = 1; } llxHeader("","",$langs->trans("Categories")); $html = new Form($db); // Action ajout d'un produit ou service if ($_POST["action"] == 'add' && $user->rights->produit->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 (!$categorie->label || !$categorie->description) { $_GET["action"] = 'create'; $ok = false; } if ($ok) { if (sizeof($cats_meres) > 1 && sizeof(array_unique($cats_meres)) != sizeof($cats_meres)) { // alors il y a des valeurs en double print '

'.$langs->trans("ErrSameCatSelected").'

'; $_GET["action"] = 'create'; $ok = false; } } 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"] = ''; } } } } } /* * Fiche en mode création */ if ($user->rights->produit->creer) { if ($_GET["action"] == 'create' || $_POST["addcat"] == 'addcat') { print '
'; print ''; print ''; print ''; print ''; 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 ''; } /* * 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("Dernière modification $Date$ révision $Revision$"); ?>