diff --git a/htdocs/core/conf.class.php b/htdocs/core/conf.class.php index f1e2428493e..9184e2a5556 100644 --- a/htdocs/core/conf.class.php +++ b/htdocs/core/conf.class.php @@ -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 diff --git a/htdocs/includes/modules/DolibarrModules.class.php b/htdocs/includes/modules/DolibarrModules.class.php index 23eb8831a81..493fdc9300a 100644 --- a/htdocs/includes/modules/DolibarrModules.class.php +++ b/htdocs/includes/modules/DolibarrModules.class.php @@ -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); diff --git a/htdocs/includes/modules/modMultiCompany.class.php b/htdocs/includes/modules/modMultiCompany.class.php index 5974fc283de..dec385d196b 100644 --- a/htdocs/includes/modules/modMultiCompany.class.php +++ b/htdocs/includes/modules/modMultiCompany.class.php @@ -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. diff --git a/htdocs/lib/security.lib.php b/htdocs/lib/security.lib.php index 68a5913f674..bad8a0bc1fa 100644 --- a/htdocs/lib/security.lib.php +++ b/htdocs/lib/security.lib.php @@ -143,6 +143,18 @@ function dol_loginfunction($langs,$conf,$mysoc) print '   '.$langs->trans("Password").'   '; print ''; print ''; + + // Entity field + if ($conf->multicompany->enabled) + { + $html = new Form($db); + //TODO: creer class + $entity = array('1'=>'company1','2'=>'company2'); + print '   '.$langs->trans("Entity").'   '; + print ''; + $html->select_array('entity',$entity); + print ''; + } print ' '."\n"; diff --git a/htdocs/main.inc.php b/htdocs/main.inc.php index 22e7ba9b9c9..1e55f197a92 100644 --- a/htdocs/main.inc.php +++ b/htdocs/main.inc.php @@ -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()); diff --git a/htdocs/user/logout.php b/htdocs/user/logout.php index 63023a3c967..de59304a6c5 100644 --- a/htdocs/user/logout.php +++ b/htdocs/user/logout.php @@ -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);