Skip to content

Commit

Permalink
Fixing category ordering when 2 categories have the same position, sp…
Browse files Browse the repository at this point in the history
…otted by sephizack.
  • Loading branch information
reines committed Sep 18, 2010
1 parent 88611a5 commit 7b8ee54
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions admin_categories.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,23 +126,22 @@
{
confirm_referrer('admin_categories.php');

$cat_order = array_map('trim', $_POST['cat_order']);
$cat_name = array_map('pun_trim', $_POST['cat_name']);

$result = $db->query('SELECT id, disp_position FROM '.$db->prefix.'categories ORDER BY disp_position') or error('Unable to fetch category list', __FILE__, __LINE__, $db->error());
$num_cats = $db->num_rows($result);
$categories = $_POST['cat'];
if (empty($categories))
message($lang_common['Bad request']);

for ($i = 0; $i < $num_cats; ++$i)
foreach ($categories as $cat_id => $cur_cat)
{
if ($cat_name[$i] == '')
$cur_cat['name'] = pun_trim($cur_cat['name']);
$cur_cat['order'] = trim($cur_cat['order']);

if ($cur_cat['name'] == '')
message($lang_admin_categories['Must enter name message']);

if ($cat_order[$i] == '' || preg_match('/[^0-9]/', $cat_order[$i]))
if ($cur_cat['order'] == '' || preg_match('/[^0-9]/', $cur_cat['order']))
message($lang_admin_categories['Must enter integer message']);

list($cat_id, $position) = $db->fetch_row($result);

$db->query('UPDATE '.$db->prefix.'categories SET cat_name=\''.$db->escape($cat_name[$i]).'\', disp_position='.$cat_order[$i].' WHERE id='.$cat_id) or error('Unable to update category', __FILE__, __LINE__, $db->error());
$db->query('UPDATE '.$db->prefix.'categories SET cat_name=\''.$db->escape($cur_cat['name']).'\', disp_position='.$cur_cat['order'].' WHERE id='.intval($cat_id)) or error('Unable to update category', __FILE__, __LINE__, $db->error());
}

// Regenerate the quick jump cache
Expand All @@ -159,7 +158,7 @@
$num_cats = $db->num_rows($result);

for ($i = 0; $i < $num_cats; ++$i)
$cat_list[] = $db->fetch_row($result);
$cat_list[] = $db->fetch_assoc($result);

$page_title = array(pun_htmlspecialchars($pun_config['o_board_title']), $lang_admin_common['Admin'], $lang_admin_common['Categories']);
define('PUN_ACTIVE_PAGE', 'admin');
Expand Down Expand Up @@ -205,8 +204,8 @@
<select name="cat_to_delete" tabindex="3">
<?php

foreach ($cat_list as $category)
echo "\t\t\t\t\t\t\t\t\t\t\t".'<option value="'.$category[0].'">'.pun_htmlspecialchars($category[1]).'</option>'."\n";
foreach ($cat_list as $cur_cat)
echo "\t\t\t\t\t\t\t\t\t\t\t".'<option value="'.$cur_cat['id'].'">'.pun_htmlspecialchars($cur_cat['cat_name']).'</option>'."\n";

?>
</select>
Expand Down Expand Up @@ -238,13 +237,13 @@
<tbody>
<?php

foreach ($cat_list as $i => $category)
foreach ($cat_list as $cur_cat)
{

?>
<tr>
<td class="tcl"><input type="text" name="cat_name[<?php echo $i ?>]" value="<?php echo pun_htmlspecialchars($category[1]) ?>" size="35" maxlength="80" /></td>
<td><input type="text" name="cat_order[<?php echo $i ?>]" value="<?php echo $category[2] ?>" size="3" maxlength="3" /></td>
<td class="tcl"><input type="text" name="cat[<?php echo $cur_cat['id'] ?>][name]" value="<?php echo pun_htmlspecialchars($cur_cat['cat_name']) ?>" size="35" maxlength="80" /></td>
<td><input type="text" name="cat[<?php echo $cur_cat['id'] ?>][order]" value="<?php echo $cur_cat['disp_position'] ?>" size="3" maxlength="3" /></td>
</tr>
<?php

Expand Down

0 comments on commit 7b8ee54

Please sign in to comment.