* Copyright (C) 2006-2010 Laurent Destailleur * Copyright (C) 2005-2010 Regis Houssin * Copyright (C) 2007 Patrick Raguin * * 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. */ /** * \file htdocs/categories/fiche.php * \ingroup category * \brief Page to create a new category * \version $Id$ */ require("../main.inc.php"); require_once(DOL_DOCUMENT_ROOT."/categories/class/categorie.class.php"); // If socid provided by ajax company selector if (! empty($_REQUEST['socid_id'])) { $_GET['socid'] = $_GET['socid_id']; $_POST['socid'] = $_POST['socid_id']; $_REQUEST['socid'] = $_REQUEST['socid_id']; } // Security check $socid=isset($_GET['socid'])?$_GET['socid']:$_POST['socid']; if (!$user->rights->categorie->lire) accessforbidden(); if (isset ($_REQUEST['choix'])) { $nbcats = $_REQUEST['choix']; } else { // par default, une nouvelle categorie sera dans une seule categorie mere $nbcats = 1; } if ($_REQUEST['origin']) { if ($_GET['type'] == 0) $idProdOrigin = $_REQUEST['origin']; if ($_GET['type'] == 1) $idSupplierOrigin = $_REQUEST['origin']; if ($_GET['type'] == 2) $idCompanyOrigin = $_REQUEST['origin']; if ($_GET['type'] == 3) $idMemberOrigin = $_REQUEST['origin']; } if ($_REQUEST['catorigin']) { if ($_GET['type'] == 0) $idCatOrigin = $_REQUEST['catorigin']; } $urlfrom=isset($_REQUEST["urlfrom"])?$_REQUEST["urlfrom"]:''; /* * Actions */ if ($_POST["action"] == 'add' && $user->rights->categorie->creer) { // Action ajout d'une categorie if ($_POST["cancel"]) { if ($urlfrom) { header("Location: ".$urlfrom); exit; } else if ($idProdOrigin) { header("Location: ".DOL_URL_ROOT.'/categories/categorie.php?id='.$idProdOrigin.'&type='.$_GET["type"]); exit; } else if ($idCompanyOrigin) { header("Location: ".DOL_URL_ROOT.'/categories/categorie.php?socid='.$idCompanyOrigin.'&type='.$_GET["type"]); exit; } else if ($idSupplierOrigin) { header("Location: ".DOL_URL_ROOT.'/categories/categorie.php?socid='.$idSupplierOrigin.'&type='.$_GET["type"]); exit; } else if ($idMemberOrigin) { header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idMemberOrigin.'&type='.$_GET["type"]); exit; } else if ($idCatOrigin) { header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idCatOrigin.'&type='.$_GET["type"]); exit; } else { header("Location: ".DOL_URL_ROOT.'/categories/index.php?leftmenu=cat&type='.$_GET["type"]); exit; } } $categorie = new Categorie($db); $categorie->label = $_POST["nom"]; $categorie->description = $_POST["description"]; $categorie->socid = ($_POST["socid"] ? $_POST["socid"] : 'null'); $categorie->visible = $_POST["visible"]; $categorie->type = $_POST["type"]; if($_POST['catMere'] != "-1") $categorie->id_mere = $_POST['catMere']; if (! $categorie->label) { $categorie->error = $langs->trans("ErrorFieldRequired",$langs->transnoentities("Ref")); $_GET["action"] = 'create'; } else if (! $categorie->description) { $categorie->error = $langs->trans("ErrorFieldRequired",$langs->transnoentities("Description")); $_GET["action"] = 'create'; } // Create category in database if (! $categorie->error) { $result = $categorie->create(); if ($result > 0) { $_GET["action"] = 'confirmed'; $_POST["addcat"] = ''; } } } if ($_POST["action"] == 'add' && $user->rights->categorie->creer) { // Action confirmation de creation categorie if ($_GET["action"] == 'confirmed') { if ($urlfrom) { header("Location: ".$urlfrom); exit; } else if ($idProdOrigin) { header("Location: ".DOL_URL_ROOT.'/categories/categorie.php?id='.$idProdOrigin.'&mesg='.urlencode($langs->trans("CatCreated"))); exit; } else if ($idCompanyOrigin) { header("Location: ".DOL_URL_ROOT.'/categories/categorie.php?socid='.$idCompanyOrigin.'&mesg='.urlencode($langs->trans("CatCreated"))); exit; } else if ($idSupplierOrigin) { header("Location: ".DOL_URL_ROOT.'/categories/categorie.php?socid='.$idSupplierOrigin.'&mesg='.urlencode($langs->trans("CatCreated"))); exit; } else if ($idMemberOrigin) { header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idMemberOrigin.'&type='.$_GET["type"]); exit; } else if ($idCatOrigin) { header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idCatOrigin.'&mesg='.urlencode($langs->trans("CatCreated"))); exit; } header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$result.'&type='.$_POST["type"]); exit; } } /* * View */ llxHeader("","",$langs->trans("Categories")); $html = new Form($db); if ($user->rights->categorie->creer) { /* * Fiche en mode creation */ if ($_GET["action"] == 'create' || $_POST["addcat"] == 'addcat') { print '
'; print ''; print ''; print ''; print ''; print ''; print ''; if ($_REQUEST['origin']) { print ''; } if ($_REQUEST['catorigin']) { print ''; } print ''; print_fiche_titre($langs->trans("CreateCat")); if ($categorie->error) { print '
'; print $categorie->error; print '
'; } print ''; print ''; print ''; print ''; print ''; print '
'.$langs->trans("Ref").''; print'
'.$langs->trans("Description").''; if ($conf->fckeditor->enabled && $conf->global->FCKEDITOR_ENABLE_PRODUCTDESC) { require_once(DOL_DOCUMENT_ROOT."/lib/doleditor.class.php"); $doleditor=new DolEditor('description',$categorie->description,200,'dolibarr_notes'); $doleditor->Create(); } else { print ''; } print '
'.$langs->trans ("AddIn").''; print $html->select_all_categories($_GET['type'],$_REQUEST['catorigin']); print '
'; print '

'; print ''; print '     '; print ''; print '
'; print '
'; } } $db->close(); llxFooter('$Date$ - $Revision$'); ?>