Quick Search:

View

Revision:

Diff

Diff from 545 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 545 2006-04-28 14:04:49Z 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
33       if (tep_not_null($order_id)) {
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');
72         $Qdel->bindTable(':table_orders_products_aattributes', TABLE_ORDERS_PRODUCTS_ATTRIBUTES);
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
521
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_country, customers_telephone, customers_email_address, customers_address_format_id, customers_ip_address, delivery_name, delivery_company, delivery_street_address, delivery_suburb, delivery_city, delivery_postcode, delivery_state, delivery_country, delivery_address_format_id, billing_name, billing_company, billing_street_address, billing_suburb, billing_city, billing_postcode, billing_state, billing_country, billing_address_format_id, payment_method, payment_module, cc_type, cc_owner, cc_number, cc_expires, 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_country, :customers_telephone, :customers_email_address, :customers_address_format_id, :customers_ip_address, :delivery_name, :delivery_company, :delivery_street_address, :delivery_suburb, :delivery_city, :delivery_postcode, :delivery_state, :delivery_country, :delivery_address_format_id, :billing_name, :billing_company, :billing_street_address, :billing_suburb, :billing_city, :billing_postcode, :billing_state, :billing_country, :billing_address_format_id, :payment_method, :payment_module, :cc_type, :cc_owner, :cc_number, :cc_expires, now(), :orders_status, :currency, :currency_value)');
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']*/);
127       $Qorder->bindValue(':customers_country', '' /*$order->customer['country']['title']*/);
128       $Qorder->bindValue(':customers_telephone', '' /*$order->customer['telephone']*/);
129       $Qorder->bindValue(':customers_email_address', $osC_Customer->getEmailAddress());
130       $Qorder->bindInt(':customers_address_format_id', $osC_Customer->getDefaultAddressID());
131       $Qorder->bindValue(':customers_ip_address', tep_get_ip_address());
132       $Qorder->bindValue(':delivery_name', $osC_ShoppingCart->getShippingAddress('firstname') . ' ' . $osC_ShoppingCart->getShippingAddress('lastname'));
133       $Qorder->bindValue(':delivery_company', $osC_ShoppingCart->getShippingAddress('company'));
134       $Qorder->bindValue(':delivery_street_address', $osC_ShoppingCart->getShippingAddress('street_address'));
135       $Qorder->bindValue(':delivery_suburb', $osC_ShoppingCart->getShippingAddress('suburb'));
136       $Qorder->bindValue(':delivery_city', $osC_ShoppingCart->getShippingAddress('city'));
137       $Qorder->bindValue(':delivery_postcode', $osC_ShoppingCart->getShippingAddress('postcode'));
138       $Qorder->bindValue(':delivery_state', $osC_ShoppingCart->getShippingAddress('state'));
139       $Qorder->bindValue(':delivery_country', $osC_ShoppingCart->getShippingAddress('country_title'));
140       $Qorder->bindInt(':delivery_address_format_id', $osC_ShoppingCart->getShippingAddress('format_id'));
141       $Qorder->bindValue(':billing_name', $osC_ShoppingCart->getBillingAddress('firstname') . ' ' . $osC_ShoppingCart->getBillingAddress('lastname'));
142       $Qorder->bindValue(':billing_company', $osC_ShoppingCart->getBillingAddress('company'));
143       $Qorder->bindValue(':billing_street_address', $osC_ShoppingCart->getBillingAddress('street_address'));
144       $Qorder->bindValue(':billing_suburb', $osC_ShoppingCart->getBillingAddress('suburb'));
145       $Qorder->bindValue(':billing_city', $osC_ShoppingCart->getBillingAddress('city'));
146       $Qorder->bindValue(':billing_postcode', $osC_ShoppingCart->getBillingAddress('postcode'));
147       $Qorder->bindValue(':billing_state', $osC_ShoppingCart->getBillingAddress('state'));
hpdl
545
148       $Qorder->bindValue(':billing_country', $osC_ShoppingCart->getBillingAddress('country_title'));
hpdl
521
149       $Qorder->bindInt(':billing_address_format_id', $osC_ShoppingCart->getBillingAddress('format_id'));
150       $Qorder->bindValue(':payment_method', $osC_ShoppingCart->getBillingMethod('title'));
151       $Qorder->bindValue(':payment_module', $GLOBALS['osC_Payment_' . $osC_ShoppingCart->getBillingMethod('id')]->getCode());
152       $Qorder->bindValue(':cc_type', '' /*$order->info['cc_type']*/);
153       $Qorder->bindValue(':cc_owner', '' /*$order->info['cc_owner']*/);
154       $Qorder->bindValue(':cc_number', '' /*$order->info['cc_number']*/);
155       $Qorder->bindValue(':cc_expires', '' /*$order->info['cc_expires']*/);
156       $Qorder->bindInt(':orders_status', 4);
157       $Qorder->bindValue(':currency', $osC_Currencies->getCode());
158       $Qorder->bindValue(':currency_value', $osC_Currencies->value($osC_Currencies->getCode()));
159       $Qorder->execute();
160
161       $insert_id = $osC_Database->nextID();
162
163       foreach ($osC_ShoppingCart->getOrderTotals() as $module) {
164         $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)');
165         $Qtotals->bindTable(':table_orders_total', TABLE_ORDERS_TOTAL);
166         $Qtotals->bindInt(':orders_id', $insert_id);
167         $Qtotals->bindValue(':title', $module['title']);
168         $Qtotals->bindValue(':text', $module['text']);
169         $Qtotals->bindValue(':value', $module['value']);
170         $Qtotals->bindValue(':class', $module['code']);
171         $Qtotals->bindInt(':sort_order', $module['sort_order']);
172         $Qtotals->execute();
173       }
174
175       $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)');
176       $Qstatus->bindTable(':table_orders_status_history', TABLE_ORDERS_STATUS_HISTORY);
177       $Qstatus->bindInt(':orders_id', $insert_id);
178       $Qstatus->bindInt(':orders_status_id', 4);
179       $Qstatus->bindInt(':customer_notified', '0');
180       $Qstatus->bindValue(':comments', (isset($_SESSION['comments']) ? $_SESSION['comments'] : ''));
181       $Qstatus->execute();
182
183       foreach ($osC_ShoppingCart->getProducts() as $products) {
184         $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)');
185         $Qproducts->bindTable(':table_orders_products', TABLE_ORDERS_PRODUCTS);
186         $Qproducts->bindInt(':orders_id', $insert_id);
187         $Qproducts->bindInt(':products_id', tep_get_prid($products['id']));
188         $Qproducts->bindValue(':products_model', '' /*$products['model']*/);
189         $Qproducts->bindValue(':products_name', $products['name']);
190         $Qproducts->bindValue(':products_price', $products['price']);
191         $Qproducts->bindValue(':final_price', $products['final_price']);
192         $Qproducts->bindValue(':products_tax', '' /*$products['tax']*/);
193         $Qproducts->bindInt(':products_quantity', $products['quantity']);
194         $Qproducts->execute();
195
196         $order_products_id = $osC_Database->nextID();
197
198         if ($osC_ShoppingCart->hasAttributes($products['id'])) {
199           foreach ($osC_ShoppingCart->getAttributes($products['id']) as $atttributes) {
200             if (DOWNLOAD_ENABLED == '1') {
201               $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');
202               $Qattributes->bindTable(':table_products_options', TABLE_PRODUCTS_OPTIONS);
203               $Qattributes->bindTable(':table_products_options_values', TABLE_PRODUCTS_OPTIONS_VALUES);
204               $Qattributes->bindTable(':table_products_attributes', TABLE_PRODUCTS_ATTRIBUTES);
205               $Qattributes->bindTable(':table_products_attributes_download', TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD);
206               $Qattributes->bindInt(':products_id', $products['id']);
207               $Qattributes->bindInt(':options_id', $attributes['options_id']);
208               $Qattributes->bindInt(':options_values_id', $attributes['options_values_id']);
209               $Qattributes->bindInt(':popt_language_id', $osC_Language->getID());
210               $Qattributes->bindInt(':poval_language_id', $osC_Language->getID());
211             } else {
212               $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');
213               $Qattributes->bindTable(':table_products_options', TABLE_PRODUCTS_OPTIONS);
214               $Qattributes->bindTable(':table_products_options_values', TABLE_PRODUCTS_OPTIONS_VALUES);
215               $Qattributes->bindTable(':table_products_attributes', TABLE_PRODUCTS_ATTRIBUTES);
216               $Qattributes->bindInt(':products_id', $products['id']);
217               $Qattributes->bindInt(':options_id', $attributes['options_id']);
218               $Qattributes->bindInt(':options_values_id', $attributes['options_values_id']);
219               $Qattributes->bindInt(':popt_language_id', $osC_Language->getID());
220               $Qattributes->bindInt(':poval_language_id', $osC_Language->getID());
221             }
222             $Qattributes->execute();
223
224             $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)');
225             $Qopa->bindTable(':table_orders_products_attributes', TABLE_ORDERS_PRODUCTS_ATTRIBUTES);
226             $Qopa->bindInt(':orders_id', $insert_id);
227             $Qopa->bindInt(':orders_products_id', $order_products_id);
228             $Qopa->bindValue(':products_options', $Qattributes->value('products_options_name'));
229             $Qopa->bindValue(':products_options_values', $Qattributes->value('products_options_values_name'));
230             $Qopa->bindValue(':options_values_price', $Qattributes->value('options_values_price'));
231             $Qopa->bindValue(':price_prefix', $Qattributes->value('price_prefix'));
232             $Qopa->execute();
233
234             if ((DOWNLOAD_ENABLED == '1') && (strlen($Qattributes->value('products_attributes_filename')) > 0)) {
235               $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)');
236               $Qopd->bindTable(':table_orders_products_download', TABLE_ORDERS_PRODUCTS_DOWNLOAD);
237               $Qopd->bindInt(':orders_id', $insert_id);
238               $Qopd->bindInt(':orders_products_id', $order_products_id);
239               $Qopd->bindValue(':orders_products_filename', $Qattributes->value('products_attributes_filename'));
240               $Qopd->bindValue(':download_maxdays', $Qattributes->value('products_attributes_maxdays'));
241               $Qopd->bindValue(':download_count', $Qattributes->value('products_attributes_maxcount'));
242               $Qopd->execute();
243             }
244           }
245         }
246       }
247
hpdl
531
248       $_SESSION['prepOrderID'] = $osC_ShoppingCart->getCartID() . '-' . $insert_id;
249
hpdl
521
250       return $insert_id;
251     }
252
253     function process($order_id, $status_id = '') {
254       global $osC_Database;
255
256       if (empty($status_id) || (is_numeric($status_id) === false)) {
257         $status_id = DEFAULT_ORDERS_STATUS_ID;
258       }
259
260       $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)');
261       $Qstatus->bindTable(':table_orders_status_history', TABLE_ORDERS_STATUS_HISTORY);
262       $Qstatus->bindInt(':orders_id', $order_id);
263       $Qstatus->bindInt(':orders_status_id', $status_id);
264       $Qstatus->bindInt(':customer_notified', (SEND_EMAILS == '1') ? '1' : '0');
265       $Qstatus->bindValue(':comments', '');
266       $Qstatus->execute();
267
268       $Qupdate = $osC_Database->query('update :table_orders set orders_status = :orders_status where orders_id = :orders_id');
269       $Qupdate->bindTable(':table_orders', TABLE_ORDERS);
270       $Qupdate->bindInt(':orders_status', $status_id);
271       $Qupdate->bindInt(':orders_id', $order_id);
272       $Qupdate->execute();
273
274       $Qproducts = $osC_Database->query('select products_id, products_quantity from :table_orders_products where orders_id = :orders_id');
275       $Qproducts->bindTable(':table_orders_products', TABLE_ORDERS_PRODUCTS);
276       $Qproducts->bindInt(':orders_id', $order_id);
277       $Qproducts->execute();
278
279       while ($Qproducts->next()) {
280         if (STOCK_LIMITED == '1') {
281
282 /********** HPDL ; still uses logic from the shopping cart class
283           if (DOWNLOAD_ENABLED == '1') {
284             $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');
285             $Qstock->bindTable(':table_products', TABLE_PRODUCTS);
286             $Qstock->bindTable(':table_products_attributes', TABLE_PRODUCTS_ATTRIBUTES);
287             $Qstock->bindTable(':table_products_attributes_download', TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD);
288             $Qstock->bindInt(':products_id', $Qproducts->valueInt('products_id'));
289
290 // Will work with only one option for downloadable products otherwise, we have to build the query dynamically with a loop
291             if ($osC_ShoppingCart->hasAttributes($products['id'])) {
292               $products_attributes = $osC_ShoppingCart->getAttributes($products['id']);
293               $products_attributes = array_shift($products_attributes);
294
295               $Qstock->appendQuery('and pa.options_id = :options_id and pa.options_values_id = :options_values_id');
296               $Qstock->bindInt(':options_id', $products_attributes['options_id']);
297               $Qstock->bindInt(':options_values_id', $products_attributes['options_values_id']);
298             }
299           } else {
300 ************/
301             $Qstock = $osC_Database->query('select products_quantity from :table_products where products_id = :products_id');
302             $Qstock->bindTable(':table_products', TABLE_PRODUCTS);
303             $Qstock->bindInt(':products_id', $Qproducts->valueInt('products_id'));
304 // HPDL          }
305
306           $Qstock->execute();
307
308           if ($Qstock->numberOfRows() > 0) {
309             $stock_left = $Qstock->valueInt('products_quantity');
310
311 // do not decrement quantities if products_attributes_filename exists
312 // HPDL            if ((DOWNLOAD_ENABLED == '-1') || ((DOWNLOAD_ENABLED == '1') && (strlen($Qstock->value('products_attributes_filename')) < 1))) {
313               $stock_left = $stock_left - $Qproducts->valueInt('products_quantity');
314
315               $Qupdate = $osC_Database->query('update :table_products set products_quantity = :products_quantity where products_id = :products_id');
316               $Qupdate->bindTable(':table_products', TABLE_PRODUCTS);
317               $Qupdate->bindInt(':products_quantity', $stock_left);
318               $Qupdate->bindInt(':products_id', $Qproducts->valueInt('products_id'));
319               $Qupdate->execute();
320 // HPDL            }
321
322             if ((STOCK_ALLOW_CHECKOUT == '-1') && ($stock_left < 1)) {
323               $Qupdate = $osC_Database->query('update :table_products set products_status = 0 where products_id = :products_id');
324               $Qupdate->bindTable(':table_products', TABLE_PRODUCTS);
325               $Qupdate->bindInt(':products_id', $Qproducts->valueInt('products_id'));
326               $Qupdate->execute();
327             }
328           }
329         }
330
331 // Update products_ordered (for bestsellers list)
332         $Qupdate = $osC_Database->query('update :table_products set products_ordered = products_ordered + :products_ordered where products_id = :products_id');
333         $Qupdate->bindTable(':table_products', TABLE_PRODUCTS);
334         $Qupdate->bindInt(':products_ordered', $Qproducts->valueInt('products_quantity'));
335         $Qupdate->bindInt(':products_id', $Qproducts->valueInt('products_id'));
336         $Qupdate->execute();
337       }
hpdl
531
338
hpdl
538
339       osC_Order::sendEmail($order_id);
340
hpdl
531
341       unset($_SESSION['prepOrderID']);
hpdl
521
342     }
343
hpdl
538
344     function sendEmail($id) {
345       global $osC_Database, $osC_Language, $osC_Currencies;
346
347       $Qorder = $osC_Database->query('select * from :table_orders where orders_id = :orders_id limit 1');
348       $Qorder->bindTable(':table_orders', TABLE_ORDERS);
349       $Qorder->bindInt(':orders_id', $id);
350       $Qorder->execute();
351
352       if ($Qorder->numberOfRows() === 1) {
353         $email_order = STORE_NAME . "\n" .
354                        $osC_Language->get('email_order_separator') . "\n" .
355                        sprintf($osC_Language->get('email_order_order_number'), $id) . "\n" .
356                        sprintf($osC_Language->get('email_order_invoice_url'), tep_href_link(FILENAME_ACCOUNT, 'orders=' . $id, 'SSL', false, true, true)) . "\n" .
357                        sprintf($osC_Language->get('email_order_date_ordered'), osC_DateTime::getLong()) . "\n\n";
358
359         $Qproducts = $osC_Database->query('select products_model, products_name, final_price, products_tax, products_quantity from :table_orders_products where orders_id = :orders_id order by orders_products_id');
360         $Qproducts->bindTable(':table_orders_products', TABLE_ORDERS_PRODUCTS);
361         $Qproducts->bindInt(':orders_id', $id);
362         $Qproducts->execute();
363
364         $products_ordered = '';
365
366         while ($Qproducts->next()) {
367           $products_ordered .= $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"; // . $products_ordered_attributes . "\n";
368         }
369
hpdl
545
370         unset($Qproducts);
371
hpdl
538
372         $email_order .= $osC_Language->get('email_order_products') . "\n" .
373                         $osC_Language->get('email_order_separator') . "\n" .
374                         $products_ordered .
375                         $osC_Language->get('email_order_separator') . "\n";
376
377         $Qtotals = $osC_Database->query('select title, text from :table_orders_total where orders_id = :orders_id order by sort_order');
378         $Qtotals->bindTable(':table_orders_total', TABLE_ORDERS_TOTAL);
379         $Qtotals->bindInt(':orders_id', $id);
380         $Qtotals->execute();
381
382         while ($Qtotals->next()) {
383           $email_order .= strip_tags($Qtotals->value('title') . ' ' . $Qtotals->value('text')) . "\n";
384         }
385
hpdl
545
386         unset($Qtotals);
hpdl
538
387
hpdl
545
388         if ( (osc_empty($Qorder->value('delivery_name') === false)) && (osc_empty($Qorder->value('street_address') === false)) ) {
389           $address = array('name' => $Qorder->value('delivery_name'),
390                            'company' => $Qorder->value('delivery_company'),
391                            'street_address' => $Qorder->value('delivery_street_address'),
392                            'suburb' => $Qorder->value('delivery_suburb'),
393                            'city' => $Qorder->value('delivery_city'),
394                            'state' => $Qorder->value('delivery_state'),
395                            'country' => $Qorder->value('delivery_country'),
396                            'postcode' => $Qorder->value('delivery_postcode'));
hpdl
538
397
hpdl
545
398           $email_order .= "\n" . $osC_Language->get('email_order_delivery_address') . "\n" .
399                           $osC_Language->get('email_order_separator') . "\n" .
400                           tep_address_format($Qorder->valueInt('delivery_address_format_id'), $address, false, '', "\n") . "\n";
401
402           unset($address);
403         }
404
405         $address = array('name' => $Qorder->value('billing_name'),
406                          'company' => $Qorder->value('billing_company'),
407                          'street_address' => $Qorder->value('billing_street_address'),
408                          'suburb' => $Qorder->value('billing_suburb'),
409                          'city' => $Qorder->value('billing_city'),
410                          'state' => $Qorder->value('billing_state'),
411                          'country' => $Qorder->value('billing_country'),
412                          'postcode' => $Qorder->value('billing_postcode'));
413
414         $email_order .= "\n" . $osC_Language->get('email_order_billing_address') . "\n" .
415                         $osC_Language->get('email_order_separator') . "\n" .
416                         tep_address_format($Qorder->valueInt('billing_address_format_id'), $address, false, '', "\n") . "\n\n";
417
418         unset($address);
419
420         $Qstatus = $osC_Database->query('select orders_status_name from :table_orders_status where orders_status_id = :orders_status_id and language_id = :language_id');
421         $Qstatus->bindTable(':table_orders_status', TABLE_ORDERS_STATUS);
422         $Qstatus->bindInt(':orders_status_id', $Qorder->valueInt('orders_status'));
423         $Qstatus->bindInt(':language_id', $osC_Language->getID());
424         $Qstatus->execute();
425
426         $email_order .= sprintf($osC_Language->get('email_order_status'), $Qstatus->value('orders_status_name')) . "\n" .
427                         $osC_Language->get('email_order_separator') . "\n";
428
429         unset($Qstatus);
430
431         $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');
432         $Qstatuses->bindTable(':table_orders_status_history', TABLE_ORDERS_STATUS_HISTORY);
433         $Qstatuses->bindInt(':orders_id', $id);
434         $Qstatuses->execute();
435
436         while ($Qstatuses->next()) {
437           $email_order .= osC_DateTime::getLong($Qstatuses->value('date_added')) . "\n\t" . wordwrap($Qstatuses->value('comments'), 60, "\n\t", 1) . "\n\n";
438         }
439
440         unset($Qstatuses);
441
hpdl
538
442 //        if (is_object($GLOBALS[$payment])) {
443 //          $email_order .= $osC_Language->get('email_order_payment_method') . "\n" .
444 //                          $osC_Language->get('email_order_separator') . "\n";
445
446 //          $email_order .= $osC_ShoppingCart->getBillingMethod('title') . "\n\n";
447 //          if (isset($GLOBALS[$payment]->email_footer)) {
448 //            $email_order .= $GLOBALS[$payment]->email_footer . "\n\n";
449 //          }
450 //        }
451
452         tep_mail($Qorder->value('customers_name'), $Qorder->value('customers_email_address'), $osC_Language->get('email_order_subject'), $email_order, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS);
453
454 // send emails to other people
455         if (SEND_EXTRA_ORDER_EMAILS_TO != '') {
456           tep_mail('', SEND_EXTRA_ORDER_EMAILS_TO, $osC_Language->get('email_order_subject'), $email_order, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS);
457         }
458       }
hpdl
545
459
460       unset($Qorder);
hpdl
538
461     }
462
hpdl
183
463     function &getListing($limit = null, $page_keyword = 'page') {
hpdl
377
464       global $osC_Database, $osC_Customer, $osC_Language;
hpdl
183
465
hpdl
431
466       $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
467       $Qorders->bindTable(':table_orders', TABLE_ORDERS);
468       $Qorders->bindTable(':table_orders_total', TABLE_ORDERS_TOTAL);
469       $Qorders->bindTable(':table_orders_status', TABLE_ORDERS_STATUS);
hpdl
184
470       $Qorders->bindInt(':customers_id', $osC_Customer->getID());
hpdl
377
471       $Qorders->bindInt(':language_id', $osC_Language->getID());
hpdl
183
472
473       if (is_numeric($limit)) {
474         $Qorders->setBatchLimit(isset($_GET[$page_keyword]) && is_numeric($_GET[$page_keyword]) ? $_GET[$page_keyword] : 1, $limit);
475       }
476
477       $Qorders->execute();
478
479       return $Qorders;
480     }
481
482     function &getStatusListing($id = null) {
hpdl
377
483       global $osC_Database, $osC_Language;
hpdl
183
484
485       if ( ($id === null) && isset($this) ) {
486         $id = $this->_id;
487       }
488
489       $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');
490       $Qstatus->bindTable(':table_orders_status', TABLE_ORDERS_STATUS);
491       $Qstatus->bindTable(':table_orders_status_history', TABLE_ORDERS_STATUS_HISTORY);
492       $Qstatus->bindInt(':orders_id', $id);
hpdl
377
493       $Qstatus->bindInt(':language_id', $osC_Language->getID());
hpdl
183
494
495       return $Qstatus;
496     }
497
498     function getCustomerID($id = null) {
499       global $osC_Database;
500
501       if ( ($id === null) && isset($this) ) {
502         $id = $this->_id;
503       }
504
505       $Qcustomer = $osC_Database->query('select customers_id from :table_orders where orders_id = :orders_id');
506       $Qcustomer->bindTable(':table_orders', TABLE_ORDERS);
507       $Qcustomer->bindInt(':orders_id', $id);
508       $Qcustomer->execute();
509
510       return $Qcustomer->valueInt('customers_id');
511     }
512
513     function numberOfEntries() {
514       global $osC_Database, $osC_Customer;
515       static $total_entries;
516
517       if (is_numeric($total_entries) === false) {
518         if ($osC_Customer->isLoggedOn()) {
519           $Qorders = $osC_Database->query('select count(*) as total from :table_orders where customers_id = :customers_id');
520           $Qorders->bindTable(':table_orders', TABLE_ORDERS);
hpdl
184
521           $Qorders->bindInt(':customers_id', $osC_Customer->getID());
hpdl
183
522           $Qorders->execute();
523
524           $total_entries = $Qorders->valueInt('total');
525         } else {
526           $total_entries = 0;
527         }
528       }
529
530       return $total_entries;
531     }
532
533     function numberOfProducts($id = null) {
534       global $osC_Database;
535
536       if ( ($id === null) && isset($this) ) {
537         $id = $this->_id;
538       }
539
540       $Qproducts = $osC_Database->query('select count(*) as total from :table_orders_products where orders_id = :orders_id');
541       $Qproducts->bindTable(':table_orders_products', TABLE_ORDERS_PRODUCTS);
542       $Qproducts->bindInt(':orders_id', $id);
543       $Qproducts->execute();
544
545       return $Qproducts->valueInt('total');
546     }
547
hpdl
538
548     function exists($id, $customer_id = null) {
549       global $osC_Database;
hpdl
183
550
hpdl
538
551       $Qorder = $osC_Database->query('select orders_id from :table_orders where orders_id = :orders_id');
hpdl
183
552
hpdl
538
553       if (isset($customer_id) && is_numeric($customer_id)) {
554         $Qorder->appendQuery('and customers_id = :customers_id');
555         $Qorder->bindInt(':customers_id', $customer_id);
556       }
557
558       $Qorder->appendQuery('limit 1');
559       $Qorder->bindTable(':table_orders', TABLE_ORDERS);
560       $Qorder->bindInt(':orders_id', $id);
561       $Qorder->execute();
562
563       return ($Qorder->numberOfRows() === 1);
564     }
565
hpdl
1
566     function query($order_id) {
hpdl
377
567       global $osC_Database, $osC_Language;
hpdl
1
568
hpdl
20
569       $Qorder = $osC_Database->query('select customers_id, customers_name, customers_company, customers_street_address, customers_suburb, customers_city, customers_postcode, customers_state, customers_country, customers_telephone, customers_email_address, customers_address_format_id, delivery_name, delivery_company, delivery_street_address, delivery_suburb, delivery_city, delivery_postcode, delivery_state, delivery_country, delivery_address_format_id, billing_name, billing_company, billing_street_address, billing_suburb, billing_city, billing_postcode, billing_state, billing_country, billing_address_format_id, payment_method, cc_type, cc_owner, cc_number, cc_expires, currency, currency_value, date_purchased, orders_status, last_modified from :table_orders where orders_id = :orders_id');
570       $Qorder->bindTable(':table_orders', TABLE_ORDERS);
571       $Qorder->bindInt(':orders_id', $order_id);
572       $Qorder->execute();
hpdl
1
573
hpdl
20
574       $Qtotals = $osC_Database->query('select title, text, class from :table_orders_total where orders_id = :orders_id order by sort_order');
575       $Qtotals->bindTable(':table_orders_total', TABLE_ORDERS_TOTAL);
576       $Qtotals->bindInt(':orders_id', $order_id);
577       $Qtotals->execute();
hpdl
1
578
hpdl
20
579       $shipping_method_string = '';
580       $order_total_string = '';
hpdl
1
581
hpdl
20
582       while ($Qtotals->next()) {
583         $this->totals[] = array('title' => $Qtotals->value('title'),
584                                 'text' => $Qtotals->value('text'));
hpdl
1
585
hpdl
431
586         if ($Qtotals->value('class') == 'shipping') {
hpdl
20
587           $shipping_method_string = strip_tags($Qtotals->value('title'));
hpdl
1
588
hpdl
20
589           if (substr($shipping_method_string, -1) == ':') {
590             $shipping_method_string = substr($Qtotals->value('title'), 0, -1);
591           }
592         }
hpdl
1
593
hpdl
431
594         if ($Qtotals->value('class') == 'total') {
hpdl
20
595           $order_total_string = strip_tags($Qtotals->value('text'));
596         }
597       }
hpdl
1
598
hpdl
20
599       $Qstatus = $osC_Database->query('select orders_status_name from :table_orders_status where orders_status_id = :orders_status_id and language_id = :language_id');
600       $Qstatus->bindTable(':table_orders_status', TABLE_ORDERS_STATUS);
hpdl
45
601       $Qstatus->bindInt(':orders_status_id', $Qorder->valueInt('orders_status'));
hpdl
377
602       $Qstatus->bindInt(':language_id', $osC_Language->getID());
hpdl
20
603       $Qstatus->execute();
hpdl
1
604
hpdl
20
605       $this->info = array('currency' => $Qorder->value('currency'),
606                           'currency_value' => $Qorder->value('currency_value'),
607                           'payment_method' => $Qorder->value('payment_method'),
608                           'cc_type' => $Qorder->value('cc_type'),
609                           'cc_owner' => $Qorder->valueProtected('cc_owner'),
610                           'cc_number' => $Qorder->valueProtected('cc_number'),
611                           'cc_expires' => $Qorder->valueProtected('cc_expires'),
612                           'date_purchased' => $Qorder->value('date_purchased'),
613                           'orders_status' => $Qstatus->value('orders_status_name'),
614                           'last_modified' => $Qorder->value('last_modified'),
615                           'total' => $order_total_string,
616                           'shipping_method' => $shipping_method_string);
hpdl
1
617
hpdl
20
618       $this->customer = array('id' => $Qorder->valueInt('customers_id'),
619                               'name' => $Qorder->valueProtected('customers_name'),
620                               'company' => $Qorder->valueProtected('customers_company'),
621                               'street_address' => $Qorder->valueProtected('customers_street_address'),
622                               'suburb' => $Qorder->valueProtected('customers_suburb'),
623                               'city' => $Qorder->valueProtected('customers_city'),
624                               'postcode' => $Qorder->valueProtected('customers_postcode'),
625                               'state' => $Qorder->valueProtected('customers_state'),
626                               'country' => $Qorder->valueProtected('customers_country'),
627                               'format_id' => $Qorder->valueInt('customers_address_format_id'),
628                               'telephone' => $Qorder->valueProtected('customers_telephone'),
629                               'email_address' => $Qorder->valueProtected('customers_email_address'));
630
631       $this->delivery = array('name' => $Qorder->valueProtected('delivery_name'),
632                               'company' => $Qorder->valueProtected('delivery_company'),
633                               'street_address' => $Qorder->valueProtected('delivery_street_address'),
634                               'suburb' => $Qorder->valueProtected('delivery_suburb'),
635                               'city' => $Qorder->valueProtected('delivery_city'),
636                               'postcode' => $Qorder->valueProtected('delivery_postcode'),
637                               'state' => $Qorder->valueProtected('delivery_state'),
638                               'country' => $Qorder->valueProtected('delivery_country'),
639                               'format_id' => $Qorder->valueInt('delivery_address_format_id'));
640
hpdl
1
641       if (empty($this->delivery['name']) && empty($this->delivery['street_address'])) {
642         $this->delivery = false;
643       }
644
hpdl
20
645       $this->billing = array('name' => $Qorder->valueProtected('billing_name'),
646                              'company' => $Qorder->valueProtected('billing_company'),
647                              'street_address' => $Qorder->valueProtected('billing_street_address'),
648                              'suburb' => $Qorder->valueProtected('billing_suburb'),
649                              'city' => $Qorder->valueProtected('billing_city'),
650                              'postcode' => $Qorder->valueProtected('billing_postcode'),
651                              'state' => $Qorder->valueProtected('billing_state'),
652                              'country' => $Qorder->valueProtected('billing_country'),
653                              'format_id' => $Qorder->valueInt('billing_address_format_id'));
hpdl
1
654
hpdl
20
655       $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');
656       $Qproducts->bindTable(':table_orders_products', TABLE_ORDERS_PRODUCTS);
657       $Qproducts->bindInt(':orders_id', $order_id);
658       $Qproducts->execute();
659
hpdl
1
660       $index = 0;
661
hpdl
20
662       while ($Qproducts->next()) {
hpdl
1
663         $subindex = 0;
664
hpdl
20
665         $this->products[$index] = array('qty' => $Qproducts->valueInt('products_quantity'),
666                                         'id' => $Qproducts->valueInt('products_id'),
667                                         'name' => $Qproducts->value('products_name'),
668                                         'model' => $Qproducts->value('products_model'),
669                                         'tax' => $Qproducts->value('products_tax'),
670                                         'price' => $Qproducts->value('products_price'),
671                                         'final_price' => $Qproducts->value('final_price'));
672
673         $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');
674         $Qattributes->bindTable(':table_orders_products_attributes', TABLE_ORDERS_PRODUCTS_ATTRIBUTES);
675         $Qattributes->bindInt(':orders_id', $order_id);
676         $Qattributes->bindInt(':orders_products_id', $Qproducts->valueInt('orders_products_id'));
677         $Qattributes->execute();
678
679         if ($Qattributes->numberOfRows()) {
680           while ($Qattributes->next()) {
681             $this->products[$index]['attributes'][$subindex] = array('option' => $Qattributes->value('products_options'),
682                                                                      'value' => $Qattributes->value('products_options_values'),
683                                                                      'prefix' => $Qattributes->value('price_prefix'),
684                                                                      'price' => $Qattributes->value('options_values_price'));
685
hpdl
1
686             $subindex++;
687           }
688         }
689
690         $this->info['tax_groups']["{$this->products[$index]['tax']}"] = '1';
691
692         $index++;
693       }
694     }
695   }
696 ?>