// code review of AdminGroupShop - norms

This commit is contained in:
mMarinetti committed 2012-01-27 16:00:15 +00:00
1 parent 84ab7f1fc3
commit 56932f40e3
4 files changed
+96 -93

No files matched your search

+2 -1
View File
@@ -73,6 +73,7 @@ class AdminControllerCore extends Controller
/** @var string Default ORDER BY clause when $_orderBy is not defined */ /** @var string Default ORDER BY clause when $_orderBy is not defined */
protected $_defaultOrderBy = false; protected $_defaultOrderBy = false;
protected $_defaultOrderWay = 'ASC';
public $tpl_form_vars = array(); public $tpl_form_vars = array();
public $tpl_list_vars = array(); public $tpl_list_vars = array();
@@ -1954,7 +1955,7 @@ class AdminControllerCore extends Controller
if (empty($order_by)) if (empty($order_by))
$order_by = $this->context->cookie->__get($this->table.'Orderby') ? $this->context->cookie->__get($this->table.'Orderby') : $this->_defaultOrderBy; $order_by = $this->context->cookie->__get($this->table.'Orderby') ? $this->context->cookie->__get($this->table.'Orderby') : $this->_defaultOrderBy;
if (empty($order_way)) if (empty($order_way))
$order_way = $this->context->cookie->__get($this->table.'Orderway') ? $this->context->cookie->__get($this->table.'Orderway') : 'ASC'; $order_way = $this->context->cookie->__get($this->table.'Orderway') ? $this->context->cookie->__get($this->table.'Orderway') : $this->_defaultOrderWay;
$limit = (int)Tools::getValue('pagination', $limit); $limit = (int)Tools::getValue('pagination', $limit);
$this->context->cookie->{$this->table.'_pagination'} = $limit; $this->context->cookie->{$this->table.'_pagination'} = $limit;
+21 -27
View File
@@ -28,6 +28,9 @@
class AdminCustomersControllerCore extends AdminController class AdminCustomersControllerCore extends AdminController
{ {
protected $delete_mode; protected $delete_mode;
protected $_defaultOrderBy = 'date_add';
protected $_defaultOrderWay = 'DESC';
public function __construct() public function __construct()
{ {
@@ -406,7 +409,6 @@ class AdminCustomersControllerCore extends AdminController
array_splice($this->fields_form['input'], $k, 1); array_splice($this->fields_form['input'], $k, 1);
} }
if (Shop::isFeatureActive()) if (Shop::isFeatureActive())
{ {
$this->fields_form['input'][] = array( $this->fields_form['input'][] = array(
@@ -514,7 +516,8 @@ class AdminCustomersControllerCore extends AdminController
} }
foreach ($groups as $group) foreach ($groups as $group)
$this->fields_value['groupBox_'.$group['id_group']] = Tools::getValue('groupBox_'.$group['id_group'], in_array($group['id_group'], $customer_groups_ids)); $this->fields_value['groupBox_'.$group['id_group']] =
Tools::getValue('groupBox_'.$group['id_group'], in_array($group['id_group'], $customer_groups_ids));
return parent::renderForm(); return parent::renderForm();
} }
@@ -644,6 +647,7 @@ class AdminCustomersControllerCore extends AdminController
for ($i = 0; $i < $total_referrers; $i++) for ($i = 0; $i < $total_referrers; $i++)
$referrers[$i]['date_add'] = Tools::displayDate($referrers[$i]['date_add'], $this->default_form_language, true); $referrers[$i]['date_add'] = Tools::displayDate($referrers[$i]['date_add'], $this->default_form_language, true);
$shop = new Shop($customer->id_shop);
$this->tpl_view_vars = array( $this->tpl_view_vars = array(
'customer' => $customer, 'customer' => $customer,
'gender_image' => $gender_image, 'gender_image' => $gender_image,
@@ -654,7 +658,7 @@ class AdminCustomersControllerCore extends AdminController
'last_visit' => Tools::displayDate($customer_stats['last_visit'], $this->default_form_language, true), 'last_visit' => Tools::displayDate($customer_stats['last_visit'], $this->default_form_language, true),
'count_better_customers' => $count_better_customers, 'count_better_customers' => $count_better_customers,
'shop_is_feature_active' => Shop::isFeatureActive(), 'shop_is_feature_active' => Shop::isFeatureActive(),
'name_shop' => Shop::getInstance($customer->id_shop)->name, 'name_shop' => $shop->name,
'customer_birthday' => Tools::displayDate($customer->birthday, $this->default_form_language), 'customer_birthday' => Tools::displayDate($customer->birthday, $this->default_form_language),
'last_update' => Tools::displayDate($customer->date_upd, $this->default_form_language, true), 'last_update' => Tools::displayDate($customer->date_upd, $this->default_form_language, true),
'customer_exists' => Customer::customerExists($customer->email), 'customer_exists' => Customer::customerExists($customer->email),
@@ -712,7 +716,7 @@ class AdminCustomersControllerCore extends AdminController
$this->deleted = true; $this->deleted = true;
else else
{ {
$this->errors[] = Tools::displayError('Unknown delete mode:'.' '.$this->deleted); $this->errors[] = Tools::displayError('Unknown delete mode:').' '.$this->deleted;
return; return;
} }
@@ -764,9 +768,9 @@ class AdminCustomersControllerCore extends AdminController
return parent::processSave($token); return parent::processSave($token);
} }
public function afterDelete($object, $oldId) public function afterDelete($object, $old_id)
{ {
$customer = new Customer($oldId); $customer = new Customer($old_id);
$addresses = $customer->getAddresses($this->default_form_language); $addresses = $customer->getAddresses($this->default_form_language);
foreach ($addresses as $k => $v) foreach ($addresses as $k => $v)
{ {
@@ -826,32 +830,19 @@ class AdminCustomersControllerCore extends AdminController
Tools::redirectAdmin(self::$currentIndex.'&token='.$this->token); Tools::redirectAdmin(self::$currentIndex.'&token='.$this->token);
} }
public function getList($id_lang, $order_by = null, $order_way = null, $start = 0, $limit = null, $id_lang_shop = null)
{
return parent::getList(
Context::getContext()->language->id,
!Tools::getValue($this->table.'Orderby') ? 'date_add' : null,
!Tools::getValue($this->table.'Orderway') ? 'DESC' : null
);
}
public static function printNewsIcon($id_customer, $tr) public static function printNewsIcon($id_customer, $tr)
{ {
$customer = new Customer($tr['id_customer']); return '<a href="index.php?tab=AdminCustomers&id_customer='
if (!Validate::isLoadedObject($customer)) .(int)$id_customer.'&changeNewsletterVal&token='.Tools::getAdminTokenLite('AdminCustomers').'">
return; '.($tr['newsletter'] ? '<img src="../img/admin/enabled.gif" />' : '<img src="../img/admin/disabled.gif" />').
return '<a href="index.php?tab=AdminCustomers&id_customer='.(int)$customer->id.'&changeNewsletterVal&token='.Tools::getAdminTokenLite('AdminCustomers').'">
'.($customer->newsletter ? '<img src="../img/admin/enabled.gif" />' : '<img src="../img/admin/disabled.gif" />').
'</a>'; '</a>';
} }
public static function printOptinIcon($id_customer, $tr) public static function printOptinIcon($id_customer, $tr)
{ {
$customer = new Customer($tr['id_customer']); return '<a href="index.php?tab=AdminCustomers&id_customer='
if (!Validate::isLoadedObject($customer)) .$id_customer.'&changeOptinVal&token='.Tools::getAdminTokenLite('AdminCustomers').'">;
return; '.($tr['optin'] ? '<img src="../img/admin/enabled.gif" />' : '<img src="../img/admin/disabled.gif" />').
return '<a href="index.php?tab=AdminCustomers&id_customer='.(int)$customer->id.'&changeOptinVal&token='.Tools::getAdminTokenLite('AdminCustomers').'">
'.($customer->optin ? '<img src="../img/admin/enabled.gif" />' : '<img src="../img/admin/disabled.gif" />').
'</a>'; '</a>';
} }
@@ -880,8 +871,11 @@ class AdminCustomersControllerCore extends AdminController
} }
/** /**
* Search customers * add to $this->content the result of Customer::SearchByName
*/ * (encoded in json)
*
* @return void
*/
public function ajaxProcessSearchCustomers() public function ajaxProcessSearchCustomers()
{ {
if ($customers = Customer::searchByName(pSQL(Tools::getValue('customer_search')))) if ($customers = Customer::searchByName(pSQL(Tools::getValue('customer_search'))))
@@ -122,7 +122,8 @@ class AdminGroupShopControllerCore extends AdminController
'label' => $this->l('Disabled') 'label' => $this->l('Disabled')
) )
), ),
'desc' => $this->l('Share orders and carts between shops of this group (you can share orders only if you share customers and available quantities)') 'desc' =>
$this->l('Share orders and carts between shops of this group (you can share orders only if you share customers and available quantities)')
), ),
array( array(
'type' => 'radio', 'type' => 'radio',
@@ -226,10 +227,11 @@ class AdminGroupShopControllerCore extends AdminController
'desc' => $this->l('Use this option to associate data (products, modules, etc.) the same way as the selected shop') 'desc' => $this->l('Use this option to associate data (products, modules, etc.) the same way as the selected shop')
); );
$default_group_shop = new Shop(Configuration::get('PS_SHOP_DEFAULT'));
$this->tpl_form_vars = array( $this->tpl_form_vars = array(
'disabled' => $disabled, 'disabled' => $disabled,
'checked' => (Tools::getValue('addgroup_shop') !== false) ? true : false, 'checked' => (Tools::getValue('addgroup_shop') !== false) ? true : false,
'defaultGroup' => Shop::getInstance(Configuration::get('PS_SHOP_DEFAULT'))->getGroupID(), 'defaultGroup' => $default_group_shop->getGroupID(),
); );
if (isset($this->fields_import_form)) if (isset($this->fields_import_form))
$this->tpl_form_vars = array_merge($this->tpl_form_vars, array('form_import' => $this->fields_import_form)); $this->tpl_form_vars = array_merge($this->tpl_form_vars, array('form_import' => $this->fields_import_form));
@@ -27,26 +27,26 @@
class AdminModulesPositionsControllerCore extends AdminController class AdminModulesPositionsControllerCore extends AdminController
{ {
private $displayKey = 0; private $display_key = 0;
public function postProcess() public function postProcess()
{ {
// Getting key value for display // Getting key value for display
if (Tools::getValue('show_modules') && strval(Tools::getValue('show_modules')) != 'all') if (Tools::getValue('show_modules') && strval(Tools::getValue('show_modules')) != 'all')
$this->displayKey = (int)(Tools::getValue('show_modules')); $this->display_key = (int)Tools::getValue('show_modules');
// Change position in hook // Change position in hook
if (array_key_exists('changePosition', $_GET)) if (array_key_exists('changePosition', $_GET))
{ {
if ($this->tabAccess['edit'] === '1') if ($this->tabAccess['edit'] === '1')
{ {
$id_module = (int)(Tools::getValue('id_module')); $id_module = (int)Tools::getValue('id_module');
$id_hook = (int)(Tools::getValue('id_hook')); $id_hook = (int)Tools::getValue('id_hook');
$module = Module::getInstanceById($id_module); $module = Module::getInstanceById($id_module);
if (Validate::isLoadedObject($module)) if (Validate::isLoadedObject($module))
{ {
$module->updatePosition($id_hook, (int)(Tools::getValue('direction'))); $module->updatePosition($id_hook, (int)Tools::getValue('direction'));
Tools::redirectAdmin(self::$currentIndex.($this->displayKey ? '&show_modules='.$this->displayKey : '').'&token='.$this->token); Tools::redirectAdmin(self::$currentIndex.($this->display_key ? '&show_modules='.$this->display_key : '').'&token='.$this->token);
} }
else else
$this->errors[] = Tools::displayError('module cannot be loaded'); $this->errors[] = Tools::displayError('module cannot be loaded');
@@ -58,12 +58,12 @@ class AdminModulesPositionsControllerCore extends AdminController
// Add new module in hook // Add new module in hook
elseif (Tools::isSubmit('submitAddToHook')) elseif (Tools::isSubmit('submitAddToHook'))
{ {
if ($this->tabAccess['add'] === '1') if ($this->tabAccess['add'] === '1')
{ {
// Getting vars... // Getting vars...
$id_module = (int)(Tools::getValue('id_module')); $id_module = (int)Tools::getValue('id_module');
$module = Module::getInstanceById($id_module); $module = Module::getInstanceById($id_module);
$id_hook = (int)(Tools::getValue('id_hook')); $id_hook = (int)Tools::getValue('id_hook');
$hook = new Hook($id_hook); $hook = new Hook($id_hook);
if (!$id_module || !Validate::isLoadedObject($module)) if (!$id_module || !Validate::isLoadedObject($module))
@@ -94,7 +94,7 @@ class AdminModulesPositionsControllerCore extends AdminController
} }
if (!$this->errors) if (!$this->errors)
Tools::redirectAdmin(self::$currentIndex.'&conf=16'.($this->displayKey ? '&show_modules='.$this->displayKey : '').'&token='.$this->token); Tools::redirectAdmin(self::$currentIndex.'&conf=16'.($this->display_key ? '&show_modules='.$this->display_key : '').'&token='.$this->token);
} }
} }
else else
@@ -104,12 +104,12 @@ class AdminModulesPositionsControllerCore extends AdminController
// Edit module from hook // Edit module from hook
elseif (Tools::isSubmit('submitEditGraft')) elseif (Tools::isSubmit('submitEditGraft'))
{ {
if ($this->tabAccess['add'] === '1') if ($this->tabAccess['add'] === '1')
{ {
// Getting vars... // Getting vars...
$id_module = (int)(Tools::getValue('id_module')); $id_module = (int)Tools::getValue('id_module');
$module = Module::getInstanceById($id_module); $module = Module::getInstanceById($id_module);
$id_hook = (int)(Tools::getValue('id_hook')); $id_hook = (int)Tools::getValue('id_hook');
$hook = new Hook($id_hook); $hook = new Hook($id_hook);
if (!$id_module || !Validate::isLoadedObject($module)) if (!$id_module || !Validate::isLoadedObject($module))
@@ -138,7 +138,7 @@ class AdminModulesPositionsControllerCore extends AdminController
$this->errors[] = Tools::displayError('An error occurred while transplanting module to hook.'); $this->errors[] = Tools::displayError('An error occurred while transplanting module to hook.');
if (!$this->errors) if (!$this->errors)
Tools::redirectAdmin(self::$currentIndex.'&conf=16'.($this->displayKey ? '&show_modules='.$this->displayKey : '').'&token='.$this->token); Tools::redirectAdmin(self::$currentIndex.'&conf=16'.($this->display_key ? '&show_modules='.$this->display_key : '').'&token='.$this->token);
} }
else else
{ {
@@ -153,7 +153,7 @@ class AdminModulesPositionsControllerCore extends AdminController
if (!$module->editExceptions($id_hook, $exceptions, Context::getContext()->shop->getListOfID())) if (!$module->editExceptions($id_hook, $exceptions, Context::getContext()->shop->getListOfID()))
$this->errors[] = Tools::displayError('An error occurred while transplanting module to hook.'); $this->errors[] = Tools::displayError('An error occurred while transplanting module to hook.');
else else
Tools::redirectAdmin(self::$currentIndex.'&conf=16'.($this->displayKey ? '&show_modules='.$this->displayKey : '').'&token='.$this->token); Tools::redirectAdmin(self::$currentIndex.'&conf=16'.($this->display_key ? '&show_modules='.$this->display_key : '').'&token='.$this->token);
} }
} }
} }
@@ -164,11 +164,11 @@ class AdminModulesPositionsControllerCore extends AdminController
// Delete module from hook // Delete module from hook
elseif (array_key_exists('deleteGraft', $_GET)) elseif (array_key_exists('deleteGraft', $_GET))
{ {
if ($this->tabAccess['delete'] === '1') if ($this->tabAccess['delete'] === '1')
{ {
$id_module = (int)(Tools::getValue('id_module')); $id_module = (int)Tools::getValue('id_module');
$module = Module::getInstanceById($id_module); $module = Module::getInstanceById($id_module);
$id_hook = (int)(Tools::getValue('id_hook')); $id_hook = (int)Tools::getValue('id_hook');
$hook = new Hook($id_hook); $hook = new Hook($id_hook);
if (!Validate::isLoadedObject($module)) if (!Validate::isLoadedObject($module))
$this->errors[] = Tools::displayError('module cannot be loaded'); $this->errors[] = Tools::displayError('module cannot be loaded');
@@ -176,10 +176,11 @@ class AdminModulesPositionsControllerCore extends AdminController
$this->errors[] = Tools::displayError('Hook cannot be loaded.'); $this->errors[] = Tools::displayError('Hook cannot be loaded.');
else else
{ {
if (!$module->unregisterHook($id_hook, Context::getContext()->shop->getListOfID()) || !$module->unregisterExceptions($id_hook, Context::getContext()->shop->getListOfID())) if (!$module->unregisterHook($id_hook, Context::getContext()->shop->getListOfID())
|| !$module->unregisterExceptions($id_hook, Context::getContext()->shop->getListOfID()))
$this->errors[] = Tools::displayError('An error occurred while deleting module from hook.'); $this->errors[] = Tools::displayError('An error occurred while deleting module from hook.');
else else
Tools::redirectAdmin(self::$currentIndex.'&conf=17'.($this->displayKey ? '&show_modules='.$this->displayKey : '').'&token='.$this->token); Tools::redirectAdmin(self::$currentIndex.'&conf=17'.($this->display_key ? '&show_modules='.$this->display_key : '').'&token='.$this->token);
} }
} }
else else
@@ -196,20 +197,20 @@ class AdminModulesPositionsControllerCore extends AdminController
$explode = explode('_', $unhook); $explode = explode('_', $unhook);
$id_hook = $explode[0]; $id_hook = $explode[0];
$id_module = $explode[1]; $id_module = $explode[1];
$module = Module::getInstanceById((int)($id_module)); $module = Module::getInstanceById((int)$id_module);
$hook = new Hook((int)($id_hook)); $hook = new Hook((int)$id_hook);
if (!Validate::isLoadedObject($module)) if (!Validate::isLoadedObject($module))
$this->errors[] = Tools::displayError('module cannot be loaded'); $this->errors[] = Tools::displayError('module cannot be loaded');
elseif (!$id_hook || !Validate::isLoadedObject($hook)) elseif (!$id_hook || !Validate::isLoadedObject($hook))
$this->errors[] = Tools::displayError('Hook cannot be loaded.'); $this->errors[] = Tools::displayError('Hook cannot be loaded.');
else else
{ {
if (!$module->unregisterHook((int)($id_hook)) || !$module->unregisterExceptions((int)($id_hook))) if (!$module->unregisterHook((int)$id_hook) || !$module->unregisterExceptions((int)$id_hook))
$this->errors[] = Tools::displayError('An error occurred while deleting module from hook.'); $this->errors[] = Tools::displayError('An error occurred while deleting module from hook.');
} }
} }
if (!count($this->errors)) if (!count($this->errors))
Tools::redirectAdmin(self::$currentIndex.'&conf=17'.($this->displayKey ? '&show_modules='.$this->displayKey : '').'&token='.$this->token); Tools::redirectAdmin(self::$currentIndex.'&conf=17'.($this->display_key ? '&show_modules='.$this->display_key : '').'&token='.$this->token);
} }
} }
} }
@@ -239,19 +240,19 @@ class AdminModulesPositionsControllerCore extends AdminController
$assoc_modules_id = array(); $assoc_modules_id = array();
foreach ($modules as $module) foreach ($modules as $module)
if ($tmpInstance = Module::getInstanceById((int)$module['id_module'])) if ($tmp_instance = Module::getInstanceById((int)$module['id_module']))
{ {
// We want to be able to sort modules by display name // We want to be able to sort modules by display name
$module_instances[$tmpInstance->displayName] = $tmpInstance; $module_instances[$tmp_instance->displayName] = $tmp_instance;
// But we also want to associate hooks to modules using the modules IDs // But we also want to associate hooks to modules using the modules IDs
$assoc_modules_id[(int)$module['id_module']] = $tmpInstance->displayName; $assoc_modules_id[(int)$module['id_module']] = $tmp_instance->displayName;
} }
ksort($module_instances); ksort($module_instances);
$hooks = Hook::getHooks(!(int)(Tools::getValue('hook_position'))); $hooks = Hook::getHooks(!(int)Tools::getValue('hook_position'));
foreach ($hooks as $key => $hook) foreach ($hooks as $key => $hook)
{ {
// Get all modules for this hook or only the filtered module // Get all modules for this hook or only the filtered module
$hooks[$key]['modules'] = Hook::getModulesFromHook($hook['id_hook'], $this->displayKey); $hooks[$key]['modules'] = Hook::getModulesFromHook($hook['id_hook'], $this->display_key);
$hooks[$key]['module_count'] = count($hooks[$key]['modules']); $hooks[$key]['module_count'] = count($hooks[$key]['modules']);
// If modules were found, link to the previously created Module instances // If modules were found, link to the previously created Module instances
if (is_array($hooks[$key]['modules']) && !empty($hooks[$key]['modules'])) if (is_array($hooks[$key]['modules']) && !empty($hooks[$key]['modules']))
@@ -263,7 +264,7 @@ class AdminModulesPositionsControllerCore extends AdminController
$this->addJqueryPlugin('tablednd'); $this->addJqueryPlugin('tablednd');
$this->toolbar_btn['save'] = array( $this->toolbar_btn['save'] = array(
'href' => self::$currentIndex.'&addToHook'.($this->displayKey ? '&show_modules='.$this->displayKey : '').'&token='.$this->token, 'href' => self::$currentIndex.'&addToHook'.($this->display_key ? '&show_modules='.$this->display_key : '').'&token='.$this->token,
'desc' => $this->l('Transplant a module') 'desc' => $this->l('Transplant a module')
); );
@@ -275,11 +276,13 @@ class AdminModulesPositionsControllerCore extends AdminController
'token' => $this->token, 'token' => $this->token,
'url_show_modules' => self::$currentIndex.'&token='.$this->token.'&show_modules=', 'url_show_modules' => self::$currentIndex.'&token='.$this->token.'&show_modules=',
'modules' => $module_instances, 'modules' => $module_instances,
'url_show_invisible' => self::$currentIndex.'&token='.$this->token.'&show_modules='.(int)(Tools::getValue('show_modules')).'&hook_position=', 'url_show_invisible' => self::$currentIndex.'&token='.$this->token.'&show_modules='.(int)Tools::getValue('show_modules').'&hook_position=',
'hook_position' => Tools::getValue('hook_position'), 'hook_position' => Tools::getValue('hook_position'),
'live_edit' => Shop::isFeatureActive() && $this->context->shop->getContextType() != Shop::CONTEXT_SHOP, 'live_edit' => Shop::isFeatureActive() && $this->context->shop->getContextType() != Shop::CONTEXT_SHOP,
'url_live_edit' => $this->context->link->getPageLink('index', false, null, 'live_edit&ad='.$admin_dir.'&liveToken='.sha1($admin_dir._COOKIE_KEY_).((Shop::isFeatureActive()) ? '&id_shop='.Context::getContext()->shop->getID() : '')), 'url_live_edit' => $this->context->link->getPageLink('index', false, null,
'display_key' => $this->displayKey, 'live_edit&ad='.$admin_dir.'&liveToken='.sha1($admin_dir._COOKIE_KEY_)
.(Shop::isFeatureActive()?'&id_shop='.Context::getContext()->shop->getID() : '')),
'display_key' => $this->display_key,
'hooks' => $hooks, 'hooks' => $hooks,
'url_submit' => self::$currentIndex.'&token='.$this->token, 'url_submit' => self::$currentIndex.'&token='.$this->token,
'can_move' => (Shop::isFeatureActive() && $this->context->shop->getContextType() != Shop::CONTEXT_SHOP) ? false : true, 'can_move' => (Shop::isFeatureActive() && $this->context->shop->getContextType() != Shop::CONTEXT_SHOP) ? false : true,
@@ -294,8 +297,8 @@ class AdminModulesPositionsControllerCore extends AdminController
$this->initToolbarTitle(); $this->initToolbarTitle();
// toolbar (save, cancel, new, ..) // toolbar (save, cancel, new, ..)
$this->initToolbar(); $this->initToolbar();
$id_module = (int)(Tools::getValue('id_module')); $id_module = (int)Tools::getValue('id_module');
$id_hook = (int)(Tools::getValue('id_hook')); $id_hook = (int)Tools::getValue('id_hook');
if (Tools::isSubmit('editGraft')) if (Tools::isSubmit('editGraft'))
{ {
// Check auth for this page // Check auth for this page
@@ -310,39 +313,39 @@ class AdminModulesPositionsControllerCore extends AdminController
if (!Db::getInstance()->getValue($sql)) if (!Db::getInstance()->getValue($sql))
Tools::redirectAdmin(self::$currentIndex.'&token='.$this->token); Tools::redirectAdmin(self::$currentIndex.'&token='.$this->token);
$slModule = Module::getInstanceById($id_module); $sl_module = Module::getInstanceById($id_module);
$exceptsList = $slModule->getExceptions($id_hook, true); $excepts_list = $sl_module->getExceptions($id_hook, true);
$exceptsDiff = false; $excepts_diff = false;
$excepts = ''; $excepts = '';
if ($exceptsList) if ($excepts_list)
{ {
$first = current($exceptsList); $first = current($excepts_list);
foreach ($exceptsList as $k => $v) foreach ($excepts_list as $k => $v)
if (array_diff($v, $first) || array_diff($first, $v)) if (array_diff($v, $first) || array_diff($first, $v))
$exceptsDiff = true; $excepts_diff = true;
if (!$exceptsDiff) if (!$excepts_diff)
$excepts = implode(', ', $first); $excepts = implode(', ', $first);
} }
} }
else else
{ {
$exceptsDiff = false; $excepts_diff = false;
$exceptsList = Tools::getValue('exceptions', array(array())); $excepts_list = Tools::getValue('exceptions', array(array()));
} }
$modules = Module::getModulesInstalled(0); $modules = Module::getModulesInstalled(0);
$instances = array(); $instances = array();
foreach ($modules as $module) foreach ($modules as $module)
if ($tmpInstance = Module::getInstanceById($module['id_module'])) if ($tmp_instance = Module::getInstanceById($module['id_module']))
$instances[$tmpInstance->displayName] = $tmpInstance; $instances[$tmp_instance->displayName] = $tmp_instance;
ksort($instances); ksort($instances);
$modules = $instances; $modules = $instances;
$hooks = Hook::getHooks(0); $hooks = Hook::getHooks(0);
$exception_list_diff = array(); $exception_list_diff = array();
foreach ($exceptsList as $shopID => $fileList) foreach ($excepts_list as $shop_id => $file_list)
$exception_list_diff[] = $this->displayModuleExceptionList($fileList, $shopID); $exception_list_diff[] = $this->displayModuleExceptionList($file_list, $shop_id);
$tpl = $this->createTemplate('form.tpl'); $tpl = $this->createTemplate('form.tpl');
$tpl->assign(array( $tpl->assign(array(
@@ -352,10 +355,10 @@ class AdminModulesPositionsControllerCore extends AdminController
'id_hook' => (int)Tools::getValue('id_hook'), 'id_hook' => (int)Tools::getValue('id_hook'),
'show_modules' => Tools::getValue('show_modules'), 'show_modules' => Tools::getValue('show_modules'),
'hooks' => $hooks, 'hooks' => $hooks,
'exception_list' => $this->displayModuleExceptionList(array_shift($exceptsList), 0), 'exception_list' => $this->displayModuleExceptionList(array_shift($excepts_list), 0),
'exception_list_diff' => $exception_list_diff, 'exception_list_diff' => $exception_list_diff,
'except_diff' => isset($exceptsDiff) ? $exceptsDiff : null, 'except_diff' => isset($excepts_diff) ? $excepts_diff : null,
'display_key' => $this->displayKey, 'display_key' => $this->display_key,
'modules' => $modules, 'modules' => $modules,
'show_toolbar' => true, 'show_toolbar' => true,
'toolbar_btn' => $this->toolbar_btn, 'toolbar_btn' => $this->toolbar_btn,
@@ -366,23 +369,26 @@ class AdminModulesPositionsControllerCore extends AdminController
return $tpl->fetch(); return $tpl->fetch();
} }
public function displayModuleExceptionList($fileList, $shopID) public function displayModuleExceptionList($file_list, $shop_id)
{ {
if (!is_array($fileList)) if (!is_array($file_list))
$fileList = ($fileList) ? array($fileList) : array(); $file_list = ($file_list) ? array($file_list) : array();
$content = '<input type="text" name="exceptions['.$shopID.']" size="40" value="'.implode(', ', $fileList).'" id="em_text_'.$shopID.'">'; $content = '<input type="text" name="exceptions['.$shop_id.']" size="40" value="'.implode(', ', $file_list).'" id="em_text_'.$shop_id.'">';
if ($shopID) if ($shop_id)
$content .= ' ('.Shop::getInstance($shopID)->name.')'; {
$content .= '<br /><select id="em_list_'.$shopID.'">'; $shop = new Shop($shop_id);
$content .= ' ('.$shop->name.')';
}
$content .= '<br /><select id="em_list_'.$shop_id.'">';
// @todo do something better with controllers // @todo do something better with controllers
$controllers = Dispatcher::getControllers(_PS_FRONT_CONTROLLER_DIR_); $controllers = Dispatcher::getControllers(_PS_FRONT_CONTROLLER_DIR_);
ksort($controllers); ksort($controllers);
foreach ($controllers as $k => $v) foreach ($controllers as $k => $v)
$content .= '<option value="'.$k.'">'.$k.'</option>'; $content .= '<option value="'.$k.'">'.$k.'</option>';
$content .= '</select> <input type="button" class="button" value="'.$this->l('Add').'" onclick="position_exception_add('.$shopID.')" /> $content .= '</select> <input type="button" class="button" value="'.$this->l('Add').'" onclick="position_exception_add('.$shop_id.')" />
<input type="button" class="button" value="'.$this->l('Remove').'" onclick="position_exception_remove('.$shopID.')" /><br /><br />'; <input type="button" class="button" value="'.$this->l('Remove').'" onclick="position_exception_remove('.$shop_id.')" /><br /><br />';
return $content; return $content;
} }