Example #1
0
function wpsc_packing_slip($purchase_id)
{
    echo "<!DOCTYPE html><html><head><title>" . __('Packing Slip', 'wpsc') . "</title></head><body id='wpsc-packing-slip'>";
    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>".__('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\t`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['billing_region']) && $delivery_region_count > 0) {
                            echo "\t<tr><td>" . __('State', 'wpsc') . ":</td><td>" . wpsc_get_region($purch_data['billing_region']) . "</td></tr>\n\r";
                        }
                        echo "\t<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;
                    case 'delivery_country':
                        if (is_numeric($purch_data['shipping_region']) && $delivery_region_count > 0) {
                            echo "\t<tr><td>" . __('State', 'wpsc') . ":</td><td>" . wpsc_get_region($purch_data['shipping_region']) . "</td></tr>\n\r";
                        }
                        echo "\t<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;
                    case 'heading':
                        if ($form_field['name'] == "Hidden Fields") {
                            continue;
                        } else {
                            echo "\t<tr class='heading'><td colspan='2'><strong>" . wp_kses($form_field['name'], array()) . ":</strong></td></tr>\n\r";
                        }
                        break;
                    default:
                        if ($form_field['name'] == "Cupcakes") {
                            parse_str($rekeyed_input[$form_field['id']]['value'], $cupcakes);
                            foreach ($cupcakes as $product_id => $quantity) {
                                $product = get_post($product_id);
                                $string .= "(" . $quantity . ") " . $product->post_title . ", ";
                            }
                            $string = rtrim($string, ", ");
                            echo "\t<tr><td>" . wp_kses($form_field['name'], array()) . ":</td><td>" . htmlentities(stripslashes($string), ENT_QUOTES, 'UTF-8') . "</td></tr>\n\r";
                        } else {
                            if ($form_field['name'] == "State" && !empty($purch_data['billing_region']) || $form_field['name'] == "State" && !empty($purch_data['billing_region'])) {
                                echo "";
                            } else {
                                echo "\t<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 "\t<tr><td>" . __('Name', 'wpsc') . ":</td><td>" . $purch_data['firstname'] . " " . $purch_data['lastname'] . "</td></tr>\n\r";
            echo "\t<tr><td>" . __('Address', 'wpsc') . ":</td><td>" . $purch_data['address'] . "</td></tr>\n\r";
            echo "\t<tr><td>" . __('Phone', 'wpsc') . ":</td><td>" . $purch_data['phone'] . "</td></tr>\n\r";
            echo "\t<tr><td>" . __('Email', 'wpsc') . ":</td><td>" . $purch_data['email'] . "</td></tr>\n\r";
        }
        if (2 == get_option('payment_method')) {
            $gateway_name = '';
            $nzshpcrt_gateways = nzshpcrt_get_gateways();
            foreach ($nzshpcrt_gateways as $gateway) {
                if ($purch_data['gateway'] != 'testmode') {
                    if ($gateway['internalname'] == $purch_data['gateway']) {
                        $gateway_name = $gateway['name'];
                    }
                } else {
                    $gateway_name = __('Manual Payment', 'wpsc');
                }
            }
        }
        echo "</table>\n\r";
        do_action('wpsc_packing_slip_extra_info', $purchase_id);
        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>' . __('Tax', 'wpsc') . '</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'";
            }
            // product ID will be $cart_row['prodid']. need to fetch name and stuff
            $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 $cart_row['name'];
            echo stripslashes($variation_list);
            echo " </td>";
            echo " <td>";
            echo wpsc_currency_display($price);
            echo " </td>";
            echo " <td>";
            echo wpsc_currency_display($shipping);
            echo " </td>";
            echo '<td>';
            echo wpsc_currency_display($cart_row['tax_charged']);
            echo '</td>';
            echo '</tr>';
        }
        echo "</table>";
        echo '<table class="packing-slip-totals">';
        echo '<tr><th>Base Shipping</th><td>' . wpsc_currency_display($purch_data['base_shipping']) . '</td></tr>';
        echo '<tr><th>Total Shipping</th><td>' . wpsc_currency_display($purch_data['base_shipping'] + $total_shipping) . '</td></tr>';
        //wpec_taxes
        if ($purch_data['wpec_taxes_total'] != 0.0) {
            echo '<tr><th>Taxes</th><td>' . wpsc_currency_display($purch_data['wpec_taxes_total']) . '</td></tr>';
        }
        echo '<tr><th>Total Price</th><td>' . wpsc_currency_display($purch_data['totalprice']) . '</td></tr>';
        echo '</table>';
        echo "</div>\n\r";
    } else {
        echo "<br />" . __('This users cart was empty', 'wpsc');
    }
}
 function shippingstate($id)
 {
     global $wpdb;
     if (is_numeric($id)) {
         $name = wpsc_get_region($id);
         return $name;
     } else {
         return $id;
     }
 }
Example #3
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;
    }
}
    public function filter_confirm_transaction_page()
    {
        ob_start();
        ?>
		<table width='400' class='paypal_express_form'>
	        <tr>
	            <td align='left' class='firstcol'><strong><?php 
        _e('Order Total:', 'wpsc');
        ?>
</strong></td>
	            <td align='left'><?php 
        echo wpsc_currency_display($this->purchase_log->get('totalprice'));
        ?>
</td>
	        </tr>
			<tr>
			    <td align='left' colspan='2'><strong><?php 
        _e('Shipping Details:', 'wpsc');
        ?>
</strong></td>
			</tr>
	        <tr>
	            <td align='left' class='firstcol'>
	                <?php 
        echo __('Address:', 'wpsc');
        ?>
				</td>
	            <td align='left'>
					<?php 
        echo esc_html($this->checkout_data->get('shippingaddress'));
        ?>
	            </td>
	        </tr>
	        <tr>
	            <td align='left' class='firstcol'>
	                <?php 
        echo __('City:', 'wpsc');
        ?>
				</td>
	            <td align='left'><?php 
        echo esc_html($this->checkout_data->get('shippingcity'));
        ?>
</td>
	        </tr>
	        <tr>
	            <td align='left' class='firstcol'>
	                <?php 
        echo __('State:', 'wpsc');
        ?>
				</td>
	            <td align='left'>
					<?php 
        echo esc_html(wpsc_get_region($this->checkout_data->get('shippingstate')));
        ?>
				</td>
	        </tr>
	        <tr>
	            <td align='left' class='firstcol'>
	                <?php 
        echo __('Postal code:', 'wpsc');
        ?>
				</td>
	            <td align='left'><?php 
        echo esc_html($this->checkout_data->get('shippingpostcode'));
        ?>
</td>
	        </tr>
	        <tr>
	            <td align='left' class='firstcol'>
	                <?php 
        echo __('Country:', 'wpsc');
        ?>
</td>
	            <td align='left'><?php 
        echo esc_html(wpsc_get_country($this->checkout_data->get('shippingcountry')));
        ?>
</td>
	        </tr>
	        <tr>
	            <td colspan='2'>
					<form action="<?php 
        echo remove_query_arg(array('payment_gateway', 'payment_gateway_callback'));
        ?>
" method='post'>
						<input type='hidden' name='payment_gateway' value='paypal-express-checkout' />
						<input type='hidden' name='payment_gateway_callback' value='process_confirmed_payment' />
						<p><input name='action' type='submit' value='<?php 
        _e('Confirm Payment', 'wpsc');
        ?>
' /></p>
					</form>
				</td>
	        </tr>
	    </table>
		<?php 
        $output = apply_filters('wpsc_confirm_payment_message', ob_get_clean(), $this->purchase_log);
        return $output;
    }
Example #5
0
    /**
     * General entry point for WPEC external shipping calculator
     * This function expects no arguments but requires POST data
     * and configuration from the plugin settings
     * @return array $rate_table List of rates in "Service"=>"Rate" format
     */
    function getQuote()
    {
        global $wpdb, $wpec_ash, $wpec_ash_tools, $wpsc_cart;
        $data = array();
        //************** These values are common to all entry points **************
        //*** User/Customer Entered Values ***\\
        //*** Set up the destination country ***\
        $data["dest_country"] = wpsc_get_customer_meta('shipping_country');
        $settings = get_option('wpec_usps');
        //Disable International Shipping. Default: Enabled as it currently is.
        $data['intl_rate'] = isset($settings['intl_rate']) && !empty($settings['intl_rate']) ? FALSE : TRUE;
        if (!$data['intl_rate'] && $data['dest_country'] != get_option('base_country')) {
            return array();
        }
        // If ths zip code is provided via a form post use it!
        $data["dest_zipcode"] = (string) wpsc_get_customer_meta('shippingpostcode');
        if (!is_object($wpec_ash_tools)) {
            $wpec_ash_tools = new ASHTools();
        }
        if (empty($data["dest_zipcode"]) && $wpec_ash_tools->needs_post_code($data["dest_country"])) {
            // We cannot get a quote without a zip code so might as well return!
            return array();
        }
        //*** Grab Total Weight from the shipment object for simple shipping
        $data["weight"] = wpsc_cart_weight_total();
        if (empty($data["weight"])) {
            return array();
        }
        // If the region code is provided via a form post use it!
        if (isset($_POST['region']) && !empty($_POST['region'])) {
            $data['dest_state'] = wpsc_get_region(sanitize_text_field($_POST['region']));
        } else {
            if ($dest_state = wpsc_get_customer_meta('shipping_state')) {
                // Well, we have a zip code in the session and no new one provided
                $data['dest_state'] = $dest_state;
            } else {
                $data['dest_state'] = "";
            }
        }
        $data["dest_country"] = $wpec_ash_tools->get_full_country($data["dest_country"]);
        $data["dest_country"] = $this->_update_country($data["dest_country"]);
        if (!is_object($wpec_ash)) {
            $wpec_ash = new ASH();
        }
        $shipping_cache_check['state'] = $data['dest_state'];
        $shipping_cache_check['country'] = $data['dest_country'];
        $shipping_cache_check['zipcode'] = $data["dest_zipcode"];
        $this->shipment = $wpec_ash->get_shipment();
        $this->shipment->set_destination($this->internal_name, $shipping_cache_check);
        $this->shipment->rates_expire = date('Y-m-d');
        //Date will be checked against the cached date.
        $data['shipper'] = $this->internal_name;
        $data["adv_rate"] = !empty($settings["adv_rate"]) ? $settings["adv_rate"] : FALSE;
        // Use advanced shipping for Domestic Rates ? Not available
        if ($data["weight"] > 70 && !(bool) $data["adv_rate"]) {
            //USPS has a weight limit: https://www.usps.com/send/can-you-mail-it.htm?#3.
            $over_weight_txt = apply_filters('wpsc_shipment_over_weight', __('Your order exceeds the standard shipping weight limit.
													Please contact us to quote other shipping alternatives.', 'wp-e-commerce'), $data);
            $shipping_quotes[$over_weight_txt] = 0;
            // yes, a constant.
            $wpec_ash->cache_results($this->internal_name, array($shipping_quotes), $this->shipment);
            return array($shipping_quotes);
        }
        // Check to see if the cached shipment is still accurate, if not we need new rate
        $cache = $wpec_ash->check_cache($this->internal_name, $this->shipment);
        // We do not want to spam USPS (and slow down our process) if we already
        // have a shipping quote!
        if (count($cache["rate_table"]) >= 1) {
            //$cache['rate_table'] could be array(0).
            return $cache["rate_table"];
        }
        //*** WPEC Configuration values ***\\
        $this->use_test_env = !isset($settings["test_server"]) ? false : (bool) $settings['test_server'];
        $data["fcl_type"] = !empty($settings["fcl_type"]) ? $settings["fcl_type"] : "PARCEL";
        $data["mail_type"] = !empty($settings["intl_pkg"]) ? $settings["intl_pkg"] : "Package";
        $data["base_zipcode"] = get_option("base_zipcode");
        $data["services"] = !empty($settings["services"]) ? $settings["services"] : array("STANDARD POST", "PRIORITY", "PRIORITY EXPRESS", "FIRST CLASS");
        foreach ($data["services"] as $id => $service) {
            if ($service == 'PARCEL') {
                $data["services"][$id] = 'STANDARD POST';
            }
            if ($service == 'EXPRESS') {
                $data["services"][$id] = 'PRIORITY EXPRESS';
            }
        }
        $data["user_id"] = $settings["id"];
        $data["value"] = $wpsc_cart->calculate_subtotal(true);
        //Required by $this->_build_intl_shipment.
        $data = apply_filters('wpsc_shipment_data', $data, $this->shipment);
        if (isset($data['stop'])) {
            //Do not get rates.
            return array();
        }
        //************ GET THE RATE ************\\
        $rate_table = apply_filters('wpsc_rates_table', $this->_run_quote($data), $data, $this->shipment);
        //Avoid trying getting rates again and again when the stored zip code is incorrect.
        //************ CACHE the Results ************\\
        $wpec_ash->cache_results($this->internal_name, $rate_table, $this->shipment);
        return $rate_table;
    }
function wpsc_packing_slip($purchase_id)
{
    _wpsc_deprecated_function(__FUNCTION__, '3.8.13');
    echo "<!DOCTYPE html><html><meta http-equiv=\"content-type\" content=\"text-html; charset=utf-8\"><head><title>" . __('Packing Slip', 'wp-e-commerce') . "</title></head><body id='wpsc-packing-slip'>";
    global $wpdb;
    $purch_sql = $wpdb->prepare("SELECT * FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE `id`=%d", $purchase_id);
    $purch_data = $wpdb->get_row($purch_sql, ARRAY_A);
    $cartsql = $wpdb->prepare("SELECT * FROM `" . WPSC_TABLE_CART_CONTENTS . "` WHERE `purchaseid`=%d", $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>' . esc_html__('Packing Slip', 'wp-e-commerce') . "</h2>\n\r");
        echo "<strong>" . esc_html__('Order', 'wp-e-commerce') . " #</strong> " . $purchase_id . "<br /><br />\n\r";
        echo "<table>\n\r";
        $form_sql = $wpdb->prepare("SELECT * FROM `" . WPSC_TABLE_SUBMITTED_FORM_DATA . "` WHERE `log_id` = %d", $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' ORDER BY `checkout_order`", ARRAY_A);
            foreach ($form_data as $form_field) {
                switch ($form_field['type']) {
                    case 'country':
                        $region_count_sql = $wpdb->prepare("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('%s')", $purch_data['billing_country']);
                        $delivery_region_count = $wpdb->get_var($region_count_sql);
                        if (is_numeric($purch_data['billing_region']) && $delivery_region_count > 0) {
                            echo "\t<tr><td>" . esc_html__('State', 'wp-e-commerce') . ":</td><td>" . wpsc_get_region($purch_data['billing_region']) . "</td></tr>\n\r";
                        }
                        echo "\t<tr><td>" . esc_html($form_field['name']) . ":</td><td>" . esc_html($rekeyed_input[$form_field['id']]['value']) . "</td></tr>\n\r";
                        break;
                    case 'delivery_country':
                        if (is_numeric($purch_data['shipping_region']) && $delivery_region_count > 0) {
                            echo "\t<tr><td>" . esc_html__('State', 'wp-e-commerce') . ":</td><td>" . wpsc_get_region($purch_data['shipping_region']) . "</td></tr>\n\r";
                        }
                        echo "\t<tr><td>" . esc_html($form_field['name']) . ":</td><td>" . esc_html($rekeyed_input[$form_field['id']]['value']) . "</td></tr>\n\r";
                        break;
                    case 'heading':
                        if ($form_field['name'] == "Hidden Fields") {
                            continue;
                        } else {
                            echo "\t<tr class='heading'><td colspan='2'><strong>" . esc_html($form_field['name']) . ":</strong></td></tr>\n\r";
                        }
                        break;
                    default:
                        if ($form_field['name'] == "State" && !empty($purch_data['billing_region']) || $form_field['name'] == "State" && !empty($purch_data['billing_region'])) {
                            echo "";
                        } else {
                            echo "\t<tr><td>" . esc_html($form_field['name']) . ":</td><td>" . (isset($rekeyed_input[$form_field['id']]) ? esc_html($rekeyed_input[$form_field['id']]['value']) : '') . "</td></tr>\n\r";
                        }
                        break;
                }
            }
        } else {
            echo "\t<tr><td>" . esc_html__('Name', 'wp-e-commerce') . ":</td><td>" . $purch_data['firstname'] . " " . $purch_data['lastname'] . "</td></tr>\n\r";
            echo "\t<tr><td>" . esc_html__('Address', 'wp-e-commerce') . ":</td><td>" . $purch_data['address'] . "</td></tr>\n\r";
            echo "\t<tr><td>" . esc_html__('Phone', 'wp-e-commerce') . ":</td><td>" . $purch_data['phone'] . "</td></tr>\n\r";
            echo "\t<tr><td>" . esc_html__('Email', 'wp-e-commerce') . ":</td><td>" . $purch_data['email'] . "</td></tr>\n\r";
        }
        if (2 == get_option('payment_method')) {
            $gateway_name = '';
            global $nzshpcrt_gateways;
            foreach ($nzshpcrt_gateways as $gateway) {
                if ($purch_data['gateway'] != 'testmode') {
                    if ($gateway['internalname'] == $purch_data['gateway']) {
                        $gateway_name = $gateway['name'];
                    }
                } else {
                    $gateway_name = esc_html__('Manual Payment', 'wp-e-commerce');
                }
            }
        }
        echo "</table>\n\r";
        do_action('wpsc_packing_slip_extra_info', $purchase_id);
        echo "<table class='packing_slip'>";
        echo "<tr>";
        echo " <th>" . esc_html__('Quantity', 'wp-e-commerce') . " </th>";
        echo " <th>" . esc_html__('Name', 'wp-e-commerce') . "</th>";
        echo " <th>" . esc_html__('Price', 'wp-e-commerce') . " </th>";
        echo " <th>" . esc_html__('Shipping', 'wp-e-commerce') . " </th>";
        echo '<th>' . esc_html__('Tax', 'wp-e-commerce') . '</th>';
        echo '</tr>';
        $endtotal = 0;
        $all_donations = true;
        $all_no_shipping = true;
        $file_link_list = array();
        $total_shipping = 0;
        foreach ($cart_log as $cart_row) {
            $alternate = "";
            $j++;
            if ($j % 2 != 0) {
                $alternate = "class='alt'";
            }
            // product ID will be $cart_row['prodid']. need to fetch name and stuff
            $variation_list = '';
            if ($cart_row['donation'] != 1) {
                $all_donations = false;
            }
            if ($cart_row['no_shipping'] != 1) {
                $shipping = $cart_row['pnp'];
                $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 apply_filters('the_title', $cart_row['name']);
            echo $variation_list;
            echo " </td>";
            echo " <td>";
            echo wpsc_currency_display($price);
            echo " </td>";
            echo " <td>";
            echo wpsc_currency_display($shipping);
            echo " </td>";
            echo '<td>';
            echo wpsc_currency_display($cart_row['tax_charged']);
            echo '</td>';
            echo '</tr>';
        }
        echo "</table>";
        echo '<table class="packing-slip-totals">';
        if (floatval($purch_data['discount_value'])) {
            echo '<tr><th>' . esc_html__('Discount', 'wp-e-commerce') . '</th><td>(' . wpsc_currency_display($purch_data['discount_value']) . ')</td></tr>';
        }
        echo '<tr><th>' . esc_html__('Base Shipping', 'wp-e-commerce') . '</th><td>' . wpsc_currency_display($purch_data['base_shipping']) . '</td></tr>';
        echo '<tr><th>' . esc_html__('Total Shipping', 'wp-e-commerce') . '</th><td>' . wpsc_currency_display($purch_data['base_shipping'] + $total_shipping) . '</td></tr>';
        //wpec_taxes
        if ($purch_data['wpec_taxes_total'] != 0.0) {
            echo '<tr><th>' . esc_html__('Taxes', 'wp-e-commerce') . '</th><td>' . wpsc_currency_display($purch_data['wpec_taxes_total']) . '</td></tr>';
        }
        echo '<tr><th>' . esc_html__('Total Price', 'wp-e-commerce') . '</th><td>' . wpsc_currency_display($purch_data['totalprice']) . '</td></tr>';
        echo '</table>';
        echo "</div>\n\r";
    } else {
        echo "<br />" . esc_html__('This users cart was empty', 'wp-e-commerce');
    }
}
function wpsc_display_purchlog_shipping_state_and_postcode()
{
    global $purchlogitem;
    $state = '';
    if (is_numeric($purchlogitem->extrainfo->shipping_region)) {
        $state = esc_html(wpsc_get_region($purchlogitem->extrainfo->shipping_region));
    } else {
        $state = esc_html($purchlogitem->shippinginfo['shippingstate']['value']);
    }
    if (!empty($purchlogitem->shippinginfo['shippingpostcode']['value'])) {
        if (empty($state)) {
            $state = esc_html($purchlogitem->shippinginfo['shippingpostcode']['value']);
        } else {
            $state .= ', ' . esc_html($purchlogitem->shippinginfo['shippingpostcode']['value']);
        }
    }
    return $state;
}
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);
        }
    }
}
 public function get_raw_message()
 {
     global $wpdb;
     $form_data = new WPSC_Checkout_Form_Data($this->purchase_log->get('id'));
     $raw_data = $form_data->get_raw_data();
     $args = $this->get_common_args();
     $data = array('billing' => array('title' => __('Billing Details', 'wp-e-commerce'), 'fields' => array()), 'shipping' => array('title' => __('Shipping Details', 'wp-e-commerce'), 'fields' => array()), 'misc' => array('title' => __('Other Details', 'wp-e-commerce'), 'fields' => array()));
     foreach ($raw_data as $field) {
         if (strpos($field->unique_name, 'billing') !== false) {
             $type = 'billing';
         } elseif (strpos($field->unique_name, 'shipping') !== false) {
             $type = 'shipping';
         } else {
             $type = 'misc';
         }
         $data[$type]['fields'][] = $field;
     }
     // Transaction details
     $message = '<strong>' . __('Transaction Details', 'wp-e-commerce') . "</strong>\r\n";
     $message .= __('Sale Log ID', 'wp-e-commerce') . ': %purchase_id%' . "\r\n";
     if (!empty($args['transaction_id'])) {
         $message .= __('Transaction ID', 'wp-e-commerce') . ': %transaction_id%' . "\r\n";
     }
     // Discount
     if (!empty($args['coupon_code'])) {
         $message .= __('Coupon Code', 'wp-e-commerce') . ': %coupon_code%' . "\r\n";
         $message .= __('Discount Value', 'wp-e-commerce') . ': %discount%' . "\r\n";
     }
     // Subtotal, tax, shipping, total
     $message .= __('Subtotal', 'wp-e-commerce') . ': %subtotal%' . "\r\n";
     $message .= __('Tax', 'wp-e-commerce') . ': %tax%' . "\r\n";
     $message .= __('Shipping', 'wp-e-commerce') . ': %shipping%' . "\r\n";
     $message .= __('Total', 'wp-e-commerce') . ': %total%' . "\r\n";
     $message .= __('Payment Method', 'wp-e-commerce') . ': %payment_method%' . "\r\n";
     if (!get_option('do_not_use_shipping')) {
         $message .= __('Shipping Method', 'wp-e-commerce') . ': %shipping_method%' . "\r\n";
         $message .= __('Shipping Option', 'wp-e-commerce') . ': %shipping_option%' . "\r\n";
     }
     $message .= "\r\n";
     // Items
     $message .= '<strong>' . __('Items', 'wp-e-commerce') . "</strong>\r\n";
     $message .= "%product_list%\r\n";
     // Checkout fields
     $message .= "\r\n";
     foreach ($data as $section) {
         if (empty($section['fields'])) {
             continue;
         }
         $message .= "<strong>{$section['title']}</strong>\r\n";
         foreach ($section['fields'] as $field) {
             if (strpos($field->unique_name, 'state') && is_numeric($field->value)) {
                 $field->value = wpsc_get_region($field->value);
             }
             $message .= $field->name . ' : ' . $field->value . "\r\n";
         }
         $message .= "\r\n";
     }
     // preserve pre-3.8.9 hooks
     $message = apply_filters('wpsc_transaction_result_report', $message);
     return apply_filters('wpsc_purchase_log_admin_notification_raw_message', $message, $this);
 }
/**
 * transaction_results function main function for creating the purchase reports, transaction results page, and email receipts
 * @access public
 *
 * @since 3.7
 * @param $sessionid (string) unique session id
 * @param echo_to_screen (boolean) whether to output the results or return them (potentially redundant)
 * @param $transaction_id (int) the transaction id
 */
function transaction_results($sessionid, $display_to_screen = true, $transaction_id = null)
{
    // Do we seriously need this many globals?
    global $wpdb, $wpsc_cart, $echo_to_screen, $purchase_log, $order_url;
    global $message_html, $cart, $errorcode, $wpsc_purchlog_statuses, $wpsc_gateways;
    $wpec_taxes_controller = new wpec_taxes_controller();
    $is_transaction = false;
    $errorcode = 0;
    $purchase_log = $wpdb->get_row($wpdb->prepare("SELECT * FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE `sessionid`= %s LIMIT 1", $sessionid), ARRAY_A);
    $order_status = $purchase_log['processed'];
    $curgateway = $purchase_log['gateway'];
    if (!is_bool($display_to_screen)) {
        $display_to_screen = true;
    }
    $echo_to_screen = $display_to_screen;
    //new variable to check whether function is being called from wpsc_purchlog_resend_email()
    $resend_email = isset($_REQUEST['email_buyer_id']) ? true : false;
    if (is_numeric($sessionid)) {
        if ($echo_to_screen) {
            echo apply_filters('wpsc_pre_transaction_results', '');
        }
        // New code to check whether transaction is processed, true if accepted false if pending or incomplete
        $is_transaction = wpsc_check_purchase_processed($purchase_log['processed']);
        $message_html = $message = stripslashes(get_option('wpsc_email_receipt'));
        if ($is_transaction) {
            $message = __('The Transaction was successful', 'wpsc') . "\r\n" . $message;
            $message_html = __('The Transaction was successful', 'wpsc') . "<br />" . $message_html;
        }
        $country = get_option('country_form_field');
        $billing_country = '';
        $shipping_country = '';
        if (!empty($purchase_log['shipping_country'])) {
            $billing_country = $purchase_log['billing_country'];
            $shipping_country = $purchase_log['shipping_country'];
        } elseif (!empty($country)) {
            $country = $wpdb->get_var($wpdb->prepare("SELECT `value` FROM `" . WPSC_TABLE_SUBMITED_FORM_DATA . "` WHERE `log_id` = %d AND `form_id` = %d LIMIT 1", $purchase_log['id'], get_option('country_form_field')));
            $billing_country = $country;
            $shipping_country = $country;
        }
        $email = wpsc_get_buyers_email($purchase_log['id']);
        $previous_download_ids = array();
        $product_list = $product_list_html = $report_product_list = '';
        $cart = $wpdb->get_results($wpdb->prepare("SELECT * FROM `" . WPSC_TABLE_CART_CONTENTS . "` WHERE `purchaseid` = %d", $purchase_log['id']), ARRAY_A);
        if ($cart != null && $errorcode == 0) {
            $total_shipping = '';
            foreach ($cart as $row) {
                $link = array();
                $wpdb->update(WPSC_TABLE_DOWNLOAD_STATUS, array('active' => '1'), array('cartid' => $row['id'], '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 ($is_transaction) {
                    $download_data = $wpdb->get_results($wpdb->prepare("SELECT *\n\t\t\t\t\tFROM `" . WPSC_TABLE_DOWNLOAD_STATUS . "`\n\t\t\t\t\tWHERE `active`='1'\n\t\t\t\t\tAND `purchid` = %d\n\t\t\t\t\tAND `cartid` = %d", $purchase_log['id'], $row['id']), ARRAY_A);
                    if (count($download_data) > 0) {
                        foreach ($download_data as $single_download) {
                            $file_data = get_post($single_download['product_id']);
                            // if the uniqueid is not equal to null, its "valid", regardless of what it is
                            $argsdl = array('post_type' => 'wpsc-product-file', 'post_parent' => $single_download['product_id'], 'numberposts' => -1, 'post_status' => 'all');
                            $download_file_posts = (array) get_posts($argsdl);
                            foreach ((array) $download_file_posts as $single_file_post) {
                                if ($single_file_post->ID == $single_download['fileid']) {
                                    $current_Dl_product_file_post = $single_file_post;
                                    break;
                                }
                            }
                            $file_name = $current_Dl_product_file_post->post_title;
                            if ($single_download['uniqueid'] == null) {
                                $link[] = array("url" => site_url("?downloadid=" . $single_download['id']), "name" => $file_name);
                            } else {
                                $link[] = array("url" => site_url("?downloadid=" . $single_download['uniqueid']), "name" => $file_name);
                            }
                        }
                    } else {
                        $order_status = $purchase_log['processed'];
                    }
                    if (isset($download_data['id'])) {
                        $previous_download_ids[] = $download_data['id'];
                    }
                }
                do_action('wpsc_confirm_checkout', $purchase_log['id']);
                $total = 0;
                $shipping = $row['pnp'];
                $total_shipping += $shipping;
                $total += $row['price'] * $row['quantity'];
                $message_price = wpsc_currency_display($total, array('display_as_html' => false));
                $message_price_html = wpsc_currency_display($total);
                $shipping_price = wpsc_currency_display($shipping, array('display_as_html' => false));
                if (isset($purchase['gateway']) && 'wpsc_merchant_testmode' != $purchase['gateway']) {
                    if ($gateway['internalname'] == $purch_data[0]['gateway']) {
                        $gateway_name = $gateway['name'];
                    }
                } else {
                    $gateway_name = "Manual Payment";
                }
                $variation_list = '';
                if (!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 .= " - " . $row['name'] . "  " . $message_price . " " . __('Click to download', 'wpsc') . ":";
                    $product_list_html .= " - " . $row['name'] . "  " . $message_price_html . "&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";
                    }
                    $product_list .= $additional_content;
                    $product_list_html .= $additional_content;
                } else {
                    $product_list .= " - " . $row['quantity'] . " " . $row['name'] . "  " . $message_price . "\n\r";
                    if ($shipping > 0) {
                        $product_list .= sprintf(__(' - Shipping: %s
', 'wpsc'), $shipping_price);
                    }
                    $product_list_html .= "\n\r - " . $row['quantity'] . " " . $row['name'] . "  " . $message_price_html . "\n\r";
                    if ($shipping > 0) {
                        $product_list_html .= sprintf(__(' &nbsp; Shipping: %s
', 'wpsc'), $shipping_price);
                    }
                }
                //add tax if included
                if ($wpec_taxes_controller->wpec_taxes_isenabled() && $wpec_taxes_controller->wpec_taxes_isincluded()) {
                    $taxes_text = ' - - ' . __('Tax Included', 'wpsc') . ': ' . wpsc_currency_display($row['tax_charged'], array('display_as_html' => false)) . "\n\r";
                    $taxes_text_html = ' - - ' . __('Tax Included', 'wpsc') . ': ' . wpsc_currency_display($row['tax_charged']);
                    $product_list .= $taxes_text;
                    $product_list_html .= $taxes_text_html;
                }
                // if
                $report = get_option('wpsc_email_admin');
                $report_product_list .= " - " . $row['quantity'] . " " . $row['name'] . "  " . $message_price . "\n\r";
            }
            // closes foreach cart as row
            // Decrement the stock here
            if ($is_transaction) {
                wpsc_decrement_claimed_stock($purchase_log['id']);
            }
            if (!empty($purchase_log['discount_data'])) {
                $coupon_data = $wpdb->get_row($wpdb->prepare("SELECT * FROM `" . WPSC_TABLE_COUPON_CODES . "` WHERE coupon_code = %s LIMIT 1", $purchase_log['discount_data']), ARRAY_A);
                if ($coupon_data['use-once'] == 1) {
                    $wpdb->update(WPSC_TABLE_COUPON_CODES, array('active' => '0', 'is-used' => '1'), array('id' => $coupon_data['id']));
                }
            }
            $total_shipping = wpsc_get_total_shipping($purchase_log['id']);
            $total = $purchase_log['totalprice'];
            $total_price_email = '';
            $total_price_html = '';
            $total_tax_html = '';
            $total_tax = '';
            $total_shipping_html = '';
            $total_shipping_email = '';
            if (wpsc_uses_shipping() || !empty($purchase_log['base_shipping'])) {
                $total_shipping_email .= sprintf(__('Total Shipping: %s
	', 'wpsc'), wpsc_currency_display($total_shipping, array('display_as_html' => false)));
            }
            $total_price_email .= sprintf(__('Total: %s
', 'wpsc'), wpsc_currency_display($total, array('display_as_html' => false)));
            if ($purchase_log['discount_value'] > 0) {
                $discount_email = __('Discount', 'wpsc') . "\n\r: ";
                $discount_email .= $purchase_log['discount_data'] . ' : ' . wpsc_currency_display($purchase_log['discount_value'], array('display_as_html' => false)) . "\n\r";
                $report .= $discount_email . "\n\r";
                $total_shipping_email .= $discount_email;
                $total_shipping_html .= __('Discount', 'wpsc') . ": " . wpsc_currency_display($purchase_log['discount_value']) . "\n\r";
            }
            //only show total tax if tax is not included
            if ($wpec_taxes_controller->wpec_taxes_isenabled() && !$wpec_taxes_controller->wpec_taxes_isincluded()) {
                $total_tax_html .= __('Total Tax', 'wpsc') . ': ' . wpsc_currency_display($purchase_log['wpec_taxes_total']) . "\n\r";
                $total_tax .= __('Total Tax', 'wpsc') . ': ' . wpsc_currency_display($purchase_log['wpec_taxes_total'], array('display_as_html' => false)) . "\n\r";
            }
            if (wpsc_uses_shipping() || !empty($purchase_log['base_shipping'])) {
                $total_shipping_html .= '<hr>' . sprintf(__('Total Shipping: %s
	', 'wpsc'), wpsc_currency_display($total_shipping));
            }
            $total_price_html .= sprintf(__('Total: %s
', 'wpsc'), wpsc_currency_display($total));
            $report_id = sprintf(__("Purchase # %s\n", 'wpsc'), $purchase_log['id']);
            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'];
            }
            $message = apply_filters('wpsc_transaction_result_message', $message);
            $message = str_replace('%purchase_id%', $report_id, $message);
            $message = str_replace('%product_list%', $product_list, $message);
            $message = str_replace('%total_tax%', $total_tax, $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);
            $report = apply_filters('wpsc_transaction_result_report', $report);
            $report = str_replace('%purchase_id%', $report_id, $report);
            $report = str_replace('%product_list%', $report_product_list, $report);
            $report = str_replace('%total_tax%', $total_tax, $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 = apply_filters('wpsc_transaction_result_message_html', $message_html);
            $message_html = str_replace('%purchase_id%', $report_id, $message_html);
            $message_html = str_replace('%product_list%', $product_list_html, $message_html);
            $message_html = str_replace('%total_tax%', $total_tax_html, $message_html);
            $message_html = str_replace('%total_shipping%', $total_shipping_html, $message_html);
            $message_html = str_replace('%total_price%', $total_price_html, $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);
            if (!empty($email)) {
                add_filter('wp_mail_from', 'wpsc_replace_reply_address', 0);
                add_filter('wp_mail_from_name', 'wpsc_replace_reply_name', 0);
                $message = apply_filters('wpsc_email_message', $message, $report_id, $product_list, $total_tax, $total_shipping_email, $total_price_email);
                if (!$is_transaction) {
                    $payment_instructions = strip_tags(stripslashes(get_option('payment_instructions')));
                    if (!empty($payment_instructions)) {
                        $payment_instructions .= "\n\r";
                    }
                    $message = __('Thank you, your purchase is pending, you will be sent an email once the order clears.', 'wpsc') . "\n\r" . $payment_instructions . $message;
                    $message_html = __('Thank you, your purchase is pending, you will be sent an email once the order clears.', 'wpsc') . "\n\r" . $payment_instructions . $message_html;
                    // prevent email duplicates
                    if (!get_transient("{$sessionid}_pending_email_sent") || $resend_email) {
                        wp_mail($email, __('Order Pending: Payment Required', 'wpsc'), $message);
                        set_transient("{$sessionid}_pending_email_sent", true, 60 * 60 * 12);
                    }
                } elseif (!get_transient("{$sessionid}_receipt_email_sent") || $resend_email) {
                    wp_mail($email, __('Purchase Receipt', 'wpsc'), $message);
                    set_transient("{$sessionid}_receipt_email_sent", true, 60 * 60 * 12);
                }
            }
            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";
            $form_sql = $wpdb->prepare("SELECT * FROM `" . WPSC_TABLE_SUBMITED_FORM_DATA . "` WHERE `log_id` = %d", $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($wpdb->prepare("SELECT * FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` WHERE `id` = %d LIMIT 1", $form_field['form_id']), ARRAY_A);
                    switch ($form_data['type']) {
                        case "country":
                            $country_code = $form_field['value'];
                            $report_user .= $form_data['name'] . ": " . wpsc_get_country($country_code) . "\n";
                            //check if country has a state then display if it does.
                            $country_data = wpsc_country_has_state($country_code);
                            if ($country_data['has_regions'] == 1) {
                                $report_user .= __('Billing 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";
                            break;
                        default:
                            if ($form_data['name'] == 'State' && is_numeric($form_field['value'])) {
                                $report_user .= __('Delivery State', 'wpsc') . ": " . wpsc_get_state_by_id($form_field['value'], 'name') . "\n";
                            } else {
                                $report_user .= wp_kses($form_data['name'], array()) . ": " . $form_field['value'] . "\n";
                            }
                            break;
                    }
                }
            }
            $report_user .= "\n\r";
            $report = $report_id . $report_user . $report;
            //echo '======REPORT======<br />'.$report.'<br />';
            //echo '======EMAIL======<br />'.$message.'<br />';
            if (get_option('purch_log_email') != null && $purchase_log['email_sent'] != 1) {
                wp_mail(get_option('purch_log_email'), __('Purchase Report', 'wpsc'), $report);
                $wpdb->update(WPSC_TABLE_PURCHASE_LOGS, array('email_sent' => '1'), array('sessionid' => $sessionid));
            }
            /// Adjust stock and empty the cart
            $wpsc_cart->submit_stock_claims($purchase_log['id']);
            $wpsc_cart->empty_cart();
        }
    }
}
 /**
  * Given a WPEC state code (int), will return the state/region name
  *
  * @since 0.0.1
  * @param int $state_code
  * @return string|int will be int if wordpress database & wpec are not available
  */
 function get_state($state_code)
 {
     $state_code = isset($_POST['region']) ? $_POST['region'] : $state_code;
     return wpsc_get_region($state_code);
 }
function wpsc_user_details()
{
    global $wpdb, $user_ID, $wpsc_purchlog_statuses, $gateway_checkout_form_fields, $purchase_log, $col_count;
    $nzshpcrt_gateways = nzshpcrt_get_gateways();
    $i = 0;
    $subtotal = 0;
    do_action('wpsc_pre_purchase_logs');
    foreach ((array) $purchase_log as $purchase) {
        $status_state = "expand";
        $status_style = "display:none;";
        $alternate = "";
        $i++;
        if ($i % 2 != 0) {
            $alternate = "class='alt'";
        }
        echo "<tr {$alternate}>\n\r";
        echo " <td class='processed'>";
        echo "<a href='#' onclick='return show_details_box(\"status_box_" . $purchase['id'] . "\",\"log_expander_icon_" . $purchase['id'] . "\");'>";
        if (!empty($_GET['id']) && $_GET['id'] == $purchase['id']) {
            $status_state = "collapse";
            $status_style = "style='display: block;'";
        }
        echo "<img class='log_expander_icon' id='log_expander_icon_" . $purchase['id'] . "' src='" . WPSC_CORE_IMAGES_URL . "/icon_window_{$status_state}.gif' alt='' title='' />";
        echo "<span id='form_group_" . $purchase['id'] . "_text'>" . __('Details', 'wpsc') . "</span>";
        echo "</a>";
        echo " </td>\n\r";
        echo " <td>";
        echo date("jS M Y", $purchase['date']);
        echo " </td>\n\r";
        echo " <td>";
        $country = get_option('country_form_field');
        if ($purchase['shipping_country'] != '') {
            $billing_country = $purchase['billing_country'];
            $shipping_country = $purchase['shipping_country'];
        } elseif (!empty($country)) {
            $country_sql = "SELECT * FROM `" . WPSC_TABLE_SUBMITED_FORM_DATA . "` WHERE `log_id` = '" . $purchase['id'] . "' AND `form_id` = '" . get_option('country_form_field') . "' LIMIT 1";
            $country_data = $wpdb->get_results($country_sql, ARRAY_A);
            $billing_country = $country_data[0]['value'];
            $shipping_country = $country_data[0]['value'];
        }
        echo wpsc_currency_display($purchase['totalprice'], array('display_as_html' => false));
        $subtotal += $purchase['totalprice'];
        echo " </td>\n\r";
        if (get_option('payment_method') == 2) {
            echo " <td>";
            $gateway_name = '';
            foreach ((array) $nzshpcrt_gateways as $gateway) {
                if ($purchase['gateway'] != 'testmode') {
                    if ($gateway['internalname'] == $purchase['gateway']) {
                        $gateway_name = $gateway['name'];
                    }
                } else {
                    $gateway_name = "Manual Payment";
                }
            }
            echo $gateway_name;
            echo " </td>\n\r";
        }
        echo "</tr>\n\r";
        echo "<tr>\n\r";
        echo " <td colspan='{$col_count}' class='details'>\n\r";
        echo "  <div id='status_box_" . $purchase['id'] . "' class='order_status' style=\"{$status_style}\">\n\r";
        echo "  <div>\n\r";
        //order status code lies here
        //check what $purchase['processed'] reflects in the $wpsc_purchlog_statuses array
        $status_name = wpsc_find_purchlog_status_name($purchase['processed']);
        echo "  <strong class='form_group'>" . __('Order Status', 'wpsc') . ":</strong>\n\r";
        echo $status_name . "<br /><br />";
        do_action('wpsc_user_log_after_order_status', $purchase);
        //written by allen
        $usps_id = get_option('usps_user_id');
        if ($usps_id != null) {
            $XML1 = "<TrackFieldRequest USERID=\"{$usps_id}\"><TrackID ID=\"" . $purchase['track_id'] . "\"></TrackID></TrackFieldRequest>";
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, "http://secure.shippingapis.com/ShippingAPITest.dll?");
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($ch, CURLOPT_POST, 1);
            curl_setopt($ch, CURLOPT_HEADER, 0);
            $postdata = "API=TrackV2&XML=" . $XML1;
            curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
            $parser = new xml2array();
            $parsed = $parser->parse($result);
            $parsed = $parsed[0]['children'][0]['children'];
            if ($purchase['track_id'] != null) {
                echo "<br /><br />";
                echo " <strong class='form_group'>" . __('Shipping Address', 'wpsc') . "</strong>\n\r";
                echo "<table>";
                foreach ((array) $parsed as $parse) {
                    if ($parse['name'] == "TRACKSUMMARY") {
                        foreach ((array) $parse['children'] as $attrs) {
                            if ($attrs['name'] != "EVENT") {
                                $attrs['name'] = str_replace("EVENT", "", $attrs['name']);
                            }
                            $bar = ucfirst(strtolower($attrs['name']));
                            echo "<tr><td>" . $bar . "</td><td>" . $attrs['tagData'] . "</td></tr>";
                        }
                    }
                }
                echo "</table>";
            }
            echo "<br /><br />";
        }
        //end of written by allen
        //cart contents display starts here;
        echo "  <strong class='form_group'>" . __('Order Details', 'wpsc') . ":</strong>\n\r";
        $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 "<table class='logdisplay'>";
            echo "<tr class='toprow2'>";
            echo " <td>";
            _e('Name', 'wpsc');
            echo " </td>";
            echo " <td>";
            _e('Quantity', 'wpsc');
            echo " </td>";
            echo " <td>";
            _e('Price', 'wpsc');
            echo " </td>";
            echo " <td>";
            _e('GST', 'wpsc');
            echo " </td>";
            echo " <td>";
            _e('Shipping', 'wpsc');
            echo " </td>";
            echo " <td>";
            _e('Total', 'wpsc');
            echo " </td>";
            echo "</tr>";
            $gsttotal = false;
            $endtotal = $total_shipping = 0;
            foreach ((array) $cart_log as $cart_row) {
                $alternate = "";
                $j++;
                if ($j % 2 != 0) {
                    $alternate = "class='alt'";
                }
                $variation_list = '';
                $billing_country = !empty($country_data[0]['value']) ? $country_data[0]['value'] : '';
                $shipping_country = !empty($country_data[0]['value']) ? $country_data[0]['value'] : '';
                $shipping = $cart_row['pnp'];
                $total_shipping += $shipping;
                echo "<tr {$alternate}>";
                echo " <td>";
                echo $cart_row['name'];
                echo $variation_list;
                echo " </td>";
                echo " <td>";
                echo $cart_row['quantity'];
                echo " </td>";
                echo " <td>";
                $price = $cart_row['price'] * $cart_row['quantity'];
                echo wpsc_currency_display($price);
                echo " </td>";
                echo " <td>";
                $gst = $cart_row['tax_charged'];
                if ($gst > 0) {
                    $gsttotal += $gst;
                }
                echo wpsc_currency_display($gst, array('display_as_html' => false));
                echo " </td>";
                echo " <td>";
                echo wpsc_currency_display($shipping, array('display_as_html' => false));
                echo " </td>";
                echo " <td>";
                $endtotal += $price;
                echo wpsc_currency_display($shipping + $price, array('display_as_html' => false));
                echo " </td>";
                echo '</tr>';
            }
            echo "<tr >";
            echo " <td>";
            echo " </td>";
            echo " <td>";
            echo " </td>";
            echo " <td>";
            echo " <td>";
            echo " </td>";
            echo " </td>";
            echo " <td>";
            echo "<strong>" . __('Total Shipping', 'wpsc') . ":</strong><br />";
            echo "<strong>" . __('Total Tax', 'wpsc') . ":</strong><br />";
            echo "<strong>" . __('Final Total', 'wpsc') . ":</strong>";
            echo " </td>";
            echo " <td>";
            $total_shipping += $purchase['base_shipping'];
            $endtotal += $total_shipping;
            $endtotal += $purchase['wpec_taxes_total'];
            echo wpsc_currency_display($total_shipping, array('display_as_html' => false)) . "<br />";
            if ($gsttotal) {
                //if false then must be exclusive.. doesnt seem too reliable needs more testing
                echo wpsc_currency_display($gsttotal, array('display_as_html' => false)) . "<br />";
            } else {
                echo wpsc_currency_display($purchase['wpec_taxes_total'], array('display_as_html' => false)) . "<br />";
            }
            echo wpsc_currency_display($endtotal, array('display_as_html' => false));
            echo " </td>";
            echo '</tr>';
            echo "</table>";
            echo "<br />";
            echo "<strong>" . __('Customer Details', 'wpsc') . ":</strong>";
            echo "<table class='customer_details'>";
            $usersql = "SELECT `" . WPSC_TABLE_SUBMITED_FORM_DATA . "`.value, `" . WPSC_TABLE_CHECKOUT_FORMS . "`.* FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` LEFT JOIN `" . WPSC_TABLE_SUBMITED_FORM_DATA . "` ON `" . WPSC_TABLE_CHECKOUT_FORMS . "`.id = `" . WPSC_TABLE_SUBMITED_FORM_DATA . "`.`form_id` WHERE `" . WPSC_TABLE_SUBMITED_FORM_DATA . "`.log_id=" . $purchase['id'] . " OR `" . WPSC_TABLE_CHECKOUT_FORMS . "`.type = 'heading' ORDER BY `" . WPSC_TABLE_CHECKOUT_FORMS . "`.`checkout_order`";
            $formfields = $wpdb->get_results($usersql, ARRAY_A);
            if (!empty($formfields)) {
                foreach ((array) $formfields as $form_field) {
                    // If its a heading display the Name otherwise continue on
                    if ('heading' == $form_field['type']) {
                        echo "  <tr><td colspan='2'>" . $form_field['name'] . ":</td></tr>";
                        continue;
                    }
                    switch ($form_field['unique_name']) {
                        case 'shippingstate':
                            if (is_numeric($purchase['shipping_region'])) {
                                $state = wpsc_get_region($purchase['shipping_region']);
                            } else {
                                $state = $form_field['value'];
                            }
                            echo "  <tr><td>" . $form_field['name'] . ":</td><td>" . $state . "</td></tr>";
                            break;
                        case 'billingstate':
                            if (is_numeric($purchase['billing_region'])) {
                                $state = wpsc_get_region($purchase['billing_region']);
                            } else {
                                $state = $form_field['value'];
                            }
                            echo "  <tr><td>" . $form_field['name'] . ":</td><td>" . $state . "</td></tr>";
                            break;
                        default:
                            echo "  <tr><td>" . $form_field['name'] . ":</td><td>" . esc_html($form_field['value']) . "</td></tr>";
                    }
                }
            }
            $payment_gateway_names = '';
            $payment_gateway_names = get_option('payment_gateway_names');
            foreach ((array) $payment_gateway_names as $gatewayname) {
                //if the gateway has a custom name
                if (!empty($gatewayname)) {
                    $display_name = $payment_gateway_names[$purchase_log[0]['gateway']];
                } else {
                    //if not fall back on default name
                    foreach ((array) $nzshpcrt_gateways as $gateway) {
                        if ($gateway['internalname'] == $purchase['gateway']) {
                            $display_name = $gateway['name'];
                        }
                    }
                }
            }
            echo "  <tr><td>" . __('Payment Method', 'wpsc') . ":</td><td>" . $display_name . "</td></tr>";
            echo "  <tr><td>" . __('Purchase #', 'wpsc') . ":</td><td>" . $purchase['id'] . "</td></tr>";
            if ($purchase['transactid'] != '') {
                echo "  <tr><td>" . __('Transaction Id', 'wpsc') . ":</td><td>" . $purchase['transactid'] . "</td></tr>";
            }
            echo "</table>";
        }
        echo "  </div>\n\r";
        echo "  </div>\n\r";
        echo " </td>\n\r";
        echo "</tr>\n\r";
    }
}
Example #13
0
File: sm38.php Project: bulats/chef
function print_packing_slip_data($input_data, $form_data, $purch_data, $rekeyed_input, $purchase_id_value)
{
    global $wpdb;
    if ($input_data != null) {
        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->_real_escape($purch_data[$purchase_id_value]['billing_country']) . "')");
                    if (is_numeric($purch_data[$purchase_id_value]['billing_region']) && $delivery_region_count > 0) {
                        echo "\t<tr><td>" . __('State', 'wpsc') . ":</td><td> " . wpsc_get_region($purch_data[$purchase_id_value]['billing_region']) . "</td></tr>\n\r";
                    }
                    echo "\t<tr><td>" . wp_kses($form_field['name'], array()) . ":</td><td>" . htmlentities(stripslashes($rekeyed_input[$purchase_id_value][$form_field['id']]['value']), ENT_QUOTES, 'UTF-8') . "</td></tr>\n\r";
                    break;
                case 'delivery_country':
                    if (is_numeric($purch_data[$purchase_id_value]['shipping_region']) && $delivery_region_count > 0) {
                        echo "\t<tr><td>" . __('State', 'wpsc') . ":</td><td> " . wpsc_get_region($purch_data[$purchase_id_value]['shipping_region']) . "</td></tr>\n\r";
                    }
                    echo "\t<tr><td>" . wp_kses($form_field['name'], array()) . ":</td><td>" . htmlentities(stripslashes($rekeyed_input[$purchase_id_value][$form_field['id']]['value']), ENT_QUOTES, 'UTF-8') . "</td></tr>\n\r";
                    break;
                case 'heading':
                    if ($form_field['name'] == "Hidden Fields") {
                        continue;
                    } else {
                        echo "<tr class='heading'><td colspan='2'><strong><u>" . wp_kses($form_field['name'], array()) . "</u>:</strong></td></tr>\n\r";
                    }
                    break;
                default:
                    if ($form_field['name'] == "Cupcakes") {
                        parse_str($rekeyed_input[$purchase_id_value][$form_field['id']]['value'], $cupcakes);
                        foreach ($cupcakes as $product_id => $quantity) {
                            $product = get_post($product_id);
                            $string .= "(" . $quantity . ") " . $product->post_title . ", ";
                        }
                        $string = rtrim($string, ", ");
                        echo "\t<tr><td>" . wp_kses($form_field['name'], array()) . ":</td><td>" . htmlentities(stripslashes($string), ENT_QUOTES, 'UTF-8') . "</td></tr>\n\r";
                    } else {
                        if ($form_field['name'] == "State" && !empty($purch_data[$purchase_id_value]['billing_region']) || $form_field['name'] == "State" && !empty($purch_data[$purchase_id_value]['billing_region'])) {
                            echo "";
                        } else {
                            echo "\t<tr><td>" . wp_kses($form_field['name'], array()) . ":</td><td>" . (isset($rekeyed_input[$purchase_id_value][$form_field['id']]) ? htmlentities(stripslashes($rekeyed_input[$purchase_id_value][$form_field['id']]['value']), ENT_QUOTES, 'UTF-8') : '') . "</td></tr>\n\r";
                        }
                    }
                    break;
            }
        }
    } else {
        echo "\t<tr><td>" . __('Name', 'wpsc') . ":</td><td> " . $purch_data[$purchase_id_value]['firstname'] . " " . $purch_data[$purchase_id_value]['lastname'] . "</td></tr>\n\r";
        echo "\t<tr><td>" . __('Address', 'wpsc') . ":</td><td> " . $purch_data[$purchase_id_value]['address'] . "</td></tr>\n\r";
        echo "\t<tr><td>" . __('Phone', 'wpsc') . ":</td><td> " . $purch_data[$purchase_id_value]['phone'] . "</td></tr>\n\r";
        echo "\t<tr><td>" . __('Email', 'wpsc') . ":</td><td> " . $purch_data[$purchase_id_value]['email'] . "</td></tr>\n\r";
    }
    if (2 == get_option('payment_method')) {
        $gateway_name = '';
        $nzshpcrt_gateways = nzshpcrt_get_gateways();
        foreach ($nzshpcrt_gateways as $gateway) {
            if ($purch_data[$purchase_id_value]['gateway'] != 'testmode') {
                if ($gateway['internalname'] == $purch_data[$purchase_id_value]['gateway']) {
                    $gateway_name = $gateway['name'];
                }
            } else {
                $gateway_name = __('Manual Payment', 'wpsc');
            }
        }
    }
}