Make sure we can only move modules to allowed columns

Moving a module to a column type (side & center columns) where
this module already exists will cause massive issues
This commit is contained in:
Marc Alexander
2012-04-08 17:03:44 +02:00
parent a7bb3b3226
commit 86eb3e7526
3 changed files with 150 additions and 157 deletions

View File

@@ -379,6 +379,18 @@ class acp_portal
case 'modules': case 'modules':
$action = request_var('action', ''); $action = request_var('action', '');
$module_id = request_var('module_id', ''); $module_id = request_var('module_id', '');
// Create an array of already installed modules
$portal_modules = obtain_portal_modules();
$installed_modules = $module_column = array();
foreach($portal_modules as $cur_module)
{
$installed_modules[] = $cur_module['module_classname'];
// Create an array with the columns the module is in
$module_column[$cur_module['module_classname']][] = column_num_string($cur_module['module_column']);
}
if ($action == 'move_up') if ($action == 'move_up')
{ {
$sql = 'SELECT module_order, module_column $sql = 'SELECT module_order, module_column
@@ -405,8 +417,13 @@ class acp_portal
$db->sql_query($sql); $db->sql_query($sql);
} }
} }
else
{
trigger_error($user->lang['UNABLE_TO_MOVE_ROW'] . adm_back_link($this->u_action));
}
$cache->destroy('portal_modules'); $cache->destroy('portal_modules');
redirect($this->u_action); // redirect in order to get rid of excessive URL parameters
} }
elseif ($action == 'move_down') elseif ($action == 'move_down')
{ {
@@ -433,8 +450,13 @@ class acp_portal
$db->sql_query($sql); $db->sql_query($sql);
} }
} }
else
{
trigger_error($user->lang['UNABLE_TO_MOVE_ROW'] . adm_back_link($this->u_action));
}
$cache->destroy('portal_modules'); $cache->destroy('portal_modules');
redirect($this->u_action); // redirect in order to get rid of excessive URL parameters
} }
elseif($action == 'move_right') elseif($action == 'move_right')
{ {
@@ -456,83 +478,77 @@ class acp_portal
} }
$c_class = new $class(); $c_class = new $class();
if($c_class->columns & column_string_const(column_num_string($module_data['module_column'] + 1))) if ($module_data !== false)
{ {
if ($module_data !== false) if($c_class->columns & column_string_const(column_num_string($module_data['module_column'] + 1)))
{ {
$sql = 'UPDATE ' . PORTAL_MODULES_TABLE . ' $move_action = 1; // we move 1 column to the right
SET module_order = module_order + 1 }
WHERE module_order >= ' . (int) $module_data['module_order'] . ' elseif($c_class->columns & column_string_const(column_num_string($module_data['module_column'] + 2)) && $module_data['module_column'] != 2)
AND module_column = ' . (int) ($module_data['module_column'] + 1); {
$db->sql_query($sql); $move_action = 2; // we move 2 columns to the right
$updated = $db->sql_affectedrows(); }
$sql = 'UPDATE ' . PORTAL_MODULES_TABLE . ' /**
SET module_column = module_column + 1 * moving only 1 column to the right means we will either end up in the right column
WHERE module_id = ' . (int) $module_id; * or in the center column. this is not possible when moving 2 columns to the right.
$db->sql_query($sql); * therefore we only need to check if we won't end up with a duplicate module in the
* new column (side columns (left & right) or center columns (top, center, bottom)).
$sql = 'UPDATE ' . PORTAL_MODULES_TABLE . ' * of course this does not apply to custom modules.
SET module_order = module_order - 1 */
WHERE module_order >= ' . (int) $module_data['module_order'] . ' if ($module_data['module_classname'] != 'custom' && $move_action == 1)
AND module_column = ' . (int) $module_data['module_column']; {
$db->sql_query($sql); $column_string = column_num_string($module_data['module_column'] + $move_action);
// we can only move right to the right & center column
// the module that needs to moved is in the last row if ($column_string == 'right' &&
if(!$updated) isset($module_column[$module_data['module_classname']]) &&
in_array('right', $module_column[$module_data['module_classname']]))
{ {
$sql = 'SELECT MAX(module_order) as new_order trigger_error($user->lang['UNABLE_TO_MOVE'] . adm_back_link($this->u_action));
FROM ' . PORTAL_MODULES_TABLE . ' }
WHERE module_order < ' . (int) $module_data['module_order'] . ' elseif ($column_string == 'center' &&
AND module_column = ' . (int) ($module_data['module_column'] + 1); isset($module_column[$module_data['module_classname']]) &&
$db->sql_query($sql); (in_array('center', $module_column[$module_data['module_classname']]) ||
$new_order = $db->sql_fetchfield('new_order') + 1; in_array('top', $module_column[$module_data['module_classname']]) ||
in_array('bottom', $module_column[$module_data['module_classname']])))
$sql = 'UPDATE ' . PORTAL_MODULES_TABLE . ' {
SET module_order = ' . (int) $new_order . ' // we are moving from the left to the center column so we should move to the right column instead
WHERE module_id = ' . (int) $module_id; $move_action = 2;
$db->sql_query($sql);
} }
} }
}
elseif($c_class->columns & column_string_const(column_num_string($module_data['module_column'] + 2)) && $module_data['module_column'] != 2) $sql = 'UPDATE ' . PORTAL_MODULES_TABLE . '
{ SET module_order = module_order + 1
if ($module_data !== false) WHERE module_order >= ' . (int) $module_data['module_order'] . '
{ AND module_column = ' . (int) ($module_data['module_column'] + $move_action);
$sql = 'UPDATE ' . PORTAL_MODULES_TABLE . ' $db->sql_query($sql);
SET module_order = module_order + 1 $updated = $db->sql_affectedrows();
WHERE module_order >= ' . (int) $module_data['module_order'] . '
AND module_column = ' . (int) ($module_data['module_column'] + 2);
$db->sql_query($sql);
$updated = $db->sql_affectedrows();
$sql = 'UPDATE ' . PORTAL_MODULES_TABLE . '
SET module_column = module_column + ' . $move_action . '
WHERE module_id = ' . (int) $module_id;
$db->sql_query($sql);
$sql = 'UPDATE ' . PORTAL_MODULES_TABLE . '
SET module_order = module_order - 1
WHERE module_order >= ' . (int) $module_data['module_order'] . '
AND module_column = ' . (int) $module_data['module_column'];
$db->sql_query($sql);
// the module that needs to moved is in the last row
if(!$updated)
{
$sql = 'SELECT MAX(module_order) as new_order
FROM ' . PORTAL_MODULES_TABLE . '
WHERE module_order < ' . (int) $module_data['module_order'] . '
AND module_column = ' . (int) ($module_data['module_column'] + $move_action);
$db->sql_query($sql);
$new_order = $db->sql_fetchfield('new_order') + 1;
$sql = 'UPDATE ' . PORTAL_MODULES_TABLE . ' $sql = 'UPDATE ' . PORTAL_MODULES_TABLE . '
SET module_column = module_column + 2 SET module_order = ' . (int) $new_order . '
WHERE module_id = ' . (int) $module_id; WHERE module_id = ' . (int) $module_id;
$db->sql_query($sql); $db->sql_query($sql);
$sql = 'UPDATE ' . PORTAL_MODULES_TABLE . '
SET module_order = module_order - 1
WHERE module_order >= ' . (int) $module_data['module_order'] . '
AND module_column = ' . (int) $module_data['module_column'];
$db->sql_query($sql);
// the module that needs to moved is in the last row
if(!$updated)
{
$sql = 'SELECT MAX(module_order) as new_order
FROM ' . PORTAL_MODULES_TABLE . '
WHERE module_order < ' . (int) $module_data['module_order'] . '
AND module_column = ' . (int) ($module_data['module_column'] + 2);
$db->sql_query($sql);
$new_order = $db->sql_fetchfield('new_order') + 1;
$sql = 'UPDATE ' . PORTAL_MODULES_TABLE . '
SET module_order = ' . (int) $new_order . '
WHERE module_id = ' . (int) $module_id;
$db->sql_query($sql);
}
} }
} }
else else
@@ -541,6 +557,7 @@ class acp_portal
} }
$cache->destroy('portal_modules'); $cache->destroy('portal_modules');
redirect($this->u_action); // redirect in order to get rid of excessive URL parameters
} }
elseif($action == 'move_left') elseif($action == 'move_left')
{ {
@@ -562,82 +579,77 @@ class acp_portal
} }
$c_class = new $class(); $c_class = new $class();
if($c_class->columns & column_string_const(column_num_string($module_data['module_column'] - 1))) if ($module_data !== false)
{ {
if ($module_data !== false) if($c_class->columns & column_string_const(column_num_string($module_data['module_column'] - 1)))
{ {
$sql = 'UPDATE ' . PORTAL_MODULES_TABLE . ' $move_action = 1; // we move 1 column to the left
SET module_order = module_order + 1 }
WHERE module_order >= ' . $module_data['module_order'] . ' elseif($c_class->columns & column_string_const(column_num_string($module_data['module_column'] - 2)) && $module_data['module_column'] != 2)
AND module_column = ' . ($module_data['module_column'] - 1); {
$db->sql_query($sql); $move_action = 2; // we move 2 columns to the left
$updated = $db->sql_affectedrows(); }
$sql = 'UPDATE ' . PORTAL_MODULES_TABLE . ' /**
SET module_column = module_column - 1 * moving only 1 column to the left means we will either end up in the left column
WHERE module_id = ' . (int) $module_id; * or in the center column. this is not possible when moving 2 columns to the left.
$db->sql_query($sql); * therefore we only need to check if we won't end up with a duplicate module in the
* new column (side columns (left & right) or center columns (top, center, bottom)).
$sql = 'UPDATE ' . PORTAL_MODULES_TABLE . ' * of course this does not apply to custom modules.
SET module_order = module_order - 1 */
WHERE module_order >= ' . $module_data['module_order'] . ' if ($module_data['module_classname'] != 'custom' && $move_action == 1)
AND module_column = ' . $module_data['module_column']; {
$db->sql_query($sql); $column_string = column_num_string($module_data['module_column'] - $move_action);
// we can only move left to the left & center column
// the module that needs to moved is in the last row if ($column_string == 'left' &&
if(!$updated) isset($module_column[$module_data['module_classname']]) &&
in_array('left', $module_column[$module_data['module_classname']]))
{ {
$sql = 'SELECT MAX(module_order) as new_order trigger_error($user->lang['UNABLE_TO_MOVE'] . adm_back_link($this->u_action));
FROM ' . PORTAL_MODULES_TABLE . ' }
WHERE module_order < ' . $module_data['module_order'] . ' elseif ($column_string == 'center' &&
AND module_column = ' . (int) ($module_data['module_column'] - 1); isset($module_column[$module_data['module_classname']]) &&
$db->sql_query($sql); (in_array('center', $module_column[$module_data['module_classname']]) ||
$new_order = $db->sql_fetchfield('new_order') + 1; in_array('top', $module_column[$module_data['module_classname']]) ||
in_array('bottom', $module_column[$module_data['module_classname']])))
$sql = 'UPDATE ' . PORTAL_MODULES_TABLE . ' {
SET module_order = ' . $new_order . ' // we are moving from the right to the center column so we should move to the left column instead
WHERE module_id = ' . (int) $module_id; $move_action = 2;
$db->sql_query($sql);
} }
} }
}
elseif($c_class->columns & column_string_const(column_num_string($module_data['module_column'] - 2)) && $module_data['module_column'] != 2)
{
if ($module_data !== false)
{
$sql = 'UPDATE ' . PORTAL_MODULES_TABLE . '
SET module_order = module_order + 1
WHERE module_order >= ' . $module_data['module_order'] . '
AND module_column = ' . ($module_data['module_column'] - 2);
$db->sql_query($sql);
$updated = $db->sql_affectedrows();
$sql = 'UPDATE ' . PORTAL_MODULES_TABLE . '
SET module_order = module_order + 1
WHERE module_order >= ' . $module_data['module_order'] . '
AND module_column = ' . ($module_data['module_column'] - $move_action);
$db->sql_query($sql);
$updated = $db->sql_affectedrows();
$sql = 'UPDATE ' . PORTAL_MODULES_TABLE . '
SET module_column = module_column - ' . $move_action . '
WHERE module_id = ' . (int) $module_id;
$db->sql_query($sql);
$sql = 'UPDATE ' . PORTAL_MODULES_TABLE . '
SET module_order = module_order - 1
WHERE module_order >= ' . $module_data['module_order'] . '
AND module_column = ' . $module_data['module_column'];
$db->sql_query($sql);
// the module that needs to moved is in the last row
if(!$updated)
{
$sql = 'SELECT MAX(module_order) as new_order
FROM ' . PORTAL_MODULES_TABLE . '
WHERE module_order < ' . $module_data['module_order'] . '
AND module_column = ' . (int) ($module_data['module_column'] - $move_action);
$db->sql_query($sql);
$new_order = $db->sql_fetchfield('new_order') + 1;
$sql = 'UPDATE ' . PORTAL_MODULES_TABLE . ' $sql = 'UPDATE ' . PORTAL_MODULES_TABLE . '
SET module_column = module_column - 2 SET module_order = ' . $new_order . '
WHERE module_id = ' . (int) $module_id; WHERE module_id = ' . (int) $module_id;
$db->sql_query($sql); $db->sql_query($sql);
$sql = 'UPDATE ' . PORTAL_MODULES_TABLE . '
SET module_order = module_order - 1
WHERE module_order >= ' . $module_data['module_order'] . '
AND module_column = ' . $module_data['module_column'];
$db->sql_query($sql);
// the module that needs to moved is in the last row
if(!$updated)
{
$sql = 'SELECT MAX(module_order) as new_order
FROM ' . PORTAL_MODULES_TABLE . '
WHERE module_order < ' . $module_data['module_order'] . '
AND module_column = ' . (int) ($module_data['module_column'] - 2);
$db->sql_query($sql);
$new_order = $db->sql_fetchfield('new_order') + 1;
$sql = 'UPDATE ' . PORTAL_MODULES_TABLE . '
SET module_order = ' . $new_order . '
WHERE module_id = ' . (int) $module_id;
$db->sql_query($sql);
}
} }
} }
else else
@@ -646,6 +658,7 @@ class acp_portal
} }
$cache->destroy('portal_modules'); $cache->destroy('portal_modules');
redirect($this->u_action); // redirect in order to get rid of excessive URL parameters
} }
elseif ($action == 'delete') elseif ($action == 'delete')
{ {
@@ -716,17 +729,6 @@ class acp_portal
{ {
$submit = (isset($_POST['submit'])) ? true : false; $submit = (isset($_POST['submit'])) ? true : false;
$directory = $phpbb_root_path . 'portal/modules/'; $directory = $phpbb_root_path . 'portal/modules/';
// Create an array of already installed modules
$portal_modules = obtain_portal_modules();
$installed_modules = $module_column = array();
foreach($portal_modules as $cur_module)
{
$installed_modules[] = $cur_module['module_classname'];
// Create an array with the columns the module is in
$module_column[$cur_module['module_classname']][] = column_num_string($cur_module['module_column']);
}
if ($submit) if ($submit)
{ {
@@ -845,17 +847,6 @@ class acp_portal
$module_class = str_replace(array('portal_', ".$phpEx"), '', $file); $module_class = str_replace(array('portal_', ".$phpEx"), '', $file);
$column_string = column_num_string($add_column); $column_string = column_num_string($add_column);
// Create an array of already installed modules
$portal_modules = obtain_portal_modules();
$installed_modules = $module_column = array();
foreach($portal_modules as $cur_module)
{
$installed_modules[] = $cur_module['module_classname'];
// Create an array with the columns the module is in
$module_column[$cur_module['module_classname']][] = column_num_string($cur_module['module_column']);
}
// do we want to add the module to the side columns or to the center columns? // do we want to add the module to the side columns or to the center columns?
if ($module_class != 'custom') if ($module_class != 'custom')
{ {

View File

@@ -53,6 +53,7 @@ $lang = array_merge($lang, array(
'MOVE_LEFT' => 'Nach links', 'MOVE_LEFT' => 'Nach links',
'B3P_FILE_NOT_FOUND' => 'Die angegebene Datei konnte nicht gefunden werden', 'B3P_FILE_NOT_FOUND' => 'Die angegebene Datei konnte nicht gefunden werden',
'UNABLE_TO_MOVE' => 'Es ist nicht möglich den Block in die gewählte Spalte zu verschieben.', 'UNABLE_TO_MOVE' => 'Es ist nicht möglich den Block in die gewählte Spalte zu verschieben.',
'UNABLE_TO_MOVE_ROW' => 'Es ist nicht möglich den Block in die gewählte Reihe zu verschieben.',
'DELETE_MODULE_CONFIRM' => 'Bist du sicher, dass du das Modul "%1$s" löschen möchtest?', 'DELETE_MODULE_CONFIRM' => 'Bist du sicher, dass du das Modul "%1$s" löschen möchtest?',
'MODULE_RESET_SUCCESS' => 'Modul Einstellungen erfolgreich zurückgesetzt.', 'MODULE_RESET_SUCCESS' => 'Modul Einstellungen erfolgreich zurückgesetzt.',
'MODULE_RESET_CONFIRM' => 'Bist du sicher, dass du die Einstellungen des Moduls "%1$s" zurücksetzen willst?', 'MODULE_RESET_CONFIRM' => 'Bist du sicher, dass du die Einstellungen des Moduls "%1$s" zurücksetzen willst?',

View File

@@ -52,6 +52,7 @@ $lang = array_merge($lang, array(
'MOVE_LEFT' => 'Move left', 'MOVE_LEFT' => 'Move left',
'B3P_FILE_NOT_FOUND' => 'The requested file could not be found', 'B3P_FILE_NOT_FOUND' => 'The requested file could not be found',
'UNABLE_TO_MOVE' => 'It is not possible to move the block to the selected column.', 'UNABLE_TO_MOVE' => 'It is not possible to move the block to the selected column.',
'UNABLE_TO_MOVE_ROW' => 'It is not possible to move the block to the selected row.',
'DELETE_MODULE_CONFIRM' => 'Are you sure you wish to delete the module "%1$s"?', 'DELETE_MODULE_CONFIRM' => 'Are you sure you wish to delete the module "%1$s"?',
'MODULE_RESET_SUCCESS' => 'Successfully reset the module settings.', 'MODULE_RESET_SUCCESS' => 'Successfully reset the module settings.',
'MODULE_RESET_CONFIRM' => 'Are you sure you wish to reset the settings of the module "%1$s"?', 'MODULE_RESET_CONFIRM' => 'Are you sure you wish to reset the settings of the module "%1$s"?',