// AdminTab compatibility: Dispatcher for BO now search tabs in database, not on the disk. AdminTabs now uses the new BO theme.

git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@10236 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
tDidierjean
2011-11-17 18:15:07 +00:00
parent 60272fbce4
commit 740ac7c843
9 changed files with 163 additions and 145 deletions
+15 -13
View File
@@ -49,13 +49,20 @@ function bindDatepicker($id, $time)
});';
}
// id can be a identifier or an array of identifiers
/**
* Deprecated since 1.5
* Use Controller::addJqueryUi('ui.datepicker') instead
*
* @param int|array $id id can be a identifier or an array of identifiers
* @param unknown_type $time
*/
function includeDatepicker($id, $time = false)
{
Tools::displayAsDeprecated();
echo '<script type="text/javascript" src="'.__PS_BASE_URI__.'js/jquery/jquery-ui-1.8.10.custom.min.js"></script>';
$iso = Db::getInstance()->getValue('SELECT iso_code FROM '._DB_PREFIX_.'lang WHERE `id_lang` = '.(int)Context::getContext()->language->id);
if ($iso != 'en')
echo '<script type="text/javascript" src="'.__PS_BASE_URI__.'js/jquery/datepicker/ui/i18n/ui.datepicker-'.$iso.'.js"></script>';
echo '<script type="text/javascript" src="'.__PS_BASE_URI__.'js/jquery/ui/i18n/jquery.ui.datepicker-'.$iso.'.js"></script>';
echo '<script type="text/javascript">';
if (is_array($id))
foreach ($id as $id2)
@@ -233,16 +240,12 @@ function translate($string)
*/
function checkingTab($tab)
{
static $controllers;
if (is_null($controllers))
$controllers = Dispatcher::getControllers(_PS_ADMIN_DIR_.'/tabs/');
$tab = trim($tab);
$tab_lowercase = strtolower($tab);
if (!Validate::isTabName($tab))
return false;
$row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('SELECT id_tab, module FROM `'._DB_PREFIX_.'tab` WHERE class_name = \''.pSQL($tab).'\'');
$row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('SELECT id_tab, module, class_name FROM `'._DB_PREFIX_.'tab` WHERE class_name = \''.pSQL($tab).'\'');
if (!$row['id_tab'])
{
if (isset(AdminTab::$tabParenting[$tab]))
@@ -250,10 +253,8 @@ function checkingTab($tab)
echo sprintf(Tools::displayError('Tab %s cannot be found.'),$tab);
return false;
}
if ($row['module'] AND file_exists(_PS_MODULE_DIR_.'/'.$row['module'].'/'.$controllers[$tab_lowercase].'.php'))
include_once(_PS_MODULE_DIR_.'/'.$row['module'].'/'.$controllers[$tab_lowercase].'.php');
elseif (file_exists(_PS_ADMIN_DIR_.'/tabs/'.$controllers[$tab_lowercase].'.php'))
include_once(_PS_ADMIN_DIR_.'/tabs/'.$controllers[$tab_lowercase].'.php');
// Class file is included in Dispatcher::dispatch() function
if (!class_exists($tab, false) OR !$row['id_tab'])
{
echo sprintf(Tools::displayError('Tab file %s cannot be found.'),$tab);
@@ -434,7 +435,7 @@ function generateShopList()
*
* @return void
*/
function runAdminTab($ajaxMode = false)
function runAdminTab($tab, $ajaxMode = false)
{
$ajaxMode = (bool)$ajaxMode;
@@ -449,6 +450,7 @@ function runAdminTab($ajaxMode = false)
// $tab = $_REQUEST['tab'];
if ($adminObj = checkingTab($tab))
{
$noTabLink = $adminObj->noTabLink;
// init is different for new tabs (AdminController) and old tabs (AdminTab)
if ($adminObj instanceof AdminController)
{
+34 -31
View File
@@ -183,7 +183,8 @@ echo ' var html = "";
<body '.((!empty(Context::getContext()->employee->bo_color)) ? 'style="background:'.Tools::htmlentitiesUTF8(Context::getContext()->employee->bo_color).'"' : '').'>
<div id="top_container">
<div id="container">
<div id="header_infos"><span>
<div id="header">
<div id="header_infos">
<a id="header_shopname" href="index.php"><span>'.Configuration::get('PS_SHOP_NAME').'</span></a><div id="notifs_icon_wrapper">';
if (Configuration::get('PS_SHOW_NEW_ORDERS') == 1)
{
@@ -219,12 +220,14 @@ echo ' var html = "";
</div>';
}
echo '</div><span id="employee_links">
<a href="index.php?controller=AdminEmployees&id_employee='.(int)Context::getContext()->employee->id.'&updateemployee&token='.Tools::getAdminTokenLite('AdminEmployees').'" class="employee" alt="">'.translate('My preferences').'</a>
<span class="separator"></span>
<span class="employee_name">
'.Tools::substr(Context::getContext()->employee->firstname, 0, 1).'.&nbsp;'.htmlentities(Context::getContext()->employee->lastname, ENT_COMPAT, 'UTF-8').'
[ <a href="index.php?logout" id="header_logout"><span>'.translate('logout').'</span></a> ]';
</span><span class="separator"></span><a href="index.php?logout" id="header_logout"><span>'.translate('logout').'</span></a><span class="separator"></span>';
if (Context::getContext()->shop->getBaseURL())
echo '- <a href="'.Context::getContext()->shop->getBaseURL().'" id="header_foaccess" target="_blank" title="'.translate('View my shop').'"><span>'.translate('View my shop').'</span></a>';
echo ' - <a href="index.php?controller=AdminEmployees&id_employee='.(int)Context::getContext()->employee->id.'&updateemployee&token='.Tools::getAdminTokenLite('AdminEmployees').'" style="font-size: 10px;"><img src="../img/admin/employee.gif" alt="" /> '.translate('My preferences').'</a>
</span></div>
echo '<a href="'.Context::getContext()->shop->getBaseURL().'" id="header_foaccess" target="_blank" title="'.translate('View my shop').'"><span>'.translate('View my shop').'</span></a>';
echo '</span>
<div id="header_search">
<form method="post" action="index.php?controller=AdminSearch&token='.Tools::getAdminTokenLite('AdminSearch').'">
<input type="text" name="bo_query" id="bo_query"
@@ -271,15 +274,15 @@ echo ' </select>
if (Shop::isFeatureActive())
echo '<div id="header_shoplist">'.translate('Select your shop:').' '.generateShopList().'</div>';
echo '<div class="flatclear">&nbsp;</div>';
echo '</div>';
echo Hook::exec('backOfficeTop');
echo '<ul id="menu">';
if (empty($tab))
echo '<div class="mainsubtablist" style="display:none"></div>';
// This is made to display the subtab list
$controllers = Dispatcher::getControllers(_PS_ADMIN_DIR_.'/tabs/');
$id_current_tab = (int)Tab::getIdFromClassName($controllers[$tab]);
$id_current_tab = (int)Tab::getIdFromClassName($tab);
$myCurrentTab = new Tab($id_current_tab);
$tabs = Tab::getTabs(Context::getContext()->language->id, 0);
$echoLis = '';
@@ -292,42 +295,42 @@ foreach ($tabs AS $t)
if (trim($t['module']) != '')
$img = _MODULE_DIR_.$t['module'].'/'.$t['class_name'].'.gif';
$current = ((strtolower($t['class_name']) == $tab) OR ($myCurrentTab->id_parent == $t['id_tab']));
echo '<li class="submenu_size '.($current ? 'active' : '').'" id="maintab'.$t['id_tab'].'">
<a href="index.php?controller='.$t['class_name'].'&token='.Tools::getAdminToken($t['class_name'].(int)($t['id_tab']).(int)Context::getContext()->employee->id).'">
echo '<li class="submenu_size '.($current ? 'active' : '').' maintab" id="maintab'.$t['id_tab'].'">
<span class="title">
<img src="'.$img.'" alt="" /> '.$t['name'].'
</a>
</li>';
$echoLi = '';
</span>
<ul class="submenu">';
$subTabs = Tab::getTabs(Context::getContext()->language->id, (int)$t['id_tab']);
// @todo need a better way than using noTabLink property, keeping the fact to avoid db modification
if (!in_array($t['class_name'], $noTabLink))
array_unshift($subTabs, $t);
foreach ($subTabs AS $t2)
if (checkTabRights($t2['id_tab']) === true)
$echoLi .= '<li><a href="index.php?controller='.$t2['class_name'].'&token='.Tools::getAdminTokenLite($t2['class_name']).'">'.$t2['name'].'</a></li>';
echo '<li><a href="index.php?controller='.$t2['class_name'].'&token='.Tools::getAdminTokenLite($t2['class_name']).'">'.$t2['name'].'</a></li>';
echo '</ul></li>';
$echoLi = '';
foreach ($subTabs AS $t2)
if (checkTabRights($t2['id_tab']) === true)
$echoLi .= '<li class="subitem"><a href="index.php?controller='.$t2['class_name'].'&token='.Tools::getAdminTokenLite($t2['class_name']).'">'.$t2['name'].'</a></li>';
if ($current)
$mainsubtablist = $echoLi;
$echoLis .= '<div id="tab'.(int)($t['id_tab']).'_subtabs" style="display:none">'.$echoLi.'</div>';
}
echo ' </ul>'.$echoLis;
if (Context::getContext()->employee->bo_uimode == 'hover')
echo ' <script type="text/javascript">
$("#menu li").hoverIntent({over:hoverTabs,timeout:100,out:outTabs});
function outTabs(){}
function hoverTabs() {
var content = $("#tab"+parseInt(this.id.substr(7, 3))+"_subtabs").html();
$("#submenu").html(content);
if (content.length == 0)
$("#submenu").removeClass("withLeftBorder");
else
$("#submenu").addClass("withLeftBorder");
$("#menu li").removeClass("active");
$(this).addClass("active");
}
</script>';
echo ' <ul id="submenu" '.(strlen($mainsubtablist) ? 'class="withLeftBorder clearfix"' : '').'>'.$mainsubtablist.'</ul>
<div id="main">
echo '
</div>
<div id="main">
<div id="content">'
.(file_exists(_PS_ADMIN_DIR_.'/../install') ? '<div style="background-color: #FFEBCC;border: 1px solid #F90;line-height: 20px;margin: 0px 0px 10px;padding: 10px 20px;">'
.translate('For security reasons, you must also:').' '.
translate('delete the /install folder').
'</div>' : '').'
';
if(defined('_PS_MODE_DEV_') && _PS_MODE_DEV_)
echo '<div class="warn">This tab is an AdminTab</div>';
+2 -2
View File
@@ -38,7 +38,7 @@ if (!isset($_REQUEST['controller']) && isset($_REQUEST['tab']))
$_REQUEST['controller'] = strtolower($_REQUEST['tab']);
// Prepare and trigger admin dispatcher
Dispatcher::getInstance()->setDefaultController('adminhome');
Dispatcher::getInstance()->setControllerNotFound('adminnotfound');
Dispatcher::getInstance()->setDefaultController('AdminHome');
Dispatcher::getInstance()->setControllerNotFound('AdminNotFound');
Dispatcher::getInstance()->setControllerDirectories(array(_PS_ADMIN_DIR_.'/tabs/', _PS_ADMIN_CONTROLLER_DIR_));
Dispatcher::getInstance()->dispatch();
+2 -7
View File
@@ -39,14 +39,9 @@ if (isset($_GET['logout']))
if (!isset($context->employee) || !$context->employee->isLoggedBack())
Tools::redirectAdmin('login.php?redirect='.$_SERVER['REQUEST_URI']);
// Set current index
//$currentIndex = $_SERVER['SCRIPT_NAME'].(($tab = Tools::getValue('tab')) ? '?tab='.$tab : '');
//if (empty($tab))
//{
$currentIndex = $_SERVER['SCRIPT_NAME'].(($controller = Tools::getValue('controller')) ? '?controller='.$controller: '');
$tab = $controller;
//}
$currentIndex = $_SERVER['SCRIPT_NAME'].(($controller = Tools::getValue('controller')) ? '?controller='.$controller: '');
if ($back = Tools::getValue('back'))
$currentIndex .= '&back='.urlencode($back);
AdminTab::$currentIndex = $currentIndex;
+40 -74
View File
@@ -239,79 +239,45 @@ $(document).ready(function()
</select>
</div>
{if $multi_shop}
<div id="header_shoplist"><span>{l s='Select your shop:'}</span>{$shop_list}</div>
{/if}
{$HOOK_TOP}
</div>
<ul id="menu">
{if !$tab}
<div class="mainsubtablist" style="display:none">
</div>
{/if}
{foreach $tabs AS $t}
<li class="submenu_size maintab {if $t.current}active{/if}" id="maintab{$t.id_tab}">
<span class="title">
<img src="{$t.img}" alt="" />{$t.name}
</span>
<ul class="submenu">
{foreach from=$t.sub_tabs item=t2}
<li><a href="{$t2.href}">{$t2.name}</a></li>
{/foreach}
</ul>
</li>
{/foreach}
</ul>
{foreach $tabs AS $t}
<div id="tab{$t.id_tab}_subtabs" style="display:none">
{foreach $t.sub_tabs AS $t2}
<li class="subitem" ><a href="{$t2.href}">{$t2.name}</a></li>
{/foreach}
<div class="flatclear">&nbsp;</div>
</div>
{if $multi_shop}
<div id="header_shoplist"><span>{l s='Select your shop:'}</span>{$shop_list}</div>
{/if}
{$HOOK_TOP}
</div>
<ul id="menu">
{if !$tab}
<div class="mainsubtablist" style="display:none">
</div>
{/if}
{foreach $tabs AS $t}
<li class="submenu_size maintab {if $t.current}active{/if}" id="maintab{$t.id_tab}">
<span class="title">
<img src="{$t.img}" alt="" />{$t.name}
</span>
<ul class="submenu">
{foreach from=$t.sub_tabs item=t2}
<li><a href="{$t2.href}">{$t2.name}</a></li>
{/foreach}
{* @todo : handle bo_uimode == hover / not hover ?
{if $employee->bo_uimode == 'hover'}
<script type="text/javascript">
$("#menu li").hoverIntent( { over:hoverTabs,timeout:100,out:outTabs } );
function outTabs(){}
function hoverTabs() {
var content = $("#tab"+parseInt(this.id.substr(7, 3))+"_subtabs").html();
$("#submenu").html(content);
if (content.length == 0)
$("#submenu").removeClass("withLeftBorder");
else
$("#submenu").addClass("withLeftBorder");
$("#menu li").removeClass("active");
$(this).addClass("active");
}
</script>
{/if}
<ul id="submenu" {if isset($mainsubtab)}class="withLeftBorder clearfix"{/if}>
{if isset($mainsubtab)}
{foreach $mainsubtab.sub_tabs AS $t}
<li>
<a href="{$t.href}">{$t.name}</a></li>
{/foreach}
{/if}
</ul>
*}
</div> {* end header *}
</ul>
</li>
{/foreach}
</ul>
</div> {* end header *}
{/if}
<div id="main">
<div id="content">
{if $install_dir_exists}
<div style="background-color: #FFEBCC;border: 1px solid #F90;line-height: 20px;margin: 0px 0px 10px;padding: 10px 20px;">
{l s='For security reasons, you must also:'} {l s='delete the /install folder'}
</div>
{/if}
{if $is_multishop && $shop_context != 'all'}
<div class="multishop_info">
{if $shop_context == 'group'}
{l s='You are configuring your store for group shop '}<b>{$shop_name}</b>
{elseif $shop_context == 'shop'}
{l s='You are configuring your store for shop '}<b>{$shop_name}</b>
{/if}
</div>
{/if}
<div id="main">
<div id="content">
{if $install_dir_exists}
<div style="background-color: #FFEBCC;border: 1px solid #F90;line-height: 20px;margin: 0px 0px 10px;padding: 10px 20px;">
{l s='For security reasons, you must also:'} {l s='delete the /install folder'}
</div>
{/if}
{if $is_multishop && $shop_context != 'all'}
<div class="multishop_info">
{if $shop_context == 'group'}
{l s='You are configuring your store for group shop '}<b>{$shop_name}</b>
{elseif $shop_context == 'shop'}
{l s='You are configuring your store for shop '}<b>{$shop_name}</b>
{/if}
</div>
{/if}
+1 -3
View File
@@ -26,7 +26,7 @@
{include file='header.tpl'}
{if isset($conf)}
<div class="conf">
<img src="../img/admin/ok2.png" alt="" />{$conf}
{$conf}
</div>
{/if}
@@ -35,7 +35,6 @@
<span style="float:right">
<a id="hideError" href="#"><img alt="X" src="../img/admin/close.png" /></a>
</span>
<img src="../img/admin/error2.png" />
{if count($errors) == 1}
{$errors[0]}
{else}
@@ -71,7 +70,6 @@
<span style="float:right">
<a id="hideWarn" href=""><img alt="X" src="../img/admin/close.png" /></a>
</span>
<img src="../img/admin/warn2.png" />
{if count($warnings) > 1}
{l s='There are'} {count($warnings)} {l s='warnings'}
{else}
+2 -3
View File
@@ -61,7 +61,7 @@ class AdminControllerCore extends Controller
/** @var integer Tab id */
public $id = -1;
/** @var array noTabLink array of admintab names witch have no content */
/** @var array noTabLink array of admintabs with no content */
public $noTabLink = array('AdminCatalog', 'AdminTools', 'AdminStock', 'AdminAccounting');
/** @var string Security token */
@@ -748,7 +748,6 @@ class AdminControllerCore extends Controller
if ($this->tabAccess['edit'] === '1')
{
$this->beforeUpdateOptions();
$languages = Language::getLanguages(false);
foreach ($this->options as $category => $category_data)
@@ -852,7 +851,7 @@ class AdminControllerCore extends Controller
}
else
$this->_errors[] = Tools::displayError('You do not have permission to edit here.');
// todo : return value ?
}
+3
View File
@@ -199,6 +199,9 @@ abstract class AdminTabCore
'AdminStatsTab' => 'AdminStats'
);
/** @var array noTabLink array of admintabs with no content */
public $noTabLink = array('AdminCatalog', 'AdminTools', 'AdminStock', 'AdminAccounting');
public function __construct()
{
$this->context = Context::getContext();
+64 -12
View File
@@ -144,12 +144,12 @@ class DispatcherCore
/**
* @var string Set default controller, which will be used if http parameter 'controller' is empty
*/
protected $default_controller = 'index';
protected $default_controller = 'Index';
/**
* @var string Controller to use if found controller doesn't exist
*/
protected $controller_not_found = 'pagenotfound';
protected $controller_not_found = 'PageNotFound';
/**
* @var array List of controllers where are stored controllers
@@ -217,6 +217,30 @@ class DispatcherCore
$this->controller_directories = $dir;
}
public static function getAdminController($name)
{
if (!Validate::isTabName($name))
return false;
$row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('SELECT id_tab, class_name, module FROM `'._DB_PREFIX_.'tab` WHERE LOWER(class_name) = \''.pSQL($name).'\'');
return $row;
}
public static function includeModuleClass($module, $name)
{
if (file_exists(_PS_MODULE_DIR_.$module.'/'.$name.'Controller.php'))
{
include(_PS_MODULE_DIR_.$module.'/'.$name.'Controller.php');
return true;
}
if (file_exists(_PS_MODULE_DIR_.$module.'/'.$name.'.php'))
{
include(_PS_MODULE_DIR_.$module.'/'.$name.'.php');
return false;
}
}
/**
* Find the controller and instantiate it
*/
@@ -234,26 +258,54 @@ class DispatcherCore
// Get current controller and list of controllers
$this->getController();
$controllers = Dispatcher::getControllers($this->controller_directories);
if (!$this->controller)
$this->controller = $this->default_controller;
// For retrocompatibility with admin/tabs/ old system
if (isset($controllers[$this->controller]) && defined('_PS_ADMIN_DIR_') && file_exists(_PS_ADMIN_DIR_.'/tabs/'.$controllers[$this->controller].'.php'))
// FO dispatch
if (!defined('_PS_ADMIN_DIR_'))
{
require_once(_PS_ADMIN_DIR_.'/functions.php');
$ajaxMode = !empty($_REQUEST['ajaxMode']);
runAdminTab($ajaxMode);
return;
$controllers = self::getControllers($this->controller_directories);
if (isset($controllers[$this->controller]))
$this->controller = $controllers[$this->controller];
else
$this->controller = $this->controller_not_found;
}
// BO dispatch
else
{
// Get controller class name
$controller_row = self::getAdminController($this->controller);
if (empty($controller_row))
$this->controller = $this->controller_not_found;
else
$this->controller = $controller_row['class_name'];
// If Tab/Controller is in module, include it
if (!empty($controller_row['module']))
$is_controller = self::includeModuleClass($controller_row['module'], $this->controller);
// If it is an AdminTab, include it
elseif (file_exists(_PS_ADMIN_DIR_.'/tabs/'.$this->controller.'.php'))
{
include(_PS_ADMIN_DIR_.'/tabs/'.$this->controller.'.php');
$is_controller = false;
}
// For retrocompatibility with admin/tabs/ old system
if (isset($is_controller) && !$is_controller)
{
require_once(_PS_ADMIN_DIR_.'/functions.php');
$ajaxMode = !empty($_REQUEST['ajaxMode']);
runAdminTab($this->controller, $ajaxMode);
return;
}
else
$this->controller = $this->controller.'Controller';
}
else if (!isset($controllers[$this->controller]))
$this->controller = $this->controller_not_found;
// Instantiate controller
try
{
Controller::getController($controllers[$this->controller])->run();
Controller::getController($this->controller)->run();
}
catch (PrestashopException $e)
{