Quick Search:

View

Revision:

Diff

Diff from 1862 to:

Annotations

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

Annotated File View

hpdl
1242
1 <?php
2 /*
3   $Id: $
4
5   osCommerce, Open Source E-Commerce Solutions
6   http://www.oscommerce.com
7
8   Copyright (c) 2007 osCommerce
9
hpdl
1498
10   This program is free software; you can redistribute it and/or modify
11   it under the terms of the GNU General Public License v2 (1991)
12   as published by the Free Software Foundation.
hpdl
1242
13 */
14
15   class osC_Customers_Admin {
16     function getData($id, $key = null) {
17       global $osC_Database;
18
19       $Qcustomer = $osC_Database->query('select c.*, date_format(c.customers_dob, "%Y") as customers_dob_year, date_format(c.customers_dob, "%m") as customers_dob_month, date_format(c.customers_dob, "%d") as customers_dob_date, ab.* from :table_customers c left join :table_address_book ab on (c.customers_default_address_id = ab.address_book_id and c.customers_id = ab.customers_id) where c.customers_id = :customers_id');
20       $Qcustomer->bindTable(':table_customers', TABLE_CUSTOMERS);
21       $Qcustomer->bindTable(':table_address_book', TABLE_ADDRESS_BOOK);
22       $Qcustomer->bindInt(':customers_id', $id);
23       $Qcustomer->execute();
24
25       $data = $Qcustomer->toArray();
26
27       $Qreviews = $osC_Database->query('select count(*) as total from :table_reviews where customers_id = :customers_id');
28       $Qreviews->bindTable(':table_reviews', TABLE_REVIEWS);
29       $Qreviews->bindInt(':customers_id', $id);
30       $Qreviews->execute();
31
32       $data['total_reviews'] = $Qreviews->valueInt('total');
33
34       $Qreviews->freeResult();
35       $Qcustomer->freeResult();
36
37       $data['customers_full_name'] = $data['customers_firstname'] . ' ' . $data['customers_lastname'];
38
39       if ( !empty($key) ) {
40         return $data[$key];
41       }
42
43       return $data;
44     }
45
46     function getAddressBookData($customer_id, $address_book_id = null) {
47       global $osC_Database;
48
49       $Qab = $osC_Database->query('select ab.address_book_id, ab.entry_gender as gender, ab.entry_firstname as firstname, ab.entry_lastname as lastname, ab.entry_company as company, ab.entry_street_address as street_address, ab.entry_suburb as suburb, ab.entry_city as city, ab.entry_postcode as postcode, ab.entry_state as state, ab.entry_zone_id as zone_id, ab.entry_country_id as country_id, ab.entry_telephone as telephone_number, ab.entry_fax as fax_number, z.zone_code as zone_code, c.countries_name as country_title from :table_address_book ab left join :table_zones z on (ab.entry_zone_id = z.zone_id), :table_countries c where');
50
51       if ( is_numeric($address_book_id) ) {
52         $Qab->appendQuery('ab.address_book_id = :address_book_id and');
53         $Qab->bindInt(':address_book_id', $address_book_id);
54       }
55
56       $Qab->appendQuery('ab.customers_id = :customers_id and ab.entry_country_id = c.countries_id');
57       $Qab->bindTable(':table_address_book', TABLE_ADDRESS_BOOK);
58       $Qab->bindTable(':table_zones', TABLE_ZONES);
59       $Qab->bindTable(':table_countries', TABLE_COUNTRIES);
60       $Qab->bindInt(':customers_id', $customer_id);
61       $Qab->execute();
62
63       if ( is_numeric($address_book_id) ) {
64         $data = $Qab->toArray();
65
66         $Qab->freeResult();
67
68         return $data;
69       }
70
71       return $Qab;
72     }
73
74     function save($id = null, $data, $send_email = true) {
hpdl
1492
75       global $osC_Database, $osC_Language;
hpdl
1242
76
77       $error = false;
78
79       $osC_Database->startTransaction();
80
81       if ( is_numeric($id) ) {
82         $Qcustomer = $osC_Database->query('update :table_customers set customers_gender = :customers_gender, customers_firstname = :customers_firstname, customers_lastname = :customers_lastname, customers_email_address = :customers_email_address, customers_dob = :customers_dob, customers_newsletter = :customers_newsletter, customers_status = :customers_status, date_account_last_modified = :date_account_last_modified where customers_id = :customers_id');
83         $Qcustomer->bindRaw(':date_account_last_modified', 'now()');
84         $Qcustomer->bindInt(':customers_id', $id);
85       } else {
86         $Qcustomer = $osC_Database->query('insert into :table_customers (customers_gender, customers_firstname, customers_lastname, customers_email_address, customers_dob, customers_newsletter, customers_status, number_of_logons, date_account_created) values (:customers_gender, :customers_firstname, :customers_lastname, :customers_email_address, :customers_dob, :customers_newsletter, :customers_status, :number_of_logons, :date_account_created)');
87         $Qcustomer->bindInt(':number_of_logons', 0);
88         $Qcustomer->bindRaw(':date_account_created', 'now()');
89       }
90
91       $Qcustomer->bindTable(':table_customers', TABLE_CUSTOMERS);
92       $Qcustomer->bindValue(':customers_gender', $data['gender']);
93       $Qcustomer->bindValue(':customers_firstname', $data['firstname']);
94       $Qcustomer->bindValue(':customers_lastname', $data['lastname']);
95       $Qcustomer->bindValue(':customers_email_address', $data['email_address']);
96       $Qcustomer->bindValue(':customers_dob', $data['dob_year'] . '-' . $data['dob_month'] . '-' . $data['dob_day'] . ' 00:00:00');
97       $Qcustomer->bindInt(':customers_newsletter', $data['newsletter']);
98       $Qcustomer->bindInt(':customers_status', $data['status']);
hpdl
1374
99       $Qcustomer->setLogging($_SESSION['module'], $id);
hpdl
1242
100       $Qcustomer->execute();
101
102       if ( !$osC_Database->isError() ) {
103         if ( !empty($data['password']) ) {
104           $customer_id = ( !empty($id) ) ? $id : $osC_Database->nextID();
105
106           $Qpassword = $osC_Database->query('update :table_customers set customers_password = :customers_password where customers_id = :customers_id');
107           $Qpassword->bindTable(':table_customers', TABLE_CUSTOMERS);
108           $Qpassword->bindValue(':customers_password', osc_encrypt_string(trim($data['password'])));
109           $Qpassword->bindInt(':customers_id', $customer_id);
hpdl
1374
110           $Qpassword->setLogging($_SESSION['module'], $customer_id);
hpdl
1242
111           $Qpassword->execute();
112
113           if ( $osC_Database->isError() ) {
114             $error = true;
115           }
116         }
117       }
118
119       if ( $error === false ) {
120         $osC_Database->commitTransaction();
121
122         if ( $send_email === true ) {
123           if ( empty($id) ) {
hpdl
1492
124             $full_name = trim($data['firstname'] . ' ' . $data['lastname']);
hpdl
1242
125
126             $email_text = '';
127
128             if ( ACCOUNT_GENDER > -1 ) {
129               if ( $data['gender'] == 'm' ) {
hpdl
1492
130                 $email_text .= sprintf($osC_Language->get('email_greet_mr'), trim($data['lastname'])) . "\n\n";
hpdl
1242
131               } else {
hpdl
1492
132                 $email_text .= sprintf($osC_Language->get('email_greet_ms'), trim($data['lastname'])) . "\n\n";
hpdl
1242
133               }
134             } else {
hpdl
1492
135               $email_text .= sprintf($osC_Language->get('email_greet_general'), $full_name) . "\n\n";
hpdl
1242
136             }
137
hpdl
1492
138             $email_text .= sprintf($osC_Language->get('email_text'), STORE_NAME, STORE_OWNER_EMAIL_ADDRESS, trim($data['password']));
hpdl
1242
139
hpdl
1492
140             osc_email($full_name, $data['email_address'], $osC_Language->get('email_subject'), $email_text, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS);
hpdl
1242
141           }
142         }
143
144         return true;
145       }
146
147       $osC_Database->rollbackTransaction();
148
149       return false;
150     }
151
152     function delete($id, $delete_reviews = true) {
hpdl
1859
153       global $osC_Database, $osC_Session;
hpdl
1242
154
155       $error = false;
156
157       $osC_Database->startTransaction();
158
159       if ( $delete_reviews === true ) {
160         $Qreviews = $osC_Database->query('delete from :table_reviews where customers_id = :customers_id');
161         $Qreviews->bindTable(':table_reviews', TABLE_REVIEWS);
162         $Qreviews->bindInt(':customers_id', $id);
hpdl
1374
163         $Qreviews->setLogging($_SESSION['module'], $id);
hpdl
1242
164         $Qreviews->execute();
165
166         if ( $osC_Database->isError() ) {
167           $error = true;
168         }
169       } else {
170         $Qcheck = $osC_Database->query('select reviews_id from :table_reviews where customers_id = :customers_id limit 1');
171         $Qcheck->bindTable(':table_reviews', TABLE_REVIEWS);
172         $Qcheck->bindInt(':customers_id', $id);
173         $Qcheck->execute();
174
175         if ( $Qcheck->numberOfRows() > 0 ) {
176           $Qreviews = $osC_Database->query('update :table_reviews set customers_id = null where customers_id = :customers_id');
177           $Qreviews->bindTable(':table_reviews', TABLE_REVIEWS);
178           $Qreviews->bindInt(':customers_id', $id);
hpdl
1374
179           $Qreviews->setLogging($_SESSION['module'], $id);
hpdl
1242
180           $Qreviews->execute();
181
182           if ( $osC_Database->isError() ) {
183             $error = true;
184           }
185         }
186       }
187
188       if ( $error === false ) {
189         $Qab = $osC_Database->query('delete from :table_address_book where customers_id = :customers_id');
190         $Qab->bindTable(':table_address_book', TABLE_ADDRESS_BOOK);
191         $Qab->bindInt(':customers_id', $id);
hpdl
1374
192         $Qab->setLogging($_SESSION['module'], $id);
hpdl
1242
193         $Qab->execute();
194
195         if ( $osC_Database->isError() ) {
196           $error = true;
197         }
198       }
199
200       if ( $error === false ) {
hpdl
1862
201         $Qsc = $osC_Database->query('delete from :table_shopping_carts where customers_id = :customers_id');
202         $Qsc->bindTable(':table_shopping_carts', TABLE_SHOPPING_CARTS);
203         $Qsc->bindInt(':customers_id', $id);
204         $Qsc->execute();
hpdl
1242
205
206         if ( $osC_Database->isError() ) {
207           $error = true;
208         }
209       }
210
211       if ( $error === false ) {
hpdl
1862
212         $Qsccvv = $osC_Database->query('delete from :table_shopping_carts_custom_variants_values where customers_id = :customers_id');
213         $Qsccvv->bindTable(':table_shopping_carts_custom_variants_values', TABLE_SHOPPING_CARTS_CUSTOM_VARIANTS_VALUES);
214         $Qsccvv->bindInt(':customers_id', $id);
215         $Qsccvv->execute();
216
217         if ( $osC_Database->isError() ) {
218           $error = true;
219         }
220       }
221
222       if ( $error === false ) {
hpdl
1242
223         $Qpn = $osC_Database->query('delete from :table_products_notifications where customers_id = :customers_id');
224         $Qpn->bindTable(':table_products_notifications', TABLE_PRODUCTS_NOTIFICATIONS);
225         $Qpn->bindInt(':customers_id', $id);
hpdl
1374
226         $Qpn->setLogging($_SESSION['module'], $id);
hpdl
1242
227         $Qpn->execute();
228
229         if ( $osC_Database->isError() ) {
230           $error = true;
231         }
232       }
233
234       if ( $error === false ) {
235         $Qcheck = $osC_Database->query('select session_id from :table_whos_online where customer_id = :customer_id');
236         $Qcheck->bindTable(':table_whos_online', TABLE_WHOS_ONLINE);
237         $Qcheck->bindInt(':customer_id', $id);
238         $Qcheck->execute();
239
240         if ( $Qcheck->numberOfRows() > 0 ) {
hpdl
1859
241           $osC_Session->delete($Qcheck->value('session_id'));
hpdl
1242
242
243           $Qwho = $osC_Database->query('delete from :table_whos_online where customer_id = :customer_id');
244           $Qwho->bindTable(':table_whos_online', TABLE_WHOS_ONLINE);
245           $Qwho->bindInt(':customer_id', $id);
246           $Qwho->execute();
247
248           if ( $osC_Database->isError() ) {
249             $error = true;
250           }
251         }
252       }
253
254       if ( $error === false ) {
255         $Qcustomers = $osC_Database->query('delete from :table_customers where customers_id = :customers_id');
256         $Qcustomers->bindTable(':table_customers', TABLE_CUSTOMERS);
257         $Qcustomers->bindInt(':customers_id', $id);
hpdl
1374
258         $Qcustomers->setLogging($_SESSION['module'], $id);
hpdl
1242
259         $Qcustomers->execute();
260
261         if ( $osC_Database->isError() ) {
262           $error = true;
263         }
264       }
265
266       if ( $error === false ) {
267         $osC_Database->commitTransaction();
268
269         return true;
270       }
271
272       $osC_Database->rollbackTransaction();
273
274       return false;
275     }
276
277     function saveAddress($id = null, $data) {
278       global $osC_Database;
279
280       $error = false;
281
282       $osC_Database->startTransaction();
283
284       $Qcustomer = $osC_Database->query('select customers_gender, customers_firstname, customers_lastname, customers_email_address, customers_default_address_id from :table_customers where customers_id = :customers_id');
285       $Qcustomer->bindTable(':table_customers', TABLE_CUSTOMERS);
286       $Qcustomer->bindInt(':customers_id', $data['customer_id']);
287       $Qcustomer->execute();
288
289       if ( is_numeric($id) ) {
290         $Qab = $osC_Database->query('update :table_address_book set entry_gender = :entry_gender, entry_company = :entry_company, entry_firstname = :entry_firstname, entry_lastname = :entry_lastname, entry_street_address = :entry_street_address, entry_suburb = :entry_suburb, entry_postcode = :entry_postcode, entry_city = :entry_city, entry_state = :entry_state, entry_country_id = :entry_country_id, entry_zone_id = :entry_zone_id, entry_telephone = :entry_telephone, entry_fax = :entry_fax where address_book_id = :address_book_id and customers_id = :customers_id');
291         $Qab->bindInt(':address_book_id', $id);
292       } else {
293         $Qab = $osC_Database->query('insert into :table_address_book (customers_id, entry_gender, entry_company, entry_firstname, entry_lastname, entry_street_address, entry_suburb, entry_postcode, entry_city, entry_state, entry_country_id, entry_zone_id, entry_telephone, entry_fax) values (:customers_id, :entry_gender, :entry_company, :entry_firstname, :entry_lastname, :entry_street_address, :entry_suburb, :entry_postcode, :entry_city, :entry_state, :entry_country_id, :entry_zone_id, :entry_telephone, :entry_fax)');
294       }
295
296       $Qab->bindTable(':table_address_book', TABLE_ADDRESS_BOOK);
297       $Qab->bindInt(':customers_id', $data['customer_id']);
298       $Qab->bindValue(':entry_gender', $data['gender']);
299       $Qab->bindValue(':entry_company', $data['company']);
300       $Qab->bindValue(':entry_firstname', $data['firstname']);
301       $Qab->bindValue(':entry_lastname', $data['lastname']);
302       $Qab->bindValue(':entry_street_address', $data['street_address']);
303       $Qab->bindValue(':entry_suburb', $data['suburb']);
304       $Qab->bindValue(':entry_postcode', $data['postcode']);
305       $Qab->bindValue(':entry_city', $data['city']);
306       $Qab->bindValue(':entry_state', $data['state']);
307       $Qab->bindInt(':entry_country_id', $data['country_id']);
308       $Qab->bindInt(':entry_zone_id', $data['zone_id']);
309       $Qab->bindValue(':entry_telephone', $data['telephone']);
310       $Qab->bindValue(':entry_fax', $data['fax']);
hpdl
1374
311       $Qab->setLogging($_SESSION['module'], $id);
hpdl
1242
312       $Qab->execute();
313
314       if ( !$osC_Database->isError() ) {
315         if ( ( $Qcustomer->valueInt('customers_default_address_id') < 1 ) || ( $data['primary'] === true ) ) {
316           $address_book_id = ( is_numeric($id) ? $id : $osC_Database->nextID() );
317
318           $Qupdate = $osC_Database->query('update :table_customers set customers_default_address_id = :customers_default_address_id where customers_id = :customers_id');
319           $Qupdate->bindTable(':table_customers', TABLE_CUSTOMERS);
320           $Qupdate->bindInt(':customers_default_address_id', $address_book_id);
321           $Qupdate->bindInt(':customers_id', $data['customer_id']);
hpdl
1374
322           $Qupdate->setLogging($_SESSION['module'], $address_book_id);
hpdl
1242
323           $Qupdate->execute();
324
325           if ( $osC_Database->isError() ) {
326             $error = true;
327           }
328         }
329       } else {
330         $error = true;
331       }
332
333       if ( $error === false ) {
334         $osC_Database->commitTransaction();
335
336         return true;
337       }
338
339       $osC_Database->rollbackTransaction();
340
341       return false;
342     }
343
344     function deleteAddress($id, $customer_id = null) {
345       global $osC_Database;
346
347       $Qdelete = $osC_Database->query('delete from :table_address_book where address_book_id = :address_book_id');
348
349       if ( !empty($customer_id) ) {
350         $Qdelete->appendQuery('and customers_id = :customers_id');
351         $Qdelete->bindInt(':customers_id', $customer_id);
352       }
353
354       $Qdelete->bindTable(':table_address_book', TABLE_ADDRESS_BOOK);
355       $Qdelete->bindInt(':address_book_id', $id);
hpdl
1374
356       $Qdelete->setLogging($_SESSION['module'], $id);
hpdl
1242
357       $Qdelete->execute();
358
359       if ( !$osC_Database->isError() ) {
360         return true;
361       }
362
363       return false;
364     }
365   }
366 ?>