Fix for r8752

(the code removed actually was quite important - this checkin merges this with the new code)

git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@8970 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
Meik Sievertsen 2008-10-06 05:44:32 +00:00
parent 059acbcd1d
commit 9f0b6766f9

View file

@ -49,47 +49,57 @@ function gen_sort_selects(&$limit_days, &$sort_by_text, &$sort_days, &$sort_key,
$sorts = array( $sorts = array(
'st' => array( 'st' => array(
'selected' => $sort_days, 'key' => 'sort_days',
'default' => $def_st, 'default' => $def_st,
'options' => $limit_days, 'options' => $limit_days,
'output' => &$s_limit_days,), 'output' => &$s_limit_days,
),
'sk' => array( 'sk' => array(
'selected' => $sort_key, 'key' => 'sort_key',
'default' => $def_sk, 'default' => $def_sk,
'options' => $sort_by_text, 'options' => $sort_by_text,
'output' => &$s_sort_key,), 'output' => &$s_sort_key,
),
'sd' => array( 'sd' => array(
'selected' => $sort_dir, 'key' => 'sort_dir',
'default' => $def_sd, 'default' => $def_sd,
'options' => $sort_dir_text, 'options' => $sort_dir_text,
'output' => &$s_sort_dir,), 'output' => &$s_sort_dir,
),
); );
$u_sort_param = ''; $u_sort_param = '';
foreach ($sorts as $name => $sort_ary) foreach ($sorts as $name => $sort_ary)
{ {
$key = $sort_ary['key'];
$selected = $$sort_ary['key'];
// Check if the key is selectable. If not, we reset to the default or first key found. // Check if the key is selectable. If not, we reset to the default or first key found.
// This ensures the values are always valid. // This ensures the values are always valid. We also set $sort_dir/sort_key/etc. to the
if (!isset($sort_ary['options'][$sort_ary['selected']])) // correct value, else the protection is void. ;)
if (!isset($sort_ary['options'][$selected]))
{ {
if ($sort_ary['default'] !== false) if ($sort_ary['default'] !== false)
{ {
$sort_ary['selected'] = $sort_ary['default']; $selected = $$key = $sort_ary['default'];
} }
else else
{ {
@reset($sort_ary['options']); @reset($sort_ary['options']);
$sort_ary['selected'] = key($sort_ary['options']); $selected = $$key = key($sort_ary['options']);
} }
} }
$sort_ary['output'] = '<select name="' . $name . '" id="' . $name . '">'; $sort_ary['output'] = '<select name="' . $name . '" id="' . $name . '">';
foreach ($sort_ary['options'] as $option => $text) foreach ($sort_ary['options'] as $option => $text)
{ {
$selected = ($sort_ary['selected']== $option) ? ' selected="selected"' : ''; $sort_ary['output'] .= '<option value="' . $option . '"' . (($selected == $option) ? ' selected="selected"' : '') . '>' . $text . '</option>';
$sort_ary['output'] .= '<option value="' . $option . '"' . $selected . '>' . $text . '</option>';
} }
$sort_ary['output'] .= '</select>'; $sort_ary['output'] .= '</select>';
$u_sort_param .= ($sort_ary['selected'] !== $sort_ary['default']) ? ((strlen($u_sort_param)) ? '&amp;' : '') . "{$name}={$sort_ary['selected']}" : '';
$u_sort_param .= ($selected !== $sort_ary['default']) ? ((strlen($u_sort_param)) ? '&amp;' : '') . "{$name}={$selected}" : '';
} }
return; return;