/**
 Function and action for duplicating products,
*/
function wpsc_duplicate_product()
{
    global $wpdb;
    $product_id = absint($_GET['product']);
    check_admin_referer('duplicate_product_' . $product_id);
    if ($product_id > 0) {
        $sql = " INSERT INTO " . WPSC_TABLE_PRODUCT_LIST . "( `name` , `description` , `additional_description` , `price` , `weight` , `weight_unit` , `pnp` , `international_pnp` , `file` , `image`  , `quantity_limited` , `quantity` , `special` , `special_price` , `display_frontpage` , `notax` , `active` , `publish`, `donation` , `no_shipping` , `thumbnail_image` , `thumbnail_state` ) SELECT `name` , `description` , `additional_description` , `price` , `weight` , `weight_unit` , `pnp` , `international_pnp` , `file` , `image`  , `quantity_limited` , `quantity` , `special` , `special_price` , `display_frontpage` , `notax` , `active`  , `publish`, `donation` , `no_shipping` , `thumbnail_image` , `thumbnail_state` FROM " . WPSC_TABLE_PRODUCT_LIST . " WHERE id = '" . $product_id . "' ";
        //	exit($sql);
        $wpdb->query($sql);
        $new_id = $wpdb->get_var("SELECT LAST_INSERT_ID() AS `id` FROM `" . WPSC_TABLE_PRODUCT_LIST . "` LIMIT 1");
        //Inserting duplicated variations record.
        $nzshpcrt_variations = new nzshpcrt_variations();
        $nzshpcrt_variations->duplicate_variation_values($new_id, $product_id);
        /*
        		$variation_assocs = $wpdb->get_results("SELECT * FROM ".WPSC_TABLE_VARIATION_ASSOC." WHERE associated_id = ".$product_id, ARRAY_A);
        		if(count($variation_assocs))foreach($variation_assocs as $variation_assoc){
        			$wpdb->query("INSERT INTO ".WPSC_TABLE_VARIATION_ASSOC." VALUES ('', '".$variation_assoc['type']."', '".$variation_assoc['name']."', '".$new_id."', '".$variation_assoc['variation_id']."');");
        		}
        		
        		$variation_combinations = $wpdb->get_results("SELECT * FROM ".WPSC_TABLE_VARIATION_COMBINATIONS." WHERE product_id = ".$product_id, ARRAY_A);
        		if(count($variation_combinations))foreach($variation_combinations as $variation_combination){
        			$variation_properties = $wpdb->get_results("SELECT * FROM ".WPSC_TABLE_VARIATION_PROPERTIES." WHERE id = ".$variation_combination['priceandstock_id'], ARRAY_A);
        			exit('<pre>'.print_r($variation_properties, true).'</pre>');
        			$wpdb->query("INSERT INTO ".WPSC_TABLE_VARIATION_PROPERTIES." VALUES ('', '".$new_id."', '".$variation_properties[0]['stock']."', '".$variation_properties[0]['price']."', '".$variation_properties[0]['weight']."', '".$variation_properties[0]['weight_unit']."', '".$variation_properties[0]['visibility']."', '".$variation_properties[0]['file']."');");
        			$new_prop_id= $wpdb->get_var("SELECT LAST_INSERT_ID() AS `id` FROM `".WPSC_TABLE_VARIATION_PROPERTIES."` LIMIT 1");
        			$wpdb->query("INSERT INTO ".WPSC_TABLE_VARIATION_COMBINATIONS." VALUES ('".$new_id."', '".$new_prop_id."', '".$variation_combination['value_id']."', '".$variation_combination['variation_id']."', '".$variation_combination['all_variation_ids']."');");			
        		}
        		
        		$variation_values_assocs = $wpdb->get_results("SELECT * FROM ".WPSC_TABLE_VARIATION_VALUES_ASSOC." WHERE product_id = ".$product_id, ARRAY_A);
        		if(count($variation_values_assocs))foreach($variation_values_assocs as $variation_values_assoc){
        			$wpdb->query("INSERT INTO ".WPSC_TABLE_VARIATION_VALUES_ASSOC." VALUES ('', '".$new_id."', '".$variation_values_assoc['value_id']."', '".$variation_values_assoc['visible']."', '".$variation_values_assoc['variation_id']."');");
        		}
        		//end of variations
        */
        //Inserting duplicated category record.
        $category_assoc = $wpdb->get_col("SELECT `category_id` FROM " . WPSC_TABLE_ITEM_CATEGORY_ASSOC . " WHERE product_id = '" . $product_id . "'");
        $new_product_category = array();
        if (count($category_assoc) > 0) {
            foreach ($category_assoc as $key => $category) {
                $new_product_category[] = "('" . $new_id . "','" . $category . "')";
                $check_existing = $wpdb->get_results("SELECT * FROM `" . WPSC_TABLE_PRODUCT_ORDER . "` WHERE `category_id` IN('{$category}') AND `order` IN('0') LIMIT 1;", ARRAY_A);
                if ($wpdb->get_var("SELECT `id` FROM `" . WPSC_TABLE_PRODUCT_ORDER . "` WHERE `category_id` IN('{$category}') AND `product_id` IN('{$product_id}') LIMIT 1")) {
                    $wpdb->query("UPDATE `" . WPSC_TABLE_PRODUCT_ORDER . "` SET `order` = '0' WHERE `category_id` IN('{$category}') AND `product_id` IN('{$product_id}') LIMIT 1;");
                } else {
                    $wpdb->query("INSERT INTO `" . WPSC_TABLE_PRODUCT_ORDER . "` (`category_id`, `product_id`, `order`) VALUES ('{$category}', '{$product_id}', 0)");
                }
                if ($check_existing != null) {
                    $wpdb->query("UPDATE `" . WPSC_TABLE_PRODUCT_ORDER . "` SET `order` = (`order` + 1) WHERE `category_id` IN('{$category}') AND `product_id` NOT IN('{$product_id}') AND `order` < '0'");
                }
            }
            $wpdb->query("INSERT INTO " . WPSC_TABLE_ITEM_CATEGORY_ASSOC . " (product_id, category_id) VALUES " . implode(",", $new_product_category));
        }
        //Inserting duplicated meta info
        $meta_values = $wpdb->get_results("SELECT `meta_key`, `meta_value`, `custom` FROM `" . WPSC_TABLE_PRODUCTMETA . "` WHERE product_id='" . $product_id . "' AND  `meta_key` NOT IN ('url_name') ", ARRAY_A);
        $new_meta_value = array();
        if (count($meta_values) > 0) {
            foreach ($meta_values as $key => $meta) {
                $new_meta_value[] = "('" . $new_id . "','" . $meta['meta_key'] . "','" . $meta['meta_value'] . "','" . $meta['custom'] . "')";
            }
            $wpdb->query("INSERT INTO `" . WPSC_TABLE_PRODUCTMETA . "` (`product_id`, `meta_key`, `meta_value`, `custom`) VALUES " . implode(",", $new_meta_value));
        }
        $product_name = $wpdb->get_var("SELECT `name` FROM `" . WPSC_TABLE_PRODUCT_LIST . "` WHERE `id` = '{$new_id}' LIMIT 1");
        if ($product_name != '') {
            $tidied_name = strtolower(trim($product_name));
            $url_name = sanitize_title($tidied_name);
            $similar_names = $wpdb->get_row("SELECT COUNT(*) AS `count`, MAX(REPLACE(`meta_value`, '{$url_name}', '')) AS `max_number` FROM `" . WPSC_TABLE_PRODUCTMETA . "` WHERE `meta_key` IN ('url_name') AND `meta_value` REGEXP '^({$url_name}){1}[[:digit:]]*\$' ", ARRAY_A);
            $extension_number = '';
            if ($similar_names['count'] > 0) {
                $extension_number = (int) $similar_names['max_number'] + 1;
            }
            $url_name .= $extension_number;
            add_product_meta($new_id, 'url_name', $url_name, true);
        }
        $tags = wp_get_object_terms($product_id, 'product_tag', array('fields' => 'names'));
        wp_set_object_terms($new_id, $tags, 'product_tag');
        //Inserting duplicated image info
        $image_values = $wpdb->get_results("SELECT `image`, `width`, `height`, `image_order`, `meta` FROM " . WPSC_TABLE_PRODUCT_IMAGES . " WHERE product_id='" . $product_id . "'", ARRAY_A);
        $new_image_value = array();
        if (count($image_values) > 0) {
            foreach ($image_values as $key => $image) {
                if ($image['image'] != '') {
                    if (is_numeric($image['width']) && is_numeric($image['height'])) {
                        $image['width'] = absint($image['width']);
                        $image['height'] = absint($image['height']);
                    } else {
                        $image['width'] = 'null';
                        $image['height'] = 'null';
                    }
                    $new_image_value[] = "('" . $new_id . "','" . $image['image'] . "'," . $image['width'] . "," . $image['height'] . ",'" . $image['image_order'] . "','" . $image['meta'] . "')";
                }
            }
            if (count($new_image_value) > 0) {
                $new_image_value = implode(",", $new_image_value);
                $sql = "INSERT INTO " . WPSC_TABLE_PRODUCT_IMAGES . " (`product_id`, `image`, `width`, `height`, `image_order`, `meta`) VALUES " . $new_image_value;
                $wpdb->query($sql);
            }
        }
        $duplicated = true;
    }
    $sendback = wp_get_referer();
    if (isset($duplicated)) {
        $sendback = add_query_arg('duplicated', (int) $duplicated, $sendback);
    }
    wp_redirect($sendback);
    exit;
}
function wpsc_update_custom_meta($product_id, $post_data)
{
    global $wpdb;
    if ($post_data['new_custom_meta'] != null) {
        foreach ((array) $post_data['new_custom_meta']['name'] as $key => $name) {
            $value = $post_data['new_custom_meta']['value'][(int) $key];
            if ($name != '' && $value != '') {
                add_product_meta($product_id, $name, $value, false, true);
            }
        }
    }
    if ($post_data['custom_meta'] != null) {
        foreach ((array) $post_data['custom_meta'] as $key => $values) {
            if ($values['name'] != '' && $values['value'] != '') {
                $wpdb->query("UPDATE `" . WPSC_TABLE_PRODUCTMETA . "` SET `meta_key` = '" . $wpdb->escape($values['name']) . "', `meta_value` = '" . $wpdb->escape($values['value']) . "' WHERE `id` IN ('" . (int) $key . "')LIMIT 1 ;");
                // echo "UPDATE `".WPSC_TABLE_PRODUCTMETA."` SET `meta_key` = '".$wpdb->escape($values['name'])."', `meta_value` = '".$wpdb->escape($values['value'])."' WHERE `id` IN ('".(int)$key."') LIMIT 1 ;";
                //add_product_meta($_POST['prodid'], $values['name'], $values['value'], false, true);
            }
        }
    }
}
function wpsc_add_product($product_values)
{
    global $wpdb;
    // takes an array, inserts it into the database as a product
    $success = false;
    $insertsql = "INSERT INTO `" . WPSC_TABLE_PRODUCT_LIST . "` SET";
    $insertsql .= "`name` = '" . $wpdb->escape($product_values['name']) . "',";
    $insertsql .= "`description`  = '" . $wpdb->escape($product_values['description']) . "',";
    $insertsql .= "`additional_description`  = '" . $wpdb->escape($product_values['additional_description']) . "',";
    $insertsql .= "`price` = '" . $wpdb->escape($product_values['price']) . "',";
    $insertsql .= "`quantity_limited` = '" . $wpdb->escape($product_values['quantity_limited']) . "',";
    $insertsql .= "`quantity` = '" . $wpdb->escape($product_values['quantity']) . "',";
    $insertsql .= "`special` = '" . $wpdb->escape($product_values['special']) . "',";
    $insertsql .= "`special_price` = '" . $wpdb->escape($product_values['special_price']) . "',";
    $insertsql .= "`weight` = '" . $wpdb->escape($product_values['weight']) . "',";
    $insertsql .= "`weight_unit` = '" . $wpdb->escape($product_values['weight_unit']) . "',";
    $insertsql .= "`no_shipping` = '" . $wpdb->escape($product_values['no_shipping']) . "',";
    $insertsql .= "`pnp` = '" . $wpdb->escape($product_values['pnp']) . "',";
    $insertsql .= "`international_pnp` = '" . $wpdb->escape($product_values['international_pnp']) . "',";
    $insertsql .= "`donation` = '" . $wpdb->escape($product_values['donation']) . "',";
    $insertsql .= "`display_frontpage` = '" . $wpdb->escape($product_values['display_frontpage']) . "',";
    $insertsql .= "`notax` = '" . $wpdb->escape($product_values['notax']) . "',";
    $insertsql .= "`image` = '0',";
    $insertsql .= "`file` = '0',";
    $insertsql .= "`thumbnail_state` = '0' ;";
    //Insert the data
    if ($wpdb->query($insertsql)) {
        // if we succeeded, we have a product id, we wants it for the next stuff
        $product_id = $wpdb->get_var("SELECT LAST_INSERT_ID() AS `id` FROM `" . WPSC_TABLE_PRODUCT_LIST . "` LIMIT 1");
        // add the tags
        if (function_exists('wp_insert_term')) {
            product_tag_init();
            $tags = $product_values['product_tag'];
            if ($tags != "") {
                $tags = explode(',', $tags);
                foreach ($tags as $tag) {
                    $tt = wp_insert_term((string) $tag, 'product_tag');
                }
                $return = wp_set_object_terms($product_id, $tags, 'product_tag');
            }
        }
        $image = wpsc_item_process_image($product_id, $product_values['image_path'], basename($product_values['image_path']), $product_values['width'], $product_values['height'], $product_values['image_resize']);
        if ($image != null) {
            $wpdb->query("UPDATE `" . WPSC_TABLE_PRODUCT_LIST . "` SET `image` = '" . $wpdb->escape($image) . "' WHERE `id`='" . $product_id . "' LIMIT 1");
        }
        // add the product meta values
        if ($product_values['productmeta_values'] != null) {
            foreach ((array) $product_values['productmeta_values'] as $key => $value) {
                if (get_product_meta($product_id, $key) != false) {
                    update_product_meta($product_id, $key, $value);
                } else {
                    add_product_meta($product_id, $key, $value);
                }
            }
        }
        // and the custom meta values
        if ($product_values['new_custom_meta'] != null) {
            foreach ((array) $product_values['new_custom_meta']['name'] as $key => $name) {
                $value = $product_values['new_custom_meta']['value'][(int) $key];
                if ($name != '' && $value != '') {
                    add_product_meta($product_id, $name, $value, false, true);
                }
            }
        }
        // Add the tidy url name
        $tidied_name = trim($product_values['name']);
        $tidied_name = strtolower($tidied_name);
        $url_name = sanitize_title($tidied_name);
        $similar_names = $wpdb->get_row("SELECT COUNT(*) AS `count`, MAX(REPLACE(`meta_value`, '" . $wpdb->escape($url_name) . "', '')) AS `max_number` FROM `" . WPSC_TABLE_PRODUCTMETA . "` WHERE `meta_key` IN ('url_name') AND `meta_value` REGEXP '^(" . $wpdb->escape($url_name) . "){1}(\\d)*\$' ", ARRAY_A);
        $extension_number = '';
        if ($similar_names['count'] > 0) {
            $extension_number = (int) $similar_names['max_number'] + 1;
        }
        $url_name .= $extension_number;
        add_product_meta($product_id, 'url_name', $url_name, true);
        // Add the varations and associated values
        $variations_procesor = new nzshpcrt_variations();
        if ($product_values['variation_values'] != null) {
            $variations_procesor->add_to_existing_product($product_id, $product_values['variation_values']);
        }
        if ($product_values['variation_priceandstock'] != null) {
            $variations_procesor->update_variation_values($product_id, $product_values['variation_priceandstock']);
        }
        // Add the selelcted categories
        $item_list = '';
        if (count($product_values['category']) > 0) {
            foreach ($product_values['category'] as $category_id) {
                $category_id = (int) $category_id;
                $check_existing = $wpdb->get_var("SELECT `id` FROM `" . WPSC_TABLE_ITEM_CATEGORY_ASSOC . "` WHERE `product_id` = " . $product_id . " AND `category_id` = '{$category_id}' LIMIT 1");
                if ($check_existing == null) {
                    $wpdb->query("INSERT INTO `" . WPSC_TABLE_ITEM_CATEGORY_ASSOC . "` ( `product_id` , `category_id` ) VALUES ( '" . $product_id . "', '" . $category_id . "');");
                }
            }
        }
        $success = true;
    }
    return $success;
}
示例#4
0
 $url_name = preg_replace(array("/(\\s)+/", "/[^\\w-]+/i"), array("-", ''), $tidied_name);
 $similar_names = $wpdb->get_row("SELECT COUNT(*) AS `count`, MAX(REPLACE(`meta_value`, '{$url_name}', '')) AS `max_number` FROM `" . $wpdb->prefix . "wpsc_productmeta` WHERE `meta_key` IN ('url_name') AND `meta_value` REGEXP '^({$url_name}){1}(\\d)*\$' ", ARRAY_A);
 $extension_number = '';
 if ($similar_names['count'] > 0) {
     $extension_number = (int) $similar_names['max_number'] + 1;
 }
 $stored_name = get_product_meta($_POST['prodid'], 'url_name', true);
 if (get_product_meta($_POST['prodid'], 'url_name', true) != false) {
     $current_url_name = get_product_meta($_POST['prodid'], 'url_name');
     if ($current_url_name[0] != $url_name) {
         $url_name .= $extension_number;
         update_product_meta($_POST['prodid'], 'url_name', $url_name);
     }
 } else {
     $url_name .= $extension_number;
     add_product_meta($_POST['prodid'], 'url_name', $url_name, true);
 }
 /* update thumbnail images */
 if (!($thumbnail_image == null && $_POST['image_resize'] == 3 && $_POST['current_thumbnail_image'] != null)) {
     if ($thumbnail_image != null) {
         $wpdb->query("UPDATE `" . $wpdb->prefix . "product_list` SET `thumbnail_image` = '" . $thumbnail_image . "' WHERE `id`='" . $_POST['prodid'] . "' LIMIT 1");
     }
 }
 $image_resize = $_POST['image_resize'];
 if (!is_numeric($image_resize) || $image_resize < 1) {
     $image_resize = 0;
 }
 $wpdb->query("UPDATE `" . $wpdb->prefix . "product_list` SET `thumbnail_state` = '" . $image_resize . "' WHERE `id`='" . $_POST['prodid'] . "' LIMIT 1");
 if ($_POST['deleteimage'] == 1) {
     $wpdb->query("UPDATE `" . $wpdb->prefix . "product_list` SET `image` = ''  WHERE `id`='" . $_POST['prodid'] . "' LIMIT 1");
 }
示例#5
0
function wpsc_install()
{
    global $wpdb, $user_level, $wp_rewrite, $wp_version;
    $table_name = $wpdb->prefix . "wpsc_product_list";
    $first_install = false;
    $result = mysql_list_tables(DB_NAME);
    $tables = array();
    while ($row = mysql_fetch_row($result)) {
        $tables[] = $row[0];
    }
    if (!in_array($table_name, $tables)) {
        $first_install = true;
        add_option('wpsc_purchaselogs_fixed', true);
    }
    if (get_option('wpsc_version') == null) {
        add_option('wpsc_version', WPSC_VERSION, 'wpsc_version', 'yes');
    }
    // run the create or update code here.
    wpsc_create_or_update_tables();
    wpsc_create_upload_directories();
    /* all code to add new database tables and columns must be above here */
    if (get_option('wpsc_version') < WPSC_VERSION || get_option('wpsc_version') == WPSC_VERSION && get_option('wpsc_minor_version') < WPSC_MINOR_VERSION) {
        update_option('wpsc_version', WPSC_VERSION);
        update_option('wpsc_minor_version', WPSC_MINOR_VERSION);
    }
    $add_initial_category = $wpdb->get_results("SELECT COUNT(*) AS `count` FROM `" . WPSC_TABLE_PRODUCT_CATEGORIES . "`;", ARRAY_A);
    if ($add_initial_category[0]['count'] == 0) {
        $wpdb->query("INSERT INTO `" . WPSC_TABLE_CATEGORISATION_GROUPS . "` (`id`, `name`, `description`, `active`, `default`) VALUES (1, 'Categories', 'Product Categories', '1', '1')");
        $wpdb->query("INSERT INTO `" . WPSC_TABLE_CATEGORISATION_GROUPS . "` (`id`, `name`, `description`, `active`, `default`) VALUES (2, 'Brands', 'Product Brands', '1', '0')");
        $wpdb->query("INSERT INTO `" . WPSC_TABLE_PRODUCT_CATEGORIES . "` (`group_id`, `name` , `description`, `active`) VALUES ('1', '" . TXT_WPSC_EXAMPLECATEGORY . "', '" . TXT_WPSC_EXAMPLEDETAILS . "', '1');");
        $wpdb->query("INSERT INTO `" . WPSC_TABLE_PRODUCT_CATEGORIES . "` (`group_id`, `name` , `description`, `active`) VALUES ('2', '" . TXT_WPSC_EXAMPLEBRAND . "', '" . TXT_WPSC_EXAMPLEDETAILS . "', '1');");
    }
    $purchase_statuses_data = $wpdb->get_results("SELECT COUNT(*) AS `count` FROM `" . WPSC_TABLE_PURCHASE_STATUSES . "`", ARRAY_A);
    if ($purchase_statuses_data[0]['count'] == 0) {
        $wpdb->query("INSERT INTO `" . WPSC_TABLE_PURCHASE_STATUSES . "` (`name` , `active` , `colour` ) \n    VALUES\n    ('" . TXT_WPSC_RECEIVED . "', '1', ''),\n    ('" . TXT_WPSC_ACCEPTED_PAYMENT . "', '1', ''),\n    ('" . TXT_WPSC_JOB_DISPATCHED . "', '1', ''),\n    ('" . TXT_WPSC_PROCESSED . "', '1', '');");
    }
    $check_category_assoc = $wpdb->get_results("SELECT COUNT(*) AS `count` FROM `" . WPSC_TABLE_ITEM_CATEGORY_ASSOC . "`;", ARRAY_A);
    if ($check_category_assoc[0]['count'] == 0) {
        $sql = "SELECT * FROM `" . WPSC_TABLE_PRODUCT_LIST . "` WHERE `active`=1";
        $product_list = $wpdb->get_results($sql, ARRAY_A);
        foreach ((array) $product_list as $product) {
            $results = $wpdb->query("INSERT INTO `" . WPSC_TABLE_ITEM_CATEGORY_ASSOC . "` (`product_id` , `category_id` ) VALUES ('" . $product['id'] . "', '" . $product['category'] . "');");
        }
    }
    add_option('show_thumbnails', 1, TXT_WPSC_SHOWTHUMBNAILS, "yes");
    add_option('product_image_width', '', TXT_WPSC_PRODUCTIMAGEWIDTH, 'yes');
    add_option('product_image_height', '', TXT_WPSC_PRODUCTIMAGEHEIGHT, 'yes');
    add_option('category_image_width', '', TXT_WPSC_CATEGORYIMAGEWIDTH, 'yes');
    add_option('category_image_height', '', TXT_WPSC_CATEGORYIMAGEHEIGHT, 'yes');
    add_option('product_list_url', '', TXT_WPSC_PRODUCTLISTURL, 'yes');
    add_option('shopping_cart_url', '', TXT_WPSC_SHOPPINGCARTURL, 'yes');
    add_option('checkout_url', '', TXT_WPSC_CHECKOUTURL, 'yes');
    add_option('transact_url', '', TXT_WPSC_TRANSACTURL, 'yes');
    add_option('payment_gateway', '', TXT_WPSC_PAYMENTGATEWAY, 'yes');
    if (function_exists('register_sidebar')) {
        add_option('cart_location', '4', TXT_WPSC_CARTLOCATION, 'yes');
    } else {
        add_option('cart_location', '1', TXT_WPSC_CARTLOCATION, 'yes');
    }
    if (function_exists('register_sidebar')) {
        add_option('cart_location', '4', TXT_WPSC_CARTLOCATION, 'yes');
    } else {
        add_option('cart_location', '1', TXT_WPSC_CARTLOCATION, 'yes');
    }
    //add_option('show_categorybrands', '0', TXT_WPSC_SHOWCATEGORYBRANDS, 'yes');
    add_option('currency_type', '156', TXT_WPSC_CURRENCYTYPE, 'yes');
    add_option('currency_sign_location', '3', TXT_WPSC_CURRENCYSIGNLOCATION, 'yes');
    add_option('gst_rate', '1', TXT_WPSC_GSTRATE, 'yes');
    add_option('max_downloads', '1', TXT_WPSC_MAXDOWNLOADS, 'yes');
    add_option('display_pnp', '1', TXT_WPSC_DISPLAYPNP, 'yes');
    add_option('display_specials', '1', TXT_WPSC_DISPLAYSPECIALS, 'yes');
    add_option('do_not_use_shipping', '0', 'do_not_use_shipping', 'yes');
    add_option('postage_and_packaging', '0', TXT_WPSC_POSTAGEAND_PACKAGING, 'yes');
    add_option('purch_log_email', '', TXT_WPSC_PURCHLOGEMAIL, 'yes');
    add_option('return_email', '', TXT_WPSC_RETURNEMAIL, 'yes');
    add_option('terms_and_conditions', '', TXT_WPSC_TERMSANDCONDITIONS, 'yes');
    add_option('google_key', 'none', TXT_WPSC_GOOGLEMECHANTKEY, 'yes');
    add_option('google_id', 'none', TXT_WPSC_GOOGLEMECHANTID, 'yes');
    add_option('default_brand', 'none', TXT_WPSC_DEFAULTBRAND, 'yes');
    add_option('wpsc_default_category', 'all', TXT_WPSC_DEFAULTCATEGORY, 'yes');
    add_option('product_view', 'default', "", 'yes');
    add_option('add_plustax', 'default', "", '1');
    add_option('nzshpcrt_first_load', '0', "", 'yes');
    if (!(get_option('show_categorybrands') > 0 && get_option('show_categorybrands') < 3)) {
        update_option('show_categorybrands', 2);
    }
    //add_option('show_categorybrands', '0', TXT_WPSC_SHOWCATEGORYBRANDS, 'yes');
    /* PayPal options */
    add_option('paypal_business', '', TXT_WPSC_PAYPALBUSINESS, 'yes');
    add_option('paypal_url', '', TXT_WPSC_PAYPALURL, 'yes');
    add_option('paypal_ipn', '1', TXT_WPSC_PAYPALURL, 'yes');
    //update_option('paypal_url', "https://www.sandbox.paypal.com/xclick");
    add_option('paypal_multiple_business', '', TXT_WPSC_PAYPALBUSINESS, 'yes');
    if (get_option('paypal_multiple_url') == null) {
        add_option('paypal_multiple_url', TXT_WPSC_PAYPALURL, 'yes');
        update_option('paypal_multiple_url', "https://www.paypal.com/cgi-bin/webscr");
    }
    add_option('product_ratings', '0', TXT_WPSC_SHOWPRODUCTRATINGS, 'yes');
    add_option('wpsc_email_receipt', TXT_WPSC_DEFAULT_PURCHASE_RECEIPT, 'yes');
    add_option('wpsc_email_admin', TXT_WPSC_DEFAULT_PURCHASE_REPORT, 'yes');
    if (get_option('wpsc_selected_theme') == '') {
        add_option('wpsc_selected_theme', 'default', 'Selected Theme', 'yes');
        update_option('wpsc_selected_theme', "default");
    }
    if (!get_option('product_image_height')) {
        update_option('product_image_height', '96');
        update_option('product_image_width', '96');
    }
    if (!get_option('category_image_height')) {
        update_option('category_image_height', '96');
        update_option('category_image_width', '96');
    }
    if (!get_option('single_view_image_height')) {
        update_option('single_view_image_height', '128');
        update_option('single_view_image_width', '128');
    }
    if (!get_option('wpsc_gallery_image_height')) {
        update_option('wpsc_gallery_image_height', '96');
        update_option('wpsc_gallery_image_width', '96');
    }
    if (!is_array(get_option('custom_gateway_options'))) {
        update_option('custom_gateway_options', array('testmode'));
    }
    add_option("wpsc_category_url_cache", array(), '', 'yes');
    wpsc_product_files_htaccess();
    /*
     * This part creates the pages and automatically puts their URLs into the options page.
     * As you can probably see, it is very easily extendable, just pop in your page and the deafult content in the array and you are good to go.
     */
    $post_date = date("Y-m-d H:i:s");
    $post_date_gmt = gmdate("Y-m-d H:i:s");
    $num = 0;
    $pages[$num]['name'] = 'products-page';
    $pages[$num]['title'] = TXT_WPSC_PRODUCTSPAGE;
    $pages[$num]['tag'] = '[productspage]';
    $pages[$num]['option'] = 'product_list_url';
    $num++;
    $pages[$num]['name'] = 'checkout';
    $pages[$num]['title'] = TXT_WPSC_CHECKOUT;
    $pages[$num]['tag'] = '[shoppingcart]';
    $pages[$num]['option'] = 'shopping_cart_url';
    //   $num++;
    //   $pages[$num]['name'] = 'enter-details';
    //   $pages[$num]['title'] = TXT_WPSC_ENTERDETAILS;
    //   $pages[$num]['tag'] = '[checkout]';
    //   $pages[2$num]['option'] = 'checkout_url';
    $num++;
    $pages[$num]['name'] = 'transaction-results';
    $pages[$num]['title'] = TXT_WPSC_TRANSACTIONRESULTS;
    $pages[$num]['tag'] = '[transactionresults]';
    $pages[$num]['option'] = 'transact_url';
    $num++;
    $pages[$num]['name'] = 'your-account';
    $pages[$num]['title'] = TXT_WPSC_YOUR_ACCOUNT;
    $pages[$num]['tag'] = '[userlog]';
    $pages[$num]['option'] = 'user_account_url';
    $newpages = false;
    $i = 0;
    $post_parent = 0;
    foreach ($pages as $page) {
        $check_page = $wpdb->get_row("SELECT * FROM `" . $wpdb->posts . "` WHERE `post_content` LIKE '%" . $page['tag'] . "%'  AND `post_type` NOT IN('revision') LIMIT 1", ARRAY_A);
        if ($check_page == null) {
            if ($i == 0) {
                $post_parent = 0;
            } else {
                $post_parent = $first_id;
            }
            if ($wp_version >= 2.1) {
                $sql = "INSERT INTO " . $wpdb->posts . "\n        (post_author, post_date, post_date_gmt, post_content, post_content_filtered, post_title, post_excerpt,  post_status, comment_status, ping_status, post_password, post_name, to_ping, pinged, post_modified, post_modified_gmt, post_parent, menu_order, post_type)\n        VALUES\n        ('1', '{$post_date}', '{$post_date_gmt}', '" . $page['tag'] . "', '', '" . $page['title'] . "', '', 'publish', 'closed', 'closed', '', '" . $page['name'] . "', '', '', '{$post_date}', '{$post_date_gmt}', '{$post_parent}', '0', 'page')";
            } else {
                $sql = "INSERT INTO " . $wpdb->posts . "\n        (post_author, post_date, post_date_gmt, post_content, post_content_filtered, post_title, post_excerpt,  post_status, comment_status, ping_status, post_password, post_name, to_ping, pinged, post_modified, post_modified_gmt, post_parent, menu_order)\n        VALUES\n        ('1', '{$post_date}', '{$post_date_gmt}', '" . $page['tag'] . "', '', '" . $page['title'] . "', '', 'static', 'closed', 'closed', '', '" . $page['name'] . "', '', '', '{$post_date}', '{$post_date_gmt}', '{$post_parent}', '0')";
            }
            $wpdb->query($sql);
            $post_id = $wpdb->insert_id;
            if ($i == 0) {
                $first_id = $post_id;
            }
            $wpdb->query("UPDATE {$wpdb->posts} SET guid = '" . get_permalink($post_id) . "' WHERE ID = '{$post_id}'");
            update_option($page['option'], get_permalink($post_id));
            if ($page['option'] == 'shopping_cart_url') {
                update_option('checkout_url', get_permalink($post_id));
            }
            $newpages = true;
            $i++;
        }
    }
    if ($newpages == true) {
        wp_cache_delete('all_page_ids', 'pages');
        $wp_rewrite->flush_rules();
    }
    /* adds nice names for permalinks for products */
    $check_product_names = $wpdb->get_results("SELECT `" . WPSC_TABLE_PRODUCT_LIST . "`.`id`, `" . WPSC_TABLE_PRODUCT_LIST . "`.`name`, `" . WPSC_TABLE_PRODUCTMETA . "`.`meta_key` FROM `" . WPSC_TABLE_PRODUCT_LIST . "` LEFT JOIN `" . WPSC_TABLE_PRODUCTMETA . "` ON `" . WPSC_TABLE_PRODUCT_LIST . "`.`id` = `" . WPSC_TABLE_PRODUCTMETA . "`.`product_id` WHERE (`" . WPSC_TABLE_PRODUCTMETA . "`.`meta_key` IN ('url_name') AND  `" . WPSC_TABLE_PRODUCTMETA . "`.`meta_value` IN (''))  OR ISNULL(`" . WPSC_TABLE_PRODUCTMETA . "`.`meta_key`)", ARRAY_A);
    if ($check_product_names != null) {
        foreach ((array) $check_product_names as $datarow) {
            $tidied_name = trim($datarow['name']);
            $tidied_name = strtolower($tidied_name);
            $url_name = sanitize_title($tidied_name);
            $similar_names = $wpdb->get_row("SELECT COUNT(*) AS `count`, MAX(REPLACE(`meta_value`, '{$url_name}', '')) AS `max_number` FROM `" . WPSC_TABLE_PRODUCTMETA . "` WHERE `meta_key` LIKE 'url_name' AND `meta_value` REGEXP '^({$url_name}){1}(\\d)*\$' ", ARRAY_A);
            $extension_number = '';
            if ($similar_names['count'] > 0) {
                $extension_number = (int) $similar_names['max_number'] + 1;
            }
            if (get_product_meta($datarow['id'], 'url_name') != false) {
                $current_url_name = get_product_meta($datarow['id'], 'url_name');
                if ($current_url_name != $url_name) {
                    $url_name .= $extension_number;
                    update_product_meta($datarow['id'], 'url_name', $url_name);
                }
            } else {
                $url_name .= $extension_number;
                add_product_meta($datarow['id'], 'url_name', $url_name, true);
            }
        }
    }
    /* adds nice names for permalinks for categories */
    $check_category_names = $wpdb->get_results("SELECT DISTINCT `nice-name` FROM `" . WPSC_TABLE_PRODUCT_CATEGORIES . "` WHERE `nice-name` IN ('') AND `active` IN ('1')");
    if ($check_category_names != null) {
        $sql_query = "SELECT `id`, `name` FROM `" . WPSC_TABLE_PRODUCT_CATEGORIES . "` WHERE `active` IN('1')";
        $sql_data = $wpdb->get_results($sql_query, ARRAY_A);
        foreach ((array) $sql_data as $datarow) {
            $tidied_name = trim($datarow['name']);
            $tidied_name = strtolower($tidied_name);
            $url_name = sanitize_title($tidied_name);
            $similar_names = $wpdb->get_row("SELECT COUNT(*) AS `count`, MAX(REPLACE(`nice-name`, '{$url_name}', '')) AS `max_number` FROM `" . WPSC_TABLE_PRODUCT_CATEGORIES . "` WHERE `nice-name` REGEXP '^({$url_name}){1}(\\d)*\$' ", ARRAY_A);
            $extension_number = '';
            if ($similar_names['count'] > 0) {
                $extension_number = (int) $similar_names['max_number'] + 1;
            }
            $url_name .= $extension_number;
            $wpdb->query("UPDATE `" . WPSC_TABLE_PRODUCT_CATEGORIES . "` SET `nice-name` = '{$url_name}' WHERE `id` = '" . $datarow['id'] . "' LIMIT 1 ;");
        }
        $wp_rewrite->flush_rules();
    }
    /* Moves images to thumbnails directory */
    // this code should no longer be needed, as most people will be using a sufficiently new version
    $image_dir = WPSC_FILE_PATH . "/images/";
    $product_images = WPSC_IMAGE_DIR;
    $product_thumbnails = WPSC_THUMBNAIL_DIR;
    if (!is_dir($product_thumbnails)) {
        @mkdir($product_thumbnails, 0775);
    }
    $product_list = $wpdb->get_results("SELECT * FROM `" . WPSC_TABLE_PRODUCT_LIST . "` WHERE `image` != ''", ARRAY_A);
    foreach ((array) $product_list as $product) {
        if (!glob($product_thumbnails . $product['image'])) {
            $new_filename = $product['id'] . "_" . $product['image'];
            if (file_exists($image_dir . $product['image'])) {
                copy($image_dir . $product['image'], $product_thumbnails . $new_filename);
                if (file_exists($product_images . $product['image'])) {
                    copy($product_images . $product['image'], $product_images . $new_filename);
                }
                $wpdb->query("UPDATE `" . WPSC_TABLE_PRODUCT_LIST . "` SET `image` = '" . $new_filename . "' WHERE `id`='" . $product['id'] . "' LIMIT 1");
            } else {
                $imagedir = $product_thumbnails;
                $name = $new_filename;
                $new_image_path = $product_images . $product['image'];
                $imagepath = $product['image'];
                $height = get_option('product_image_height');
                $width = get_option('product_image_width');
                if (file_exists($product_images . $product['image'])) {
                    include "extra_image_processing.php";
                    copy($product_images . $product['image'], $product_images . $new_filename);
                    $wpdb->query("UPDATE `" . WPSC_TABLE_PRODUCT_LIST . "` SET `image` = '" . $new_filename . "' WHERE `id`='" . $product['id'] . "' LIMIT 1");
                }
            }
        }
    }
    // */
}
示例#6
0
        $tidied_name = strtolower($tidied_name);
        $url_name = preg_replace(array("/(\\s)+/", "/[^\\w-]+/"), array("-", ''), $tidied_name);
        $similar_names = $wpdb->get_row("SELECT COUNT(*) AS `count`, MAX(REPLACE(`meta_value`, '{$url_name}', '')) AS `max_number` FROM `" . $wpdb->prefix . "wpsc_productmeta` WHERE `meta_key` LIKE 'url_name' AND `meta_value` REGEXP '^({$url_name}){1}(\\d)*\$' ", ARRAY_A);
        $extension_number = '';
        if ($similar_names['count'] > 0) {
            $extension_number = (int) $similar_names['max_number'] + 1;
        }
        if (get_product_meta($datarow['id'], 'url_name') != false) {
            $current_url_name = get_product_meta($datarow['id'], 'url_name');
            if ($current_url_name != $url_name) {
                $url_name .= $extension_number;
                update_product_meta($datarow['id'], 'url_name', $url_name);
            }
        } else {
            $url_name .= $extension_number;
            add_product_meta($datarow['id'], 'url_name', $url_name, true);
        }
    }
}
/* creates table to store data on what was bought with what however many times */
if ($wpdb->get_var("SHOW TABLES LIKE '" . $wpdb->prefix . "also_bought_product'") != $wpdb->prefix . "also_bought_product") {
    $wpsc_also_bought_product = "CREATE TABLE `" . $wpdb->prefix . "also_bought_product` (\n  `id` bigint(20) unsigned NOT NULL auto_increment,\n  `selected_product` bigint(20) unsigned NOT NULL default '0',\n  `associated_product` bigint(20) unsigned NOT NULL default '0',\n  `quantity` int(10) unsigned NOT NULL default '0',\n  PRIMARY KEY  (`id`)\n) TYPE=MyISAM;";
    $wpdb->query($wpsc_also_bought_product);
}
if (!$wpdb->get_results("SELECT `id` FROM `" . $wpdb->prefix . "also_bought_product`")) {
    /* inserts data on what was bought with what however many times */
    $product_ids = $wpdb->get_col("SELECT `id` FROM `" . $wpdb->prefix . "product_list` WHERE `active` IN('1')");
    foreach ((array) $product_ids as $prodid) {
        $cart_ids = $wpdb->get_results("SELECT `purchaseid` FROM `" . $wpdb->prefix . "cart_contents` WHERE `prodid` IN ('{$prodid}')", ARRAY_A);
        $popular_array = array();
        foreach ((array) $cart_ids as $cart_id) {
示例#7
0
function nzshpcrt_install()
{
    global $wpdb, $user_level, $wp_rewrite, $wp_version;
    $table_name = $wpdb->prefix . "product_list";
    //$log_table_name = $wpdb->prefix . "sms_log";
    if ($wp_version < 2.1) {
        get_currentuserinfo();
        if ($user_level < 8) {
            return;
        }
    }
    $first_install = false;
    $result = mysql_list_tables(DB_NAME);
    $tables = array();
    while ($row = mysql_fetch_row($result)) {
        $tables[] = $row[0];
    }
    if (!in_array($table_name, $tables)) {
        $first_install = true;
    }
    if (get_option('wpsc_version') == null) {
        add_option('wpsc_version', WPSC_VERSION, 'wpsc_version', 'yes');
    }
    // Table structure for table `".$wpdb->prefix."also_bought_product`
    $num = 0;
    $wpsc_tables[$num]['table_name'] = $wpdb->prefix . "also_bought_product";
    $wpsc_tables[$num]['table_sql'] = "CREATE TABLE `" . $wpdb->prefix . "also_bought_product` (\n\t\t`id` bigint(20) unsigned NOT NULL auto_increment,\n\t\t`selected_product` bigint(20) unsigned NOT NULL default '0',\n\t\t`associated_product` bigint(20) unsigned NOT NULL default '0',\n\t\t`quantity` int(10) unsigned NOT NULL default '0',\n\t\tPRIMARY KEY  (`id`)\n\t) TYPE=MyISAM ;\n\t";
    // Table structure for table `".$wpdb->prefix."cart_contents`
    $num++;
    $wpsc_tables[$num]['table_name'] = $wpdb->prefix . 'cart_contents';
    $wpsc_tables[$num]['table_sql'] = "CREATE TABLE `" . $wpdb->prefix . "cart_contents` (\n\t\t`id` bigint(20) unsigned NOT NULL auto_increment,\n\t\t`prodid` bigint(20) unsigned NOT NULL default '0',\n\t\t`purchaseid` bigint(20) unsigned NOT NULL default '0',\n\t\t`price` varchar(128) NOT NULL default '0',\n\t\t`pnp` varchar(128) NOT NULL default '0',\n\t\t`gst` varchar(128) NOT NULL default '0',\n\t\t`quantity` int(10) unsigned NOT NULL default '0',\n\t\t`donation` varchar(1) NOT NULL default '0',\n\t\t`no_shipping` varchar(1) NOT NULL default '0',\n\t\t`files` TEXT NOT NULL default '',\n\t\tPRIMARY KEY  (`id`)\n\t) TYPE=MyISAM ;\n\t";
    // Table structure for table `".$wpdb->prefix."cart_item_extras`
    $num++;
    $wpsc_tables[$num]['table_name'] = $wpdb->prefix . 'cart_item_extras';
    $wpsc_tables[$num]['table_sql'] = "CREATE TABLE `" . $wpdb->prefix . "cart_item_extras` (\n\t\t`id` int(11) NOT NULL auto_increment,\n\t\t`cart_id` int(11) NOT NULL,\n\t\t`extra_id` int(11) NOT NULL,\n\t\tPRIMARY KEY  (`id`)\n\t) TYPE=MyISAM;\n\t";
    // Table structure for table `".$wpdb->prefix."cart_item_variations`
    $num++;
    $wpsc_tables[$num]['table_name'] = $wpdb->prefix . 'cart_item_variations';
    $wpsc_tables[$num]['table_sql'] = "CREATE TABLE `" . $wpdb->prefix . "cart_item_variations` (\n\t\t`id` bigint(20) unsigned NOT NULL auto_increment,\n\t\t`cart_id` bigint(20) unsigned NOT NULL default '0',\n\t\t`variation_id` bigint(20) unsigned NOT NULL default '0',\n\t\t`value_id` bigint(20) unsigned NOT NULL default '0',\n\t\tPRIMARY KEY  (`id`)\n\t) TYPE=MyISAM;\n\t";
    // Table structure for table `".$wpdb->prefix."collect_data_forms`
    $num++;
    $wpsc_tables[$num]['table_name'] = $wpdb->prefix . 'collect_data_forms';
    $wpsc_tables[$num]['table_sql'] = "CREATE TABLE `" . $wpdb->prefix . "collect_data_forms` (\n\t\t`id` bigint(20) unsigned NOT NULL auto_increment,\n\t\t`name` varchar(255) NOT NULL default '',\n\t\t`type` varchar(64) NOT NULL default '',\n\t\t`mandatory` varchar(1) NOT NULL default '0',\n\t\t`display_log` char(1) NOT NULL default '0',\n\t\t`default` varchar(128) NOT NULL default '0',\n\t\t`active` varchar(1) NOT NULL default '1',\n\t\t`order` int(10) unsigned NOT NULL default '0',\n\t\tPRIMARY KEY  (`id`),\n\t\tKEY `order` (`order`)\n\t) TYPE=MyISAM ;\n\t";
    // Table structure for table `".$wpdb->prefix."currency_list`
    $num++;
    $wpsc_tables[$num]['table_name'] = $wpdb->prefix . 'currency_list';
    $wpsc_tables[$num]['table_sql'] = "CREATE TABLE `" . $wpdb->prefix . "currency_list` (\n\t\t`id` bigint(20) unsigned NOT NULL auto_increment,\n\t\t`country` varchar(255) NOT NULL default '',\n\t\t`isocode` char(2) default NULL,\n\t\t`currency` varchar(255) NOT NULL default '',\n\t\t`symbol` varchar(10) NOT NULL default '',\n\t\t`symbol_html` varchar(10) NOT NULL default '',\n\t\t`code` char(3) NOT NULL default '',\n\t\t`has_regions` char(1) NOT NULL default '0',\n\t\t`tax` varchar(8) NOT NULL default '',\n\t\tPRIMARY KEY  (`id`)\n\t) TYPE=MyISAM ;\n\t";
    // Table structure for table `".$wpdb->prefix."download_status`
    $num++;
    $wpsc_tables[$num]['table_name'] = $wpdb->prefix . 'download_status';
    $wpsc_tables[$num]['table_sql'] = "CREATE TABLE `" . $wpdb->prefix . "download_status` (\n\t\t`id` bigint(20) unsigned NOT NULL auto_increment,\n\t\t`fileid` bigint(20) unsigned NOT NULL default '0',\n\t\t`purchid` bigint(20) unsigned NOT NULL default '0',\n\t\t`uniqueid` varchar(64) default NULL,\n\t\t`downloads` int(11) NOT NULL default '0',\n\t\t`ip_number` varchar(255) NOT NULL default '',\n\t\t`active` varchar(1) NOT NULL default '0',\n\t\t`datetime` datetime NOT NULL,\n\t\tPRIMARY KEY  (`id`),\n\t\tUNIQUE KEY `uniqueid` (`uniqueid`)\n\t) TYPE=MyISAM;\n\t";
    // Table structure for table `".$wpdb->prefix."extras_values`
    $num++;
    $wpsc_tables[$num]['table_name'] = $wpdb->prefix . 'extras_values';
    $wpsc_tables[$num]['table_sql'] = "CREATE TABLE `" . $wpdb->prefix . "extras_values` (\n\t\t`id` int(11) NOT NULL auto_increment,\n\t\t`name` varchar(128) NOT NULL,\n\t\t`extras_id` int(11) NOT NULL,\n\t\tPRIMARY KEY  (`id`)\n\t) TYPE=MyISAM;\n\t";
    // Table structure for table `".$wpdb->prefix."extras_values_associations`
    $num++;
    $wpsc_tables[$num]['table_name'] = $wpdb->prefix . 'extras_values_associations';
    $wpsc_tables[$num]['table_sql'] = "CREATE TABLE `" . $wpdb->prefix . "extras_values_associations` (\n\t\t`id` int(11) NOT NULL auto_increment,\n\t\t`product_id` int(11) NOT NULL,\n\t\t`value_id` int(11) NOT NULL,\n\t\t`price` varchar(20) NOT NULL,\n\t\t`visible` varchar(1) NOT NULL,\n\t\t`extras_id` int(11) NOT NULL,\n\t\tPRIMARY KEY  (`id`)\n\t) TYPE=MyISAM;\n\t";
    // Table structure for table `".$wpdb->prefix."item_category_associations`
    $num++;
    $wpsc_tables[$num]['table_name'] = $wpdb->prefix . 'item_category_associations';
    $wpsc_tables[$num]['table_sql'] = "CREATE TABLE `" . $wpdb->prefix . "item_category_associations` (\n\t\t`id` bigint(20) unsigned NOT NULL auto_increment,\n\t\t`product_id` bigint(20) unsigned NOT NULL default '0',\n\t\t`category_id` bigint(20) unsigned NOT NULL default '0',\n\t\tPRIMARY KEY  (`id`),\n\t\tUNIQUE KEY `product_id` (`product_id`,`category_id`)\n\t) TYPE=MyISAM ;\n\t";
    // Table structure for table `".$wpdb->prefix."product_brands`
    $num++;
    $wpsc_tables[$num]['table_name'] = $wpdb->prefix . 'product_brands';
    $wpsc_tables[$num]['table_sql'] = "CREATE TABLE `" . $wpdb->prefix . "product_brands` (\n\t\t`id` bigint(20) NOT NULL auto_increment,\n\t\t`name` text NOT NULL,\n\t\t`description` text NOT NULL,\n\t\t`active` varchar(1) NOT NULL default '1',\n\t\t`order` bigint(20) unsigned NOT NULL,\n\t\tPRIMARY KEY  (`id`)\n\t) TYPE=MyISAM ;\n\t";
    // Table structure for table `".$wpdb->prefix."product_categories`
    $num++;
    $wpsc_tables[$num]['table_name'] = $wpdb->prefix . 'product_categories';
    $wpsc_tables[$num]['table_sql'] = "CREATE TABLE `" . $wpdb->prefix . "product_categories` (\n\t\t`id` bigint(20) NOT NULL auto_increment,\n\t\t`group_id` BIGINT( 20 ) UNSIGNED NOT NULL,\n\t\t`name` text NOT NULL,\n\t\t`nice-name` varchar(255) NOT NULL,\n\t\t`description` text NOT NULL,\n\t\t`image` text NOT NULL,\n\t\t`fee` varchar(1) NOT NULL default '0',\n\t\t`active` varchar(1) NOT NULL default '1',\n\t\t`category_parent` bigint(20) unsigned default '0',\n\t\t`order` bigint(20) unsigned NOT NULL,\n\t\tPRIMARY KEY  (`id`),\n\t\tKEY `group_id` (`group_id`),\n\t\tKEY `nice-name` (`nice-name`)\n\t) TYPE=MyISAM ;\n\t";
    // Table structure for table `".$wpdb->prefix."product_extra`
    $num++;
    $wpsc_tables[$num]['table_name'] = $wpdb->prefix . 'product_extra';
    $wpsc_tables[$num]['table_sql'] = "CREATE TABLE `" . $wpdb->prefix . "product_extra` (\n\t\t`id` int(11) NOT NULL auto_increment,\n\t\t`name` varchar(128) NOT NULL,\n\t\tPRIMARY KEY  (`id`)\n\t) TYPE=MyISAM;\n\t";
    // Table structure for table `".$wpdb->prefix."product_files`
    $num++;
    $wpsc_tables[$num]['table_name'] = $wpdb->prefix . 'product_files';
    $wpsc_tables[$num]['table_sql'] = "CREATE TABLE `" . $wpdb->prefix . "product_files` (\n\t\t`id` bigint(20) unsigned NOT NULL auto_increment,\n\t\t`filename` varchar(255) NOT NULL default '',\n\t\t`mimetype` varchar(128) NOT NULL default '',\n\t\t`idhash` varchar(45) NOT NULL default '',\n\t\t`preview` varchar(255) NOT NULL default '',\n\t\t`preview_mimetype` varchar(128) NOT NULL default '',\n\t\t`date` varchar(255) NOT NULL,\n\t\tPRIMARY KEY  (`id`)\n\t) TYPE=MyISAM ;\n\t";
    // Table structure for table `".$wpdb->prefix."product_images`
    $num++;
    $wpsc_tables[$num]['table_name'] = $wpdb->prefix . 'product_images';
    $wpsc_tables[$num]['table_sql'] = "CREATE TABLE `" . $wpdb->prefix . "product_images` (\n\t\t`id` bigint(20) unsigned NOT NULL auto_increment,\n\t\t`product_id` bigint(20) unsigned NOT NULL,\n\t\t`image` varchar(255) NOT NULL,\n\t\t`width` mediumint(8) unsigned NOT NULL,\n\t\t`height` mediumint(8) unsigned NOT NULL,\n\t\tPRIMARY KEY  (`id`),\n\t\tKEY `product_id` (`product_id`)\n\t) TYPE=MyISAM ;\n\t";
    // Table structure for table `".$wpdb->prefix."product_list`
    $num++;
    $wpsc_tables[$num]['table_name'] = $wpdb->prefix . 'product_list';
    $wpsc_tables[$num]['table_sql'] = "CREATE TABLE `" . $wpdb->prefix . "product_list` (\n\t\t`id` bigint(20) unsigned NOT NULL auto_increment,\n\t\t`name` text NOT NULL,\n\t\t`description` longtext NOT NULL,\n\t\t`additional_description` longtext NOT NULL,\n\t\t`price` varchar(20) NOT NULL default '0',\n\t\t`weight` int(11) NOT NULL default '0',\n\t\t`weight_unit` varchar(10) NOT NULL,\n\t\t`pnp` varchar(20) NOT NULL default '0',\n\t\t`international_pnp` varchar(20) NOT NULL default '0',\n\t\t`file` bigint(20) unsigned NOT NULL,\n\t\t`image` text NOT NULL,\n\t\t`category` bigint(20) unsigned NOT NULL default '0',\n\t\t`brand` bigint(20) unsigned NOT NULL default '0',\n\t\t`quantity_limited` varchar(1) NOT NULL,\n\t\t`quantity` int(10) unsigned NOT NULL default '0',\n\t\t`special` varchar(1) NOT NULL default '0',\n\t\t`special_price` varchar(20) NOT NULL default '0',\n\t\t`display_frontpage` varchar(1) NOT NULL default '0',\n\t\t`notax` varchar(1) NOT NULL default '0',\n\t\t`active` varchar(1) NOT NULL default '1',\n\t\t`donation` varchar(1) NOT NULL default '0',\n\t\t`no_shipping` varchar(1) NOT NULL default '0',\n\t\t`thumbnail_image` text,\n\t\t`thumbnail_state` int(11) NOT NULL,\n\t\tPRIMARY KEY  (`id`)\n\t) TYPE=MyISAM ;\n\t";
    // Table structure for table `".$wpdb->prefix."product_order`
    $num++;
    $wpsc_tables[$num]['table_name'] = $wpdb->prefix . 'product_order';
    $wpsc_tables[$num]['table_sql'] = "CREATE TABLE `" . $wpdb->prefix . "product_order` (\n\t\t`id` bigint(20) unsigned NOT NULL auto_increment,\n\t\t`category_id` bigint(20) unsigned NOT NULL default '0',\n\t\t`product_id` bigint(20) unsigned NOT NULL default '0',\n\t\t`order` bigint(20) unsigned NOT NULL default '0',\n\t\tPRIMARY KEY  (`id`),\n\t\tUNIQUE KEY `category_id` (`category_id`,`product_id`),\n\t\tKEY `order` (`order`)\n\t) TYPE=MyISAM ;\n\t";
    // Table structure for table `".$wpdb->prefix."product_rating`
    $num++;
    $wpsc_tables[$num]['table_name'] = $wpdb->prefix . 'product_rating';
    $wpsc_tables[$num]['table_sql'] = "CREATE TABLE `" . $wpdb->prefix . "product_rating` (\n\t\t`id` bigint(20) unsigned NOT NULL auto_increment,\n\t\t`ipnum` varchar(30) NOT NULL default '',\n\t\t`productid` bigint(20) unsigned NOT NULL default '0',\n\t\t`rated` tinyint(1) NOT NULL default '0',\n\t\t`time` bigint(20) unsigned NOT NULL,\n\t\tPRIMARY KEY  (`id`)\n\t) TYPE=MyISAM;\n\t";
    // Table structure for table `".$wpdb->prefix."product_variations`
    $num++;
    $wpsc_tables[$num]['table_name'] = $wpdb->prefix . 'product_variations';
    $wpsc_tables[$num]['table_sql'] = "CREATE TABLE `" . $wpdb->prefix . "product_variations` (\n\t\t`id` bigint(20) unsigned NOT NULL auto_increment,\n\t\t`name` varchar(128) NOT NULL default '',\n\t\t`variation_association` bigint(20) unsigned NOT NULL default '0',\n\t\tPRIMARY KEY  (`id`),\n\t\tKEY `variation_association` (`variation_association`)\n\t) TYPE=MyISAM;\n\t";
    // Table structure for table `".$wpdb->prefix."purchase_logs`
    $num++;
    $wpsc_tables[$num]['table_name'] = $wpdb->prefix . 'purchase_logs';
    $wpsc_tables[$num]['table_sql'] = "CREATE TABLE `" . $wpdb->prefix . "purchase_logs` (\n\t\t`id` bigint(20) unsigned NOT NULL auto_increment,\n\t\t`totalprice` varchar(128) NOT NULL default '0',\n\t\t`statusno` smallint(6) NOT NULL default '0',\n\t\t`sessionid` varchar(255) NOT NULL default '',\n\t\t`transactid` varchar(255) NOT NULL default '',\n\t\t`authcode` varchar(255) NOT NULL default '',\n\t\t`downloadid` bigint(20) unsigned NOT NULL default '0',\n\t\t`processed` bigint(20) unsigned NOT NULL default '1',\n\t\t`user_ID` bigint(20) unsigned default NULL,\n\t\t`date` varchar(255) NOT NULL default '',\n\t\t`gateway` varchar(64) NOT NULL default '',\n\t\t`billing_country` char(6) NOT NULL default '',\n\t\t`shipping_country` char(6) NOT NULL default '',\n\t\t`base_shipping` varchar(128) NOT NULL default '0',\n\t\t`email_sent` char(1) NOT NULL default '0',\n\t\t`discount_value` varchar(32) NOT NULL default '0',\n\t\t`discount_data` text NOT NULL,\n\t\t`track_id` varchar(50) default NULL default '',\n\t\t`shipping_region` char(6) NOT NULL default '',\n\t\t`find_us` varchar(255) NOT NULL  default '',\n\t\t`engravetext` varchar(255) default NULL,\n\t\t`closest_store` varchar(255) default NULL,\n\t\t`google_order_number` varchar(20) NOT NULL default '',\n\t\t`google_user_marketing_preference` varchar(10) NOT NULL default '',\n\t\t`google_status` longtext NOT NULL,\n\t\tPRIMARY KEY  (`id`),\n\t\tUNIQUE KEY `sessionid` (`sessionid`),\n\t\tKEY `gateway` (`gateway`)\n\t) TYPE=MyISAM ;\n\t";
    // Table structure for table `".$wpdb->prefix."purchase_statuses`
    $num++;
    $wpsc_tables[$num]['table_name'] = $wpdb->prefix . 'purchase_statuses';
    $wpsc_tables[$num]['table_sql'] = "CREATE TABLE `" . $wpdb->prefix . "purchase_statuses` (\n\t\t`id` bigint(20) unsigned NOT NULL auto_increment,\n\t\t`name` varchar(128) NOT NULL default '',\n\t\t`active` varchar(1) NOT NULL default '0',\n\t\t`colour` varchar(6) NOT NULL default '',\n\t\tPRIMARY KEY  (`id`)\n\t) TYPE=MyISAM ;\n\t";
    // Table structure for table `".$wpdb->prefix."region_tax`
    $num++;
    $wpsc_tables[$num]['table_name'] = $wpdb->prefix . 'region_tax';
    $wpsc_tables[$num]['table_sql'] = "CREATE TABLE `" . $wpdb->prefix . "region_tax` (\n\t\t`id` bigint(20) unsigned NOT NULL auto_increment,\n\t\t`country_id` bigint(20) unsigned NOT NULL default '0',\n\t\t`name` varchar(64) NOT NULL default '',\n\t\t`code` char(2) NOT NULL default '',\n\t\t`tax` float NOT NULL default '0',\n\t\tPRIMARY KEY  (`id`),\n\t\tKEY `country_id` (`country_id`)\n\t) TYPE=MyISAM ;\n\t";
    // Table structure for table `".$wpdb->prefix."submited_form_data`
    $num++;
    $wpsc_tables[$num]['table_name'] = $wpdb->prefix . 'submited_form_data';
    $wpsc_tables[$num]['table_sql'] = "CREATE TABLE `" . $wpdb->prefix . "submited_form_data` (\n\t\t`id` bigint(20) unsigned NOT NULL auto_increment,\n\t\t`log_id` bigint(20) unsigned NOT NULL default '0',\n\t\t`form_id` bigint(20) unsigned NOT NULL default '0',\n\t\t`value` varchar(255) NOT NULL default '',\n\t\tPRIMARY KEY  (`id`),\n\t\tKEY `log_id` (`log_id`,`form_id`)\n\t) TYPE=MyISAM ;\n\t";
    // Table structure for table `".$wpdb->prefix."variation_associations`
    $num++;
    $wpsc_tables[$num]['table_name'] = $wpdb->prefix . 'variation_associations';
    $wpsc_tables[$num]['table_sql'] = "CREATE TABLE `" . $wpdb->prefix . "variation_associations` (\n\t\t`id` bigint(20) unsigned NOT NULL auto_increment,\n\t\t`type` varchar(64) NOT NULL default '',\n\t\t`name` varchar(128) NOT NULL default '',\n\t\t`associated_id` bigint(20) unsigned NOT NULL default '0',\n\t\t`variation_id` bigint(20) unsigned NOT NULL default '0',\n\t\tPRIMARY KEY  (`id`),\n\t\tKEY `associated_id` (`associated_id`),\n\t\tKEY `variation_id` (`variation_id`)\n\t) TYPE=MyISAM;\n\t";
    // Table structure for table `".$wpdb->prefix."variation_priceandstock`
    $num++;
    $wpsc_tables[$num]['table_name'] = $wpdb->prefix . 'variation_priceandstock';
    $wpsc_tables[$num]['table_sql'] = "CREATE TABLE `" . $wpdb->prefix . "variation_priceandstock` (\n\t\t`id` bigint(20) unsigned NOT NULL auto_increment,\n\t\t`product_id` bigint(20) unsigned NOT NULL default '0',\n\t\t`variation_id_1` bigint(20) unsigned NOT NULL default '0',\n\t\t`variation_id_2` bigint(20) unsigned NOT NULL default '0',\n\t\t`stock` bigint(20) unsigned NOT NULL default '0',\n\t\t`price` varchar(32) NOT NULL default '0',\n\t\t`file` varchar(1) NOT NULL default '0',\n\t\tPRIMARY KEY  (`id`),\n\t\tKEY `product_id` (`product_id`),\n\t\tKEY `variation_id_1` (`variation_id_1`,`variation_id_2`)\n\t) TYPE=MyISAM;\n\t";
    // Table structure for table `".$wpdb->prefix."variation_values`
    $num++;
    $wpsc_tables[$num]['table_name'] = $wpdb->prefix . 'variation_values';
    $wpsc_tables[$num]['table_sql'] = "CREATE TABLE `" . $wpdb->prefix . "variation_values` (\n\t\t`id` bigint(20) unsigned NOT NULL auto_increment,\n\t\t`name` varchar(128) NOT NULL default '',\n\t\t`variation_id` bigint(20) unsigned NOT NULL default '0',\n\t\tPRIMARY KEY  (`id`),\n\t\tKEY `variation_id` (`variation_id`)\n\t) TYPE=MyISAM;\n\t";
    // Table structure for table `".$wpdb->prefix."variation_values_associations`
    $num++;
    $wpsc_tables[$num]['table_name'] = $wpdb->prefix . 'variation_values_associations';
    $wpsc_tables[$num]['table_sql'] = "CREATE TABLE `" . $wpdb->prefix . "variation_values_associations` (\n\t\t`id` bigint(20) unsigned NOT NULL auto_increment,\n\t\t`product_id` bigint(20) unsigned NOT NULL default '0',\n\t\t`value_id` bigint(20) unsigned NOT NULL default '0',\n\t\t`quantity` int(11) NOT NULL default '0',\n\t\t`price` varchar(32) NOT NULL default '0',\n\t\t`visible` varchar(1) NOT NULL default '0',\n\t\t`variation_id` bigint(20) unsigned NOT NULL default '0',\n\t\tPRIMARY KEY  (`id`),\n\t\tKEY `product_id` (`product_id`,`value_id`,`variation_id`)\n\t) TYPE=MyISAM;\n\t";
    // Table structure for table `".$wpdb->prefix."wpsc_coupon_codes`
    $num++;
    $wpsc_tables[$num]['table_name'] = $wpdb->prefix . 'wpsc_coupon_codes';
    $wpsc_tables[$num]['table_sql'] = "CREATE TABLE `" . $wpdb->prefix . "wpsc_coupon_codes` (\n\t\t`id` bigint(20) unsigned NOT NULL auto_increment,\n\t\t`coupon_code` varchar(255) default NULL,\n\t\t`value` bigint(20) unsigned NOT NULL default '0',\n\t\t`is-percentage` char(1) NOT NULL default '0',\n\t\t`use-once` char(1) NOT NULL default '0',\n\t\t`is-used` char(1) NOT NULL default '0',\n\t\t`active` char(1) NOT NULL default '1',\n\t\t`every_product` varchar(255) NOT NULL,\n\t\t`start` datetime NOT NULL,\n\t\t`expiry` datetime NOT NULL,\n\t\tPRIMARY KEY  (`id`),\n\t\tKEY `coupon_code` (`coupon_code`),\n\t\tKEY `active` (`active`),\n\t\tKEY `start` (`start`),\n\t\tKEY `expiry` (`expiry`)\n\t) TYPE=MyISAM ;\n\t";
    // Table structure for table `".$wpdb->prefix."wpsc_logged_subscriptions`
    $num++;
    $wpsc_tables[$num]['table_name'] = $wpdb->prefix . 'wpsc_logged_subscriptions';
    $wpsc_tables[$num]['table_sql'] = "CREATE TABLE `" . $wpdb->prefix . "wpsc_logged_subscriptions` (\n\t\t`id` bigint(20) unsigned NOT NULL auto_increment,\n\t\t`cart_id` bigint(20) unsigned NOT NULL default '0',\n\t\t`user_id` bigint(20) unsigned NOT NULL default '0',\n\t\t`length` varchar(64) NOT NULL default '0',\n\t\t`start_time` varchar(64) NOT NULL default '0',\n\t\t`active` varchar(1) NOT NULL default '0',\n\t\tPRIMARY KEY  (`id`),\n\t\tKEY `cart_id` (`cart_id`),\n\t\tKEY `user_id` (`user_id`),\n\t\tKEY `start_time` (`start_time`)\n\t) TYPE=MyISAM;\n\t";
    // Table structure for table `".$wpdb->prefix."wpsc_productmeta`
    $num++;
    $wpsc_tables[$num]['table_name'] = $wpdb->prefix . 'wpsc_productmeta';
    $wpsc_tables[$num]['table_sql'] = "CREATE TABLE `" . $wpdb->prefix . "wpsc_productmeta` (\n\t\t`id` bigint(20) unsigned NOT NULL auto_increment,\n\t\t`product_id` bigint(20) unsigned NOT NULL default '0',\n\t\t`meta_key` varchar(255) default NULL,\n\t\t`meta_value` longtext,\n\t\tPRIMARY KEY  (`id`),\n\t\tKEY `product_id` (`product_id`),\n\t\tKEY `meta_key` (`meta_key`)\n\t) TYPE=MyISAM ;\n\t";
    $num++;
    $wpsc_tables[$num]['table_name'] = $wpdb->prefix . 'wpsc_categorisation_groups';
    $wpsc_tables[$num]['table_sql'] = "CREATE TABLE `" . $wpdb->prefix . "wpsc_categorisation_groups` (\n  `id` bigint(20) unsigned NOT NULL auto_increment,\n  `name` varchar(255) NOT NULL,\n  `description` text NOT NULL,\n  `active` varchar(1) NOT NULL default '1',\n  `default` varchar(1) NOT NULL default '0',\n  PRIMARY KEY  (`id`),\n  KEY `group_name` (`name`)\n) ENGINE=MyISAM ;\n\t";
    // and here is where the tables are added to the database, fairly simple, if it doesnt find the table, it makes it
    foreach ($wpsc_tables as $wpsc_table) {
        if (!$wpdb->get_var("SHOW TABLES LIKE '{$wpsc_table['table_name']}'")) {
            $wpdb->query($wpsc_table['table_sql']);
        }
    }
    wpsc_create_upload_directories();
    require dirname(__FILE__) . "/currency_list.php";
    /*
    Updates from old versions, 
    */
    if (get_option('wpsc_version') <= 3.5) {
        include_once 'updates/update-to-3.5.0.php';
    }
    //
    //   if((get_option('wpsc_version') < 3.5 ) || ((get_option('wpsc_version') == 3.5 ) && (get_option('wpsc_minor_version') <= 2))) {
    include_once 'updates/update-to-3.5.2.php';
    //     }
    include_once 'updates/update-to-3.5.2.php';
    include_once 'updates/update-to-3.6.0.php';
    include_once 'updates/update-to-3.6.4.php';
    /* all code to add new database tables and columns must be above here */
    if (get_option('wpsc_version') < WPSC_VERSION || get_option('wpsc_version') == WPSC_VERSION && get_option('wpsc_minor_version') < WPSC_MINOR_VERSION) {
        update_option('wpsc_version', WPSC_VERSION);
        update_option('wpsc_minor_version', WPSC_MINOR_VERSION);
    }
    $currency_data = $wpdb->get_var("SELECT COUNT(*) AS `count` FROM `" . $wpdb->prefix . "currency_list`");
    if ($currency_data == 0) {
        $currency_array = explode("\n", $currency_sql);
        foreach ($currency_array as $currency_row) {
            $wpdb->query($currency_row);
        }
    }
    $add_initial_category = $wpdb->get_results("SELECT COUNT(*) AS `count` FROM `" . $wpdb->prefix . "product_categories`;", ARRAY_A);
    if ($add_initial_category[0]['count'] == 0) {
        $wpdb->query("INSERT INTO `{$wpdb->prefix}wpsc_categorisation_groups` (`id`, `name`, `description`, `active`, `default`) VALUES (1, 'Categories', 'Product Categories', '1', '1')");
        $wpdb->query("INSERT INTO `{$wpdb->prefix}wpsc_categorisation_groups` (`id`, `name`, `description`, `active`, `default`) VALUES (2, 'Brands', 'Product Brands', '1', '0')");
        $wpdb->query("INSERT INTO `" . $wpdb->prefix . "product_categories` (`group_id`, `name` , `description`, `active`) VALUES ('1', '" . TXT_WPSC_EXAMPLECATEGORY . "', '" . TXT_WPSC_EXAMPLEDETAILS . "', '1');");
        $wpdb->query("INSERT INTO `" . $wpdb->prefix . "product_categories` (`group_id`, `name` , `description`, `active`) VALUES ('2', '" . TXT_WPSC_EXAMPLEBRAND . "', '" . TXT_WPSC_EXAMPLEDETAILS . "', '1');");
    }
    $purchase_statuses_data = $wpdb->get_results("SELECT COUNT(*) AS `count` FROM `" . $wpdb->prefix . "purchase_statuses`", ARRAY_A);
    if ($purchase_statuses_data[0]['count'] == 0) {
        $wpdb->query("INSERT INTO `" . $wpdb->prefix . "purchase_statuses` (`name` , `active` , `colour` ) \n    VALUES\n    ('" . TXT_WPSC_RECEIVED . "', '1', ''),\n    ('" . TXT_WPSC_ACCEPTED_PAYMENT . "', '1', ''),\n    ('" . TXT_WPSC_JOB_DISPATCHED . "', '1', ''),\n    ('" . TXT_WPSC_PROCESSED . "', '1', '');");
    }
    $check_category_assoc = $wpdb->get_results("SELECT COUNT(*) AS `count` FROM `" . $wpdb->prefix . "item_category_associations`;", ARRAY_A);
    if ($check_category_assoc[0]['count'] == 0) {
        $sql = "SELECT * FROM `" . $wpdb->prefix . "product_list` WHERE `active`=1";
        $product_list = $wpdb->get_results($sql, ARRAY_A);
        foreach ((array) $product_list as $product) {
            $results = $wpdb->query("INSERT INTO `" . $wpdb->prefix . "item_category_associations` (`product_id` , `category_id` ) VALUES ('" . $product['id'] . "', '" . $product['category'] . "');");
        }
    }
    $add_regions = $wpdb->get_var("SELECT COUNT(*) AS `count` FROM `" . $wpdb->prefix . "region_tax`");
    // exit($add_regions);
    if ($add_regions < 1) {
        $wpdb->query("INSERT INTO `" . $wpdb->prefix . "region_tax` ( `country_id` , `name` , `tax` ) VALUES ( '100', 'Alberta', '0.00')");
        $wpdb->query("INSERT INTO `" . $wpdb->prefix . "region_tax` ( `country_id` , `name` , `tax` ) VALUES ( '100', 'British Columbia', '0.00')");
        $wpdb->query("INSERT INTO `" . $wpdb->prefix . "region_tax` ( `country_id` , `name` , `tax` ) VALUES ( '100', 'Manitoba', '0.00')");
        $wpdb->query("INSERT INTO `" . $wpdb->prefix . "region_tax` ( `country_id` , `name` , `tax` ) VALUES ( '100', 'New Brunswick', '0.00')");
        $wpdb->query("INSERT INTO `" . $wpdb->prefix . "region_tax` ( `country_id` , `name` , `tax` ) VALUES ( '100', 'Newfoundland', '0.00')");
        $wpdb->query("INSERT INTO `" . $wpdb->prefix . "region_tax` ( `country_id` , `name` , `tax` ) VALUES ( '100', 'Northwest Territories', '0.00')");
        $wpdb->query("INSERT INTO `" . $wpdb->prefix . "region_tax` ( `country_id` , `name` , `tax` ) VALUES ( '100', 'Nova Scotia', '0.00')");
        $wpdb->query("INSERT INTO `" . $wpdb->prefix . "region_tax` ( `country_id` , `name` , `tax` ) VALUES ( '100', 'Nunavut', '0.00')");
        $wpdb->query("INSERT INTO `" . $wpdb->prefix . "region_tax` ( `country_id` , `name` , `tax` ) VALUES ( '100', 'Ontario', '0.00')");
        $wpdb->query("INSERT INTO `" . $wpdb->prefix . "region_tax` ( `country_id` , `name` , `tax` ) VALUES ( '100', 'Prince Edward Island', '0.00')");
        $wpdb->query("INSERT INTO `" . $wpdb->prefix . "region_tax` ( `country_id` , `name` , `tax` ) VALUES ( '100', 'Quebec', '0.00')");
        $wpdb->query("INSERT INTO `" . $wpdb->prefix . "region_tax` ( `country_id` , `name` , `tax` ) VALUES ( '100', 'Saskatchewan', '0.00')");
        $wpdb->query("INSERT INTO `" . $wpdb->prefix . "region_tax` ( `country_id` , `name` , `tax` ) VALUES ( '100', 'Yukon', '0.00')");
        $wpdb->query("INSERT INTO `" . $wpdb->prefix . "region_tax` ( `country_id` , `name` , `tax` ) VALUES ( '136', 'Alabama', '0.00')");
        $wpdb->query("INSERT INTO `" . $wpdb->prefix . "region_tax` ( `country_id` , `name` , `tax` ) VALUES ( '136', 'Alaska', '0.00')");
        $wpdb->query("INSERT INTO `" . $wpdb->prefix . "region_tax` ( `country_id` , `name` , `tax` ) VALUES ( '136', 'Arizona', '0.00')");
        $wpdb->query("INSERT INTO `" . $wpdb->prefix . "region_tax` ( `country_id` , `name` , `tax` ) VALUES ( '136', 'Arkansas', '0.00')");
        $wpdb->query("INSERT INTO `" . $wpdb->prefix . "region_tax` ( `country_id` , `name` , `tax` ) VALUES ( '136', 'California', '0.00')");
        $wpdb->query("INSERT INTO `" . $wpdb->prefix . "region_tax` ( `country_id` , `name` , `tax` ) VALUES ( '136', 'Colorado', '0.00')");
        $wpdb->query("INSERT INTO `" . $wpdb->prefix . "region_tax` ( `country_id` , `name` , `tax` ) VALUES ( '136', 'Connecticut', '0.00')");
        $wpdb->query("INSERT INTO `" . $wpdb->prefix . "region_tax` ( `country_id` , `name` , `tax` ) VALUES ( '136', 'Delaware', '0.00')");
        $wpdb->query("INSERT INTO `" . $wpdb->prefix . "region_tax` ( `country_id` , `name` , `tax` ) VALUES ( '136', 'Florida', '0.00')");
        $wpdb->query("INSERT INTO `" . $wpdb->prefix . "region_tax` ( `country_id` , `name` , `tax` ) VALUES ( '136', 'Georgia', '0.00')");
        $wpdb->query("INSERT INTO `" . $wpdb->prefix . "region_tax` ( `country_id` , `name` , `tax` ) VALUES ( '136', 'Hawaii', '0.00')");
        $wpdb->query("INSERT INTO `" . $wpdb->prefix . "region_tax` ( `country_id` , `name` , `tax` ) VALUES ( '136', 'Idaho', '0.00')");
        $wpdb->query("INSERT INTO `" . $wpdb->prefix . "region_tax` ( `country_id` , `name` , `tax` ) VALUES ( '136', 'Illinois', '0.00')");
        $wpdb->query("INSERT INTO `" . $wpdb->prefix . "region_tax` ( `country_id` , `name` , `tax` ) VALUES ( '136', 'Indiana', '0.00')");
        $wpdb->query("INSERT INTO `" . $wpdb->prefix . "region_tax` ( `country_id` , `name` , `tax` ) VALUES ( '136', 'Iowa', '0.00')");
        $wpdb->query("INSERT INTO `" . $wpdb->prefix . "region_tax` ( `country_id` , `name` , `tax` ) VALUES ( '136', 'Kansas', '0.00')");
        $wpdb->query("INSERT INTO `" . $wpdb->prefix . "region_tax` ( `country_id` , `name` , `tax` ) VALUES ( '136', 'Kentucky', '0.00')");
        $wpdb->query("INSERT INTO `" . $wpdb->prefix . "region_tax` ( `country_id` , `name` , `tax` ) VALUES ( '136', 'Louisiana', '0.00')");
        $wpdb->query("INSERT INTO `" . $wpdb->prefix . "region_tax` ( `country_id` , `name` , `tax` ) VALUES ( '136', 'Maine', '0.00')");
        $wpdb->query("INSERT INTO `" . $wpdb->prefix . "region_tax` ( `country_id` , `name` , `tax` ) VALUES ( '136', 'Maryland', '0.00')");
        $wpdb->query("INSERT INTO `" . $wpdb->prefix . "region_tax` ( `country_id` , `name` , `tax` ) VALUES ( '136', 'Massachusetts', '0.00')");
        $wpdb->query("INSERT INTO `" . $wpdb->prefix . "region_tax` ( `country_id` , `name` , `tax` ) VALUES ( '136', 'Michigan', '0.00')");
        $wpdb->query("INSERT INTO `" . $wpdb->prefix . "region_tax` ( `country_id` , `name` , `tax` ) VALUES ( '136', 'Minnesota', '0.00')");
        $wpdb->query("INSERT INTO `" . $wpdb->prefix . "region_tax` ( `country_id` , `name` , `tax` ) VALUES ( '136', 'Mississippi', '0.00')");
        $wpdb->query("INSERT INTO `" . $wpdb->prefix . "region_tax` ( `country_id` , `name` , `tax` ) VALUES ( '136', 'Missouri', '0.00')");
        $wpdb->query("INSERT INTO `" . $wpdb->prefix . "region_tax` ( `country_id` , `name` , `tax` ) VALUES ( '136', 'Montana', '0.00')");
        $wpdb->query("INSERT INTO `" . $wpdb->prefix . "region_tax` ( `country_id` , `name` , `tax` ) VALUES ( '136', 'Nebraska', '0.00')");
        $wpdb->query("INSERT INTO `" . $wpdb->prefix . "region_tax` ( `country_id` , `name` , `tax` ) VALUES ( '136', 'Nevada', '0.00')");
        $wpdb->query("INSERT INTO `" . $wpdb->prefix . "region_tax` ( `country_id` , `name` , `tax` ) VALUES ( '136', 'New Hampshire', '0.00')");
        $wpdb->query("INSERT INTO `" . $wpdb->prefix . "region_tax` ( `country_id` , `name` , `tax` ) VALUES ( '136', 'New Jersey', '0.00')");
        $wpdb->query("INSERT INTO `" . $wpdb->prefix . "region_tax` ( `country_id` , `name` , `tax` ) VALUES ( '136', 'New Mexico', '0.00')");
        $wpdb->query("INSERT INTO `" . $wpdb->prefix . "region_tax` ( `country_id` , `name` , `tax` ) VALUES ( '136', 'New York', '0.00')");
        $wpdb->query("INSERT INTO `" . $wpdb->prefix . "region_tax` ( `country_id` , `name` , `tax` ) VALUES ( '136', 'North Carolina', '0.00')");
        $wpdb->query("INSERT INTO `" . $wpdb->prefix . "region_tax` ( `country_id` , `name` , `tax` ) VALUES ( '136', 'North Dakota', '0.00')");
        $wpdb->query("INSERT INTO `" . $wpdb->prefix . "region_tax` ( `country_id` , `name` , `tax` ) VALUES ( '136', 'Ohio', '0.00')");
        $wpdb->query("INSERT INTO `" . $wpdb->prefix . "region_tax` ( `country_id` , `name` , `tax` ) VALUES ( '136', 'Oklahoma', '0.00')");
        $wpdb->query("INSERT INTO `" . $wpdb->prefix . "region_tax` ( `country_id` , `name` , `tax` ) VALUES ( '136', 'Oregon', '0.00')");
        $wpdb->query("INSERT INTO `" . $wpdb->prefix . "region_tax` ( `country_id` , `name` , `tax` ) VALUES ( '136', 'Pennsylvania', '0.00')");
        $wpdb->query("INSERT INTO `" . $wpdb->prefix . "region_tax` ( `country_id` , `name` , `tax` ) VALUES ( '136', 'Rhode Island', '0.00')");
        $wpdb->query("INSERT INTO `" . $wpdb->prefix . "region_tax` ( `country_id` , `name` , `tax` ) VALUES ( '136', 'South Carolina', '0.00')");
        $wpdb->query("INSERT INTO `" . $wpdb->prefix . "region_tax` ( `country_id` , `name` , `tax` ) VALUES ( '136', 'South Dakota', '0.00')");
        $wpdb->query("INSERT INTO `" . $wpdb->prefix . "region_tax` ( `country_id` , `name` , `tax` ) VALUES ( '136', 'Tennessee', '0.00')");
        $wpdb->query("INSERT INTO `" . $wpdb->prefix . "region_tax` ( `country_id` , `name` , `tax` ) VALUES ( '136', 'Texas', '0.00')");
        $wpdb->query("INSERT INTO `" . $wpdb->prefix . "region_tax` ( `country_id` , `name` , `tax` ) VALUES ( '136', 'Utah', '0.00')");
        $wpdb->query("INSERT INTO `" . $wpdb->prefix . "region_tax` ( `country_id` , `name` , `tax` ) VALUES ( '136', 'Vermont', '0.00')");
        $wpdb->query("INSERT INTO `" . $wpdb->prefix . "region_tax` ( `country_id` , `name` , `tax` ) VALUES ( '136', 'Virginia', '0.00')");
        $wpdb->query("INSERT INTO `" . $wpdb->prefix . "region_tax` ( `country_id` , `name` , `tax` ) VALUES ( '136', 'Washington', '0.00')");
        $wpdb->query("INSERT INTO `" . $wpdb->prefix . "region_tax` ( `country_id` , `name` , `tax` ) VALUES ( '136', 'Washington DC', '0.00')");
        $wpdb->query("INSERT INTO `" . $wpdb->prefix . "region_tax` ( `country_id` , `name` , `tax` ) VALUES ( '136', 'West Virginia', '0.00')");
        $wpdb->query("INSERT INTO `" . $wpdb->prefix . "region_tax` ( `country_id` , `name` , `tax` ) VALUES ( '136', 'Wisconsin', '0.00')");
        $wpdb->query("INSERT INTO `" . $wpdb->prefix . "region_tax` ( `country_id` , `name` , `tax` ) VALUES ( '136', 'Wyoming', '0.00')");
        $wpdb->query("UPDATE `" . $wpdb->prefix . "region_tax` SET `code` = 'AL' WHERE `name` IN('Alabama')LIMIT 1 ;");
        $wpdb->query("UPDATE `" . $wpdb->prefix . "region_tax` SET `code` = 'AK' WHERE `name` IN('Alaska') LIMIT 1 ;");
        $wpdb->query("UPDATE `" . $wpdb->prefix . "region_tax` SET `code` = 'AZ' WHERE `name` IN('Arizona') LIMIT 1 ;");
        $wpdb->query("UPDATE `" . $wpdb->prefix . "region_tax` SET `code` = 'AR' WHERE `name` IN('Arkansas') LIMIT 1 ;");
        $wpdb->query("UPDATE `" . $wpdb->prefix . "region_tax` SET `code` = 'CA' WHERE `name` IN('California') LIMIT 1 ;");
        $wpdb->query("UPDATE `" . $wpdb->prefix . "region_tax` SET `code` = 'CO' WHERE `name` IN('Colorado') LIMIT 1 ;");
        $wpdb->query("UPDATE `" . $wpdb->prefix . "region_tax` SET `code` = 'CT' WHERE `name` IN('Connecticut') LIMIT 1 ;");
        $wpdb->query("UPDATE `" . $wpdb->prefix . "region_tax` SET `code` = 'DE' WHERE `name` IN('Delaware') LIMIT 1 ;");
        $wpdb->query("UPDATE `" . $wpdb->prefix . "region_tax` SET `code` = 'FL' WHERE `name` IN('Florida') LIMIT 1 ;");
        $wpdb->query("UPDATE `" . $wpdb->prefix . "region_tax` SET `code` = 'GA' WHERE `name` IN('Georgia')  LIMIT 1 ;");
        $wpdb->query("UPDATE `" . $wpdb->prefix . "region_tax` SET `code` = 'HI' WHERE `name` IN('Hawaii')  LIMIT 1 ;");
        $wpdb->query("UPDATE `" . $wpdb->prefix . "region_tax` SET `code` = 'ID' WHERE`name` IN('Idaho')  LIMIT 1 ;");
        $wpdb->query("UPDATE `" . $wpdb->prefix . "region_tax` SET `code` = 'IL' WHERE `name` IN('Illinois')  LIMIT 1 ;");
        $wpdb->query("UPDATE `" . $wpdb->prefix . "region_tax` SET `code` = 'IN' WHERE `name` IN('Indiana')  LIMIT 1 ;");
        $wpdb->query("UPDATE `" . $wpdb->prefix . "region_tax` SET `code` = 'IA' WHERE `name` IN('Iowa')  LIMIT 1 ;");
        $wpdb->query("UPDATE `" . $wpdb->prefix . "region_tax` SET `code` = 'KS' WHERE `name` IN('Kansas')  LIMIT 1 ;");
        $wpdb->query("UPDATE `" . $wpdb->prefix . "region_tax` SET `code` = 'KY' WHERE `name` IN('Kentucky') LIMIT 1 ;");
        $wpdb->query("UPDATE `" . $wpdb->prefix . "region_tax` SET `code` = 'LA' WHERE `name` IN('Louisiana') LIMIT 1 ;");
        $wpdb->query("UPDATE `" . $wpdb->prefix . "region_tax` SET `code` = 'ME' WHERE `name` IN('Maine') LIMIT 1 ;");
        $wpdb->query("UPDATE `" . $wpdb->prefix . "region_tax` SET `code` = 'MD' WHERE `name` IN('Maryland') LIMIT 1 ;");
        $wpdb->query("UPDATE `" . $wpdb->prefix . "region_tax` SET `code` = 'MA' WHERE `name` IN('Massachusetts') LIMIT 1 ;");
        $wpdb->query("UPDATE `" . $wpdb->prefix . "region_tax` SET `code` = 'MI' WHERE `name` IN('Michigan') LIMIT 1 ;");
        $wpdb->query("UPDATE `" . $wpdb->prefix . "region_tax` SET `code` = 'MN' WHERE `name` IN('Minnesota') LIMIT 1 ;");
        $wpdb->query("UPDATE `" . $wpdb->prefix . "region_tax` SET `code` = 'MS' WHERE `name` IN('Mississippi') LIMIT 1 ;");
        $wpdb->query("UPDATE `" . $wpdb->prefix . "region_tax` SET `code` = 'MO' WHERE `name` IN('Missouri') LIMIT 1 ;");
        $wpdb->query("UPDATE `" . $wpdb->prefix . "region_tax` SET `code` = 'MT' WHERE `name` IN('Montana') LIMIT 1 ;");
        $wpdb->query("UPDATE `" . $wpdb->prefix . "region_tax` SET `code` = 'NE' WHERE `name` IN('Nebraska') LIMIT 1 ;");
        $wpdb->query("UPDATE `" . $wpdb->prefix . "region_tax` SET `code` = 'NV' WHERE `name` IN('Nevada') LIMIT 1 ;");
        $wpdb->query("UPDATE `" . $wpdb->prefix . "region_tax` SET `code` = 'NH' WHERE `name` IN('New Hampshire') LIMIT 1 ;");
        $wpdb->query("UPDATE `" . $wpdb->prefix . "region_tax` SET `code` = 'NJ' WHERE `name` IN('New Jersey') LIMIT 1 ;");
        $wpdb->query("UPDATE `" . $wpdb->prefix . "region_tax` SET `code` = 'NM' WHERE `name` IN('New Mexico') LIMIT 1 ;");
        $wpdb->query("UPDATE `" . $wpdb->prefix . "region_tax` SET `code` = 'NY' WHERE `name` IN('New York') LIMIT 1 ;");
        $wpdb->query("UPDATE `" . $wpdb->prefix . "region_tax` SET `code` = 'NC' WHERE `name` IN('North Carolina') LIMIT 1 ;");
        $wpdb->query("UPDATE `" . $wpdb->prefix . "region_tax` SET `code` = 'ND' WHERE `name` IN('North Dakota') LIMIT 1 ;");
        $wpdb->query("UPDATE `" . $wpdb->prefix . "region_tax` SET `code` = 'OH' WHERE `name` IN('Ohio') LIMIT 1 ;");
        $wpdb->query("UPDATE `" . $wpdb->prefix . "region_tax` SET `code` = 'OK' WHERE `name` IN('Oklahoma') LIMIT 1 ;");
        $wpdb->query("UPDATE `" . $wpdb->prefix . "region_tax` SET `code` = 'OR' WHERE `name` IN('Oregon') LIMIT 1 ;");
        $wpdb->query("UPDATE `" . $wpdb->prefix . "region_tax` SET `code` = 'PA' WHERE `name` IN('Pennsylvania') LIMIT 1 ;");
        $wpdb->query("UPDATE `" . $wpdb->prefix . "region_tax` SET `code` = 'RI' WHERE `name` IN('Rhode Island') LIMIT 1 ;");
        $wpdb->query("UPDATE `" . $wpdb->prefix . "region_tax` SET `code` = 'SC' WHERE `name` IN('South Carolina') LIMIT 1 ;");
        $wpdb->query("UPDATE `" . $wpdb->prefix . "region_tax` SET `code` = 'SD' WHERE `name` IN('South Dakota') LIMIT 1 ;");
        $wpdb->query("UPDATE `" . $wpdb->prefix . "region_tax` SET `code` = 'TN' WHERE `name` IN('Tennessee') LIMIT 1 ;");
        $wpdb->query("UPDATE `" . $wpdb->prefix . "region_tax` SET `code` = 'TX' WHERE `name` IN('Texas') LIMIT 1 ;");
        $wpdb->query("UPDATE `" . $wpdb->prefix . "region_tax` SET `code` = 'UT' WHERE `name` IN('Utah') LIMIT 1 ;");
        $wpdb->query("UPDATE `" . $wpdb->prefix . "region_tax` SET `code` = 'VT' WHERE `name` IN('Vermont') LIMIT 1 ;");
        $wpdb->query("UPDATE `" . $wpdb->prefix . "region_tax` SET `code` = 'VA' WHERE `name` IN('Virginia') LIMIT 1 ;");
        $wpdb->query("UPDATE `" . $wpdb->prefix . "region_tax` SET `code` = 'WA' WHERE `name` IN('Washington') LIMIT 1 ;");
        $wpdb->query("UPDATE `" . $wpdb->prefix . "region_tax` SET `code` = 'DC' WHERE `name` IN('Washington DC') LIMIT 1 ;");
        $wpdb->query("UPDATE `" . $wpdb->prefix . "region_tax` SET `code` = 'WV' WHERE `name` IN('West Virginia') LIMIT 1 ;");
        $wpdb->query("UPDATE `" . $wpdb->prefix . "region_tax` SET `code` = 'WI' WHERE `name` IN('Wisconsin') LIMIT 1 ;");
        $wpdb->query("UPDATE `" . $wpdb->prefix . "region_tax` SET `code` = 'WY' WHERE `name` IN('Wyoming') LIMIT 1 ;");
    }
    $data_forms = $wpdb->get_results("SELECT COUNT(*) AS `count` FROM `" . $wpdb->prefix . "collect_data_forms`", ARRAY_A);
    if ($data_forms[0]['count'] == 0) {
        $wpdb->query("INSERT INTO `" . $wpdb->prefix . "collect_data_forms` ( `name`, `type`, `mandatory`, `display_log`, `default`, `active`, `order`) VALUES ( '" . TXT_WPSC_YOUR_BILLING_CONTACT_DETAILS . "', 'heading', '0', '0', '', '1', 1),\n\t( '" . TXT_WPSC_FIRSTNAME . "', 'text', '1', '1', '', '1', 2),\n\t( '" . TXT_WPSC_LASTNAME . "', 'text', '1', '1', '', '1', 3),\n\t( '" . TXT_WPSC_ADDRESS . "', 'address', '1', '0', '', '1', 4),\n\t( '" . TXT_WPSC_CITY . "', 'city', '1', '0', '', '1', 5),\n\t( '" . TXT_WPSC_COUNTRY . "', 'country', '1', '0', '', '1', 7),\n\t( '" . TXT_WPSC_POSTAL_CODE . "', 'text', '0', '0', '', '1', 8),\n\t( '" . TXT_WPSC_EMAIL . "', 'email', '1', '1', '', '1', 9),\n\t( '" . TXT_WPSC_DELIVER_TO_A_FRIEND . "', 'heading', '0', '0', '', '1', 10),\n\t( '" . TXT_WPSC_FIRSTNAME . "', 'text', '0', '0', '', '1', 11),\n\t( '" . TXT_WPSC_LASTNAME . "', 'text', '0', '0', '', '1', 12),\n\t( '" . TXT_WPSC_ADDRESS . "', 'address', '0', '0', '', '1', 13),\n\t( '" . TXT_WPSC_CITY . "', 'city', '0', '0', '', '1', 14),\n\t( '" . TXT_WPSC_STATE . "', 'text', '0', '0', '', '1', 15),\n\t( '" . TXT_WPSC_COUNTRY . "', 'delivery_country', '0', '0', '', '1', 16),\n\t( '" . TXT_WPSC_POSTAL_CODE . "', 'text', '0', '0', '', '1', 17);");
        update_option('country_form_field', $country_form_id[0]['id']);
        update_option('email_form_field', $email_form_id[0]['id']);
        $wpdb->query("INSERT INTO `" . $wpdb->prefix . "collect_data_forms` ( `name`, `type`, `mandatory`, `display_log`, `default`, `active`, `order` ) VALUES ( '" . TXT_WPSC_PHONE . "', 'text', '1', '0', '', '1', '8');");
    }
    $product_brands_data = $wpdb->get_results("SELECT COUNT(*) AS `count` FROM `" . $wpdb->prefix . "product_brands`", ARRAY_A);
    if ($product_brands_data[0]['count'] == 0) {
        $wpdb->query("INSERT INTO `" . $wpdb->prefix . "product_brands` ( `name`, `description`, `active`, `order`) VALUES ( '" . TXT_WPSC_EXAMPLEBRAND . "','" . TXT_WPSC_EXAMPLEDETAILS . "', '1', '0');");
    }
    add_option('show_thumbnails', 1, TXT_WPSC_SHOWTHUMBNAILS, "yes");
    add_option('product_image_width', '', TXT_WPSC_PRODUCTIMAGEWIDTH, 'yes');
    add_option('product_image_height', '', TXT_WPSC_PRODUCTIMAGEHEIGHT, 'yes');
    add_option('category_image_width', '', TXT_WPSC_CATEGORYIMAGEWIDTH, 'yes');
    add_option('category_image_height', '', TXT_WPSC_CATEGORYIMAGEHEIGHT, 'yes');
    add_option('product_list_url', '', TXT_WPSC_PRODUCTLISTURL, 'yes');
    add_option('shopping_cart_url', '', TXT_WPSC_SHOPPINGCARTURL, 'yes');
    add_option('checkout_url', '', TXT_WPSC_CHECKOUTURL, 'yes');
    add_option('transact_url', '', TXT_WPSC_TRANSACTURL, 'yes');
    add_option('payment_gateway', '', TXT_WPSC_PAYMENTGATEWAY, 'yes');
    if (function_exists('register_sidebar')) {
        add_option('cart_location', '4', TXT_WPSC_CARTLOCATION, 'yes');
    } else {
        add_option('cart_location', '1', TXT_WPSC_CARTLOCATION, 'yes');
    }
    if (function_exists('register_sidebar')) {
        add_option('cart_location', '4', TXT_WPSC_CARTLOCATION, 'yes');
    } else {
        add_option('cart_location', '1', TXT_WPSC_CARTLOCATION, 'yes');
    }
    //add_option('show_categorybrands', '0', TXT_WPSC_SHOWCATEGORYBRANDS, 'yes');
    add_option('currency_type', '156', TXT_WPSC_CURRENCYTYPE, 'yes');
    add_option('currency_sign_location', '3', TXT_WPSC_CURRENCYSIGNLOCATION, 'yes');
    add_option('gst_rate', '1', TXT_WPSC_GSTRATE, 'yes');
    add_option('max_downloads', '1', TXT_WPSC_MAXDOWNLOADS, 'yes');
    add_option('display_pnp', '1', TXT_WPSC_DISPLAYPNP, 'yes');
    add_option('display_specials', '1', TXT_WPSC_DISPLAYSPECIALS, 'yes');
    add_option('do_not_use_shipping', '0', 'do_not_use_shipping', 'yes');
    add_option('postage_and_packaging', '0', TXT_WPSC_POSTAGEAND_PACKAGING, 'yes');
    add_option('purch_log_email', '', TXT_WPSC_PURCHLOGEMAIL, 'yes');
    add_option('return_email', '', TXT_WPSC_RETURNEMAIL, 'yes');
    add_option('terms_and_conditions', '', TXT_WPSC_TERMSANDCONDITIONS, 'yes');
    add_option('google_key', 'none', TXT_WPSC_GOOGLEMECHANTKEY, 'yes');
    add_option('google_id', 'none', TXT_WPSC_GOOGLEMECHANTID, 'yes');
    add_option('default_brand', 'none', TXT_WPSC_DEFAULTBRAND, 'yes');
    add_option('wpsc_default_category', 'none', TXT_WPSC_DEFAULTCATEGORY, 'yes');
    add_option('product_view', 'default', "", 'yes');
    add_option('add_plustax', 'default', "", '1');
    add_option('nzshpcrt_first_load', '0', "", 'yes');
    if (!(get_option('show_categorybrands') > 0 && get_option('show_categorybrands') < 3)) {
        update_option('show_categorybrands', 2);
    }
    //add_option('show_categorybrands', '0', TXT_WPSC_SHOWCATEGORYBRANDS, 'yes');
    /* PayPal options */
    add_option('paypal_business', '', TXT_WPSC_PAYPALBUSINESS, 'yes');
    add_option('paypal_url', '', TXT_WPSC_PAYPALURL, 'yes');
    //update_option('paypal_url', "https://www.sandbox.paypal.com/xclick");
    add_option('paypal_multiple_business', '', TXT_WPSC_PAYPALBUSINESS, 'yes');
    if (get_option('paypal_multiple_url') == null) {
        add_option('paypal_multiple_url', '', TXT_WPSC_PAYPALURL, 'yes');
        update_option('paypal_multiple_url', "https://www.paypal.com/cgi-bin/webscr");
    }
    add_option('product_ratings', '0', TXT_WPSC_SHOWPRODUCTRATINGS, 'yes');
    if (get_option('wpsc_selected_theme') == '') {
        add_option('wpsc_selected_theme', 'default', 'Selected Theme', 'yes');
        update_option('wpsc_selected_theme', "default");
    }
    if (!get_option('product_image_height')) {
        update_option('product_image_height', '96');
        update_option('product_image_width', '96');
    }
    if (!get_option('category_image_height')) {
        update_option('category_image_height', '96');
        update_option('category_image_width', '96');
    }
    if (!get_option('single_view_image_height')) {
        update_option('single_view_image_height', '128');
        update_option('single_view_image_width', '128');
    }
    wpsc_product_files_htaccess();
    /*
     * This part creates the pages and automatically puts their URLs into the options page.
     * As you can probably see, it is very easily extendable, just pop in your page and the deafult content in the array and you are good to go.
     */
    $post_date = date("Y-m-d H:i:s");
    $post_date_gmt = gmdate("Y-m-d H:i:s");
    $num = 0;
    $pages[$num]['name'] = 'products-page';
    $pages[$num]['title'] = TXT_WPSC_PRODUCTSPAGE;
    $pages[$num]['tag'] = '[productspage]';
    $pages[$num]['option'] = 'product_list_url';
    $num++;
    $pages[$num]['name'] = 'checkout';
    $pages[$num]['title'] = TXT_WPSC_CHECKOUT;
    $pages[$num]['tag'] = '[shoppingcart]';
    $pages[$num]['option'] = 'shopping_cart_url';
    //   $num++;
    //   $pages[$num]['name'] = 'enter-details';
    //   $pages[$num]['title'] = TXT_WPSC_ENTERDETAILS;
    //   $pages[$num]['tag'] = '[checkout]';
    //   $pages[2$num]['option'] = 'checkout_url';
    $num++;
    $pages[$num]['name'] = 'transaction-results';
    $pages[$num]['title'] = TXT_WPSC_TRANSACTIONRESULTS;
    $pages[$num]['tag'] = '[transactionresults]';
    $pages[$num]['option'] = 'transact_url';
    $num++;
    $pages[$num]['name'] = 'your-account';
    $pages[$num]['title'] = TXT_WPSC_YOUR_ACCOUNT;
    $pages[$num]['tag'] = '[userlog]';
    $pages[$num]['option'] = 'user_account_url';
    $newpages = false;
    $i = 0;
    $post_parent = 0;
    foreach ($pages as $page) {
        $check_page = $wpdb->get_row("SELECT * FROM `" . $wpdb->posts . "` WHERE `post_content` LIKE '%" . $page['tag'] . "%' LIMIT 1", ARRAY_A);
        if ($check_page == null) {
            if ($i == 0) {
                $post_parent = 0;
            } else {
                $post_parent = $first_id;
            }
            if ($wp_version >= 2.1) {
                $sql = "INSERT INTO " . $wpdb->posts . "\n        (post_author, post_date, post_date_gmt, post_content, post_content_filtered, post_title, post_excerpt,  post_status, comment_status, ping_status, post_password, post_name, to_ping, pinged, post_modified, post_modified_gmt, post_parent, menu_order, post_type)\n        VALUES\n        ('1', '{$post_date}', '{$post_date_gmt}', '" . $page['tag'] . "', '', '" . $page['title'] . "', '', 'publish', 'closed', 'closed', '', '" . $page['name'] . "', '', '', '{$post_date}', '{$post_date_gmt}', '{$post_parent}', '0', 'page')";
            } else {
                $sql = "INSERT INTO " . $wpdb->posts . "\n        (post_author, post_date, post_date_gmt, post_content, post_content_filtered, post_title, post_excerpt,  post_status, comment_status, ping_status, post_password, post_name, to_ping, pinged, post_modified, post_modified_gmt, post_parent, menu_order)\n        VALUES\n        ('1', '{$post_date}', '{$post_date_gmt}', '" . $page['tag'] . "', '', '" . $page['title'] . "', '', 'static', 'closed', 'closed', '', '" . $page['name'] . "', '', '', '{$post_date}', '{$post_date_gmt}', '{$post_parent}', '0')";
            }
            $wpdb->query($sql);
            $post_id = $wpdb->insert_id;
            if ($i == 0) {
                $first_id = $post_id;
            }
            $wpdb->query("UPDATE {$wpdb->posts} SET guid = '" . get_permalink($post_id) . "' WHERE ID = '{$post_id}'");
            update_option($page['option'], get_permalink($post_id));
            if ($page['option'] == 'shopping_cart_url') {
                update_option('checkout_url', get_permalink($post_id));
            }
            $newpages = true;
            $i++;
        }
    }
    if ($newpages == true) {
        wp_cache_delete('all_page_ids', 'pages');
        $wp_rewrite->flush_rules();
    }
    /* adds nice names for permalinks for products */
    $check_product_names = $wpdb->get_results("SELECT `" . $wpdb->prefix . "product_list`.`id`, `" . $wpdb->prefix . "product_list`.`name`, `" . $wpdb->prefix . "wpsc_productmeta`.`meta_key` FROM `" . $wpdb->prefix . "product_list` LEFT JOIN `" . $wpdb->prefix . "wpsc_productmeta` ON `" . $wpdb->prefix . "product_list`.`id` = `" . $wpdb->prefix . "wpsc_productmeta`.`product_id` WHERE (`" . $wpdb->prefix . "wpsc_productmeta`.`meta_key` IN ('url_name') AND  `" . $wpdb->prefix . "wpsc_productmeta`.`meta_value` IN (''))  OR ISNULL(`" . $wpdb->prefix . "wpsc_productmeta`.`meta_key`)");
    if ($check_product_names != null) {
        $sql_query = "SELECT `id`, `name` FROM `" . $wpdb->prefix . "product_list` WHERE `active` IN('1')";
        $sql_data = $wpdb->get_results($sql_query, ARRAY_A);
        foreach ((array) $sql_data as $datarow) {
            $tidied_name = trim($datarow['name']);
            $tidied_name = strtolower($tidied_name);
            $url_name = preg_replace(array("/(\\s)+/", "/[^\\w-]+/"), array("-", ''), $tidied_name);
            $similar_names = $wpdb->get_row("SELECT COUNT(*) AS `count`, MAX(REPLACE(`meta_value`, '{$url_name}', '')) AS `max_number` FROM `" . $wpdb->prefix . "wpsc_productmeta` WHERE `meta_key` LIKE 'url_name' AND `meta_value` REGEXP '^({$url_name}){1}(\\d)*\$' ", ARRAY_A);
            $extension_number = '';
            if ($similar_names['count'] > 0) {
                $extension_number = (int) $similar_names['max_number'] + 1;
            }
            if (get_product_meta($datarow['id'], 'url_name') != false) {
                $current_url_name = get_product_meta($datarow['id'], 'url_name');
                if ($current_url_name[0] != $url_name) {
                    $url_name .= $extension_number;
                    update_product_meta($datarow['id'], 'url_name', $url_name);
                }
            } else {
                $url_name .= $extension_number;
                add_product_meta($datarow['id'], 'url_name', $url_name, true);
            }
        }
    }
    /* adds nice names for permalinks for categories */
    $check_category_names = $wpdb->get_results("SELECT DISTINCT `nice-name` FROM `" . $wpdb->prefix . "product_categories` WHERE `nice-name` IN ('') AND `active` IN ('1')");
    if ($check_category_names != null) {
        $sql_query = "SELECT `id`, `name` FROM `" . $wpdb->prefix . "product_categories` WHERE `active` IN('1')";
        $sql_data = $wpdb->get_results($sql_query, ARRAY_A);
        foreach ((array) $sql_data as $datarow) {
            $tidied_name = trim($datarow['name']);
            $tidied_name = strtolower($tidied_name);
            $url_name = preg_replace(array("/(\\s)+/", "/[^\\w-]+/"), array("-", ''), $tidied_name);
            $similar_names = $wpdb->get_row("SELECT COUNT(*) AS `count`, MAX(REPLACE(`nice-name`, '{$url_name}', '')) AS `max_number` FROM `" . $wpdb->prefix . "product_categories` WHERE `nice-name` REGEXP '^({$url_name}){1}(\\d)*\$' ", ARRAY_A);
            $extension_number = '';
            if ($similar_names['count'] > 0) {
                $extension_number = (int) $similar_names['max_number'] + 1;
            }
            $url_name .= $extension_number;
            $wpdb->query("UPDATE `" . $wpdb->prefix . "product_categories` SET `nice-name` = '{$url_name}' WHERE `id` = '" . $datarow['id'] . "' LIMIT 1 ;");
        }
        $wp_rewrite->flush_rules();
    }
    /* Moves images to thumbnails directory */
    // this code should no longer be needed, as most people will be using a sufficiently new version
    $image_dir = WPSC_FILE_PATH . "/images/";
    $product_images = WPSC_IMAGE_DIR;
    $product_thumbnails = WPSC_THUMBNAIL_DIR;
    if (!is_dir($product_thumbnails)) {
        @mkdir($product_thumbnails, 0775);
    }
    $product_list = $wpdb->get_results("SELECT * FROM `" . $wpdb->prefix . "product_list` WHERE `image` != ''", ARRAY_A);
    foreach ((array) $product_list as $product) {
        if (!glob($product_thumbnails . $product['image'])) {
            $new_filename = $product['id'] . "_" . $product['image'];
            if (file_exists($image_dir . $product['image'])) {
                copy($image_dir . $product['image'], $product_thumbnails . $new_filename);
                if (file_exists($product_images . $product['image'])) {
                    copy($product_images . $product['image'], $product_images . $new_filename);
                }
                $wpdb->query("UPDATE `" . $wpdb->prefix . "product_list` SET `image` = '" . $new_filename . "' WHERE `id`='" . $product['id'] . "' LIMIT 1");
            } else {
                $imagedir = $product_thumbnails;
                $name = $new_filename;
                $new_image_path = $product_images . $product['image'];
                $imagepath = $product['image'];
                $height = get_option('product_image_height');
                $width = get_option('product_image_width');
                if (file_exists($product_images . $product['image'])) {
                    include "extra_image_processing.php";
                    copy($product_images . $product['image'], $product_images . $new_filename);
                    $wpdb->query("UPDATE `" . $wpdb->prefix . "product_list` SET `image` = '" . $new_filename . "' WHERE `id`='" . $product['id'] . "' LIMIT 1");
                }
            }
        }
    }
    // */
}
示例#8
0
function wpsc_install()
{
    global $wpdb, $user_level, $wp_rewrite, $wp_version;
    $table_name = $wpdb->prefix . "wpsc_product_list";
    $first_install = false;
    $result = mysql_list_tables(DB_NAME);
    $tables = array();
    while ($row = mysql_fetch_row($result)) {
        $tables[] = $row[0];
    }
    if (!in_array($table_name, $tables)) {
        $first_install = true;
        add_option('wpsc_purchaselogs_fixed', true);
    }
    if (get_option('wpsc_version') == null) {
        add_option('wpsc_version', WPSC_VERSION, 'wpsc_version', 'yes');
    }
    // run the create or update code here.
    wpsc_create_or_update_tables();
    wpsc_create_upload_directories();
    if (!wp_get_schedule("wpsc_hourly_cron_tasks")) {
        wp_schedule_event(time(), 'hourly', 'wpsc_hourly_cron_tasks');
    }
    if (!wp_get_schedule("wpsc_daily_cron_tasks")) {
        wp_schedule_event(time(), 'daily', 'wpsc_daily_cron_tasks');
    }
    //wp_get_schedule( $hook, $args )
    /* all code to add new database tables and columns must be above here */
    if (get_option('wpsc_version') < WPSC_VERSION || get_option('wpsc_version') == WPSC_VERSION && get_option('wpsc_minor_version') < WPSC_MINOR_VERSION) {
        update_option('wpsc_version', WPSC_VERSION);
        update_option('wpsc_minor_version', WPSC_MINOR_VERSION);
    }
    $add_initial_category = $wpdb->get_results("SELECT COUNT(*) AS `count` FROM `" . WPSC_TABLE_PRODUCT_CATEGORIES . "`;", ARRAY_A);
    if ($add_initial_category[0]['count'] == 0) {
        $wpdb->query("INSERT INTO `" . WPSC_TABLE_CATEGORISATION_GROUPS . "` (`id`, `name`, `description`, `active`, `default`) VALUES (1, 'Categories', 'Product Categories', '1', '1')");
        $wpdb->query("INSERT INTO `" . WPSC_TABLE_CATEGORISATION_GROUPS . "` (`id`, `name`, `description`, `active`, `default`) VALUES (2, 'Brands', 'Product Brands', '1', '0')");
        $wpdb->query("INSERT INTO `" . WPSC_TABLE_PRODUCT_CATEGORIES . "` (`group_id`, `name` , `description`, `active`) VALUES ('1', '" . __('Example category', 'wpsc') . "', '" . __('Example details', 'wpsc') . "', '1');");
        $wpdb->query("INSERT INTO `" . WPSC_TABLE_PRODUCT_CATEGORIES . "` (`group_id`, `name` , `description`, `active`) VALUES ('2', '" . __('Example Brand', 'wpsc') . "', '" . __('Example details', 'wpsc') . "', '1');");
    }
    $purchase_statuses_data = $wpdb->get_results("SELECT COUNT(*) AS `count` FROM `" . WPSC_TABLE_PURCHASE_STATUSES . "`", ARRAY_A);
    if ($purchase_statuses_data[0]['count'] == 0) {
        $wpdb->query("INSERT INTO `" . WPSC_TABLE_PURCHASE_STATUSES . "` (`name` , `active` , `colour` ) \r\n    VALUES\r\n    ('" . __('Order Received', 'wpsc') . "', '1', ''),\r\n    ('" . __('Accepted Payment', 'wpsc') . "', '1', ''),\r\n    ('" . __('Job Dispatched', 'wpsc') . "', '1', ''),\r\n    ('" . __('Closed Order', 'wpsc') . "', '1', '');");
    }
    $check_category_assoc = $wpdb->get_results("SELECT COUNT(*) AS `count` FROM `" . WPSC_TABLE_ITEM_CATEGORY_ASSOC . "`;", ARRAY_A);
    if ($check_category_assoc[0]['count'] == 0) {
        $sql = "SELECT * FROM `" . WPSC_TABLE_PRODUCT_LIST . "` WHERE `active`=1";
        $product_list = $wpdb->get_results($sql, ARRAY_A);
        foreach ((array) $product_list as $product) {
            $results = $wpdb->query("INSERT INTO `" . WPSC_TABLE_ITEM_CATEGORY_ASSOC . "` (`product_id` , `category_id` ) VALUES ('" . $product['id'] . "', '" . $product['category'] . "');");
        }
    }
    add_option('show_thumbnails', 1, __('Show Thumbnails', 'wpsc'), "yes");
    add_option('product_image_width', '', __('product image width', 'wpsc'), 'yes');
    add_option('product_image_height', '', __('product image height', 'wpsc'), 'yes');
    add_option('category_image_width', '', __('product group image width', 'wpsc'), 'yes');
    add_option('category_image_height', '', __('product group image height', 'wpsc'), 'yes');
    add_option('product_list_url', '', __('The location of the product list', 'wpsc'), 'yes');
    add_option('shopping_cart_url', '', __('The location of the shopping cart', 'wpsc'), 'yes');
    add_option('checkout_url', '', __('The location of the checkout page', 'wpsc'), 'yes');
    add_option('transact_url', '', __('The location of the transaction detail page', 'wpsc'), 'yes');
    add_option('payment_gateway', '', __('The payment gateway to use', 'wpsc'), 'yes');
    if (function_exists('register_sidebar')) {
        add_option('cart_location', '4', __('Cart Location', 'wpsc'), 'yes');
    } else {
        add_option('cart_location', '1', __('Cart Location', 'wpsc'), 'yes');
    }
    if (function_exists('register_sidebar')) {
        add_option('cart_location', '4', __('Cart Location', 'wpsc'), 'yes');
    } else {
        add_option('cart_location', '1', __('Cart Location', 'wpsc'), 'yes');
    }
    //add_option('show_categorybrands', '0', __('Display categories or brands or both', 'wpsc'), 'yes');
    add_option('currency_type', '156', __('Currency type', 'wpsc'), 'yes');
    add_option('currency_sign_location', '3', __('Currency sign location', 'wpsc'), 'yes');
    add_option('gst_rate', '1', __('the GST rate', 'wpsc'), 'yes');
    add_option('max_downloads', '1', __('the download limit', 'wpsc'), 'yes');
    add_option('display_pnp', '1', __('Display or hide postage and packaging', 'wpsc'), 'yes');
    add_option('display_specials', '1', __('Display or hide specials on the sidebar', 'wpsc'), 'yes');
    add_option('do_not_use_shipping', '1', 'do_not_use_shipping', 'no');
    add_option('postage_and_packaging', '0', __('Default postage and packaging', 'wpsc'), 'yes');
    add_option('purch_log_email', '', __('Email address that purchase log is sent to', 'wpsc'), 'yes');
    add_option('return_email', '', __('Email address that purchase reports are sent from', 'wpsc'), 'yes');
    add_option('terms_and_conditions', '', __('Checkout terms and conditions', 'wpsc'), 'yes');
    add_option('google_key', 'none', __('Google Merchant Key', 'wpsc'), 'yes');
    add_option('google_id', 'none', __('Google Merchant ID', 'wpsc'), 'yes');
    add_option('default_brand', 'none', __('Default Brand', 'wpsc'), 'yes');
    add_option('wpsc_default_category', 'all', __('Select what product group you want to display on the products page', 'wpsc'), 'yes');
    add_option('product_view', 'default', "", 'yes');
    add_option('add_plustax', 'default', "", '1');
    add_option('nzshpcrt_first_load', '0', "", 'yes');
    if (!(get_option('show_categorybrands') > 0 && get_option('show_categorybrands') < 3)) {
        update_option('show_categorybrands', 2);
    }
    //add_option('show_categorybrands', '0', __('Display categories or brands or both', 'wpsc'), 'yes');
    /* PayPal options */
    add_option('paypal_business', '', __('paypal business', 'wpsc'), 'yes');
    add_option('paypal_url', '', __('paypal url', 'wpsc'), 'yes');
    add_option('paypal_ipn', '1', __('paypal url', 'wpsc'), 'yes');
    //update_option('paypal_url', "https://www.sandbox.paypal.com/xclick");
    add_option('paypal_multiple_business', '', __('paypal business', 'wpsc'), 'yes');
    if (get_option('paypal_multiple_url') == null) {
        add_option('paypal_multiple_url', __('paypal url', 'wpsc'), 'yes');
        update_option('paypal_multiple_url', "https://www.paypal.com/cgi-bin/webscr");
    }
    add_option('product_ratings', '0', __('Show Product Ratings', 'wpsc'), 'yes');
    add_option('wpsc_email_receipt', __('Thank you for purchasing with %shop_name%, any items to be shipped will be processed as soon as possible, any items that can be downloaded can be downloaded using the links on this page.All prices include tax and postage and packaging where applicable.You ordered these items:%product_list%%total_shipping%%total_price%', 'wpsc'), 'yes');
    add_option('wpsc_email_admin', __('%product_list%%total_shipping%%total_price%', 'wpsc'), 'yes');
    if (get_option('wpsc_selected_theme') == '') {
        add_option('wpsc_selected_theme', 'default', 'Selected Theme', 'yes');
        update_option('wpsc_selected_theme', "default");
    }
    if (!get_option('product_image_height')) {
        update_option('product_image_height', '96');
        update_option('product_image_width', '96');
    }
    if (!get_option('category_image_height')) {
        update_option('category_image_height', '96');
        update_option('category_image_width', '96');
    }
    if (!get_option('single_view_image_height')) {
        update_option('single_view_image_height', '128');
        update_option('single_view_image_width', '128');
    }
    if (!get_option('wpsc_gallery_image_height')) {
        update_option('wpsc_gallery_image_height', '96');
        update_option('wpsc_gallery_image_width', '96');
    }
    if (!is_array(get_option('custom_gateway_options'))) {
        update_option('custom_gateway_options', array('testmode'));
    }
    add_option("wpsc_category_url_cache", array(), '', 'yes');
    wpsc_product_files_htaccess();
    /*
     * This part creates the pages and automatically puts their URLs into the options page.
     * As you can probably see, it is very easily extendable, just pop in your page and the deafult content in the array and you are good to go.
     */
    $post_date = date("Y-m-d H:i:s");
    $post_date_gmt = gmdate("Y-m-d H:i:s");
    $num = 0;
    $pages[$num]['name'] = 'products-page';
    $pages[$num]['title'] = __('Products Page', 'wpsc');
    $pages[$num]['tag'] = '[productspage]';
    $pages[$num]['option'] = 'product_list_url';
    $num++;
    $pages[$num]['name'] = 'checkout';
    $pages[$num]['title'] = __('Checkout', 'wpsc');
    $pages[$num]['tag'] = '[shoppingcart]';
    $pages[$num]['option'] = 'shopping_cart_url';
    //   $num++;
    //   $pages[$num]['name'] = 'enter-details';
    //   $pages[$num]['title'] = __('Enter Your Details', 'wpsc');
    //   $pages[$num]['tag'] = '[checkout]';
    //   $pages[2$num]['option'] = 'checkout_url';
    $num++;
    $pages[$num]['name'] = 'transaction-results';
    $pages[$num]['title'] = __('Transaction Results', 'wpsc');
    $pages[$num]['tag'] = '[transactionresults]';
    $pages[$num]['option'] = 'transact_url';
    $num++;
    $pages[$num]['name'] = 'your-account';
    $pages[$num]['title'] = __('Your Account', 'wpsc');
    $pages[$num]['tag'] = '[userlog]';
    $pages[$num]['option'] = 'user_account_url';
    $newpages = false;
    $i = 0;
    $post_parent = 0;
    foreach ($pages as $page) {
        $check_page = $wpdb->get_row("SELECT * FROM `" . $wpdb->posts . "` WHERE `post_content` LIKE '%" . $page['tag'] . "%'  AND `post_type` NOT IN('revision') LIMIT 1", ARRAY_A);
        if ($check_page == null) {
            if ($i == 0) {
                $post_parent = 0;
            } else {
                $post_parent = $first_id;
            }
            if ($wp_version >= 2.1) {
                $sql = "INSERT INTO " . $wpdb->posts . "\r\n        (post_author, post_date, post_date_gmt, post_content, post_content_filtered, post_title, post_excerpt,  post_status, comment_status, ping_status, post_password, post_name, to_ping, pinged, post_modified, post_modified_gmt, post_parent, menu_order, post_type)\r\n        VALUES\r\n        ('1', '{$post_date}', '{$post_date_gmt}', '" . $page['tag'] . "', '', '" . $page['title'] . "', '', 'publish', 'closed', 'closed', '', '" . $page['name'] . "', '', '', '{$post_date}', '{$post_date_gmt}', '{$post_parent}', '0', 'page')";
            } else {
                $sql = "INSERT INTO " . $wpdb->posts . "\r\n        (post_author, post_date, post_date_gmt, post_content, post_content_filtered, post_title, post_excerpt,  post_status, comment_status, ping_status, post_password, post_name, to_ping, pinged, post_modified, post_modified_gmt, post_parent, menu_order)\r\n        VALUES\r\n        ('1', '{$post_date}', '{$post_date_gmt}', '" . $page['tag'] . "', '', '" . $page['title'] . "', '', 'static', 'closed', 'closed', '', '" . $page['name'] . "', '', '', '{$post_date}', '{$post_date_gmt}', '{$post_parent}', '0')";
            }
            $wpdb->query($sql);
            $post_id = $wpdb->insert_id;
            if ($i == 0) {
                $first_id = $post_id;
            }
            $wpdb->query("UPDATE {$wpdb->posts} SET guid = '" . get_permalink($post_id) . "' WHERE ID = '{$post_id}'");
            update_option($page['option'], get_permalink($post_id));
            if ($page['option'] == 'shopping_cart_url') {
                update_option('checkout_url', get_permalink($post_id));
            }
            $newpages = true;
            $i++;
        }
    }
    if ($newpages == true) {
        wp_cache_delete('all_page_ids', 'pages');
        $wp_rewrite->flush_rules();
    }
    /* adds nice names for permalinks for products */
    $check_product_names = $wpdb->get_results("SELECT `" . WPSC_TABLE_PRODUCT_LIST . "`.`id`, `" . WPSC_TABLE_PRODUCT_LIST . "`.`name`, `" . WPSC_TABLE_PRODUCTMETA . "`.`meta_key` FROM `" . WPSC_TABLE_PRODUCT_LIST . "` LEFT JOIN `" . WPSC_TABLE_PRODUCTMETA . "` ON `" . WPSC_TABLE_PRODUCT_LIST . "`.`id` = `" . WPSC_TABLE_PRODUCTMETA . "`.`product_id` WHERE (`" . WPSC_TABLE_PRODUCTMETA . "`.`meta_key` IN ('url_name') AND  `" . WPSC_TABLE_PRODUCTMETA . "`.`meta_value` IN (''))  OR ISNULL(`" . WPSC_TABLE_PRODUCTMETA . "`.`meta_key`)", ARRAY_A);
    if ($check_product_names != null) {
        foreach ((array) $check_product_names as $datarow) {
            $tidied_name = trim($datarow['name']);
            $tidied_name = strtolower($tidied_name);
            $url_name = sanitize_title($tidied_name);
            $similar_names = $wpdb->get_row("SELECT COUNT(*) AS `count`, MAX(REPLACE(`meta_value`, '{$url_name}', '')) AS `max_number` FROM `" . WPSC_TABLE_PRODUCTMETA . "` WHERE `meta_key` LIKE 'url_name' AND `meta_value` REGEXP '^({$url_name}){1}(\\d)*\$' ", ARRAY_A);
            $extension_number = '';
            if ($similar_names['count'] > 0) {
                $extension_number = (int) $similar_names['max_number'] + 1;
            }
            if (get_product_meta($datarow['id'], 'url_name') != false) {
                $current_url_name = get_product_meta($datarow['id'], 'url_name');
                if ($current_url_name != $url_name) {
                    $url_name .= $extension_number;
                    update_product_meta($datarow['id'], 'url_name', $url_name);
                }
            } else {
                $url_name .= $extension_number;
                add_product_meta($datarow['id'], 'url_name', $url_name, true);
            }
        }
    }
    /* adds nice names for permalinks for categories */
    $check_category_names = $wpdb->get_results("SELECT DISTINCT `nice-name` FROM `" . WPSC_TABLE_PRODUCT_CATEGORIES . "` WHERE `nice-name` IN ('') AND `active` IN ('1')");
    if ($check_category_names != null) {
        $sql_query = "SELECT `id`, `name` FROM `" . WPSC_TABLE_PRODUCT_CATEGORIES . "` WHERE `active` IN('1')";
        $sql_data = $wpdb->get_results($sql_query, ARRAY_A);
        foreach ((array) $sql_data as $datarow) {
            $tidied_name = trim($datarow['name']);
            $tidied_name = strtolower($tidied_name);
            $url_name = sanitize_title($tidied_name);
            $similar_names = $wpdb->get_row("SELECT COUNT(*) AS `count`, MAX(REPLACE(`nice-name`, '{$url_name}', '')) AS `max_number` FROM `" . WPSC_TABLE_PRODUCT_CATEGORIES . "` WHERE `nice-name` REGEXP '^({$url_name}){1}(\\d)*\$' ", ARRAY_A);
            $extension_number = '';
            if ($similar_names['count'] > 0) {
                $extension_number = (int) $similar_names['max_number'] + 1;
            }
            $url_name .= $extension_number;
            $wpdb->query("UPDATE `" . WPSC_TABLE_PRODUCT_CATEGORIES . "` SET `nice-name` = '{$url_name}' WHERE `id` = '" . $datarow['id'] . "' LIMIT 1 ;");
        }
        $wp_rewrite->flush_rules();
    }
    /* Moves images to thumbnails directory */
    // this code should no longer be needed, as most people will be using a sufficiently new version
    $image_dir = WPSC_FILE_PATH . "/images/";
    $product_images = WPSC_IMAGE_DIR;
    $product_thumbnails = WPSC_THUMBNAIL_DIR;
    if (!is_dir($product_thumbnails)) {
        @mkdir($product_thumbnails, 0775);
    }
    $product_list = $wpdb->get_results("SELECT * FROM `" . WPSC_TABLE_PRODUCT_LIST . "` WHERE `image` != ''", ARRAY_A);
    foreach ((array) $product_list as $product) {
        if (!glob($product_thumbnails . $product['image'])) {
            $new_filename = $product['id'] . "_" . $product['image'];
            if (file_exists($image_dir . $product['image'])) {
                copy($image_dir . $product['image'], $product_thumbnails . $new_filename);
                if (file_exists($product_images . $product['image'])) {
                    copy($product_images . $product['image'], $product_images . $new_filename);
                }
                $wpdb->query("UPDATE `" . WPSC_TABLE_PRODUCT_LIST . "` SET `image` = '" . $new_filename . "' WHERE `id`='" . $product['id'] . "' LIMIT 1");
            } else {
                $imagedir = $product_thumbnails;
                $name = $new_filename;
                $new_image_path = $product_images . $product['image'];
                $imagepath = $product['image'];
                $height = get_option('product_image_height');
                $width = get_option('product_image_width');
                if (file_exists($product_images . $product['image'])) {
                    include "extra_image_processing.php";
                    copy($product_images . $product['image'], $product_images . $new_filename);
                    $wpdb->query("UPDATE `" . WPSC_TABLE_PRODUCT_LIST . "` SET `image` = '" . $new_filename . "' WHERE `id`='" . $product['id'] . "' LIMIT 1");
                }
            }
        }
    }
    // */
}