New: early development of multi-company module

This commit is contained in:
Regis Houssin 2009-04-15 20:09:43 +00:00
parent 8ddc11823b
commit 94a5df6a2d
6 changed files with 71 additions and 13 deletions

View File

@ -54,6 +54,8 @@ class Conf
var $tabs_modules=array();
var $logbuffer=array();
var $entity;
/**
@ -63,17 +65,30 @@ class Conf
*/
function setValues($db)
{
global $conf;
dol_syslog("Conf::setValues");
// Par defaut, a oui
$this->global->PRODUIT_CONFIRM_DELETE_LINE=1;
// Load entity cookie
$entityCookieName = "DOLENTITYID_dolibarr";
if (!$_COOKIE[$entityCookieName]){
$conf->entity = 1;
}else{
$conf->entity = $_COOKIE[$entityCookieName];
}
//$conf->entity = $conf->entity ? $conf->entity : 1;
/*
* Definition de toutes les Constantes globales d'environnement
* - En constante php (TODO a virer)
* - En $this->global->key=value
*/
$sql = "SELECT name, value FROM ".MAIN_DB_PREFIX."const";
$sql = "SELECT name, value, entity FROM ".MAIN_DB_PREFIX."const ";
$sql.= " WHERE entity = ".$conf->entity;
$result = $db->query($sql);
if ($result)
{
@ -114,7 +129,6 @@ class Conf
}
$db->free($result);
// On reprend parametres du fichier de config conf.php
// \TODO Mettre tous les param de conf DB dans une propriete de la classe

View File

@ -390,13 +390,17 @@ class DolibarrModules
function _active()
{
$err = 0;
//TODO : define entity id
$entity = 1;
$sql = "DELETE FROM ".MAIN_DB_PREFIX."const WHERE name = '".$this->const_name."'";
$sql = "DELETE FROM ".MAIN_DB_PREFIX."const ";
$sql.= "WHERE name = '".$this->const_name."' ";
$sql.= "AND entity = ".$entity;
dol_syslog("DolibarrModules::_active sql=".$sql, LOG_DEBUG);
$this->db->query($sql);
$sql = "INSERT INTO ".MAIN_DB_PREFIX."const (name,value,visible) VALUES";
$sql.= " ('".$this->const_name."','1',0)";
$sql = "INSERT INTO ".MAIN_DB_PREFIX."const (name,value,visible,entity) VALUES";
$sql.= " ('".$this->const_name."','1',0,".$entity.")";
dol_syslog("DolibarrModules::_active sql=".$sql, LOG_DEBUG);
if (!$this->db->query($sql))
{
@ -414,8 +418,12 @@ class DolibarrModules
function _unactive()
{
$err = 0;
//TODO : define entity id
$entity = 1;
$sql = "DELETE FROM ".MAIN_DB_PREFIX."const WHERE name = '".$this->const_name."'";
$sql = "DELETE FROM ".MAIN_DB_PREFIX."const ";
$sql.= "WHERE name = '".$this->const_name."'";
$sql.= "AND entity = ".$entity;
dol_syslog("DolibarrModules::_unactive sql=".$sql);
$this->db->query($sql);

View File

@ -201,13 +201,13 @@ class modMultiCompany extends DolibarrModules
* \return int 1 if OK, 0 if KO
*/
function init()
{
$sql = array();
{
$sql = array();
$result=$this->load_tables();
return $this->_init($sql);
}
return $this->_init($sql);
}
/**
* \brief Function called when module is disabled.

View File

@ -143,6 +143,18 @@ function dol_loginfunction($langs,$conf,$mysoc)
print '<tr><td align="left" valign="top" nowrap="nowrap"> &nbsp; <b>'.$langs->trans("Password").'</b> &nbsp; </td>';
print '<td valign="top" nowrap="nowrap"><input id="password" name="password" class="flat" type="password" size="15" maxlength="30" tabindex="2">';
print '</td></tr>';
// Entity field
if ($conf->multicompany->enabled)
{
$html = new Form($db);
//TODO: creer class
$entity = array('1'=>'company1','2'=>'company2');
print '<tr><td align="left" valign="top" nowrap="nowrap"> &nbsp; <b>'.$langs->trans("Entity").'</b> &nbsp; </td>';
print '<td valign="top" nowrap="nowrap">';
$html->select_array('entity',$entity);
print '</td></tr>';
}
print '<tr><td colspan="3">&nbsp;</td></tr>'."\n";

View File

@ -115,7 +115,6 @@ set_include_path($_SERVER['DOCUMENT_ROOT'].'/htdocs');
// Set and init common variables
require_once("master.inc.php");
// Check if HTTPS
if ($conf->main_force_https)
{
@ -264,6 +263,22 @@ if (! isset($_SESSION["dol_login"]))
{
$test=false;
$conf->authmode=$mode; // This properties is defined only when login
// Call function to check entity
if ($conf->multicompany->enabled && isset($_POST["entity"]))
{
$entitytotest=$_POST["entity"];
// Creation du cookie
$entityCookieName = "DOLENTITYID_dolibarr";
if (!isset($HTTP_COOKIE_VARS[$entityCookieName]))
{
setcookie($entityCookieName, $entitytotest, 0, "/", "", 0);
}
//$conf->entity = $_COOKIE[$entityCookieName];
// Reload index.php
$url=DOL_URL_ROOT."/index.php";
header("Location: ".$url);
}
}
}
else
@ -387,6 +402,7 @@ if (! isset($_SESSION["dol_login"]))
// Nouvelle session pour ce login
$_SESSION["dol_login"]=$user->login;
$_SESSION["dol_authmode"]=$conf->authmode;
dol_syslog("This is a new started user session. _SESSION['dol_login']=".$_SESSION["dol_login"].' Session id='.session_id());

View File

@ -36,13 +36,21 @@ require_once("../main.inc.php");
// Define url to go after disconnect
$urlfrom=empty($_SESSION["urlfrom"])?'':$_SESSION["urlfrom"];
// Module Phenix
// Phenix module
if ($conf->phenix->enabled && $conf->phenix->cookie)
{
// Destruction du cookie
// Destroy cookie
setcookie($conf->phenix->cookie, '', 1, "/");
}
// Multi-Company module
if ($conf->multicompany->enabled)
{
// Destroy entity cookie
$entityCookieName = "DOLENTITYID_dolibarr";
setcookie($entityCookieName, '', 1, "/");
}
// Destroy session
$sessionname="DOLSESSID_".$dolibarr_main_db_name;
if (! empty($conf->global->MAIN_SESSION_TIMEOUT)) ini_set('session.gc_maxlifetime',$conf->global->MAIN_SESSION_TIMEOUT);