Don't store selected category order when you want to update category.
To resolve this problem in admin/categories.php
change this code:if ($action == "updatecat") {
$error = array();
$cat_id = (isset($HTTP_POST_VARS['cat_id'])) ? intval($HTTP_POST_VARS['cat_id']) : intval($HTTP_GET_VARS['cat_id']);
$cat_parent_id = intval($HTTP_POST_VARS['cat_parent_id']);
$cat_name = un_htmlspecialchars(trim($HTTP_POST_VARS['cat_name']));
$cat_description = un_htmlspecialchars(trim($HTTP_POST_VARS['cat_description']));
$cat_hits = intval(trim($HTTP_POST_VARS['cat_hits']));
$auth_viewcat = $HTTP_POST_VARS['auth_viewcat'];
$auth_viewimage = $HTTP_POST_VARS['auth_viewimage'];
$auth_download = $HTTP_POST_VARS['auth_download'];
$auth_upload = $HTTP_POST_VARS['auth_upload'];
$auth_directupload = $HTTP_POST_VARS['auth_directupload'];
$auth_vote = $HTTP_POST_VARS['auth_vote'];
$auth_sendpostcard = $HTTP_POST_VARS['auth_sendpostcard'];
$auth_readcomment = $HTTP_POST_VARS['auth_readcomment'];
$auth_postcomment = $HTTP_POST_VARS['auth_postcomment'];
$subcats = (isset($HTTP_POST_VARS['subcats']) && $HTTP_POST_VARS['subcats']) ? 1 : 0;
$subcat_ids = array();
get_subcategories_id($cat_id);
if ($cat_parent_id == $cat_id || in_array($cat_parent_id, $subcat_ids)) {
$msg .= sprintf("<span class=\"marktext\">%s</span><br />", $lang['parent_cat_error']);
$error['cat_parent_id'] = 1;
}
if ($cat_name == "") {
$error['cat_name'] = 1;
}
if (empty($error)) {
$sql = "UPDATE ".CATEGORIES_TABLE."
SET cat_name = '$cat_name', cat_description = '$cat_description', cat_parent_id = $cat_parent_id, cat_hits = $cat_hits, auth_viewcat = $auth_viewcat, auth_viewimage = $auth_viewimage, auth_download = $auth_download, auth_upload = $auth_upload, auth_directupload = $auth_directupload, auth_vote = $auth_vote, auth_sendpostcard = $auth_sendpostcard, auth_readcomment = $auth_readcomment, auth_postcomment = $auth_postcomment
WHERE cat_id = $cat_id";
$result = $site_db->query($sql);
if ($subcats) {
function get_subcategories_id($cat_id = 0)
{
global $subcat_ids, $cat_parent_cache;
if (!isset($cat_parent_cache[$cat_id]))
{
return false;
}
foreach ($cat_parent_cache[$cat_id] as $key => $val)
{
$subcat_ids[] = $val;
get_subcategories_id($val);
}
return $subcat_ids;
}
$subcat_ids = array();
$subcat_ids = get_subcategories_id($cat_id);
if (!empty($subcat_ids))
{
$sql = "UPDATE ".CATEGORIES_TABLE."
SET auth_viewcat = $auth_viewcat, auth_viewimage = $auth_viewimage, auth_download = $auth_download, auth_upload = $auth_upload, auth_directupload = $auth_directupload, auth_vote = $auth_vote, auth_sendpostcard = $auth_sendpostcard, auth_readcomment = $auth_readcomment, auth_postcomment = $auth_postcomment
WHERE cat_id IN (".implode($subcat_ids, ",").")";
$result = $site_db->query($sql);
}
}
$msg = ($result) ? $lang['cat_edit_success'] : $lang['cat_edit_error'];
$action = "modifycats";
}
else {
$msg .= sprintf("<span class=\"marktext\">%s</span>", $lang['lostfield_error']);
$action = "editcat";
}
}
to this:if ($action == "updatecat") {
$error = array();
$cat_id = (isset($HTTP_POST_VARS['cat_id'])) ? intval($HTTP_POST_VARS['cat_id']) : intval($HTTP_GET_VARS['cat_id']);
$cat_parent_id = intval($HTTP_POST_VARS['cat_parent_id']);
$cat_name = un_htmlspecialchars(trim($HTTP_POST_VARS['cat_name']));
$cat_description = un_htmlspecialchars(trim($HTTP_POST_VARS['cat_description']));
$cat_hits = intval(trim($HTTP_POST_VARS['cat_hits']));
$cat_order = (isset($HTTP_POST_VARS['cat_order'])) ? intval($HTTP_POST_VARS['cat_order']) : 0;
$auth_viewcat = $HTTP_POST_VARS['auth_viewcat'];
$auth_viewimage = $HTTP_POST_VARS['auth_viewimage'];
$auth_download = $HTTP_POST_VARS['auth_download'];
$auth_upload = $HTTP_POST_VARS['auth_upload'];
$auth_directupload = $HTTP_POST_VARS['auth_directupload'];
$auth_vote = $HTTP_POST_VARS['auth_vote'];
$auth_sendpostcard = $HTTP_POST_VARS['auth_sendpostcard'];
$auth_readcomment = $HTTP_POST_VARS['auth_readcomment'];
$auth_postcomment = $HTTP_POST_VARS['auth_postcomment'];
$subcats = (isset($HTTP_POST_VARS['subcats']) && $HTTP_POST_VARS['subcats']) ? 1 : 0;
$subcat_ids = array();
get_subcategories_id($cat_id);
if ($cat_parent_id == $cat_id || in_array($cat_parent_id, $subcat_ids)) {
$msg .= sprintf("<span class=\"marktext\">%s</span><br />", $lang['parent_cat_error']);
$error['cat_parent_id'] = 1;
}
if ($cat_name == "") {
$error['cat_name'] = 1;
}
if (empty($error)) {
if (!$cat_order) {
$sql = "SELECT cat_order
FROM ".CATEGORIES_TABLE."
WHERE cat_parent_id = $cat_parent_id
ORDER BY cat_order DESC
LIMIT 1";
$catorder = $site_db->query_firstrow($sql);
$cat_order = $catorder['cat_order'] + 10;
$do_updat_cat_order = 0;
}
else {
$do_updat_cat_order = 1;
}
$sql = "UPDATE ".CATEGORIES_TABLE."
SET cat_name = '$cat_name', cat_order = '$cat_order', cat_description = '$cat_description', cat_parent_id = $cat_parent_id, cat_hits = $cat_hits, auth_viewcat = $auth_viewcat, auth_viewimage = $auth_viewimage, auth_download = $auth_download, auth_upload = $auth_upload, auth_directupload = $auth_directupload, auth_vote = $auth_vote, auth_sendpostcard = $auth_sendpostcard, auth_readcomment = $auth_readcomment, auth_postcomment = $auth_postcomment
WHERE cat_id = $cat_id";
$result = $site_db->query($sql);
if ($do_updat_cat_order) {
update_cat_order($cat_parent_id);
}
if ($subcats) {
function get_subcategories_id($cat_id = 0)
{
global $subcat_ids, $cat_parent_cache;
if (!isset($cat_parent_cache[$cat_id]))
{
return false;
}
foreach ($cat_parent_cache[$cat_id] as $key => $val)
{
$subcat_ids[] = $val;
get_subcategories_id($val);
}
return $subcat_ids;
}
$subcat_ids = array();
$subcat_ids = get_subcategories_id($cat_id);
if (!empty($subcat_ids))
{
$sql = "UPDATE ".CATEGORIES_TABLE."
SET auth_viewcat = $auth_viewcat, auth_viewimage = $auth_viewimage, auth_download = $auth_download, auth_upload = $auth_upload, auth_directupload = $auth_directupload, auth_vote = $auth_vote, auth_sendpostcard = $auth_sendpostcard, auth_readcomment = $auth_readcomment, auth_postcomment = $auth_postcomment
WHERE cat_id IN (".implode($subcat_ids, ",").")";
$result = $site_db->query($sql);
}
}
$msg = ($result) ? $lang['cat_edit_success'] : $lang['cat_edit_error'];
$action = "modifycats";
}
else {
$msg .= sprintf("<span class=\"marktext\">%s</span>", $lang['lostfield_error']);
$action = "editcat";
}
}