Quick Search:

View

Revision:

Diff

Diff from 1060 to:

Annotations

Annotate by Age | Author | Mixed | None
/fisheye/browse/osCommerce/trunk/oscommerce/includes/classes/order.php

Annotated File View

hpdl
1
1 <?php
2 /*
hpdl
20
3   $Id: order.php 1060 2006-10-22 13:38:10Z hpdl $
hpdl
1
4
5   osCommerce, Open Source E-Commerce Solutions
6   http://www.oscommerce.com
7
hpdl
554
8   Copyright (c) 2006 osCommerce
hpdl
1
9
10   Released under the GNU General Public License
11 */
12
hpdl
554
13   class osC_Order {
hpdl
1
14     var $info, $totals, $products, $customer, $delivery, $content_type;
15
hpdl
368
16 /* Private variables */
17
18     var $_id;
19
20 /* Class constructor */
21
hpdl
554
22     function osC_Order($order_id = '') {
hpdl
368
23       if (is_numeric($order_id)) {
24         $this->_id = $order_id;
25       }
26
hpdl
1
27       $this->info = array();
28       $this->totals = array();
29       $this->products = array();
30       $this->customer = array();
31       $this->delivery = array();
32
hpdl
757
33       if (!empty($order_id)) {
hpdl
1
34         $this->query($order_id);
35       } else {
36         $this->cart();
37       }
38     }
39
hpdl
368
40 /* Public methods */
41
hpdl
554
42     function getStatusID($id) {
43       global $osC_Database;
44
45       $Qorder = $osC_Database->query('select orders_status from :table_orders where orders_id = :orders_id');
46       $Qorder->bindTable(':table_orders', TABLE_ORDERS);
47       $Qorder->bindInt(':orders_id', $id);
48       $Qorder->execute();
49
50       if ($Qorder->numberOfRows()) {
51         return $Qorder->valueInt('orders_status');
52       }
53
54       return false;
55     }
56
57     function remove($id) {
58       global $osC_Database;
59
60       $Qcheck = $osC_Database->query('select orders_status from :table_orders where orders_id = :orders_id');
61       $Qcheck->bindTable(':table_orders', TABLE_ORDERS);
62       $Qcheck->bindInt(':orders_id', $id);
63       $Qcheck->execute();
64
65       if ($Qcheck->valueInt('orders_status') === 4) {
66         $Qdel = $osC_Database->query('delete from :table_orders_products_download where orders_id = :orders_id');
67         $Qdel->bindTable(':table_orders_products_download', TABLE_ORDERS_PRODUCTS_DOWNLOAD);
68         $Qdel->bindInt(':orders_id', $id);
69         $Qdel->execute();
70
71         $Qdel = $osC_Database->query('delete from :table_orders_products_attributes where orders_id = :orders_id');
hpdl
1060
72         $Qdel->bindTable(':table_orders_products_attributes', TABLE_ORDERS_PRODUCTS_ATTRIBUTES);
hpdl
554
73         $Qdel->bindInt(':orders_id', $id);
74         $Qdel->execute();
75
76         $Qdel = $osC_Database->query('delete from :table_orders_products where orders_id = :orders_id');
77         $Qdel->bindTable(':table_orders_products', TABLE_ORDERS_PRODUCTS);
78         $Qdel->bindInt(':orders_id', $id);
79         $Qdel->execute();
80
81         $Qdel = $osC_Database->query('delete from :table_orders_status_history where orders_id = :orders_id');
82         $Qdel->bindTable(':table_orders_status_history', TABLE_ORDERS_STATUS_HISTORY);
83         $Qdel->bindInt(':orders_id', $id);
84         $Qdel->execute();
85
86         $Qdel = $osC_Database->query('delete from :table_orders_total where orders_id = :orders_id');
87         $Qdel->bindTable(':table_orders_total', TABLE_ORDERS_TOTAL);
88         $Qdel->bindInt(':orders_id', $id);
89         $Qdel->execute();
90
91         $Qdel = $osC_Database->query('delete from :table_orders where orders_id = :orders_id');
92         $Qdel->bindTable(':table_orders', TABLE_ORDERS);
93         $Qdel->bindInt(':orders_id', $id);
94         $Qdel->execute();
95       }
96
97       if (isset($_SESSION['prepOrderID'])) {
98         unset($_SESSION['prepOrderID']);
99       }
100     }
101
102     function insert() {
103       global $osC_Database, $osC_Customer, $osC_Language, $osC_Currencies, $osC_ShoppingCart;
104
105       if (isset($_SESSION['prepOrderID'])) {
106         $_prep = explode('-', $_SESSION['prepOrderID']);
107
108         if ($_prep[0] == $osC_ShoppingCart->getCartID()) {
109           return $_prep[1]; // order_id
110         } else {
111           if (osC_Order::getStatusID($_prep[1]) === 4) {
112             osC_Order::remove($_prep[1]);
113           }
114         }
115       }
116
hpdl
757
117       $Qorder = $osC_Database->query('insert into :table_orders (customers_id, customers_name, customers_company, customers_street_address, customers_suburb, customers_city, customers_postcode, customers_state, customers_state_code, customers_country, customers_country_iso2, customers_country_iso3, customers_telephone, customers_email_address, customers_address_format, customers_ip_address, delivery_name, delivery_company, delivery_street_address, delivery_suburb, delivery_city, delivery_postcode, delivery_state, delivery_state_code, delivery_country, delivery_country_iso2, delivery_country_iso3, delivery_address_format, billing_name, billing_company, billing_street_address, billing_suburb, billing_city, billing_postcode, billing_state, billing_state_code, billing_country, billing_country_iso2, billing_country_iso3, billing_address_format, payment_method, payment_module, date_purchased, orders_status, currency, currency_value) values (:customers_id, :customers_name, :customers_company, :customers_street_address, :customers_suburb, :customers_city, :customers_postcode, :customers_state, :customers_state_code, :customers_country, :customers_country_iso2, :customers_country_iso3, :customers_telephone, :customers_email_address, :customers_address_format, :customers_ip_address, :delivery_name, :delivery_company, :delivery_street_address, :delivery_suburb, :delivery_city, :delivery_postcode, :delivery_state, :delivery_state_code, :delivery_country, :delivery_country_iso2, :delivery_country_iso3, :delivery_address_format, :billing_name, :billing_company, :billing_street_address, :billing_suburb, :billing_city, :billing_postcode, :billing_state, :billing_state_code, :billing_country, :billing_country_iso2, :billing_country_iso3, :billing_address_format, :payment_method, :payment_module, now(), :orders_status, :currency, :currency_value)');
hpdl
554
118       $Qorder->bindTable(':table_orders', TABLE_ORDERS);
119       $Qorder->bindInt(':customers_id', $osC_Customer->getID());
120       $Qorder->bindValue(':customers_name', $osC_Customer->getName());
121       $Qorder->bindValue(':customers_company', '' /*$order->customer['company']*/);
122       $Qorder->bindValue(':customers_street_address', '' /*$order->customer['street_address']*/);
123       $Qorder->bindValue(':customers_suburb', '' /*$order->customer['suburb']*/);
124       $Qorder->bindValue(':customers_city', '' /*$order->customer['city']*/);
125       $Qorder->bindValue(':customers_postcode', '' /*$order->customer['postcode']*/);
126       $Qorder->bindValue(':customers_state', '' /*$order->customer['state']*/);
hpdl
757
127       $Qorder->bindValue(':customers_state_code', '');
hpdl
554
128       $Qorder->bindValue(':customers_country', '' /*$order->customer['country']['title']*/);
hpdl
757
129       $Qorder->bindValue(':customers_country_iso2', '');
130       $Qorder->bindValue(':customers_country_iso3', '');
hpdl
554
131       $Qorder->bindValue(':customers_telephone', '' /*$order->customer['telephone']*/);
132       $Qorder->bindValue(':customers_email_address', $osC_Customer->getEmailAddress());
hpdl
757
133       $Qorder->bindValue(':customers_address_format', '');
134       $Qorder->bindValue(':customers_ip_address', osc_get_ip_address());
hpdl
554
135       $Qorder->bindValue(':delivery_name', $osC_ShoppingCart->getShippingAddress('firstname') . ' ' . $osC_ShoppingCart->getShippingAddress('lastname'));
136       $Qorder->bindValue(':delivery_company', $osC_ShoppingCart->getShippingAddress('company'));
137       $Qorder->bindValue(':delivery_street_address', $osC_ShoppingCart->getShippingAddress('street_address'));
138       $Qorder->bindValue(':delivery_suburb', $osC_ShoppingCart->getShippingAddress('suburb'));
139       $Qorder->bindValue(':delivery_city', $osC_ShoppingCart->getShippingAddress('city'));
140       $Qorder->bindValue(':delivery_postcode', $osC_ShoppingCart->getShippingAddress('postcode'));
141       $Qorder->bindValue(':delivery_state', $osC_ShoppingCart->getShippingAddress('state'));
hpdl
757
142       $Qorder->bindValue(':delivery_state_code', $osC_ShoppingCart->getShippingAddress('zone_code'));
hpdl
554
143       $Qorder->bindValue(':delivery_country', $osC_ShoppingCart->getShippingAddress('country_title'));
hpdl
757
144       $Qorder->bindValue(':delivery_country_iso2', $osC_ShoppingCart->getShippingAddress('country_iso_code_2'));
145       $Qorder->bindValue(':delivery_country_iso3', $osC_ShoppingCart->getShippingAddress('country_iso_code_3'));
146       $Qorder->bindValue(':delivery_address_format', $osC_ShoppingCart->getShippingAddress('format'));
hpdl
554
147       $Qorder->bindValue(':billing_name', $osC_ShoppingCart->getBillingAddress('firstname') . ' ' . $osC_ShoppingCart->getBillingAddress('lastname'));
148       $Qorder->bindValue(':billing_company', $osC_ShoppingCart->getBillingAddress('company'));
149       $Qorder->bindValue(':billing_street_address', $osC_ShoppingCart->getBillingAddress('street_address'));
150       $Qorder->bindValue(':billing_suburb', $osC_ShoppingCart->getBillingAddress('suburb'));
151       $Qorder->bindValue(':billing_city', $osC_ShoppingCart->getBillingAddress('city'));
152       $Qorder->bindValue(':billing_postcode', $osC_ShoppingCart->getBillingAddress('postcode'));
153       $Qorder->bindValue(':billing_state', $osC_ShoppingCart->getBillingAddress('state'));
hpdl
757
154       $Qorder->bindValue(':billing_state_code', $osC_ShoppingCart->getBillingAddress('zone_code'));
hpdl
554
155       $Qorder->bindValue(':billing_country', $osC_ShoppingCart->getBillingAddress('country_title'));
hpdl
757
156       $Qorder->bindValue(':billing_country_iso2', $osC_ShoppingCart->getBillingAddress('country_iso_code_2'));
157       $Qorder->bindValue(':billing_country_iso3', $osC_ShoppingCart->getBillingAddress('country_iso_code_3'));
158       $Qorder->bindValue(':billing_address_format', $osC_ShoppingCart->getBillingAddress('format'));
hpdl
554
159       $Qorder->bindValue(':payment_method', $osC_ShoppingCart->getBillingMethod('title'));
160       $Qorder->bindValue(':payment_module', $GLOBALS['osC_Payment_' . $osC_ShoppingCart->getBillingMethod('id')]->getCode());
161       $Qorder->bindInt(':orders_status', 4);
162       $Qorder->bindValue(':currency', $osC_Currencies->getCode());
163       $Qorder->bindValue(':currency_value', $osC_Currencies->value($osC_Currencies->getCode()));
164       $Qorder->execute();
165
166       $insert_id = $osC_Database->nextID();
167
168       foreach ($osC_ShoppingCart->getOrderTotals() as $module) {
169         $Qtotals = $osC_Database->query('insert into :table_orders_total (orders_id, title, text, value, class, sort_order) values (:orders_id, :title, :text, :value, :class, :sort_order)');
170         $Qtotals->bindTable(':table_orders_total', TABLE_ORDERS_TOTAL);
171         $Qtotals->bindInt(':orders_id', $insert_id);
172         $Qtotals->bindValue(':title', $module['title']);
173         $Qtotals->bindValue(':text', $module['text']);
174         $Qtotals->bindValue(':value', $module['value']);
175         $Qtotals->bindValue(':class', $module['code']);
176         $Qtotals->bindInt(':sort_order', $module['sort_order']);
177         $Qtotals->execute();
178       }
179
180       $Qstatus = $osC_Database->query('insert into :table_orders_status_history (orders_id, orders_status_id, date_added, customer_notified, comments) values (:orders_id, :orders_status_id, now(), :customer_notified, :comments)');
181       $Qstatus->bindTable(':table_orders_status_history', TABLE_ORDERS_STATUS_HISTORY);
182       $Qstatus->bindInt(':orders_id', $insert_id);
183       $Qstatus->bindInt(':orders_status_id', 4);
184       $Qstatus->bindInt(':customer_notified', '0');
185       $Qstatus->bindValue(':comments', (isset($_SESSION['comments']) ? $_SESSION['comments'] : ''));
186       $Qstatus->execute();
187
188       foreach ($osC_ShoppingCart->getProducts() as $products) {
189         $Qproducts = $osC_Database->query('insert into :table_orders_products (orders_id, products_id, products_model, products_name, products_price, final_price, products_tax, products_quantity) values (:orders_id, :products_id, :products_model, :products_name, :products_price, :final_price, :products_tax, :products_quantity)');
190         $Qproducts->bindTable(':table_orders_products', TABLE_ORDERS_PRODUCTS);
191         $Qproducts->bindInt(':orders_id', $insert_id);
hpdl
757
192         $Qproducts->bindInt(':products_id', osc_get_product_id($products['id']));
hpdl
554
193         $Qproducts->bindValue(':products_model', '' /*$products['model']*/);
194         $Qproducts->bindValue(':products_name', $products['name']);
195         $Qproducts->bindValue(':products_price', $products['price']);
196         $Qproducts->bindValue(':final_price', $products['final_price']);
197         $Qproducts->bindValue(':products_tax', '' /*$products['tax']*/);
198         $Qproducts->bindInt(':products_quantity', $products['quantity']);
199         $Qproducts->execute();
200
201         $order_products_id = $osC_Database->nextID();
202
203         if ($osC_ShoppingCart->hasAttributes($products['id'])) {
204           foreach ($osC_ShoppingCart->getAttributes($products['id']) as $attributes) {
205             if (DOWNLOAD_ENABLED == '1') {
206               $Qattributes = $osC_Database->query('select popt.products_options_name, poval.products_options_values_name, pa.options_values_price, pa.price_prefix, pad.products_attributes_maxdays, pad.products_attributes_maxcount, pad.products_attributes_filename from :table_products_options popt, :table_products_options_values poval, :table_products_attributes pa left join :table_products_attributes_download pad on (pa.products_attributes_id = pad.products_attributes_id) where pa.products_id = :products_id and pa.options_id = :options_id and pa.options_id = popt.products_options_id and pa.options_values_id = :options_values_id and pa.options_values_id = poval.products_options_values_id and popt.language_id = :popt_language_id and poval.language_id = :poval_language_id');
207               $Qattributes->bindTable(':table_products_options', TABLE_PRODUCTS_OPTIONS);
208               $Qattributes->bindTable(':table_products_options_values', TABLE_PRODUCTS_OPTIONS_VALUES);
209               $Qattributes->bindTable(':table_products_attributes', TABLE_PRODUCTS_ATTRIBUTES);
210               $Qattributes->bindTable(':table_products_attributes_download', TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD);
211               $Qattributes->bindInt(':products_id', $products['id']);
212               $Qattributes->bindInt(':options_id', $attributes['options_id']);
213               $Qattributes->bindInt(':options_values_id', $attributes['options_values_id']);
214               $Qattributes->bindInt(':popt_language_id', $osC_Language->getID());
215               $Qattributes->bindInt(':poval_language_id', $osC_Language->getID());
216             } else {
217               $Qattributes = $osC_Database->query('select popt.products_options_name, poval.products_options_values_name, pa.options_values_price, pa.price_prefix from :table_products_options popt, :table_products_options_values poval, :table_products_attributes pa where pa.products_id = :products_id and pa.options_id = :options_id and pa.options_id = popt.products_options_id and pa.options_values_id = :options_values_id and pa.options_values_id = poval.products_options_values_id and popt.language_id = :popt_language_id and poval.language_id = :poval_language_id');
218               $Qattributes->bindTable(':table_products_options', TABLE_PRODUCTS_OPTIONS);
219               $Qattributes->bindTable(':table_products_options_values', TABLE_PRODUCTS_OPTIONS_VALUES);
220               $Qattributes->bindTable(':table_products_attributes', TABLE_PRODUCTS_ATTRIBUTES);
221               $Qattributes->bindInt(':products_id', $products['id']);
222               $Qattributes->bindInt(':options_id', $attributes['options_id']);
223               $Qattributes->bindInt(':options_values_id', $attributes['options_values_id']);
224               $Qattributes->bindInt(':popt_language_id', $osC_Language->getID());
225               $Qattributes->bindInt(':poval_language_id', $osC_Language->getID());
226             }
227             $Qattributes->execute();
228
229             $Qopa = $osC_Database->query('insert into :table_orders_products_attributes (orders_id, orders_products_id, products_options, products_options_values, options_values_price, price_prefix) values (:orders_id, :orders_products_id, :products_options, :products_options_values, :options_values_price, :price_prefix)');
230             $Qopa->bindTable(':table_orders_products_attributes', TABLE_ORDERS_PRODUCTS_ATTRIBUTES);
231             $Qopa->bindInt(':orders_id', $insert_id);
232             $Qopa->bindInt(':orders_products_id', $order_products_id);
233             $Qopa->bindValue(':products_options', $Qattributes->value('products_options_name'));
234             $Qopa->bindValue(':products_options_values', $Qattributes->value('products_options_values_name'));
235             $Qopa->bindValue(':options_values_price', $Qattributes->value('options_values_price'));
236             $Qopa->bindValue(':price_prefix', $Qattributes->value('price_prefix'));
237             $Qopa->execute();
238
239             if ((DOWNLOAD_ENABLED == '1') && (strlen($Qattributes->value('products_attributes_filename')) > 0)) {
240               $Qopd = $osC_Database->query('insert into :table_orders_products_download (orders_id, orders_products_id, orders_products_filename, download_maxdays, download_count) values (:orders_id, :orders_products_id, :orders_products_filename, :download_maxdays, :download_count)');
241               $Qopd->bindTable(':table_orders_products_download', TABLE_ORDERS_PRODUCTS_DOWNLOAD);
242               $Qopd->bindInt(':orders_id', $insert_id);
243               $Qopd->bindInt(':orders_products_id', $order_products_id);
244               $Qopd->bindValue(':orders_products_filename', $Qattributes->value('products_attributes_filename'));
245               $Qopd->bindValue(':download_maxdays', $Qattributes->value('products_attributes_maxdays'));
246               $Qopd->bindValue(':download_count', $Qattributes->value('products_attributes_maxcount'));
247               $Qopd->execute();
248             }
249           }
250         }
251       }
252
253       $_SESSION['prepOrderID'] = $osC_ShoppingCart->getCartID() . '-' . $insert_id;
254
255       return $insert_id;
256     }
257
258     function process($order_id, $status_id = '') {
259       global $osC_Database;
260
261       if (empty($status_id) || (is_numeric($status_id) === false)) {
262         $status_id = DEFAULT_ORDERS_STATUS_ID;
263       }
264
265       $Qstatus = $osC_Database->query('insert into :table_orders_status_history (orders_id, orders_status_id, date_added, customer_notified, comments) values (:orders_id, :orders_status_id, now(), :customer_notified, :comments)');
266       $Qstatus->bindTable(':table_orders_status_history', TABLE_ORDERS_STATUS_HISTORY);
267       $Qstatus->bindInt(':orders_id', $order_id);
268       $Qstatus->bindInt(':orders_status_id', $status_id);
269       $Qstatus->bindInt(':customer_notified', (SEND_EMAILS == '1') ? '1' : '0');
270       $Qstatus->bindValue(':comments', '');
271       $Qstatus->execute();
272
273       $Qupdate = $osC_Database->query('update :table_orders set orders_status = :orders_status where orders_id = :orders_id');
274       $Qupdate->bindTable(':table_orders', TABLE_ORDERS);
275       $Qupdate->bindInt(':orders_status', $status_id);
276       $Qupdate->bindInt(':orders_id', $order_id);
277       $Qupdate->execute();
278
279       $Qproducts = $osC_Database->query('select products_id, products_quantity from :table_orders_products where orders_id = :orders_id');
280       $Qproducts->bindTable(':table_orders_products', TABLE_ORDERS_PRODUCTS);
281       $Qproducts->bindInt(':orders_id', $order_id);
282       $Qproducts->execute();
283
284       while ($Qproducts->next()) {
285         if (STOCK_LIMITED == '1') {
286
287 /********** HPDL ; still uses logic from the shopping cart class
288           if (DOWNLOAD_ENABLED == '1') {
289             $Qstock = $osC_Database->query('select products_quantity, pad.products_attributes_filename from :table_products p left join :table_products_attributes pa on (p.products_id = pa.products_id) left join :table_products_attributes_download pad on (pa.products_attributes_id = pad.products_attributes_id) where p.products_id = :products_id');
290             $Qstock->bindTable(':table_products', TABLE_PRODUCTS);
291             $Qstock->bindTable(':table_products_attributes', TABLE_PRODUCTS_ATTRIBUTES);
292             $Qstock->bindTable(':table_products_attributes_download', TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD);
293             $Qstock->bindInt(':products_id', $Qproducts->valueInt('products_id'));
294
295 // Will work with only one option for downloadable products otherwise, we have to build the query dynamically with a loop
296             if ($osC_ShoppingCart->hasAttributes($products['id'])) {
297               $products_attributes = $osC_ShoppingCart->getAttributes($products['id']);
298               $products_attributes = array_shift($products_attributes);
299
300               $Qstock->appendQuery('and pa.options_id = :options_id and pa.options_values_id = :options_values_id');
301               $Qstock->bindInt(':options_id', $products_attributes['options_id']);
302               $Qstock->bindInt(':options_values_id', $products_attributes['options_values_id']);
303             }
304           } else {
305 ************/
306             $Qstock = $osC_Database->query('select products_quantity from :table_products where products_id = :products_id');
307             $Qstock->bindTable(':table_products', TABLE_PRODUCTS);
308             $Qstock->bindInt(':products_id', $Qproducts->valueInt('products_id'));
309 // HPDL          }
310
311           $Qstock->execute();
312
313           if ($Qstock->numberOfRows() > 0) {
314             $stock_left = $Qstock->valueInt('products_quantity');
315
316 // do not decrement quantities if products_attributes_filename exists
317 // HPDL            if ((DOWNLOAD_ENABLED == '-1') || ((DOWNLOAD_ENABLED == '1') && (strlen($Qstock->value('products_attributes_filename')) < 1))) {
318               $stock_left = $stock_left - $Qproducts->valueInt('products_quantity');
319
320               $Qupdate = $osC_Database->query('update :table_products set products_quantity = :products_quantity where products_id = :products_id');
321               $Qupdate->bindTable(':table_products', TABLE_PRODUCTS);
322               $Qupdate->bindInt(':products_quantity', $stock_left);
323               $Qupdate->bindInt(':products_id', $Qproducts->valueInt('products_id'));
324               $Qupdate->execute();
325 // HPDL            }
326
327             if ((STOCK_ALLOW_CHECKOUT == '-1') && ($stock_left < 1)) {
328               $Qupdate = $osC_Database->query('update :table_products set products_status = 0 where products_id = :products_id');
329               $Qupdate->bindTable(':table_products', TABLE_PRODUCTS);
330               $Qupdate->bindInt(':products_id', $Qproducts->valueInt('products_id'));
331               $Qupdate->execute();
332             }
333           }
334         }
335
336 // Update products_ordered (for bestsellers list)
337         $Qupdate = $osC_Database->query('update :table_products set products_ordered = products_ordered + :products_ordered where products_id = :products_id');
338         $Qupdate->bindTable(':table_products', TABLE_PRODUCTS);
339         $Qupdate->bindInt(':products_ordered', $Qproducts->valueInt('products_quantity'));
340         $Qupdate->bindInt(':products_id', $Qproducts->valueInt('products_id'));
341         $Qupdate->execute();
342       }
343
344       osC_Order::sendEmail($order_id);
345
346       unset($_SESSION['prepOrderID']);
347     }
348
349     function sendEmail($id) {
350       global $osC_Database, $osC_Language, $osC_Currencies;
351
352       $Qorder = $osC_Database->query('select * from :table_orders where orders_id = :orders_id limit 1');
353       $Qorder->bindTable(':table_orders', TABLE_ORDERS);
354       $Qorder->bindInt(':orders_id', $id);
355       $Qorder->execute();
356
357       if ($Qorder->numberOfRows() === 1) {
358         $email_order = STORE_NAME . "\n" .
359                        $osC_Language->get('email_order_separator') . "\n" .
360                        sprintf($osC_Language->get('email_order_order_number'), $id) . "\n" .
hpdl
754
361                        sprintf($osC_Language->get('email_order_invoice_url'), osc_href_link(FILENAME_ACCOUNT, 'orders=' . $id, 'SSL', false, true, true)) . "\n" .
hpdl
554
362                        sprintf($osC_Language->get('email_order_date_ordered'), osC_DateTime::getLong()) . "\n\n" .
363                        $osC_Language->get('email_order_products') . "\n" .
364                        $osC_Language->get('email_order_separator') . "\n";
365
366         $Qproducts = $osC_Database->query('select orders_products_id, products_model, products_name, final_price, products_tax, products_quantity from :table_orders_products where orders_id = :orders_id order by orders_products_id');
367         $Qproducts->bindTable(':table_orders_products', TABLE_ORDERS_PRODUCTS);
368         $Qproducts->bindInt(':orders_id', $id);
369         $Qproducts->execute();
370
371         while ($Qproducts->next()) {
372           $email_order .= $Qproducts->valueInt('products_quantity') . ' x ' . $Qproducts->value('products_name') . ' (' . $Qproducts->value('products_model') . ') = ' . $osC_Currencies->displayPriceWithTaxRate($Qproducts->value('final_price'), $Qproducts->value('products_tax'), $Qproducts->valueInt('products_quantity'), $Qorder->value('currency'), $Qorder->value('currency_value')) . "\n";
373
374           $Qattributes = $osC_Database->query('select products_options, products_options_values from :table_orders_products_attributes where orders_id = :orders_id and orders_products_id = :orders_products_id order by orders_products_attributes_id');
375           $Qattributes->bindTable(':table_orders_products_attributes', TABLE_ORDERS_PRODUCTS_ATTRIBUTES);
376           $Qattributes->bindInt(':orders_id', $id);
377           $Qattributes->bindInt(':orders_products_id', $Qproducts->valueInt('orders_products_id'));
378           $Qattributes->execute();
379
380           while ($Qattributes->next()) {
381             $email_order .= "\t" . $Qattributes->value('products_options') . ': ' . $Qattributes->value('products_options_values') . "\n";
382           }
383         }
384
385         unset($Qproducts);
386         unset($Qattributes);
387
388         $email_order .= $osC_Language->get('email_order_separator') . "\n";
389
390         $Qtotals = $osC_Database->query('select title, text from :table_orders_total where orders_id = :orders_id order by sort_order');
391         $Qtotals->bindTable(':table_orders_total', TABLE_ORDERS_TOTAL);
392         $Qtotals->bindInt(':orders_id', $id);
393         $Qtotals->execute();
394
395         while ($Qtotals->next()) {
396           $email_order .= strip_tags($Qtotals->value('title') . ' ' . $Qtotals->value('text')) . "\n";
397         }
398
399         unset($Qtotals);
400
401         if ( (osc_empty($Qorder->value('delivery_name') === false)) && (osc_empty($Qorder->value('street_address') === false)) ) {
402           $address = array('name' => $Qorder->value('delivery_name'),
403                            'company' => $Qorder->value('delivery_company'),
404                            'street_address' => $Qorder->value('delivery_street_address'),
405                            'suburb' => $Qorder->value('delivery_suburb'),
406                            'city' => $Qorder->value('delivery_city'),
407                            'state' => $Qorder->value('delivery_state'),
hpdl
928
408                            'zone_code' => $Qorder->value('delivery_state_code'),
409                            'country_title' => $Qorder->value('delivery_country'),
410                            'country_iso2' => $Qorder->value('delivery_country_iso2'),
411                            'country_iso3' => $Qorder->value('delivery_country_iso3'),
hpdl
554
412                            'postcode' => $Qorder->value('delivery_postcode'));
413
414           $email_order .= "\n" . $osC_Language->get('email_order_delivery_address') . "\n" .
415                           $osC_Language->get('email_order_separator') . "\n" .
hpdl
757
416                           osC_Address::format($address, "\n") . "\n";
hpdl
554
417
418           unset($address);
419         }
420
421         $address = array('name' => $Qorder->value('billing_name'),
422                          'company' => $Qorder->value('billing_company'),
423                          'street_address' => $Qorder->value('billing_street_address'),
424                          'suburb' => $Qorder->value('billing_suburb'),
425                          'city' => $Qorder->value('billing_city'),
426                          'state' => $Qorder->value('billing_state'),
hpdl
928
427                          'zone_code' => $Qorder->value('billing_state_code'),
428                          'country_title' => $Qorder->value('billing_country'),
429                          'country_iso2' => $Qorder->value('billing_country_iso2'),
430                          'country_iso3' => $Qorder->value('billing_country_iso3'),
hpdl
554
431                          'postcode' => $Qorder->value('billing_postcode'));
432
433         $email_order .= "\n" . $osC_Language->get('email_order_billing_address') . "\n" .
434                         $osC_Language->get('email_order_separator') . "\n" .
hpdl
757
435                         osC_Address::format($address, "\n") . "\n\n";
hpdl
554
436
437         unset($address);
438
439         $Qstatus = $osC_Database->query('select orders_status_name from :table_orders_status where orders_status_id = :orders_status_id and language_id = :language_id');
440         $Qstatus->bindTable(':table_orders_status', TABLE_ORDERS_STATUS);
441         $Qstatus->bindInt(':orders_status_id', $Qorder->valueInt('orders_status'));
442         $Qstatus->bindInt(':language_id', $osC_Language->getID());
443         $Qstatus->execute();
444
445         $email_order .= sprintf($osC_Language->get('email_order_status'), $Qstatus->value('orders_status_name')) . "\n" .
446                         $osC_Language->get('email_order_separator') . "\n";
447
448         unset($Qstatus);
449
450         $Qstatuses = $osC_Database->query('select date_added, comments from :table_orders_status_history where orders_id = :orders_id and comments != "" order by orders_status_history_id');
451         $Qstatuses->bindTable(':table_orders_status_history', TABLE_ORDERS_STATUS_HISTORY);
452         $Qstatuses->bindInt(':orders_id', $id);
453         $Qstatuses->execute();
454
455         while ($Qstatuses->next()) {
456           $email_order .= osC_DateTime::getLong($Qstatuses->value('date_added')) . "\n\t" . wordwrap(str_replace("\n", "\n\t", $Qstatuses->value('comments')), 60, "\n\t", 1) . "\n\n";
457         }
458
459         unset($Qstatuses);
460
461 //        if (is_object($GLOBALS[$payment])) {
462 //          $email_order .= $osC_Language->get('email_order_payment_method') . "\n" .
463 //                          $osC_Language->get('email_order_separator') . "\n";
464
465 //          $email_order .= $osC_ShoppingCart->getBillingMethod('title') . "\n\n";
466 //          if (isset($GLOBALS[$payment]->email_footer)) {
467 //            $email_order .= $GLOBALS[$payment]->email_footer . "\n\n";
468 //          }
469 //        }
470
hpdl
757
471         osc_email($Qorder->value('customers_name'), $Qorder->value('customers_email_address'), $osC_Language->get('email_order_subject'), $email_order, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS);
hpdl
554
472
473 // send emails to other people
474         if (SEND_EXTRA_ORDER_EMAILS_TO != '') {
hpdl
757
475           osc_email('', SEND_EXTRA_ORDER_EMAILS_TO, $osC_Language->get('email_order_subject'), $email_order, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS);
hpdl
554
476         }
477       }
478
479       unset($Qorder);
480     }
481
hpdl
368
482     function &getListing($limit = null, $page_keyword = 'page') {
hpdl
383
483       global $osC_Database, $osC_Customer, $osC_Language;
hpdl
368
484
hpdl
443
485       $Qorders = $osC_Database->query('select o.orders_id, o.date_purchased, o.delivery_name, o.delivery_country, o.billing_name, o.billing_country, ot.text as order_total, s.orders_status_name from :table_orders o, :table_orders_total ot, :table_orders_status s where o.customers_id = :customers_id and o.orders_id = ot.orders_id and ot.class = "total" and o.orders_status = s.orders_status_id and s.language_id = :language_id order by orders_id desc');
hpdl
368
486       $Qorders->bindTable(':table_orders', TABLE_ORDERS);
487       $Qorders->bindTable(':table_orders_total', TABLE_ORDERS_TOTAL);
488       $Qorders->bindTable(':table_orders_status', TABLE_ORDERS_STATUS);
489       $Qorders->bindInt(':customers_id', $osC_Customer->getID());
hpdl
383
490       $Qorders->bindInt(':language_id', $osC_Language->getID());
hpdl
368
491
492       if (is_numeric($limit)) {
493         $Qorders->setBatchLimit(isset($_GET[$page_keyword]) && is_numeric($_GET[$page_keyword]) ? $_GET[$page_keyword] : 1, $limit);
494       }
495
496       $Qorders->execute();
497
498       return $Qorders;
499     }
500
501     function &getStatusListing($id = null) {
hpdl
383
502       global $osC_Database, $osC_Language;
hpdl
368
503
504       if ( ($id === null) && isset($this) ) {
505         $id = $this->_id;
506       }
507
508       $Qstatus = $osC_Database->query('select os.orders_status_name, osh.date_added, osh.comments from :table_orders_status os, :table_orders_status_history osh where osh.orders_id = :orders_id and osh.orders_status_id = os.orders_status_id and os.language_id = :language_id order by osh.date_added');
509       $Qstatus->bindTable(':table_orders_status', TABLE_ORDERS_STATUS);
510       $Qstatus->bindTable(':table_orders_status_history', TABLE_ORDERS_STATUS_HISTORY);
511       $Qstatus->bindInt(':orders_id', $id);
hpdl
383
512       $Qstatus->bindInt(':language_id', $osC_Language->getID());
hpdl
368
513
514       return $Qstatus;
515     }
516
517     function getCustomerID($id = null) {
518       global $osC_Database;
519
520       if ( ($id === null) && isset($this) ) {
521         $id = $this->_id;
522       }
523
524       $Qcustomer = $osC_Database->query('select customers_id from :table_orders where orders_id = :orders_id');
525       $Qcustomer->bindTable(':table_orders', TABLE_ORDERS);
526       $Qcustomer->bindInt(':orders_id', $id);
527       $Qcustomer->execute();
528
529       return $Qcustomer->valueInt('customers_id');
530     }
531
532     function numberOfEntries() {
533       global $osC_Database, $osC_Customer;
534       static $total_entries;
535
536       if (is_numeric($total_entries) === false) {
537         if ($osC_Customer->isLoggedOn()) {
538           $Qorders = $osC_Database->query('select count(*) as total from :table_orders where customers_id = :customers_id');
539           $Qorders->bindTable(':table_orders', TABLE_ORDERS);
540           $Qorders->bindInt(':customers_id', $osC_Customer->getID());
541           $Qorders->execute();
542
543           $total_entries = $Qorders->valueInt('total');
544         } else {
545           $total_entries = 0;
546         }
547       }
548
549       return $total_entries;
550     }
551
552     function numberOfProducts($id = null) {
553       global $osC_Database;
554
555       if ( ($id === null) && isset($this) ) {
556         $id = $this->_id;
557       }
558
559       $Qproducts = $osC_Database->query('select count(*) as total from :table_orders_products where orders_id = :orders_id');
560       $Qproducts->bindTable(':table_orders_products', TABLE_ORDERS_PRODUCTS);
561       $Qproducts->bindInt(':orders_id', $id);
562       $Qproducts->execute();
563
564       return $Qproducts->valueInt('total');
565     }
566
hpdl
554
567     function exists($id, $customer_id = null) {
568       global $osC_Database;
hpdl
368
569
hpdl
554
570       $Qorder = $osC_Database->query('select orders_id from :table_orders where orders_id = :orders_id');
hpdl
368
571
hpdl
554
572       if (isset($customer_id) && is_numeric($customer_id)) {
573         $Qorder->appendQuery('and customers_id = :customers_id');
574         $Qorder->bindInt(':customers_id', $customer_id);
575       }
576
577       $Qorder->appendQuery('limit 1');
578       $Qorder->bindTable(':table_orders', TABLE_ORDERS);
579       $Qorder->bindInt(':orders_id', $id);
580       $Qorder->execute();
581
582       return ($Qorder->numberOfRows() === 1);
583     }
584
hpdl
1
585     function query($order_id) {
hpdl
383
586       global $osC_Database, $osC_Language;
hpdl
1
587
hpdl
757
588       $Qorder = $osC_Database->query('select * from :table_orders where orders_id = :orders_id');
hpdl
20
589       $Qorder->bindTable(':table_orders', TABLE_ORDERS);
590       $Qorder->bindInt(':orders_id', $order_id);
591       $Qorder->execute();
hpdl
1
592
hpdl
20
593       $Qtotals = $osC_Database->query('select title, text, class from :table_orders_total where orders_id = :orders_id order by sort_order');
594       $Qtotals->bindTable(':table_orders_total', TABLE_ORDERS_TOTAL);
595       $Qtotals->bindInt(':orders_id', $order_id);
596       $Qtotals->execute();
hpdl
1
597
hpdl
20
598       $shipping_method_string = '';
599       $order_total_string = '';
hpdl
1
600
hpdl
20
601       while ($Qtotals->next()) {
602         $this->totals[] = array('title' => $Qtotals->value('title'),
603                                 'text' => $Qtotals->value('text'));
hpdl
1
604
hpdl
443
605         if ($Qtotals->value('class') == 'shipping') {
hpdl
20
606           $shipping_method_string = strip_tags($Qtotals->value('title'));
hpdl
1
607
hpdl
20
608           if (substr($shipping_method_string, -1) == ':') {
609             $shipping_method_string = substr($Qtotals->value('title'), 0, -1);
610           }
611         }
hpdl
1
612
hpdl
443
613         if ($Qtotals->value('class') == 'total') {
hpdl
20
614           $order_total_string = strip_tags($Qtotals->value('text'));
615         }
616       }
hpdl
1
617
hpdl
20
618       $Qstatus = $osC_Database->query('select orders_status_name from :table_orders_status where orders_status_id = :orders_status_id and language_id = :language_id');
619       $Qstatus->bindTable(':table_orders_status', TABLE_ORDERS_STATUS);
hpdl
46
620       $Qstatus->bindInt(':orders_status_id', $Qorder->valueInt('orders_status'));
hpdl
383
621       $Qstatus->bindInt(':language_id', $osC_Language->getID());
hpdl
20
622       $Qstatus->execute();
hpdl
1
623
hpdl
20
624       $this->info = array('currency' => $Qorder->value('currency'),
625                           'currency_value' => $Qorder->value('currency_value'),
626                           'payment_method' => $Qorder->value('payment_method'),
627                           'date_purchased' => $Qorder->value('date_purchased'),
628                           'orders_status' => $Qstatus->value('orders_status_name'),
629                           'last_modified' => $Qorder->value('last_modified'),
630                           'total' => $order_total_string,
631                           'shipping_method' => $shipping_method_string);
hpdl
1
632
hpdl
20
633       $this->customer = array('id' => $Qorder->valueInt('customers_id'),
634                               'name' => $Qorder->valueProtected('customers_name'),
635                               'company' => $Qorder->valueProtected('customers_company'),
636                               'street_address' => $Qorder->valueProtected('customers_street_address'),
637                               'suburb' => $Qorder->valueProtected('customers_suburb'),
638                               'city' => $Qorder->valueProtected('customers_city'),
639                               'postcode' => $Qorder->valueProtected('customers_postcode'),
640                               'state' => $Qorder->valueProtected('customers_state'),
hpdl
926
641                               'zone_code' => $Qorder->value('customers_state_code'),
642                               'country_title' => $Qorder->valueProtected('customers_country'),
hpdl
757
643                               'country_iso2' => $Qorder->value('customers_country_iso2'),
644                               'country_iso3' => $Qorder->value('customers_country_iso3'),
645                               'format' => $Qorder->value('customers_address_format'),
hpdl
20
646                               'telephone' => $Qorder->valueProtected('customers_telephone'),
647                               'email_address' => $Qorder->valueProtected('customers_email_address'));
648
649       $this->delivery = array('name' => $Qorder->valueProtected('delivery_name'),
650                               'company' => $Qorder->valueProtected('delivery_company'),
651                               'street_address' => $Qorder->valueProtected('delivery_street_address'),
652                               'suburb' => $Qorder->valueProtected('delivery_suburb'),
653                               'city' => $Qorder->valueProtected('delivery_city'),
654                               'postcode' => $Qorder->valueProtected('delivery_postcode'),
655                               'state' => $Qorder->valueProtected('delivery_state'),
hpdl
926
656                               'zone_code' => $Qorder->value('delivery_state_code'),
657                               'country_title' => $Qorder->valueProtected('delivery_country'),
hpdl
757
658                               'country_iso2' => $Qorder->value('delivery_country_iso2'),
659                               'country_iso3' => $Qorder->value('delivery_country_iso3'),
660                               'format' => $Qorder->value('delivery_address_format'));
hpdl
20
661
hpdl
1
662       if (empty($this->delivery['name']) && empty($this->delivery['street_address'])) {
663         $this->delivery = false;
664       }
665
hpdl
20
666       $this->billing = array('name' => $Qorder->valueProtected('billing_name'),
667                              'company' => $Qorder->valueProtected('billing_company'),
668                              'street_address' => $Qorder->valueProtected('billing_street_address'),
669                              'suburb' => $Qorder->valueProtected('billing_suburb'),
670                              'city' => $Qorder->valueProtected('billing_city'),
671                              'postcode' => $Qorder->valueProtected('billing_postcode'),
672                              'state' => $Qorder->valueProtected('billing_state'),
hpdl
926
673                              'zone_code' => $Qorder->value('billing_state_code'),
674                              'country_title' => $Qorder->valueProtected('billing_country'),
hpdl
757
675                              'country_iso2' => $Qorder->value('billing_country_iso2'),
676                              'country_iso3' => $Qorder->value('billing_country_iso3'),
677                              'format' => $Qorder->value('billing_address_format'));
hpdl
1
678
hpdl
20
679       $Qproducts = $osC_Database->query('select orders_products_id, products_id, products_name, products_model, products_price, products_tax, products_quantity, final_price from :table_orders_products where orders_id = :orders_id');
680       $Qproducts->bindTable(':table_orders_products', TABLE_ORDERS_PRODUCTS);
681       $Qproducts->bindInt(':orders_id', $order_id);
682       $Qproducts->execute();
683
hpdl
1
684       $index = 0;
685
hpdl
20
686       while ($Qproducts->next()) {
hpdl
1
687         $subindex = 0;
688
hpdl
20
689         $this->products[$index] = array('qty' => $Qproducts->valueInt('products_quantity'),
690                                         'id' => $Qproducts->valueInt('products_id'),
691                                         'name' => $Qproducts->value('products_name'),
692                                         'model' => $Qproducts->value('products_model'),
693                                         'tax' => $Qproducts->value('products_tax'),
694                                         'price' => $Qproducts->value('products_price'),
695                                         'final_price' => $Qproducts->value('final_price'));
696
697         $Qattributes = $osC_Database->query('select products_options, products_options_values, options_values_price, price_prefix from :table_orders_products_attributes where orders_id = :orders_id and orders_products_id = :orders_products_id');
698         $Qattributes->bindTable(':table_orders_products_attributes', TABLE_ORDERS_PRODUCTS_ATTRIBUTES);
699         $Qattributes->bindInt(':orders_id', $order_id);
700         $Qattributes->bindInt(':orders_products_id', $Qproducts->valueInt('orders_products_id'));
701         $Qattributes->execute();
702
703         if ($Qattributes->numberOfRows()) {
704           while ($Qattributes->next()) {
705             $this->products[$index]['attributes'][$subindex] = array('option' => $Qattributes->value('products_options'),
706                                                                      'value' => $Qattributes->value('products_options_values'),
707                                                                      'prefix' => $Qattributes->value('price_prefix'),
708                                                                      'price' => $Qattributes->value('options_values_price'));
709
hpdl
1
710             $subindex++;
711           }
712         }
713
714         $this->info['tax_groups']["{$this->products[$index]['tax']}"] = '1';
715
716         $index++;
717       }
718     }
719   }
720 ?>