diff --git a/admin-dev/tabs/AdminModulesPositions.php b/admin-dev/tabs/AdminModulesPositions.php index c14a7a9ac..92b896463 100644 --- a/admin-dev/tabs/AdminModulesPositions.php +++ b/admin-dev/tabs/AdminModulesPositions.php @@ -65,12 +65,7 @@ class AdminModulesPositions extends AdminTab $module = Module::getInstanceById($id_module); $id_hook = (int)(Tools::getValue('id_hook')); $hook = new Hook($id_hook); - $excepts = explode(',', str_replace(' ', '', Tools::getValue('exceptions'))); - - // Checking vars... - foreach ($excepts AS $except) - if (!Validate::isFileName($except)) - $this->_errors[] = Tools::displayError('No valid value for field exceptions'); + if (!$id_module OR !Validate::isLoadedObject($module)) $this->_errors[] = Tools::displayError('module cannot be loaded'); elseif (!$id_hook OR !Validate::isLoadedObject($hook)) @@ -84,9 +79,21 @@ class AdminModulesPositions extends AdminTab { if (!$module->registerHook($hook->name, Context::getContext()->shop->getListOfID())) $this->_errors[] = Tools::displayError('An error occurred while transplanting module to hook.'); - elseif (!$module->registerExceptions($id_hook, $excepts, Context::getContext()->shop->getListOfID())) - $this->_errors[] = Tools::displayError('An error occurred while transplanting module to hook.'); else + { + $exceptions = Tools::getValue('exceptions'); + $exceptions = (isset($exceptions[0])) ? $exceptions[0] : array(); + $exceptions = explode(',', str_replace(' ', '', $exceptions)); + + foreach ($exceptions AS $except) + if (!Validate::isFileName($except)) + $this->_errors[] = Tools::displayError('No valid value for field exceptions'); + + if (!$this->_errors && !$module->registerExceptions($id_hook, $exceptions, Context::getContext()->shop->getListOfID())) + $this->_errors[] = Tools::displayError('An error occurred while transplanting module to hook.'); + } + + if (!$this->_errors) Tools::redirectAdmin(self::$currentIndex.'&conf=16'.($this->displayKey ? '&show_modules='.$this->displayKey : '').'&token='.$this->token); } } @@ -122,11 +129,13 @@ class AdminModulesPositions extends AdminTab foreach ($exception AS $except) if (!Validate::isFileName($except)) $this->_errors[] = Tools::displayError('No valid value for field exceptions'); - - // Add files exceptions - if (!$module->editExceptions($id_hook, $exception, Context::getContext()->shop->getListOfID())) - $this->_errors[] = Tools::displayError('An error occurred while transplanting module to hook.'); + + $exceptions[$id] = $exception; } + + // Add files exceptions + if (!$module->editExceptions($id_hook, $exceptions)) + $this->_errors[] = Tools::displayError('An error occurred while transplanting module to hook.'); if (!$this->_errors) Tools::redirectAdmin(self::$currentIndex.'&conf=16'.($this->displayKey ? '&show_modules='.$this->displayKey : '').'&token='.$this->token); @@ -358,7 +367,7 @@ class AdminModulesPositions extends AdminTab { $first = current($exceptsList); foreach ($exceptsList as $k => $v) - if (array_diff($v, $first)) + if (array_diff($v, $first) || array_diff($first, $v)) $exceptsDiff = true; if (!$exceptsDiff) @@ -368,7 +377,7 @@ class AdminModulesPositions extends AdminTab else { $exceptsDiff = false; - $excepts = strval(Tools::getValue('exceptions')); + $exceptsList = Tools::getValue('exceptions', array(array())); } $modules = Module::getModulesInstalled(0); @@ -423,9 +432,12 @@ class AdminModulesPositions extends AdminTab if (r.test(inputValue)) { var rep = ''; - if (new RegExp(listValue+' *,').test(inputValue)) - rep = ','; - $('#em_text_'+shopID).val(inputValue.replace(r, rep)); + if (new RegExp(', *'+listValue+' *,').test(inputValue)) + $('#em_text_'+shopID).val(inputValue.replace(r, ',')); + else if (new RegExp(listValue+' *,').test(inputValue)) + $('#em_text_'+shopID).val(inputValue.replace(r, '')); + else + $('#em_text_'+shopID).val(inputValue.replace(r, '')); } } //]]> @@ -437,7 +449,7 @@ EOF; { echo '
'; - $this->displayModuleExceptionList($excepts, 0); + $this->displayModuleExceptionList(array_shift($exceptsList), 0); echo $this->l('Please specify those files for which you do not want the module to be displayed').'.
'.$this->l('Please type each filename separated by a comma').'. @@ -449,9 +461,7 @@ EOF; echo '
'; foreach ($exceptsList as $shopID => $fileList) - { $this->displayModuleExceptionList($fileList, $shopID); - } echo $this->l('Please specify those files for which you do not want the module to be displayed').'.
'.$this->l('Please type each filename separated by a comma').'.

diff --git a/classes/Module.php b/classes/Module.php index 8821a09d5..a771f7de9 100644 --- a/classes/Module.php +++ b/classes/Module.php @@ -438,7 +438,7 @@ abstract class ModuleCore public function registerExceptions($id_hook, $excepts, $shopList = null) { if (is_null($shopList)) - $shopList = Shop::getShops(true, null, true); + Context::getContext()->shop->getListOfID(); foreach ($shopList as $shopID) { @@ -460,10 +460,17 @@ abstract class ModuleCore return true; } - public function editExceptions($hookID, $excepts, $shopList = null) + public function editExceptions($hookID, $excepts) { - $this->unregisterExceptions($hookID, $shopList); - return $this->registerExceptions($hookID, $excepts, $shopList); + $result = true; + foreach ($excepts as $shopID => $except) + { + $shopList = ($shopID == 0) ? Context::getContext()->shop->getListOfID() : array($shopID); + $this->unregisterExceptions($hookID, $shopList); + $result &= $this->registerExceptions($hookID, $except, $shopList); + } + + return $result; } diff --git a/classes/Shop.php b/classes/Shop.php index c12d3b6e6..4f2b58491 100644 --- a/classes/Shop.php +++ b/classes/Shop.php @@ -509,7 +509,7 @@ class ShopCore extends ObjectModel /** * Get a list of ID concerned by the shop context (E.g. if context is shop group, get list of children shop ID) * - * @param int $share If false, dont check share datas from group. Else can take a Shop::SHARE_* constant value + * @param string $share If false, dont check share datas from group. Else can take a Shop::SHARE_* constant value * @return array */ public function getListOfID($share = false)