1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-06-01 20:19:13 +02:00

[ticket/12038] Do not rely on stale order value to move items.

This makes it possible to move the items more than once with AJAX.

PHPBB3-12038
This commit is contained in:
Cesar G 2013-12-06 12:50:16 -08:00
parent 823d2b697a
commit 3ccc8add10
3 changed files with 53 additions and 48 deletions

View File

@ -47,6 +47,11 @@ class acp_permission_roles
$form_name = 'acp_permissions';
add_form_key($form_name);
if (!$role_id && in_array($action, array('remove', 'edit', 'move_up', 'move_down')))
{
trigger_error($user->lang['NO_ROLE_SELECTED'] . adm_back_link($this->u_action), E_USER_WARNING);
}
switch ($mode)
{
case 'admin_roles':
@ -86,11 +91,6 @@ class acp_permission_roles
{
case 'remove':
if (!$role_id)
{
trigger_error($user->lang['NO_ROLE_SELECTED'] . adm_back_link($this->u_action), E_USER_WARNING);
}
$sql = 'SELECT *
FROM ' . ACL_ROLES_TABLE . '
WHERE role_id = ' . $role_id;
@ -124,10 +124,6 @@ class acp_permission_roles
break;
case 'edit':
if (!$role_id)
{
trigger_error($user->lang['NO_ROLE_SELECTED'] . adm_back_link($this->u_action), E_USER_WARNING);
}
// Get role we edit
$sql = 'SELECT *
@ -274,12 +270,7 @@ class acp_permission_roles
case 'edit':
if ($action == 'edit')
{
if (!$role_id)
{
trigger_error($user->lang['NO_ROLE_SELECTED'] . adm_back_link($this->u_action), E_USER_WARNING);
}
{
$sql = 'SELECT *
FROM ' . ACL_ROLES_TABLE . '
WHERE role_id = ' . $role_id;
@ -367,7 +358,17 @@ class acp_permission_roles
case 'move_up':
case 'move_down':
$order = request_var('order', 0);
$sql = 'SELECT role_order
FROM ' . ACL_ROLES_TABLE . "
WHERE role_id = $role_id";
$result = $db->sql_query($sql);
$order = $db->sql_fetchfield('role_order');
if ($order === false || ($order == 0 && $action == 'move_up'))
{
break;
}
$order = (int) $order;
$order_total = $order * 2 + (($action == 'move_up') ? -1 : 1);
$sql = 'UPDATE ' . ACL_ROLES_TABLE . '
@ -430,8 +431,8 @@ class acp_permission_roles
'U_EDIT' => $this->u_action . '&action=edit&role_id=' . $row['role_id'],
'U_REMOVE' => $this->u_action . '&action=remove&role_id=' . $row['role_id'],
'U_MOVE_UP' => $this->u_action . '&action=move_up&order=' . $row['role_order'],
'U_MOVE_DOWN' => $this->u_action . '&action=move_down&order=' . $row['role_order'],
'U_MOVE_UP' => $this->u_action . '&action=move_up&role_id=' . $row['role_id'],
'U_MOVE_DOWN' => $this->u_action . '&action=move_down&role_id=' . $row['role_id'],
'U_DISPLAY_ITEMS' => ($row['role_id'] == $display_item) ? '' : $this->u_action . '&display_item=' . $row['role_id'] . '#assigned_to')
);

View File

@ -39,11 +39,17 @@ class acp_profile
$this->tpl_name = 'acp_profile';
$this->page_title = 'ACP_CUSTOM_PROFILE_FIELDS';
$field_id = $request->variable('field_id', 0);
$action = (isset($_POST['create'])) ? 'create' : request_var('action', '');
$error = array();
$s_hidden_fields = '';
if (!$field_id && in_array($action, array('delete','activate', 'deactivate', 'move_up', 'move_down', 'edit')))
{
trigger_error($user->lang['NO_FIELD_ID'] . adm_back_link($this->u_action), E_USER_WARNING);
}
// Define some default values for each field type
$default_values = array(
FIELD_STRING => array('field_length' => 10, 'field_minlen' => 0, 'field_maxlen' => 20, 'field_validation' => '.*', 'field_novalue' => '', 'field_default_value' => ''),
@ -98,12 +104,6 @@ class acp_profile
switch ($action)
{
case 'delete':
$field_id = request_var('field_id', 0);
if (!$field_id)
{
trigger_error($user->lang['NO_FIELD_ID'] . adm_back_link($this->u_action), E_USER_WARNING);
}
if (confirm_box(true))
{
@ -210,12 +210,6 @@ class acp_profile
break;
case 'activate':
$field_id = request_var('field_id', 0);
if (!$field_id)
{
trigger_error($user->lang['NO_FIELD_ID'] . adm_back_link($this->u_action), E_USER_WARNING);
}
$sql = 'SELECT lang_id
FROM ' . LANG_TABLE . "
@ -256,12 +250,6 @@ class acp_profile
break;
case 'deactivate':
$field_id = request_var('field_id', 0);
if (!$field_id)
{
trigger_error($user->lang['NO_FIELD_ID'] . adm_back_link($this->u_action), E_USER_WARNING);
}
$sql = 'UPDATE ' . PROFILE_FIELDS_TABLE . "
SET field_active = 0
@ -291,7 +279,19 @@ class acp_profile
case 'move_up':
case 'move_down':
$field_order = request_var('order', 0);
$sql = 'SELECT field_order
FROM ' . PROFILE_FIELDS_TABLE . "
WHERE field_id = $field_id";
$result = $db->sql_query($sql);
$field_order = $db->sql_fetchfield('field_order');
$db->sql_freeresult($result);
if ($field_order === false || ($field_order == 0 && $action == 'move_up'))
{
break;
}
$field_order = (int) $field_order;
$order_total = $field_order * 2 + (($action == 'move_up') ? -1 : 1);
$sql = 'UPDATE ' . PROFILE_FIELDS_TABLE . "
@ -312,7 +312,6 @@ class acp_profile
case 'create':
case 'edit':
$field_id = request_var('field_id', 0);
$step = request_var('step', 1);
$submit = (isset($_REQUEST['next']) || isset($_REQUEST['prev'])) ? true : false;
@ -324,11 +323,6 @@ class acp_profile
// We are editing... we need to grab basic things
if ($action == 'edit')
{
if (!$field_id)
{
trigger_error($user->lang['NO_FIELD_ID'] . adm_back_link($this->u_action), E_USER_WARNING);
}
$sql = 'SELECT l.*, f.*
FROM ' . PROFILE_LANG_TABLE . ' l, ' . PROFILE_FIELDS_TABLE . ' f
WHERE l.lang_id = ' . $this->edit_lang_id . "
@ -927,8 +921,8 @@ class acp_profile
'U_EDIT' => $this->u_action . "&action=edit&field_id=$id",
'U_TRANSLATE' => $this->u_action . "&action=edit&field_id=$id&step=3",
'U_DELETE' => $this->u_action . "&action=delete&field_id=$id",
'U_MOVE_UP' => $this->u_action . "&action=move_up&order={$row['field_order']}",
'U_MOVE_DOWN' => $this->u_action . "&action=move_down&order={$row['field_order']}",
'U_MOVE_UP' => $this->u_action . "&action=move_up&field_id=$id",
'U_MOVE_DOWN' => $this->u_action . "&action=move_down&field_id=$id",
'S_NEED_EDIT' => $s_need_edit)
);

View File

@ -281,7 +281,17 @@ class acp_reasons
case 'move_up':
case 'move_down':
$order = request_var('order', 0);
$sql = 'SELECT reason_order
FROM ' . REPORTS_REASONS_TABLE . "
WHERE reason_id = $reason_id";
$result = $db->sql_query($sql);
$order = $db->sql_fetchfield('reason_order');
if ($order === false || ($order == 0 && $action == 'move_up'))
{
break;
}
$order = (int) $order;
$order_total = $order * 2 + (($action == 'move_up') ? -1 : 1);
$sql = 'UPDATE ' . REPORTS_REASONS_TABLE . '
@ -371,8 +381,8 @@ class acp_reasons
'U_EDIT' => $this->u_action . '&action=edit&id=' . $row['reason_id'],
'U_DELETE' => (!$other_reason) ? $this->u_action . '&action=delete&id=' . $row['reason_id'] : '',
'U_MOVE_UP' => $this->u_action . '&action=move_up&order=' . $row['reason_order'],
'U_MOVE_DOWN' => $this->u_action . '&action=move_down&order=' . $row['reason_order'])
'U_MOVE_UP' => $this->u_action . '&action=move_up&id=' . $row['reason_id'],
'U_MOVE_DOWN' => $this->u_action . '&action=move_down&id=' . $row['reason_id'])
);
}
$db->sql_freeresult($result);