New: early development of multi-company module

This commit is contained in:
Regis Houssin 2009-05-04 10:27:01 +00:00
parent fc1949bfdc
commit 268c58ded6
11 changed files with 130 additions and 28 deletions

View File

@ -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 "</tr>\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);

View File

@ -2,7 +2,7 @@
/* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2008 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
* Copyright (C) 2005-2007 Regis Houssin <regis@dolibarr.fr>
* Copyright (C) 2005-2009 Regis Houssin <regis@dolibarr.fr>
*
* 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'<EFBFBD>dition g<>n<EFBFBD>rique des dictionnaires de donn<6E>es
// Mettre ici tous les caract<EFBFBD>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<EFBFBD>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 '<td colspan="3"><input type="submit" class="button" name="actionadd" value="'.$langs->trans("Add").'"></td>';
print "</tr>";
if ($alabelisused) // Si un des champs est un libell<EFBFBD>
if ($alabelisused) // Si un des champs est un libelle
{
print '<tr><td colspan="'.(count($fieldlist)+2).'">* '.$langs->trans("LabelUsedByDefault").'.</td></tr>';
}
@ -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<EFBFBD>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 '<td align="center" nowrap="nowrap">';
// Est-ce une entr<EFBFBD>e du dictionnaire qui peut etre d<>sactiv<69>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;

View File

@ -3,6 +3,7 @@
* Copyright (C) 2003 Jean-Louis Bergamo <jlb@j1b.org>
* Copyright (C) 2004-2008 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
* Copyright (C) 2005-2009 Regis Houssin <regis@dolibarr.fr>
*
* 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

View File

@ -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)
{

View File

@ -1,5 +1,5 @@
<?php
/* Copyright (C) 2007-2008 Regis Houssin <regis@dolibarr.fr>
/* Copyright (C) 2007-2009 Regis Houssin <regis@dolibarr.fr>
* Copyright (C) 2008 Laurent Destailleur <eldy@users.sourceforge.net>
*
* 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)
{

View File

@ -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

View File

@ -3,7 +3,7 @@
-- Copyright (C) 2004-2005 Laurent Destailleur <eldy@users.sourceforge.net>
-- Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
-- Copyright (C) 2004 Guillaume Delecourt <guillaume.delecourt@opensides.be>
-- Copyright (C) 2005-2007 Regis Houssin <regis@dolibarr.fr>
-- Copyright (C) 2005-2009 Regis Houssin <regis@dolibarr.fr>
-- Copyright (C) 2007 Patrick Raguin <patrick.raguin@gmail.com>
--
-- 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);
--

View File

@ -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);
ALTER TABLE llx_contrat ADD UNIQUE INDEX uk_contrat_ref (ref, entity);
ALTER TABLE llx_dolibarr_modules ADD PRIMARY KEY (numero, entity);

View File

@ -1,6 +1,6 @@
-- ========================================================================
-- Copyright (C) 2007 Regis Houssin <regis@dolibarr.fr>
-- Copyright (C) 2008 Laurent Destailleur <eldy@users.sourceforge.net>
-- Copyright (C) 2007-2009 Regis Houssin <regis@dolibarr.fr>
-- Copyright (C) 2008 Laurent Destailleur <eldy@users.sourceforge.net>
--
-- 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;

View File

@ -0,0 +1,22 @@
-- ============================================================================
-- Copyright (C) 2009 Regis Houssin <regis@dolibarr.fr>
--
-- 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);

View File

@ -1,5 +1,6 @@
-- ========================================================================
-- Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
-- Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
-- Copyright (C) 2005-2009 Regis Houssin <regis@dolibarr.fr>
--
-- 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