From 268c58ded6109af4469244c01b1a52f3fa6f2364 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Mon, 4 May 2009 10:27:01 +0000 Subject: [PATCH] New: early development of multi-company module --- htdocs/admin/barcode.php | 2 + htdocs/admin/dict.php | 14 +-- htdocs/admin/modules.php | 1 + htdocs/core/conf.class.php | 4 +- .../barcode/html.formbarcode.class.php | 6 +- .../modules/DolibarrModules.class.php | 87 ++++++++++++++++--- mysql/data/data.sql | 4 +- mysql/migration/2.6.0-2.7.0.sql | 6 +- mysql/tables/llx_c_barcode_type.sql | 6 +- mysql/tables/llx_dolibarr_modules.key.sql | 22 +++++ mysql/tables/llx_dolibarr_modules.sql | 6 +- 11 files changed, 130 insertions(+), 28 deletions(-) create mode 100644 mysql/tables/llx_dolibarr_modules.key.sql diff --git a/htdocs/admin/barcode.php b/htdocs/admin/barcode.php index 51d8b3a438c..69f651f3bb7 100644 --- a/htdocs/admin/barcode.php +++ b/htdocs/admin/barcode.php @@ -39,6 +39,7 @@ if ($_POST["action"] == 'setcoder') $sqlp = "UPDATE ".MAIN_DB_PREFIX."c_barcode_type"; $sqlp.= " SET coder = '" . $_POST["coder"]."'"; $sqlp.= " WHERE rowid = ". $_POST["code_id"]; + $sqlp.= " AND entity = ".$conf->entity; $resql=$db->query($sqlp); //print $sqlp; @@ -138,6 +139,7 @@ print "\n"; $sql = "SELECT rowid, code as encoding, libelle, coder, example"; $sql.= " FROM ".MAIN_DB_PREFIX."c_barcode_type"; +$sql.= " WHERE entity = ".$conf->entity; dol_syslog("admin/barcode.php sql=".$sql); $resql=$db->query($sql); diff --git a/htdocs/admin/dict.php b/htdocs/admin/dict.php index 235537947e0..12823318489 100644 --- a/htdocs/admin/dict.php +++ b/htdocs/admin/dict.php @@ -2,7 +2,7 @@ /* Copyright (C) 2004 Rodolphe Quiedeville * Copyright (C) 2004-2008 Laurent Destailleur * Copyright (C) 2004 Benoit Mortier - * Copyright (C) 2005-2007 Regis Houssin + * Copyright (C) 2005-2009 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 @@ -44,8 +44,8 @@ $actl[1] = $langs->trans("Disable"); $active = 1; -// Cette page est une page d'�dition g�n�rique des dictionnaires de donn�es -// Mettre ici tous les caract�ristiques des dictionnaires +// Cette page est une page d'edition generique des dictionnaires de donnees +// Mettre ici tous les caracteristiques des dictionnaires // Ordres d'affichage des dictionnaires (0 pour espace) $taborder=array(9,0,4,3,2,0,1,8,16,0,5,11,0,6,0,10,12,13,0,14,0,7,17,0,18,0,15); @@ -502,7 +502,7 @@ if ($_GET["id"]) foreach ($fieldlist as $field => $value) { // Determine le nom du champ par rapport aux noms possibles - // dans les dictionnaires de donn�es + // dans les dictionnaires de donnees $valuetoshow=ucfirst($fieldlist[$field]); // Par defaut if ($fieldlist[$field]=='source') { $valuetoshow=$langs->trans("Contact"); } if ($fieldlist[$field]=='price') { $valuetoshow=$langs->trans("PriceUHT"); } @@ -543,7 +543,7 @@ if ($_GET["id"]) print ''; print ""; - if ($alabelisused) // Si un des champs est un libell� + if ($alabelisused) // Si un des champs est un libelle { print '* '.$langs->trans("LabelUsedByDefault").'.'; } @@ -565,7 +565,7 @@ if ($_GET["id"]) foreach ($fieldlist as $field => $value) { // Determine le nom du champ par rapport aux noms possibles - // dans les dictionnaires de donn�es + // dans les dictionnaires de donnees $showfield=1; // Par defaut $valuetoshow=ucfirst($fieldlist[$field]); // Par defaut if ($fieldlist[$field]=='source') { $valuetoshow=$langs->trans("Contact"); } @@ -635,7 +635,7 @@ if ($_GET["id"]) } print ''; - // Est-ce une entr�e du dictionnaire qui peut etre d�sactiv�e ? + // Est-ce une entree du dictionnaire qui peut etre desactivee ? $iserasable=1; // Oui par defaut if (isset($obj->code) && ($obj->code == '0' || $obj->code == '' || eregi('unknown',$obj->code))) $iserasable=0; if ($obj->type && $obj->type == 'system') $iserasable=0; diff --git a/htdocs/admin/modules.php b/htdocs/admin/modules.php index 23a741e05f0..7b015a68fc0 100644 --- a/htdocs/admin/modules.php +++ b/htdocs/admin/modules.php @@ -3,6 +3,7 @@ * Copyright (C) 2003 Jean-Louis Bergamo * Copyright (C) 2004-2008 Laurent Destailleur * Copyright (C) 2004 Eric Seigne + * Copyright (C) 2005-2009 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 diff --git a/htdocs/core/conf.class.php b/htdocs/core/conf.class.php index d43c83b1ea8..849da7819ec 100644 --- a/htdocs/core/conf.class.php +++ b/htdocs/core/conf.class.php @@ -76,8 +76,10 @@ class Conf * - En constante php (TODO a virer) * - En $this->global->key=value */ - $sql = "SELECT name, value, entity FROM ".MAIN_DB_PREFIX."const"; + $sql = "SELECT name, value, entity"; + $sql.= " FROM ".MAIN_DB_PREFIX."const"; $sql.= " WHERE entity IN (0,".$this->entity.")"; + $result = $db->query($sql); if ($result) { diff --git a/htdocs/includes/barcode/html.formbarcode.class.php b/htdocs/includes/barcode/html.formbarcode.class.php index f095d0dbd28..d45b915afdd 100644 --- a/htdocs/includes/barcode/html.formbarcode.class.php +++ b/htdocs/includes/barcode/html.formbarcode.class.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2007-2009 Regis Houssin * Copyright (C) 2008 Laurent Destailleur * * This program is free software; you can redistribute it and/or modify @@ -91,12 +91,14 @@ class FormBarCode */ function select_barcode_type($selected='',$htmlname='coder_id',$useempty=0) { - global $langs; + global $langs,$conf; $sql = "SELECT rowid, code, libelle"; $sql.= " FROM ".MAIN_DB_PREFIX."c_barcode_type"; $sql.= " WHERE coder <> '0'"; + $sql.= " AND entity = ".$conf->entity; $sql.= " ORDER BY rowid"; + $result = $this->db->query($sql); if ($result) { diff --git a/htdocs/includes/modules/DolibarrModules.class.php b/htdocs/includes/modules/DolibarrModules.class.php index 09c7998cd93..82316252f1b 100644 --- a/htdocs/includes/modules/DolibarrModules.class.php +++ b/htdocs/includes/modules/DolibarrModules.class.php @@ -272,11 +272,15 @@ class DolibarrModules */ function getDbVersion() { - global $langs; + global $langs,$conf; + $langs->load("admin"); - $sql ="SELECT active_version FROM ".MAIN_DB_PREFIX."dolibarr_modules"; - $sql .= " WHERE numero=".$this->numero." AND active = 1"; + $sql ="SELECT active_version"; + $sql.= " FROM ".MAIN_DB_PREFIX."dolibarr_modules"; + $sql.= " WHERE numero = ".$this->numero; + $sql.= " AND entity = ".$conf->entity; + $sql.= " AND active = 1"; dol_syslog("DolibarrModules::getDbVersion sql=".$sql); $resql = $this->db->query($sql); @@ -341,15 +345,32 @@ class DolibarrModules */ function _dbactive() { + global $conf; + $err = 0; - $sql = "DELETE FROM ".MAIN_DB_PREFIX."dolibarr_modules WHERE numero=".$this->numero.";"; + $sql = "DELETE FROM ".MAIN_DB_PREFIX."dolibarr_modules"; + $sql.= " WHERE numero = ".$this->numero; + $sql.= " AND entity = ".$conf->entity; + dol_syslog("DolibarrModules::_dbactive sql=".$sql, LOG_DEBUG); $this->db->query($sql); - $sql = "INSERT INTO ".MAIN_DB_PREFIX."dolibarr_modules (numero,active,active_date,active_version)"; + $sql = "INSERT INTO ".MAIN_DB_PREFIX."dolibarr_modules ("; + $sql.= "numero"; + $sql.= ", entity"; + $sql.= ", active"; + $sql.= ", active_date"; + $sql.= ", active_version"; + $sql.= ")"; $sql.= " VALUES ("; - $sql.= $this->numero.",1,".$this->db->idate(gmmktime()).",'".$this->version."')"; + $sql.= $this->numero; + $sql.= ", ".$conf->entity; + $sql.= ", 1"; + $sql.= ", ".$this->db->idate(gmmktime()); + $sql.= ", '".$this->version."'"; + $sql.= ")"; + dol_syslog("DolibarrModules::_dbactive sql=".$sql, LOG_DEBUG); $this->db->query($sql); @@ -364,9 +385,14 @@ class DolibarrModules */ function _dbunactive() { + global $conf; + $err = 0; - $sql = "DELETE FROM ".MAIN_DB_PREFIX."dolibarr_modules WHERE numero=".$this->numero; + $sql = "DELETE FROM ".MAIN_DB_PREFIX."dolibarr_modules"; + $sql.= " WHERE numero = ".$this->numero; + $sql.= " AND entity = ".$conf->entity; + dol_syslog("DolibarrModules::_dbunactive sql=".$sql, LOG_DEBUG); $this->db->query($sql); @@ -387,11 +413,13 @@ class DolibarrModules $sql = "DELETE FROM ".MAIN_DB_PREFIX."const"; $sql.= " WHERE name = '".$this->const_name."'"; $sql.= " AND entity = ".$conf->entity; + dol_syslog("DolibarrModules::_active sql=".$sql, LOG_DEBUG); $this->db->query($sql); $sql = "INSERT INTO ".MAIN_DB_PREFIX."const (name,value,visible,entity) VALUES"; $sql.= " ('".$this->const_name."','1',0,".$conf->entity.")"; + dol_syslog("DolibarrModules::_active sql=".$sql, LOG_DEBUG); if (!$this->db->query($sql)) { @@ -415,6 +443,7 @@ class DolibarrModules $sql = "DELETE FROM ".MAIN_DB_PREFIX."const"; $sql.= " WHERE name = '".$this->const_name."'"; $sql.= " AND entity = ".$conf->entity; + dol_syslog("DolibarrModules::_unactive sql=".$sql); $this->db->query($sql); @@ -503,6 +532,7 @@ class DolibarrModules $sql = "SELECT count(*) FROM ".MAIN_DB_PREFIX."boxes_def"; $sql.= " WHERE file = '".$file."'"; $sql.= " AND entity = ".$conf->entity; + if ($note) $sql.=" AND note ='".addslashes($note)."'"; $result=$this->db->query($sql); @@ -516,6 +546,7 @@ class DolibarrModules $sql.= $conf->entity.","; $sql.= $note?"'".addslashes($note)."'":"null"; $sql.= ")"; + dol_syslog("DolibarrModules::insert_boxes sql=".$sql); if (! $this->db->query($sql)) { @@ -557,12 +588,14 @@ class DolibarrModules $sql.= " WHERE ".MAIN_DB_PREFIX."boxes.box_id = ".MAIN_DB_PREFIX."boxes_def.rowid"; $sql.= " AND ".MAIN_DB_PREFIX."boxes_def.file = '".addslashes($file)."'"; $sql.= " AND ".MAIN_DB_PREFIX."boxes_def.entity = ".$conf->entity; + dol_syslog("DolibarrModules::delete_boxes sql=".$sql); $this->db->query($sql); $sql = "DELETE FROM ".MAIN_DB_PREFIX."boxes_def"; $sql.= " WHERE file = '".addslashes($file)."'"; $sql.= " AND entity = ".$conf->entity; + dol_syslog("DolibarrModules::delete_boxes sql=".$sql); if (! $this->db->query($sql)) { @@ -589,6 +622,7 @@ class DolibarrModules $sql = "DELETE FROM ".MAIN_DB_PREFIX."const"; $sql.= " WHERE name = '".$this->const_name."_CSS'"; $sql.= " AND entity = ".$conf->entity; + dol_syslog("DolibarrModules::delete_style_sheet sql=".$sql); if (! $this->db->query($sql)) { @@ -612,6 +646,7 @@ class DolibarrModules $sql = "DELETE FROM ".MAIN_DB_PREFIX."const"; $sql.= " WHERE name like '".$this->const_name."_TABS_%'"; $sql.= " AND entity = ".$conf->entity; + dol_syslog("DolibarrModules::delete_tabs sql=".$sql); if (! $this->db->query($sql)) { @@ -633,8 +668,23 @@ class DolibarrModules if ($this->style_sheet) { - $sql = "INSERT INTO ".MAIN_DB_PREFIX."const (name,type,value,note,visible,entity)"; - $sql.= " VALUES ('".$this->const_name."_CSS','chaine','".$this->style_sheet."','Style sheet for module ".$this->name."','0',".$conf->entity.")"; + $sql = "INSERT INTO ".MAIN_DB_PREFIX."const ("; + $sql.= "name"; + $sql.= ", type"; + $sql.= ", value"; + $sql.= ", note"; + $sql.= ", visible"; + $sql.= ", entity"; + $sql.= ")"; + $sql.= " VALUES ("; + $sql.= "'".$this->const_name."_CSS'"; + $sql.= ", 'chaine'"; + $sql.= ", '".$this->style_sheet."'"; + $sql.= ", 'Style sheet for module ".$this->name."'"; + $sql.= ", '0'"; + $sql.= ", ".$conf->entity; + $sql.= ")"; + dol_syslog("DolibarrModules::insert_style_sheet sql=".$sql); $resql=$this->db->query($sql); /* Allow duplicate key @@ -665,8 +715,23 @@ class DolibarrModules { if ($value) { - $sql = "INSERT INTO ".MAIN_DB_PREFIX."const (name,type,value,note,visible,entity)"; - $sql.= " VALUES ('".$this->const_name."_TABS_".$i."','chaine','".$value."',null,'0',".$conf->entity.")"; + $sql = "INSERT INTO ".MAIN_DB_PREFIX."const ("; + $sql.= "name"; + $sql.= ", type"; + $sql.= ", value"; + $sql.= ", note"; + $sql.= ", visible"; + $sql.= ", entity"; + $sql.= ")"; + $sql.= " VALUES ("; + $sql.= "'".$this->const_name."_TABS_".$i."'"; + $sql.= ", 'chaine'"; + $sql.= ", '".$value."'"; + $sql.= ", null"; + $sql.= ", '0'"; + $sql.= ", ".$conf->entity; + $sql.= ")"; + dol_syslog("DolibarrModules::insert_tabs sql=".$sql); $resql=$this->db->query($sql); /* Allow duplicate key diff --git a/mysql/data/data.sql b/mysql/data/data.sql index 5907c1b1f60..2bb7e08e919 100644 --- a/mysql/data/data.sql +++ b/mysql/data/data.sql @@ -3,7 +3,7 @@ -- Copyright (C) 2004-2005 Laurent Destailleur -- Copyright (C) 2004 Benoit Mortier -- Copyright (C) 2004 Guillaume Delecourt --- Copyright (C) 2005-2007 Regis Houssin +-- Copyright (C) 2005-2009 Regis Houssin -- Copyright (C) 2007 Patrick Raguin -- -- This program is free software; you can redistribute it and/or modify @@ -198,7 +198,7 @@ insert into llx_const (name, value, type, note, visible) VALUES ('PROPALE_VALIDI -- -- Barcode -- -insert into llx_const (name, value, type, note, visible) values ('GENBARCODE_LOCATION','/usr/local/bin/genbarcode','chaine','location of genbarcode',0); +insert into llx_const (name, value, type, note, visible, entity) values ('GENBARCODE_LOCATION','/usr/local/bin/genbarcode','chaine','location of genbarcode',0,0); -- diff --git a/mysql/migration/2.6.0-2.7.0.sql b/mysql/migration/2.6.0-2.7.0.sql index 4edd80ad1b1..2bffc4b8410 100644 --- a/mysql/migration/2.6.0-2.7.0.sql +++ b/mysql/migration/2.6.0-2.7.0.sql @@ -33,6 +33,8 @@ ALTER TABLE llx_facture_fourn ADD COLUMN entity integer DEFAULT 1 NOT NULL AFTER ALTER TABLE llx_livraison ADD COLUMN entity integer DEFAULT 1 NOT NULL AFTER ref; ALTER TABLE llx_fichinter ADD COLUMN entity integer DEFAULT 1 NOT NULL AFTER ref; ALTER TABLE llx_contrat ADD COLUMN entity integer DEFAULT 1 NOT NULL AFTER ref; +ALTER TABLE llx_c_barcode_type ADD COLUMN entity integer DEFAULT 1 NOT NULL AFTER code; +ALTER TABLE llx_dolibarr_modules ADD COLUMN entity integer DEFAULT 1 NOT NULL AFTER numero; ALTER TABLE llx_rights_def DROP PRIMARY KEY; ALTER TABLE llx_user_param DROP INDEX fk_user; @@ -55,6 +57,7 @@ ALTER TABLE llx_facture_fourn DROP INDEX uk_facture_fourn_ref; ALTER TABLE llx_livraison DROP INDEX idx_expedition_uk_ref; ALTER TABLE llx_livraison DROP INDEX idx_livraison_uk_ref; ALTER TABLE llx_fichinter DROP INDEX ref; +ALTER TABLE llx_dolibarr_modules DROP PRIMARY KEY; ALTER TABLE llx_rights_def ADD PRIMARY KEY (id, entity); ALTER TABLE llx_user_param ADD UNIQUE INDEX uk_user_param (fk_user,param,entity); @@ -77,4 +80,5 @@ ALTER TABLE llx_expedition ADD UNIQUE INDEX idx_expedition_uk_ref (ref, entity); ALTER TABLE llx_facture_fourn ADD UNIQUE INDEX uk_facture_fourn_ref (facnumber, fk_soc, entity); ALTER TABLE llx_livraison ADD UNIQUE INDEX idx_livraison_uk_ref (ref, entity); ALTER TABLE llx_fichinter ADD UNIQUE INDEX uk_fichinter_ref (ref, entity); -ALTER TABLE llx_contrat ADD UNIQUE INDEX uk_contrat_ref (ref, entity); \ No newline at end of file +ALTER TABLE llx_contrat ADD UNIQUE INDEX uk_contrat_ref (ref, entity); +ALTER TABLE llx_dolibarr_modules ADD PRIMARY KEY (numero, entity); \ No newline at end of file diff --git a/mysql/tables/llx_c_barcode_type.sql b/mysql/tables/llx_c_barcode_type.sql index a2fce7ffd61..491695f1dac 100644 --- a/mysql/tables/llx_c_barcode_type.sql +++ b/mysql/tables/llx_c_barcode_type.sql @@ -1,6 +1,6 @@ -- ======================================================================== --- Copyright (C) 2007 Regis Houssin --- Copyright (C) 2008 Laurent Destailleur +-- Copyright (C) 2007-2009 Regis Houssin +-- Copyright (C) 2008 Laurent Destailleur -- -- 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 @@ -23,7 +23,9 @@ create table llx_c_barcode_type ( rowid integer AUTO_INCREMENT PRIMARY KEY, code varchar(16) NOT NULL, + entity integer DEFAULT 1 NOT NULL, -- multi company id libelle varchar(50) NOT NULL, coder varchar(16) NOT NULL, example varchar(16) NOT NULL + )type=innodb; diff --git a/mysql/tables/llx_dolibarr_modules.key.sql b/mysql/tables/llx_dolibarr_modules.key.sql new file mode 100644 index 00000000000..2aa0c8a9f41 --- /dev/null +++ b/mysql/tables/llx_dolibarr_modules.key.sql @@ -0,0 +1,22 @@ +-- ============================================================================ +-- Copyright (C) 2009 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$ +-- =========================================================================== + + +ALTER TABLE llx_dolibarr_modules ADD PRIMARY KEY (numero, entity); diff --git a/mysql/tables/llx_dolibarr_modules.sql b/mysql/tables/llx_dolibarr_modules.sql index e54a83465d7..6afaaf384f9 100644 --- a/mysql/tables/llx_dolibarr_modules.sql +++ b/mysql/tables/llx_dolibarr_modules.sql @@ -1,5 +1,6 @@ -- ======================================================================== --- Copyright (C) 2005 Rodolphe Quiedeville +-- Copyright (C) 2005 Rodolphe Quiedeville +-- Copyright (C) 2005-2009 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 @@ -20,7 +21,8 @@ create table llx_dolibarr_modules ( - numero integer PRIMARY KEY, + numero integer, + entity integer DEFAULT 1 NOT NULL, -- multi company id active tinyint DEFAULT 0 NOT NULL, active_date datetime NOT NULL, active_version varchar(25) NOT NULL