array_push($cat_ids, $cat);
    if ($fields['category_location']) {
        while ($id = cw_group_edit_each($ge_id, 1, $cat)) {
            array_push($cat_ids, $id);
        }
    }
    if (!in_array($cat_location, $cat_ids)) {
        foreach ($cat_ids as $id) {
            // Get all affected categories - parent and children
            $parent_id = cw_query_first_cell("select parent_id from {$tables['categories']} where category_id='{$id}'");
            $subcats = cw_category_get_subcategory_ids($id);
            db_query("update {$tables['categories']} set parent_id='{$cat_location}' where category_id='{$id}'");
            cw_category_update_path($id);
            if (count($subcats)) {
                foreach ($subcats as $scat_id) {
                    cw_category_update_path($scat_id);
                }
            }
            $path = array($parent_id, $cat_location);
            cw_recalc_subcat_count($path);
        }
        $top_message = array('content' => cw_get_langvar_by_name('msg_adm_category_move'), 'type' => 'I');
        cw_header_location("index.php?target={$target}&mode=edit&cat={$cat}&ge_id={$ge_id}");
    }
}
if ($action == "delete_icon" && !empty($cat)) {
    cw_image_delete($cat, 'categories_images_thumb');
    if ($ge_id && $fields['image']) {
        while ($id = cw_group_edit_each($ge_id, 100, $cat)) {
            cw_image_delete($id, 'categories_images_thumb');
        }
function cw_category_update_path($cat, $rec = false)
{
    global $tables;
    $path = array();
    $level = 0;
    cw_category_generate_path($cat, $path);
    $path[] = $cat;
    db_query("delete from {$tables['categories_parents']} where category_id='{$cat}'");
    foreach ($path as $val) {
        cw_array2insert('categories_parents', array('category_id' => $cat, 'parent_id' => $val, 'level' => $level++));
    }
    if ($rec) {
        $subcats = cw_category_get_subcategory_ids($cat);
        if (count($subcats)) {
            foreach ($subcats as $scat_id) {
                cw_category_update_path($scat_id);
            }
        }
    }
}