Beispiel #1
0
function wpsc_category_options($group_id, $this_category = null, $category_id = null, $iteration = 0, $selected_id = null)
{
    global $wpdb;
    $selected_term = get_term($selected_id, 'wpsc_product_category');
    $values = get_terms('wpsc_product_category', 'hide_empty=0&parent=' . $group_id);
    $selected = "";
    $output = "";
    foreach ((array) $values as $option) {
        if ($option->term_id != $this_category) {
            if (isset($selected_term->parent) && $selected_term->parent == $option->term_id) {
                $selected = "selected='selected'";
            }
            $output .= "<option {$selected} value='" . $option->term_id . "'>" . str_repeat("-", $iteration) . esc_html($option->name) . "</option>\r\n";
            $output .= wpsc_category_options($option->term_id, $this_category, $option->term_id, $iteration + 1, $selected_id);
            $selected = "";
        }
    }
    return $output;
}
function wpsc_category_options($group_id, $this_category = null, $category_id = null, $iteration = 0, $selected_id = null)
{
    /*
     * Displays the category forms for adding and editing products
     * Recurses to generate the branched view for subcategories
     */
    global $wpdb;
    $siteurl = get_option('siteurl');
    if (is_numeric($category_id)) {
        $values = $wpdb->get_results("SELECT * FROM `" . WPSC_TABLE_PRODUCT_CATEGORIES . "` WHERE `group_id` = '{$group_id}' AND `active`='1' AND `id` != '{$this_category}' AND `category_parent` = '{$category_id}'  ORDER BY `id` ASC", ARRAY_A);
    } else {
        $values = $wpdb->get_results("SELECT * FROM `" . WPSC_TABLE_PRODUCT_CATEGORIES . "` WHERE `group_id` = '{$group_id}' AND `active`='1' AND `id` != '{$this_category}' AND `category_parent` = '0'  ORDER BY `id` ASC", ARRAY_A);
    }
    foreach ((array) $values as $option) {
        if ($selected_id == $option['id']) {
            $selected = "selected='selected'";
        }
        $output .= "<option {$selected} value='" . $option['id'] . "'>" . str_repeat("-", $iteration) . stripslashes($option['name']) . "</option>\r\n";
        $output .= wpsc_category_options($group_id, $this_category, $option['id'], $iteration + 1, $selected_id);
        $selected = "";
    }
    return $output;
}