diff --git a/htdocs/core/class/conf.class.php b/htdocs/core/class/conf.class.php index b12210b5fd9..47cbd6cb01d 100644 --- a/htdocs/core/class/conf.class.php +++ b/htdocs/core/class/conf.class.php @@ -192,10 +192,12 @@ class Conf } $i++; } - - // Load multicompany configuration - if (! empty($this->multicompany->enabled)) + + // Object $mc + if (! defined('NOREQUIREMC') && ! empty($this->multicompany->enabled)) { + global $mc; + $ret = @dol_include_once('/multicompany/class/actions_multicompany.class.php'); if ($ret) { diff --git a/htdocs/core/lib/security.lib.php b/htdocs/core/lib/security.lib.php index 2dfe55ae0eb..dc3e2a0c13c 100644 --- a/htdocs/core/lib/security.lib.php +++ b/htdocs/core/lib/security.lib.php @@ -266,17 +266,10 @@ function dol_loginfunction($langs,$conf,$mysoc) // Entity field $select_entity=''; - if (! empty($conf->global->MAIN_MODULE_MULTICOMPANY) && empty($conf->global->MULTICOMPANY_HIDE_LOGIN_COMBOBOX)) + if (! empty($conf->multicompany->enabled) && empty($conf->global->MULTICOMPANY_HIDE_LOGIN_COMBOBOX)) { $rowspan++; - - $res=dol_include_once('/multicompany/class/actions_multicompany.class.php'); - if ($res) - { - $mc = new ActionsMulticompany($db); - - $select_entity=$mc->select_entities($lastentity, 'tabindex="3"', 1); - } + $select_entity = $mc->select_entities($lastentity, 'tabindex="3"', 1); } // Security graphical code diff --git a/htdocs/main.inc.php b/htdocs/main.inc.php index 3bf545422ec..0f28ce7722d 100644 --- a/htdocs/main.inc.php +++ b/htdocs/main.inc.php @@ -734,22 +734,12 @@ else $heightforframes=48; // Switch to another entity -if (!empty($conf->global->MAIN_MODULE_MULTICOMPANY)) +if (! empty($conf->multicompany->enabled) && GETPOST('action') == 'switchentity') { - if (GETPOST('action') == 'switchentity') + if ($mc->switchEntity(GETPOST('entity')) >= 0) { - $res = @dol_include_once("/multicompany/class/actions_multicompany.class.php"); - - if ($res) - { - $mc = new ActionsMulticompany($db); - - if($mc->switchEntity(GETPOST('entity')) >= 0) - { - Header("Location: ".DOL_URL_ROOT.'/'); - exit; - } - } + Header("Location: ".DOL_URL_ROOT.'/'); + exit; } } @@ -1032,7 +1022,9 @@ function top_htmlhead($head, $title='', $disablejs=0, $disablehead=0, $arrayofjs */ function top_menu($head, $title='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='') { - global $user, $conf, $langs, $db, $dolibarr_main_authentication; + global $user, $conf, $langs, $db; + global $dolibarr_main_authentication; + global $mc; $form=new Form($db); @@ -1217,16 +1209,10 @@ function top_menu($head, $title='', $target='', $disablejs=0, $disablehead=0, $a print $form->textwithtooltip('',$loginhtmltext,2,1,$logintext,'',1); - // Select entity - if (! empty($conf->global->MAIN_MODULE_MULTICOMPANY)) + // Show entity info + if (! empty($conf->multicompany->enabled)) { - $res=@dol_include_once('/multicompany/class/actions_multicompany.class.php'); - - if ($res) - { - $mc = new ActionsMulticompany($db); - $mc->showInfo($conf->entity); - } + $mc->showInfo($conf->entity); } print $form->textwithtooltip('',$logouthtmltext,2,1,$logouttext,'',1); diff --git a/htdocs/master.inc.php b/htdocs/master.inc.php index 2e351983167..6d4a338cbc8 100644 --- a/htdocs/master.inc.php +++ b/htdocs/master.inc.php @@ -93,7 +93,7 @@ if (! defined('NOREQUIRETRAN')) } /* - * Creation objet $db + * Object $db */ if (! defined('NOREQUIREDB')) { @@ -111,7 +111,7 @@ if (! defined('NOREQUIREDB')) unset($conf->db->pass); // This is to avoid password to be shown in memory/swap dump /* - * Creation objet $user + * Object $user */ if (! defined('NOREQUIREUSER')) { @@ -129,23 +129,22 @@ if (! defined('NOREQUIREDB')) { $conf->entity = $_SESSION["dol_entity"]; } - elseif (! empty($_ENV["dol_entity"])) // Entity inside a CLI script + else if (! empty($_ENV["dol_entity"])) // Entity inside a CLI script { $conf->entity = $_ENV["dol_entity"]; } - elseif (isset($_POST["loginfunction"]) && GETPOST("entity")) // Just after a login page + else if (isset($_POST["loginfunction"]) && GETPOST("entity")) // Just after a login page { $conf->entity = GETPOST("entity",'int'); } - else + else if (! empty($conf->file->cookie_cryptkey)) { $prefix=dol_getprefix(); $entityCookieName = 'DOLENTITYID_'.$prefix; - if (! empty($_COOKIE[$entityCookieName]) && ! empty($conf->file->cookie_cryptkey)) // Just for view specific login page + if (! empty($_COOKIE[$entityCookieName])) // Just for view specific login page { include_once(DOL_DOCUMENT_ROOT."/core/class/cookie.class.php"); - $lastuser = ''; - $lastentity = ''; + $lastuser = ''; $lastentity = ''; $entityCookie = new DolCookie($conf->file->cookie_cryptkey); $cookieValue = $entityCookie->_getCookie($entityCookieName); list($lastuser, $lastentity) = explode('|', $cookieValue); diff --git a/htdocs/user/fiche.php b/htdocs/user/fiche.php index d82a3db71b1..5cb79c1b98d 100644 --- a/htdocs/user/fiche.php +++ b/htdocs/user/fiche.php @@ -746,7 +746,6 @@ if (($action == 'create') || ($action == 'adduserldap')) { if (empty($conf->multicompany->transverse_mode) && $conf->entity == 1 && $user->admin && ! $user->entity) { - $mc = new ActionsMulticompany($db); print "".''.$langs->trans("Entity").''; print "".$mc->select_entities($conf->entity); print "\n"; @@ -1076,7 +1075,6 @@ else } else { - $mc = new ActionsMulticompany($db); $mc->getInfo($fuser->entity); print $mc->label; } @@ -1327,7 +1325,6 @@ else { if ($conf->entity == 1 && $conf->multicompany->transverse_mode) { - $mc = new ActionsMulticompany($db); print ''.$langs->trans("Entity").''; print "".$mc->select_entities($conf->entity); } @@ -1378,9 +1375,8 @@ else print img_object($langs->trans("ShowGroup"),"group").' '.$group->nom; } print ''; - if(! empty($conf->multicompany->enabled) && !empty($conf->multicompany->transverse_mode) && $conf->entity == 1 && $user->admin && ! $user->entity) + if (! empty($conf->multicompany->enabled) && ! empty($conf->multicompany->transverse_mode) && $conf->entity == 1 && $user->admin && ! $user->entity) { - $mc = new ActionsMulticompany($db); $mc->getInfo($group->usergroup_entity); print ''.$mc->label.""; } @@ -1594,9 +1590,8 @@ else //Multicompany if (! empty($conf->multicompany->enabled)) { - if(empty($conf->multicompany->transverse_mode) && $conf->entity == 1 && $user->admin && ! $user->entity) + if (empty($conf->multicompany->transverse_mode) && $conf->entity == 1 && $user->admin && ! $user->entity) { - $mc = new ActionsMulticompany($db); print "".''.$langs->trans("Entity").''; print "".$mc->select_entities($conf->entity); print "\n"; diff --git a/htdocs/user/group/fiche.php b/htdocs/user/group/fiche.php index f670ce144a9..105057af858 100644 --- a/htdocs/user/group/fiche.php +++ b/htdocs/user/group/fiche.php @@ -233,7 +233,6 @@ if ($action == 'create') { if (empty($conf->multicompany->transverse_mode) && $conf->entity == 1 && $user->admin && ! $user->entity) { - $mc = new ActionsMulticompany($db); print "".''.$langs->trans("Entity").''; print "".$mc->select_entities($conf->entity); print "\n"; @@ -311,7 +310,6 @@ else // Multicompany if (! empty($conf->multicompany->enabled) && empty($conf->multicompany->transverse_mode) && $conf->entity == 1 && $user->admin && ! $user->entity) { - $mc = new ActionsMulticompany($db); $mc->getInfo($object->entity); print "".''.$langs->trans("Entity").''; print ''.$mc->label; @@ -382,7 +380,6 @@ else { if ($conf->entity == 1 && $conf->multicompany->transverse_mode) { - $mc = new ActionsMulticompany($db); print ''.$langs->trans("Entity").''; print "".$mc->select_entities($conf->entity); } @@ -435,7 +432,6 @@ else print ''.$useringroup->firstname.''; if(! empty($conf->multicompany->enabled) && $conf->entity == 1) { - $mc = new ActionsMulticompany($db); $mc->getInfo($useringroup->usergroup_entity); print ''.$mc->label.""; } @@ -480,7 +476,6 @@ else { if (empty($conf->multicompany->transverse_mode) && $conf->entity == 1 && $user->admin && ! $user->entity) { - $mc = new ActionsMulticompany($db); print "".''.$langs->trans("Entity").''; print "".$mc->select_entities($object->entity); print "\n"; diff --git a/htdocs/user/group/index.php b/htdocs/user/group/index.php index 1ea8f476949..f0e34feffc0 100644 --- a/htdocs/user/group/index.php +++ b/htdocs/user/group/index.php @@ -108,8 +108,6 @@ if ($resql) //multicompany if(! empty($conf->multicompany->enabled) && empty($conf->multicompany->transverse_mode) && $conf->entity == 1) { - dol_include_once("/multicompany/class/actions_multicompany.class.php"); - $mc = new ActionsMulticompany($db); $mc->getInfo($obj->entity); print ''.$mc->label.''; } diff --git a/htdocs/user/home.php b/htdocs/user/home.php index 4db28e191a3..62a4cf6b637 100644 --- a/htdocs/user/home.php +++ b/htdocs/user/home.php @@ -153,7 +153,6 @@ if ($resql) } else { - $mc = new ActionsMulticompany($db); $mc->getInfo($obj->entity); print $mc->label; } @@ -232,7 +231,6 @@ if ($canreadperms) print ""; if (! empty($conf->multicompany->enabled)) { - $mc = new ActionsMulticompany($db); $mc->getInfo($obj->entity); print ''; print $mc->label; diff --git a/htdocs/user/index.php b/htdocs/user/index.php index 304d8508abb..b9f520a60d3 100644 --- a/htdocs/user/index.php +++ b/htdocs/user/index.php @@ -137,7 +137,6 @@ if ($result) } else { - $mc = new ActionsMulticompany($db); $mc->getInfo($obj->entity); print $mc->label; } diff --git a/htdocs/user/passwordforgotten.php b/htdocs/user/passwordforgotten.php index 6d5bc3c98e2..8a355b4b5b5 100644 --- a/htdocs/user/passwordforgotten.php +++ b/htdocs/user/passwordforgotten.php @@ -208,34 +208,27 @@ elseif (! empty($mysoc->logo_small) && is_readable($conf->mycompany->dir_output. // Entity combobox $select_entity=''; -if (! empty($conf->global->MAIN_MODULE_MULTICOMPANY) && empty($conf->global->MULTICOMPANY_HIDE_LOGIN_COMBOBOX) && ! $disabled) +if (! empty($conf->multicompany->enabled) && empty($conf->global->MULTICOMPANY_HIDE_LOGIN_COMBOBOX) && ! $disabled) { $rowspan++; $lastuser=''; $lastentity = GETPOST('entity'); - if (! empty($conf->global->MAIN_MULTICOMPANY_COOKIE)) + if (! empty($conf->global->MULTICOMPANY_COOKIE_ENABLED)) { $prefix=dol_getprefix(); $entityCookieName = 'DOLENTITYID_'.$prefix; if (isset($_COOKIE[$entityCookieName])) { include_once(DOL_DOCUMENT_ROOT . "/core/class/cookie.class.php"); - - $cryptkey = (! empty($conf->file->cookie_cryptkey) ? $conf->file->cookie_cryptkey : '' ); - - $entityCookie = new DolCookie($cryptkey); + $lastuser = ''; $lastentity = ''; + $entityCookie = new DolCookie($conf->file->cookie_cryptkey); $cookieValue = $entityCookie->_getCookie($entityCookieName); list($lastuser, $lastentity) = explode('|', $cookieValue); } } - $res=dol_include_once('/multicompany/class/actions_multicompany.class.php'); - if ($res) - { - $mc = new ActionsMulticompany($db); - $select_entity = $mc->select_entities($lastentity,'tabindex="2"'); - } + $select_entity = $mc->select_entities($lastentity,'tabindex="2"'); } // Security graphical code