Fork me on GitHub
Subscribe 2

Ticket #114 (fixed bug)

Bug Categories

  • Created: 2010-09-04 08:33:21
  • Reported by: sephizack
  • Assigned to: Reines
  • Milestone: 1.4.3
  • Component: code
  • Priority: high

I just found and fixed a big bug: When using the same value for the position of the categories, your function mixes up the category IDs!

So now we find forums in wrong categories...

File: admin_categories.php
Fixed code lines:

else if (isset($_POST['update'])) // Change position and name of the categories
{
confirm_referrer('admin_categories.php');

$cat_order = $_POST['cat_order'];
$cat_name = $_POST['cat_name'];
$cat_id = $_POST['cat_id'];

$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);

for ($i = 0; $i < $num_cats; ++$i)
{

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

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

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

And you need to add a new colum with IDs here:

<tr><th scope="col">ID (ne pas modif)</th>
                        <th class="tcl" scope="col"><?php echo $lang_admin_categories['Category name label'] ?></th>
                        <th scope="col"><?php echo $lang_admin_categories['Category position label'] ?></th>

and here :

    <td><input type="text" name="cat_id[<?php echo $i ?>]" value="<?php echo $category[0] ?>" size="3" maxlength="3" /></td>
                                    <td class="tcl"><input type="text" name="cat_name[<?php echo $i ?>]" value="<?php echo pun_htmlspecialchars(utf8_encode($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>

History

Franz 2010-09-04 15:26:19

  • Description changed. (Diff)

Reines 2010-09-09 21:40:35

  • Milestone set to 1.4.3.

Reines 2010-09-18 11:50:58

  • Owner set to Reines.

Reines 2010-09-18 13:18:28

  • Status changed from open to fixed.

Thanks, this should now be fixed.

I didn't use your patch, as the original logic of selecting the old stuff as a count is just weird/wrong. Also the user shouldn't have the option of changing the ID otherwise weird things will happen.