<?php
/**
* File contains the order-processing class ("order")
*
* @package classes
* @copyright Copyright 2003-2007 Zen Cart Development Team
* @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
* @version $Id: order.php 7129 2007-09-29 03:03:04Z drbyte $
*/
/**
* order class
*
* Handles all order-processing functions
*
* @package classes
*/
if (!defined('IS_ADMIN_FLAG')) {
die('Illegal Access');
}
class order extends base {
var $info, $totals, $products, $customer, $delivery, $content_type, $email_low_stock, $products_ordered_attributes,
$products_ordered, $products_ordered_email, $attachArray;
function order($order_id = '') {
$this->info = array();
$this->totals = array();
$this->products = array();
$this->customer = array();
$this->delivery = array();
if (zen_not_null($order_id)) {
$this->query($order_id);
} else {
$this->cart();
}
}
function query($order_id) {
global $db;
$order_id = zen_db_prepare_input($order_id);
$order_query = "select customers_id, customers_name, customers_company,
customers_street_address, customers_suburb, customers_city,
customers_postcode, customers_state, customers_country,
customers_telephone, customers_email_address, customers_address_format_id,
delivery_name, delivery_company, delivery_street_address, delivery_suburb,
delivery_city, delivery_postcode, delivery_state, delivery_country,
delivery_address_format_id, billing_name, billing_company,
billing_street_address, billing_suburb, billing_city, billing_postcode,
billing_state, billing_country, billing_address_format_id,
payment_method, payment_module_code, shipping_method, shipping_module_code,
coupon_code, cc_type, cc_owner, cc_number, cc_expires, currency, currency_value,
date_purchased, orders_status, last_modified, order_total, order_tax, ip_address
from " . TABLE_ORDERS . "
where orders_id = '" . (int)$order_id . "'";
$order = $db->Execute($order_query);
$totals_query = "select title, text, class
from " . TABLE_ORDERS_TOTAL . "
where orders_id = '" . (int)$order_id . "'
order by sort_order";
$totals = $db->Execute($totals_query);
while (!$totals->EOF) {
if ($totals->fields['class'] == 'ot_coupon') {
$coupon_link_query = "SELECT coupon_id
from " . TABLE_COUPONS . "
where coupon_code ='" . $order->fields['coupon_code'] . "'";
$coupon_link = $db->Execute($coupon_link_query);
$zc_coupon_link = '<a href="javascript:couponpopupWindow(\'' . zen_href_link(FILENAME_POPUP_COUPON_HELP, 'cID=' . $coupon_link->fields['coupon_id']) . '\')">';
}
$this->totals[] = array('title' => ($totals->fields['class'] == 'ot_coupon' ? $zc_coupon_link . $totals->fields['title'] . '</a>' : $totals->fields['title']),
'text' => $totals->fields['text'],
'class' => $totals->fields['class']);
$totals->MoveNext();
}
$order_total_query = "select text, value
from " . TABLE_ORDERS_TOTAL . "
where orders_id = '" . (int)$order_id . "'
and class = 'ot_total'";
$order_total = $db->Execute($order_total_query);
$shipping_method_query = "select title, value
from " . TABLE_ORDERS_TOTAL . "
where orders_id = '" . (int)$order_id . "'
and class = 'ot_shipping'";
$shipping_method = $db->Execute($shipping_method_query);
$order_status_query = "select orders_status_name
from " . TABLE_ORDERS_STATUS . "
where orders_status_id = '" . $order->fields['orders_status'] . "'
and language_id = '" . (int)$_SESSION['languages_id'] . "'";
$order_status = $db->Execute($order_status_query);
$this->info = array('currency' => $order->fields['currency'],
'currency_value' => $order->fields['currency_value'],
'payment_method' => $order->fields['payment_method'],
'payment_module_code' => $order->fields['payment_module_code'],
'shipping_method' => $order->fields['shipping_method'],
'shipping_module_code' => $order->fields['shipping_module_code'],
'coupon_code' => $order->fields['coupon_code'],
'cc_type' => $order->fields['cc_type'],
'cc_owner' => $order->fields['cc_owner'],
'cc_number' => $order->fields['cc_number'],
'cc_expires' => $order->fields['cc_expires'],
'date_purchased' => $order->fields['date_purchased'],
'orders_status' => $order_status->fields['orders_status_name'],
'last_modified' => $order->fields['last_modified'],
'total' => $order->fields['order_total'],
'tax' => $order->fields['order_tax'],
'ip_address' => $order->fields['ip_address']
);
$this->customer = array('id' => $order->fields['customers_id'],
'name' => $order->fields['customers_name'],
'company' => $order->fields['customers_company'],
'street_address' => $order->fields['customers_street_address'],
'suburb' => $order->fields['customers_suburb'],
'city' => $order->fields['customers_city'],
'postcode' => $order->fields['customers_postcode'],
'state' => $order->fields['customers_state'],
'country' => $order->fields['customers_country'],
'format_id' => $order->fields['customers_address_format_id'],
'telephone' => $order->fields['customers_telephone'],
'email_address' => $order->fields['customers_email_address']);
$this->delivery = array('name' => $order->fields['delivery_name'],
'company' => $order->fields['delivery_company'],
'street_address' => $order->fields['delivery_street_address'],
'suburb' => $order->fields['delivery_suburb'],
'city' => $order->fields['delivery_city'],
'postcode' => $order->fields['delivery_postcode'],
'state' => $order->fields['delivery_state'],
'country' => $order->fields['delivery_country'],
'format_id' => $order->fields['delivery_address_format_id']);
if (empty($this->delivery['name']) && empty($this->delivery['street_address'])) {
$this->delivery = false;
}
$this->billing = array('name' => $order->fields['billing_name'],
'company' => $order->fields['billing_company'],
'street_address' => $order->fields['billing_street_address'],
'suburb' => $order->fields['billing_suburb'],
'city' => $order->fields['billing_city'],
'postcode' => $o