if ($categories_type == 4) {
     // Tree-type structure
     $sql = " SELECT category_path ";
     $sql .= " FROM " . $table_prefix . "categories ";
     $sql .= " WHERE category_id=" . $db->tosql($category_id, INTEGER);
     $db->query($sql);
     if ($db->next_record()) {
         $active_category_path = $db->f("category_path");
         $active_category_path .= $category_id;
     }
     $categories_ids = VA_Categories::find_all_ids("c.parent_category_id IN (" . $db->tosql($active_category_path, INTEGERS_LIST) . ")", VIEW_CATEGORIES_PERM);
     $allowed_categories_ids = VA_Categories::find_all_ids("c.parent_category_id IN (" . $db->tosql($active_category_path, INTEGERS_LIST) . ")", VIEW_CATEGORIES_ITEMS_PERM);
 } else {
     $not = true;
     $categories_ids = VA_Categories::find_all_ids(array('not' => 1), VIEW_CATEGORIES_PERM);
     $allowed_categories_ids = VA_Categories::find_all_ids(array('not' => 1), VIEW_CATEGORIES_ITEMS_PERM);
 }
 if (!$not && !$categories_ids) {
     return;
 }
 $categories = array();
 $sql = " SELECT category_id, category_name, a_title, friendly_url, ";
 $sql .= " short_description, image, image_alt, image_large, image_large_alt, parent_category_id ";
 $sql .= " FROM " . $table_prefix . "categories ";
 if ($not) {
     if ($categories_ids) {
         $sql .= " WHERE category_id NOT IN (" . $db->tosql($categories_ids, INTEGERS_LIST) . ") ";
     }
     $sql .= " ORDER BY parent_category_id, category_order, category_name ";
     $db->RecordsPerPage = 1000;
 } else {