Quick Search:

View

Revision:

Diff

Diff from 1443 to:

Annotations

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

Annotated File View

hpdl
1
1 <?php
2 /*
hpdl
20
3   $Id: order.php 1443 2007-03-08 22:20:43Z hpdl $
hpdl
1
4
5   osCommerce, Open Source E-Commerce Solutions
6   http://www.oscommerce.com
7
hpdl
521
8   Copyright (c) 2006 osCommerce
hpdl
1
9
10   Released under the GNU General Public License
11 */
12
hpdl
521
13   class osC_Order {
hpdl
1
14     var $info, $totals, $products, $customer, $delivery, $content_type;
15
hpdl
183
16 /* Private variables */
17
18     var $_id;
19
20 /* Class constructor */
21
hpdl
521
22     function osC_Order($order_id = '') {
hpdl
183
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
734
33       if (!empty($order_id)) {
hpdl
1
34         $this->query($order_id);
35       } else {
36         $this->cart();
37       }
38     }
39
hpdl
183
40 /* Public methods */
41
hpdl
521
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
1059
72         $Qdel->bindTable(':table_orders_products_attributes', TABLE_ORDERS_PRODUCTS_ATTRIBUTES);
hpdl
521
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       }
hpdl
531
96
97       if (isset($_SESSION['prepOrderID'])) {
98         unset($_SESSION['prepOrderID']);
99       }
hpdl
521
100     }
101
102     function insert() {
103       global $osC_Database, $osC_Customer, $osC_Language, $osC_Currencies, $osC_ShoppingCart;
104
hpdl
531
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
732
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
521
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
732
127       $Qorder->bindValue(':customers_state_code', '');
hpdl
521
128       $Qorder->bindValue(':customers_country', '' /*$order->customer['country']['title']*/);
hpdl
732
129       $Qorder->bindValue(':customers_country_iso2', '');
130       $Qorder->bindValue(':customers_country_iso3', '');
hpdl
521
131       $Qorder->bindValue(':customers_telephone', '' /*$order->customer['telephone']*/);
132       $Qorder->bindValue(':customers_email_address', $osC_Customer->getEmailAddress());
hpdl
732
133       $Qorder->bindValue(':customers_address_format', '');
hpdl
733
134       $Qorder->bindValue(':customers_ip_address', osc_get_ip_address());
hpdl
521
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
732
142       $Qorder->bindValue(':delivery_state_code', $osC_ShoppingCart->getShippingAddress('zone_code'));
hpdl
521
143       $Qorder->bindValue(':delivery_country', $osC_ShoppingCart->getShippingAddress('country_title'));
hpdl
732
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
521
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
732
154       $Qorder->bindValue(':billing_state_code', $osC_ShoppingCart->getBillingAddress('zone_code'));
hpdl
545
155       $Qorder->bindValue(':billing_country', $osC_ShoppingCart->getBillingAddress('country_title'));
hpdl
732
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
521
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
734
192         $Qproducts->bindInt(':products_id', osc_get_product_id($products['id']));
hpdl
521
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'])) {
hpdl
548
204           foreach ($osC_ShoppingCart->getAttributes($products['id']) as $attributes) {
hpdl
521
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
hpdl
531
253       $_SESSION['prepOrderID'] = $osC_ShoppingCart->getCartID() . '-' . $insert_id;
254
hpdl
521
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       }
hpdl
531
343
hpdl
538
344       osC_Order::sendEmail($order_id);
345
hpdl
531
346       unset($_SESSION['prepOrderID']);
hpdl
521
347     }
348
hpdl
538
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
686
361                        sprintf($osC_Language->get('email_order_invoice_url'), osc_href_link(FILENAME_ACCOUNT, 'orders=' . $id, 'SSL', false, true, true)) . "\n" .
hpdl
548
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";
hpdl
538
365
hpdl
548
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');
hpdl
538
367         $Qproducts->bindTable(':table_orders_products', TABLE_ORDERS_PRODUCTS);
368         $Qproducts->bindInt(':orders_id', $id);
369         $Qproducts->execute();
370
hpdl
548
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";
hpdl
538
373
hpdl
548
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           }
hpdl
538
383         }
384
hpdl
545
385         unset($Qproducts);
hpdl
548
386         unset($Qattributes);
hpdl
545
387
hpdl
548
388         $email_order .= $osC_Language->get('email_order_separator') . "\n";
hpdl
538
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
hpdl
545
399         unset($Qtotals);
hpdl
538
400
hpdl
545
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
927
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
1443
412                            'postcode' => $Qorder->value('delivery_postcode'),
413                            'format' => $Qorder->value('delivery_address_format'));
hpdl
538
414
hpdl
545
415           $email_order .= "\n" . $osC_Language->get('email_order_delivery_address') . "\n" .
416                           $osC_Language->get('email_order_separator') . "\n" .
hpdl
732
417                           osC_Address::format($address, "\n") . "\n";
hpdl
545
418
419           unset($address);
420         }
421
422         $address = array('name' => $Qorder->value('billing_name'),
423                          'company' => $Qorder->value('billing_company'),
424                          'street_address' => $Qorder->value('billing_street_address'),
425                          'suburb' => $Qorder->value('billing_suburb'),
426                          'city' => $Qorder->value('billing_city'),
427                          'state' => $Qorder->value('billing_state'),
hpdl
927
428                          'zone_code' => $Qorder->value('billing_state_code'),
429                          'country_title' => $Qorder->value('billing_country'),
430                          'country_iso2' => $Qorder->value('billing_country_iso2'),
431                          'country_iso3' => $Qorder->value('billing_country_iso3'),
hpdl
1443
432                          'postcode' => $Qorder->value('billing_postcode'),
433                          'format' => $Qorder->value('billing_address_format'));
hpdl
545
434
435         $email_order .= "\n" . $osC_Language->get('email_order_billing_address') . "\n" .
436                         $osC_Language->get('email_order_separator') . "\n" .
hpdl
732
437                         osC_Address::format($address, "\n") . "\n\n";
hpdl
545
438
439         unset($address);
440
441         $Qstatus = $osC_Database->query('select orders_status_name from :table_orders_status where orders_status_id = :orders_status_id and language_id = :language_id');
442         $Qstatus->bindTable(':table_orders_status', TABLE_ORDERS_STATUS);
443         $Qstatus->bindInt(':orders_status_id', $Qorder->valueInt('orders_status'));
444         $Qstatus->bindInt(':language_id', $osC_Language->getID());
445         $Qstatus->execute();
446
447         $email_order .= sprintf($osC_Language->get('email_order_status'), $Qstatus->value('orders_status_name')) . "\n" .
448                         $osC_Language->get('email_order_separator') . "\n";
449
450         unset($Qstatus);
451
452         $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');
453         $Qstatuses->bindTable(':table_orders_status_history', TABLE_ORDERS_STATUS_HISTORY);
454         $Qstatuses->bindInt(':orders_id', $id);
455         $Qstatuses->execute();
456
457         while ($Qstatuses->next()) {
hpdl
546
458           $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";
hpdl
545
459         }
460
461         unset($Qstatuses);
462
hpdl
538
463 //        if (is_object($GLOBALS[$payment])) {
464 //          $email_order .= $osC_Language->get('email_order_payment_method') . "\n" .
465 //                          $osC_Language->get('email_order_separator') . "\n";
466
467 //          $email_order .= $osC_ShoppingCart->getBillingMethod('title') . "\n\n";
468 //          if (isset($GLOBALS[$payment]->email_footer)) {
469 //            $email_order .= $GLOBALS[$payment]->email_footer . "\n\n";
470 //          }
471 //        }
472
hpdl
734
473         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
538
474
475 // send emails to other people
476         if (SEND_EXTRA_ORDER_EMAILS_TO != '') {
hpdl
734
477           osc_email('', SEND_EXTRA_ORDER_EMAILS_TO, $osC_Language->get('email_order_subject'), $email_order, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS);
hpdl
538
478         }
479       }
hpdl
545
480
481       unset($Qorder);
hpdl
538
482     }
483
hpdl
183
484     function &getListing($limit = null, $page_keyword = 'page') {
hpdl
377
485       global $osC_Database, $osC_Customer, $osC_Language;
hpdl
183
486
hpdl
431
487       $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
183
488       $Qorders->bindTable(':table_orders', TABLE_ORDERS);
489       $Qorders->bindTable(':table_orders_total', TABLE_ORDERS_TOTAL);
490       $Qorders->bindTable(':table_orders_status', TABLE_ORDERS_STATUS);
hpdl
184
491       $Qorders->bindInt(':customers_id', $osC_Customer->getID());
hpdl
377
492       $Qorders->bindInt(':language_id', $osC_Language->getID());
hpdl
183
493
494       if (is_numeric($limit)) {
495         $Qorders->setBatchLimit(isset($_GET[$page_keyword]) && is_numeric($_GET[$page_keyword]) ? $_GET[$page_keyword] : 1, $limit);
496       }
497
498       $Qorders->execute();
499
500       return $Qorders;
501     }
502
503     function &getStatusListing($id = null) {
hpdl
377
504       global $osC_Database, $osC_Language;
hpdl
183
505
506       if ( ($id === null) && isset($this) ) {
507         $id = $this->_id;
508       }
509
510       $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');
511       $Qstatus->bindTable(':table_orders_status', TABLE_ORDERS_STATUS);
512       $Qstatus->bindTable(':table_orders_status_history', TABLE_ORDERS_STATUS_HISTORY);
513       $Qstatus->bindInt(':orders_id', $id);
hpdl
377
514       $Qstatus->bindInt(':language_id', $osC_Language->getID());
hpdl
183
515
516       return $Qstatus;
517     }
518
519     function getCustomerID($id = null) {
520       global $osC_Database;
521
522       if ( ($id === null) && isset($this) ) {
523         $id = $this->_id;
524       }
525
526       $Qcustomer = $osC_Database->query('select customers_id from :table_orders where orders_id = :orders_id');
527       $Qcustomer->bindTable(':table_orders', TABLE_ORDERS);
528       $Qcustomer->bindInt(':orders_id', $id);
529       $Qcustomer->execute();
530
531       return $Qcustomer->valueInt('customers_id');
532     }
533
534     function numberOfEntries() {
535       global $osC_Database, $osC_Customer;
536       static $total_entries;
537
538       if (is_numeric($total_entries) === false) {
539         if ($osC_Customer->isLoggedOn()) {
540           $Qorders = $osC_Database->query('select count(*) as total from :table_orders where customers_id = :customers_id');
541           $Qorders->bindTable(':table_orders', TABLE_ORDERS);
hpdl
184
542           $Qorders->bindInt(':customers_id', $osC_Customer->getID());
hpdl
183
543           $Qorders->execute();
544
545           $total_entries = $Qorders->valueInt('total');
546         } else {
547           $total_entries = 0;
548         }
549       }
550
551       return $total_entries;
552     }
553
554     function numberOfProducts($id = null) {
555       global $osC_Database;
556
557       if ( ($id === null) && isset($this) ) {
558         $id = $this->_id;
559       }
560
561       $Qproducts = $osC_Database->query('select count(*) as total from :table_orders_products where orders_id = :orders_id');
562       $Qproducts->bindTable(':table_orders_products', TABLE_ORDERS_PRODUCTS);
563       $Qproducts->bindInt(':orders_id', $id);
564       $Qproducts->execute();
565
566       return $Qproducts->valueInt('total');
567     }
568
hpdl
538
569     function exists($id, $customer_id = null) {
570       global $osC_Database;
hpdl
183
571
hpdl
538
572       $Qorder = $osC_Database->query('select orders_id from :table_orders where orders_id = :orders_id');
hpdl
183
573
hpdl
538
574       if (isset($customer_id) && is_numeric($customer_id)) {
575         $Qorder->appendQuery('and customers_id = :customers_id');
576         $Qorder->bindInt(':customers_id', $customer_id);
577       }
578
579       $Qorder->appendQuery('limit 1');
580       $Qorder->bindTable(':table_orders', TABLE_ORDERS);
581       $Qorder->bindInt(':orders_id', $id);
582       $Qorder->execute();
583
584       return ($Qorder->numberOfRows() === 1);
585     }
586
hpdl
1
587     function query($order_id) {
hpdl
377
588       global $osC_Database, $osC_Language;
hpdl
1
589
hpdl
732
590       $Qorder = $osC_Database->query('select * from :table_orders where orders_id = :orders_id');
hpdl
20
591       $Qorder->bindTable(':table_orders', TABLE_ORDERS);
592       $Qorder->bindInt(':orders_id', $order_id);
593       $Qorder->execute();
hpdl
1
594
hpdl
20
595       $Qtotals = $osC_Database->query('select title, text, class from :table_orders_total where orders_id = :orders_id order by sort_order');
596       $Qtotals->bindTable(':table_orders_total', TABLE_ORDERS_TOTAL);
597       $Qtotals->bindInt(':orders_id', $order_id);
598       $Qtotals->execute();
hpdl
1
599
hpdl
20
600       $shipping_method_string = '';
601       $order_total_string = '';
hpdl
1
602
hpdl
20
603       while ($Qtotals->next()) {
604         $this->totals[] = array('title' => $Qtotals->value('title'),
605                                 'text' => $Qtotals->value('text'));
hpdl
1
606
hpdl
431
607         if ($Qtotals->value('class') == 'shipping') {
hpdl
20
608           $shipping_method_string = strip_tags($Qtotals->value('title'));
hpdl
1
609
hpdl
20
610           if (substr($shipping_method_string, -1) == ':') {
611             $shipping_method_string = substr($Qtotals->value('title'), 0, -1);
612           }
613         }
hpdl
1
614
hpdl
431
615         if ($Qtotals->value('class') == 'total') {
hpdl
20
616           $order_total_string = strip_tags($Qtotals->value('text'));
617         }
618       }
hpdl
1
619
hpdl
20
620       $Qstatus = $osC_Database->query('select orders_status_name from :table_orders_status where orders_status_id = :orders_status_id and language_id = :language_id');
621       $Qstatus->bindTable(':table_orders_status', TABLE_ORDERS_STATUS);
hpdl
45
622       $Qstatus->bindInt(':orders_status_id', $Qorder->valueInt('orders_status'));
hpdl
377
623       $Qstatus->bindInt(':language_id', $osC_Language->getID());
hpdl
20
624       $Qstatus->execute();
hpdl
1
625
hpdl
20
626       $this->info = array('currency' => $Qorder->value('currency'),
627                           'currency_value' => $Qorder->value('currency_value'),
628                           'payment_method' => $Qorder->value('payment_method'),
629                           'date_purchased' => $Qorder->value('date_purchased'),
630                           'orders_status' => $Qstatus->value('orders_status_name'),
631                           'last_modified' => $Qorder->value('last_modified'),
632                           'total' => $order_total_string,
633                           'shipping_method' => $shipping_method_string);
hpdl
1
634
hpdl
20
635       $this->customer = array('id' => $Qorder->valueInt('customers_id'),
636                               'name' => $Qorder->valueProtected('customers_name'),
637                               'company' => $Qorder->valueProtected('customers_company'),
638                               'street_address' => $Qorder->valueProtected('customers_street_address'),
639                               'suburb' => $Qorder->valueProtected('customers_suburb'),
640                               'city' => $Qorder->valueProtected('customers_city'),
641                               'postcode' => $Qorder->valueProtected('customers_postcode'),
642                               'state' => $Qorder->valueProtected('customers_state'),
hpdl
925
643                               'zone_code' => $Qorder->value('customers_state_code'),
644                               'country_title' => $Qorder->valueProtected('customers_country'),
hpdl
732
645                               'country_iso2' => $Qorder->value('customers_country_iso2'),
646                               'country_iso3' => $Qorder->value('customers_country_iso3'),
647                               'format' => $Qorder->value('customers_address_format'),
hpdl
20
648                               'telephone' => $Qorder->valueProtected('customers_telephone'),
649                               'email_address' => $Qorder->valueProtected('customers_email_address'));
650
651       $this->delivery = array('name' => $Qorder->valueProtected('delivery_name'),
652                               'company' => $Qorder->valueProtected('delivery_company'),
653                               'street_address' => $Qorder->valueProtected('delivery_street_address'),
654                               'suburb' => $Qorder->valueProtected('delivery_suburb'),
655                               'city' => $Qorder->valueProtected('delivery_city'),
656                               'postcode' => $Qorder->valueProtected('delivery_postcode'),
657                               'state' => $Qorder->valueProtected('delivery_state'),
hpdl
925
658                               'zone_code' => $Qorder->value('delivery_state_code'),
659                               'country_title' => $Qorder->valueProtected('delivery_country'),
hpdl
732
660                               'country_iso2' => $Qorder->value('delivery_country_iso2'),
661                               'country_iso3' => $Qorder->value('delivery_country_iso3'),
662                               'format' => $Qorder->value('delivery_address_format'));
hpdl
20
663
hpdl
1
664       if (empty($this->delivery['name']) && empty($this->delivery['street_address'])) {
665         $this->delivery = false;
666       }
667
hpdl
20
668       $this->billing = array('name' => $Qorder->valueProtected('billing_name'),
669                              'company' => $Qorder->valueProtected('billing_company'),
670                              'street_address' => $Qorder->valueProtected('billing_street_address'),
671                              'suburb' => $Qorder->valueProtected('billing_suburb'),
672                              'city' => $Qorder->valueProtected('billing_city'),
673                              'postcode' => $Qorder->valueProtected('billing_postcode'),
674                              'state' => $Qorder->valueProtected('billing_state'),
hpdl
925
675                              'zone_code' => $Qorder->value('billing_state_code'),
676                              'country_title' => $Qorder->valueProtected('billing_country'),
hpdl
732
677                              'country_iso2' => $Qorder->value('billing_country_iso2'),
678                              'country_iso3' => $Qorder->value('billing_country_iso3'),
679                              'format' => $Qorder->value('billing_address_format'));
hpdl
1
680
hpdl
20
681       $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');
682       $Qproducts->bindTable(':table_orders_products', TABLE_ORDERS_PRODUCTS);
683       $Qproducts->bindInt(':orders_id', $order_id);
684       $Qproducts->execute();
685
hpdl
1
686       $index = 0;
687
hpdl
20
688       while ($Qproducts->next()) {
hpdl
1
689         $subindex = 0;
690
hpdl
20
691         $this->products[$index] = array('qty' => $Qproducts->valueInt('products_quantity'),
692                                         'id' => $Qproducts->valueInt('products_id'),
693                                         'name' => $Qproducts->value('products_name'),
694                                         'model' => $Qproducts->value('products_model'),
695                                         'tax' => $Qproducts->value('products_tax'),
696                                         'price' => $Qproducts->value('products_price'),
697                                         'final_price' => $Qproducts->value('final_price'));
698
699         $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');
700         $Qattributes->bindTable(':table_orders_products_attributes', TABLE_ORDERS_PRODUCTS_ATTRIBUTES);
701         $Qattributes->bindInt(':orders_id', $order_id);
702         $Qattributes->bindInt(':orders_products_id', $Qproducts->valueInt('orders_products_id'));
703         $Qattributes->execute();
704
705         if ($Qattributes->numberOfRows()) {
706           while ($Qattributes->next()) {
707             $this->products[$index]['attributes'][$subindex] = array('option' => $Qattributes->value('products_options'),
708                                                                      'value' => $Qattributes->value('products_options_values'),
709                                                                      'prefix' => $Qattributes->value('price_prefix'),
710                                                                      'price' => $Qattributes->value('options_values_price'));
711
hpdl
1
712             $subindex++;
713           }
714         }
715
716         $this->info['tax_groups']["{$this->products[$index]['tax']}"] = '1';
717
718         $index++;
719       }
720     }
721   }
722 ?>