function cw_group_edit_update_category($ge_id, $cat, $fields, $data)
{
    if (!$ge_id || !$cat || !count($fields)) {
        return;
    }
    global $tables, $config, $edited_language;
    $query_fields = cw_query_column("desc {$tables['categories']}", 'Field');
    $to_update = array_intersect($query_fields, array_keys($fields));
    # kornev, add attributes to update
    if ($edited_language != $config['default_admin_language']) {
        cw_unset($to_update, 'category', 'description');
    }
    if ($to_update) {
        cw_group_edit_copy($ge_id, 'categories', 'category_id', $cat, $to_update);
    }
    if ($fields['membership_ids']) {
        while ($id = cw_group_edit_each($ge_id, 1, $cat)) {
            cw_membership_update('categories', $id, $data['membership_ids'], 'category_id');
        }
    }
    if ($fields['avail']) {
        while ($id = cw_group_edit_each($ge_id, 1, $cat)) {
            cw_category_update_status($id, $data['avail']);
        }
    }
    if ($fields['category'] || $fields['description']) {
        $to_update = array_intersect(array('category', 'description'), array_keys($fields));
        cw_group_edit_copy($ge_id, 'categories_lng', 'category_id', $cat, $to_update, "code='{$edited_language}'");
    }
    if ($fields['image']) {
        cw_group_edit_copy($ge_id, 'categories_images_thumb', 'id', $cat);
    }
    cw_attributes_group_update($ge_id, $cat, 'C', $fields);
}
         $file_upload_data['categories_images_thumb']['is_redirect'] = false;
         $saved_category['image'] = $file_upload_data['categories_images_thumb'];
     }
     cw_header_location("index.php?target={$target}&mode={$mode}&cat={$cat}&ge_id={$ge_id}");
 }
 if ($mode == 'add') {
     $cat = cw_array2insert('categories', array('parent_id' => $cat));
     cw_category_update_path($cat);
 }
 $update_fields = array('category', 'description', 'featured', 'order_by', 'short_list');
 array_push($update_fields, 'meta_descr', 'meta_keywords');
 if ($edited_language != $config['default_admin_language']) {
     cw_unset($update_fields, 'category', 'description');
 }
 cw_array2update('categories', $category_update, "category_id='{$cat}'", $update_fields);
 cw_category_update_status($cat, $category_update['status']);
 cw_category_update_path($cat);
 cw_membership_update('categories', $cat, $category_update['membership_ids'], 'category_id');
 $category_lng = array();
 $category_lng['code'] = $edited_language;
 $category_lng['category_id'] = $cat;
 $category_lng['category'] = $category_update['category'];
 $category_lng['description'] = $category_update['description'];
 cw_array2insert('categories_lng', $category_lng, true, array('code', 'category_id', 'category', 'description'));
 if (cw_image_check_posted($file_upload_data['categories_images_thumb'])) {
     cw_image_save($file_upload_data['categories_images_thumb']);
 }
 $parent_categories = cw_category_get_path($cat);
 if (is_array($parent_categories)) {
     cw_recalc_subcat_count($parent_categories);
 }
}
if ($action == 'list') {
    if (empty($delete_arr)) {
        $top_message = array('content' => cw_get_langvar_by_name('lbl_please_select_categories_for_editing'), 'type' => 'I');
        cw_header_location('index.php?target=' . $target);
    }
    $cat_ids = array_keys($delete_arr);
    $ge_id = cw_group_edit_add($cat_ids);
    $cat_id = $cat_ids[0];
    cw_header_location('index.php?target=' . $target . '&mode=edit&cat=' . $cat_id . '&ge_id=' . $ge_id);
}
if ($action == 'apply' && is_array($posted_data)) {
    foreach ($posted_data as $k => $v) {
        $query_data = array('order_by' => intval($v['order_by']));
        cw_array2update('categories', $query_data, "category_id='" . $k . "'");
        cw_category_update_status($k, $v['status']);
    }
    if ($cat) {
        $path = cw_category_get_subcategory_ids($cat);
        if (!empty($path)) {
            cw_recalc_subcat_count($path);
        }
    } else {
        cw_recalc_subcat_count();
    }
    $top_message = array('content' => cw_get_langvar_by_name('msg_adm_categories_upd'), 'type' => 'I');
    cw_header_location("index.php?target={$target}" . ($mode ? '&mode=' . $mode : '') . "&cat={$cat}&js_tab={$js_tab}");
}
if ($action == 'delete') {
    if ($confirmed == "Y") {
        # kronev, for the big amount of products - the