[-] BO: Fix #PSCFV-5930 #PSCFV-5939 the filters are handled as the same between tabs which can cause sql errors

This commit is contained in:
Rémi Gaillard committed 2013-01-14 12:08:12 +01:00
1 parent 556955a7f0
commit ef904c9083
2 files changed
+18 -28

No files matched your search

+13 -24
View File
@@ -419,41 +419,28 @@ class AdminControllerCore extends Controller
*/ */
public function processFilter() public function processFilter()
{ {
$prefix = str_replace(array('admin', 'controller'), '', Tools::strtolower(get_class($this)));
// Filter memorization // Filter memorization
if (isset($_POST) && !empty($_POST) && isset($this->table)) if (isset($_POST) && !empty($_POST) && isset($this->table))
foreach ($_POST as $key => $value) foreach ($_POST as $key => $value)
{ {
if (is_array($this->table)) if (stripos($key, $this->table.'Filter_') === 0)
{ $this->context->cookie->{$prefix.$key} = !is_array($value) ? $value : serialize($value);
foreach ($this->table as $table) elseif(stripos($key, 'submitFilter') === 0)
if (stripos($key, $table.'Filter_') === 0 || stripos($key, 'submitFilter') === 0)
$this->context->cookie->$key = !is_array($value) ? $value : serialize($value);
}
elseif (stripos($key, $this->table.'Filter_') === 0 || stripos($key, 'submitFilter') === 0)
$this->context->cookie->$key = !is_array($value) ? $value : serialize($value); $this->context->cookie->$key = !is_array($value) ? $value : serialize($value);
} }
if (isset($_GET) && !empty($_GET) && isset($this->table)) if (isset($_GET) && !empty($_GET) && isset($this->table))
foreach ($_GET as $key => $value) foreach ($_GET as $key => $value)
{ if (stripos($key, $this->table.'OrderBy') === 0 || stripos($key, $this->table.'Orderway') === 0)
if (is_array($this->table))
{
foreach ($this->table as $table)
if (stripos($key, $table.'OrderBy') === 0 || stripos($key, $table.'Orderway') === 0)
$this->context->cookie->$key = $value;
}
elseif (stripos($key, $this->table.'OrderBy') === 0 || stripos($key, $this->table.'Orderway') === 0)
$this->context->cookie->$key = $value; $this->context->cookie->$key = $value;
} $filters = $this->context->cookie->getFamily($prefix.$this->table.'Filter_');
$filters = $this->context->cookie->getFamily($this->table.'Filter_');
foreach ($filters as $key => $value) foreach ($filters as $key => $value)
{ {
/* Extracting filters from $_POST on key filter_ */ /* Extracting filters from $_POST on key filter_ */
if ($value != null && !strncmp($key, $this->table.'Filter_', 7 + Tools::strlen($this->table))) if ($value != null && !strncmp($key, $prefix.$this->table.'Filter_', 7 + Tools::strlen($prefix.$this->table)))
{ {
$key = Tools::substr($key, 7 + Tools::strlen($this->table)); $key = Tools::substr($key, 7 + Tools::strlen($prefix.$this->table));
/* Table alias could be specified using a ! eg. alias!field */ /* Table alias could be specified using a ! eg. alias!field */
$tmp_tab = explode('!', $key); $tmp_tab = explode('!', $key);
$filter = count($tmp_tab) > 1 ? $tmp_tab[1] : $tmp_tab[0]; $filter = count($tmp_tab) > 1 ? $tmp_tab[1] : $tmp_tab[0];
@@ -835,11 +822,12 @@ class AdminControllerCore extends Controller
*/ */
public function processResetFilters() public function processResetFilters()
{ {
$filters = $this->context->cookie->getFamily($this->table.'Filter_'); $prefix = str_replace(array('admin', 'controller'), '', Tools::strtolower(get_class($this)));
$filters = $this->context->cookie->getFamily($prefix.$this->table.'Filter_');
foreach ($filters as $cookie_key => $filter) foreach ($filters as $cookie_key => $filter)
if (strncmp($cookie_key, $this->table.'Filter_', 7 + Tools::strlen($this->table)) == 0) if (strncmp($cookie_key, $prefix.$this->table.'Filter_', 7 + Tools::strlen($prefix.$this->table)) == 0)
{ {
$key = substr($cookie_key, 7 + Tools::strlen($this->table)); $key = substr($cookie_key, 7 + Tools::strlen($prefix.$this->table));
/* Table alias could be specified using a ! eg. alias!field */ /* Table alias could be specified using a ! eg. alias!field */
$tmp_tab = explode('!', $key); $tmp_tab = explode('!', $key);
$key = (count($tmp_tab) > 1 ? $tmp_tab[1] : $tmp_tab[0]); $key = (count($tmp_tab) > 1 ? $tmp_tab[1] : $tmp_tab[0]);
@@ -1592,6 +1580,7 @@ class AdminControllerCore extends Controller
$helper->multiple_fieldsets = $this->multiple_fieldsets; $helper->multiple_fieldsets = $this->multiple_fieldsets;
$helper->row_hover = $this->row_hover; $helper->row_hover = $this->row_hover;
$helper->position_identifier = $this->position_identifier; $helper->position_identifier = $this->position_identifier;
$helper->controller_name = $this->controller_name;
// For each action, try to add the corresponding skip elements list // For each action, try to add the corresponding skip elements list
$helper->list_skip_actions = $this->list_skip_actions; $helper->list_skip_actions = $this->list_skip_actions;
+5 -4
View File
@@ -530,11 +530,12 @@ class HelperListCore extends Helper
if ($this->position_identifier && ($this->orderBy == 'position' && $this->orderWay != 'DESC')) if ($this->position_identifier && ($this->orderBy == 'position' && $this->orderWay != 'DESC'))
$table_dnd = true; $table_dnd = true;
$prefix = str_replace(array('admin', 'controller'), '', Tools::strtolower($this->controller_name));
foreach ($this->fields_list as $key => $params) foreach ($this->fields_list as $key => $params)
{ {
if (!isset($params['type'])) if (!isset($params['type']))
$params['type'] = 'text'; $params['type'] = 'text';
$value = Context::getContext()->cookie->{$this->table.'Filter_'.(array_key_exists('filter_key', $params) ? $params['filter_key'] : $key)}; $value = Context::getContext()->cookie->{$prefix.$this->table.'Filter_'.(array_key_exists('filter_key', $params) ? $params['filter_key'] : $key)};
switch ($params['type']) switch ($params['type'])
{ {
case 'bool': case 'bool':
@@ -558,9 +559,9 @@ class HelperListCore extends Helper
case 'select': case 'select':
foreach ($params['list'] as $option_value => $option_display) foreach ($params['list'] as $option_value => $option_display)
{ {
if (isset(Context::getContext()->cookie->{$this->table.'Filter_'.$params['filter_key']}) if (isset(Context::getContext()->cookie->{$prefix.$this->table.'Filter_'.$params['filter_key']})
&& Context::getContext()->cookie->{$this->table.'Filter_'.$params['filter_key']} == $option_value && Context::getContext()->cookie->{$prefix.$this->table.'Filter_'.$params['filter_key']} == $option_value
&& Context::getContext()->cookie->{$this->table.'Filter_'.$params['filter_key']} != '') && Context::getContext()->cookie->{$prefix.$this->table.'Filter_'.$params['filter_key']} != '')
$this->fields_list[$key]['select'][$option_value]['selected'] = 'selected'; $this->fields_list[$key]['select'][$option_value]['selected'] = 'selected';
} }
break; break;