Quick Search:

View

Revision:

Diff

Diff from 538 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 538 2006-04-27 16:53:59Z 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'));
148       $Qorder->bindValue(':billing_country', $osC_ShoppingCart->getBillingAddress('country_id'));
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         if (isset($_SESSION['comments'])) {
360           $email_order .= tep_output_string_protected($_SESSION['comments']) . "\n\n";
361         }
362
363         $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');
364         $Qproducts->bindTable(':table_orders_products', TABLE_ORDERS_PRODUCTS);
365         $Qproducts->bindInt(':orders_id', $id);
366         $Qproducts->execute();
367
368         $products_ordered = '';
369
370         while ($Qproducts->next()) {
371           $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";
372         }
373
374         $email_order .= $osC_Language->get('email_order_products') . "\n" .
375                         $osC_Language->get('email_order_separator') . "\n" .
376                         $products_ordered .
377                         $osC_Language->get('email_order_separator') . "\n";
378
379         $Qtotals = $osC_Database->query('select title, text from :table_orders_total where orders_id = :orders_id order by sort_order');
380         $Qtotals->bindTable(':table_orders_total', TABLE_ORDERS_TOTAL);
381         $Qtotals->bindInt(':orders_id', $id);
382         $Qtotals->execute();
383
384         while ($Qtotals->next()) {
385           $email_order .= strip_tags($Qtotals->value('title') . ' ' . $Qtotals->value('text')) . "\n";
386         }
387
388 //        if ($order->content_type != 'virtual') {
389 //          $email_order .= "\n" . $osC_Language->get('email_order_delivery_address') . "\n" .
390 //                          $osC_Language->get('email_order_separator') . "\n" .
391 //                          tep_address_label($osC_Customer->getID(), $osC_ShoppingCart->getShippingAddress('id'), 0, '', "\n") . "\n";
392 //        }
393
394 //        $email_order .= "\n" . $osC_Language->get('email_order_billing_address') . "\n" .
395 //                        $osC_Language->get('email_order_separator') . "\n" .
396 //                        tep_address_label($osC_Customer->getID(), $osC_ShoppingCart->getBillingAddress('id'), 0, '', "\n") . "\n\n";
397
398 //        if (is_object($GLOBALS[$payment])) {
399 //          $email_order .= $osC_Language->get('email_order_payment_method') . "\n" .
400 //                          $osC_Language->get('email_order_separator') . "\n";
401
402 //          $email_order .= $osC_ShoppingCart->getBillingMethod('title') . "\n\n";
403 //          if (isset($GLOBALS[$payment]->email_footer)) {
404 //            $email_order .= $GLOBALS[$payment]->email_footer . "\n\n";
405 //          }
406 //        }
407
408         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);
409
410 // send emails to other people
411         if (SEND_EXTRA_ORDER_EMAILS_TO != '') {
412           tep_mail('', SEND_EXTRA_ORDER_EMAILS_TO, $osC_Language->get('email_order_subject'), $email_order, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS);
413         }
414       }
415     }
416
hpdl
183
417     function &getListing($limit = null, $page_keyword = 'page') {
hpdl
377
418       global $osC_Database, $osC_Customer, $osC_Language;
hpdl
183
419
hpdl
431
420       $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
421       $Qorders->bindTable(':table_orders', TABLE_ORDERS);
422       $Qorders->bindTable(':table_orders_total', TABLE_ORDERS_TOTAL);
423       $Qorders->bindTable(':table_orders_status', TABLE_ORDERS_STATUS);
hpdl
184
424       $Qorders->bindInt(':customers_id', $osC_Customer->getID());
hpdl
377
425       $Qorders->bindInt(':language_id', $osC_Language->getID());
hpdl
183
426
427       if (is_numeric($limit)) {
428         $Qorders->setBatchLimit(isset($_GET[$page_keyword]) && is_numeric($_GET[$page_keyword]) ? $_GET[$page_keyword] : 1, $limit);
429       }
430
431       $Qorders->execute();
432
433       return $Qorders;
434     }
435
436     function &getStatusListing($id = null) {
hpdl
377
437       global $osC_Database, $osC_Language;
hpdl
183
438
439       if ( ($id === null) && isset($this) ) {
440         $id = $this->_id;
441       }
442
443       $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');
444       $Qstatus->bindTable(':table_orders_status', TABLE_ORDERS_STATUS);
445       $Qstatus->bindTable(':table_orders_status_history', TABLE_ORDERS_STATUS_HISTORY);
446       $Qstatus->bindInt(':orders_id', $id);
hpdl
377
447       $Qstatus->bindInt(':language_id', $osC_Language->getID());
hpdl
183
448
449       return $Qstatus;
450     }
451
452     function getCustomerID($id = null) {
453       global $osC_Database;
454
455       if ( ($id === null) && isset($this) ) {
456         $id = $this->_id;
457       }
458
459       $Qcustomer = $osC_Database->query('select customers_id from :table_orders where orders_id = :orders_id');
460       $Qcustomer->bindTable(':table_orders', TABLE_ORDERS);
461       $Qcustomer->bindInt(':orders_id', $id);
462       $Qcustomer->execute();
463
464       return $Qcustomer->valueInt('customers_id');
465     }
466
467     function numberOfEntries() {
468       global $osC_Database, $osC_Customer;
469       static $total_entries;
470
471       if (is_numeric($total_entries) === false) {
472         if ($osC_Customer->isLoggedOn()) {
473           $Qorders = $osC_Database->query('select count(*) as total from :table_orders where customers_id = :customers_id');
474           $Qorders->bindTable(':table_orders', TABLE_ORDERS);
hpdl
184
475           $Qorders->bindInt(':customers_id', $osC_Customer->getID());
hpdl
183
476           $Qorders->execute();
477
478           $total_entries = $Qorders->valueInt('total');
479         } else {
480           $total_entries = 0;
481         }
482       }
483
484       return $total_entries;
485     }
486
487     function numberOfProducts($id = null) {
488       global $osC_Database;
489
490       if ( ($id === null) && isset($this) ) {
491         $id = $this->_id;
492       }
493
494       $Qproducts = $osC_Database->query('select count(*) as total from :table_orders_products where orders_id = :orders_id');
495       $Qproducts->bindTable(':table_orders_products', TABLE_ORDERS_PRODUCTS);
496       $Qproducts->bindInt(':orders_id', $id);
497       $Qproducts->execute();
498
499       return $Qproducts->valueInt('total');
500     }
501
hpdl
538
502     function exists($id, $customer_id = null) {
503       global $osC_Database;
hpdl
183
504
hpdl
538
505       $Qorder = $osC_Database->query('select orders_id from :table_orders where orders_id = :orders_id');
hpdl
183
506
hpdl
538
507       if (isset($customer_id) && is_numeric($customer_id)) {
508         $Qorder->appendQuery('and customers_id = :customers_id');
509         $Qorder->bindInt(':customers_id', $customer_id);
510       }
511
512       $Qorder->appendQuery('limit 1');
513       $Qorder->bindTable(':table_orders', TABLE_ORDERS);
514       $Qorder->bindInt(':orders_id', $id);
515       $Qorder->execute();
516
517       return ($Qorder->numberOfRows() === 1);
518     }
519
hpdl
1
520     function query($order_id) {
hpdl
377
521       global $osC_Database, $osC_Language;
hpdl
1
522
hpdl
20
523       $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');
524       $Qorder->bindTable(':table_orders', TABLE_ORDERS);
525       $Qorder->bindInt(':orders_id', $order_id);
526       $Qorder->execute();
hpdl
1
527
hpdl
20
528       $Qtotals = $osC_Database->query('select title, text, class from :table_orders_total where orders_id = :orders_id order by sort_order');
529       $Qtotals->bindTable(':table_orders_total', TABLE_ORDERS_TOTAL);
530       $Qtotals->bindInt(':orders_id', $order_id);
531       $Qtotals->execute();
hpdl
1
532
hpdl
20
533       $shipping_method_string = '';
534       $order_total_string = '';
hpdl
1
535
hpdl
20
536       while ($Qtotals->next()) {
537         $this->totals[] = array('title' => $Qtotals->value('title'),
538                                 'text' => $Qtotals->value('text'));
hpdl
1
539
hpdl
431
540         if ($Qtotals->value('class') == 'shipping') {
hpdl
20
541           $shipping_method_string = strip_tags($Qtotals->value('title'));
hpdl
1
542
hpdl
20
543           if (substr($shipping_method_string, -1) == ':') {
544             $shipping_method_string = substr($Qtotals->value('title'), 0, -1);
545           }
546         }
hpdl
1
547
hpdl
431
548         if ($Qtotals->value('class') == 'total') {
hpdl
20
549           $order_total_string = strip_tags($Qtotals->value('text'));
550         }
551       }
hpdl
1
552
hpdl
20
553       $Qstatus = $osC_Database->query('select orders_status_name from :table_orders_status where orders_status_id = :orders_status_id and language_id = :language_id');
554       $Qstatus->bindTable(':table_orders_status', TABLE_ORDERS_STATUS);
hpdl
45
555       $Qstatus->bindInt(':orders_status_id', $Qorder->valueInt('orders_status'));
hpdl
377
556       $Qstatus->bindInt(':language_id', $osC_Language->getID());
hpdl
20
557       $Qstatus->execute();
hpdl
1
558
hpdl
20
559       $this->info = array('currency' => $Qorder->value('currency'),
560                           'currency_value' => $Qorder->value('currency_value'),
561                           'payment_method' => $Qorder->value('payment_method'),
562                           'cc_type' => $Qorder->value('cc_type'),
563                           'cc_owner' => $Qorder->valueProtected('cc_owner'),
564                           'cc_number' => $Qorder->valueProtected('cc_number'),
565                           'cc_expires' => $Qorder->valueProtected('cc_expires'),
566                           'date_purchased' => $Qorder->value('date_purchased'),
567                           'orders_status' => $Qstatus->value('orders_status_name'),
568                           'last_modified' => $Qorder->value('last_modified'),
569                           'total' => $order_total_string,
570                           'shipping_method' => $shipping_method_string);
hpdl
1
571
hpdl
20
572       $this->customer = array('id' => $Qorder->valueInt('customers_id'),
573                               'name' => $Qorder->valueProtected('customers_name'),
574                               'company' => $Qorder->valueProtected('customers_company'),
575                               'street_address' => $Qorder->valueProtected('customers_street_address'),
576                               'suburb' => $Qorder->valueProtected('customers_suburb'),
577                               'city' => $Qorder->valueProtected('customers_city'),
578                               'postcode' => $Qorder->valueProtected('customers_postcode'),
579                               'state' => $Qorder->valueProtected('customers_state'),
580                               'country' => $Qorder->valueProtected('customers_country'),
581                               'format_id' => $Qorder->valueInt('customers_address_format_id'),
582                               'telephone' => $Qorder->valueProtected('customers_telephone'),
583                               'email_address' => $Qorder->valueProtected('customers_email_address'));
584
585       $this->delivery = array('name' => $Qorder->valueProtected('delivery_name'),
586                               'company' => $Qorder->valueProtected('delivery_company'),
587                               'street_address' => $Qorder->valueProtected('delivery_street_address'),
588                               'suburb' => $Qorder->valueProtected('delivery_suburb'),
589                               'city' => $Qorder->valueProtected('delivery_city'),
590                               'postcode' => $Qorder->valueProtected('delivery_postcode'),
591                               'state' => $Qorder->valueProtected('delivery_state'),
592                               'country' => $Qorder->valueProtected('delivery_country'),
593                               'format_id' => $Qorder->valueInt('delivery_address_format_id'));
594
hpdl
1
595       if (empty($this->delivery['name']) && empty($this->delivery['street_address'])) {
596         $this->delivery = false;
597       }
598
hpdl
20
599       $this->billing = array('name' => $Qorder->valueProtected('billing_name'),
600                              'company' => $Qorder->valueProtected('billing_company'),
601                              'street_address' => $Qorder->valueProtected('billing_street_address'),
602                              'suburb' => $Qorder->valueProtected('billing_suburb'),
603                              'city' => $Qorder->valueProtected('billing_city'),
604                              'postcode' => $Qorder->valueProtected('billing_postcode'),
605                              'state' => $Qorder->valueProtected('billing_state'),
606                              'country' => $Qorder->valueProtected('billing_country'),
607                              'format_id' => $Qorder->valueInt('billing_address_format_id'));
hpdl
1
608
hpdl
20
609       $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');
610       $Qproducts->bindTable(':table_orders_products', TABLE_ORDERS_PRODUCTS);
611       $Qproducts->bindInt(':orders_id', $order_id);
612       $Qproducts->execute();
613
hpdl
1
614       $index = 0;
615
hpdl
20
616       while ($Qproducts->next()) {
hpdl
1
617         $subindex = 0;
618
hpdl
20
619         $this->products[$index] = array('qty' => $Qproducts->valueInt('products_quantity'),
620                                         'id' => $Qproducts->valueInt('products_id'),
621                                         'name' => $Qproducts->value('products_name'),
622                                         'model' => $Qproducts->value('products_model'),
623                                         'tax' => $Qproducts->value('products_tax'),
624                                         'price' => $Qproducts->value('products_price'),
625                                         'final_price' => $Qproducts->value('final_price'));
626
627         $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');
628         $Qattributes->bindTable(':table_orders_products_attributes', TABLE_ORDERS_PRODUCTS_ATTRIBUTES);
629         $Qattributes->bindInt(':orders_id', $order_id);
630         $Qattributes->bindInt(':orders_products_id', $Qproducts->valueInt('orders_products_id'));
631         $Qattributes->execute();
632
633         if ($Qattributes->numberOfRows()) {
634           while ($Qattributes->next()) {
635             $this->products[$index]['attributes'][$subindex] = array('option' => $Qattributes->value('products_options'),
636                                                                      'value' => $Qattributes->value('products_options_values'),
637                                                                      'prefix' => $Qattributes->value('price_prefix'),
638                                                                      'price' => $Qattributes->value('options_values_price'));
639
hpdl
1
640             $subindex++;
641           }
642         }
643
644         $this->info['tax_groups']["{$this->products[$index]['tax']}"] = '1';
645
646         $index++;
647       }
648     }
649   }
650 ?>