New: early development of multi-company module
This commit is contained in:
parent
8ddc11823b
commit
94a5df6a2d
@ -54,6 +54,8 @@ class Conf
|
|||||||
var $tabs_modules=array();
|
var $tabs_modules=array();
|
||||||
|
|
||||||
var $logbuffer=array();
|
var $logbuffer=array();
|
||||||
|
|
||||||
|
var $entity;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -63,17 +65,30 @@ class Conf
|
|||||||
*/
|
*/
|
||||||
function setValues($db)
|
function setValues($db)
|
||||||
{
|
{
|
||||||
|
global $conf;
|
||||||
|
|
||||||
dol_syslog("Conf::setValues");
|
dol_syslog("Conf::setValues");
|
||||||
|
|
||||||
// Par defaut, a oui
|
// Par defaut, a oui
|
||||||
$this->global->PRODUIT_CONFIRM_DELETE_LINE=1;
|
$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
|
* Definition de toutes les Constantes globales d'environnement
|
||||||
* - En constante php (TODO a virer)
|
* - En constante php (TODO a virer)
|
||||||
* - En $this->global->key=value
|
* - 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);
|
$result = $db->query($sql);
|
||||||
if ($result)
|
if ($result)
|
||||||
{
|
{
|
||||||
@ -114,7 +129,6 @@ class Conf
|
|||||||
}
|
}
|
||||||
$db->free($result);
|
$db->free($result);
|
||||||
|
|
||||||
|
|
||||||
// On reprend parametres du fichier de config conf.php
|
// On reprend parametres du fichier de config conf.php
|
||||||
// \TODO Mettre tous les param de conf DB dans une propriete de la classe
|
// \TODO Mettre tous les param de conf DB dans une propriete de la classe
|
||||||
|
|
||||||
|
|||||||
@ -390,13 +390,17 @@ class DolibarrModules
|
|||||||
function _active()
|
function _active()
|
||||||
{
|
{
|
||||||
$err = 0;
|
$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);
|
dol_syslog("DolibarrModules::_active sql=".$sql, LOG_DEBUG);
|
||||||
$this->db->query($sql);
|
$this->db->query($sql);
|
||||||
|
|
||||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."const (name,value,visible) VALUES";
|
$sql = "INSERT INTO ".MAIN_DB_PREFIX."const (name,value,visible,entity) VALUES";
|
||||||
$sql.= " ('".$this->const_name."','1',0)";
|
$sql.= " ('".$this->const_name."','1',0,".$entity.")";
|
||||||
dol_syslog("DolibarrModules::_active sql=".$sql, LOG_DEBUG);
|
dol_syslog("DolibarrModules::_active sql=".$sql, LOG_DEBUG);
|
||||||
if (!$this->db->query($sql))
|
if (!$this->db->query($sql))
|
||||||
{
|
{
|
||||||
@ -414,8 +418,12 @@ class DolibarrModules
|
|||||||
function _unactive()
|
function _unactive()
|
||||||
{
|
{
|
||||||
$err = 0;
|
$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);
|
dol_syslog("DolibarrModules::_unactive sql=".$sql);
|
||||||
$this->db->query($sql);
|
$this->db->query($sql);
|
||||||
|
|
||||||
|
|||||||
@ -201,13 +201,13 @@ class modMultiCompany extends DolibarrModules
|
|||||||
* \return int 1 if OK, 0 if KO
|
* \return int 1 if OK, 0 if KO
|
||||||
*/
|
*/
|
||||||
function init()
|
function init()
|
||||||
{
|
{
|
||||||
$sql = array();
|
$sql = array();
|
||||||
|
|
||||||
$result=$this->load_tables();
|
$result=$this->load_tables();
|
||||||
|
|
||||||
return $this->_init($sql);
|
return $this->_init($sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Function called when module is disabled.
|
* \brief Function called when module is disabled.
|
||||||
|
|||||||
@ -143,6 +143,18 @@ function dol_loginfunction($langs,$conf,$mysoc)
|
|||||||
print '<tr><td align="left" valign="top" nowrap="nowrap"> <b>'.$langs->trans("Password").'</b> </td>';
|
print '<tr><td align="left" valign="top" nowrap="nowrap"> <b>'.$langs->trans("Password").'</b> </td>';
|
||||||
print '<td valign="top" nowrap="nowrap"><input id="password" name="password" class="flat" type="password" size="15" maxlength="30" tabindex="2">';
|
print '<td valign="top" nowrap="nowrap"><input id="password" name="password" class="flat" type="password" size="15" maxlength="30" tabindex="2">';
|
||||||
print '</td></tr>';
|
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"> <b>'.$langs->trans("Entity").'</b> </td>';
|
||||||
|
print '<td valign="top" nowrap="nowrap">';
|
||||||
|
$html->select_array('entity',$entity);
|
||||||
|
print '</td></tr>';
|
||||||
|
}
|
||||||
|
|
||||||
print '<tr><td colspan="3"> </td></tr>'."\n";
|
print '<tr><td colspan="3"> </td></tr>'."\n";
|
||||||
|
|
||||||
|
|||||||
@ -115,7 +115,6 @@ set_include_path($_SERVER['DOCUMENT_ROOT'].'/htdocs');
|
|||||||
// Set and init common variables
|
// Set and init common variables
|
||||||
require_once("master.inc.php");
|
require_once("master.inc.php");
|
||||||
|
|
||||||
|
|
||||||
// Check if HTTPS
|
// Check if HTTPS
|
||||||
if ($conf->main_force_https)
|
if ($conf->main_force_https)
|
||||||
{
|
{
|
||||||
@ -264,6 +263,22 @@ if (! isset($_SESSION["dol_login"]))
|
|||||||
{
|
{
|
||||||
$test=false;
|
$test=false;
|
||||||
$conf->authmode=$mode; // This properties is defined only when login
|
$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
|
else
|
||||||
@ -387,6 +402,7 @@ if (! isset($_SESSION["dol_login"]))
|
|||||||
|
|
||||||
// Nouvelle session pour ce login
|
// Nouvelle session pour ce login
|
||||||
$_SESSION["dol_login"]=$user->login;
|
$_SESSION["dol_login"]=$user->login;
|
||||||
|
|
||||||
$_SESSION["dol_authmode"]=$conf->authmode;
|
$_SESSION["dol_authmode"]=$conf->authmode;
|
||||||
dol_syslog("This is a new started user session. _SESSION['dol_login']=".$_SESSION["dol_login"].' Session id='.session_id());
|
dol_syslog("This is a new started user session. _SESSION['dol_login']=".$_SESSION["dol_login"].' Session id='.session_id());
|
||||||
|
|
||||||
|
|||||||
@ -36,13 +36,21 @@ require_once("../main.inc.php");
|
|||||||
// Define url to go after disconnect
|
// Define url to go after disconnect
|
||||||
$urlfrom=empty($_SESSION["urlfrom"])?'':$_SESSION["urlfrom"];
|
$urlfrom=empty($_SESSION["urlfrom"])?'':$_SESSION["urlfrom"];
|
||||||
|
|
||||||
// Module Phenix
|
// Phenix module
|
||||||
if ($conf->phenix->enabled && $conf->phenix->cookie)
|
if ($conf->phenix->enabled && $conf->phenix->cookie)
|
||||||
{
|
{
|
||||||
// Destruction du cookie
|
// Destroy cookie
|
||||||
setcookie($conf->phenix->cookie, '', 1, "/");
|
setcookie($conf->phenix->cookie, '', 1, "/");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Multi-Company module
|
||||||
|
if ($conf->multicompany->enabled)
|
||||||
|
{
|
||||||
|
// Destroy entity cookie
|
||||||
|
$entityCookieName = "DOLENTITYID_dolibarr";
|
||||||
|
setcookie($entityCookieName, '', 1, "/");
|
||||||
|
}
|
||||||
|
|
||||||
// Destroy session
|
// Destroy session
|
||||||
$sessionname="DOLSESSID_".$dolibarr_main_db_name;
|
$sessionname="DOLSESSID_".$dolibarr_main_db_name;
|
||||||
if (! empty($conf->global->MAIN_SESSION_TIMEOUT)) ini_set('session.gc_maxlifetime',$conf->global->MAIN_SESSION_TIMEOUT);
|
if (! empty($conf->global->MAIN_SESSION_TIMEOUT)) ini_set('session.gc_maxlifetime',$conf->global->MAIN_SESSION_TIMEOUT);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user