From e2d2461d1fdde7e1193833bd3dd0321a46f0ef0f Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Thu, 15 Apr 2010 17:34:44 +0000 Subject: [PATCH] Fix: category problem --- htdocs/categories/categorie.php | 42 +++++++++---------- htdocs/categories/fiche.php | 2 +- .../install/mysql/migration/2.8.0-2.9.0.sql | 13 ++++++ htdocs/lib/company.lib.php | 4 +- htdocs/lib/product.lib.php | 2 +- 5 files changed, 39 insertions(+), 24 deletions(-) diff --git a/htdocs/categories/categorie.php b/htdocs/categories/categorie.php index 6d0ced755ff..a72a3187a05 100644 --- a/htdocs/categories/categorie.php +++ b/htdocs/categories/categorie.php @@ -1,7 +1,7 @@ * Copyright (C) 2005 Brice Davoleau - * Copyright (C) 2005-2009 Regis Houssin + * Copyright (C) 2005-2010 Regis Houssin * Copyright (C) 2006-2010 Laurent Destailleur * Copyright (C) 2007 Patrick Raguin * @@ -41,36 +41,36 @@ $dbtablename = ''; if (! empty($_REQUEST["socid"])) { $_REQUEST["id"]=$_REQUEST["socid"]; } -if (! isset($_REQUEST["typeid"])) $_REQUEST["typeid"]=0; -if ($_REQUEST["typeid"] == 1) $_GET["socid"]=$_REQUEST["id"]; -if ($_REQUEST["typeid"] == 2) $_GET["socid"]=$_REQUEST["id"]; +if (! isset($_REQUEST["type"])) $_REQUEST["type"]=0; +if ($_REQUEST["type"] == 1) $_GET["socid"]=$_REQUEST["id"]; +if ($_REQUEST["type"] == 2) $_GET["socid"]=$_REQUEST["id"]; if ($_REQUEST["id"] || $_REQUEST["ref"]) { - if ($_REQUEST["typeid"] == 0) { - $type = 'member'; - $objecttype = 'adherent&categorie'; + if ($_REQUEST["type"] == 0) { + $type = 'product'; + $objecttype = 'produit|service&categorie'; $objectid = isset($_REQUEST["id"])?$_REQUEST["id"]:(isset($_REQUEST["ref"])?$_REQUEST["ref"]:''); - $dbtablename = 'adherent'; + $dbtablename = 'product'; $fieldid = isset($_REQUEST["ref"])?'ref':'rowid'; } - if ($_REQUEST["typeid"] == 1) { + if ($_REQUEST["type"] == 1) { $type = 'fournisseur'; $socid = isset($_REQUEST["socid"])?$_REQUEST["socid"]:''; $objecttype = 'societe&categorie'; $objectid = isset($_REQUEST["id"])?$_REQUEST["id"]:(isset($_REQUEST["socid"])?$_REQUEST["socid"]:''); $fieldid = 'rowid'; } - if ($_REQUEST["typeid"] == 2) { + if ($_REQUEST["type"] == 2) { $type = 'societe'; $socid = isset($_REQUEST["socid"])?$_REQUEST["socid"]:''; $objecttype = 'societe&categorie'; $objectid = isset($_REQUEST["id"])?$_REQUEST["id"]:(isset($_REQUEST["socid"])?$_REQUEST["socid"]:''); $fieldid = 'rowid'; } - if ($_REQUEST["typeid"] == 3) { + if ($_REQUEST["type"] == 3) { $type = 'member'; - $objecttype = 'produit|service&categorie'; + $objecttype = 'adherent&categorie'; $objectid = isset($_REQUEST["id"])?$_REQUEST["id"]:(isset($_REQUEST["ref"])?$_REQUEST["ref"]:''); - $dbtablename = 'product'; + $dbtablename = 'adherent'; $fieldid = isset($_REQUEST["ref"])?'ref':'rowid'; } } @@ -87,7 +87,7 @@ $result = restrictedArea($user,$objecttype,$objectid,$dbtablename,'','',$fieldid //Suppression d'un objet d'une categorie if ($_REQUEST["removecat"]) { - if ($_REQUEST["typeid"]==0 && ($user->rights->produit->creer || $user->rights->service->creer)) + if ($_REQUEST["type"]==0 && ($user->rights->produit->creer || $user->rights->service->creer)) { require_once(DOL_DOCUMENT_ROOT."/product/product.class.php"); $object = new Product($db); @@ -95,17 +95,17 @@ if ($_REQUEST["removecat"]) if ($_REQUEST["id"]) $result = $object->fetch($_REQUEST["id"]); $type = 'product'; } - if ($_REQUEST["typeid"]==1 && $user->rights->societe->creer) + if ($_REQUEST["type"]==1 && $user->rights->societe->creer) { $object = new Societe($db); $result = $object->fetch($objectid); } - if ($_REQUEST["typeid"]==2 && $user->rights->societe->creer) + if ($_REQUEST["type"]==2 && $user->rights->societe->creer) { $object = new Societe($db); $result = $object->fetch($objectid); } - if ($_REQUEST["typeid"] == 3 && $user->rights->adherent->creer) + if ($_REQUEST["type"] == 3 && $user->rights->adherent->creer) { require_once(DOL_DOCUMENT_ROOT."/adherents/adherent.class.php"); $object = new Adherent($db); @@ -123,7 +123,7 @@ if (isset($_REQUEST["catMere"]) && $_REQUEST["catMere"]>=0) $_GET["id"]=$_REQUEST["id"]; $_GET["type"]=$_REQUEST["type"]; - if ($_REQUEST["typeid"]==0 && ($user->rights->produit->creer || $user->rights->service->creer)) + if ($_REQUEST["type"]==0 && ($user->rights->produit->creer || $user->rights->service->creer)) { require_once(DOL_DOCUMENT_ROOT."/product/product.class.php"); $object = new Product($db); @@ -131,19 +131,19 @@ if (isset($_REQUEST["catMere"]) && $_REQUEST["catMere"]>=0) if ($_REQUEST["id"]) $result = $object->fetch($_REQUEST["id"]); $type = 'product'; } - if ($_REQUEST["typeid"]==1 && $user->rights->societe->creer) + if ($_REQUEST["type"]==1 && $user->rights->societe->creer) { $object = new Societe($db); $result = $object->fetch($objectid); $type = 'fournisseur'; } - if ($_REQUEST["typeid"]==2 && $user->rights->societe->creer) + if ($_REQUEST["type"]==2 && $user->rights->societe->creer) { $object = new Societe($db); $result = $object->fetch($objectid); $type = 'societe'; } - if ($_REQUEST["typeid"]==3 && $user->rights->adherent->creer) + if ($_REQUEST["type"]==3 && $user->rights->adherent->creer) { require_once(DOL_DOCUMENT_ROOT."/adherents/adherent.class.php"); $object = new Adherent($db); diff --git a/htdocs/categories/fiche.php b/htdocs/categories/fiche.php index 8eb51645b80..f23e33cb060 100644 --- a/htdocs/categories/fiche.php +++ b/htdocs/categories/fiche.php @@ -1,7 +1,7 @@ * Copyright (C) 2006-2010 Laurent Destailleur - * Copyright (C) 2005-2008 Regis Houssin + * Copyright (C) 2005-2010 Regis Houssin * Copyright (C) 2007 Patrick Raguin * * This program is free software; you can redistribute it and/or modify diff --git a/htdocs/install/mysql/migration/2.8.0-2.9.0.sql b/htdocs/install/mysql/migration/2.8.0-2.9.0.sql index d913303c91e..4c92a763f27 100755 --- a/htdocs/install/mysql/migration/2.8.0-2.9.0.sql +++ b/htdocs/install/mysql/migration/2.8.0-2.9.0.sql @@ -200,3 +200,16 @@ ALTER TABLE llx_deplacement ADD COLUMN fk_statut INTEGER DEFAULT 1 NOT NULL aft drop table llx_appro; ALTER TABLE llx_events MODIFY COLUMN user_agent varchar(255) NULL; + +create table llx_categorie_member +( + fk_categorie integer NOT NULL, + fk_member integer NOT NULL +)type=innodb; + +ALTER TABLE llx_categorie_member ADD PRIMARY KEY (fk_categorie, fk_member); +ALTER TABLE llx_categorie_member ADD INDEX idx_categorie_member_fk_categorie (fk_categorie); +ALTER TABLE llx_categorie_member ADD INDEX idx_categorie_member_fk_member (fk_member); + +ALTER TABLE llx_categorie_member ADD CONSTRAINT fk_categorie_member_categorie_rowid FOREIGN KEY (fk_categorie) REFERENCES llx_categorie (rowid); +ALTER TABLE llx_categorie_member ADD CONSTRAINT fk_categorie_member_member_rowid FOREIGN KEY (fk_member) REFERENCES llx_adherent (rowid); diff --git a/htdocs/lib/company.lib.php b/htdocs/lib/company.lib.php index 8bd5c12ff84..1f251cc3b21 100644 --- a/htdocs/lib/company.lib.php +++ b/htdocs/lib/company.lib.php @@ -83,7 +83,9 @@ function societe_prepare_head($objsoc) //show categorie tab if ($conf->categorie->enabled) { - $head[$h][0] = DOL_URL_ROOT.'/categories/categorie.php?socid='.$objsoc->id; + $type = 2; + if ($objsoc->fournisseur) $type = 1; + $head[$h][0] = DOL_URL_ROOT.'/categories/categorie.php?socid='.$objsoc->id."&type=".$type; $head[$h][1] = $langs->trans('Categories'); $head[$h][2] = 'category'; $h++; diff --git a/htdocs/lib/product.lib.php b/htdocs/lib/product.lib.php index 4185e607892..67629d7516b 100644 --- a/htdocs/lib/product.lib.php +++ b/htdocs/lib/product.lib.php @@ -62,7 +62,7 @@ function product_prepare_head($product, $user) // Show category tab if ($conf->categorie->enabled && $user->rights->categorie->lire) { - $head[$h][0] = DOL_URL_ROOT."/categories/categorie.php?id=".$product->id."&typeid=3"; + $head[$h][0] = DOL_URL_ROOT."/categories/categorie.php?id=".$product->id.'&type=0'; $head[$h][1] = $langs->trans('Categories'); $head[$h][2] = 'category'; $h++;