From a07bbfa36f5ac865468418344d8fc777bceee756 Mon Sep 17 00:00:00 2001 From: tDidierjean Date: Thu, 17 Nov 2011 18:15:07 +0000 Subject: [PATCH] // AdminTab compatibility: Dispatcher for BO now search tabs in database, not on the disk. AdminTabs now uses the new BO theme. --- admin-dev/functions.php | 28 ++++--- admin-dev/header.inc.php | 65 +++++++-------- admin-dev/index.php | 4 +- admin-dev/init.php | 9 +-- admin-dev/themes/template/header.tpl | 114 ++++++++++----------------- admin-dev/themes/template/layout.tpl | 4 +- classes/AdminController.php | 5 +- classes/AdminTab.php | 3 + classes/Dispatcher.php | 76 +++++++++++++++--- 9 files changed, 163 insertions(+), 145 deletions(-) diff --git a/admin-dev/functions.php b/admin-dev/functions.php index 923f44b78..04c99cbb6 100644 --- a/admin-dev/functions.php +++ b/admin-dev/functions.php @@ -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 ''; $iso = Db::getInstance()->getValue('SELECT iso_code FROM '._DB_PREFIX_.'lang WHERE `id_lang` = '.(int)Context::getContext()->language->id); if ($iso != 'en') - echo ''; + echo ''; echo ''; -echo ' -
+ +echo ' +
+
' .(file_exists(_PS_ADMIN_DIR_.'/../install') ? '
' .translate('For security reasons, you must also:').' '. translate('delete the /install folder'). '
' : '').' '; + if(defined('_PS_MODE_DEV_') && _PS_MODE_DEV_) + echo '
This tab is an AdminTab
'; diff --git a/admin-dev/index.php b/admin-dev/index.php index b34f0ba31..4e1d1beeb 100644 --- a/admin-dev/index.php +++ b/admin-dev/index.php @@ -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(); diff --git a/admin-dev/init.php b/admin-dev/init.php index c3c99a4b9..d054fbb81 100644 --- a/admin-dev/init.php +++ b/admin-dev/init.php @@ -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; diff --git a/admin-dev/themes/template/header.tpl b/admin-dev/themes/template/header.tpl index 0d219ad54..4d41499e9 100644 --- a/admin-dev/themes/template/header.tpl +++ b/admin-dev/themes/template/header.tpl @@ -239,79 +239,45 @@ $(document).ready(function()
- {if $multi_shop} -
{l s='Select your shop:'}{$shop_list}
- {/if} - {$HOOK_TOP} -
- - {foreach $tabs AS $t} - + {if $multi_shop} +
{l s='Select your shop:'}{$shop_list}
+ {/if} + {$HOOK_TOP} + + + {* end header *} {/if} -
-
- {if $install_dir_exists} -
- {l s='For security reasons, you must also:'} {l s='delete the /install folder'} -
- {/if} - - {if $is_multishop && $shop_context != 'all'} -
- {if $shop_context == 'group'} - {l s='You are configuring your store for group shop '}{$shop_name} - {elseif $shop_context == 'shop'} - {l s='You are configuring your store for shop '}{$shop_name} - {/if} -
- {/if} +
+
+ {if $install_dir_exists} +
+ {l s='For security reasons, you must also:'} {l s='delete the /install folder'} +
+ {/if} + + {if $is_multishop && $shop_context != 'all'} +
+ {if $shop_context == 'group'} + {l s='You are configuring your store for group shop '}{$shop_name} + {elseif $shop_context == 'shop'} + {l s='You are configuring your store for shop '}{$shop_name} + {/if} +
+ {/if} diff --git a/admin-dev/themes/template/layout.tpl b/admin-dev/themes/template/layout.tpl index 0b0b9720a..d4c7c142b 100644 --- a/admin-dev/themes/template/layout.tpl +++ b/admin-dev/themes/template/layout.tpl @@ -26,7 +26,7 @@ {include file='header.tpl'} {if isset($conf)}
- {$conf} + {$conf}
{/if} @@ -35,7 +35,6 @@ X - {if count($errors) == 1} {$errors[0]} {else} @@ -71,7 +70,6 @@ X - {if count($warnings) > 1} {l s='There are'} {count($warnings)} {l s='warnings'} {else} diff --git a/classes/AdminController.php b/classes/AdminController.php index 5a9f4bd51..7858efe69 100644 --- a/classes/AdminController.php +++ b/classes/AdminController.php @@ -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 ? } diff --git a/classes/AdminTab.php b/classes/AdminTab.php index 377b5dc29..3a2bff7a8 100644 --- a/classes/AdminTab.php +++ b/classes/AdminTab.php @@ -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(); diff --git a/classes/Dispatcher.php b/classes/Dispatcher.php index 9886bbed1..f739cf38f 100644 --- a/classes/Dispatcher.php +++ b/classes/Dispatcher.php @@ -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) {