(Multi-Company) Works on possibility to defined global group

This commit is contained in:
Regis Houssin 2011-05-16 15:21:54 +00:00
parent 781e806c19
commit 1f0ff52ea2
5 changed files with 50 additions and 14 deletions

View File

@ -105,6 +105,12 @@ ALTER TABLE llx_facturedet ADD INDEX idx_facturedet_fk_product (fk_product);
ALTER TABLE llx_mailing_cibles ADD COLUMN tag varchar(128) NULL AFTER other;
ALTER TABLE llx_mailing ADD COLUMN tag varchar(128) NULL AFTER email_errorsto;
ALTER TABLE llx_usergroup_user DROP INDEX fk_user;
ALTER TABLE llx_usergroup_user ADD COLUMN entity integer DEFAULT 1 NOT NULL AFTER rowid;
ALTER TABLE llx_usergroup_user ADD UNIQUE INDEX uk_usergroup_entity (entity,fk_user,fk_usergroup);
ALTER TABLE llx_usergroup_user ADD CONSTRAINT fk_usergroup_user_fk_user FOREIGN KEY (fk_user) REFERENCES llx_user (rowid);
ALTER TABLE llx_usergroup_user ADD CONSTRAINT fk_usergroup_user_fk_usergroup FOREIGN KEY (fk_usergroup) REFERENCES llx_usergroup (rowid);
--Add Chile data (id pays=67)
-- Regions Chile
INSERT INTO llx_c_regions (rowid, code_region, fk_pays, cheflieu, tncc, nom, active) VALUES (6701, 6701, 67, NULL, NULL, 'Tarapacá', 1);

View File

@ -0,0 +1,24 @@
-- ============================================================================
-- Copyright (C) 2011 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_usergroup_user ADD UNIQUE INDEX uk_user_group_entity (entity,fk_user,fk_usergroup);
ALTER TABLE llx_usergroup_user ADD CONSTRAINT fk_usergroup_user_fk_user FOREIGN KEY (fk_user) REFERENCES llx_user (rowid);
ALTER TABLE llx_usergroup_user ADD CONSTRAINT fk_usergroup_user_fk_usergroup FOREIGN KEY (fk_usergroup) REFERENCES llx_usergroup (rowid);

View File

@ -1,5 +1,6 @@
-- ============================================================================
-- Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
-- Copyright (C) 2011 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
@ -21,8 +22,8 @@
create table llx_usergroup_user
(
rowid integer AUTO_INCREMENT PRIMARY KEY,
entity integer DEFAULT 1 NOT NULL, -- multi company id
fk_user integer NOT NULL,
fk_usergroup integer NOT NULL,
fk_usergroup integer NOT NULL
UNIQUE(fk_user,fk_usergroup)
)ENGINE=innodb;

View File

@ -4,7 +4,7 @@
* Copyright (c) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org>
* Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
* Copyright (C) 2005-2010 Regis Houssin <regis@dolibarr.fr>
* Copyright (C) 2005-2011 Regis Houssin <regis@dolibarr.fr>
* Copyright (C) 2005 Lionel Cousteix <etm_ltd@tiscali.co.uk>
*
* This program is free software; you can redistribute it and/or modify
@ -1465,34 +1465,38 @@ class User extends CommonObject
/**
* \brief Add user into a group
* \param group id du groupe
* Add user into a group
* @param group id du groupe
*/
function SetInGroup($group)
{
global $conf;
$sql = "DELETE FROM ".MAIN_DB_PREFIX."usergroup_user";
$sql .= " WHERE fk_user = ".$this->id;
$sql .= " AND fk_usergroup = ".$group;
$sql.= " WHERE fk_user = ".$this->id;
$sql.= " AND fk_usergroup = ".$group;
$sql.= " AND entity = ".$conf->entity;
$result = $this->db->query($sql);
$sql = "INSERT INTO ".MAIN_DB_PREFIX."usergroup_user (fk_user, fk_usergroup)";
$sql .= " VALUES (".$this->id.",".$group.")";
$sql = "INSERT INTO ".MAIN_DB_PREFIX."usergroup_user (entity, fk_user, fk_usergroup)";
$sql.= " VALUES (".$conf->entity.",".$this->id.",".$group.")";
$result = $this->db->query($sql);
}
/**
* \brief Remove a user from a group
* \param group id du groupe
* Remove a user from a group
* @param group id du groupe
*/
function RemoveFromGroup($group)
{
global $conf;
$sql = "DELETE FROM ".MAIN_DB_PREFIX."usergroup_user";
$sql .= " WHERE fk_user = ".$this->id;
$sql .= " AND fk_usergroup = ".$group;
$sql.= " WHERE fk_user = ".$this->id;
$sql.= " AND fk_usergroup = ".$group;
$sql.= " AND entity = ".$conf->entity;
$result = $this->db->query($sql);
}

View File

@ -1,6 +1,7 @@
<?php
/* Copyright (c) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (c) 2005-2010 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (c) 2005-2011 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
@ -494,7 +495,7 @@ class UserGroup extends CommonObject
$now=dol_now();
$sql = "INSERT into ".MAIN_DB_PREFIX."usergroup (datec, nom, entity)";
$sql = "INSERT INTO ".MAIN_DB_PREFIX."usergroup (datec, nom, entity)";
$sql.= " VALUES('".$this->db->idate($now)."','".$this->db->escape($this->nom)."',".$conf->entity.")";
dol_syslog("UserGroup::Create sql=".$sql, LOG_DEBUG);