Exemplo n.º 1
1
function nzshpcrt_specials($input = null)
{
    global $wpdb;
    $image_width = get_option('product_image_width');
    $image_height = get_option('product_image_height');
    $siteurl = get_option('siteurl');
    $sql = "SELECT * FROM `" . WPSC_TABLE_PRODUCT_LIST . "` WHERE `special_price` != '0.00'  AND `active` IN ('1') ORDER BY RAND() LIMIT 1";
    $product = $wpdb->get_results($sql, ARRAY_A);
    if ($product != null) {
        $output = "<div>";
        foreach ($product as $special) {
            $special['name'] = htmlentities(stripslashes($special['name']), ENT_QUOTES, "UTF-8");
            $output .= "<strong><a class='wpsc_product_title' href='" . wpsc_product_url($special['id'], $special['category']) . "'>" . $special['name'] . "</a></strong><br /> ";
            if (is_numeric($special['image'])) {
                $image_file_name = $wpdb->get_var("SELECT `image` FROM `" . WPSC_TABLE_PRODUCT_IMAGES . "` WHERE `id`= '" . $special['image'] . "' LIMIT 1");
                if ($image_file_name != '') {
                    $image_path = "index.php?productid=" . $special['id'] . "&amp;width=" . $image_width . "&amp;height=" . $image_height . "";
                    $output .= "<img src='" . $image_path . "' title='" . $special['name'] . "' alt='" . $special['name'] . "' /><br />";
                }
            }
            //exit('Widget specisl'.get_option('wpsc_special_description'));
            if (get_option('wpsc_special_description') != '1') {
                $output .= $special['description'] . "<br />";
            }
            $variations_processor = new nzshpcrt_variations();
            $variations_output = $variations_processor->display_product_variations($special['id'], true, false, true);
            $output .= $variations_output[0];
            if ($variations_output[1] !== null) {
                $special['price'] = $variations_output[1];
                $special['special_price'] = 0;
            }
            if ($variations_output[1] == null) {
                $output .= "<span class='oldprice'>" . nzshpcrt_currency_display($special['price'], $special['notax'], false) . "</span><br />";
            }
            $output .= "<span id='special_product_price_" . $special['id'] . "'><span class='pricedisplay'>";
            $output .= nzshpcrt_currency_display($special['price'] - $special['special_price'], $special['notax'], false, $product['id']);
            $output .= "</span></span><br />";
            $output .= "<form id='specials_" . $special['id'] . "' method='post' action='' onsubmit='submitform(this, null);return false;' >";
            $output .= "<input type='hidden' name='product_id' value='" . $special['id'] . "'/>";
            $output .= "<input type='hidden' name='item' value='" . $special['id'] . "' />";
            $output .= "<input type='hidden' name='wpsc_ajax_action' value='special_widget' />";
            if ($special['quantity_limited'] == 1 && $special['quantity'] < 1) {
                $output .= TXT_WPSC_PRODUCTSOLDOUT . "";
            } else {
                //$output .= $variations_processor->display_product_variations($special['id'],true);
                $output .= "<input type='submit' name='" . TXT_WPSC_ADDTOCART . "' value='" . TXT_WPSC_ADDTOCART . "'  />";
            }
            $output .= "</form>";
        }
        $output .= "</div>";
    } else {
        $output = '';
    }
    echo $input . $output;
}
Exemplo n.º 2
1
 function display_product_extras($product_id, $no_label = false, $no_br = false, $update_price = false)
 {
     global $wpdb;
     $output = '';
     $sql = "SELECT * FROM `" . $wpdb->prefix . "product_list` WHERE `id`='" . $product_id . "' LIMIT 1";
     $product_data = $wpdb->get_row($sql, ARRAY_A);
     $extras_assoc_sql = "SELECT * FROM `" . $wpdb->prefix . "extras_values_associations` WHERE product_id IN ('{$product_id}')";
     $extras_assoc_data = $wpdb->get_results($extras_assoc_sql, ARRAY_A);
     if (count($extras_assoc_data) == 0) {
         return '';
     }
     foreach ($extras_assoc_data as $extras_association) {
         $extras_ids[] = $extras_association['extras_id'];
     }
     //echo
     $special = 'false';
     if ($no_label == true) {
         $special = 'true';
     }
     $extras_ids_str = implode(',', $extras_ids);
     $extras_name_sql = "SELECT * FROM " . $wpdb->prefix . "product_extra WHERE id IN (" . $extras_ids_str . ") ORDER BY id";
     $extras_name_data = $wpdb->get_results($extras_name_sql, ARRAY_A);
     //exit("<pre>".print_r($extras_name_data,1)."</pre>");
     $j = 0;
     $x = 0;
     foreach ($extras_name_data as $extras_name_datum) {
         $j++;
         $extras_value_sql = "SELECT * FROM " . $wpdb->prefix . "extras_values WHERE extras_id IN (" . $extras_name_datum['id'] . ")";
         $extras_value_data = $wpdb->get_results($extras_value_sql, ARRAY_A);
         //exit("<pre>".print_r($extras_value_data,1)."</pre>");
         $output .= "<label>" . $extras_name_datum['name'] . "</label>" . $extras_name_datum['price'] . "<br>";
         if ($j == 1) {
             $price = '';
             $checked = 'checked="checked"';
         } else {
             $price = nzshpcrt_currency_display($extras_assoc_data[$x]['price'], 0);
             $checked = '';
         }
         foreach ($extras_value_data as $extras_value_datum) {
             if ($j == 1) {
                 $price = '';
             } else {
                 $price = nzshpcrt_currency_display($extras_assoc_data[$x]['price'], 0);
             }
             $output .= "<input style='float:left;' type='checkbox' {$checked} name='extras[]' value='" . $extras_value_datum['id'] . "' class='extras_" . $product_id . "' id='extras_" . $product_id . "_" . $extras_value_datum['id'] . "' onclick='manage_extras(" . $product_id . "," . $extras_value_datum['id'] . "," . $special . ")' id='extra_value_id_" . $extras_value_datum['id'] . "'><label style='float:left;' for='extras_" . $product_id . "_" . $extras_value_datum['id'] . "'>" . $extras_value_datum['name'] . "&ensp;" . $price . "</label><img style='display:none;float:left;' id='extras_indicator" . $product_id . $extras_value_datum['id'] . "' src=' " . WPSC_DIR_NAME . "/images/indicator.gif'><br>";
             $x++;
         }
     }
     return $output;
 }
Exemplo n.º 3
0
 function wpsc_grid_title_and_price(&$product)
 {
     $output .= "<div class='grid_price'>";
     if ($soldout) {
         $output .= "<span class='soldoutgrid'>Sold out</span>";
     } else {
         if ($product['special'] == 1) {
             $output .= nzshpcrt_currency_display($product['price'] - $product['special_price'], $product['notax'], false, $product['id']) . "\n\r";
         } else {
             $output .= nzshpcrt_currency_display($product['price'], $product['notax']) . "\n\r";
         }
     }
     $output .= "</div>";
     $output .= "<div class='grid_prodcut_title'><a href='" . wpsc_product_url($product['id']) . "'>" . stripslashes($product['name']) . "</a></div>";
     return $output;
 }
Exemplo n.º 4
0
function nzshpcrt_specials($input = null)
{
    global $wpdb;
    $siteurl = get_option('siteurl');
    $sql = "SELECT * FROM `" . $wpdb->prefix . "product_list` WHERE `special` = '1'  ORDER BY RAND() LIMIT 1";
    $product = $wpdb->get_results($sql, ARRAY_A);
    if ($product != null) {
        $output = "<div><div>";
        foreach ($product as $special) {
            $output .= "<strong>" . $special['name'] . "</strong><br /> ";
            if ($special['image'] != null) {
                $output .= "<img src='{$siteurl}/wp-content/plugins/wp-shopping-cart/product_images/thumbnails/" . $special['image'] . "' title='" . $special['name'] . "' alt='" . $special['name'] . "' /><br />";
            }
            $output .= $special['description'] . "<br />";
            //       $output .= $special['price'];
            $variations_processor = new nzshpcrt_variations();
            $variations_output = $variations_processor->display_product_variations($special['id'], true, false, true);
            $output .= $variations_output[0];
            if ($variations_output[1] !== null) {
                $special['price'] = $variations_output[1];
            }
            if ($variations_output[1] == null) {
                $output .= "<span class='oldprice'>" . nzshpcrt_currency_display($special['price'], $special['notax'], false) . "</span><br />";
            }
            $output .= "<span id='special_product_price_" . $special['id'] . "'><span class='pricedisplay'>";
            $output .= nzshpcrt_currency_display($special['price'] - $special['special_price'], $special['notax'], false, $product['id']);
            $output .= "</span></span><br />";
            $output .= "<form id='specials_" . $special['id'] . "' name='{$num}' method='post' action='#' onsubmit='submitform(this);return false;' >";
            $output .= "<input type='hidden' name='prodid' value='" . $special['id'] . "'/>";
            $output .= "<input type='hidden' name='item' value='" . $special['id'] . "' />";
            if ($special['quantity_limited'] == 1 && $special['quantity'] < 1) {
                $output .= TXT_WPSC_PRODUCTSOLDOUT . "";
            } else {
                //$output .= $variations_processor->display_product_variations($special['id'],true);
                $output .= "<input type='submit' name='" . TXT_WPSC_ADDTOCART . "' value='" . TXT_WPSC_ADDTOCART . "'  />";
            }
            $output .= "</form>";
        }
        $output .= "</div></div>";
    } else {
        $output = '';
    }
    echo $input . $output;
}
function nzshpcrt_price_range($input = null)
{
    global $wpdb;
    $siteurl = get_option('siteurl');
    $product_page = get_option("product_list_url");
    if (stristr($product_page, "?")) {
        $seperater = '&';
    } else {
        $seperater = '?';
    }
    $result = $wpdb->get_results("SELECT DISTINCT `price` FROM " . WPSC_TABLE_PRODUCT_LIST . " WHERE `active` IN ('1') ORDER BY price ASC", ARRAY_A);
    if ($result != null) {
        sort($result);
        $count = count($result);
        $price_seperater = ceil($count / 6);
        for ($i = 0; $i < $count; $i += $price_seperater) {
            $ranges[] = round($result[$i]['price'], -1);
        }
        $ranges = array_unique($ranges);
        $final_count = count($ranges);
        $ranges = array_merge(array(), $ranges);
        $_SESSION['price_range'] = $ranges;
        //	echo('<pre>'.print_r($ranges, true).'</pre>');
        for ($i = 0; $i < $final_count; $i++) {
            $j = $i;
            if ($i == $final_count - 1) {
                echo "<a href='" . htmlentities($product_page . $seperater . "range=" . $j) . "'>Over " . nzshpcrt_currency_display($ranges[$i], 1, true) . "</a><br/>";
            } else {
                if ($ranges[$i] == 0) {
                    echo "<a href='" . htmlentities($product_page . $seperater . "range=" . $j) . "'>Under " . nzshpcrt_currency_display($ranges[$i + 1], 1, true) . "</a><br/>";
                } else {
                    echo "<a href='" . htmlentities($product_page . $seperater . "range=" . $j) . "'>" . nzshpcrt_currency_display($ranges[$i], 1, true) . " - " . nzshpcrt_currency_display($ranges[$i + 1], 1, true) . "</a><br/>";
                }
            }
        }
        if (get_option('permalink_structure') != '') {
            $seperator = "?";
        } else {
            $seperator = "&amp;";
        }
        echo "<a href='" . get_option("product_list_url") . $seperator . "range=all'>" . __('Show All', 'wpsc') . "</a><br/>";
    }
}
function transaction_results($sessionid, $echo_to_screen = true, $transaction_id = null)
{
    global $wpdb, $wpsc_cart, $wpsc_shipping_modules;
    echo $sessionid;
    //$curgateway = get_option('payment_gateway');
    $curgateway = $wpdb->get_var("SELECT gateway FROM " . WPSC_TABLE_PURCHASE_LOGS . " WHERE sessionid='{$sessionid}'");
    $errorcode = 0;
    $order_status = 2;
    /*
     * {Notes} Double check that $Echo_To_Screen is a boolean value
     */
    $echo_to_screen = !is_bool($echo_to_screen) ? true : $echo_to_screen;
    //exit('triggered but with errors?'.$echo_to_screen);
    if (is_numeric($sessionid)) {
        if ($echo_to_screen) {
            echo apply_filters('wpsc_pre_transaction_results', '');
        }
        $purchase_log = $wpdb->get_row("SELECT * FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE `sessionid`= " . $sessionid . " LIMIT 1", ARRAY_A);
        $thepurchlogitem = new wpsc_purchaselogs_items((int) $purchase_log['id']);
        if ($purchase_log['gateway'] == "testmode" && $purchase_log['processed'] < 2) {
            $message = stripslashes(get_option('wpsc_email_receipt'));
            $message_html = $message;
        } else {
            $message = stripslashes(get_option('wpsc_email_receipt'));
            $message_html = $message;
        }
        $order_url = site_url("/wp-admin/admin.php?page=" . WPSC_DIR_NAME . "/display-log.php&amp;purchcaseid=" . $purchase_log['id']);
        if ($_GET['ipn_request'] != 'true' and get_option('paypal_ipn') == 1) {
            if ($purchase_log == null) {
                echo __('We&#39;re Sorry, your order has not been accepted, the most likely reason is that you have insufficient funds.', 'wpsc');
                if (get_option('purch_log_email') != null && $purchase_log['email_sent'] != 1) {
                    wp_mail(get_option('purch_log_email'), __('New pending order', 'wpsc'), __('There is a new order awaiting processing:', 'wpsc') . $order_url, "From: " . get_option('return_email') . "");
                }
                return false;
            } else {
                if ($purchase_log['processed'] < 2) {
                    //added by Thomas on 20/6/2007
                    echo __('Thank you, your purchase is pending, you will be sent an email once the order clears.', 'wpsc') . "<p style='margin: 1em 0px 0px 0px;' >" . nl2br(stripslashes(get_option('payment_instructions'))) . "</p>";
                    /*if($purchase_log['gateway'] != 'testmode') {
                    			if((get_option('purch_log_email') != null) && ($purchase_log['email_sent'] != 1)) {
                    				mail(get_option('purch_log_email'), __('New pending order', 'wpsc'), __('There is a new order awaiting processing:', 'wpsc').$order_url, "From: ".get_option('return_email')."");
                    			}
                    			return false;
                    		}*/
                }
            }
        }
        if (isset($_GET['ssl_result_message']) && $_GET['ssl_result_message'] == 'APPROVAL') {
            $order_status = 2;
            $purchase_log['processed'] = 2;
        }
        $cart = $wpdb->get_results("SELECT * FROM `" . WPSC_TABLE_CART_CONTENTS . "` WHERE `purchaseid`='{$purchase_log['id']}'", ARRAY_A);
        if ($purchase_log['shipping_country'] != '') {
            $billing_country = $purchase_log['billing_country'];
            $shipping_country = $purchase_log['shipping_country'];
        } else {
            $country = $wpdb->get_var("SELECT `value` FROM `" . WPSC_TABLE_SUBMITED_FORM_DATA . "` WHERE `log_id`=" . $purchase_log['id'] . " AND `form_id` = '" . get_option('country_form_field') . "' LIMIT 1");
            $billing_country = $country;
            $shipping_country = $country;
        }
        $email_form_field = $wpdb->get_results("SELECT `id`,`type` FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` WHERE `type` IN ('email') AND `active` = '1' ORDER BY `order` ASC LIMIT 1", ARRAY_A);
        $email = $wpdb->get_var("SELECT `value` FROM `" . WPSC_TABLE_SUBMITED_FORM_DATA . "` WHERE `log_id`=" . $purchase_log['id'] . " AND `form_id` = '" . $email_form_field[0]['id'] . "' LIMIT 1");
        $stock_adjusted = false;
        $previous_download_ids = array(0);
        $product_list = '';
        if ($cart != null && $errorcode == 0) {
            foreach ($cart as $row) {
                $link = "";
                $product_data = $wpdb->get_row("SELECT * FROM `" . WPSC_TABLE_PRODUCT_LIST . "` WHERE `id`='{$row['prodid']}' LIMIT 1", ARRAY_A);
                if ($purchase_log['email_sent'] != 1) {
                    $wpdb->query("UPDATE `" . WPSC_TABLE_DOWNLOAD_STATUS . "` SET `active`='1' WHERE (`fileid` = '{$product_data['file']}' OR `cartid` = '{$row['id']}' ) AND `purchid` = '{$purchase_log['id']}'");
                }
                do_action('wpsc_transaction_result_cart_item', array("purchase_id" => $purchase_log['id'], "cart_item" => $row, "purchase_log" => $purchase_log));
                if ($purchase_log['processed'] >= 2) {
                    $download_data = $wpdb->get_results("SELECT * FROM `" . WPSC_TABLE_DOWNLOAD_STATUS . "`\r\n\t\t\t\t\t INNER JOIN `" . WPSC_TABLE_PRODUCT_FILES . "`\r\n\t\t\t\t\t  ON `" . WPSC_TABLE_DOWNLOAD_STATUS . "`.`fileid` = `" . WPSC_TABLE_PRODUCT_FILES . "`.`id`\r\n\t\t\t\t\t  WHERE `" . WPSC_TABLE_DOWNLOAD_STATUS . "`.`active`='1'\r\n\t\t\t\t\t  AND `" . WPSC_TABLE_DOWNLOAD_STATUS . "`.`purchid`='" . $purchase_log['id'] . "'\r\n\t\t\t\t\t  AND (\r\n\t\t\t\t\t\t`" . WPSC_TABLE_DOWNLOAD_STATUS . "`.`cartid` = '" . $row['id'] . "'\r\n\t\t\t\t\t\t\tOR (\r\n\t\t\t\t\t\t\t\t`" . WPSC_TABLE_DOWNLOAD_STATUS . "`.`cartid` IS NULL\r\n\t\t\t\t\t\t\t\tAND `" . WPSC_TABLE_DOWNLOAD_STATUS . "`.`fileid` = '{$product_data['file']}'\r\n\t\t\t\t\t\t\t)\r\n\t\t\t\t\t\t)\r\n\t\t\t\t\t\tAND `" . WPSC_TABLE_DOWNLOAD_STATUS . "`.`id` NOT IN ('" . implode("','", $previous_download_ids) . "')", ARRAY_A);
                    $link = array();
                    //exit('IM HERE'.$errorcode.'<pre>'.print_r($download_data).'</pre>');
                    if (sizeof($download_data) != 0) {
                        foreach ($download_data as $single_download) {
                            if ($single_download['uniqueid'] == null) {
                                // if the uniqueid is not equal to null, its "valid", regardless of what it is
                                $link[] = array("url" => site_url("?downloadid=" . $single_download['id']), "name" => $single_download["filename"]);
                            } else {
                                $link[] = array("url" => site_url("?downloadid=" . $single_download['uniqueid']), "name" => $single_download["filename"]);
                            }
                        }
                        //$order_status= 4;
                    } else {
                        $order_status = $purchase_log['processed'];
                    }
                    $previous_download_ids[] = $download_data['id'];
                    do_action('wpsc_confirm_checkout', $purchase_log['id']);
                }
                //	do_action('wpsc_confirm_checkout', $purchase_log['id']);
                $shipping = $row['pnp'];
                $total_shipping += $shipping;
                if ($product_data['special'] == 1) {
                    $price_modifier = $product_data['special_price'];
                } else {
                    $price_modifier = 0;
                }
                $total += $row['price'] * $row['quantity'];
                $message_price = nzshpcrt_currency_display($row['price'] * $row['quantity'], $product_data['notax'], true);
                $shipping_price = nzshpcrt_currency_display($shipping, 1, true);
                $variation_values = $wpdb->get_col("SELECT `value_id`  FROM `" . WPSC_TABLE_CART_ITEM_VARIATIONS . "` WHERE `cart_id`='{$row['id']}'");
                //echo "<pre>".print_r($product_data,true)."</pre>";
                $variation_count = count($variation_values);
                if ($purchase['gateway'] != 'testmode') {
                    if ($gateway['internalname'] == $purch_data[0]['gateway']) {
                        $gateway_name = $gateway['name'];
                    }
                } else {
                    $gateway_name = "Manual Payment";
                }
                //echo "<pre>".print_r($variation_values,true)."</pre>";
                $variation_list = '';
                if ($variation_count > 0) {
                    $value_names = $wpdb->get_col("SELECT `name` FROM `" . WPSC_TABLE_VARIATION_VALUES . "` WHERE `id` IN ('" . implode("','", $variation_values) . "')");
                    $variation_list = " (" . stripslashes(implode(", ", $value_names)) . ")";
                }
                if ($link != '' && !empty($link)) {
                    $additional_content = apply_filters('wpsc_transaction_result_content', array("purchase_id" => $purchase_log['id'], "cart_item" => $row, "purchase_log" => $purchase_log));
                    if (!is_string($additional_content)) {
                        $additional_content = '';
                    }
                    //$product_list .= " - ". $product_data['name'] . stripslashes($variation_list) ."  ".$message_price ." ".__('Click to download', 'wpsc').":\n\r $link\n\r".$additional_content;
                    //$product_list_html .= " - ". $product_data['name'] . stripslashes($variation_list) ."  ".$message_price ."&nbsp;&nbsp;<a href='$link'>".__('Click to download', 'wpsc')."</a>\n". $additional_content;
                    $product_list .= " - " . $product_data['name'] . stripslashes($variation_list) . "  " . $message_price;
                    $product_list_html .= " - " . $product_data['name'] . stripslashes($variation_list) . "  " . $message_price;
                    foreach ($link as $single_link) {
                        $product_list .= "\n\r " . $single_link["name"] . ": " . $single_link["url"] . "\n\r";
                        $product_list_html .= "<a href='" . $single_link["url"] . "'>" . $single_link["name"] . "</a>\n";
                        $report_product_list .= "\n\r " . $single_link["name"] . ": " . $single_link["url"] . "\n\r";
                        //	$report_product_list .="<a href='".$single_link["url"]."'>".$single_link["name"]."</a>\n";
                    }
                    $product_list .= $additional_content;
                    $product_list_html .= $additional_content;
                } else {
                    $plural = '';
                    if ($row['quantity'] > 1) {
                        $plural = "s";
                    }
                    $product_list .= $row['quantity'] . " - " . $product_data['name'] . stripslashes($variation_list) . "  " . $message_price . "\n\r";
                    if ($shipping > 0) {
                        $product_list .= " - " . __('Shipping', 'wpsc') . ":" . $shipping_price . "\n\r";
                    }
                    $product_list_html .= $row['quantity'] . " -  " . $product_data['name'] . stripslashes($variation_list) . "  " . $message_price . "\n\r";
                    if ($shipping > 0) {
                        $product_list_html .= " &nbsp; " . __('Shipping', 'wpsc') . ":" . $shipping_price . "\n\r";
                    }
                    $report_product_list .= $row['quantity'] . " - " . $product_data['name'] . stripslashes($variation_list) . "  " . $message_price . "\n\r";
                }
                $report = get_option('wpsc_email_admin');
            }
            // Decrement the stock here
            if ($purchase_log['processed'] >= 2) {
                wpsc_decrement_claimed_stock($purchase_log['id']);
            }
            if ($purchase_log['discount_data'] != '') {
                $coupon_data = $wpdb->get_row("SELECT * FROM `" . WPSC_TABLE_COUPON_CODES . "` WHERE coupon_code='" . $wpdb->escape($purchase_log['discount_data']) . "' LIMIT 1", ARRAY_A);
                if ($coupon_data['use-once'] == 1) {
                    $wpdb->query("UPDATE `" . WPSC_TABLE_COUPON_CODES . "` SET `active`='0', `is-used`='1' WHERE `id`='" . $coupon_data['id'] . "' LIMIT 1");
                }
            }
            //$wpdb->query("UPDATE `".WPSC_TABLE_DOWNLOAD_STATUS."` SET `active`='1' WHERE `fileid`='".$product_data['file']."' AND `purchid` = '".$purchase_log['id']."' LIMIT 1");
            //if (!isset($_SESSION['quote_shipping']))
            //$total_shipping = nzshpcrt_determine_base_shipping($total_shipping, $shipping_country);
            $total_shipping += $purchase_log['base_shipping'];
            $total = $purchase_log['totalprice'];
            // echo $total;
            // $message.= "\n\r";
            $product_list .= "Your Purchase No.: " . $purchase_log['id'] . "\n\r";
            if ($purchase_log['discount_value'] > 0) {
                $discount_email .= __('Discount', 'wpsc') . "\n\r: ";
                $discount_email .= $purchase_log['discount_data'] . ' : ' . nzshpcrt_currency_display($purchase_log['discount_value'], 1, true) . "\n\r";
            }
            $total_shipping_email .= __('Total Shipping', 'wpsc') . ": " . nzshpcrt_currency_display($total_shipping, 1, true) . "\n\r";
            $total_price_email .= __('Total', 'wpsc') . ": " . nzshpcrt_currency_display($total, 1, true) . "\n\r";
            $product_list_html .= "Your Purchase No.: " . $purchase_log['id'] . "\n\n\r";
            if ($purchase_log['discount_value'] > 0) {
                $report .= $discount_email . "\n\r";
                $total_shipping_html .= __('Discount', 'wpsc') . ": " . nzshpcrt_currency_display($purchase_log['discount_value'], 1, true) . "\n\r";
            }
            $total_shipping_html .= __('Total Shipping', 'wpsc') . ": " . nzshpcrt_currency_display($total_shipping, 1, true) . "\n\r";
            $total_price_html .= __('Total', 'wpsc') . ": " . nzshpcrt_currency_display($total, 1, true) . "\n\r";
            if (isset($_GET['ti'])) {
                $message .= "\n\r" . __('Your Transaction ID', 'wpsc') . ": " . $_GET['ti'];
                $message_html .= "\n\r" . __('Your Transaction ID', 'wpsc') . ": " . $_GET['ti'];
                $report .= "\n\r" . __('Transaction ID', 'wpsc') . ": " . $_GET['ti'];
            } else {
                $report_id = "Purchase # " . $purchase_log['id'] . "\n\r";
            }
            //echo "<pre>".print_r($purchase_log,true)."</pre>";
            $message = str_replace('%product_list%', $product_list, $message);
            $message = str_replace('%total_shipping%', $total_shipping_email, $message);
            $message = str_replace('%total_price%', $total_price_email, $message);
            $message = str_replace('%shop_name%', get_option('blogname'), $message);
            $message = str_replace('%find_us%', $purchase_log['find_us'], $message);
            //$message = str_replace('%order_status%',get_option('blogname'),$message);
            $report = str_replace('%product_list%', $report_product_list, $report);
            $report = str_replace('%total_shipping%', $total_shipping_email, $report);
            $report = str_replace('%total_price%', $total_price_email, $report);
            $report = str_replace('%shop_name%', get_option('blogname'), $report);
            $report = str_replace('%find_us%', $purchase_log['find_us'], $report);
            $message_html = str_replace('%product_list%', $product_list_html, $message_html);
            $message_html = str_replace('%total_shipping%', $total_shipping_html, $message_html);
            $message_html = str_replace('%total_price%', $total_price_email, $message_html);
            $message_html = str_replace('%shop_name%', get_option('blogname'), $message_html);
            $message_html = str_replace('%find_us%', $purchase_log['find_us'], $message_html);
            //$message_html = str_replace('%order_status%',get_option('blogname'),$message_html);
            if ($email != '' && $purchase_log['email_sent'] != 1) {
                add_filter('wp_mail_from', 'wpsc_replace_reply_address', 0);
                add_filter('wp_mail_from_name', 'wpsc_replace_reply_name', 0);
                if ($purchase_log['processed'] < 2) {
                    $payment_instructions = strip_tags(get_option('payment_instructions'));
                    $message = __('Thank you, your purchase is pending, you will be sent an email once the order clears.', 'wpsc') . "\n\r" . $payment_instructions . "\n\r" . $message;
                    wp_mail($email, __('Order Pending: Payment Required', 'wpsc'), $message);
                } else {
                    wp_mail($email, __('Purchase Receipt', 'wpsc'), $message);
                }
            }
            remove_filter('wp_mail_from_name', 'wpsc_replace_reply_name');
            remove_filter('wp_mail_from', 'wpsc_replace_reply_address');
            $report_user = __('Customer Details', 'wpsc') . "\n\r";
            $report_user .= "Billing Info \n\r";
            foreach ((array) $thepurchlogitem->userinfo as $userinfo) {
                if ($userinfo['unique_name'] != 'billingcountry') {
                    $report_user .= "" . $userinfo['name'] . ": " . $userinfo['value'] . "\n";
                } else {
                    $userinfo['value'] = maybe_unserialize($userinfo['value']);
                    if (is_array($userinfo['value'])) {
                        if (!empty($userinfo['value'][1]) && !is_numeric($userinfo['value'][1])) {
                            $report_user .= "State: " . $userinfo['value'][1] . "\n";
                        } elseif (is_numeric($userinfo['value'][1])) {
                            $report_user .= "State: " . wpsc_get_state_by_id($userinfo['value'][1], 'name') . "\n";
                        }
                        if (!empty($userinfo['value'][0])) {
                            $report_user .= "Country: " . $userinfo['value'][0] . "\n";
                        }
                    } else {
                        $report_user .= "" . $userinfo['name'] . ": " . $userinfo['value'] . "\n";
                    }
                }
            }
            $report_user .= "\n\rShipping Info \n\r";
            foreach ((array) $thepurchlogitem->shippinginfo as $userinfo) {
                if ($userinfo['unique_name'] != 'shippingcountry' && $userinfo['unique_name'] != 'shippingstate') {
                    $report_user .= "" . $userinfo['name'] . ": " . $userinfo['value'] . "\n";
                } elseif ($userinfo['unique_name'] == 'shippingcountry') {
                    $userinfo['value'] = maybe_unserialize($userinfo['value']);
                    if (is_array($userinfo['value'])) {
                        if (!empty($userinfo['value'][1]) && !is_numeric($userinfo['value'][1])) {
                            $report_user .= "State: " . $userinfo['value'][1] . "\n";
                        } elseif (is_numeric($userinfo['value'][1])) {
                            $report_user .= "State: " . wpsc_get_state_by_id($userinfo['value'][1], 'name') . "\n";
                        }
                        if (!empty($userinfo['value'][0])) {
                            $report_user .= "Country: " . $userinfo['value'][0] . "\n";
                        }
                    } else {
                        $report_user .= "" . $userinfo['name'] . ": " . $userinfo['value'] . "\n";
                    }
                } elseif ($userinfo['unique_name'] == 'shippingstate') {
                    if (!empty($userinfo['value']) && !is_numeric($userinfo['value'])) {
                        $report_user .= "" . $userinfo['name'] . ": " . $userinfo['value'] . "\n";
                    } elseif (is_numeric($userinfo['value'])) {
                        $report_user .= "State: " . wpsc_get_state_by_id($userinfo['value'], 'name') . "\n";
                    }
                }
            }
            $report_user .= "\n\r";
            /*
            				$form_sql = "SELECT * FROM `".WPSC_TABLE_SUBMITED_FORM_DATA."` WHERE `log_id` = '".$purchase_log['id']."'";
            				$form_data = $wpdb->get_results($form_sql,ARRAY_A);
            					
            				if($form_data != null) {
            				
            					foreach($form_data as $form_field) {
            						$form_data = $wpdb->get_row("SELECT * FROM `".WPSC_TABLE_CHECKOUT_FORMS."` WHERE `id` = '".$form_field['form_id']."' LIMIT 1", ARRAY_A);
            
            						switch($form_data['type']) {
            							case "country":
            							$report_user .= $form_data['name'].": ".wpsc_get_country($form_field['value'])."\n";
            							$report_user .= __('State', 'wpsc').": ".wpsc_get_region($purchase_log['billing_region'])."\n";
            							break;
            							
            							case "delivery_country":
            							$report_user .= $form_data['name'].": ".wpsc_get_country($form_field['value'])."\n";
            							$report_user .= __('Delivery State', 'wpsc').": ".wpsc_get_region($purchase_log['shipping_region'])."\n";
            							break;
            							
            							default:
            							$report_user .= wp_kses($form_data['name'], array()).": ".$form_field['value']."\n";
            							break;
            						}
            					}
            				}
            	
            				$report_user .= "\n\r";
            */
            $report = $report_user . $report_id . $report;
            if ($stock_adjusted == true) {
                $wpdb->query("UPDATE `" . WPSC_TABLE_PURCHASE_LOGS . "` SET `stock_adjusted` = '1' WHERE `sessionid` = " . $sessionid . " LIMIT 1");
            }
            if (get_option('purch_log_email') != null && $purchase_log['email_sent'] != 1) {
                wp_mail(get_option('purch_log_email'), __('Purchase Report', 'wpsc'), $report);
            }
            if ($purchase_log['processed'] < 2) {
                echo "<br />" . nl2br(str_replace("\$", '\\$', $message_html));
                return;
            }
            /// Empty the cart
            $wpsc_cart->submit_stock_claims($purchase_log['id']);
            $wpsc_cart->empty_cart();
            if (true === $echo_to_screen) {
                echo '<div class="wrap">';
                if ($sessionid != null) {
                    echo __('The Transaction was successful', 'wpsc') . "<br />";
                    echo "<br />" . nl2br(str_replace("\$", '\\$', $message_html));
                }
                echo '</div>';
            }
        } else {
            if (true === $echo_to_screen) {
                echo '<div class="wrap">';
                echo __('Oops, there is nothing in your cart.', 'wpsc') . "<a href='" . get_option("product_list_url") . "'>" . __('Please visit our shop', 'wpsc') . "</a>";
                echo '</div>';
            }
        }
        if ($purchase_log['email_sent'] != 1 and $sessionid != '') {
            if (preg_match("/^[\\w\\s._,-]+\$/", $transaction_id)) {
                $transact_id_sql = "`transactid` = '" . $transaction_id . "',";
            }
            $update_sql = "UPDATE `" . WPSC_TABLE_PURCHASE_LOGS . "` SET {$transact_id_sql} `email_sent` = '1', `processed` = '{$order_status}' WHERE `sessionid` = " . $sessionid . " LIMIT 1";
            $wpdb->query($update_sql);
        }
    }
}
Exemplo n.º 7
0
function wpsc_display_coupons_page()
{
    global $wpdb;
    if (isset($_POST) && is_array($_POST) && !empty($_POST)) {
        if (isset($_POST['add_coupon']) && $_POST['add_coupon'] == 'true' && !($_POST['is_edit_coupon'] == 'true')) {
            $coupon_code = $_POST['add_coupon_code'];
            $discount = (double) $_POST['add_discount'];
            // cast to boolean, then integer, prevents the value from being anything but 1 or 0
            $discount_type = (int) $_POST['add_discount_type'];
            $use_once = (int) (bool) $_POST['add_use-once'];
            $every_product = (int) (bool) $_POST['add_every_product'];
            // 		$start_date = date("Y-m-d H:i:s", mktime(0, 0, 0, (int)$_POST['add_start']['month'], (int)$_POST['add_start']['day'], (int)$_POST['add_start']['year']));
            // 		$end_date = date("Y-m-d H:i:s", mktime(0, 0, 0, (int)$_POST['add_end']['month'], (int)$_POST['add_end']['day'], (int)$_POST['add_end']['year']));
            $start_date = date('Y-m-d', strtotime($_POST['add_start'])) . " 00:00:00";
            $end_date = date('Y-m-d', strtotime($_POST['add_end'])) . " 00:00:00";
            $rules = $_POST['rules'];
            foreach ($rules as $key => $rule) {
                foreach ($rule as $k => $r) {
                    $new_rule[$k][$key] = $r;
                }
            }
            foreach ($new_rule as $key => $rule) {
                if ($rule['value'] == '') {
                    unset($new_rule[$key]);
                }
            }
            if ($wpdb->query("INSERT INTO `" . WPSC_TABLE_COUPON_CODES . "` ( `coupon_code` , `value` , `is-percentage` , `use-once` , `is-used` , `active` , `every_product` , `start` , `expiry`, `condition` ) VALUES ( '{$coupon_code}', '{$discount}', '{$discount_type}', '{$use_once}', '0', '1', '{$every_product}', '{$start_date}' , '{$end_date}' , '" . serialize($new_rule) . "' );")) {
                echo "<div class='updated'><p align='center'>" . __('Thanks, the coupon has been added.', 'wpsc') . "</p></div>";
            }
        }
        if (isset($_POST['is_edit_coupon']) && $_POST['is_edit_coupon'] == 'true' && !isset($_POST['delete_condition']) && !isset($_POST['submit_condition'])) {
            //exit('<pre>'.print_r($_POST, true).'</pre>');
            foreach ((array) $_POST['edit_coupon'] as $coupon_id => $coupon_data) {
                //echo('<pre>'.print_r($coupon_data,true)."</pre>");
                $coupon_id = (int) $coupon_id;
                // convert dates to a form that compares well and can be inserted into the database
                // 			$coupon_data['start'] = date("Y-m-d H:i:s", mktime(0, 0, 0, (int)$coupon_data['start']['month'], (int)$coupon_data['start']['day'], (int)$coupon_data['start']['year']));
                // 			$coupon_data['expiry'] = date("Y-m-d H:i:s", mktime(0, 0, 0, (int)$coupon_data['expiry']['month'], (int)$coupon_data['expiry']['day'], (int)$coupon_data['expiry']['year']));
                $coupon_data['start'] = $coupon_data['start'] . " 00:00:00";
                $coupon_data['expiry'] = $coupon_data['expiry'] . " 00:00:00";
                $check_values = $wpdb->get_row("SELECT `id`, `coupon_code`, `value`, `is-percentage`, `use-once`, `active`, `start`, `expiry` FROM `" . WPSC_TABLE_COUPON_CODES . "` WHERE `id` = '{$coupon_id}'", ARRAY_A);
                //sort both arrays to make sure that if they contain the same stuff, that they will compare to be the same, may not need to do this, but what the heck
                //	exit('<pre>'.print_r($coupon_data, true).'</pre>');
                ksort($check_values);
                ksort($coupon_data);
                if ($check_values != $coupon_data) {
                    $insert_array = array();
                    foreach ($coupon_data as $coupon_key => $coupon_value) {
                        if ($coupon_key == "submit_coupon" || $coupon_key == "delete_coupon") {
                            continue;
                        }
                        if ($coupon_value != $check_values[$coupon_key]) {
                            $insert_array[] = "`{$coupon_key}` = '{$coupon_value}'";
                        }
                    }
                    //if(in_array(mixed needle, array haystack [, bool strict]))
                    //exit("<pre>".print_r($conditions,true)."</pre>");
                    if (count($insert_array) > 0) {
                        $wpdb->query("UPDATE `" . WPSC_TABLE_COUPON_CODES . "` SET " . implode(", ", $insert_array) . " WHERE `id` = '{$coupon_id}' LIMIT 1;");
                    }
                    unset($insert_array);
                    $rules = $_POST['rules'];
                    foreach ((array) $rules as $key => $rule) {
                        foreach ($rule as $k => $r) {
                            $new_rule[$k][$key] = $r;
                        }
                    }
                    foreach ((array) $new_rule as $key => $rule) {
                        if ($rule['value'] == '') {
                            unset($new_rule[$key]);
                        }
                    }
                    /*
                    $sql ="UPDATE `".WPSC_TABLE_COUPON_CODES."` SET `condition`='".serialize($new_rule)."' WHERE `id` = '$coupon_id' LIMIT 1";
                    				$wpdb->query($sql);
                    */
                    $conditions = $wpdb->get_var("SELECT `condition` FROM `" . WPSC_TABLE_COUPON_CODES . "` WHERE `id` = '" . (int) $_POST['coupon_id'] . "' LIMIT 1");
                    $conditions = unserialize($conditions);
                    $new_cond = array();
                    if ($_POST['rules']['value'][0] != '') {
                        $new_cond['property'] = $_POST['rules']['property'][0];
                        $new_cond['logic'] = $_POST['rules']['logic'][0];
                        $new_cond['value'] = $_POST['rules']['value'][0];
                        $conditions[] = $new_cond;
                    }
                    $sql = "UPDATE `" . WPSC_TABLE_COUPON_CODES . "` SET `condition`='" . serialize($conditions) . "' WHERE `id` = '" . (int) $_POST['coupon_id'] . "' LIMIT 1";
                    $wpdb->query($sql);
                }
                if ($coupon_data['delete_coupon'] != '') {
                    $wpdb->query("DELETE FROM `" . WPSC_TABLE_COUPON_CODES . "` WHERE `id` = '{$coupon_id}' LIMIT 1;");
                }
            }
        }
        if (isset($_POST['delete_condition'])) {
            $conditions = $wpdb->get_var("SELECT `condition` FROM `" . WPSC_TABLE_COUPON_CODES . "` WHERE `id` = '" . (int) $_POST['coupon_id'] . "' LIMIT 1");
            $conditions = unserialize($conditions);
            unset($conditions[(int) $_POST['delete_condition']]);
            //$conditions = array_values($conditions);
            //  exit('<pre>'.print_r($_POST, true).'</pre><pre>'.print_r($conditions, true).'</pre>'.$sql);
            $sql = "UPDATE `" . WPSC_TABLE_COUPON_CODES . "` SET `condition`='" . serialize($conditions) . "' WHERE `id` = '" . (int) $_POST['coupon_id'] . "' LIMIT 1";
            $wpdb->query($sql);
        }
        if (isset($_POST['submit_condition'])) {
            $conditions = $wpdb->get_var("SELECT `condition` FROM `" . WPSC_TABLE_COUPON_CODES . "` WHERE `id` = '" . (int) $_POST['coupon_id'] . "' LIMIT 1");
            $conditions = unserialize($conditions);
            $new_cond = array();
            $new_cond['property'] = $_POST['rules']['property'][0];
            $new_cond['logic'] = $_POST['rules']['logic'][0];
            $new_cond['value'] = $_POST['rules']['value'][0];
            $conditions[] = $new_cond;
            $sql = "UPDATE `" . WPSC_TABLE_COUPON_CODES . "` SET `condition`='" . serialize($conditions) . "' WHERE `id` = '" . (int) $_POST['coupon_id'] . "' LIMIT 1";
            $wpdb->query($sql);
        }
        if ($_POST['change-settings'] == 'true') {
            if ($_POST['wpsc_also_bought'] == 1) {
                update_option('wpsc_also_bought', 1);
            } else {
                update_option('wpsc_also_bought', 0);
            }
            if ($_POST['display_find_us'] == 'on') {
                update_option('display_find_us', 1);
            } else {
                update_option('display_find_us', 0);
            }
            if ($_POST['wpsc_share_this'] == 1) {
                update_option('wpsc_share_this', 1);
            } else {
                update_option('wpsc_share_this', 0);
            }
        }
    }
    /*<strong><?php echo TXT_WPSC_ADD_COUPON; ?></strong>*/
    ?>
<script type='text/javascript'>
	jQuery(".pickdate").datepicker();
		/* jQuery datepicker selector */
	if (typeof jQuery('.pickdate').datepicker != "undefined") {
		jQuery('.pickdate').datepicker({ dateFormat: 'yy-mm-dd' });
	}
</script>
<div class="wrap">
  <h2><?php 
    echo __('Coupons', 'wpsc');
    ?>
</h2>
  <div style='margin:0px;' class="tablenav wpsc_admin_nav">
  <!-- <a target="_blank" href="http://www.instinct.co.nz/e-commerce/marketing/" class="about_this_page"><span>About This Page</span> </a> -->

 	<form action='' method='post'>
		<input id='add_coupon_box_link' type='submit' class=' add_item_link button' name='add_coupon_button' value='<?php 
    echo __('Create Coupon', 'wpsc');
    ?>
' onclick='return show_status_box("add_coupon_box","add_coupon_box_link");return false;' />
	</form>
</div>
<!-- <form name='edit_coupon' method='post' action=''>   -->
<table style="width: 100%;">
  <tr>
    <td id="coupon_data">
    

<div id='add_coupon_box' class='modify_coupon' >
<form name='add_coupon' method='post' action=''>
<table class='add-coupon' >
 <tr>
   <th>
   <?php 
    echo __('Coupon Code', 'wpsc');
    ?>
   </th>
   <th>
   <?php 
    echo __('Discount', 'wpsc');
    ?>
   </th>
   <th>
   <?php 
    echo __('Start', 'wpsc');
    ?>
   </th>
   <th>
   <?php 
    echo __('Expiry', 'wpsc');
    ?>
   </th>
   <th>
   <?php 
    echo __('Use Once', 'wpsc');
    ?>
   </th>
   <th>
   <?php 
    echo __('Active', 'wpsc');
    ?>
   </th>
  <!--
 <th>
   <?php 
    echo __('Apply On All Products', 'wpsc');
    ?>
   </th>
-->
 </tr>
 <tr>
   <td>
   <input type='text' value='' name='add_coupon_code' />
   </td>
   <td>
   <input type='text' value='' size='3' name='add_discount' />
   <select name='add_discount_type'>
     <option value='0' >$</option>
     <option value='1' >%</option>
     <option value='2' >Free shipping</option>
   </select>
   </td>
   <td>
   <input type='text' class='pickdate' size='11' name='add_start' />
   <!--<select name='add_start[day]'>
   <?php 
    for ($i = 1; $i <= 31; ++$i) {
        $selected = '';
        if ($i == date("d")) {
            $selected = "selected='selected'";
        }
        echo "<option {$selected} value='{$i}'>{$i}</option>";
    }
    ?>
   </select>
   <select name='add_start[month]'>
   <?php 
    for ($i = 1; $i <= 12; ++$i) {
        $selected = '';
        if ($i == (int) date("m")) {
            $selected = "selected='selected'";
        }
        echo "<option {$selected} value='{$i}'>" . date("M", mktime(0, 0, 0, $i, 1, date("Y"))) . "</option>";
    }
    ?>
   </select>
   <select name='add_start[year]'>
   <?php 
    for ($i = date("Y"); $i <= date("Y") + 12; ++$i) {
        $selected = '';
        if ($i == date("Y")) {
            $selected = "selected='true'";
        }
        echo "<option {$selected} value='{$i}'>" . $i . "</option>";
    }
    ?>
   </select>-->
   </td>
   <td>
   <input type='text' class='pickdate' size='11' name='add_end'>
   <!--<select name='add_end[day]'>
   <?php 
    for ($i = 1; $i <= 31; ++$i) {
        $selected = '';
        if ($i == date("d")) {
            $selected = "selected='true'";
        }
        echo "<option {$selected} value='{$i}'>{$i}</option>";
    }
    ?>
   </select>
   <select name='add_end[month]'>
   <?php 
    for ($i = 1; $i <= 12; ++$i) {
        $selected = '';
        if ($i == (int) date("m")) {
            $selected = "selected='true'";
        }
        echo "<option {$selected} value='{$i}'>" . date("M", mktime(0, 0, 0, $i, 1, date("Y"))) . "</option>";
    }
    ?>
   </select>
   <select name='add_end[year]'>
   <?php 
    for ($i = date("Y"); $i <= date("Y") + 12; ++$i) {
        $selected = '';
        if ($i == date("Y") + 1) {
            $selected = "selected='true'";
        }
        echo "<option {$selected} value='{$i}'>" . $i . "</option>";
    }
    ?>
   </select>-->
   </td>
   <td>
   <input type='hidden' value='0' name='add_use-once' />
   <input type='checkbox' value='1' name='add_use-once' />
   </td>
   <td>
   <input type='hidden' value='0' name='add_active' />
   <input type='checkbox' value='1' checked='checked' name='add_active' />
   </td>

   <td>
   
   <input type='hidden' value='true' name='add_coupon' />
   <input type='submit' value='Add Coupon' name='submit_coupon' class='button-primary' />
   </td>
 </tr>
 <tr><td colspan="2">
		   <input type='hidden' value='0' name='add_every_product' />
			<input type="checkbox" value="1" name='add_every_product'/>
		<?php 
    _e('Apply On All Products', 'wpsc');
    ?>
</td></tr>

<tr><td colspan='3'><span id='table_header'>Conditions</span></td></tr>
<tr><td colspan="8">
	<div class='coupon_condition' >
		<div class='first_condition'>
			<select class="ruleprops" name="rules[property][]">
				<option value="item_name" rel="order">Item name</option>
				<option value="item_quantity" rel="order">Item quantity</option>
				<option value="total_quantity" rel="order">Total quantity</option>
				<option value="subtotal_amount" rel="order">Subtotal amount</option>
				<?php 
    echo apply_filters('wpsc_coupon_rule_property_options', '');
    ?>
			</select>
			<select name="rules[logic][]">
				<option value="equal">Is equal to</option>
				<option value="greater">Is greater than</option>
				<option value="less">Is less than</option>
				<option value="contains">Contains</option>
				<option value="not_contain">Does not contain</option>
				<option value="begins">Begins with</option>
				<option value="ends">Ends with</option>
			</select>
			<span>
				<input type="text" name="rules[value][]"/>
			</span>
			<span>
            	<script>
				var coupon_number=1;
				function add_another_property(this_button){
					var new_property='<div class="coupon_condition">\n'+
						'<div><img height="16" width="16" class="delete" alt="Delete" src="<?php 
    echo WPSC_URL;
    ?>
/images/cross.png" onclick="jQuery(this).parent().remove();"/> \n'+
							'<select class="ruleprops" name="rules[property][]"> \n'+
								'<option value="item_name" rel="order">Item name</option> \n'+
								'<option value="item_quantity" rel="order">Item quantity</option>\n'+
								'<option value="total_quantity" rel="order">Total quantity</option>\n'+ 
								'<option value="subtotal_amount" rel="order">Subtotal amount</option>\n'+ 
								'<?php 
    echo apply_filters('wpsc_coupon_rule_property_options', '');
    ?>
'+
							'</select> \n'+
							'<select name="rules[logic][]"> \n'+
								'<option value="equal">Is equal to</option> \n'+
								'<option value="greater">Is greater than</option> \n'+
								'<option value="less">Is less than</option> \n'+
								'<option value="contains">Contains</option> \n'+
								'<option value="not_contain">Does not contain</option> \n'+
								'<option value="begins">Begins with</option> \n'+
								'<option value="ends">Ends with</option> \n'+
							'</select> \n'+
							'<span> \n'+
								'<input type="text" name="rules[value][]"/> \n'+
							'</span>  \n'+
						'</div> \n'+
					'</div> ';
		
					jQuery('.coupon_condition :first').after(new_property);
					coupon_number++;
				}
				</script>
			
			</span>
			
		</div>
	</div>
</tr>
<tr><td>	<a class="wpsc_coupons_condition_add" onclick="add_another_property(jQuery(this));">
					<?php 
    _e('Add New Condition', 'wpsc');
    ?>
				</a></td></tr>
</table>
<br />
</form>  
</div>    

  <?php 
    $num = 0;
    echo "<table class='coupon-list'>\n\r";
    echo "  <tr class='toprow'>\n\r";
    echo "    <th>\n\r";
    echo __('Coupon Code', 'wpsc');
    echo "    </th>\n\r";
    echo "    <th>\n\r";
    echo __('Discount', 'wpsc');
    echo "    </th>\n\r";
    echo "    <th>\n\r";
    echo __('Start', 'wpsc');
    echo "    </th>\n\r";
    echo "    <th>\n\r";
    echo __('Expiry', 'wpsc');
    echo "    </th>\n\r";
    echo "    <th>\n\r";
    echo __('Active', 'wpsc');
    echo "    </th>\n\r";
    echo "    <th>\n\r";
    echo __('Apply On All Products', 'wpsc');
    echo "    </th>\n\r";
    echo "    <th>\n\r";
    echo __('Edit', 'wpsc');
    echo "    </th>\n\r";
    $i = 0;
    $coupon_data = $wpdb->get_results("SELECT * FROM `" . WPSC_TABLE_COUPON_CODES . "` ", ARRAY_A);
    //exit('Coupon Data<pre>'.print_r($coupon_data, true).'</pre>');
    foreach ((array) $coupon_data as $coupon) {
        $alternate = "";
        $i++;
        if ($i % 2 != 0) {
            $alternate = "class='alt'";
        }
        echo "<tr {$alternate}>\n\r";
        echo "    <td>\n\r";
        echo $coupon['coupon_code'];
        echo "    </td>\n\r";
        echo "    <td>\n\r";
        if ($coupon['is-percentage'] == 1) {
            echo $coupon['value'] . "%";
        } else {
            echo nzshpcrt_currency_display($coupon['value'], 1);
        }
        echo "    </td>\n\r";
        echo "    <td>\n\r";
        echo date("d/m/Y", strtotime($coupon['start']));
        echo "    </td>\n\r";
        echo "    <td>\n\r";
        echo date("d/m/Y", strtotime($coupon['expiry']));
        echo "    </td>\n\r";
        echo "    <td>\n\r";
        switch ($coupon['active']) {
            case 1:
                echo "<img src='" . WPSC_URL . "/images/yes_stock.gif' alt='' title='' />";
                break;
            case 0:
            default:
                echo "<img src='" . WPSC_URL . "/images/no_stock.gif' alt='' title='' />";
                break;
        }
        echo "    </td>\n\r";
        echo "    <td>\n\r";
        switch ($coupon['every_product']) {
            case 1:
                echo "<img src='" . WPSC_URL . "/images/yes_stock.gif' alt='' title='' />";
                break;
            case 0:
            default:
                echo "<img src='" . WPSC_URL . "/images/no_stock.gif' alt='' title='' />";
                break;
        }
        echo "    </td>\n\r";
        echo "    <td>\n\r";
        echo "<a title='" . $coupon['coupon_code'] . "' href='javascript:void(0)' class='wpsc_edit_coupon'  >" . __('Edit', 'wpsc') . "</a>";
        echo "    </td>\n\r";
        echo "  </tr>\n\r";
        echo "  <tr>\n\r";
        echo "    <td colspan='7' style='padding-left:0px;'>\n\r";
        //  $status_style = "style='display: block;'";
        echo "      <div id='coupon_box_" . $coupon['id'] . "' class='modify_coupon' >\n\r";
        coupon_edit_form($coupon);
        echo "      </div>\n\r";
        echo "    </td>\n\r";
        echo "  </tr>\n\r";
    }
    echo "</table>\n\r";
    ?>
  <p style='margin: 0px 0px 5px 0px;'>
  	 <?php 
    _e('<strong>Note:</strong> Due to a current limitation of PayPal, if your user makes a purchase and uses a coupon, we can not send a list of items through to paypal for processing. Rather, we must send the total amount of the purchase, so that within PayPal the user who purchases a product will see your shop name and the total amount of their purchase.', 'wpsc');
    ?>
  </p>
    </td>
  </tr>
</table>
<!-- <input type='hidden' value='true' name='is_edit_coupon' /> -->
<!-- </form> -->

<br />


      
<h2><?php 
    echo __('Marketing Settings', 'wpsc');
    ?>
</h2>

<form name='cart_options' method='POST' action=''>
<input type='hidden' value='true' name='change-settings' />
  <table>
    <tr>
      <td>
        <?php 
    echo __('Display Cross Sales', 'wpsc');
    ?>
:
      </td>
      <td>
        <?php 
    $wpsc_also_bought = get_option('wpsc_also_bought');
    $wpsc_also_bought1 = "";
    $wpsc_also_bought2 = "";
    switch ($wpsc_also_bought) {
        case 0:
            $wpsc_also_bought2 = "checked ='true'";
            break;
        case 1:
            $wpsc_also_bought1 = "checked ='true'";
            break;
    }
    ?>
        <input type='radio' value='1' name='wpsc_also_bought' id='wpsc_also_bought1' <?php 
    echo $wpsc_also_bought1;
    ?>
 /> <label for='wpsc_also_bought1'><?php 
    echo __('Yes', 'wpsc');
    ?>
</label> &nbsp;
        <input type='radio' value='0' name='wpsc_also_bought' id='wpsc_also_bought2' <?php 
    echo $wpsc_also_bought2;
    ?>
 /> <label for='wpsc_also_bought2'><?php 
    echo __('No', 'wpsc');
    ?>
</label>
      </td>
    </tr>
    
    <tr>
      <td>
      <?php 
    echo __('Show Share This (Social Bookmarks)', 'wpsc');
    ?>
:
      </td>
      <td>
        <?php 
    $wpsc_share_this = get_option('wpsc_share_this');
    $wpsc_share_this1 = "";
    $wpsc_share_this2 = "";
    switch ($wpsc_share_this) {
        case 0:
            $wpsc_share_this2 = "checked ='true'";
            break;
        case 1:
            $wpsc_share_this1 = "checked ='true'";
            break;
    }
    ?>
        <input type='radio' value='1' name='wpsc_share_this' id='wpsc_share_this1' <?php 
    echo $wpsc_share_this1;
    ?>
 /> <label for='wpsc_share_this1'><?php 
    echo __('Yes', 'wpsc');
    ?>
</label> &nbsp;
        <input type='radio' value='0' name='wpsc_share_this' id='wpsc_share_this2' <?php 
    echo $wpsc_share_this2;
    ?>
 /> <label for='wpsc_share_this2'><?php 
    echo __('No', 'wpsc');
    ?>
</label>
      </td>
    </tr>
	<tr>
        <td>
		<?php 
    echo __('Display How Customer Found Us Survey', 'wpsc');
    ?>
        </td>
	<?php 
    $display_find_us = get_option('display_find_us');
    if ($display_find_us == '1') {
        $display_find_us1 = "checked ='checked'";
    }
    ?>
        <td>
		<input <?php 
    echo $display_find_us1;
    ?>
 type='checkbox' name='display_find_us'>
        </td>
      </tr>
      <tr>
        <td>
	
        </td>
        <td>
        <input  type='submit' value='<?php 
    echo __('Submit', 'wpsc');
    ?>
' name='form_submit' />
        </td>
      </tr>
  </table>
</form>

<h2><?php 
    echo __('RSS Address', 'wpsc');
    ?>
</h2>
<table>
	<tr>
		<td colspan='2'>
			<?php 
    echo __('<strong>Note:</strong> Not only can people use this RSS to keep update with your product list but you can also use this link to promote your products in your facebook profile. <br />Just add the <a href="http://apps.facebook.com/getshopped">getshopped! facebook application</a> to your facebook profile and follow the instructions.', 'wpsc');
    ?>
		</td>
	</tr>
	<tr><td>&nbsp;</td></tr>
	<tr>
		<td>
			RSS Feed Address:
		</td>
		<td>
			<?php 
    echo get_bloginfo('url') . "/index.php?rss=true&amp;action=product_list";
    ?>
		</td>
	</tr>
</table>

<h2><?php 
    echo __('Google Merchant Centre / Google Product Search', 'wpsc');
    ?>
</h2>
<p>To import your products into <a href="http://www.google.com/merchants/" target="_blank">Google Merchant Centre</a> so that they appear within Google Product Search results, sign up for a Google Merchant Centre account and add a scheduled data feed with the following URL:</p>
<?php 
    $google_feed_url = get_bloginfo('url') . "/index.php?rss=true&action=product_list&xmlformat=google";
    ?>
<a href="<?php 
    echo htmlentities($google_feed_url);
    ?>
"><?php 
    echo htmlentities($google_feed_url);
    ?>
</a>
</div>
<?php 
}
function transaction_results($sessionid, $echo_to_screen = true, $transaction_id = null)
{
    global $wpdb, $wpsc_cart;
    //$curgateway = get_option('payment_gateway');
    $curgateway = $wpdb->get_var("SELECT gateway FROM " . WPSC_TABLE_PURCHASE_LOGS . " WHERE sessionid='{$sessionid}'");
    $errorcode = 0;
    $order_status = 2;
    $siteurl = get_option('siteurl');
    /*
     * {Notes} Double check that $Echo_To_Screen is a boolean value
     */
    $echo_to_screen = !is_bool($echo_to_screen) ? true : $echo_to_screen;
    //exit('triggered but with errors?'.$echo_to_screen);
    if (is_numeric($sessionid)) {
        if ($echo_to_screen) {
            echo apply_filters('wpsc_pre_transaction_results', '');
        }
        $purchase_log = $wpdb->get_row("SELECT * FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE `sessionid`= " . $sessionid . " LIMIT 1", ARRAY_A);
        if ($purchase_log['gateway'] == "testmode" && $purchase_log['processed'] < 2) {
            $message = get_option('wpsc_email_receipt');
            $message_html = $message;
        } else {
            $message = get_option('wpsc_email_receipt');
            $message_html = $message;
        }
        $order_url = $siteurl . "/wp-admin/admin.php?page=" . WPSC_DIR_NAME . "/display-log.php&amp;purchcaseid=" . $purchase_log['id'];
        if ($_GET['ipn_request'] != 'true' and get_option('paypal_ipn') == 1) {
            if ($purchase_log == null) {
                echo TXT_WPSC_ORDER_FAILED;
                if (get_option('purch_log_email') != null && $purchase_log['email_sent'] != 1) {
                    wp_mail(get_option('purch_log_email'), TXT_WPSC_NEW_ORDER_PENDING_SUBJECT, TXT_WPSC_NEW_ORDER_PENDING_BODY . $order_url, "From: " . get_option('return_email') . "");
                }
                return false;
            } else {
                if ($purchase_log['processed'] < 2) {
                    //added by Thomas on 20/6/2007
                    echo TXT_WPSC_ORDER_PENDING . "<p style='margin: 1em 0px 0px 0px;' >" . nl2br(get_option('payment_instructions')) . "</p>";
                    /*if($purchase_log['gateway'] != 'testmode') {
                    			if((get_option('purch_log_email') != null) && ($purchase_log['email_sent'] != 1)) {
                    				mail(get_option('purch_log_email'), TXT_WPSC_NEW_ORDER_PENDING_SUBJECT, TXT_WPSC_NEW_ORDER_PENDING_BODY.$order_url, "From: ".get_option('return_email')."");
                    			}
                    			return false;
                    		}*/
                }
            }
        }
        $cart = $wpdb->get_results("SELECT * FROM `" . WPSC_TABLE_CART_CONTENTS . "` WHERE `purchaseid`='{$purchase_log['id']}'", ARRAY_A);
        if ($purchase_log['shipping_country'] != '') {
            $billing_country = $purchase_log['billing_country'];
            $shipping_country = $purchase_log['shipping_country'];
        } else {
            $country = $wpdb->get_var("SELECT `value` FROM `" . WPSC_TABLE_SUBMITED_FORM_DATA . "` WHERE `log_id`=" . $purchase_log['id'] . " AND `form_id` = '" . get_option('country_form_field') . "' LIMIT 1");
            $billing_country = $country;
            $shipping_country = $country;
        }
        $email_form_field = $wpdb->get_results("SELECT `id`,`type` FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` WHERE `type` IN ('email') AND `active` = '1' ORDER BY `order` ASC LIMIT 1", ARRAY_A);
        $email = $wpdb->get_var("SELECT `value` FROM `" . WPSC_TABLE_SUBMITED_FORM_DATA . "` WHERE `log_id`=" . $purchase_log['id'] . " AND `form_id` = '" . $email_form_field[0]['id'] . "' LIMIT 1");
        $stock_adjusted = false;
        $previous_download_ids = array(0);
        $product_list = '';
        if ($cart != null && $errorcode == 0) {
            foreach ($cart as $row) {
                $link = "";
                $product_data = $wpdb->get_row("SELECT * FROM `" . WPSC_TABLE_PRODUCT_LIST . "` WHERE `id`='{$row['prodid']}' LIMIT 1", ARRAY_A);
                if ($purchase_log['email_sent'] != 1) {
                    $wpdb->query("UPDATE `" . WPSC_TABLE_DOWNLOAD_STATUS . "` SET `active`='1' WHERE (`fileid` = '{$product_data['file']}' OR `cartid` = '{$row['id']}' ) AND `purchid` = '{$purchase_log['id']}'");
                }
                do_action('wpsc_transaction_result_cart_item', array("purchase_id" => $purchase_log['id'], "cart_item" => $row, "purchase_log" => $purchase_log));
                if ($purchase_log['processed'] >= 2) {
                    //echo "SELECT * FROM `".WPSC_TABLE_DOWNLOAD_STATUS."` WHERE `active`='1' AND `purchid`='".$purchase_log['id']."' AND (`cartid` = '".$row['id']."' OR (`cartid` IS NULL AND `fileid` = '{$product_data['file']}') ) AND `id` NOT IN ('".implode("','",$previous_download_ids)."') LIMIT 1";
                    $download_data = $wpdb->get_row("SELECT * FROM `" . WPSC_TABLE_DOWNLOAD_STATUS . "` WHERE `active`='1' AND `purchid`='" . $purchase_log['id'] . "' AND (`cartid` = '" . $row['id'] . "' OR (`cartid` IS NULL AND `fileid` = '{$product_data['file']}') ) AND `id` NOT IN ('" . implode("','", $previous_download_ids) . "') LIMIT 1", ARRAY_A);
                    //exit('IM HERE'.$errorcode.'<pre>'.print_r($download_data).'</pre>');
                    if ($download_data != null) {
                        if ($download_data['uniqueid'] == null) {
                            // if the uniqueid is not equal to null, its "valid", regardless of what it is
                            $link = $siteurl . "?downloadid=" . $download_data['id'];
                        } else {
                            $link = $siteurl . "?downloadid=" . $download_data['uniqueid'];
                        }
                        //$order_status= 4;
                    } else {
                        $order_status = $purchase_log['processed'];
                    }
                    $previous_download_ids[] = $download_data['id'];
                }
                do_action('wpsc_confirm_checkout', $purchase_log['id']);
                $shipping = $row['pnp'] * $row['quantity'];
                $total_shipping += $shipping;
                if ($product_data['special'] == 1) {
                    $price_modifier = $product_data['special_price'];
                } else {
                    $price_modifier = 0;
                }
                $total += $row['price'] * $row['quantity'];
                $message_price = nzshpcrt_currency_display($row['price'] * $row['quantity'], $product_data['notax'], true);
                $shipping_price = nzshpcrt_currency_display($shipping, 1, true);
                $variation_values = $wpdb->get_col("SELECT `value_id`  FROM `" . WPSC_TABLE_CART_ITEM_VARIATIONS . "` WHERE `cart_id`='{$row['id']}'");
                //echo "<pre>".print_r($product_data,true)."</pre>";
                $variation_count = count($variation_values);
                if ($purchase['gateway'] != 'testmode') {
                    if ($gateway['internalname'] == $purch_data[0]['gateway']) {
                        $gateway_name = $gateway['name'];
                    }
                } else {
                    $gateway_name = "Manual Payment";
                }
                //echo "<pre>".print_r($variation_values,true)."</pre>";
                $variation_list = '';
                if ($variation_count > 0) {
                    $value_names = $wpdb->get_col("SELECT `name` FROM `" . WPSC_TABLE_VARIATION_VALUES . "` WHERE `id` IN ('" . implode("','", $variation_values) . "')");
                    $variation_list = " (" . stripslashes(implode(", ", $value_names)) . ")";
                }
                if ($link != '') {
                    $additional_content = apply_filters('wpsc_transaction_result_content', array("purchase_id" => $purchase_log['id'], "cart_item" => $row, "purchase_log" => $purchase_log));
                    if (!is_string($additional_content)) {
                        $additional_content = '';
                    }
                    $product_list .= " - " . $product_data['name'] . stripslashes($variation_list) . "  " . $message_price . " " . TXT_WPSC_CLICKTODOWNLOAD . ":\n\r {$link}\n\r" . $additional_content;
                    $product_list_html .= " - " . $product_data['name'] . stripslashes($variation_list) . "  " . $message_price . "&nbsp;&nbsp;<a href='{$link}'>" . TXT_WPSC_CLICKTODOWNLOAD . "</a>\n" . $additional_content;
                } else {
                    $plural = '';
                    if ($row['quantity'] > 1) {
                        $plural = "s";
                    }
                    $product_list .= " - " . $row['quantity'] . " " . $product_data['name'] . stripslashes($variation_list) . "  " . $message_price . "\n\r";
                    if ($shipping > 0) {
                        $product_list .= " - " . TXT_WPSC_SHIPPING . ":" . $shipping_price . "\n\r";
                    }
                    $product_list_html .= " - " . $row['quantity'] . " " . $product_data['name'] . stripslashes($variation_list) . "  " . $message_price . "\n\r";
                    if ($shipping > 0) {
                        $product_list_html .= " &nbsp; " . TXT_WPSC_SHIPPING . ":" . $shipping_price . "\n\r";
                    }
                }
                $report = get_option('wpsc_email_admin');
                $report_product_list .= " - " . $product_data['name'] . stripslashes($variation_list) . "  " . $message_price . "\n\r";
            }
            // KTTODO - call out to ezprints here
            if ($purchase_log['processed'] >= 2 && $purchase_log['ezprints_order_sent_count'] < 1) {
                $ezprints_body = sendEzPrintsOrder($purchase_log['id']);
                $wpdb->query("UPDATE `" . WPSC_TABLE_PURCHASE_LOGS . "` SET `ezprints_order_sent_count` = 1 WHERE `id` = " . $purchase_log['id'] . " LIMIT 1");
            }
            // Decrement the stock here
            if ($purchase_log['processed'] >= 2) {
                wpsc_decrement_claimed_stock($purchase_log['id']);
            }
            if ($purchase_log['discount_data'] != '') {
                $coupon_data = $wpdb->get_row("SELECT * FROM `" . WPSC_TABLE_COUPON_CODES . "` WHERE coupon_code='" . $wpdb->escape($purchase_log['discount_data']) . "' LIMIT 1", ARRAY_A);
                if ($coupon_data['use-once'] == 1) {
                    $wpdb->query("UPDATE `" . WPSC_TABLE_COUPON_CODES . "` SET `active`='0', `is-used`='1' WHERE `id`='" . $coupon_data['id'] . "' LIMIT 1");
                }
            }
            //$wpdb->query("UPDATE `".WPSC_TABLE_DOWNLOAD_STATUS."` SET `active`='1' WHERE `fileid`='".$product_data['file']."' AND `purchid` = '".$purchase_log['id']."' LIMIT 1");
            //if (!isset($_SESSION['quote_shipping']))
            //$total_shipping = nzshpcrt_determine_base_shipping($total_shipping, $shipping_country);
            $total_shipping += $purchase_log['base_shipping'];
            $total = $purchase_log['totalprice'];
            // echo $total;
            // $message.= "\n\r";
            $product_list .= "Your Purchase No.: " . $purchase_log['id'] . "\n\r";
            if ($purchase_log['discount_value'] > 0) {
                $discount_email .= TXT_WPSC_DISCOUNT . "\n\r: ";
                $discount_email .= $purchase_log['discount_data'] . ' : ' . nzshpcrt_currency_display($purchase_log['discount_value'], 1, true) . "\n\r";
            }
            $total_shipping_email .= TXT_WPSC_TOTALSHIPPING . ": " . nzshpcrt_currency_display($total_shipping, 1, true) . "\n\r";
            $total_price_email .= TXT_WPSC_TOTAL . ": " . nzshpcrt_currency_display($total, 1, true) . "\n\r";
            $product_list_html .= "Your Purchase No.: " . $purchase_log['id'] . "\n\n\r";
            if ($purchase_log['discount_value'] > 0) {
                $report .= $discount_email . "\n\r";
                $total_shipping_html .= TXT_WPSC_DISCOUNT . ": " . nzshpcrt_currency_display($purchase_log['discount_value'], 1, true) . "\n\r";
            }
            $total_shipping_html .= TXT_WPSC_TOTALSHIPPING . ": " . nzshpcrt_currency_display($total_shipping, 1, true) . "\n\r";
            $total_price_html .= TXT_WPSC_TOTAL . ": " . nzshpcrt_currency_display($total, 1, true) . "\n\r";
            if (isset($_GET['ti'])) {
                $message .= "\n\r" . TXT_WPSC_YOURTRANSACTIONID . ": " . $_GET['ti'];
                $message_html .= "\n\r" . TXT_WPSC_YOURTRANSACTIONID . ": " . $_GET['ti'];
                $report .= "\n\r" . TXT_WPSC_TRANSACTIONID . ": " . $_GET['ti'];
            } else {
                $report_id = "Purchase No.: " . $purchase_log['id'] . "\n\r";
            }
            //echo "<pre>".print_r($purchase_log,true)."</pre>";
            $message = str_replace('%product_list%', $product_list, $message);
            $message = str_replace('%total_shipping%', $total_shipping_email, $message);
            $message = str_replace('%total_price%', $total_price_email, $message);
            //$message = str_replace('%order_status%',get_option('blogname'),$message);
            $message = str_replace('%shop_name%', get_option('blogname'), $message);
            $report = str_replace('%product_list%', $report_product_list, $report);
            $report = str_replace('%total_shipping%', $total_shipping_email, $report);
            $report = str_replace('%total_price%', $total_price_email, $report);
            $report = str_replace('%shop_name%', get_option('blogname'), $report);
            $message_html = str_replace('%product_list%', $product_list_html, $message_html);
            $message_html = str_replace('%total_shipping%', $total_shipping_html, $message_html);
            $message_html = str_replace('%total_price%', $total_price_email, $message_html);
            $message_html = str_replace('%shop_name%', get_option('blogname'), $message_html);
            //$message_html = str_replace('%order_status%',get_option('blogname'),$message_html);
            if ($email != '' && $purchase_log['email_sent'] != 1) {
                add_filter('wp_mail_from', 'wpsc_replace_reply_address', 0);
                add_filter('wp_mail_from_name', 'wpsc_replace_reply_name', 0);
                if ($purchase_log['processed'] < 2) {
                    $payment_instructions = strip_tags(get_option('payment_instructions'));
                    $message = TXT_WPSC_ORDER_PENDING . "\n\r" . $payment_instructions . "\n\r" . $message;
                    wp_mail($email, TXT_WPSC_ORDER_PENDING_PAYMENT_REQUIRED, $message);
                } else {
                    wp_mail($email, TXT_WPSC_PURCHASERECEIPT, $message);
                }
            }
            remove_filter('wp_mail_from_name', 'wpsc_replace_reply_name');
            remove_filter('wp_mail_from', 'wpsc_replace_reply_address');
            $report_user = TXT_WPSC_CUSTOMERDETAILS . "\n\r";
            $form_sql = "SELECT * FROM `" . WPSC_TABLE_SUBMITED_FORM_DATA . "` WHERE `log_id` = '" . $purchase_log['id'] . "'";
            $form_data = $wpdb->get_results($form_sql, ARRAY_A);
            if ($form_data != null) {
                foreach ($form_data as $form_field) {
                    $form_data = $wpdb->get_row("SELECT * FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` WHERE `id` = '" . $form_field['form_id'] . "' LIMIT 1", ARRAY_A);
                    switch ($form_data['type']) {
                        case "country":
                            $delivery_region_count = $wpdb->get_var("SELECT COUNT(`regions`.`id`) FROM `" . WPSC_TABLE_REGION_TAX . "` AS `regions` INNER JOIN `" . WPSC_TABLE_CURRENCY_LIST . "` AS `country` ON `country`.`id` = `regions`.`country_id` WHERE `country`.`isocode` IN('" . $wpdb->escape($purchase_log['billing_country']) . "')");
                            if (is_numeric($purchase_log['shipping_region']) && $delivery_region_count > 0) {
                                $report_user .= TXT_WPSC_STATE . ": " . wpsc_get_region($purchase_log['billing_region']) . "\n";
                            }
                            $report_user .= $form_data['name'] . ": " . wpsc_get_country($form_field['value']) . "\n";
                            break;
                        case "delivery_country":
                            $delivery_region_count = $wpdb->get_var("SELECT COUNT(`regions`.`id`) FROM `" . WPSC_TABLE_REGION_TAX . "` AS `regions` INNER JOIN `" . WPSC_TABLE_CURRENCY_LIST . "` AS `country` ON `country`.`id` = `regions`.`country_id` WHERE `country`.`isocode` IN('" . $wpdb->escape($purchase_log['shipping_country']) . "')");
                            if (is_numeric($purchase_log['shipping_region']) && $delivery_region_count > 0) {
                                $report_user .= TXT_WPSC_DELIVERY_STATE . ": " . wpsc_get_region($purchase_log['shipping_region']) . "\n";
                            }
                            $report_user .= $form_data['name'] . ": " . wpsc_get_country($form_field['value']) . "\n";
                            break;
                        default:
                            $report_user .= $form_data['name'] . ": " . $form_field['value'] . "\n";
                            break;
                    }
                }
            }
            $report_user .= "\n\r";
            $report = $report_user . $report_id . $report;
            if ($stock_adjusted == true) {
                $wpdb->query("UPDATE `" . WPSC_TABLE_PURCHASE_LOGS . "` SET `stock_adjusted` = '1' WHERE `sessionid` = " . $sessionid . " LIMIT 1");
            }
            if (get_option('purch_log_email') != null && $purchase_log['email_sent'] != 1) {
                wp_mail(get_option('purch_log_email'), TXT_WPSC_PURCHASEREPORT, $report);
            }
            if ($purchase_log['processed'] < 2) {
                echo "<br />" . nl2br(str_replace("\$", '\\$', $message_html));
                return;
            }
            /// Empty the cart
            $wpsc_cart->submit_stock_claims($purchase_log['id']);
            $wpsc_cart->empty_cart();
            if (true === $echo_to_screen) {
                echo '<div class="wrap">';
                if ($sessionid != null) {
                    echo TXT_WPSC_THETRANSACTIONWASSUCCESSFUL . "<br />";
                    echo "<br />" . nl2br(str_replace("\$", '\\$', $message_html));
                }
                echo '</div>';
            }
        } else {
            if (true === $echo_to_screen) {
                echo '<div class="wrap">';
                echo TXT_WPSC_BUYPRODUCTS;
                echo '</div>';
            }
        }
        if ($purchase_log['email_sent'] != 1 and $sessionid != '') {
            if (preg_match("/^[\\w\\s._,-]+\$/", $transaction_id)) {
                $transact_id_sql = "`transactid` = '" . $transaction_id . "',";
            }
            $update_sql = "UPDATE `" . WPSC_TABLE_PURCHASE_LOGS . "` SET {$transact_id_sql} `email_sent` = '1', `processed` = '{$order_status}' WHERE `sessionid` = " . $sessionid . " LIMIT 1";
            $wpdb->query($update_sql);
        }
    }
}
 function wpec_transaction_tracking($push)
 {
     global $wpdb, $purchlogs, $cart_log_id;
     if (!isset($cart_log_id) || empty($cart_log_id)) {
         return $push;
     }
     $city = $wpdb->get_var("SELECT tf.value\n\t\t                               FROM " . WPSC_TABLE_SUBMITED_FORM_DATA . " tf\n\t\t                          LEFT JOIN " . WPSC_TABLE_CHECKOUT_FORMS . " cf\n\t\t                                 ON cf.id = tf.form_id\n\t\t                              WHERE cf.type = 'city'\n\t\t                                AND log_id = " . $cart_log_id);
     $country = $wpdb->get_var("SELECT tf.value\n\t\t                                  FROM " . WPSC_TABLE_SUBMITED_FORM_DATA . " tf\n\t\t                             LEFT JOIN " . WPSC_TABLE_CHECKOUT_FORMS . " cf\n\t\t                                    ON cf.id = tf.form_id\n\t\t                                 WHERE cf.type = 'country'\n\t\t                                   AND log_id = " . $cart_log_id);
     $cart_items = $wpdb->get_results("SELECT * FROM " . WPSC_TABLE_CART_CONTENTS . " WHERE purchaseid = " . $cart_log_id, ARRAY_A);
     $total_shipping = $purchlogs->allpurchaselogs[0]->base_shipping;
     $total_tax = 0;
     foreach ($cart_items as $item) {
         $total_shipping += $item['pnp'];
         $total_tax += $item['tax_charged'];
     }
     $push[] = "'_addTrans','" . $cart_log_id . "'," . "'" . GA_Filter::ga_str_clean(get_bloginfo('name')) . "'," . "'" . nzshpcrt_currency_display($purchlogs->allpurchaselogs[0]->totalprice, 1, true, false, true) . "'," . "'" . nzshpcrt_currency_display($total_tax, 1, true, false, true) . "'," . "'" . nzshpcrt_currency_display($total_shipping, 1, true, false, true) . "'," . "'" . $city . "'," . "''," . "'" . $country . "'";
     // Country
     foreach ($cart_items as $item) {
         $item['sku'] = $wpdb->get_var("SELECT meta_value FROM " . WPSC_TABLE_PRODUCTMETA . " WHERE meta_key = 'sku' AND product_id = '" . $item['prodid'] . "' LIMIT 1");
         $item['category'] = $wpdb->get_var("SELECT pc.name FROM " . WPSC_TABLE_PRODUCT_CATEGORIES . " pc LEFT JOIN " . WPSC_TABLE_ITEM_CATEGORY_ASSOC . " ca ON pc.id = ca.category_id WHERE pc.group_id = '1' AND ca.product_id = '" . $item['prodid'] . "'");
         $push[] = "'_addItem'," . "'" . $cart_log_id . "'," . "'" . $item['sku'] . "'," . "'" . str_replace("'", "", $item['name']) . "'," . "'" . $item['category'] . "'," . "'" . $item['price'] . "'," . "'" . $item['quantity'] . "'";
         // Item Quantity
     }
     $push[] = "'_trackTrans'";
     return $push;
 }
Exemplo n.º 10
0
/**
 * Purchase log ajax code starts here
*/
function wpsc_purchlog_resend_email()
{
    global $wpdb;
    $siteurl = get_option('siteurl');
    $log_id = $_GET['email_buyer_id'];
    if (is_numeric($log_id)) {
        $selectsql = "SELECT * FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE `id`= " . $log_id . " LIMIT 1";
        $purchase_log = $wpdb->get_row($selectsql, ARRAY_A);
        if ($purchase_log['gateway'] == "testmode" && $purchase_log['processed'] < 2) {
            $message = get_option("wpsc_email_receipt");
            $message_html = "<h2  style='font-size:16px;font-weight:bold;color:#000;border:0px;padding-top: 0px;' >" . __('Your Order', 'wpsc') . "</h2>";
        } else {
            $message = get_option("wpsc_email_receipt");
            $message_html = $message;
        }
        $order_url = $siteurl . "/wp-admin/admin.php?page=" . WPSC_DIR_NAME . "/display-log.php&amp;purchcaseid=" . $purchase_log['id'];
        $cartsql = "SELECT * FROM `" . WPSC_TABLE_CART_CONTENTS . "` WHERE `purchaseid`=" . $purchase_log['id'] . "";
        $cart = $wpdb->get_results($cartsql, ARRAY_A);
        if ($purchase_log['shipping_country'] != '') {
            $billing_country = $purchase_log['billing_country'];
            $shipping_country = $purchase_log['shipping_country'];
        } else {
            $country = $wpdb->get_results("SELECT * FROM `" . WPSC_TABLE_SUBMITED_FORM_DATA . "` WHERE `log_id`=" . $purchase_log['id'] . " AND `form_id` = '" . get_option('country_form_field') . "' LIMIT 1", ARRAY_A);
            $billing_country = $country[0]['value'];
            $shipping_country = $country[0]['value'];
        }
        $email_form_field = $wpdb->get_results("SELECT `id`,`type` FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` WHERE `type` IN ('email') AND `active` = '1' ORDER BY `order` ASC LIMIT 1", ARRAY_A);
        $email_address = $wpdb->get_results("SELECT * FROM `" . WPSC_TABLE_SUBMITED_FORM_DATA . "` WHERE `log_id`=" . $purchase_log['id'] . " AND `form_id` = '" . $email_form_field[0]['id'] . "' LIMIT 1", ARRAY_A);
        $email = $email_address[0]['value'];
        $previous_download_ids = array(0);
        if ($cart != null) {
            foreach ($cart as $row) {
                $link = "";
                $productsql = "SELECT * FROM `" . WPSC_TABLE_PRODUCT_LIST . "` WHERE `id`=" . $row['prodid'] . "";
                $product_data = $wpdb->get_results($productsql, ARRAY_A);
                if ($product_data[0]['file'] > 0) {
                    if ($purchase_log['email_sent'] != 1) {
                        $wpdb->query("UPDATE `" . WPSC_TABLE_DOWNLOAD_STATUS . "` SET `active`='1' WHERE `fileid`='" . $product_data[0]['file'] . "' AND `purchid` = '" . $purchase_log['id'] . "' LIMIT 1");
                    }
                    if ($purchase_log['processed'] >= 2) {
                        $download_data = $wpdb->get_results("SELECT *\r\n\t\t\t\t\t\tFROM `" . WPSC_TABLE_DOWNLOAD_STATUS . "` INNER JOIN `" . WPSC_TABLE_PRODUCT_FILES . "`\r\n\t\t\t\t\t\tON `" . WPSC_TABLE_DOWNLOAD_STATUS . "`.`fileid` = `" . WPSC_TABLE_PRODUCT_FILES . "`.`id`\r\n\t\t\t\t\t\tWHERE `" . WPSC_TABLE_DOWNLOAD_STATUS . "`.`active`='1'\r\n\t\t\t\t\t\tAND `" . WPSC_TABLE_DOWNLOAD_STATUS . "`.`purchid`='" . $purchase_log['id'] . "'\r\n\t\t\t\t\t\tAND (\r\n\t\t\t\t\t\t\t`" . WPSC_TABLE_DOWNLOAD_STATUS . "`.`cartid` = '" . $row['id'] . "'\r\n\t\t\t\t\t\t\tOR (\r\n\t\t\t\t\t\t\t\t`" . WPSC_TABLE_DOWNLOAD_STATUS . "`.`cartid` IS NULL\r\n\t\t\t\t\t\t\t\tAND `" . WPSC_TABLE_DOWNLOAD_STATUS . "`.`fileid` = '{$product_data['file']}'\r\n\t\t\t\t\t\t\t)\r\n\t\t\t\t\t\t)\r\n\t\t\t\t\t\t AND `" . WPSC_TABLE_DOWNLOAD_STATUS . "`.`id` NOT IN ('" . implode("','", $previous_download_ids) . "')", ARRAY_A);
                        $link = array();
                        //exit('IM HERE'.$errorcode.'<pre>'.print_r($download_data).'</pre>');
                        if (sizeof($download_data) != 0) {
                            foreach ($download_data as $single_download) {
                                if ($single_download['uniqueid'] == null) {
                                    // if the uniqueid is not equal to null, its "valid", regardless of what it is
                                    $link[] = array("url" => $siteurl . "?downloadid=" . $single_download['id'], "name" => $single_download["filename"]);
                                } else {
                                    $link[] = array("url" => $siteurl . "?downloadid=" . $single_download['uniqueid'], "name" => $single_download["filename"]);
                                }
                            }
                        }
                        $previous_download_ids[] = $download_data['id'];
                        $order_status = 4;
                    }
                }
                do_action('wpsc_confirm_checkout', $purchase_log['id']);
                $shipping = nzshpcrt_determine_item_shipping($row['prodid'], $row['quantity'], $shipping_country);
                if (isset($_SESSION['quote_shipping'])) {
                    $shipping = $_SESSION['quote_shipping'];
                }
                $total_shipping += $shipping;
                if ($product_data[0]['special'] == 1) {
                    $price_modifier = $product_data[0]['special_price'];
                } else {
                    $price_modifier = 0;
                }
                $total += $row['price'] * $row['quantity'];
                $message_price = nzshpcrt_currency_display($row['price'] * $row['quantity'], $product_data[0]['notax'], true);
                $shipping_price = nzshpcrt_currency_display($shipping, 1, true);
                $variation_sql = "SELECT * FROM `" . WPSC_TABLE_CART_ITEM_VARIATIONS . "` WHERE `cart_id`='" . $row['id'] . "'";
                $variation_data = $wpdb->get_results($variation_sql, ARRAY_A);
                $variation_count = count($variation_data);
                if ($variation_count > 1) {
                    $variation_list = " (";
                    if ($purchase['gateway'] != 'testmode') {
                        if ($gateway['internalname'] == $purch_data[0]['gateway']) {
                            $gateway_name = $gateway['name'];
                        }
                    } else {
                        $gateway_name = "Manual Payment";
                    }
                    $i = 0;
                    foreach ($variation_data as $variation) {
                        if ($i > 0) {
                            $variation_list .= ", ";
                        }
                        $value_id = $variation['value_id'];
                        $value_data = $wpdb->get_results("SELECT * FROM `" . WPSC_TABLE_VARIATION_VALUES . "` WHERE `id`='" . $value_id . "' LIMIT 1", ARRAY_A);
                        $variation_list .= $value_data[0]['name'];
                        $i++;
                    }
                    $variation_list .= ")";
                } else {
                    if ($variation_count == 1) {
                        $value_id = $variation_data[0]['value_id'];
                        $value_data = $wpdb->get_results("SELECT * FROM `" . WPSC_TABLE_VARIATION_VALUES . "` WHERE `id`='" . $value_id . "' LIMIT 1", ARRAY_A);
                        $variation_list = " (" . $value_data[0]['name'] . ")";
                    } else {
                        $variation_list = '';
                    }
                }
                if ($link != '') {
                    $product_list .= " - " . $product_data['name'] . stripslashes($variation_list) . "  " . $message_price . " " . __('Click to download', 'wpsc') . ":";
                    $product_list_html .= " - " . $product_data['name'] . stripslashes($variation_list) . "  " . $message_price . "&nbsp;&nbsp;" . __('Click to download', 'wpsc') . ":\n\r";
                    foreach ($link as $single_link) {
                        $product_list .= "\n\r " . $single_link["name"] . ": " . $single_link["url"] . "\n\r";
                        $product_list_html .= "<a href='" . $single_link["url"] . "'>" . $single_link["name"] . "</a>\n";
                    }
                } else {
                    $plural = '';
                    if ($row['quantity'] > 1) {
                        $plural = "s";
                    }
                    $product_list .= " - " . $row['quantity'] . " " . $product_data[0]['name'] . $variation_list . "  " . $message_price . "\n";
                    if ($shipping > 0) {
                        $product_list .= " - " . __('Shipping', 'wpsc') . ":" . $shipping_price . "\n\r";
                    }
                    $product_list_html .= " - " . $row['quantity'] . " " . $product_data[0]['name'] . $variation_list . "  " . $message_price . "\n";
                    if ($shipping > 0) {
                        $product_list_html .= " - " . __('Shipping', 'wpsc') . ":" . $shipping_price . "\n\r";
                    }
                }
                $report .= " - " . $product_data[0]['name'] . $variation_list . "  " . $message_price . "\n";
            }
            if ($purchase_log['discount_data'] != '') {
                $coupon_data = $wpdb->get_row("SELECT * FROM `" . WPSC_TABLE_COUPON_CODES . "` WHERE coupon_code='" . $wpdb->escape($purchase_log['discount_data']) . "' LIMIT 1", ARRAY_A);
                if ($coupon_data['use-once'] == 1) {
                    $wpdb->query("UPDATE `" . WPSC_TABLE_COUPON_CODES . "` SET `active`='0', `is-used`='1' WHERE `id`='" . $coupon_data['id'] . "' LIMIT 1");
                }
            }
            //$wpdb->query("UPDATE `".WPSC_TABLE_DOWNLOAD_STATUS."` SET `active`='1' WHERE `fileid`='".$product_data[0]['file']."' AND `purchid` = '".$purchase_log['id']."' LIMIT 1");
            $total_shipping += $purchase_log['base_shipping'];
            $total = $total + $total_shipping - $purchase_log['discount_value'];
            // $message.= "\n\r";
            $product_list .= "Your Purchase No.: " . $purchase_log['id'] . "\n\r";
            if ($purchase_log['discount_value'] > 0) {
                $discount_email .= __('Discount', 'wpsc') . ": " . nzshpcrt_currency_display($purchase_log['discount_value'], 1, true) . "\n\r";
            }
            $total_shipping_email .= __('Total Shipping', 'wpsc') . ": " . nzshpcrt_currency_display($total_shipping, 1, true) . "\n\r";
            $total_price_email .= __('Total', 'wpsc') . ": " . nzshpcrt_currency_display($total, 1, true) . "\n\r";
            $product_list_html .= "Your Purchase No.: " . $purchase_log['id'] . "\n\n\r";
            if ($purchase_log['discount_value'] > 0) {
                $discount_html .= __('Discount', 'wpsc') . ": " . nzshpcrt_currency_display($purchase_log['discount_value'], 1, true) . "\n\r";
            }
            $total_shipping_html .= __('Total Shipping', 'wpsc') . ": " . nzshpcrt_currency_display($total_shipping, 1, true) . "\n\r";
            $total_price_html .= __('Total', 'wpsc') . ": " . nzshpcrt_currency_display($total, 1, true) . "\n\r";
            if (isset($_GET['ti'])) {
                $message .= "\n\r" . __('Your Transaction ID', 'wpsc') . ": " . $_GET['ti'];
                $message_html .= "\n\r" . __('Your Transaction ID', 'wpsc') . ": " . $_GET['ti'];
                $report .= "\n\r" . __('Transaction ID', 'wpsc') . ": " . $_GET['ti'];
            } else {
                $report_id = "Purchase No.: " . $purchase_log['id'] . "\n\r";
            }
            $message = str_replace('%product_list%', $product_list, $message);
            $message = str_replace('%total_shipping%', $total_shipping_email, $message);
            $message = str_replace('%total_price%', $total_price_email, $message);
            //$message = str_replace('%order_status%',get_option('blogname'),$message);
            $message = str_replace('%shop_name%', get_option('blogname'), $message);
            $report = str_replace('%product_list%', $report_product_list, $report);
            $report = str_replace('%total_shipping%', $total_shipping_email, $report);
            $report = str_replace('%total_price%', $total_price_email, $report);
            $report = str_replace('%shop_name%', get_option('blogname'), $report);
            $message_html = str_replace('%product_list%', $product_list_html, $message_html);
            $message_html = str_replace('%total_shipping%', $total_shipping_html, $message_html);
            $message_html = str_replace('%total_price%', $total_price_email, $message_html);
            $message_html = str_replace('%shop_name%', get_option('blogname'), $message_html);
            //	exit($message_html);
            if ($email != '') {
                add_filter('wp_mail_from', 'wpsc_replace_reply_address', 0);
                add_filter('wp_mail_from_name', 'wpsc_replace_reply_name', 0);
                if ($purchase_log['processed'] < 2) {
                    $payment_instructions = strip_tags(get_option('payment_instructions'));
                    $message = __('Thank you, your purchase is pending, you will be sent an email once the order clears.', 'wpsc') . "\n\r" . $payment_instructions . "\n\r" . $message;
                    $resent = (bool) wp_mail($email, __('Order Pending: Payment Required', 'wpsc'), $message);
                    $sent = 1;
                } else {
                    $resent = (bool) wp_mail($email, __('Purchase Receipt', 'wpsc'), $message);
                    $sent = 1;
                }
                //echo "$message<br />";
                //exit($email);
                remove_filter('wp_mail_from_name', 'wpsc_replace_reply_name');
                remove_filter('wp_mail_from', 'wpsc_replace_reply_address');
            }
        }
    }
    $sendback = wp_get_referer();
    if (isset($sent)) {
        $sendback = add_query_arg('sent', $sent, $sendback);
    }
    wp_redirect($sendback);
    exit;
}
Exemplo n.º 11
0
function wpsc_packing_slip($purchase_id)
{
    global $wpdb;
    $purch_sql = "SELECT * FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE `id`='" . $purchase_id . "'";
    $purch_data = $wpdb->get_row($purch_sql, ARRAY_A);
    //echo "<p style='padding-left: 5px;'><strong>".TXT_WPSC_DATE."</strong>:".date("jS M Y", $purch_data['date'])."</p>";
    $cartsql = "SELECT * FROM `" . WPSC_TABLE_CART_CONTENTS . "` WHERE `purchaseid`=" . $purchase_id . "";
    $cart_log = $wpdb->get_results($cartsql, ARRAY_A);
    $j = 0;
    if ($cart_log != null) {
        echo "<div class='packing_slip'>\n\r";
        echo "<h2>" . TXT_WPSC_PACKING_SLIP . "</h2>\n\r";
        echo "<strong>" . TXT_WPSC_ORDER . " #</strong> " . $purchase_id . "<br /><br />\n\r";
        echo "<table>\n\r";
        $form_sql = "SELECT * FROM `" . WPSC_TABLE_SUBMITED_FORM_DATA . "` WHERE  `log_id` = '" . (int) $purchase_id . "'";
        $input_data = $wpdb->get_results($form_sql, ARRAY_A);
        foreach ($input_data as $input_row) {
            $rekeyed_input[$input_row['form_id']] = $input_row;
        }
        if ($input_data != null) {
            $form_data = $wpdb->get_results("SELECT * FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` WHERE `active` = '1'", ARRAY_A);
            foreach ($form_data as $form_field) {
                switch ($form_field['type']) {
                    case 'country':
                        $delivery_region_count = $wpdb->get_var("SELECT COUNT(`regions`.`id`) FROM `" . WPSC_TABLE_REGION_TAX . "` AS `regions` INNER JOIN `" . WPSC_TABLE_CURRENCY_LIST . "` AS `country` ON `country`.`id` = `regions`.`country_id` WHERE `country`.`isocode` IN('" . $wpdb->escape($purch_data['billing_country']) . "')");
                        if (is_numeric($purch_data['shipping_region']) && $delivery_region_count > 0) {
                            echo "  <tr><td>" . __('State', 'wpsc') . ":</td><td>" . wpsc_get_region($purch_data['shipping_region']) . "</td></tr>\n\r";
                        }
                        echo "  <tr><td>" . wp_kses($form_field['name'], array()) . ":</td><td>" . wpsc_get_country($purch_data['billing_country']) . "</td></tr>\n\r";
                        break;
                    case 'delivery_country':
                        echo "  <tr><td>" . wp_kses($form_field['name'], array()) . ":</td><td>" . wpsc_get_country($purch_data['shipping_country']) . "</td></tr>\n\r";
                        break;
                    case 'heading':
                        echo "  <tr><td colspan='2'><strong>" . wp_kses($form_field['name'], array()) . ":</strong></td></tr>\n\r";
                        break;
                    default:
                        echo "  <tr><td>" . wp_kses($form_field['name'], array()) . ":</td><td>" . htmlentities(stripslashes($rekeyed_input[$form_field['id']]['value']), ENT_QUOTES) . "</td></tr>\n\r";
                        break;
                }
            }
        } else {
            echo "  <tr><td>" . TXT_WPSC_NAME . ":</td><td>" . $purch_data['firstname'] . " " . $purch_data['lastname'] . "</td></tr>\n\r";
            echo "  <tr><td>" . TXT_WPSC_ADDRESS . ":</td><td>" . $purch_data['address'] . "</td></tr>\n\r";
            echo "  <tr><td>" . TXT_WPSC_PHONE . ":</td><td>" . $purch_data['phone'] . "</td></tr>\n\r";
            echo "  <tr><td>" . TXT_WPSC_EMAIL . ":</td><td>" . $purch_data['email'] . "</td></tr>\n\r";
        }
        if (get_option('payment_method') == 2) {
            $gateway_name = '';
            foreach ($GLOBALS['nzshpcrt_gateways'] as $gateway) {
                if ($purch_data['gateway'] != 'testmode') {
                    if ($gateway['internalname'] == $purch_data['gateway']) {
                        $gateway_name = $gateway['name'];
                    }
                } else {
                    $gateway_name = "Manual Payment";
                }
            }
        }
        // 			echo "  <tr><td colspan='2'></td></tr>\n\r";
        // 			echo "  <tr><td>".TXT_WPSC_PAYMENT_METHOD.":</td><td>".$gateway_name."</td></tr>\n\r";
        // 			//echo "  <tr><td>".TXT_WPSC_PURCHASE_NUMBER.":</td><td>".$purch_data['id']."</td></tr>\n\r";
        // 			echo "  <tr><td>".TXT_WPSC_HOWCUSTOMERFINDUS.":</td><td>".$purch_data['find_us']."</td></tr>\n\r";
        // 			$engrave_line = explode(",",$purch_data['engravetext']);
        // 			echo "  <tr><td>".TXT_WPSC_ENGRAVE."</td><td></td></tr>\n\r";
        // 			echo "  <tr><td>".TXT_WPSC_ENGRAVE_LINE_ONE.":</td><td>".$engrave_line[0]."</td></tr>\n\r";
        // 			echo "  <tr><td>".TXT_WPSC_ENGRAVE_LINE_TWO.":</td><td>".$engrave_line[1]."</td></tr>\n\r";
        // 			if($purch_data['transactid'] != '') {
        // 				echo "  <tr><td>".TXT_WPSC_TXN_ID.":</td><td>".$purch_data['transactid']."</td></tr>\n\r";
        // 			}
        echo "</table>\n\r";
        echo "<table class='packing_slip'>";
        echo "<tr>";
        echo " <th>" . TXT_WPSC_QUANTITY . " </th>";
        echo " <th>" . TXT_WPSC_NAME . "</th>";
        echo " <th>" . TXT_WPSC_PRICE . " </th>";
        echo " <th>" . TXT_WPSC_SHIPPING . " </th>";
        echo '<th>Tax</th>';
        echo '</tr>';
        $endtotal = 0;
        $all_donations = true;
        $all_no_shipping = true;
        $file_link_list = array();
        foreach ($cart_log as $cart_row) {
            $alternate = "";
            $j++;
            if ($j % 2 != 0) {
                $alternate = "class='alt'";
            }
            $productsql = "SELECT * FROM `" . WPSC_TABLE_PRODUCT_LIST . "` WHERE `id`=" . $cart_row['prodid'] . "";
            $product_data = $wpdb->get_results($productsql, ARRAY_A);
            $variation_sql = "SELECT * FROM `" . WPSC_TABLE_CART_ITEM_VARIATIONS . "` WHERE `cart_id`='" . $cart_row['id'] . "'";
            $variation_data = $wpdb->get_results($variation_sql, ARRAY_A);
            $variation_count = count($variation_data);
            if ($variation_count > 1) {
                $variation_list = " (";
                $i = 0;
                foreach ($variation_data as $variation) {
                    if ($i > 0) {
                        $variation_list .= ", ";
                    }
                    $value_id = $variation['value_id'];
                    $value_data = $wpdb->get_results("SELECT * FROM `" . WPSC_TABLE_VARIATION_VALUES . "` WHERE `id`='" . $value_id . "' LIMIT 1", ARRAY_A);
                    $variation_list .= $value_data[0]['name'];
                    $i++;
                }
                $variation_list .= ")";
            } else {
                if ($variation_count == 1) {
                    $value_id = $variation_data[0]['value_id'];
                    $value_data = $wpdb->get_results("SELECT * FROM `" . WPSC_TABLE_VARIATION_VALUES . "` WHERE `id`='" . $value_id . "' LIMIT 1", ARRAY_A);
                    $variation_list = " (" . $value_data[0]['name'] . ")";
                } else {
                    $variation_list = '';
                }
            }
            if ($cart_row['donation'] != 1) {
                $all_donations = false;
            }
            if ($cart_row['no_shipping'] != 1) {
                $shipping = $cart_row['pnp'] * $cart_row['quantity'];
                $total_shipping += $shipping;
                $all_no_shipping = false;
            } else {
                $shipping = 0;
            }
            $price = $cart_row['price'] * $cart_row['quantity'];
            $gst = $price - $price / (1 + $cart_row['gst'] / 100);
            if ($gst > 0) {
                $tax_per_item = $gst / $cart_row['quantity'];
            }
            echo "<tr {$alternate}>";
            echo " <td>";
            echo $cart_row['quantity'];
            echo " </td>";
            echo " <td>";
            echo $product_data[0]['name'];
            echo stripslashes($variation_list);
            echo " </td>";
            echo " <td>";
            echo nzshpcrt_currency_display($price, 1);
            echo " </td>";
            echo " <td>";
            echo nzshpcrt_currency_display($shipping, 1);
            echo " </td>";
            echo '<td>';
            echo nzshpcrt_currency_display($cart_row['tax_charged'], 1);
            echo '<td>';
            echo '</tr>';
        }
        echo "</table>";
        echo "</div>\n\r";
    } else {
        echo "<br />" . TXT_WPSC_USERSCARTWASEMPTY;
    }
}
function wpsc_display_purchlog_totalprice()
{
    global $purchlogitem;
    $purchlogitem->totalAmount -= wpsc_display_purchlog_discount(true);
    $purchlogitem->totalAmount += wpsc_display_purchlog_shipping(true);
    //$purchlogitem->totalAmount += $purchlogitem->extrainfo->base_shipping;
    return nzshpcrt_currency_display($purchlogitem->extrainfo->totalprice, true);
}
Exemplo n.º 13
0
function nzshpcrt_specials($input = null)
{
    global $wpdb;
    $siteurl = SITEURL;
    $sql = "SELECT * FROM `wp_product_list` WHERE `special` = '1'  LIMIT 1";
    $product = $wpdb->get_results($sql, ARRAY_A);
    if ($product != null) {
        $output = "<div id='sideshoppingcart'><div id='shoppingcartcontents'><h2>" . TXT_WPSC_SPECIALS . "</h2><br \\>";
        foreach ($product as $special) {
            $output .= "<strong>" . $special['name'] . "</strong><br /> ";
            if ($special['image'] != null) {
                $output .= "<img src='http://th.cartoonbank.ru/" . $special['image'] . "' title='" . $special['name'] . "' alt='" . $special['name'] . "' /><br />";
            }
            $output .= $special['description'] . "<br />";
            $output .= "<span class='oldprice'>" . nzshpcrt_currency_display($special['price'], $special['notax'], false) . "</span><br />";
            //       $output .= $special['price'];
            $variations_procesor = new nzshpcrt_variations();
            $output .= $variations_procesor->display_product_variations($product['id']);
            $output .= nzshpcrt_currency_display($special['price'], $special['notax'], false, $special['id']) . "<br />";
            $output .= "<form id='specials' name='{$num}' method='POST' action='#' onsubmit='submitform(this);return false;' >";
            $output .= "<input type='hidden' name='prodid' value='" . $special['id'] . "'>";
            $output .= "<input type='hidden' name='item' value='" . $special['id'] . "' />";
            //    $output .= "<input type='submit' name='Buy' value='".TXT_WPSC_BUY."'  />";
            if ($special['quantity_limited'] == 1 && $special['quantity'] < 1) {
                $output .= TXT_WPSC_PRODUCTSOLDOUT . "";
            } else {
                $output .= $variations_procesor->display_product_variations($special['id'], true);
                $output .= "<input type='submit' name='" . TXT_WPSC_ADDTOCART . "' value='" . TXT_WPSC_ADDTOCART . "'  />";
            }
            $output .= "</form>";
        }
        $output .= "</div></div>";
    } else {
        $output = '';
    }
    echo $input . $output;
}
Exemplo n.º 14
0
 function product_display_list($product_list, $group_type, $group_sql = '', $search_sql = '')
 {
     global $wpdb;
     $siteurl = get_option('siteurl');
     if ((double) WPSC_VERSION < 3.8) {
         $images_dir = 'images';
     } else {
         $images_dir = 'wpsc-core/images';
     }
     if (get_option('permalink_structure') != '') {
         $seperator = "?";
     } else {
         $seperator = "&amp;";
     }
     $product_listing_data = wpsc_get_product_listing($product_list, $group_type, $group_sql, $search_sql);
     $product_list = $product_listing_data['product_list'];
     $output .= $product_listing_data['page_listing'];
     if ($product_listing_data['category_id']) {
         $category_nice_name = $wpdb->get_var("SELECT `nice-name` FROM `" . WPSC_TABLE_PRODUCT_CATEGORIES . "` WHERE `id` ='" . (int) $product_listing_data['category_id'] . "' LIMIT 1");
     } else {
         $category_nice_name = '';
     }
     if ($product_list != null) {
         $output .= "<table class='list_productdisplay {$category_nice_name}'>";
         $i = 0;
         foreach ($product_list as $product) {
             $num++;
             if ($i % 2 == 1) {
                 $output .= "    <tr class='product_view_{$product['id']}'>";
             } else {
                 $output .= "    <tr class='product_view_{$product['id']}' style='background-color:#EEEEEE'>";
             }
             $i++;
             $output .= "      <td style='width: 9px;'>";
             if ($product['description'] != null) {
                 $output .= "<a href='#' class='additional_description_link' onclick='return show_additional_description(\"list_description_" . $product['id'] . "\",\"link_icon" . $product['id'] . "\");'>";
                 $output .= "<img style='margin-top:3px;' id='link_icon" . $product['id'] . "' src='{$siteurl}/wp-content/plugins/" . WPSC_DIR_NAME . "/" . $images_dir . "/icon_window_expand.gif' title='" . $product['name'] . "' alt='" . $product['name'] . "' />";
                 $output .= "</a>";
             }
             $output .= "      </td>\n\r";
             $output .= "      <td width='55%'>";
             if ($product['special'] == 1) {
                 $special = "<strong class='special'>" . TXT_WPSC_SPECIAL . " - </strong>";
             } else {
                 $special = "";
             }
             $output .= "<a href='" . wpsc_product_url($product['id']) . "' class='wpsc_product_title' ><strong>" . stripslashes($product['name']) . "</strong></a>";
             $output .= "      </td>";
             $variations_procesor = new nzshpcrt_variations();
             $variations_output = $variations_procesor->display_product_variations($product['id'], false, false, true);
             if ($variations_output[1] !== null) {
                 $product['price'] = $variations_output[1];
             }
             $output .= "      <td width='10px' style='text-align: center;'>";
             if ($product['quantity'] < 1 && $product['quantity_limited'] == 1) {
                 $output .= "<img style='margin-top:5px;' src='{$siteurl}/wp-content/plugins/" . WPSC_DIR_NAME . "/" . $images_dir . "/no_stock.gif' title='No' alt='No' />";
             } else {
                 $output .= "<img style='margin-top:4px;' src='{$siteurl}/wp-content/plugins/" . WPSC_DIR_NAME . "/" . $images_dir . "/yes_stock.gif' title='Yes' alt='Yes' />";
             }
             $output .= "      </td>";
             $output .= "      <td width='10%'>";
             if ($product['special'] == 1 && $variations_output[1] === null) {
                 $output .= nzshpcrt_currency_display($product['price'] - $product['special_price'], $product['notax'], false, $product['id']) . "<br />";
             } else {
                 $output .= "<span id='product_price_" . $product['id'] . "'>" . nzshpcrt_currency_display($product['price'], $product['notax']) . "</span>";
             }
             $output .= "      </td>";
             $output .= "      <td width='20%'>";
             if (get_option('addtocart_or_buynow') == '0') {
                 $output .= "<form name='{$num}'  id='product_" . $product['id'] . "'  method='POST' action='" . get_option('product_list_url') . $seperator . "category=" . $_GET['category'] . "' onsubmit='submitform(this);return false;' >";
             }
             if (get_option('list_view_quantity') == 1) {
                 $output .= "<input type='text' name='quantity' value='1' size='3' maxlength='3'>&nbsp;";
             }
             $output .= $variations_output[0];
             $output .= "<input type='hidden' name='item' value='" . $product['id'] . "' />";
             $output .= "<input type='hidden' name='prodid' value='" . $product['id'] . "'>";
             if (get_option('wpsc_selected_theme') == 'iShop') {
                 if (get_option('addtocart_or_buynow') == '0') {
                     if ($product['quantity_limited'] == 1 && $product['quantity'] < 1) {
                         $output .= "<input disabled='true' type='submit' value='' name='Buy' class='wpsc_buy_button'/>";
                     } else {
                         $output .= "<input type='submit' name='Buy' value='' class='wpsc_buy_button'/>";
                     }
                 } else {
                     if (!($product['quantity_limited'] == 1 && $product['quantity'] < 1)) {
                         $output .= google_buynow($product['id']);
                     }
                 }
             } else {
                 if (get_option('addtocart_or_buynow') == '0') {
                     if ($product['quantity_limited'] == 1 && $product['quantity'] < 1) {
                         $output .= "<input disabled='true' type='submit' name='Buy' class='wpsc_buy_button'  value='" . TXT_WPSC_ADDTOCART . "'  />";
                     } else {
                         $output .= "<input type='submit' name='Buy' class='wpsc_buy_button'  value='" . TXT_WPSC_ADDTOCART . "'  />";
                     }
                 } else {
                     if (!($product['quantity_limited'] == 1 && $product['quantity'] < 1)) {
                         $output .= google_buynow($product['id']);
                     }
                 }
             }
             $output .= "</form>";
             $output .= "      </td>\n\r";
             $output .= "    </tr>\n\r";
             $output .= "    <tr class='list_view_description'>\n\r";
             $output .= "      <td colspan='5'>\n\r";
             $output .= "        <div id='list_description_" . $product['id'] . "'>\n\r";
             $output .= $product['description'];
             $output .= "        </div>\n\r";
             $output .= "      </td>\n\r";
             $output .= "    </tr>\n\r";
         }
         $output .= "</table>";
     } else {
         $output .= "<p>" . TXT_WPSC_NOITEMSINTHIS . " " . $group_type . ".</p>";
     }
     return $output;
 }
Exemplo n.º 15
0
function nzshpcrt_overall_total_price($country_code = null, $for_display = false, $no_discount = false, $total_checkbox = 0)
{
    /*
     * Determines the total in the shopping cart, adds the tax and shipping if a country code is supplied and adds the discount of a coupon code is present
     * Adds a dollar sign and information if there is no tax and shipping if $for_display is true
     */
    global $wpdb;
    $cart =& $_SESSION['nzshpcrt_cart'];
    $total_quantity = 0;
    $total_weight = 0;
    $all_donations = true;
    $all_no_shipping = true;
    foreach ($cart as $cart_item) {
        $product_id = $cart_item->product_id;
        $quantity = $cart_item->quantity;
        $product_variations = $cart_item->product_variations;
        $extras = $cart_item->extras;
        $extras_count = count($extras);
        $raw_price = 0;
        $variation_count = count($product_variations);
        if ($variation_count > 0) {
            foreach ($product_variations as $product_variation) {
                $value_id = $product_variation;
                $value_data = $wpdb->get_results("SELECT * FROM `" . $wpdb->prefix . "variation_values` WHERE `id`='" . $value_id . "' LIMIT 1", ARRAY_A);
            }
        }
        //$total_quantity += $quantity;
        $sql = "SELECT * FROM `" . $wpdb->prefix . "product_list` WHERE `id` = '{$product_id}' LIMIT 1";
        $product = $wpdb->get_row($sql, ARRAY_A);
        if ($product['donation'] == 1) {
            $price = $quantity * $cart_item->donation_price;
        } else {
            $price = $quantity * calculate_product_price($product_id, $product_variations, 'stay', $extras);
            if ($country_code != null) {
                if ($product['notax'] != 1) {
                    $price = nzshpcrt_calculate_tax($price, $_SESSION['selected_country'], $_SESSION['selected_region']);
                }
                $shipping = nzshpcrt_determine_item_shipping($product_id, $quantity, $country_code);
                $price += $shipping;
            }
            $all_donations = false;
        }
        if ($product['no_shipping'] != 1) {
            $all_no_shipping = false;
        }
        $total += $price;
    }
    if ($country_code != null && $all_donations == false && $all_no_shipping == false) {
        //echo $_SESSION['selected_country'];
        //exit(nzshpcrt_determine_base_shipping(0, $country_code));
        $total += nzshpcrt_determine_base_shipping(0, $_SESSION['delivery_country']);
    }
    if (!empty($_SESSION['coupon_num']) && $no_discount !== true) {
        $total += nzshpcrt_apply_coupon($total, $_SESSION['coupon_num']) - $total;
    }
    if ($for_display === true) {
        $total = nzshpcrt_currency_display($total, 1);
        if ($country_code == null && get_option('add_plustax') == 1) {
            $total .= "<span class='pluspostagetax'> + " . TXT_WPSC_POSTAGE_AND_TAX . "</span>";
        }
    }
    return $total;
}
Exemplo n.º 16
0
function wpsc_admin_products_list($category_id = 0)
{
    global $wpdb, $_wp_column_headers;
    // set is_sortable to false to start with
    $is_sortable = false;
    $page = null;
    $search_input = '';
    if ($_GET['search']) {
        $search_input = stripslashes($_GET['search']);
        $search_string = "%" . $wpdb->escape($search_input) . "%";
        $search_sql = "AND (`products`.`name` LIKE '" . $search_string . "' OR `products`.`description` LIKE '" . $search_string . "')";
    } else {
        $search_sql = '';
    }
    $search_sql = apply_filters('wpsc_admin_products_list_search_sql', $search_sql);
    if ($category_id > 0) {
        // if we are getting items from only one category, this is a monster SQL query to do this with the product order
        $sql = "SELECT `products`.`id` , `products`.`name` , `products`.`price` , `products`.`image`,`products`.`weight` , `products`.`publish`, `categories`.`category_id`,`order`.`order`, IF(ISNULL(`order`.`order`), 0, 1) AS `order_state`\r\n\t\t\tFROM `" . WPSC_TABLE_PRODUCT_LIST . "` AS `products`\r\n\t\t\tLEFT JOIN `" . WPSC_TABLE_ITEM_CATEGORY_ASSOC . "` AS `categories` ON `products`.`id` = `categories`.`product_id` \r\n\t\t\tLEFT JOIN `" . WPSC_TABLE_PRODUCT_ORDER . "` AS `order` ON ( \r\n\t\t\t\t(\t`products`.`id` = `order`.`product_id` )\r\n\t\t\tAND \r\n\t\t\t\t( `categories`.`category_id` = `order`.`category_id` )\r\n\t\t\t)\r\n\t\t\tWHERE `products`.`active` = '1' {$search_sql}\r\n\t\t\tAND `categories`.`category_id` \r\n\t\t\tIN (\r\n\t\t\t'" . $category_id . "'\r\n\t\t\t)\r\n\t\t\tORDER BY `order_state` DESC,`order`.`order` ASC,  `products`.`date_added` DESC,  `products`.`id` DESC";
        // if we are selecting a category, set is_sortable to true
        $is_sortable = true;
    } else {
        $itempp = 10;
        if ($_GET['pageno'] != 'all') {
            if ($_GET['pageno'] > 0) {
                $page = absint($_GET['pageno']);
            } else {
                $page = 1;
            }
            $start = (int) ($page * $itempp) - $itempp;
            $sql = "SELECT DISTINCT * FROM `" . WPSC_TABLE_PRODUCT_LIST . "` AS `products` WHERE `products`.`active`='1' {$search_sql} ORDER BY `products`.`date_added` DESC LIMIT {$start},{$itempp}";
            if (get_option('wpsc_sort_by') == 'dragndrop') {
                $sql = "SELECT DISTINCT * FROM `" . WPSC_TABLE_PRODUCT_LIST . "` AS `products` LEFT JOIN `" . WPSC_TABLE_PRODUCT_ORDER . "` AS `order` ON `products`.`id`= `order`.`product_id` WHERE `products`.`active`='1' AND `order`.`category_id`='0' {$search_sql} ORDER BY `order`.`order`";
            }
        } else {
            $sql = "SELECT DISTINCT * FROM `" . WPSC_TABLE_PRODUCT_LIST . "` AS `products` WHERE `products`.`active`='1' {$search_sql} ORDER BY `products`.`date_added`";
        }
    }
    //	exit($sql);
    $product_list = $wpdb->get_results($sql, ARRAY_A);
    //exit('<pre>'.print_r($product_list, true).'</pre>');
    $num_products = $wpdb->get_var("SELECT COUNT(DISTINCT `products`.`id`) FROM `" . WPSC_TABLE_PRODUCT_LIST . "` AS `products` WHERE `products`.`active`='1' {$search_sql}");
    if (isset($itempp)) {
        $num_pages = ceil($num_products / $itempp);
    }
    if ($page !== null) {
        $page_links = paginate_links(array('base' => add_query_arg('pageno', '%#%'), 'format' => '', 'prev_text' => __('&laquo;'), 'next_text' => __('&raquo;'), 'total' => $num_pages, 'current' => $page));
    }
    $this_page_url = stripslashes($_SERVER['REQUEST_URI']);
    ?>
	<div class="wpsc-separator"><br/></div>
	
	<div class="tablenav">
		
		
		
		
		<?php 
    if (get_option('wpsc_sort_by') != 'dragndrop') {
        ?>
		<div class="tablenav-pages">
			<?php 
        echo $page_links;
        ?>
	
		</div>
		<?php 
    }
    ?>
		
		<div class="alignleft actions">
			<form action="admin.php" method="get">
				<?php 
    echo wpsc_admin_category_dropdown();
    ?>
			</form>
		</div>	
	</div>
	
	
	<form id="posts-filter" action="" method="get">
		<div class="tablenav">	
			<div class="alignright search-box">
				<input type='hidden' name='page' value='wpsc-edit-products'  />
				<input type="text" class="search-input" id="page-search-input" name="search" value="<?php 
    echo $search_input;
    ?>
" />
				<input type="submit" name='wpsc_search' value="<?php 
    _e('Search');
    ?>
" class="button" />
			</div>
		
			<div class="alignleft actions">
					<select name="bulkAction">
						<option value="-1" selected="selected"><?php 
    _e('Bulk Actions');
    ?>
</option>
						<option value="delete"><?php 
    _e('Delete');
    ?>
</option>
						<option value="show"><?php 
    _e('Publish');
    ?>
</option>
						<option value="hide"><?php 
    _e('Draft');
    ?>
</option>

					</select>
					<input type='hidden' name='wpsc_admin_action' value='bulk_modify' />
					<input type="submit" value="<?php 
    _e('Apply');
    ?>
" name="doaction" id="doaction" class="button-secondary action" />
					<?php 
    wp_nonce_field('bulk-products', 'wpsc-bulk-products');
    ?>
			</div>
		</div>
	
		<input type='hidden' id='products_page_category_id'  name='category_id' value='<?php 
    echo $category_id;
    ?>
' />
		<table class="widefat page fixed" id='wpsc_product_list' cellspacing="0">
			<thead>
				<tr>
					<?php 
    print_column_headers('display-product-list');
    ?>
				</tr>
			</thead>
		
			<tfoot>
				<tr>
					<?php 
    print_column_headers('display-product-list', false);
    ?>
				</tr>
			</tfoot>
		
			<tbody>
				<?php 
    if (count($product_list) > 0) {
        foreach ((array) $product_list as $product) {
            //first set the patch to the default
            $image_path = WPSC_URL . "/images/no-image-uploaded.gif";
            if (is_numeric($product['image'])) {
                // check for automatic thumbnail images
                // file_exists(WPSC_THUMBNAIL_DIR.$product['image'])
                $product_image = $wpdb->get_var("SELECT `image` FROM  `" . WPSC_TABLE_PRODUCT_IMAGES . "` WHERE `id` = '{$product['image']}' LIMIT 1");
                // if the image exists, set the image path to it.
                if ($product_image != null && file_exists(WPSC_THUMBNAIL_DIR . $product_image)) {
                    $image_path = WPSC_THUMBNAIL_URL . $product_image;
                }
            }
            // get the  product name, unless there is no name, in which case, display text indicating so
            if ($product['name'] == '') {
                $product_name = "(" . __('No Name', 'wpsc') . ")";
            } else {
                $product_name = htmlentities(stripslashes($product['name']), ENT_QUOTES, 'UTF-8');
            }
            $category_html = '';
            if (get_option('wpsc_sort_by') != 'dragndrop') {
                $category_list = $wpdb->get_results("SELECT `" . WPSC_TABLE_PRODUCT_CATEGORIES . "`.`id`,`" . WPSC_TABLE_PRODUCT_CATEGORIES . "`.`name` FROM `" . WPSC_TABLE_ITEM_CATEGORY_ASSOC . "` , `" . WPSC_TABLE_PRODUCT_CATEGORIES . "` WHERE `" . WPSC_TABLE_ITEM_CATEGORY_ASSOC . "`.`product_id` IN ('" . $product['id'] . "') AND `" . WPSC_TABLE_ITEM_CATEGORY_ASSOC . "`.`category_id` = `" . WPSC_TABLE_PRODUCT_CATEGORIES . "`.`id` AND `" . WPSC_TABLE_PRODUCT_CATEGORIES . "`.`active` IN('1')", ARRAY_A);
            } else {
                $category_list = $wpdb->get_results("SELECT `" . WPSC_TABLE_PRODUCT_CATEGORIES . "`.`id`,`" . WPSC_TABLE_PRODUCT_CATEGORIES . "`.`name` FROM `" . WPSC_TABLE_PRODUCT_CATEGORIES . "` LEFT JOIN `" . WPSC_TABLE_ITEM_CATEGORY_ASSOC . "` ON `" . WPSC_TABLE_ITEM_CATEGORY_ASSOC . "`.`category_id`= `" . WPSC_TABLE_PRODUCT_CATEGORIES . "`.`id` WHERE `" . WPSC_TABLE_ITEM_CATEGORY_ASSOC . "`.`product_id` IN ('" . $product['product_id'] . "')  AND `" . WPSC_TABLE_PRODUCT_CATEGORIES . "`.`active` IN('1')", ARRAY_A);
            }
            $i = 0;
            foreach ((array) $category_list as $category_row) {
                if ($i > 0) {
                    $category_html .= "<br />";
                }
                $category_html .= "<a class='category_link' href='" . htmlentities(remove_query_arg('product_id', add_query_arg('category_id', $category_row['id']))) . "'>" . stripslashes($category_row['name']) . "</a>";
                $i++;
            }
            if (get_option('wpsc_sort_by') == 'dragndrop') {
                $product['id'] = $product['product_id'];
            }
            ?>
							<tr class="product-edit <?php 
            echo wpsc_publish_status($product['id']) ? ' wpsc_published' : ' wpsc_not_published';
            ?>
" id="product-<?php 
            echo $product['id'];
            ?>
" >
									<th class="check-column" scope="row">
										<input type='checkbox' name='product[]' class='deletecheckbox' value='<?php 
            echo $product['id'];
            ?>
' title="ID #<?php 
            echo $product['id'];
            ?>
" />
										<?php 
            echo do_action('wpsc_admin_product_checkbox', $product['id']);
            ?>
									</th>
									
									
									<td class="product-image ">
										<img title='Drag to a new position' src='<?php 
            echo $image_path;
            ?>
' alt='<?php 
            echo $product['name'];
            ?>
' width='38' height='38' />
									</td>
									<td class="product-title column-title">
									  <?php 
            $edit_product_url = wp_nonce_url(htmlentities(add_query_arg('product_id', $product['id'])), 'edit_product_' . $product['id']);
            ?>
										<a class='edit-product' href='<?php 
            echo $edit_product_url;
            ?>
' title="ID #<?php 
            echo $product['id'];
            ?>
: <?php 
            echo $product_name;
            ?>
"><?php 
            echo $product_name;
            ?>
</a>
											<?php 
            if ($product['publish'] != 1) {
                ?>
 - <strong> <?php 
                _e('Draft', 'wpsc');
                ?>
	</strong>	<?php 
            }
            ?>
											<?php 
            $product_alert = apply_filters('wpsc_product_alert', array(false, ''), $product);
            if (count($product_alert['messages']) > 0) {
                $product_alert['messages'] = implode("\n", (array) $product_alert['messages']);
            }
            if ($product_alert['state'] === true) {
                ?>
												<img alt='<?php 
                echo $product_alert['messages'];
                ?>
' title='<?php 
                echo $product_alert['messages'];
                ?>
' class='product-alert-image' src='<?php 
                echo WPSC_URL;
                ?>
/images/product-alert.jpg' alt='' />
												<?php 
            }
            // If a product alert has stuff to display, show it.
            // Can be used to add extra icons etc
            if (!empty($product_alert['display'])) {
                echo $product_alert['display'];
            }
            ?>
											<img class='loadingImg' style='display:none;' src='<?php 
            echo get_option('siteurl');
            ?>
/wp-admin/images/wpspin_light.gif' alt='loading' />
									
									
										<div class="wpsc-row-actions">
											<span class="edit">
												<a class='edit-product' title="Edit this post" href='<?php 
            echo $edit_product_url;
            ?>
' style="cursor:pointer;">Edit</a>
											</span>
											 |
											<span class="delete">
												<a class='submitdelete delete_button'
													title='<?php 
            echo attribute_escape(__('Delete this product', 'wpsc'));
            ?>
'
													href='<?php 
            echo wp_nonce_url("admin.php?wpsc_admin_action=delete_product&amp;product={$product['id']}", 'delete_product_' . $product['id']);
            ?>
'
													onclick="if ( confirm(' <?php 
            echo js_escape(sprintf(__("You are about to delete this product '%s'\n 'Cancel' to stop, 'OK' to delete."), $product['name']));
            ?>
') ) { return true;}return false;"
													>
													<?php 
            _e('Delete');
            ?>
												</a>
											</span>
											 |
											<span class="view">
												<a target="_blank" rel="permalink" title='View <?php 
            echo $product_name;
            ?>
' href="<?php 
            echo wpsc_product_url($product['id']);
            ?>
">View</a>
											</span>
											|
											<span class="view">
												<a rel="permalink"
													title='Duplicate <?php 
            echo $product_name;
            ?>
'
													href="<?php 
            echo wp_nonce_url("admin.php?wpsc_admin_action=duplicate_product&amp;product={$product['id']}", 'duplicate_product_' . $product['id']);
            ?>
													">
													Duplicate
												</a>
											</span>
											|
											<span class="publish_toggle">
												<a title="Change publish status"
													href="<?php 
            echo wp_nonce_url("admin.php?wpsc_admin_action=toggle_publish&product=" . $product['id'], 'toggle_publish_' . $product['id']);
            ?>
"
													>
													<?php 
            if ($product['publish'] == 1) {
                _e('Unpublish', 'wpsc');
            } else {
                _e('Publish', 'wpsc');
            }
            ?>
												</a>
											</span>
										</div>
									</td>
									
									<td class="product-price column-price">

									<?php 
            echo nzshpcrt_currency_display($product['price'], 1);
            ?>
									<div class='price-editing-fields' id='price-editing-fields-<?php 
            echo $product['id'];
            ?>
'>
										<input type='text' class='the-product-price' name='product_price[<?php 
            echo $product['id'];
            ?>
][price]' value='<?php 
            echo number_format($product['price'], 2, '.', '');
            ?>
' />
										<input type='hidden' name='product_price[<?php 
            echo $product['id'];
            ?>
][id]' value='<?php 
            echo $product['id'];
            ?>
' />
										<input type='hidden' name='product_price[<?php 
            echo $product['id'];
            ?>
][nonce]' value='<?php 
            echo wp_create_nonce('edit-product_price-' . $product['id']);
            ?>
' />
										
									
									</div>
									</td>
									<td class="column-categories"><?php 
            echo $category_html;
            ?>
</td>
							</tr>
						<?php 
        }
    } else {
        ?>
				<tr>
					<td colspan='5'>
					  <?php 
        _e("You have no products added.");
        ?>
					</td>
				</tr>
				<?php 
    }
    ?>
			
			</tbody>
		</table>
	</form>
	<?php 
}
function wpsc_packing_slip($purchase_id)
{
    global $wpdb, $purchlogitem, $wpsc_cart, $purchlog;
    if (isset($_REQUEST['purchaselog_id'])) {
        $purchlogitem = new wpsc_purchaselogs_items((int) $_REQUEST['purchaselog_id']);
    }
    $purch_sql = "SELECT * FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE `id`='" . $purchase_id . "'";
    $purch_data = $wpdb->get_row($purch_sql, ARRAY_A);
    //echo "<p style='padding-left: 5px;'><strong>".__('Date', 'wpsc')."</strong>:".date("jS M Y", $purch_data['date'])."</p>";
    $cartsql = "SELECT * FROM `" . WPSC_TABLE_CART_CONTENTS . "` WHERE `purchaseid`=" . $purchase_id . "";
    $cart_log = $wpdb->get_results($cartsql, ARRAY_A);
    $j = 0;
    if ($cart_log != null) {
        echo "<div class='packing_slip'>\n\r";
        echo apply_filters('wpsc_packing_slip_header', '<h2>' . __('Packing Slip', 'wpsc') . "</h2>\n\r");
        echo "<strong>" . __('Order', 'wpsc') . " #</strong> " . $purchase_id . "<br /><br />\n\r";
        echo "<table>\n\r";
        /*
        		
        			$form_sql = "SELECT * FROM `".WPSC_TABLE_SUBMITED_FORM_DATA."` WHERE  `log_id` = '".(int)$purchase_id."'";
        			$input_data = $wpdb->get_results($form_sql,ARRAY_A);
        */
        echo "<tr class='heading'><td colspan='2'><strong>Billing Info</strong></td></tr>";
        foreach ((array) $purchlogitem->userinfo as $userinfo) {
            if ($userinfo['unique_name'] != 'billingcountry') {
                echo "<tr><td>" . $userinfo['name'] . ": </td><td>" . $userinfo['value'] . "</td></tr>";
            } else {
                $userinfo['value'] = maybe_unserialize($userinfo['value']);
                if (is_array($userinfo['value'])) {
                    if (!empty($userinfo['value'][1]) && !is_numeric($userinfo['value'][1])) {
                        echo "<tr><td>State: </td><td>" . $userinfo['value'][1] . "</td></tr>";
                    } elseif (is_numeric($userinfo['value'][1])) {
                        echo "<tr><td>State: </td><td>" . wpsc_get_state_by_id($userinfo['value'][1], 'name') . "</td></tr>";
                    }
                    if (!empty($userinfo['value'][0])) {
                        echo "<tr><td>Country: </td><td>" . $userinfo['value'][0] . "</td></tr>";
                    }
                } else {
                    echo "<tr><td>" . $userinfo['name'] . ": </td><td>" . $userinfo['value'] . "</td></tr>";
                }
            }
        }
        echo "<tr class='heading'><td colspan='2'><strong>Shipping Info</strong></td></tr>";
        foreach ((array) $purchlogitem->shippinginfo as $userinfo) {
            if ($userinfo['unique_name'] != 'shippingcountry' && $userinfo['unique_name'] != 'shippingstate') {
                echo "<tr><td>" . $userinfo['name'] . ": </td><td>" . $userinfo['value'] . "</td></tr>";
            } elseif ($userinfo['unique_name'] == 'shippingcountry') {
                $userinfo['value'] = maybe_unserialize($userinfo['value']);
                if (is_array($userinfo['value'])) {
                    if (!empty($userinfo['value'][1]) && !is_numeric($userinfo['value'][1])) {
                        echo "<tr><td>State: </td><td>" . $userinfo['value'][1] . "</td></tr>";
                    } elseif (is_numeric($userinfo['value'][1])) {
                        echo "<tr><td>State: </td><td>" . wpsc_get_state_by_id($userinfo['value'][1], 'name') . "</td></tr>";
                    }
                    if (!empty($userinfo['value'][0])) {
                        echo "<tr><td>Country: </td><td>" . $userinfo['value'][0] . "</td></tr>";
                    }
                } else {
                    echo "<tr><td>" . $userinfo['name'] . ": </td><td>" . $userinfo['value'] . "</td></tr>";
                }
            } elseif ($userinfo['unique_name'] == 'shippingstate') {
                if (!empty($userinfo['value']) && !is_numeric($userinfo['value'])) {
                    echo "<tr><td>" . $userinfo['name'] . ": </td><td>" . $userinfo['value'] . "</td</tr>>";
                } elseif (is_numeric($userinfo['value'])) {
                    echo "<tr><td>State: </td><td>" . wpsc_get_state_by_id($userinfo['value'], 'name') . "</td></tr>";
                }
            }
        }
        //		echo('<pre>'.print_r($purchlogitem,true).'</pre>');
        /*
        	foreach($input_data as $input_row) {
        			  $rekeyed_input[$input_row['form_id']] = $input_row;
        			}
        			
        			
        			if($input_data != null) {
                $form_data = $wpdb->get_results("SELECT * FROM `".WPSC_TABLE_CHECKOUT_FORMS."` WHERE `active` = '1'",ARRAY_A);
            // exit('<pre>'.print_r($purch_data, true).'</pre>');
                foreach($form_data as $form_field) {
                  switch($form_field['type']) {
        			case 'country':
        
        						$delivery_region_count = $wpdb->get_var("SELECT COUNT(`regions`.`id`) FROM `".WPSC_TABLE_REGION_TAX."` AS `regions` INNER JOIN `".WPSC_TABLE_CURRENCY_LIST."` AS `country` ON `country`.`id` = `regions`.`country_id` WHERE `country`.`isocode` IN('".$wpdb->escape( $purch_data['billing_country'])."')");
        
                    if(is_numeric($purch_data['billing_region']) && ($delivery_region_count > 0)) {
                      echo "  <tr><td>".__('State', 'wpsc').":</td><td>".wpsc_get_region($purch_data['billing_region'])."</td></tr>\n\r";
                    }
                    echo "  <tr><td>".wp_kses($form_field['name'], array() ).":</td><td>".wpsc_get_country($purch_data['billing_country'])."</td></tr>\n\r";
                    break;
                        
                    case 'delivery_country':
                    echo "  <tr><td>".$form_field['name'].":</td><td>".wpsc_get_country($purch_data['shipping_country'])."</td></tr>\n\r";
                    break;
                        
                    case 'heading':
                    echo "  <tr><td colspan='2'><strong>".wp_kses($form_field['name'], array()).":</strong></td></tr>\n\r";
                    break;
                    
                    default:
                    if($form_field['unique_name'] == 'shippingstate'){
                    	echo "  <tr><td>".wp_kses($form_field['name'], array() ).":</td><td>".wpsc_get_region($purch_data['shipping_region'])."</td></tr>\n\r";
                    }else{
                    	echo "  <tr><td>".wp_kses($form_field['name'], array() ).":</td><td>".htmlentities(stripslashes($rekeyed_input[$form_field['id']]['value']), ENT_QUOTES,'UTF-8')."</td></tr>\n\r";
                    }
                    break;
                  }
                }
        			} else {
                echo "  <tr><td>".__('Name', 'wpsc').":</td><td>".$purch_data['firstname']." ".$purch_data['lastname']."</td></tr>\n\r";
                echo "  <tr><td>".__('Address', 'wpsc').":</td><td>".$purch_data['address']."</td></tr>\n\r";
                echo "  <tr><td>".__('Phone', 'wpsc').":</td><td>".$purch_data['phone']."</td></tr>\n\r";
                echo "  <tr><td>".__('Email', 'wpsc').":</td><td>".$purch_data['email']."</td></tr>\n\r";
        			}
        */
        if (get_option('payment_method') == 2) {
            $gateway_name = '';
            foreach ($GLOBALS['nzshpcrt_gateways'] as $gateway) {
                if ($purch_data['gateway'] != 'testmode') {
                    if ($gateway['internalname'] == $purch_data['gateway']) {
                        $gateway_name = $gateway['name'];
                    }
                } else {
                    $gateway_name = "Manual Payment";
                }
            }
        }
        // 			echo "  <tr><td colspan='2'></td></tr>\n\r";
        // 			echo "  <tr><td>".__('Payment Method', 'wpsc').":</td><td>".$gateway_name."</td></tr>\n\r";
        // 			//echo "  <tr><td>".__('Purchase No.', 'wpsc').":</td><td>".$purch_data['id']."</td></tr>\n\r";
        // 			echo "  <tr><td>".__('How The Customer Found Us', 'wpsc').":</td><td>".$purch_data['find_us']."</td></tr>\n\r";
        // 			$engrave_line = explode(",",$purch_data['engravetext']);
        // 			echo "  <tr><td>".__('Engrave text', 'wpsc')."</td><td></td></tr>\n\r";
        // 			echo "  <tr><td>".__('Line 1', 'wpsc').":</td><td>".$engrave_line[0]."</td></tr>\n\r";
        // 			echo "  <tr><td>".__('Line 2', 'wpsc').":</td><td>".$engrave_line[1]."</td></tr>\n\r";
        // 			if($purch_data['transactid'] != '') {
        // 				echo "  <tr><td>".__('Transaction Id', 'wpsc').":</td><td>".$purch_data['transactid']."</td></tr>\n\r";
        // 			}
        echo "</table>\n\r";
        echo "<table class='packing_slip'>";
        echo "<tr>";
        echo " <th>" . __('Quantity', 'wpsc') . " </th>";
        echo " <th>" . __('Name', 'wpsc') . "</th>";
        echo " <th>" . __('Price', 'wpsc') . " </th>";
        echo " <th>" . __('Shipping', 'wpsc') . " </th>";
        echo "<th>" . wpsc_display_tax_label(false) . "</th>";
        echo '</tr>';
        $endtotal = 0;
        $all_donations = true;
        $all_no_shipping = true;
        $file_link_list = array();
        //			exit('<pre>'.print_r($cart_log,true).'</pre>');
        foreach ($cart_log as $cart_row) {
            $purchlogitem->the_purch_item();
            //			exit('<pre>'.print_r, true).'</pre>');
            $alternate = "";
            $j++;
            if ($j % 2 != 0) {
                $alternate = "class='alt'";
            }
            $productsql = "SELECT * FROM `" . WPSC_TABLE_PRODUCT_LIST . "` WHERE `id`=" . $cart_row['prodid'] . "";
            $product_data = $wpdb->get_results($productsql, ARRAY_A);
            $variation_sql = "SELECT * FROM `" . WPSC_TABLE_CART_ITEM_VARIATIONS . "` WHERE `cart_id`='" . $cart_row['id'] . "'";
            $variation_data = $wpdb->get_results($variation_sql, ARRAY_A);
            $variation_count = count($variation_data);
            if ($variation_count > 1) {
                $variation_list = " (";
                $i = 0;
                foreach ($variation_data as $variation) {
                    if ($i > 0) {
                        $variation_list .= ", ";
                    }
                    $value_id = $variation['value_id'];
                    $value_data = $wpdb->get_results("SELECT * FROM `" . WPSC_TABLE_VARIATION_VALUES . "` WHERE `id`='" . $value_id . "' LIMIT 1", ARRAY_A);
                    $variation_list .= $value_data[0]['name'];
                    $i++;
                }
                $variation_list .= ")";
            } else {
                if ($variation_count == 1) {
                    $value_id = $variation_data[0]['value_id'];
                    $value_data = $wpdb->get_results("SELECT * FROM `" . WPSC_TABLE_VARIATION_VALUES . "` WHERE `id`='" . $value_id . "' LIMIT 1", ARRAY_A);
                    $variation_list = " (" . $value_data[0]['name'] . ")";
                } else {
                    $variation_list = '';
                }
            }
            if ($cart_row['donation'] != 1) {
                $all_donations = false;
            }
            if ($cart_row['no_shipping'] != 1) {
                $shipping = $cart_row['pnp'] * $cart_row['quantity'];
                $total_shipping += $shipping;
                $all_no_shipping = false;
            } else {
                $shipping = 0;
            }
            $price = $cart_row['price'] * $cart_row['quantity'];
            $gst = $price - $price / (1 + $cart_row['gst'] / 100);
            if ($gst > 0) {
                $tax_per_item = $gst / $cart_row['quantity'];
            }
            echo "<tr {$alternate}>";
            echo " <td>";
            echo $cart_row['quantity'];
            echo " </td>";
            echo " <td>";
            echo $product_data[0]['name'];
            echo stripslashes($variation_list);
            echo " </td>";
            echo " <td>";
            echo nzshpcrt_currency_display($price, 1);
            echo " </td>";
            echo " <td>";
            echo nzshpcrt_currency_display($shipping, 1);
            echo " </td>";
            echo '<td>';
            if (wpsc_tax_isincluded()) {
                echo wpsc_purchaselog_details_tax();
            } else {
                echo nzshpcrt_currency_display($cart_row['tax_charged'], 1);
            }
            echo '<td>';
            echo '</tr>';
        }
        echo "</table>";
        echo '<table class="packing-slip-totals">';
        echo '<tr><th>Base Shipping</th><td>' . nzshpcrt_currency_display($purch_data['base_shipping'], 1) . '</td></tr>';
        echo '<tr><th>Total Shipping</th><td>' . nzshpcrt_currency_display($purch_data['base_shipping'] + $total_shipping, 1) . '</td></tr>';
        echo '<tr><th>Total Price</th><td>' . nzshpcrt_currency_display($purch_data['totalprice'], 1) . '</td></tr>';
        echo '</table>';
        echo "</div>\n\r";
    } else {
        echo "<br />" . __('This users cart was empty', 'wpsc');
    }
}
Exemplo n.º 18
0
function wpsc_display_product_multicurrency()
{
    global $wpdb, $wpsc_query;
    $output = '';
    $sql = "SELECT `meta_key`, `meta_value` FROM `" . WPSC_TABLE_PRODUCTMETA . "` WHERE `product_id`=" . $wpsc_query->product['id'] . " AND `meta_key` LIKE 'currency%'";
    $results = $wpdb->get_results($sql, ARRAY_A);
    if (count($results) > 0) {
        foreach ((array) $results as $curr) {
            $isocode = str_ireplace("currency[", "", $curr['meta_key']);
            $isocode = str_ireplace("]", "", $isocode);
            $currency_data = $wpdb->get_row("SELECT `symbol`,`symbol_html`,`code` FROM `" . WPSC_TABLE_CURRENCY_LIST . "` WHERE `isocode`='" . $isocode . "' LIMIT 1", ARRAY_A);
            if ($currency_data['symbol'] != '') {
                $currency_sign = $currency_data['symbol_html'];
            } else {
                $currency_sign = $currency_data['code'];
            }
            $output .= '<span class="wpscsmall pricefloatright pricedisplay">' . $currency_sign . ' ' . nzshpcrt_currency_display($curr["meta_value"], false, false, false, true) . '</span><br />';
            //exit('<pre>'.print_r($currency_sign, true).'</pre>');
        }
    }
    return $output;
}
Exemplo n.º 19
0
function nszhpcrt_category_tag($content = '')
{
    require_once 'themes/iShop/iShop.php';
    global $wpdb;
    if (preg_match_all("/\\[wpsc_category_exclude=([\\d]+),*(full)?\\]/", $content, $matches)) {
        foreach ($matches[1] as $key => $category_id) {
            $categories[$key]['id'] = $category_id;
            $categories[$key]['display'] = $matches[2][$key];
            $categories[$key]['original_string'] = $matches[0][$key];
        }
        foreach ($categories as $category) {
            $sql1 = "SELECT DISTINCT `" . $wpdb->prefix . "product_list`.*, `" . $wpdb->prefix . "item_category_associations`.`category_id`,`" . $wpdb->prefix . "product_order`.`order`, IF(ISNULL(`" . $wpdb->prefix . "product_order`.`order`), 0, 1) AS `order_state` FROM `" . $wpdb->prefix . "product_list` LEFT JOIN `" . $wpdb->prefix . "item_category_associations` ON `" . $wpdb->prefix . "product_list`.`id` = `" . $wpdb->prefix . "item_category_associations`.`product_id` LEFT JOIN `" . $wpdb->prefix . "product_order` ON ( ( `" . $wpdb->prefix . "product_list`.`id` = `" . $wpdb->prefix . "product_order`.`product_id` ) AND ( `" . $wpdb->prefix . "item_category_associations`.`category_id` = `" . $wpdb->prefix . "product_order`.`category_id` ) ) WHERE `" . $wpdb->prefix . "product_list`.`active` = '1' AND `" . $wpdb->prefix . "item_category_associations`.`category_id` NOT IN ('" . $category['id'] . "') {$no_donations_sql} ORDER BY `order_state` DESC,`" . $wpdb->prefix . "product_order`.`order` ASC";
            $product_list1 = $wpdb->get_results($sql1, ARRAY_A);
            if (function_exists('product_display_list') && get_option('product_view') == 'list') {
                $output1 = product_display_list($product_list1, $group_type, $group_sql, $search_sql);
            } else {
                if (function_exists('product_display_grid') && get_option('product_view') == 'grid') {
                    $output1 = product_display_grid($product_list1, $group_type, $group_sql, $search_sql);
                } else {
                    $output1 = product_display_default($product_list1, '');
                }
            }
        }
        $content = str_replace($category['original_string'], $output1, $content);
    }
    if (preg_match_all("/\\[wpsc_category=([\\d]+),*(full)?\\]/", $content, $matches)) {
        foreach ($matches[1] as $key => $category_id) {
            $categories[$key]['id'] = $category_id;
            $categories[$key]['display'] = $matches[2][$key];
            $categories[$key]['original_string'] = $matches[0][$key];
        }
        //echo("<pre>".print_r($categories,true)."</pre>");
        $siteurl = get_option('siteurl');
        if (get_option('permalink_structure') != '') {
            $seperator = "?";
        } else {
            $seperator = "&amp;";
        }
        foreach ((array) $activated_widgets as $widget_container) {
            if (is_array($widget_container) && array_search(TXT_WPSC_DONATIONS, $widget_container)) {
                $no_donations_sql = "AND `" . $wpdb->prefix . "product_list`.`donation` != '1'";
                break;
            }
        }
        foreach ((array) $categories as $category) {
            $full_view = null;
            if ($category['display'] == 'full') {
                $sql = "SELECT DISTINCT `" . $wpdb->prefix . "product_list`.*, `" . $wpdb->prefix . "item_category_associations`.`category_id`,`" . $wpdb->prefix . "product_order`.`order`, IF(ISNULL(`" . $wpdb->prefix . "product_order`.`order`), 0, 1) AS `order_state` FROM `" . $wpdb->prefix . "product_list` LEFT JOIN `" . $wpdb->prefix . "item_category_associations` ON `" . $wpdb->prefix . "product_list`.`id` = `" . $wpdb->prefix . "item_category_associations`.`product_id` LEFT JOIN `" . $wpdb->prefix . "product_order` ON ( ( `" . $wpdb->prefix . "product_list`.`id` = `" . $wpdb->prefix . "product_order`.`product_id` ) AND ( `" . $wpdb->prefix . "item_category_associations`.`category_id` = `" . $wpdb->prefix . "product_order`.`category_id` ) ) WHERE `" . $wpdb->prefix . "product_list`.`active` = '1' AND `" . $wpdb->prefix . "item_category_associations`.`category_id` IN ('" . $category['id'] . "') {$no_donations_sql} ORDER BY `order_state` DESC,`" . $wpdb->prefix . "product_order`.`order` ASC";
                $product_list = $wpdb->get_results($sql, ARRAY_A);
                // sorry about the global variable, but it was the best way I could think of to avoid people having to upgrade the gold cart
                $GLOBALS['wpsc_category_id'] = $category['id'];
                if (function_exists('product_display_list') && get_option('product_view') == 'list') {
                    $output .= product_display_list($product_list, $group_type, $group_sql, $search_sql);
                } else {
                    if (function_exists('product_display_grid') && get_option('product_view') == 'grid') {
                        $output .= product_display_grid($product_list, $group_type, $group_sql, $search_sql);
                    } else {
                        $output .= product_display_default($product_list, $group_type, $group_sql, $search_sql);
                    }
                }
            } else {
                $sql = "SELECT DISTINCT `" . $wpdb->prefix . "product_list`.*, `" . $wpdb->prefix . "item_category_associations`.`category_id`,`" . $wpdb->prefix . "product_order`.`order`, IF(ISNULL(`" . $wpdb->prefix . "product_order`.`order`), 0, 1) AS `order_state` FROM `" . $wpdb->prefix . "product_list` LEFT JOIN `" . $wpdb->prefix . "item_category_associations` ON `" . $wpdb->prefix . "product_list`.`id` = `" . $wpdb->prefix . "item_category_associations`.`product_id` LEFT JOIN `" . $wpdb->prefix . "product_order` ON ( ( `" . $wpdb->prefix . "product_list`.`id` = `" . $wpdb->prefix . "product_order`.`product_id` ) AND ( `" . $wpdb->prefix . "item_category_associations`.`category_id` = `" . $wpdb->prefix . "product_order`.`category_id` ) ) WHERE `" . $wpdb->prefix . "product_list`.`active` = '1' AND `" . $wpdb->prefix . "item_category_associations`.`category_id` IN ('" . $category['id'] . "') {$no_donations_sql} ORDER BY `order_state` DESC,`" . $wpdb->prefix . "product_order`.`order` ASC";
                $product_list = $wpdb->get_results($sql, ARRAY_A);
                $output = "<div id='products_page_container' class='wrap wpsc_container'>\n\r";
                $output .= "<div id='homepage_products'>\n\r";
                if ($full_view != null) {
                    $output .= "<table class='productdisplay'>";
                }
                foreach ((array) $product_list as $product) {
                    $wpsc_theme = wpsc_theme_html($product);
                    if ($full_view == null) {
                        $output .= "<div class='category_view_product'>\n\r";
                    } else {
                        /* product image is here */
                        $output .= "<tr>";
                        $output .= "<td class='imagecol'>";
                    }
                    $output .= "<a href='" . WPSC_IMAGE_URL . $product['image'] . "' class='thickbox preview_link'  rel='" . str_replace(" ", "_", $product['name']) . "'>";
                    if ($product['image'] != '') {
                        $output .= "<img class='product_image' src='" . WPSC_THUMBNAIL_URL . $product['image'] . "' title='" . $product['name'] . "' alt='" . $product['name'] . "' />\n\r";
                    }
                    $output .= "</a>";
                    if ($full_view != null) {
                        $output .= "</td><td class='textcol'>";
                    } else {
                        $output .= "<div class='product_details'>";
                    }
                    if (get_option('hide_name_link') != 1) {
                        if ($product['special'] == 1 && $variations_output[1] === null) {
                            $output .= "<a href='" . wpsc_product_url($product['id']) . "' class='wpsc_product_title' >{$special}<strong class='special'>Special / Sale Price - </strong><strong>" . stripslashes($product['name']) . "</strong></a>";
                        } else {
                            $output .= "<a href='" . wpsc_product_url($product['id']) . "' class='wpsc_product_title' >{$special}<strong>" . stripslashes($product['name']) . "</strong></a>";
                        }
                    } else {
                        if ($product['special'] == 1 && $variations_output[1] === null) {
                            $output .= "<a class='wpsc_product_title' >{$special}<strong class='special'>Special / Sale Price - </strong><strong>" . stripslashes($product['name']) . "</strong></a>";
                        } else {
                            $output .= "<a class='wpsc_product_title' >{$special}<strong>" . stripslashes($product['name']) . "</strong></a>";
                        }
                    }
                    if ($full_view != null) {
                        if ($product['description'] != '') {
                            $output .= "<p class='wpsc_description'>" . nl2br(stripslashes($product['description'])) . "</p>";
                        }
                        if ($product['additional_description'] != '') {
                            $output .= "<a href='#' class='additional_description_link' onclick='return show_additional_description(\"additionaldescription" . $product['id'] . "\",\"link_icon" . $product['id'] . "\");'>";
                            $output .= "<img id='link_icon" . $product['id'] . "' class='additional_description_button'  src='" . WPSC_URL . "/images/icon_window_expand.gif' title='" . $product['name'] . "' alt='" . $product['name'] . "' />";
                            $output .= TXT_WPSC_MOREDETAILS . "</a>";
                            $output .= "<span class='additional_description' id='additionaldescription" . $product['id'] . "'><br />";
                            $output .= nl2br(stripslashes($product['additional_description'])) . "";
                            $output .= "</span><br />";
                        }
                    }
                    /*
                    adding to cart stuff
                    */
                    $output .= "<form id='product_" . $product['id'] . "' name='product_" . $product['id'] . "' method='post' action='" . get_option('product_list_url') . $seperator . "category=" . $_GET['category'] . "' onsubmit='submitform(this);return false;' >";
                    $output .= "<input type='hidden' name='prodid' value='" . $product['id'] . "' />";
                    $output .= "<input type='hidden' name='item' value='" . $product['id'] . "' />";
                    $variations_procesor = new nzshpcrt_variations();
                    $variations_output = $variations_procesor->display_product_variations($product['id'], false, false, true);
                    $output .= $variations_output[0];
                    if ($variations_output[1] !== null) {
                        $product['price'] = $variations_output[1];
                    }
                    if ($product['special'] == 1 && $variations_output[1] === null) {
                        $output .= "<span class='oldprice'>" . nzshpcrt_currency_display($product['price'], $product['notax']) . "</span><br />";
                        $output .= nzshpcrt_currency_display($product['price'] - $product['special_price'], $product['notax'], false, $product['id']) . "<br />";
                    } else {
                        $output .= "<span id='product_price_" . $product['id'] . "'>" . nzshpcrt_currency_display($product['price'], $product['notax']) . "</span><br />";
                    }
                    if (get_option('hide_addtocart_button') != '1' || get_option('payment_gateway') != 'google') {
                        if (isset($wpsc_theme) && is_array($wpsc_theme) && $wpsc_theme['html'] != '') {
                            $output .= $wpsc_theme['html'];
                        } else {
                            $output .= "<input type='submit' id='product_" . $product['id'] . "_submit_button' class='wpsc_buy_button' name='Buy' value='" . TXT_WPSC_ADDTOCART . "'  />";
                        }
                    }
                    $output .= "</form>";
                    if (get_option('addtocart_or_buynow') == '1') {
                        if (get_option('payment_gateway') == 'google') {
                            $output .= google_buynow($product['id']);
                        }
                    }
                    if ($full_view != null) {
                        if (get_option('product_ratings') == 1) {
                            $output .= "<div class='product_footer'>";
                            $output .= "<div class='product_average_vote'>";
                            $output .= "<strong>" . TXT_WPSC_AVGCUSTREVIEW . ":</strong>";
                            $output .= nzshpcrt_product_rating($product['id']);
                            $output .= "</div>";
                            $output .= "<div class='product_user_vote'>";
                            $vote_output = nzshpcrt_product_vote($product['id'], "onmouseover='hide_save_indicator(\"saved_" . $product['id'] . "_text\");'");
                            if ($vote_output[1] == 'voted') {
                                $output .= "<strong><span id='rating_" . $product['id'] . "_text'>" . TXT_WPSC_YOURRATING . ":</span>";
                                $output .= "<span class='rating_saved' id='saved_" . $product['id'] . "_text'> " . TXT_WPSC_RATING_SAVED . "</span>";
                                $output .= "</strong>";
                            } else {
                                if ($vote_output[1] == 'voting') {
                                    $output .= "<strong><span id='rating_" . $product['id'] . "_text'>" . TXT_WPSC_RATETHISITEM . ":</span>";
                                    $output .= "<span class='rating_saved' id='saved_" . $product['id'] . "_text'> " . TXT_WPSC_RATING_SAVED . "</span>";
                                    $output .= "</strong>";
                                }
                            }
                            $output .= $vote_output[0];
                            $output .= "</div>";
                            $output .= "</div>";
                        }
                        $output .= "</td>";
                        $output .= "</tr>";
                    } else {
                        $output .= "</div>\n\r";
                        $output .= "</div>";
                    }
                }
                if ($full_view != null) {
                    $output .= "</table>";
                }
                $output .= "</div>\n\r";
                $output .= "<br style='clear: left;'>\n\r";
                $output .= "</div>\n\r";
            }
            $content = str_replace($category['original_string'], $output, $content);
        }
    }
    return $content;
}
Exemplo n.º 20
0
function nzshpcrt_submit_ajax()
{
    global $wpdb, $user_level, $wp_rewrite;
    get_currentuserinfo();
    if (get_option('permalink_structure') != '') {
        $seperator = "?";
    } else {
        $seperator = "&amp;";
    }
    $cartt = $_SESSION['nzshpcrt_cart'];
    $cartt1 = $cartt[0]->product_id;
    // if is an AJAX request, cruddy code, could be done better but getting approval would be impossible
    if ($_POST['ajax'] == "true" || $_GET['ajax'] == "true") {
        if ($_POST['metabox'] == 'true') {
            $output .= "<div class='meta_box'>";
            if (get_option('multi_add') == '1') {
                $output .= TXT_WPSC_QUANTITY . ": <input type='text' name='quantity[]' size='3'><br>";
            }
            if (get_option('time_requested') == '1') {
                $output .= TXT_WPSC_DATE_REQUESTED . ": <input type='text' class='time_requested' name='time_requested[]' size='10'><br>";
            }
            if (get_option('commenting') == '1') {
                $output .= TXT_WPSC_COMMENT . ":<br><textarea type='text' name='comment[]'></textarea><br>";
            }
            $output .= TXT_WPSC_LABEL . ":<br><textarea type='text' name='label[]'></textarea><br>";
            $output .= "</div>";
            exit($output);
        }
        if ($_POST['submittogoogle']) {
            $newvalue = $_POST['value'];
            $amount = $_POST['amount'];
            $reason = $_POST['reason'];
            $comment = $_POST['comment'];
            $message = $_POST['message'];
            $amount = number_format($amount, 2, '.', '');
            $log_data = $wpdb->get_row("SELECT * FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE `id` = '" . $_POST['id'] . "' LIMIT 1", ARRAY_A);
            if ($newvalue == 2 && function_exists('wpsc_member_activate_subscriptions')) {
                wpsc_member_activate_subscriptions($_POST['id']);
            }
            $google_status = unserialize($log_data['google_status']);
            switch ($newvalue) {
                case "Charge":
                    if ($google_status[0] != 'CANCELLED_BY_GOOGLE') {
                        if ($amount == '') {
                            $google_status['0'] = 'Partially Charged';
                        } else {
                            $google_status['0'] = 'CHARGED';
                            $google_status['partial_charge_amount'] = $amount;
                        }
                    }
                    break;
                case "Cancel":
                    if ($google_status[0] != 'CANCELLED_BY_GOOGLE') {
                        $google_status[0] = 'CANCELLED';
                    }
                    if ($google_status[1] != 'DELIVERED') {
                        $google_status[1] = 'WILL_NOT_DELIVER';
                    }
                    break;
                case "Refund":
                    if ($amount == '') {
                        $google_status['0'] = 'Partially Refund';
                    } else {
                        $google_status['0'] = 'REFUND';
                        $google_status['partial_refund_amount'] = $amount;
                    }
                    break;
                case "Ship":
                    if ($google_status[1] != 'WILL_NOT_DELIVER') {
                        $google_status[1] = 'DELIVERED';
                    }
                    break;
                case "Archive":
                    $google_status[1] = 'ARCHIVED';
                    break;
            }
            $google_status_sql = "UPDATE `" . WPSC_TABLE_PURCHASE_LOGS . "` SET google_status='" . serialize($google_status) . "' WHERE `id` = '" . $_POST['id'] . "' LIMIT 1";
            $wpdb->query($google_status_sql);
            $merchant_id = get_option('google_id');
            $merchant_key = get_option('google_key');
            $server_type = get_option('google_server_type');
            $currency = get_option('google_cur');
            $Grequest = new GoogleRequest($merchant_id, $merchant_key, $server_type, $currency);
            $google_order_number = $wpdb->get_var("SELECT google_order_number FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE `id` = '" . $_POST['id'] . "' LIMIT 1");
            switch ($newvalue) {
                case 'Charge':
                    $Grequest->SendChargeOrder($google_order_number, $amount);
                    break;
                case 'Ship':
                    $Grequest->SendDeliverOrder($google_order_number);
                    break;
                case 'Archive':
                    $Grequest->SendArchiveOrder($google_order_number);
                    break;
                case 'Refund':
                    $Grequest->SendRefundOrder($google_order_number, $amount, $reason);
                    break;
                case 'Cancel':
                    $Grequest->SendCancelOrder($google_order_number, $reason, $comment);
                    break;
                case 'Send Message':
                    $Grequest->SendBuyerMessage($google_order_number, $message);
                    break;
            }
            $newvalue++;
            $update_sql = "UPDATE `" . WPSC_TABLE_PURCHASE_LOGS . "` SET `processed` = '" . $newvalue . "' WHERE `id` = '" . $_POST['id'] . "' LIMIT 1";
            //$wpdb->query($update_sql);
            exit;
        }
        /*
        	if(($_GET['user'] == "true") && is_numeric($_POST['prodid'])) {
        		if(function_exists('wpsc_members_init')) {
        			$memberstatus = get_product_meta($_POST['prodid'],'is_membership',true);
        		}
        
        		if(($memberstatus=='1') && ($_SESSION['nzshopcrt_cart']!=NULL)){
        		} else{
        			$sql = "SELECT * FROM `".WPSC_TABLE_PRODUCT_LIST."` WHERE `id`='".$_POST['prodid']."' LIMIT 1";
        			$item_data = $wpdb->get_results($sql,ARRAY_A);
        			if ($_POST['quantity']!='') {
        				$add_quantity = $_POST['quantity'];
        			}
        			$item_quantity = 0;
        			if($_SESSION['nzshpcrt_cart'] != null) {
        				foreach($_SESSION['nzshpcrt_cart'] as $cart_key => $cart_item) {
        					if (($memberstatus[0]!='1')&&($_SESSION['nzshpcrt_cart']!=NULL)){
        						if($cart_item->product_id == $_POST['prodid']) {
        							if(($_SESSION['nzshpcrt_cart'][$cart_key]->product_variations === $_POST['variation'])&&($_SESSION['nzshpcrt_cart'][$cart_key]->extras === $_POST['extras'])) {
        								$item_quantity += $_SESSION['nzshpcrt_cart'][$cart_key]->quantity;
        								$item_variations = $_SESSION['nzshpcrt_cart'][$cart_key]->product_variations;
        							}
        						}
        					}
        				}
        			}
        		  
        		  $item_stock = null;
        		  $variation_count = count($_POST['variation']);
        		  if($variation_count >= 1) {
        				foreach($_POST['variation'] as $value_id) {
        					if(is_numeric($value_id)) {
        						$value_ids[] = (int)$value_id;
        					}
        				}
        				
                if(count($value_ids) > 0) {
                  $variation_ids = $wpdb->get_col("SELECT `variation_id` FROM `".WPSC_TABLE_VARIATION_VALUES."` WHERE `id` IN ('".implode("','",$value_ids)."')");
                  asort($variation_ids);
                  $all_variation_ids = implode(",", $variation_ids);
                
                
                  $priceandstock_id = $wpdb->get_var("SELECT `priceandstock_id` FROM `".WPSC_TABLE_VARIATION_COMBINATIONS."` WHERE `product_id` = '".(int)$_POST['prodid']."' AND `value_id` IN ( '".implode("', '",$value_ids )."' )  AND `all_variation_ids` IN('$all_variation_ids')  GROUP BY `priceandstock_id` HAVING COUNT( `priceandstock_id` ) = '".count($value_ids)."' LIMIT 1");
                  
                  $variation_stock_data = $wpdb->get_row("SELECT * FROM `".WPSC_TABLE_VARIATION_PROPERTIES."` WHERE `id` = '{$priceandstock_id}' LIMIT 1", ARRAY_A);
                  
                  $item_stock = $variation_stock_data['stock'];
                }				
        			}
        
        			
        		if($item_stock === null) {
        			$item_stock = $item_data[0]['quantity'];
        		}
        		
        			if((($item_data[0]['quantity_limited'] == 1) && ($item_stock > 0) && ($item_stock > $item_quantity)) || ($item_data[0]['quantity_limited'] == 0)) {
        				$cartcount = count($_SESSION['nzshpcrt_cart']);
        				if(is_array($_POST['variation'])) {  $variations = $_POST['variation'];  }  else  { $variations = null; }
        				//if(is_array($_POST['extras'])) {  $extras = $_POST['extras'];  }  else  { $extras = null; }
        				$updated_quantity = false;
        				if($_SESSION['nzshpcrt_cart'] != null) {
        					foreach($_SESSION['nzshpcrt_cart'] as $cart_key => $cart_item) {
        						if ((!($memberstatus[0]=='1')&&(count($_SESSION['nzshpcrt_cart'])>0))) {
        							if((int)$cart_item->product_id === (int)$_POST['prodid']) {  // force both to integer before testing for identicality
        								if(($_SESSION['nzshpcrt_cart'][$cart_key]->extras === $extras)&&($_SESSION['nzshpcrt_cart'][$cart_key]->product_variations === $variations) && ((int)$_SESSION['nzshpcrt_cart'][$cart_key]->donation_price == (int)$_POST['donation_price'])) {
        									if ($_POST['quantity'] != ''){
        									  if(is_array($_POST['quantity'])) {
        											foreach ((array)$_POST['quantity'] as $qty) {
        												$_SESSION['nzshpcrt_cart'][$cart_key]->quantity += (int)$qty;
        											}
        										} else {
        											$_SESSION['nzshpcrt_cart'][$cart_key]->quantity += (int)$_POST['quantity'];
        										}
        									} else {
        										$_SESSION['nzshpcrt_cart'][$cart_key]->quantity++;
        									}
        									$_SESSION['nzshpcrt_cart'][$cart_key]->comment = $_POST['comment'];
        									foreach((array)$_POST['label'] as $key => $label) {
        										if ($label != '') {
        											if (array_key_exists($label, $_SESSION['nzshpcrt_cart'][$cart_key]->meta)) {
        												$_SESSION['nzshpcrt_cart'][$cart_key]->meta[$label]+=(int)$_POST['quantity'][$key];
        												$_SESSION['nzshpcrt_cart'][$cart_key]->time_requested[$label] = $_POST['time_requested'][$key];
        											} else {
        												$_SESSION['nzshpcrt_cart'][$cart_key]->meta[$label] = $_POST['quantity'][$key];
        												$_SESSION['nzshpcrt_cart'][$cart_key]->time_requested[$label] = $_POST['time_requested'][$key];
        											}
        										}
        									}
        									$updated_quantity = true;
        								}
        							}
        						}
        					}
        				}
        				if($item_data[0]['donation'] == 1) {
        					$donation = $_POST['donation_price'];
        				} else {
        					$donation = false;
        				}
        				if(!(($memberstatus=='1')&&(count($_SESSION['nzshpcrt_cart'])>0))){
        					$status = get_product_meta($cartt1, 'is_membership', true);
        					if (function_exists('wpsc_members_init') && ( $status=='1')){
        						exit();
        					}	
        					$parameters = array();
        					if($updated_quantity === false) {
        						$parameters['variation_values'] = $variations;
        						$parameters['provided_price'] = $donation;
        						$parameters['meta']=null;
        						if($_POST['quantity'] != '') {
        							$total_qty = 0;
        							foreach ($_POST['quantity'] as $key=>$qty) {
        								$total_qty+=$qty;
        								$label[$_POST['label'][$key]] = $qty;
        								$time_requested[$_POST['label'][$key]] = $_POST['time_requested'][$key];
        							}
        							$parameters['quantity'] = $total_qty;
        							//$new_cart_item = new wpsc_cart_item($_POST['prodid'],$variations,$total_qty, $donation,$_POST['comment'],$time_requested,$label);
        						} else {
        							$parameters['quantity'] = 1;
        						}
        						//mail('*****@*****.**', 'stuff', print_r($parameters,true));
        						$new_cart_item = new wpsc_cart_item($_POST['prodid'],$parameters);
        						$_SESSION['nzshpcrt_cart'][] = $new_cart_item;
        					}
        				}
        			} else {
        				$quantity_limit = true;
        			}
        		
        			$cart = $_SESSION['nzshpcrt_cart'];
        		
        			if (($memberstatus[0]=='1')&&(count($cart)>1)) {
        			} else {
        				$status = get_product_meta($cartt1, 'is_membership', true);
        				if (function_exists('wpsc_members_init') && ( $status=='1')){
        					exit('st');
        				}
        
        				//require_once(WPSC_FILE_PATH."/shopping_cart_functions.php"); 
        			  echo  "if(document.getElementById('shoppingcartcontents') != null)
        					  {
        					  document.getElementById('shoppingcartcontents').innerHTML = \"".str_replace(Array("\n","\r") , "",addslashes(nzshpcrt_shopping_basket_internals($cart,$quantity_limit))). "\";
        					  }
        					";
        
        			  
        			  if($_SESSION['slider_state'] == 0) {
        				//echo  'jQuery("#sliding_cart").css({ display: "none"});'."\n\r";
        				} else {
        				//echo  'jQuery("#sliding_cart").css({ display: "block"});'."\n\r";
        				}
        			}
        		}
              exit();
        		} else if(($_POST['user'] == "true") && ($_POST['emptycart'] == "true")) {
        			$_SESSION['nzshpcrt_cart'] = '';			
        			$_SESSION['nzshpcrt_cart'] = Array();      
        			echo  "if(document.getElementById('shoppingcartcontents') != null) {   
        			document.getElementById('shoppingcartcontents').innerHTML = \"".str_replace(Array("\n","\r") , "", addslashes(nzshpcrt_shopping_basket_internals($cart))). "\";
        			}\n\r";
        			
        			if($_POST['current_page'] == get_option('shopping_cart_url')) {
        			  echo "window.location = '".get_option('shopping_cart_url')."';\n\r"; // if we are on the checkout page, redirect back to it to clear the non-ajax cart too
        			}
        			exit();
        		}*/
        if ($_POST['store_list'] == "true") {
            $map_data['address'] = $_POST['addr'];
            $map_data['city'] = $_POST['city'];
            $map_data['country'] = 'US';
            $map_data['zipcode'] = '';
            $map_data['radius'] = '50000';
            $map_data['state'] = '';
            $map_data['submit'] = 'Find Store';
            $stores = getdistance($map_data);
            $i = 0;
            while ($rows = mysql_fetch_array($stores)) {
                //echo "<pre>".print_r($rows,1)."</pre>";
                if ($i == 0) {
                    $closest_store = $rows[5];
                }
                $i++;
                $store_list[$i] = $rows[5];
            }
            foreach ($store_list as $store) {
                $output .= "<option value='{$store}'>{$store}</option>";
            }
            echo $output;
            exit;
        }
        if (is_numeric($_POST['currencyid'])) {
            $currency_data = $wpdb->get_results("SELECT `symbol`,`symbol_html`,`code` FROM `" . WPSC_TABLE_CURRENCY_LIST . "` WHERE `id`='" . $_POST['currencyid'] . "' LIMIT 1", ARRAY_A);
            $price_out = null;
            if ($currency_data[0]['symbol'] != '') {
                $currency_sign = $currency_data[0]['symbol_html'];
            } else {
                $currency_sign = $currency_data[0]['code'];
            }
            echo $currency_sign;
            exit;
        }
        if ($_POST['buynow'] == "true") {
            if (is_numeric($_REQUEST['product_id']) && is_numeric($_REQUEST['price'])) {
                $id = $wpdb->escape((int) $_REQUEST['product_id']);
                $price = $wpdb->escape((double) $_REQUEST['price']);
                $downloads = get_option('max_downloads');
                $product_info = $wpdb->get_row("SELECT * FROM " . WPSC_TABLE_PRODUCT_LIST . " WHERE id = " . $id . " LIMIT 1", ARRAY_A);
                if (count($product_info) > 0) {
                    $sessionid = mt_rand(100, 999) . time();
                    $sql = "INSERT INTO `" . WPSC_TABLE_PURCHASE_LOGS . "` ( `totalprice` , `sessionid` , `date`, `billing_country`, `shipping_country`,`shipping_region`, `user_ID`, `discount_value` ) VALUES ( '" . $price . "', '" . $sessionid . "', '" . time() . "', 'BuyNow', 'BuyNow', 'BuyNow' , NULL , 0)";
                    $wpdb->query($sql);
                    $log_id = $wpdb->get_var("SELECT `id` FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE `sessionid` IN('" . $sessionid . "') LIMIT 1");
                    $cartsql = "INSERT INTO `" . WPSC_TABLE_CART_CONTENTS . "` ( `prodid` , `purchaseid`, `price`, `pnp`, `gst`, `quantity`, `donation`, `no_shipping` ) VALUES ('" . $id . "', '" . $log_id . "','" . $price . "','0', '0','1', '" . $donation . "', '1')";
                    $wpdb->query($cartsql);
                    $wpdb->query("INSERT INTO `" . WPSC_TABLE_DOWNLOAD_STATUS . "` ( `fileid` , `purchid` , `downloads` , `active` , `datetime` ) VALUES ( '" . $product_info['file'] . "', '" . $log_id . "', '{$downloads}', '0', NOW( ));");
                }
            }
            exit;
        }
        /* rate item */
        if ($_POST['rate_item'] == "true" && is_numeric($_POST['product_id']) && is_numeric($_POST['rating'])) {
            $nowtime = time();
            $prodid = $_POST['product_id'];
            $ip_number = $_SERVER['REMOTE_ADDR'];
            $rating = $_POST['rating'];
            $cookie_data = explode(",", $_COOKIE['voting_cookie'][$prodid]);
            if (is_numeric($cookie_data[0]) && $cookie_data[0] > 0) {
                $vote_id = $cookie_data[0];
                $wpdb->query("UPDATE `" . WPSC_TABLE_PRODUCT_RATING . "` SET `rated` = '" . $rating . "' WHERE `id` ='" . $vote_id . "' LIMIT 1 ;");
            } else {
                $insert_sql = "INSERT INTO `" . WPSC_TABLE_PRODUCT_RATING . "` ( `ipnum`  , `productid` , `rated`, `time`) VALUES ( '" . $ip_number . "', '" . $prodid . "', '" . $rating . "', '" . $nowtime . "');";
                $wpdb->query($insert_sql);
                $data = $wpdb->get_results("SELECT `id`,`rated` FROM `" . WPSC_TABLE_PRODUCT_RATING . "` WHERE `ipnum`='" . $ip_number . "' AND `productid` = '" . $prodid . "'  AND `rated` = '" . $rating . "' AND `time` = '" . $nowtime . "' ORDER BY `id` DESC LIMIT 1", ARRAY_A);
                $vote_id = $data[0]['id'];
                setcookie("voting_cookie[{$prodid}]", $vote_id . "," . $rating, time() + 60 * 60 * 24 * 360);
            }
            $output[1] = $prodid;
            $output[2] = $rating;
            echo $output[1] . "," . $output[2];
            exit;
        }
        //written by allen
        if ($_REQUEST['save_tracking_id'] == "true") {
            $id = $_POST['id'];
            $value = $_POST['value'];
            $update_sql = "UPDATE " . WPSC_TABLE_PURCHASE_LOGS . " SET track_id = '" . $value . "' WHERE id={$id}";
            $wpdb->query($update_sql);
            exit;
        }
        if ($_POST['get_updated_price'] == "true" && is_numeric($_POST['product_id'])) {
            $notax = $wpdb->get_var("SELECT `notax` FROM `" . WPSC_TABLE_PRODUCT_LIST . "` WHERE `id` IN('" . $_POST['product_id'] . "') LIMIT 1");
            foreach ((array) $_POST['variation'] as $variation) {
                if (is_numeric($variation)) {
                    $variations[] = (int) $variation;
                }
            }
            $pm = $_POST['pm'];
            echo "product_id=" . (int) $_POST['product_id'] . ";\n";
            echo "price=\"" . nzshpcrt_currency_display(calculate_product_price((int) $_POST['product_id'], $variations, 'stay', $extras), $notax, true) . "\";\n";
            echo "numeric_price=\"" . number_format(calculate_product_price((int) $_POST['product_id'], $variations, 'stay', $extras), 2) . "\";\n";
            //exit(print_r($extras,1));
            exit(" ");
        }
        // 	if(($_POST['redisplay_variation_values'] == "true")) {
        // 		$variation_processor = new nzshpcrt_variations();
        // 		$variations_selected = array_values(array_unique(array_merge((array)$_POST['new_variation_id'], (array)$_POST['variation_id'])));
        // 		foreach($variations_selected as $variation_id) {
        // 		  // cast everything to integer to make sure nothing nasty gets in.
        // 		  $variation_list[] = (int)$variation_id;
        // 		}
        // 		echo $variation_processor->variations_add_grid_view((array)$variation_list);
        // 		//echo "/*\n\r".print_r(array_values(array_unique($_POST['variation_id'])),true)."\n\r*/";
        // 		exit();
        // 	}
        //
        /*
         * function for handling the checkout billing address
         */
        if (preg_match("/[a-zA-Z]{2,4}/", $_POST['billing_country'])) {
            if ($_SESSION['selected_country'] == $_POST['billing_country']) {
                $do_not_refresh_regions = true;
            } else {
                $do_not_refresh_regions = false;
                $_SESSION['selected_country'] = $_POST['billing_country'];
            }
            if (is_numeric($_POST['form_id'])) {
                $form_id = $_POST['form_id'];
                $html_form_id = "region_country_form_{$form_id}";
            } else {
                $html_form_id = 'region_country_form';
            }
            if (is_numeric($_POST['billing_region'])) {
                $_SESSION['selected_region'] = $_POST['billing_region'];
            }
            $cart =& $_SESSION['nzshpcrt_cart'];
            if ($memberstatus[0] == '1' && count($cart) > 0) {
                echo "\n\r";
            } else {
                if ($status[0] == '1') {
                    exit;
                }
                echo "if(document.getElementById('shoppingcartcontents') != null)\n\t\t\t\t\t  {\n\t\t\t\t\t  document.getElementById('shoppingcartcontents').innerHTML = \"" . str_replace(array("\n", "\r"), "", addslashes(nzshpcrt_shopping_basket_internals($cart, $quantity_limit))) . "\";\n\t\t\t\t\t  }\n\r";
                if ($do_not_refresh_regions == false) {
                    $region_list = $wpdb->get_results("SELECT `" . WPSC_TABLE_REGION_TAX . "`.* FROM `" . WPSC_TABLE_REGION_TAX . "`, `" . WPSC_TABLE_CURRENCY_LIST . "`  WHERE `" . WPSC_TABLE_CURRENCY_LIST . "`.`isocode` IN('" . $_POST['billing_country'] . "') AND `" . WPSC_TABLE_CURRENCY_LIST . "`.`id` = `" . WPSC_TABLE_REGION_TAX . "`.`country_id`", ARRAY_A);
                    if ($region_list != null) {
                        $output .= "<select name='collected_data[" . $form_id . "][1]' class='current_region' onchange='set_billing_country(\\\"{$html_form_id}\\\", \\\"{$form_id}\\\");'>";
                        //$output .= "<option value=''>None</option>";
                        foreach ($region_list as $region) {
                            if ($_SESSION['selected_region'] == $region['id']) {
                                $selected = "selected='true'";
                            } else {
                                $selected = "";
                            }
                            $output .= "<option value='" . $region['id'] . "' {$selected}>" . $region['name'] . "</option>";
                        }
                        $output .= "</select>";
                        echo "if(document.getElementById('region_select_{$form_id}') != null)\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\tdocument.getElementById('region_select_{$form_id}').innerHTML = \"" . $output . "\";\n\t\t\t\t\t\t\t}\n\r";
                    } else {
                        echo "if(document.getElementById('region_select_{$form_id}') != null)\n\t\t\t\t\t\t{\n\t\t\t\t\t\tdocument.getElementById('region_select_{$form_id}').innerHTML = \"\";\n\t\t\t\t\t\t}\n\r";
                    }
                }
            }
            if ($_POST['changetax'] == "true") {
                if (isset($_POST['billing_region'])) {
                    $billing_region = $_POST['billing_region'];
                } else {
                    $billing_region = $_SESSION['selected_region'];
                }
                $billing_country = $_POST['billing_country'];
                $price = 0;
                $tax = 0;
                foreach ((array) $cart as $cart_item) {
                    $product_id = $cart_item->product_id;
                    $quantity = $cart_item->quantity;
                    //echo("<pre>".print_r($cart_item->product_variations,true)."</pre>");
                    $product = $wpdb->get_row("SELECT * FROM `" . WPSC_TABLE_PRODUCT_LIST . "` WHERE `id` = '{$product_id}' LIMIT 1", ARRAY_A);
                    if ($product['donation'] == 1) {
                        $price += $quantity * $cart_item->donation_price;
                    } else {
                        $product_price = $quantity * calculate_product_price($product_id, $cart_item->product_variations);
                        if ($product['notax'] != 1) {
                            $tax += nzshpcrt_calculate_tax($product_price, $billing_country, $billing_region) - $product_price;
                        }
                        $price += $product_price;
                        $all_donations = false;
                    }
                    if ($_SESSION['delivery_country'] != null) {
                        $total_shipping += nzshpcrt_determine_item_shipping($product['id'], $quantity, $_SESSION['delivery_country']);
                    }
                }
                $total_shipping += nzshpcrt_determine_base_shipping(0, $_SESSION['delivery_country']);
                $total = number_format($tax + $price + $total_shipping, 2);
                if ($tax > 0) {
                    echo "jQuery(\"tr.total_tax td\").show();\n\r";
                } else {
                    echo "jQuery(\"tr.total_tax td\").hide();\n\r";
                }
                $tax = number_format($tax, 2);
                echo "jQuery('#checkout_tax').html(\"<span class='pricedisplay'>\${$tax}</span>\");\n\r";
                echo "jQuery('#checkout_total').html(\"<span class='pricedisplay'>\${$total}</span><input id='shopping_cart_total_price' type='hidden' value='\${$total}'>\");\n\r";
            }
            exit;
        }
        if ($_POST['get_country_tax'] == "true" && preg_match("/[a-zA-Z]{2,4}/", $_POST['country_id'])) {
            $country_id = $_POST['country_id'];
            $region_list = $wpdb->get_results("SELECT `" . WPSC_TABLE_REGION_TAX . "`.* FROM `" . WPSC_TABLE_REGION_TAX . "`, `" . WPSC_TABLE_CURRENCY_LIST . "`  WHERE `" . WPSC_TABLE_CURRENCY_LIST . "`.`isocode` IN('" . $country_id . "') AND `" . WPSC_TABLE_CURRENCY_LIST . "`.`id` = `" . WPSC_TABLE_REGION_TAX . "`.`country_id`", ARRAY_A);
            if ($region_list != null) {
                echo "<select name='base_region'>\n\r";
                foreach ($region_list as $region) {
                    if (get_option('base_region') == $region['id']) {
                        $selected = "selected='true'";
                    } else {
                        $selected = "";
                    }
                    echo "<option value='" . $region['id'] . "' {$selected}>" . $region['name'] . "</option>\n\r";
                }
                echo "</select>\n\r";
            } else {
                echo "&nbsp;";
            }
            exit;
        }
        /* fill product form */
        if ($_POST['set_slider'] == "true" && is_numeric($_POST['state'])) {
            $_SESSION['slider_state'] = $_POST['state'];
            exit;
        }
        /* fill category form */
        if ($_GET['action'] == "register") {
            $siteurl = get_option('siteurl');
            require_once ABSPATH . WPINC . '/registration-functions.php';
            if ($_POST['action'] == 'register' && get_settings('users_can_register')) {
                //exit("fail for testing purposes");
                $user_login = sanitize_user($_POST['user_login']);
                $user_email = $_POST['user_email'];
                $errors = array();
                if ($user_login == '') {
                    exit($errors['user_login'] = __('<strong>ERROR</strong>: Please enter a username.'));
                }
                /* checking e-mail address */
                if ($user_email == '') {
                    exit(__('<strong>ERROR</strong>: Please type your e-mail address.'));
                } else {
                    if (!is_email($user_email)) {
                        exit(__('<strong>ERROR</strong>: The email address isn&#8217;t correct.'));
                        $user_email = '';
                    }
                }
                if (!validate_username($user_login)) {
                    $errors['user_login'] = __('<strong>ERROR</strong>: This username is invalid.  Please enter a valid username.');
                    $user_login = '';
                }
                if (username_exists($user_login)) {
                    exit(__('<strong>ERROR</strong>: This username is already registered, please choose another one.'));
                }
                /* checking the email isn't already used by another user */
                $email_exists = $wpdb->get_row("SELECT user_email FROM {$wpdb->users} WHERE user_email = '{$user_email}'");
                if ($email_exists) {
                    die(__('<strong>ERROR</strong>: This email address is already registered, please supply another.'));
                }
                if (0 == count($errors)) {
                    $password = substr(md5(uniqid(microtime())), 0, 7);
                    //xit('there?');
                    $user_id = wp_create_user($user_login, $password, $user_email);
                    if (!$user_id) {
                        exit(sprintf(__('<strong>ERROR</strong>: Couldn&#8217;t register you... please contact the <a href="mailto:%s">webmaster</a> !'), get_settings('admin_email')));
                    } else {
                        wp_new_user_notification($user_id, $password);
                        ?>
<div id="login"> 
  <h2><?php 
                        _e('Registration Complete');
                        ?>
</h2>
  <p><?php 
                        printf(__('Username: %s'), "<strong>" . wp_specialchars($user_login) . "</strong>");
                        ?>
<br />
  <?php 
                        printf(__('Password: %s'), '<strong>' . __('emailed to you') . '</strong>');
                        ?>
 <br />
  <?php 
                        printf(__('E-mail: %s'), "<strong>" . wp_specialchars($user_email) . "</strong>");
                        ?>
</p>
</div>
<?php 
                    }
                }
            } else {
                // onsubmit='submit_register_form(this);return false;'
                echo "<div id='login'>\n    <h2>Register for this blog</h2>\n    <form id='registerform' action='index.php?ajax=true&amp;action=register'  onsubmit='submit_register_form(this);return false;' method='post'>\n      <p><input type='hidden' value='register' name='action'/>\n      <label for='user_login'>Username:</label><br/> <input type='text' value='' maxlength='20' size='20' id='user_login' name='user_login'/><br/></p>\n      <p><label for='user_email'>E-mail:</label><br/> <input type='text' value='' maxlength='100' size='25' id='user_email' name='user_email'/></p>\n      <p>A password will be emailed to you.</p>\n      <p class='submit'><input type='submit' name='submit_form' id='submit' value='" . TXT_WPSC_REGISTER . " »'/><img id='register_loading_img' src='" . WPSC_URL . "/images/loading.gif' alt='' title=''></p>\n\n      \n    </form>\n    </div>";
            }
            exit;
        }
    }
    /*
    * AJAX stuff stops here, I would put an exit here, but it may screw up other plugins
    //exit();
    */
}
Exemplo n.º 21
0
function wpsc_display_purchlog_details()
{
    while (wpsc_have_purchaselog_details()) {
        wpsc_the_purchaselog_item();
        ?>
 	<tr>
 	<td><?php 
        echo wpsc_purchaselog_details_name();
        ?>
</td> <!-- NAME -->
 	<td><?php 
        echo wpsc_purchaselog_details_SKU();
        ?>
</td> <!-- SKU -->
 	<td><?php 
        echo wpsc_purchaselog_details_quantity();
        ?>
</td> <!-- QUANTITY-->
 	<td><?php 
        echo nzshpcrt_currency_display(wpsc_purchaselog_details_price(), true);
        ?>
</td> <!-- PRICE -->
 	<td><?php 
        echo nzshpcrt_currency_display(wpsc_purchaselog_details_tax(), true);
        ?>
</td> <!-- TAX -->
 	<?php 
        /* <td><?php echo nzshpcrt_currency_display(wpsc_purchaselog_details_discount(),true); ?></td> <!-- DISCOUNT --> */
        ?>
 	<td><?php 
        echo nzshpcrt_currency_display(wpsc_purchaselog_details_total(), true);
        ?>
</td> <!-- TOTAL -->
 	</tr>
 	<?php 
    }
}
Exemplo n.º 22
0
 echo "<tr >";
 echo " <td>";
 echo " </td>";
 echo " <td>";
 echo " </td>";
 echo " <td>";
 echo " </td>";
 echo " <td>";
 echo "<strong>" . TXT_WPSC_TOTALSHIPPING . ":</strong><br />";
 echo "<strong>" . TXT_WPSC_FINALTOTAL . ":</strong>";
 echo " </td>";
 echo " <td>";
 $total_shipping = nzshpcrt_determine_base_shipping($total_shipping, $shipping_country);
 $endtotal += $total_shipping;
 echo nzshpcrt_currency_display($total_shipping, 1) . "<br />";
 echo nzshpcrt_currency_display($endtotal, 1);
 echo " </td>";
 echo '</tr>';
 echo "</table>";
 echo "<br />";
 echo "<strong>" . TXT_WPSC_CUSTOMERDETAILS . "</strong>";
 echo "<table>";
 $form_sql = "SELECT * FROM `" . $wpdb->prefix . "submited_form_data` WHERE  `log_id` = '" . $purchase['id'] . "'";
 $input_data = $wpdb->get_results($form_sql, ARRAY_A);
 //exit("<pre>".print_r($input_data,true)."</pre>");
 if ($input_data != null) {
     foreach ((array) $input_data as $form_field) {
         $form_sql = "SELECT * FROM `" . $wpdb->prefix . "collect_data_forms` WHERE `active` = '1' AND `id` = '" . $form_field['form_id'] . "' LIMIT 1";
         $form_data = $wpdb->get_results($form_sql, ARRAY_A);
         if ($form_data != null) {
             $form_data = $form_data[0];
Exemplo n.º 23
0
echo nzshpcrt_currency_display(admin_display_total_price($start_timestamp, $end_timestamp), 1);
echo " " . TXT_WPSC_ACCEPTED_PAYMENTS;
?>
      </p>
      </div>
     
      
      <div class='order_summary_subsection'>
      <strong><?php 
echo TXT_WPSC_TOTAL_INCOME;
?>
</strong>
      <p id='log_total_absolute'>
      <?php 
//$total_income = $wpdb->get_results($sql,ARRAY_A);
echo nzshpcrt_currency_display(admin_display_total_price(), 1);
?>
      </p>
      </div>
      
      
     
      <div class='order_summary_subsection'>
      <strong><?php 
echo TXT_WPSC_RSS_FEED_HEADER;
?>
</strong>
      <p>
        <a class='product_log_rss' href='index.php?rss=true&amp;rss_key=key&amp;action=purchase_log'><img align='absmiddle' src='<?php 
echo WPSC_URL;
?>
Exemplo n.º 24
0
function single_product_display($product_id)
{
    global $wpdb;
    $siteurl = get_option('siteurl');
    if (get_option('permalink_structure') != '') {
        $seperator = "?";
    } else {
        $seperator = "&amp;";
    }
    // what is our product?
    if (is_numeric($product_id)) {
        $product_list = $wpdb->get_results("SELECT * FROM `" . $wpdb->prefix . "product_list` WHERE `id`='" . (int) $product_id . "' LIMIT 1", ARRAY_A);
    }
    // if we have a product
    if ($product_list != null) {
        // show the breadcrumbs
        if (get_option("show_breadcrumbs") == '1') {
            $output .= "<div class='breadcrumb'>\n\r";
            $output .= "  <a href='" . get_option('siteurl') . "'>" . get_option('blogname') . "</a> &raquo; ";
            $category = $wpdb->get_var("SELECT category_id FROM {$wpdb->prefix}item_category_associations WHERE product_id='" . $product_id . "' ORDER BY id ASC LIMIT 1");
            $category_info = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}product_categories WHERE id='" . $category . "'", ARRAY_A);
            $category_name = $wpdb->get_var("SELECT name FROM {$wpdb->prefix}product_categories WHERE id='" . $category . "'");
            while ($category_info[0]['category_parent'] != 0) {
                $category_info = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}product_categories WHERE id='" . $category_info[0]['category_parent'] . "'", ARRAY_A);
                $output .= "<a href='" . wpsc_category_url($category_info[0]['id']) . "'>" . $category_info[0]['name'] . "</a> &raquo; ";
            }
            $output .= "<a href='" . wpsc_category_url($category) . "'>" . $category_name . "</a> &raquo; ";
            $output .= $product_list[0]['name'] . "\n\r";
            $output .= "</div>\n\r";
        }
        $output .= "  <div class='productdisplay'>\n\r";
        foreach ((array) $product_list as $product) {
            $num++;
            $output .= "    <div class='single_product_display product_view_{$product['id']} '>\n\r";
            $output .= "      <div class='textcol'>\n\r";
            // display the image
            $output .= "        <div class='imagecol'>\n\r";
            if (get_option('show_thumbnails') == 1) {
                if ($product['image'] != null) {
                    if ($product['thumbnail_image'] != null) {
                        $image_file_name = $product['thumbnail_image'];
                    } else {
                        $image_file_name = $product['image'];
                    }
                    $output .= "<a href='" . WPSC_IMAGE_URL . $product['image'] . "' class='thickbox preview_link'  rel='" . str_replace(" ", "_", $product['name']) . "'>\n\r";
                    $src = WPSC_IMAGE_URL . $product['image'];
                    if (get_option('single_view_image_width') >= 1 && get_option('single_view_image_height') >= 1) {
                        $output .= "<img src='index.php?productid=" . $product['id'] . "&amp;width=" . get_option('single_view_image_width') . "&amp;height=" . get_option('single_view_image_height') . "' title='" . $product['name'] . "' alt='" . $product['name'] . "' id='product_image_" . $product['id'] . "' class='product_image'/>\n\r";
                    } else {
                        $output .= "<img src='" . WPSC_THUMBNAIL_URL . $image_file_name . "' title='" . $product['name'] . "' alt='" . $product['name'] . "' id='product_image_" . $product['id'] . "' class='product_image'/>\n\r";
                    }
                    $output .= "</a>\n\r";
                    if (function_exists("gold_shpcrt_display_extra_images")) {
                        $output .= gold_shpcrt_display_extra_images($product['id'], $product['name']);
                    }
                } else {
                    if (get_option('product_image_width') != '') {
                        $output .= "<img src='" . WPSC_URL . "/no-image-uploaded.gif' title='" . $product['name'] . "' alt='" . $product['name'] . "' width='" . get_option('product_image_width') . "' height='" . get_option('product_image_height') . "' />\n\r";
                    } else {
                        $output .= "<img src='" . WPSC_URL . "/no-image-uploaded.gif' title='" . $product['name'] . "' alt='" . $product['name'] . "' />\n\r";
                    }
                }
            }
            $output .= "        </div>\n\r";
            // if the product is special, say so
            if ($product['special'] == 1) {
                $special = "        <span class='special'>" . TXT_WPSC_SPECIAL . " - </span>\n\r";
            }
            $output .= "        <form id='product_" . $product['id'] . "' name='{$num}' method='post' action='" . get_option('product_list_url') . $seperator . "category=" . $_GET['category'] . "' onsubmit='submitform(this);return false;' >\n\r";
            $output .= "<input type='hidden' name='prodid' value='" . $product['id'] . "' />\n\r";
            $output .= "        <div class='producttext'>\n\r";
            $output .= "           <h2 class='prodtitles'>{$special}" . stripslashes($product['name']) . "</h2>\n\r";
            if (get_option('wpsc_selected_theme') == 'market3') {
                $soldout = 0;
                if ($product['quantity_limited'] && $product['quantity'] < 1) {
                    $soldout = 1;
                }
                if ($soldout) {
                    $output .= "           <span class='soldout'>Sold out</span>\n\r";
                } else {
                    $output .= "           <span class='price'>" . nzshpcrt_currency_display($product['price'], $product['notax']) . "</span>\n\r";
                }
            }
            ob_start();
            do_action('wpsc_product_addons', $product['id']);
            $output .= ob_get_contents();
            ob_end_clean();
            if (is_numeric($product['file']) && $product['file'] > 0) {
                $file_data = $wpdb->get_row("SELECT * FROM `" . $wpdb->prefix . "product_files` WHERE `id`='" . $product['file'] . "' LIMIT 1", ARRAY_A);
                if ($file_data != null && function_exists('listen_button')) {
                    $output .= listen_button($file_data['idhash'], $file_data['id']);
                }
            }
            if ($product['description'] != '') {
                $output .= "           <p  class='description'>" . nl2br(stripslashes($product['description'])) . "</p>\n\r";
            }
            if (get_option('wpsc_selected_theme') == 'market3') {
                $output .= "           <br />";
            }
            if ($product['additional_description'] != '') {
                $output .= "           <p class='single_additional_description' >\n\r";
                if (get_option('wpsc_selected_theme') == 'market3') {
                    $output .= "           <span class='additional'>Additional Details: </span>\n\r";
                }
                $output .= nl2br(stripslashes($product['additional_description'])) . "";
                $output .= "           </p>\n\r";
            }
            // print the custom fields here, if there are any
            $custom_fields = $wpdb->get_results("SELECT * FROM `{$wpdb->prefix}wpsc_productmeta` WHERE `product_id` IN('{$product['id']}') AND `custom` IN('1') ", ARRAY_A);
            if (count($custom_fields) > 0) {
                $output .= "           <div class='custom_meta'>\n\r";
                foreach ((array) $custom_fields as $custom_field) {
                    $output .= "             <strong>{$custom_field['meta_key']}:</strong> {$custom_field['meta_value']} <br />\n\r";
                }
                $output .= "           </div>\n\r";
            }
            ob_start();
            do_action('wpsc_product_addon_after_descr', $product['id']);
            $output .= ob_get_contents();
            ob_end_clean();
            if (function_exists('wpsc_akst_share_link') && get_option('wpsc_share_this') == 1) {
                $output .= wpsc_akst_share_link('return');
            }
            $variations_procesor = new nzshpcrt_variations();
            $variations_output = $variations_procesor->display_product_variations($product['id'], false, false, true);
            if ($variations_output[0] != '') {
                //will always be set, may sometimes be an empty string
                $output .= "           <p class='wpsc_variation_forms'>" . $variations_output[0] . "</p>";
            }
            if ($variations_output[1] !== null) {
                $product['price'] = $variations_output[1];
            }
            if (get_option('wpsc_selected_theme') != 'market3') {
                $output .= "           <p class='wpsc_product_price'>";
                if ($product['donation'] == 1) {
                    $currency_sign_location = get_option('currency_sign_location');
                    $currency_type = get_option('currency_type');
                    $currency_symbol = $wpdb->get_var("SELECT `symbol_html` FROM `" . $wpdb->prefix . "currency_list` WHERE `id`='" . $currency_type . "' LIMIT 1");
                    $output .= "           <label for='donation_price_" . $product['id'] . "'>" . TXT_WPSC_DONATION . ":</label> {$currency_symbol}<input type='text' id='donation_price_" . $product['id'] . "' name='donation_price' value='" . number_format($product['price'], 2) . "' size='6' /><br />";
                } else {
                    if (get_option('wpsc_selected_theme') != 'market3') {
                        if ($product['special'] == 1 && $variations_output[1] === null) {
                            $output .= "<span class='oldprice'>" . TXT_WPSC_PRICE . ": " . nzshpcrt_currency_display($product['price'], $product['notax']) . "</span><br />";
                            $output .= TXT_WPSC_PRICE . ": " . nzshpcrt_currency_display($product['price'] - $product['special_price'], $product['notax'], false, $product['id']) . "<br />";
                        } else {
                            $output .= TXT_WPSC_PRICE . ": <span id='product_price_" . $product['id'] . "'>" . nzshpcrt_currency_display($product['price'], $product['notax']) . "</span><br />";
                        }
                        // if(get_option('display_pnp') == 1) {
                        // 	$output .= TXT_WPSC_PNP.": " . nzshpcrt_currency_display($product['pnp'], 1) . "<br />";
                        // }
                    }
                }
                $output .= "</p>\n\r";
            }
            if (function_exists('wpsc_theme_html')) {
                $wpsc_theme = wpsc_theme_html($product);
            }
            $output .= "<input type='hidden' name='item' value='" . $product['id'] . "' />";
            //AND (`quantity_limited` = '1' AND `quantity` > '0' OR `quantity_limited` = '0' )
            if ($product['quantity_limited'] == 1 && $product['quantity'] < 1 && $variations_output[1] === null) {
                if (get_option("wpsc_selected_theme") != 'market3') {
                    $output .= "<p class='soldout'>" . TXT_WPSC_PRODUCTSOLDOUT . "</p>";
                }
            } else {
                if (get_option('hide_addtocart_button') != 1 && get_option('addtocart_or_buynow') == 0) {
                    if (isset($wpsc_theme) && is_array($wpsc_theme) && $wpsc_theme['html'] != '') {
                        $output .= $wpsc_theme['html'];
                    } else {
                        $output .= "<input type='submit' id='product_" . $product['id'] . "_submit_button' class='wpsc_buy_button' name='Buy' value='" . TXT_WPSC_ADDTOCART . "'  />";
                    }
                }
            }
            if (function_exists('gold_shpcrt_display_gallery')) {
                $output .= gold_shpcrt_display_gallery($product['id']);
            }
            if (get_option('product_ratings') == 1) {
                $output .= "<div class='product_footer'>";
                $output .= "<div class='product_average_vote'>";
                $output .= "<strong>" . TXT_WPSC_AVGCUSTREVIEW . ":</strong>";
                $output .= nzshpcrt_product_rating($product['id']);
                $output .= "</div>";
                $output .= "<div class='product_user_vote'>";
                $vote_output = nzshpcrt_product_vote($product['id'], "onmouseover='hide_save_indicator(\"saved_" . $product['id'] . "_text\");'");
                if ($vote_output[1] == 'voted') {
                    $output .= "<strong><span id='rating_" . $product['id'] . "_text'>" . TXT_WPSC_YOURRATING . ":</span>";
                    $output .= "<span class='rating_saved' id='saved_" . $product['id'] . "_text'> " . TXT_WPSC_RATING_SAVED . "</span>";
                    $output .= "</strong>";
                } else {
                    if ($vote_output[1] == 'voting') {
                        $output .= "<strong><span id='rating_" . $product['id'] . "_text'>" . TXT_WPSC_RATETHISITEM . ":</span>";
                        $output .= "<span class='rating_saved' id='saved_" . $product['id'] . "_text'> " . TXT_WPSC_RATING_SAVED . "</span>";
                        $output .= "</strong>";
                    }
                }
                $output .= $vote_output[0];
                $output .= "</div>";
                $output .= "</div>";
            }
            $output .= "          </div>\n\r";
            $output .= "        </form>\n\r";
            if (count($updatelink_data) > 0 && $updatelink_data[0]['meta_value'] != '') {
                $output .= external_link($product['id']);
            } else {
                if (get_option('addtocart_or_buynow') == '1') {
                    if (get_option('payment_gateway') == 'google') {
                        $output .= google_buynow($product['id']);
                    } else {
                        if (get_option('payment_gateway') == 'paypal_multiple') {
                            $output .= "<form onsubmit='log_paypal_buynow(this)' target='paypal' action='" . get_option('paypal_multiple_url') . "' method='post'>\n\t\t\t\t\t\t\t<input type='hidden' name='business' value='" . get_option('paypal_multiple_business') . "'>\n\t\t\t\t\t\t\t<input type='hidden' name='cmd' value='_xclick'>\n\t\t\t\t\t\t\t<input type='hidden' name='item_name' value='" . $product['name'] . "'>\n\t\t\t\t\t\t\t<input type='hidden' id='item_number' name='item_number' value='" . $product['id'] . "'>\n\t\t\t\t\t\t\t<input type='hidden' id='amount' name='amount' value='" . $product['price'] . "'>\n\t\t\t\t\t\t\t<input type='hidden' id='unit' name='unit' value='" . $product['price'] . "'>\n\t\t\t\t\t\t\t<input type='hidden' id='shipping' name='ship11' value='" . $shipping . "'>\n\t\t\t\t\t\t\t<input type='hidden' name='handling' value='" . get_option('base_local_shipping') . "'>\n\t\t\t\t\t\t\t<input type='hidden' name='currency_code' value='" . get_option('paypal_curcode') . "'>\n\t\t\t\t\t\t\t<input type='hidden' name='undefined_quantity' value='0'>\n\t\t\t\t\t\t\t<input type='image' name='submit' border='0' src='https://www.paypal.com/en_US/i/btn/btn_buynow_LG.gif' alt='PayPal - The safer, easier way to pay online'>\n\t\t\t\t\t\t\t<img alt='' border='0' width='1' height='1' src='https://www.paypal.com/en_US/i/scr/pixel.gif' >\n\t\t\t\t\t\t</form>\n\t\t\t\t\t";
                        }
                    }
                }
            }
            $output .= "        <form id='product_extra_" . $product['id'] . "' name='product_" . $product['id'] . "' method='post' action='" . get_option('product_list_url') . $seperator . "category=" . $_GET['category'] . "' onsubmit='submitform(this);return false;' >\n\r";
            $output .= "          <input type='hidden' name='prodid' value='" . $product['id'] . "' />\n\r";
            $output .= "          <input type='hidden' name='item' value='" . $product['id'] . "' />\n\r";
            $output .= "        </form>\n\r";
            $output .= "      </div>\n\r";
            $output .= "    </div>\n\r";
            $output .= " <div class='clear'></div>\n\r";
        }
        $output .= wpsc_also_bought($product_id);
        $output .= "  </div>";
    } else {
        // otherwise, we have no product
        $output .= "<p>" . TXT_WPSC_NOITEMSINTHIS . " " . $group_type . ".</p>";
    }
    // replace dollar signs with the HTML code so that PHP doesn't try to interpret them as variables.
    $output = str_replace('$', '&#036;', $output);
    return $output;
}
Exemplo n.º 25
0
function wpsc_admin_latest_activity()
{
    global $wpdb;
    $totalOrders = $wpdb->get_var("SELECT COUNT(*) FROM `" . WPSC_TABLE_PURCHASE_LOGS . "`");
    /*
     * This is the right hand side for the past 30 days revenue on the wp dashboard
     */
    echo "<div id='leftDashboard'>";
    echo "<strong class='dashboardHeading'>" . __('Last 30 Days', 'wpsc') . "</strong><br />";
    echo "<p class='dashboardWidgetSpecial'>";
    // calculates total amount of orders for the month
    $year = date("Y");
    $month = date("m");
    $start_timestamp = mktime(0, 0, 0, $month, 1, $year);
    $end_timestamp = mktime(0, 0, 0, $month + 1, 0, $year);
    $sql = "SELECT COUNT(*) FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE `date` BETWEEN '{$start_timestamp}' AND '{$end_timestamp}' AND `processed` IN (2,3,4) ORDER BY `date` DESC";
    $currentMonthOrders = $wpdb->get_var($sql);
    //calculates amount of money made for the month
    $currentMonthsSales = nzshpcrt_currency_display(admin_display_total_price($start_timestamp, $end_timestamp), 1);
    echo $currentMonthsSales;
    echo "<span class='dashboardWidget'>" . __('Sales', 'wpsc') . "</span>";
    echo "</p>";
    echo "<p class='dashboardWidgetSpecial'>";
    echo "<span class='pricedisplay'>";
    echo $currentMonthOrders;
    echo "</span>";
    echo "<span class='dashboardWidget'>" . __('Orders', 'wpsc') . "</span>";
    echo "</p>";
    echo "<p class='dashboardWidgetSpecial'>";
    //echo "<span class='pricedisplay'>";
    //calculates average sales amount per order for the month
    if ($currentMonthOrders > 0) {
        $monthsAverage = (int) admin_display_total_price($start_timestamp, $end_timestamp) / (int) $currentMonthOrders;
        echo nzshpcrt_currency_display($monthsAverage, 1);
    }
    //echo "</span>";
    echo "<span class='dashboardWidget'>" . __('Avg Orders', 'wpsc') . "</span>";
    echo "</p>";
    echo "</div>";
    /*
     *This is the left side for the total life time revenue on the wp dashboard
     */
    echo "<div id='rightDashboard' >";
    echo "<strong class='dashboardHeading'>" . __('Life Time', 'wpsc') . "</strong><br />";
    echo "<p class='dashboardWidgetSpecial'>";
    echo nzshpcrt_currency_display(admin_display_total_price(), 1);
    echo "<span class='dashboardWidget'>" . __('Sales', 'wpsc') . "</span>";
    echo "</p>";
    echo "<p class='dashboardWidgetSpecial'>";
    echo "<span class='pricedisplay'>";
    echo $totalOrders;
    echo "</span>";
    echo "<span class='dashboardWidget'>" . __('Orders', 'wpsc') . "</span>";
    echo "</p>";
    echo "<p class='dashboardWidgetSpecial'>";
    //echo "<span class='pricedisplay'>";
    //calculates average sales amount per order for the month
    if (admin_display_total_price() > 0 && $totalOrders > 0) {
        $totalAverage = (int) admin_display_total_price() / (int) $totalOrders;
    } else {
        $totalAverage = 0;
    }
    echo nzshpcrt_currency_display($totalAverage, 1);
    //echo "</span>";
    echo "<span class='dashboardWidget'>" . __('Avg Orders', 'wpsc') . "</span>";
    echo "</p>";
    echo "</div>";
    echo "<div style='clear:both'></div>";
}
Exemplo n.º 26
0
/**
 * Purchase log ajax code starts here
*/
function wpsc_purchlog_resend_email()
{
    global $wpdb;
    $siteurl = get_option('siteurl');
    $log_id = $_GET['email_buyer_id'];
    if (is_numeric($log_id)) {
        $selectsql = "SELECT * FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE `id`= " . $log_id . " LIMIT 1";
        $purchase_log = $wpdb->get_row($selectsql, ARRAY_A);
        if ($purchase_log['gateway'] == "testmode" && $purchase_log['processed'] < 2) {
            $message = get_option("wpsc_email_receipt");
            $message_html = "<h2  style='font-size:16px;font-weight:bold;color:#000;border:0px;padding-top: 0px;' >" . TXT_WPSC_YOUR_ORDER . "</h2>";
        } else {
            $message = get_option("wpsc_email_receipt");
            $message_html = $message;
        }
        $order_url = $siteurl . "/wp-admin/admin.php?page=" . WPSC_DIR_NAME . "/display-log.php&amp;purchcaseid=" . $purchase_log['id'];
        $cartsql = "SELECT * FROM `" . WPSC_TABLE_CART_CONTENTS . "` WHERE `purchaseid`=" . $purchase_log['id'] . "";
        $cart = $wpdb->get_results($cartsql, ARRAY_A);
        if ($purchase_log['shipping_country'] != '') {
            $billing_country = $purchase_log['billing_country'];
            $shipping_country = $purchase_log['shipping_country'];
        } else {
            $country = $wpdb->get_results("SELECT * FROM `" . WPSC_TABLE_SUBMITED_FORM_DATA . "` WHERE `log_id`=" . $purchase_log['id'] . " AND `form_id` = '" . get_option('country_form_field') . "' LIMIT 1", ARRAY_A);
            $billing_country = $country[0]['value'];
            $shipping_country = $country[0]['value'];
        }
        $email_form_field = $wpdb->get_results("SELECT `id`,`type` FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` WHERE `type` IN ('email') AND `active` = '1' ORDER BY `order` ASC LIMIT 1", ARRAY_A);
        $email_address = $wpdb->get_results("SELECT * FROM `" . WPSC_TABLE_SUBMITED_FORM_DATA . "` WHERE `log_id`=" . $purchase_log['id'] . " AND `form_id` = '" . $email_form_field[0]['id'] . "' LIMIT 1", ARRAY_A);
        $email = $email_address[0]['value'];
        $previous_download_ids = array(0);
        if ($cart != null) {
            foreach ($cart as $row) {
                $link = "";
                $productsql = "SELECT * FROM `" . WPSC_TABLE_PRODUCT_LIST . "` WHERE `id`=" . $row['prodid'] . "";
                $product_data = $wpdb->get_results($productsql, ARRAY_A);
                if ($product_data[0]['file'] > 0) {
                    if ($purchase_log['email_sent'] != 1) {
                        $wpdb->query("UPDATE `" . WPSC_TABLE_DOWNLOAD_STATUS . "` SET `active`='1' WHERE `fileid`='" . $product_data[0]['file'] . "' AND `purchid` = '" . $purchase_log['id'] . "' LIMIT 1");
                    }
                    if ($purchase_log['processed'] >= 2) {
                        $download_data = $wpdb->get_row("SELECT * FROM `" . WPSC_TABLE_DOWNLOAD_STATUS . "` WHERE `fileid`='" . $product_data[0]['file'] . "' AND `purchid`='" . $purchase_log['id'] . "' AND (`cartid` = '" . $row['id'] . "' OR `cartid` IS NULL) AND `id` NOT IN (" . make_csv($previous_download_ids) . ") LIMIT 1", ARRAY_A);
                        if ($download_data != null) {
                            if ($download_data['uniqueid'] == null) {
                                // if the uniqueid is not equal to null, its "valid", regardless of what it is
                                $link = $siteurl . "?downloadid=" . $download_data['id'];
                            } else {
                                $link = $siteurl . "?downloadid=" . $download_data['uniqueid'];
                            }
                        }
                        $previous_download_ids[] = $download_data['id'];
                        $order_status = 4;
                    }
                }
                do_action('wpsc_confirm_checkout', $purchase_log['id']);
                $shipping = nzshpcrt_determine_item_shipping($row['prodid'], $row['quantity'], $shipping_country);
                if (isset($_SESSION['quote_shipping'])) {
                    $shipping = $_SESSION['quote_shipping'];
                }
                $total_shipping += $shipping;
                if ($product_data[0]['special'] == 1) {
                    $price_modifier = $product_data[0]['special_price'];
                } else {
                    $price_modifier = 0;
                }
                $total += $row['price'] * $row['quantity'];
                $message_price = nzshpcrt_currency_display($row['price'] * $row['quantity'], $product_data[0]['notax'], true);
                $shipping_price = nzshpcrt_currency_display($shipping, 1, true);
                $variation_sql = "SELECT * FROM `" . WPSC_TABLE_CART_ITEM_VARIATIONS . "` WHERE `cart_id`='" . $row['id'] . "'";
                $variation_data = $wpdb->get_results($variation_sql, ARRAY_A);
                $variation_count = count($variation_data);
                if ($variation_count > 1) {
                    $variation_list = " (";
                    if ($purchase['gateway'] != 'testmode') {
                        if ($gateway['internalname'] == $purch_data[0]['gateway']) {
                            $gateway_name = $gateway['name'];
                        }
                    } else {
                        $gateway_name = "Manual Payment";
                    }
                    $i = 0;
                    foreach ($variation_data as $variation) {
                        if ($i > 0) {
                            $variation_list .= ", ";
                        }
                        $value_id = $variation['value_id'];
                        $value_data = $wpdb->get_results("SELECT * FROM `" . WPSC_TABLE_VARIATION_VALUES . "` WHERE `id`='" . $value_id . "' LIMIT 1", ARRAY_A);
                        $variation_list .= $value_data[0]['name'];
                        $i++;
                    }
                    $variation_list .= ")";
                } else {
                    if ($variation_count == 1) {
                        $value_id = $variation_data[0]['value_id'];
                        $value_data = $wpdb->get_results("SELECT * FROM `" . WPSC_TABLE_VARIATION_VALUES . "` WHERE `id`='" . $value_id . "' LIMIT 1", ARRAY_A);
                        $variation_list = " (" . $value_data[0]['name'] . ")";
                    } else {
                        $variation_list = '';
                    }
                }
                if ($link != '') {
                    $product_list .= " - " . $product_data['name'] . stripslashes($variation_list) . "  " . $message_price . " " . TXT_WPSC_CLICKTODOWNLOAD . ":\n {$link}\n";
                    $product_list_html .= " - " . $product_data['name'] . stripslashes($variation_list) . "  " . $message_price . "&nbsp;&nbsp;<a href='{$link}'>" . TXT_WPSC_CLICKTODOWNLOAD . "</a>\n";
                } else {
                    $plural = '';
                    if ($row['quantity'] > 1) {
                        $plural = "s";
                    }
                    $product_list .= " - " . $row['quantity'] . " " . $product_data[0]['name'] . $variation_list . "  " . $message_price . "\n";
                    if ($shipping > 0) {
                        $product_list .= " - " . TXT_WPSC_SHIPPING . ":" . $shipping_price . "\n\r";
                    }
                    $product_list_html .= " - " . $row['quantity'] . " " . $product_data[0]['name'] . $variation_list . "  " . $message_price . "\n";
                    if ($shipping > 0) {
                        $product_list_html .= " - " . TXT_WPSC_SHIPPING . ":" . $shipping_price . "\n\r";
                    }
                }
                $report .= " - " . $product_data[0]['name'] . $variation_list . "  " . $message_price . "\n";
            }
            if ($purchase_log['discount_data'] != '') {
                $coupon_data = $wpdb->get_row("SELECT * FROM `" . WPSC_TABLE_COUPON_CODES . "` WHERE coupon_code='" . $wpdb->escape($purchase_log['discount_data']) . "' LIMIT 1", ARRAY_A);
                if ($coupon_data['use-once'] == 1) {
                    $wpdb->query("UPDATE `" . WPSC_TABLE_COUPON_CODES . "` SET `active`='0', `is-used`='1' WHERE `id`='" . $coupon_data['id'] . "' LIMIT 1");
                }
            }
            //$wpdb->query("UPDATE `".WPSC_TABLE_DOWNLOAD_STATUS."` SET `active`='1' WHERE `fileid`='".$product_data[0]['file']."' AND `purchid` = '".$purchase_log['id']."' LIMIT 1");
            $total_shipping += $purchase_log['base_shipping'];
            $total = $total + $total_shipping - $purchase_log['discount_value'];
            // $message.= "\n\r";
            $product_list .= "Your Purchase No.: " . $purchase_log['id'] . "\n\r";
            if ($purchase_log['discount_value'] > 0) {
                $discount_email .= TXT_WPSC_DISCOUNT . ": " . nzshpcrt_currency_display($purchase_log['discount_value'], 1, true) . "\n\r";
            }
            $total_shipping_email .= TXT_WPSC_TOTALSHIPPING . ": " . nzshpcrt_currency_display($total_shipping, 1, true) . "\n\r";
            $total_price_email .= TXT_WPSC_TOTAL . ": " . nzshpcrt_currency_display($total, 1, true) . "\n\r";
            $product_list_html .= "Your Purchase No.: " . $purchase_log['id'] . "\n\n\r";
            if ($purchase_log['discount_value'] > 0) {
                $discount_html .= TXT_WPSC_DISCOUNT . ": " . nzshpcrt_currency_display($purchase_log['discount_value'], 1, true) . "\n\r";
            }
            $total_shipping_html .= TXT_WPSC_TOTALSHIPPING . ": " . nzshpcrt_currency_display($total_shipping, 1, true) . "\n\r";
            $total_price_html .= TXT_WPSC_TOTAL . ": " . nzshpcrt_currency_display($total, 1, true) . "\n\r";
            if (isset($_GET['ti'])) {
                $message .= "\n\r" . TXT_WPSC_YOURTRANSACTIONID . ": " . $_GET['ti'];
                $message_html .= "\n\r" . TXT_WPSC_YOURTRANSACTIONID . ": " . $_GET['ti'];
                $report .= "\n\r" . TXT_WPSC_TRANSACTIONID . ": " . $_GET['ti'];
            } else {
                $report_id = "Purchase No.: " . $purchase_log['id'] . "\n\r";
            }
            $message = str_replace('%product_list%', $product_list, $message);
            $message = str_replace('%total_shipping%', $total_shipping_email, $message);
            $message = str_replace('%total_price%', $total_price_email, $message);
            //$message = str_replace('%order_status%',get_option('blogname'),$message);
            $message = str_replace('%shop_name%', get_option('blogname'), $message);
            $report = str_replace('%product_list%', $report_product_list, $report);
            $report = str_replace('%total_shipping%', $total_shipping_email, $report);
            $report = str_replace('%total_price%', $total_price_email, $report);
            $report = str_replace('%shop_name%', get_option('blogname'), $report);
            $message_html = str_replace('%product_list%', $product_list_html, $message_html);
            $message_html = str_replace('%total_shipping%', $total_shipping_html, $message_html);
            $message_html = str_replace('%total_price%', $total_price_email, $message_html);
            $message_html = str_replace('%shop_name%', get_option('blogname'), $message_html);
            //	exit($message_html);
            if ($email != '') {
                add_filter('wp_mail_from', 'wpsc_replace_reply_address', 0);
                add_filter('wp_mail_from_name', 'wpsc_replace_reply_name', 0);
                if ($purchase_log['processed'] < 2) {
                    $payment_instructions = strip_tags(get_option('payment_instructions'));
                    $message = TXT_WPSC_ORDER_PENDING . "\n\r" . $payment_instructions . "\n\r" . $message;
                    $resent = (bool) wp_mail($email, TXT_WPSC_ORDER_PENDING_PAYMENT_REQUIRED, $message);
                    $sent = 1;
                } else {
                    $resent = (bool) wp_mail($email, TXT_WPSC_PURCHASERECEIPT, $message);
                    $sent = 1;
                }
                //echo "$message<br />";
                //exit($email);
                remove_filter('wp_mail_from_name', 'wpsc_replace_reply_name');
                remove_filter('wp_mail_from', 'wpsc_replace_reply_address');
            }
        }
    }
    $sendback = wp_get_referer();
    if (isset($sent)) {
        $sendback = add_query_arg('sent', $sent, $sendback);
    }
    wp_redirect($sendback);
    exit;
}
Exemplo n.º 27
0
/**
	* update_product_page_price function, used through ajax with variations
	* No parameters, returns nothing
*/
function wpsc_update_product_price()
{
    global $wpdb, $wpsc_cart;
    foreach ((array) $_POST['variation'] as $variation) {
        if (is_numeric($variation)) {
            $variations[] = (int) $variation;
        }
    }
    $pm = $_POST['pm'];
    echo "product_id=" . (int) $_POST['product_id'] . ";\n";
    echo "price=\"" . nzshpcrt_currency_display(calculate_product_price((int) $_POST['product_id'], $variations, 'stay', $extras), $notax, true) . "\";\n";
    echo "numeric_price=\"" . number_format(calculate_product_price((int) $_POST['product_id'], $variations, 'stay', $extras), 2) . "\";\n";
    exit;
}
Exemplo n.º 28
0
/**
 * WPCandy Display Purchase Log
 * Modified from http://wordpress.org/extend/plugins/wp-e-commerce-user-roles-and-purchase-history/
 */
function wpcandy_show_purchase_history()
{
    global $current_user, $wpdb, $table_prefix;
    get_currentuserinfo();
    $grand_total = 0;
    // Make sure the user is logged in and valid.
    if (is_numeric($current_user->ID) && $current_user->ID > 0) {
        $sql = "SELECT p.`id`, c.`name`, p.`date`, p.`totalprice`, p.`processed`, p.`sessionid` FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` AS p, `" . WPSC_TABLE_CART_CONTENTS . "` AS c WHERE p.`id`=c.`purchaseid` AND `user_ID` IN ('" . $current_user->ID . "') ORDER BY `date` DESC";
        // Get purchases
        $purchase_log = $wpdb->get_results($sql, ARRAY_A);
        if ($purchase_log != null) {
            // this user has made some purchase
            echo "<table>";
            foreach ((array) $purchase_log as $purchase) {
                $sql = "SELECT * FROM `" . WPSC_TABLE_DOWNLOAD_STATUS . "` WHERE `purchid`=" . $purchase['id'] . " AND `active` IN ('1') ORDER BY `datetime` DESC";
                // Get the products purchased
                $products = $wpdb->get_results($sql, ARRAY_A);
                $isOrderAccepted = $purchase['processed'];
                foreach ((array) $products as $product) {
                    if ($isOrderAccepted > 1) {
                        if ($product['uniqueid'] == null) {
                            $links = get_option('siteurl') . "?downloadid=" . $product['id'];
                        } else {
                            $links = get_option('siteurl') . "?downloadid=" . $product['uniqueid'];
                        }
                        $download_count = $product['downloads'];
                    }
                }
                echo '<tr>';
                echo '<th>Item</th>';
                echo '<th>Date</th>';
                echo '<th>Price</th>';
                echo '</tr>';
                echo '<tr>';
                echo '<td>' . $purchase['name'] . '</td>';
                echo '<td>' . date("d/m/Y", $purchase['date']) . '</td>';
                echo '<td>' . nzshpcrt_currency_display($purchase['totalprice'], 1, false, false, false) . '</td>';
                $grand_total += $purchase['totalprice'];
                echo '</tr>';
            }
            echo '<tr>';
            echo "<td colspan='2'><strong>Total Spent</strong></td>";
            echo '<td><strong>' . nzshpcrt_currency_display($grand_total, 1, false, false, false) . '</strong></td>';
            echo '</tr>';
            echo '</table>';
        } else {
            echo 'No transactions found.';
        }
    } else {
        echo 'You must be logged in to use this page.';
    }
}
Exemplo n.º 29
0
function wpsc_also_bought($product_id)
{
    /*
     * Displays products that were bought aling with the product defined by $product_id
     * most of it scarcely needs describing
     */
    global $wpdb;
    $siteurl = get_option('siteurl');
    if (get_option('wpsc_also_bought') == 0) {
        //returns nothing if this is off
        return '';
    }
    // to be made customiseable in a future release
    $also_bought_limit = 3;
    $element_widths = 96;
    $image_display_height = 96;
    $image_display_width = 96;
    $also_bought = $wpdb->get_results("SELECT `" . WPSC_TABLE_PRODUCT_LIST . "`.* FROM `" . WPSC_TABLE_ALSO_BOUGHT . "`, `" . WPSC_TABLE_PRODUCT_LIST . "` WHERE `selected_product`='" . $product_id . "' AND `" . WPSC_TABLE_ALSO_BOUGHT . "`.`associated_product` = `" . WPSC_TABLE_PRODUCT_LIST . "`.`id` AND `" . WPSC_TABLE_PRODUCT_LIST . "`.`active` IN('1') AND `" . WPSC_TABLE_PRODUCT_LIST . "`.`publish` IN ('1')ORDER BY `" . WPSC_TABLE_ALSO_BOUGHT . "`.`quantity` DESC LIMIT {$also_bought_limit}", ARRAY_A);
    if (count($also_bought) > 0) {
        $output = "<h2 class='prodtitles wpsc_also_bought' >" . TXT_WPSC_ALSO_BOUGHT . "</h2>";
        $output .= "<div class='wpsc_also_bought'>";
        foreach ((array) $also_bought as $also_bought_data) {
            $output .= "<div class='wpsc_also_bought_item' style='width: " . $element_widths . "px;'>";
            if (get_option('show_thumbnails') == 1) {
                if ($also_bought_data['image'] != null) {
                    $output .= "<a href='" . wpsc_product_url($also_bought_data['id']) . "' class='preview_link'  rel='" . str_replace(" ", "_", $also_bought_data['name']) . "'>";
                    $image_path = "index.php?productid=" . $also_bought_data['id'] . "&amp;width=" . $image_display_width . "&amp;height=" . $image_display_height . "";
                    $output .= "<img src='{$image_path}' id='product_image_" . $also_bought_data['id'] . "' class='product_image' style='margin-top: " . $margin_top . "px'/>";
                    $output .= "</a>";
                } else {
                    if (get_option('product_image_width') != '') {
                        $output .= "<img src='" . WPSC_URL . "/images/no-image-uploaded.gif' title='" . $also_bought_data['name'] . "' alt='" . $also_bought_data['name'] . "' width='{$image_display_height}' height='{$image_display_height}' id='product_image_" . $also_bought_data['id'] . "' class='product_image' />";
                    } else {
                        $output .= "<img src='" . WPSC_URL . "/images/no-image-uploaded.gif' title='" . $also_bought_data['name'] . "' alt='" . htmlentities(stripslashes($product['name']), ENT_QUOTES, 'UTF-8') . "' id='product_image_" . $also_bought_data['id'] . "' class='product_image' />";
                    }
                }
            }
            $variations_processor = new nzshpcrt_variations();
            $variations_output = $variations_processor->display_product_variations($also_bought_data['id'], true, false, true);
            //$output .= $variations_output[0];
            if ($variations_output[1] !== null) {
                $also_bought_data['price'] = $variations_output[1];
                $also_bought_data['special_price'] = 0;
            }
            $output .= "<a class='wpsc_product_name' href='" . wpsc_product_url($also_bought_data['id']) . "'>" . $also_bought_data['name'] . "</a>";
            $output .= nzshpcrt_currency_display($also_bought_data['price'] - $also_bought_data['special_price'], $also_bought_data['notax'], false, $also_bought_data['id']);
            //$output .= "<a href='".wpsc_product_url($also_bought_data['id'])."'>".$also_bought_data['name']."</a>";
            $output .= "</div>";
        }
        $output .= "</div>";
        $output .= "<br clear='all' />";
    }
    return $output;
}
Exemplo n.º 30
0
 echo "<a href='#' onclick='filleditform(" . $product['id'] . ");return false;'>";
 if ($product['name'] == '') {
     echo "(" . TXT_WPSC_NONAME . ")";
 } else {
     echo htmlentities(stripslashes($product['name']), ENT_QUOTES, 'UTF-8');
 }
 echo "</a>";
 if (is_numeric($_GET['catid'])) {
     echo "            </div>\n\r";
 } else {
     echo "</td><td>";
 }
 if (is_numeric($_GET['catid'])) {
     echo "            <div class='pli_price'>\n\r";
 }
 echo nzshpcrt_currency_display($product['price'], 1);
 if (is_numeric($_GET['catid'])) {
     echo "            </div>\n\r";
 }
 if (!is_numeric($_GET['catid'])) {
     echo "            <td>\n\r";
     $category_list = $wpdb->get_results("SELECT `" . $wpdb->prefix . "product_categories`.`id`,`" . $wpdb->prefix . "product_categories`.`name` FROM `" . $wpdb->prefix . "item_category_associations` , `" . $wpdb->prefix . "product_categories` WHERE `" . $wpdb->prefix . "item_category_associations`.`product_id` IN ('" . $product['id'] . "') AND `" . $wpdb->prefix . "item_category_associations`.`category_id` = `" . $wpdb->prefix . "product_categories`.`id` AND `" . $wpdb->prefix . "product_categories`.`active` IN('1')", ARRAY_A);
     $i = 0;
     foreach ((array) $category_list as $category_row) {
         if ($i > 0) {
             echo "<br />";
         }
         echo "<a href='?page=" . $_GET['page'] . "&amp;catid=" . $category_row['id'] . "'>" . stripslashes($category_row['name']) . "</a>";
         $i++;
     }
 }