Quick Search:

View

Revision:

Diff

Diff from 1859 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 ) {
201         $Qcb = $osC_Database->query('delete from :table_customers_basket where customers_id = :customers_id');
202         $Qcb->bindTable(':table_customers_basket', TABLE_CUSTOMERS_BASKET);
203         $Qcb->bindInt(':customers_id', $id);
204         $Qcb->execute();
205
206         if ( $osC_Database->isError() ) {
207           $error = true;
208         }
209       }
210
211       if ( $error === false ) {
212         $Qpn = $osC_Database->query('delete from :table_products_notifications where customers_id = :customers_id');
213         $Qpn->bindTable(':table_products_notifications', TABLE_PRODUCTS_NOTIFICATIONS);
214         $Qpn->bindInt(':customers_id', $id);
hpdl
1374
215         $Qpn->setLogging($_SESSION['module'], $id);
hpdl
1242
216         $Qpn->execute();
217
218         if ( $osC_Database->isError() ) {
219           $error = true;
220         }
221       }
222
223       if ( $error === false ) {
224         $Qcheck = $osC_Database->query('select session_id from :table_whos_online where customer_id = :customer_id');
225         $Qcheck->bindTable(':table_whos_online', TABLE_WHOS_ONLINE);
226         $Qcheck->bindInt(':customer_id', $id);
227         $Qcheck->execute();
228
229         if ( $Qcheck->numberOfRows() > 0 ) {
hpdl
1859
230           $osC_Session->delete($Qcheck->value('session_id'));
hpdl
1242
231
232           $Qwho = $osC_Database->query('delete from :table_whos_online where customer_id = :customer_id');
233           $Qwho->bindTable(':table_whos_online', TABLE_WHOS_ONLINE);
234           $Qwho->bindInt(':customer_id', $id);
235           $Qwho->execute();
236
237           if ( $osC_Database->isError() ) {
238             $error = true;
239           }
240         }
241       }
242
243       if ( $error === false ) {
244         $Qcustomers = $osC_Database->query('delete from :table_customers where customers_id = :customers_id');
245         $Qcustomers->bindTable(':table_customers', TABLE_CUSTOMERS);
246         $Qcustomers->bindInt(':customers_id', $id);
hpdl
1374
247         $Qcustomers->setLogging($_SESSION['module'], $id);
hpdl
1242
248         $Qcustomers->execute();
249
250         if ( $osC_Database->isError() ) {
251           $error = true;
252         }
253       }
254
255       if ( $error === false ) {
256         $osC_Database->commitTransaction();
257
258         return true;
259       }
260
261       $osC_Database->rollbackTransaction();
262
263       return false;
264     }
265
266     function saveAddress($id = null, $data) {
267       global $osC_Database;
268
269       $error = false;
270
271       $osC_Database->startTransaction();
272
273       $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');
274       $Qcustomer->bindTable(':table_customers', TABLE_CUSTOMERS);
275       $Qcustomer->bindInt(':customers_id', $data['customer_id']);
276       $Qcustomer->execute();
277
278       if ( is_numeric($id) ) {
279         $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');
280         $Qab->bindInt(':address_book_id', $id);
281       } else {
282         $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)');
283       }
284
285       $Qab->bindTable(':table_address_book', TABLE_ADDRESS_BOOK);
286       $Qab->bindInt(':customers_id', $data['customer_id']);
287       $Qab->bindValue(':entry_gender', $data['gender']);
288       $Qab->bindValue(':entry_company', $data['company']);
289       $Qab->bindValue(':entry_firstname', $data['firstname']);
290       $Qab->bindValue(':entry_lastname', $data['lastname']);
291       $Qab->bindValue(':entry_street_address', $data['street_address']);
292       $Qab->bindValue(':entry_suburb', $data['suburb']);
293       $Qab->bindValue(':entry_postcode', $data['postcode']);
294       $Qab->bindValue(':entry_city', $data['city']);
295       $Qab->bindValue(':entry_state', $data['state']);
296       $Qab->bindInt(':entry_country_id', $data['country_id']);
297       $Qab->bindInt(':entry_zone_id', $data['zone_id']);
298       $Qab->bindValue(':entry_telephone', $data['telephone']);
299       $Qab->bindValue(':entry_fax', $data['fax']);
hpdl
1374
300       $Qab->setLogging($_SESSION['module'], $id);
hpdl
1242
301       $Qab->execute();
302
303       if ( !$osC_Database->isError() ) {
304         if ( ( $Qcustomer->valueInt('customers_default_address_id') < 1 ) || ( $data['primary'] === true ) ) {
305           $address_book_id = ( is_numeric($id) ? $id : $osC_Database->nextID() );
306
307           $Qupdate = $osC_Database->query('update :table_customers set customers_default_address_id = :customers_default_address_id where customers_id = :customers_id');
308           $Qupdate->bindTable(':table_customers', TABLE_CUSTOMERS);
309           $Qupdate->bindInt(':customers_default_address_id', $address_book_id);
310           $Qupdate->bindInt(':customers_id', $data['customer_id']);
hpdl
1374
311           $Qupdate->setLogging($_SESSION['module'], $address_book_id);
hpdl
1242
312           $Qupdate->execute();
313
314           if ( $osC_Database->isError() ) {
315             $error = true;
316           }
317         }
318       } else {
319         $error = true;
320       }
321
322       if ( $error === false ) {
323         $osC_Database->commitTransaction();
324
325         return true;
326       }
327
328       $osC_Database->rollbackTransaction();
329
330       return false;
331     }
332
333     function deleteAddress($id, $customer_id = null) {
334       global $osC_Database;
335
336       $Qdelete = $osC_Database->query('delete from :table_address_book where address_book_id = :address_book_id');
337
338       if ( !empty($customer_id) ) {
339         $Qdelete->appendQuery('and customers_id = :customers_id');
340         $Qdelete->bindInt(':customers_id', $customer_id);
341       }
342
343       $Qdelete->bindTable(':table_address_book', TABLE_ADDRESS_BOOK);
344       $Qdelete->bindInt(':address_book_id', $id);
hpdl
1374
345       $Qdelete->setLogging($_SESSION['module'], $id);
hpdl
1242
346       $Qdelete->execute();
347
348       if ( !$osC_Database->isError() ) {
349         return true;
350       }
351
352       return false;
353     }
354   }
355 ?>