// fixed bugs related to admin bo_theme and its detection / employee update in init.php
This commit is contained in:
1 parent
8c8bc468eb
commit
9868335d40
1 file changed
+77
-62
+77
-62
@@ -31,69 +31,84 @@ $timerStart = microtime(true);
|
|||||||
// $_GET['tab'] = $_GET['controller'];
|
// $_GET['tab'] = $_GET['controller'];
|
||||||
// $_POST['tab'] = $_POST['controller'];
|
// $_POST['tab'] = $_POST['controller'];
|
||||||
// $_REQUEST['tab'] = $_REQUEST['controller'];
|
// $_REQUEST['tab'] = $_REQUEST['controller'];
|
||||||
|
try
|
||||||
$context = Context::getContext();
|
|
||||||
if (isset($_GET['logout']))
|
|
||||||
$context->employee->logout();
|
|
||||||
|
|
||||||
if (!isset($context->employee) || !$context->employee->isLoggedBack())
|
|
||||||
Tools::redirectAdmin('index.php?controller=AdminLogin&redirect='.$_SERVER['REQUEST_URI']);
|
|
||||||
|
|
||||||
// Set current index
|
|
||||||
$currentIndex = $_SERVER['SCRIPT_NAME'].(($controller = Tools::getValue('controller')) ? '?controller='.$controller: '');
|
|
||||||
|
|
||||||
if ($back = Tools::getValue('back'))
|
|
||||||
$currentIndex .= '&back='.urlencode($back);
|
|
||||||
AdminTab::$currentIndex = $currentIndex;
|
|
||||||
|
|
||||||
$iso = $context->language->iso_code;
|
|
||||||
include(_PS_TRANSLATIONS_DIR_.$iso.'/errors.php');
|
|
||||||
include(_PS_TRANSLATIONS_DIR_.$iso.'/fields.php');
|
|
||||||
include(_PS_TRANSLATIONS_DIR_.$iso.'/admin.php');
|
|
||||||
|
|
||||||
/* Server Params */
|
|
||||||
$protocol_link = (Configuration::get('PS_SSL_ENABLED')) ? 'https://' : 'http://';
|
|
||||||
$protocol_content = (isset($useSSL) AND $useSSL AND Configuration::get('PS_SSL_ENABLED')) ? 'https://' : 'http://';
|
|
||||||
$link = new Link($protocol_link, $protocol_content);
|
|
||||||
$context->link = $link;
|
|
||||||
define('_PS_BASE_URL_', Tools::getShopDomain(true));
|
|
||||||
define('_PS_BASE_URL_SSL_', Tools::getShopDomainSsl(true));
|
|
||||||
|
|
||||||
$path = dirname(__FILE__).'/themes/';
|
|
||||||
if (empty($context->employee->bo_theme) OR !file_exists($path.$context->employee->bo_theme.'/admin.css'))
|
|
||||||
{
|
{
|
||||||
if (file_exists($path.'oldschool/admin.css'))
|
$context = Context::getContext();
|
||||||
$context->employee->bo_theme = 'oldschool';
|
if (isset($_GET['logout']))
|
||||||
elseif (file_exists($path.'origins/admin.css'))
|
$context->employee->logout();
|
||||||
$context->employee->bo_theme = 'origins';
|
|
||||||
else
|
|
||||||
foreach (scandir($path) as $theme)
|
|
||||||
if ($theme[0] != '.' AND file_exists($path.$theme.'/admin.css'))
|
|
||||||
{
|
|
||||||
$employee->bo_theme = $theme;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
$context->employee->update();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Change shop context ?
|
if (!isset($context->employee) || !$context->employee->isLoggedBack())
|
||||||
if (Shop::isFeatureActive() && Tools::getValue('setShopContext') !== false)
|
Tools::redirectAdmin('index.php?controller=AdminLogin&redirect='.$_SERVER['REQUEST_URI']);
|
||||||
|
|
||||||
|
// Set current index
|
||||||
|
$currentIndex = $_SERVER['SCRIPT_NAME'].(($controller = Tools::getValue('controller')) ? '?controller='.$controller: '');
|
||||||
|
|
||||||
|
if ($back = Tools::getValue('back'))
|
||||||
|
$currentIndex .= '&back='.urlencode($back);
|
||||||
|
AdminTab::$currentIndex = $currentIndex;
|
||||||
|
|
||||||
|
$iso = $context->language->iso_code;
|
||||||
|
include(_PS_TRANSLATIONS_DIR_.$iso.'/errors.php');
|
||||||
|
include(_PS_TRANSLATIONS_DIR_.$iso.'/fields.php');
|
||||||
|
include(_PS_TRANSLATIONS_DIR_.$iso.'/admin.php');
|
||||||
|
|
||||||
|
/* Server Params */
|
||||||
|
$protocol_link = (Configuration::get('PS_SSL_ENABLED')) ? 'https://' : 'http://';
|
||||||
|
$protocol_content = (isset($useSSL) AND $useSSL AND Configuration::get('PS_SSL_ENABLED')) ? 'https://' : 'http://';
|
||||||
|
$link = new Link($protocol_link, $protocol_content);
|
||||||
|
$context->link = $link;
|
||||||
|
define('_PS_BASE_URL_', Tools::getShopDomain(true));
|
||||||
|
define('_PS_BASE_URL_SSL_', Tools::getShopDomainSsl(true));
|
||||||
|
|
||||||
|
$path = dirname(__FILE__).'/themes/';
|
||||||
|
// if the current employee theme is not valid (check layout.tpl presence),
|
||||||
|
// reset to default theme
|
||||||
|
if (empty($context->employee->bo_theme) ||
|
||||||
|
!file_exists($path.$employee->bo_theme.'/template/layout.tpl'))
|
||||||
|
{
|
||||||
|
// default admin theme is "default".
|
||||||
|
$context->employee->bo_theme = '';
|
||||||
|
if (file_exists($path.'default/template/layout.tpl'))
|
||||||
|
$context->employee->bo_theme = 'default';
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// if default theme doesn't exists, try to find one, otherwise throw exception
|
||||||
|
foreach (scandir($path) as $theme)
|
||||||
|
if ($theme[0] != '.' && file_exists($path.$theme.'/template/layout.tpl'))
|
||||||
|
{
|
||||||
|
$context->employee->bo_theme = $theme;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// if no theme is found, admin can't work.
|
||||||
|
if (empty($context->employee->bo_theme))
|
||||||
|
throw new PrestaShopException('Unable to load theme for employee, and no valid theme found');
|
||||||
|
}
|
||||||
|
$context->employee->update();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Change shop context ?
|
||||||
|
if (Shop::isFeatureActive() && Tools::getValue('setShopContext') !== false)
|
||||||
|
{
|
||||||
|
$context->cookie->shopContext = Tools::getValue('setShopContext');
|
||||||
|
$url = parse_url($_SERVER['REQUEST_URI']);
|
||||||
|
$query = (isset($url['query'])) ? $url['query'] : '';
|
||||||
|
parse_str($query, $parseQuery);
|
||||||
|
unset($parseQuery['setShopContext']);
|
||||||
|
Tools::redirectAdmin($url['path'] . '?' . http_build_query($parseQuery));
|
||||||
|
}
|
||||||
|
|
||||||
|
$context->currency = new Currency(Configuration::get('PS_CURRENCY_DEFAULT'));
|
||||||
|
|
||||||
|
$shopID = '';
|
||||||
|
if ($context->cookie->shopContext)
|
||||||
|
{
|
||||||
|
$split = explode('-', $context->cookie->shopContext);
|
||||||
|
if (count($split) == 2 && $split[0] == 's')
|
||||||
|
$shopID = (int)$split[1];
|
||||||
|
}
|
||||||
|
$context->shop = new Shop($shopID);
|
||||||
|
}
|
||||||
|
catch(PrestaShopException $e)
|
||||||
{
|
{
|
||||||
$context->cookie->shopContext = Tools::getValue('setShopContext');
|
$e->displayMessage();
|
||||||
$url = parse_url($_SERVER['REQUEST_URI']);
|
|
||||||
$query = (isset($url['query'])) ? $url['query'] : '';
|
|
||||||
parse_str($query, $parseQuery);
|
|
||||||
unset($parseQuery['setShopContext']);
|
|
||||||
Tools::redirectAdmin($url['path'] . '?' . http_build_query($parseQuery));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$context->currency = new Currency(Configuration::get('PS_CURRENCY_DEFAULT'));
|
|
||||||
|
|
||||||
$shopID = '';
|
|
||||||
if ($context->cookie->shopContext)
|
|
||||||
{
|
|
||||||
$split = explode('-', $context->cookie->shopContext);
|
|
||||||
if (count($split) == 2 && $split[0] == 's')
|
|
||||||
$shopID = (int)$split[1];
|
|
||||||
}
|
|
||||||
$context->shop = new Shop($shopID);
|
|
||||||
Reference in new issue
Block a user