From 3843925023484f323fe2cef965a75e0c4d25d438 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Sat, 19 Mar 2011 12:47:39 +0000 Subject: [PATCH] Fix: uniformize code --- htdocs/categories/fiche.php | 109 ++++++++++++++++-------------------- 1 file changed, 48 insertions(+), 61 deletions(-) diff --git a/htdocs/categories/fiche.php b/htdocs/categories/fiche.php index eaf3687afe3..a0ec25fbd17 100644 --- a/htdocs/categories/fiche.php +++ b/htdocs/categories/fiche.php @@ -1,7 +1,7 @@ * Copyright (C) 2006-2010 Laurent Destailleur - * Copyright (C) 2005-2010 Regis Houssin + * Copyright (C) 2005-2011 Regis Houssin * Copyright (C) 2007 Patrick Raguin * * This program is free software; you can redistribute it and/or modify @@ -36,28 +36,23 @@ $langs->load("categories"); $socid=GETPOST('socid'); if (!$user->rights->categorie->lire) accessforbidden(); -if (GETPOST('choix')) +$action = GETPOST('action'); +$cancel = GETPOST('cancel'); +$origin = GETPOST('origin'); +$catorigin = GETPOST('catorigin'); +$nbcats = (GETPOST('choix') ? GETPOST('choix') : 1); +$type = GETPOST('type'); +$urlfrom = GETPOST("urlfrom"); + +if ($origin) { - $nbcats = GETPOST('choix'); -} -else -{ // par default, une nouvelle categorie sera dans une seule categorie mere - $nbcats = 1; + if ($type == 0) $idProdOrigin = $origin; + if ($type == 1) $idSupplierOrigin = $origin; + if ($type == 2) $idCompanyOrigin = $origin; + if ($type == 3) $idMemberOrigin = $origin; } -if (GETPOST('origin')) -{ - if ($_GET['type'] == 0) $idProdOrigin = GETPOST('origin'); - if ($_GET['type'] == 1) $idSupplierOrigin = GETPOST('origin'); - if ($_GET['type'] == 2) $idCompanyOrigin = GETPOST('origin'); - if ($_GET['type'] == 3) $idMemberOrigin = GETPOST('origin'); -} - -if (GETPOST('catorigin')) -{ - if ($_GET['type'] == 0) $idCatOrigin = GETPOST('catorigin'); -} -$urlfrom=GETPOST("urlfrom"); +if ($catorigin && $type == 0) $idCatOrigin = $catorigin; /* @@ -65,10 +60,10 @@ $urlfrom=GETPOST("urlfrom"); */ // Add action -if ($_POST["action"] == 'add' && $user->rights->categorie->creer) +if ($action == 'add' && $user->rights->categorie->creer) { // Action ajout d'une categorie - if ($_POST["cancel"]) + if ($cancel) { if ($urlfrom) { @@ -77,70 +72,69 @@ if ($_POST["action"] == 'add' && $user->rights->categorie->creer) } else if ($idProdOrigin) { - header("Location: ".DOL_URL_ROOT.'/categories/categorie.php?id='.$idProdOrigin.'&type='.$_GET["type"]); + header("Location: ".DOL_URL_ROOT.'/categories/categorie.php?id='.$idProdOrigin.'&type='.$type); exit; } else if ($idCompanyOrigin) { - header("Location: ".DOL_URL_ROOT.'/categories/categorie.php?socid='.$idCompanyOrigin.'&type='.$_GET["type"]); + header("Location: ".DOL_URL_ROOT.'/categories/categorie.php?socid='.$idCompanyOrigin.'&type='.$type); exit; } else if ($idSupplierOrigin) { - header("Location: ".DOL_URL_ROOT.'/categories/categorie.php?socid='.$idSupplierOrigin.'&type='.$_GET["type"]); + header("Location: ".DOL_URL_ROOT.'/categories/categorie.php?socid='.$idSupplierOrigin.'&type='.$type); exit; } else if ($idMemberOrigin) { - header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idMemberOrigin.'&type='.$_GET["type"]); + header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idMemberOrigin.'&type='.$type); exit; } else if ($idCatOrigin) { - header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idCatOrigin.'&type='.$_GET["type"]); + header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idCatOrigin.'&type='.$type); exit; } else { - header("Location: ".DOL_URL_ROOT.'/categories/index.php?leftmenu=cat&type='.$_GET["type"]); + header("Location: ".DOL_URL_ROOT.'/categories/index.php?leftmenu=cat&type='.$type); exit; } } - $categorie = new Categorie($db); + $object = 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"]; + $object->label = $_POST["nom"]; + $object->description = $_POST["description"]; + $object->socid = ($_POST["socid"] ? $_POST["socid"] : 'null'); + $object->visible = $_POST["visible"]; + $object->type = $type; - if($_POST['catMere'] != "-1") - $categorie->id_mere = $_POST['catMere']; + if($_POST['catMere'] != "-1") $object->id_mere = $_POST['catMere']; - if (! $categorie->label) + if (! $object->label) { - $categorie->error = $langs->trans("ErrorFieldRequired",$langs->transnoentities("Ref")); + $object->error = $langs->trans("ErrorFieldRequired",$langs->transnoentities("Ref")); $_GET["action"] = 'create'; } // Create category in database - if (! $categorie->error) + if (! $object->error) { - $result = $categorie->create(); + $result = $object->create(); if ($result > 0) { - $_GET["action"] = 'confirmed'; + $action = 'confirmed'; $_POST["addcat"] = ''; } } } // Confirm action -if ($_POST["action"] == 'add' && $user->rights->categorie->creer) +if ($action == 'add' && $user->rights->categorie->creer) { // Action confirmation de creation categorie - if ($_GET["action"] == 'confirmed') + if ($action == 'confirmed') { if ($urlfrom) { @@ -164,7 +158,7 @@ if ($_POST["action"] == 'add' && $user->rights->categorie->creer) } else if ($idMemberOrigin) { - header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idMemberOrigin.'&type='.$_GET["type"]); + header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idMemberOrigin.'&type='.$type); exit; } else if ($idCatOrigin) @@ -173,7 +167,7 @@ if ($_POST["action"] == 'add' && $user->rights->categorie->creer) exit; } - header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$result.'&type='.$_POST["type"]); + header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$result.'&type='.$type); exit; } } @@ -191,46 +185,40 @@ if ($user->rights->categorie->creer) /* * Fiche en mode creation */ - if ($_GET["action"] == 'create' || $_POST["addcat"] == 'addcat') + if ($action == 'create' || $_POST["addcat"] == 'addcat') { - print '
'; + print ''; print ''; print ''; print ''; print ''; print ''; - print ''; - if (GETPOST('origin')) - { - print ''; - } - if (GETPOST('catorigin')) - { - print ''; - } + print ''; print ''; + if ($origin) print ''; + if ($catorigin) print ''; print_fiche_titre($langs->trans("CreateCat")); - dol_htmloutput_errors($categorie->error); + dol_htmloutput_errors($object->error); print ''; // Ref print ''; - print ''; // Description print ''; // Parent category print ''; print '
'.$langs->trans("Ref").''; + print ''.$langs->trans("Ref").''; print'
'.$langs->trans("Description").''; require_once(DOL_DOCUMENT_ROOT."/lib/doleditor.class.php"); - $doleditor=new DolEditor('description',$categorie->description,'',200,'dolibarr_notes','',false,true,$conf->fckeditor->enabled && $conf->global->FCKEDITOR_ENABLE_PRODUCTDESC,ROWS_6,50); + $doleditor=new DolEditor('description',$object->description,'',200,'dolibarr_notes','',false,true,$conf->fckeditor->enabled && $conf->global->FCKEDITOR_ENABLE_PRODUCTDESC,ROWS_6,50); $doleditor->Create(); print '
'.$langs->trans ("AddIn").''; - print $html->select_all_categories($_GET['type'],GETPOST('catorigin')); + print $html->select_all_categories($type,$catorigin); print '
'; @@ -245,7 +233,6 @@ if ($user->rights->categorie->creer) } } - $db->close(); llxFooter('$Date$ - $Revision$');