diff --git a/htdocs/categories/categorie.class.php b/htdocs/categories/categorie.class.php index 81e1de175e8..64b36a8cc3b 100644 --- a/htdocs/categories/categorie.class.php +++ b/htdocs/categories/categorie.class.php @@ -832,12 +832,14 @@ class Categorie /** * Retourne les catégories contenant le produit $id */ - function containing ($id,$type) + function containing ($id,$type,$typeid) { $cats = array (); - $sql = "SELECT fk_categorie FROM ".MAIN_DB_PREFIX."categorie_".$type." "; - $sql .= "WHERE fk_".$type." = ".$id; + $sql = "SELECT ct.fk_categorie"; + $sql.= " FROM ".MAIN_DB_PREFIX."categorie_".$type." as ct"; + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."categorie as c ON ct.fk_categorie = c.rowid"; + $sql.= " WHERE ct.fk_".$type." = ".$id." AND c.type = ".$typeid; $res = $this->db->query ($sql); @@ -887,7 +889,29 @@ class Categorie } - + /** + * \brief Vérifie le type de la catégorie + * + */ + function verify_type($id) + { + $sql = "SELECT type FROM ".MAIN_DB_PREFIX."categorie "; + $sql .= "WHERE rowid = ".$id." "; + + $result = $this->db->query ($sql); + if ($result) + { + $obj = $this->db->fetch_object($result); + + return $obj->type; + } + else + { + $this->error=$this->db->error().' sql='.$sql; + dolibarr_print_error('',$this->error); + return -1; + } + } diff --git a/htdocs/categories/categorie.php b/htdocs/categories/categorie.php index 822c877d1bc..8cdb7f5eb81 100644 --- a/htdocs/categories/categorie.php +++ b/htdocs/categories/categorie.php @@ -1,9 +1,9 @@ * Copyright (C) 2005 Brice Davoleau - * Copyright (C) 2005-2006 Regis Houssin + * Copyright (C) 2005-2007 Regis Houssin * Copyright (C) 2006-2007 Laurent Destailleur - * Copyright (C) 2007 Patrick Raguin + * 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 @@ -26,22 +26,31 @@ /** \file htdocs/categories/categorie.php \ingroup category - \brief Page de l'onglet categories de produits + \brief Page de l'onglet categories \version $Revision$ */ require("./pre.inc.php"); -require_once(DOL_DOCUMENT_ROOT."/lib/company.lib.php"); -require_once(DOL_DOCUMENT_ROOT."/societe.class.php"); require_once(DOL_DOCUMENT_ROOT."/categories/categorie.class.php"); $langs->load("categories"); -$langs->load("companies"); -$socid = isset($_GET["socid"])?$_GET["socid"]:''; +if ($_REQUEST["socid"]) +{ + $type = 'societe'; + $objectid = isset($_REQUEST["socid"])?$_REQUEST["socid"]:''; +} +else if ($_REQUEST["id"] || $_REQUEST["ref"]) +{ + $type = 'produit'; +} +else +{ + accessforbidden(); +} // Sécurité d'accès client et commerciaux -$socid = restrictedArea($user, 'societe', $socid); +$objectid = restrictedArea($user, $type, $objectid); $mesg = ''; @@ -50,27 +59,46 @@ $mesg = ''; * Actions */ -//on veut supprimer une catégorie -if ($_REQUEST["removecat"] && $user->rights->societe->creer) +//Suppression d'un objet d'une catégorie +if ($_REQUEST["removecat"]) { - $soc = new Societe($db); - if ($_REQUEST["socid"]) $result = $soc->fetch($_REQUEST["socid"]); - + if ($_REQUEST["socid"] && $user->rights->societe->creer) + { + $object = new Societe($db); + $result = $object->fetch($_REQUEST["socid"]); + } + else if (($_REQUEST["id"] || $_REQUEST["ref"]) && $user->rights->produit->creer) + { + $object = new Product($db); + if ($_REQUEST["ref"]) $result = $object->fetch('',$_REQUEST["ref"]); + if ($_REQUEST["id"]) $result = $object->fetch($_REQUEST["id"]); + $type = 'product'; + } $cat = new Categorie($db,$_REQUEST["removecat"]); - $result=$cat->del_type($soc,"societe"); + $result=$cat->del_type($object,$type); } -//on veut ajouter une catégorie -if (isset($_REQUEST["catMere"]) && $_REQUEST["catMere"]>=0 && $user->rights->societe->creer) +//Ajoute d'un objet dans une catégorie +if (isset($_REQUEST["catMere"]) && $_REQUEST["catMere"]>=0) { - $soc = new Societe($db); - if ($_REQUEST["socid"]) $result = $soc->fetch($_REQUEST["socid"]); - + if ($_REQUEST["socid"] && $user->rights->societe->creer) + { + $object = new Societe($db); + $result = $object->fetch($_REQUEST["socid"]); + } + else if (($_REQUEST["id"] || $_REQUEST["ref"]) && $user->rights->produit->creer) + { + $object = new Product($db); + if ($_REQUEST["ref"]) $result = $object->fetch('',$_REQUEST["ref"]); + if ($_REQUEST["id"]) $result = $object->fetch($_REQUEST["id"]); + $type = 'product'; + } + $cat = new Categorie($db,$_REQUEST["catMere"]); - $result=$cat->add_type($soc,"societe"); + $result=$cat->add_type($object,$type); if ($result >= 0) { - $mesg='
'.$langs->trans("Added").'
'; + $mesg='
'.$langs->trans("WasAddedSuccessfully").'
'; } else { @@ -79,29 +107,26 @@ if (isset($_REQUEST["catMere"]) && $_REQUEST["catMere"]>=0 && $user->rights->so } - - -/* -* Creation de l'objet fournisseur correspondant à l'id -*/ -if ($_GET["socid"] || $_GET["ref"]) -{ - $soc = new Societe($db); - if ($_GET["socid"]) $result = $soc->fetch($_GET["socid"]); - - llxHeader("","",$langs->trans("CardCompany".$soc->type)); -} - - - $html = new Form($db); - /* - * Fiche produit + * Fiche objet client/fournisseur */ -if ($_GET["socid"] || $_GET["ref"]) +if ($_GET["socid"]) { + require_once(DOL_DOCUMENT_ROOT."/lib/company.lib.php"); + require_once(DOL_DOCUMENT_ROOT."/societe.class.php"); + + $langs->load("companies"); + + /* + * Creation de l'objet client/fournisseur correspondant au socid + */ + $soc = new Societe($db); + $result = $soc->fetch($_GET["socid"]); + llxHeader("","",$langs->trans("CardCompany".$soc->type)); + + /* * Affichage onglets */ @@ -109,9 +134,8 @@ if ($_GET["socid"] || $_GET["ref"]) dolibarr_fiche_head($head, 'category', $soc->nom); - print ''; - + print ''; @@ -126,6 +150,15 @@ if ($_GET["socid"] || $_GET["ref"]) if ($soc->check_codeclient() <> 0) print ' '.$langs->trans("WrongCustomerCode"); print ''; } + + if ($soc->fournisseur) + { + print ''; + } print ""; @@ -151,45 +184,120 @@ if ($_GET["socid"] || $_GET["ref"]) print ''; - if ($mesg) print($mesg); + + if ($soc->client) formCategory($db,$soc,$type,2); + print '

'; + if ($soc->fournisseur) formCategory($db,$soc,$type,1); +} +else if ($_GET["id"] || $_GET["ref"]) +{ + /* + * Fiche produit + */ + + require_once(DOL_DOCUMENT_ROOT."/lib/product.lib.php"); + require_once(DOL_DOCUMENT_ROOT."/product.class.php"); + + /* + * Creation de l'objet produit correspondant à l'id + */ + $product = new Product($db); + if ($_GET["ref"]) $result = $product->fetch('',$_GET["ref"]); + if ($_GET["id"]) $result = $product->fetch($_GET["id"]); + + llxHeader("","",$langs->trans("CardProduct".$product->type)); + + + $head=product_prepare_head($product, $user); + $titre=$langs->trans("CardProduct".$product->type); + dolibarr_fiche_head($head, 'category', $titre); + + + print '
'.$langs->trans("Name").''; print $soc->nom; print '
'; + print $langs->trans('SupplierCode').''; + print $soc->code_fournisseur; + if ($soc->check_codefournisseur() <> 0) print ' '.$langs->trans("WrongSupplierCode"); + print '
".$langs->trans('Address')."".nl2br($soc->adresse)."
'; + print ""; + // Reference + print ''; + print ''; + + // Libelle + print ''; + print ''; + + // Prix + print ''; + + // Statut + print ''; + + print '
'.$langs->trans("Ref").''; + print $html->showrefnav($product,'ref','',1,'ref'); + print '
'.$langs->trans("Label").''.$product->libelle.'
'.$langs->trans("SellingPrice").''; + if ($product->price_base_type == 'TTC') + { + print price($product->price_ttc).' '.$langs->trans($product->price_base_type); + } + else + { + print price($product->price).' '.$langs->trans($product->price_base_type); + } + print '
'.$langs->trans("Status").''; + print $product->getLibStatut(2); + print '
'; + + print ''; + + if ($mesg) print($mesg); + + formCategory($db,$product,'product',0); + +} /* - * Barre d'actions + * Fonction Barre d'actions * */ - print '
'; - if ($user->rights->categorie->creer) + +function formCategory($db,$object,$type,$typeid) +{ + global $user,$langs,$html; + + if ($type == 'societe') { - print ''.$langs->trans("NewCat").''; + $nameId = 'socid'; + if ($typeid == 2) $title = $langs->trans("CustomersCategoriesShort"); + if ($typeid == 1) $title = $langs->trans("SuppliersCategoriesShort"); } - print '
'; - - + else + { + $nameId = 'id'; + } + // Formulaire ajout dans une categorie if ($user->rights->societe->creer) { print '
'; - print '
'; + print_fiche_titre($title); + print ''; print ''; print ''; + print $html->select_all_categories($typeid).' '; + if ($user->rights->categorie->creer) + { + print ''; + } print ''; print '
'; print $langs->trans("ClassifyInCategory").' '; - print $html->select_all_categories(2,$categorie->id_mere).' '; + print ''.$langs->trans("NewCat").''; + print '
'; print '
'; print '
'; } - $c = new Categorie($db); - - if ($_GET["socid"]) - { - $cats = $c->containing($_REQUEST["socid"],"societe"); - } - + $cats = $c->containing($object->id,$type,$typeid); if (sizeof($cats) > 0) { @@ -211,9 +319,9 @@ if ($_GET["socid"] || $_GET["ref"]) // Lien supprimer print ''; - if ($user->rights->societe->creer) + if ($user->rights->$type->creer) { - print ""; + print ""; print img_delete($langs->trans("DeleteFromCat")).' '; print $langs->trans("DeleteFromCat").""; } @@ -225,7 +333,6 @@ if ($_GET["socid"] || $_GET["ref"]) print "\n"; } - } print "
\n"; } @@ -233,16 +340,13 @@ if ($_GET["socid"] || $_GET["ref"]) { print $langs->trans("ErrorUnknown"); } - else { print $langs->trans("CompanyHasNoCategory")."
"; } - -} +} $db->close(); - llxFooter('$Date$ - $Revision$'); ?> diff --git a/htdocs/categories/fiche.php b/htdocs/categories/fiche.php index 657e5f483cd..57a840d9427 100644 --- a/htdocs/categories/fiche.php +++ b/htdocs/categories/fiche.php @@ -1,7 +1,7 @@ * Copyright (C) 2006 Laurent Destailleur - * Copyright (C) 2006 Regis Houssin + * Copyright (C) 2005-2007 Regis Houssin * Copyright (C) 2007 Patrick Raguin * * This program is free software; you can redistribute it and/or modify @@ -105,7 +105,7 @@ if ($_POST["action"] == 'add' && $user->rights->categorie->creer) if ($idProdOrigin) { - print ''.$langs->trans("ReturnInProduct").''; + print ''.$langs->trans("ReturnInProduct").''; } if ($idSupplierOrigin || $idCompanyOrigin) { diff --git a/htdocs/langs/en_US/categories.lang b/htdocs/langs/en_US/categories.lang index c9bc28bc8bf..2b7ca74e940 100644 --- a/htdocs/langs/en_US/categories.lang +++ b/htdocs/langs/en_US/categories.lang @@ -19,7 +19,7 @@ CatList=List of cat AllCats=All categories ViewCat=View category NewCat=Add category -NewCategory=New product/services category +NewCategory=New category ModifCat=Modify category CatCreated=Category added CreateCat=Create category diff --git a/htdocs/langs/fr_FR/categories.lang b/htdocs/langs/fr_FR/categories.lang index 600000a0811..a60206a8802 100644 --- a/htdocs/langs/fr_FR/categories.lang +++ b/htdocs/langs/fr_FR/categories.lang @@ -19,7 +19,7 @@ CatList=Liste des cat AllCats=Toutes les catégories ViewCat=Visualisation de la catégorie NewCat=Nouvelle catégorie -NewCategory=Nouvelle catégorie de produits/services +NewCategory=Nouvelle catégorie ModifCat=Modifier une catégorie CatCreated=Catégorie ajoutée CreateCat=Ajouter une catégorie diff --git a/htdocs/lib/product.lib.php b/htdocs/lib/product.lib.php index 50b18efdae0..ca850f648a1 100644 --- a/htdocs/lib/product.lib.php +++ b/htdocs/lib/product.lib.php @@ -51,7 +51,7 @@ function product_prepare_head($product, $user) //affichage onglet catégorie if ($conf->categorie->enabled) { - $head[$h][0] = DOL_URL_ROOT."/product/categorie.php?id=".$product->id; + $head[$h][0] = DOL_URL_ROOT."/categories/categorie.php?id=".$product->id; $head[$h][1] = $langs->trans('Categories'); $head[$h][2] = 'category'; $h++; diff --git a/htdocs/product/categorie.php b/htdocs/product/categorie.php deleted file mode 100644 index 2b93dc582a0..00000000000 --- a/htdocs/product/categorie.php +++ /dev/null @@ -1,236 +0,0 @@ - - * Copyright (C) 2005 Brice Davoleau - * Copyright (C) 2005-2007 Regis Houssin - * Copyright (C) 2006-2007 Laurent Destailleur - * 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. - * - * $Id$ - * $Source$ - */ - -/** - \file htdocs/product/categorie.php - \ingroup product - \brief Page de l'onglet categories de produits - \version $Revision$ -*/ - -require("./pre.inc.php"); -require_once(DOL_DOCUMENT_ROOT."/lib/product.lib.php"); -require_once(DOL_DOCUMENT_ROOT."/product.class.php"); -require_once(DOL_DOCUMENT_ROOT."/categories/categorie.class.php"); - -$langs->load("categories"); - -if (!$user->rights->produit->lire) accessforbidden(); - -$mesg = ''; - - -/* -* Actions -*/ - -//on veut supprimer une catégorie -if ($_REQUEST["removecat"] && $user->rights->produit->creer) -{ - $product = new Product($db); - if ($_REQUEST["ref"]) $result = $product->fetch('',$_REQUEST["ref"]); - if ($_REQUEST["id"]) $result = $product->fetch($_REQUEST["id"]); - - $cat = new Categorie($db,$_REQUEST["removecat"]); - $result=$cat->del_type($product,"product"); -} - -//on veut ajouter une catégorie -if (isset($_REQUEST["catMere"]) && $_REQUEST["catMere"]>=0 && $user->rights->produit->creer) -{ - $product = new Product($db); - if ($_REQUEST["ref"]) $result = $product->fetch('',$_REQUEST["ref"]); - if ($_REQUEST["id"]) $result = $product->fetch($_REQUEST["id"]); - - $cat = new Categorie($db,$_REQUEST["catMere"]); - $result=$cat->add_type($product,"product"); - if ($result >= 0) - { - $mesg='
'.$langs->trans("Added").'
'; - } - else - { - $mesg='
'.$langs->trans("Error").' '.$cat->error.'
'; - } - -} - - - -/* -* Creation de l'objet produit correspondant à l'id -*/ -if ($_GET["id"] || $_GET["ref"]) -{ - $product = new Product($db); - if ($_GET["ref"]) $result = $product->fetch('',$_GET["ref"]); - if ($_GET["id"]) $result = $product->fetch($_GET["id"]); - - llxHeader("","",$langs->trans("CardProduct".$product->type)); -} - -$html = new Form($db); - -/* - * Fiche produit - */ -if ($_GET["id"] || $_GET["ref"]) -{ - $head=product_prepare_head($product, $user); - $titre=$langs->trans("CardProduct".$product->type); - dolibarr_fiche_head($head, 'category', $titre); - - - print ''; - print ""; - // Reference - print ''; - print ''; - - // Libelle - print ''; - print ''; - - // Prix - print ''; - - // Statut - print ''; - - print '
'.$langs->trans("Ref").''; - print $html->showrefnav($product,'ref','',1,'ref'); - print '
'.$langs->trans("Label").''.$product->libelle.'
'.$langs->trans("SellingPrice").''; - if ($product->price_base_type == 'TTC') - { - print price($product->price_ttc).' '.$langs->trans($product->price_base_type); - } - else - { - print price($product->price).' '.$langs->trans($product->price_base_type); - } - print '
'.$langs->trans("Status").''; - print $product->getLibStatut(2); - print '
'; - - print ''; - - - if ($mesg) print($mesg); - - - /* - * Barre d'actions - * - */ - print '
'; - if ($user->rights->categorie->creer) - { - print ''.$langs->trans("NewCat").''; - } - print '
'; - - - // Formulaire ajout dans une categorie - if ($user->rights->produit->creer) - { - print '
'; - print '
'; - print ''; - print ''; - print ''; - print '
'; - print $langs->trans("ClassifyInCategory").' '; - print $html->select_all_categories(0,$categorie->id_mere).'
'; - print '
'; - print '
'; - } - - - $c = new Categorie($db); - - if ($_GET["id"]) - { - $cats = $c->containing($_REQUEST["id"],"product"); - } - - if ($_GET["ref"]) - { - $cats = $c->containing_ref($_REQUEST["ref"],"product"); - } - - if (sizeof($cats) > 0) - { - print_fiche_titre($langs->trans("ProductIsInCategories")); - print ''; - print ''; - - $var = true; - foreach ($cats as $cat) - { - $ways = $cat->print_all_ways (); - foreach ($ways as $way) - { - $var = ! $var; - print ""; - - // Categorie - print ""; - - // Lien supprimer - print '"; - - print "\n"; - } - - } - print "
'.$langs->trans("Categories").'
".$way."'; - if ($user->rights->produit->creer) - { - print ""; - print img_delete($langs->trans("DeleteFromCat")).' '; - print $langs->trans("DeleteFromCat").""; - } - else - { - print ' '; - } - print "

\n"; - } - else if($cats < 0) - { - print $langs->trans("ErrorUnknown"); - } - - else - { - print $langs->trans("ProductHasNoCategory")."
"; - } - -} -$db->close(); - - -llxFooter('$Date$ - $Revision$'); -?>