// Fix admin modules positions

git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@8098 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
rMalie
2011-08-17 15:30:44 +00:00
parent acfa8d8600
commit 89bc665d48
3 changed files with 42 additions and 25 deletions
+30 -20
View File
@@ -65,12 +65,7 @@ class AdminModulesPositions extends AdminTab
$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);
$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)) if (!$id_module OR !Validate::isLoadedObject($module))
$this->_errors[] = Tools::displayError('module cannot be loaded'); $this->_errors[] = Tools::displayError('module cannot be loaded');
elseif (!$id_hook OR !Validate::isLoadedObject($hook)) elseif (!$id_hook OR !Validate::isLoadedObject($hook))
@@ -84,9 +79,21 @@ class AdminModulesPositions extends AdminTab
{ {
if (!$module->registerHook($hook->name, Context::getContext()->shop->getListOfID())) if (!$module->registerHook($hook->name, 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.');
elseif (!$module->registerExceptions($id_hook, $excepts, Context::getContext()->shop->getListOfID()))
$this->_errors[] = Tools::displayError('An error occurred while transplanting module to hook.');
else 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); 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) foreach ($exception AS $except)
if (!Validate::isFileName($except)) if (!Validate::isFileName($except))
$this->_errors[] = Tools::displayError('No valid value for field exceptions'); $this->_errors[] = Tools::displayError('No valid value for field exceptions');
// Add files exceptions $exceptions[$id] = $exception;
if (!$module->editExceptions($id_hook, $exception, Context::getContext()->shop->getListOfID()))
$this->_errors[] = Tools::displayError('An error occurred while transplanting module to hook.');
} }
// Add files exceptions
if (!$module->editExceptions($id_hook, $exceptions))
$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->displayKey ? '&show_modules='.$this->displayKey : '').'&token='.$this->token);
@@ -358,7 +367,7 @@ class AdminModulesPositions extends AdminTab
{ {
$first = current($exceptsList); $first = current($exceptsList);
foreach ($exceptsList as $k => $v) foreach ($exceptsList as $k => $v)
if (array_diff($v, $first)) if (array_diff($v, $first) || array_diff($first, $v))
$exceptsDiff = true; $exceptsDiff = true;
if (!$exceptsDiff) if (!$exceptsDiff)
@@ -368,7 +377,7 @@ class AdminModulesPositions extends AdminTab
else else
{ {
$exceptsDiff = false; $exceptsDiff = false;
$excepts = strval(Tools::getValue('exceptions')); $exceptsList = Tools::getValue('exceptions', array(array()));
} }
$modules = Module::getModulesInstalled(0); $modules = Module::getModulesInstalled(0);
@@ -423,9 +432,12 @@ class AdminModulesPositions extends AdminTab
if (r.test(inputValue)) if (r.test(inputValue))
{ {
var rep = ''; var rep = '';
if (new RegExp(listValue+' *,').test(inputValue)) if (new RegExp(', *'+listValue+' *,').test(inputValue))
rep = ','; $('#em_text_'+shopID).val(inputValue.replace(r, ','));
$('#em_text_'+shopID).val(inputValue.replace(r, rep)); 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 '<label>'.$this->l('Exceptions').' :</label> echo '<label>'.$this->l('Exceptions').' :</label>
<div class="margin-form">'; <div class="margin-form">';
$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').'.<br /> echo $this->l('Please specify those files for which you do not want the module to be displayed').'.<br />
'.$this->l('Please type each filename separated by a comma').'. '.$this->l('Please type each filename separated by a comma').'.
@@ -449,9 +461,7 @@ EOF;
echo '<label>'.$this->l('Exceptions').' :</label> echo '<label>'.$this->l('Exceptions').' :</label>
<div class="margin-form">'; <div class="margin-form">';
foreach ($exceptsList as $shopID => $fileList) foreach ($exceptsList as $shopID => $fileList)
{
$this->displayModuleExceptionList($fileList, $shopID); $this->displayModuleExceptionList($fileList, $shopID);
}
echo $this->l('Please specify those files for which you do not want the module to be displayed').'.<br /> echo $this->l('Please specify those files for which you do not want the module to be displayed').'.<br />
'.$this->l('Please type each filename separated by a comma').'. '.$this->l('Please type each filename separated by a comma').'.
<br /><br /> <br /><br />
+11 -4
View File
@@ -438,7 +438,7 @@ abstract class ModuleCore
public function registerExceptions($id_hook, $excepts, $shopList = null) public function registerExceptions($id_hook, $excepts, $shopList = null)
{ {
if (is_null($shopList)) if (is_null($shopList))
$shopList = Shop::getShops(true, null, true); Context::getContext()->shop->getListOfID();
foreach ($shopList as $shopID) foreach ($shopList as $shopID)
{ {
@@ -460,10 +460,17 @@ abstract class ModuleCore
return true; return true;
} }
public function editExceptions($hookID, $excepts, $shopList = null) public function editExceptions($hookID, $excepts)
{ {
$this->unregisterExceptions($hookID, $shopList); $result = true;
return $this->registerExceptions($hookID, $excepts, $shopList); 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;
} }
+1 -1
View File
@@ -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) * 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 * @return array
*/ */
public function getListOfID($share = false) public function getListOfID($share = false)