Quick Search:

View

Revision:

Diff

Diff from 207 to:

Annotations

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

Annotated File View

hpdl
176
1 <?php
2 /*
hpdl
182
3   $Id: account.php 207 2005-09-25 23:29:31Z hpdl $
hpdl
176
4
5   osCommerce, Open Source E-Commerce Solutions
6   http://www.oscommerce.com
7
8   Copyright (c) 2005 osCommerce
9
10   Released under the GNU General Public License
11 */
12
13   class osC_Account {
14
hpdl
179
15     function &getEntry() {
16       global $osC_Database, $osC_Customer;
17
18       $Qaccount = $osC_Database->query('select customers_gender, customers_firstname, customers_lastname, unix_timestamp(customers_dob) as customers_dob, customers_email_address from :table_customers where customers_id = :customers_id');
19       $Qaccount->bindTable(':table_customers', TABLE_CUSTOMERS);
hpdl
184
20       $Qaccount->bindInt(':customers_id', $osC_Customer->getID());
hpdl
179
21       $Qaccount->execute();
22
23       return $Qaccount;
24     }
25
26     function getID($email_address) {
27       global $osC_Database;
28
29       $Quser = $osC_Database->query('select customers_id from :table_customers where customers_email_address = :customers_email_address limit 1');
30       $Quser->bindTable(':table_customers', TABLE_CUSTOMERS);
31       $Quser->bindValue(':customers_email_address', $email_address);
32       $Quser->execute();
33
34       if ($Quser->numberOfRows() === 1) {
35         return $Quser->valueInt('customers_id');
36       }
37
38       return false;
39     }
40
hpdl
206
41     function createEntry($data) {
42       global $osC_Database, $osC_Session, $osC_Customer, $osC_NavigationHistory;
43
44       $osC_Database->startTransaction();
45
46       $Qcustomer = $osC_Database->query('insert into :table_customers (customers_firstname, customers_lastname, customers_email_address, customers_newsletter, customers_status, customers_ip_address, customers_password, customers_gender, customers_dob) values (:customers_firstname, :customers_lastname, :customers_email_address, :customers_newsletter, :customers_status, :customers_ip_address, :customers_password, :customers_gender, :customers_dob)');
47       $Qcustomer->bindTable(':table_customers', TABLE_CUSTOMERS);
48       $Qcustomer->bindValue(':customers_firstname', $data['firstname']);
49       $Qcustomer->bindValue(':customers_lastname', $data['lastname']);
50       $Qcustomer->bindValue(':customers_email_address', $data['email_address']);
51       $Qcustomer->bindValue(':customers_newsletter', (isset($data['newsletter']) && ($data['newsletter'] == '1') ? '1' : ''));
52       $Qcustomer->bindValue(':customers_status', '1');
53       $Qcustomer->bindValue(':customers_ip_address', tep_get_ip_address());
54       $Qcustomer->bindValue(':customers_password', tep_encrypt_password($data['password']));
55       $Qcustomer->bindValue(':customers_gender', (((ACCOUNT_GENDER > -1) && isset($data['gender']) && (($data['gender'] == 'm') || ($data['gender'] == 'f'))) ? $data['gender'] : ''));
56       $Qcustomer->bindValue(':customers_dob', ((ACCOUNT_DATE_OF_BIRTH > -1) ? date('Ymd', $data['dob']) : ''));
57       $Qcustomer->execute();
58
59       if ($Qcustomer->affectedRows() === 1) {
60         $customer_id = $osC_Database->nextID();
61
62         $Qci = $osC_Database->query('insert into :table_customers_info (customers_info_id, customers_info_number_of_logons, customers_info_date_account_created) values (:customers_info_id, :customers_info_number_of_logons, :customers_info_date_account_created)');
63         $Qci->bindTable(':table_customers_info', TABLE_CUSTOMERS_INFO);
64         $Qci->bindInt(':customers_info_id', $customer_id);
65         $Qci->bindInt(':customers_info_number_of_logons', 0);
66         $Qci->bindRaw(':customers_info_date_account_created', 'now()');
67         $Qci->execute();
68
69         if ($Qci->affectedRows() === 1) {
70           $osC_Database->commitTransaction();
71
72           if (SERVICE_SESSION_REGENERATE_ID == 'True') {
73             $osC_Session->recreate();
74           }
75
76           $osC_Customer->setCustomerData($customer_id);
77
78 // restore cart contents
79           $_SESSION['cart']->restore_contents();
80
81           $osC_NavigationHistory->removeCurrentPage();
82
83 // build the message content
84           if ((ACCOUNT_GENDER > -1) && isset($data['gender'])) {
85              if ($data['gender'] == 'm') {
86                $email_text = sprintf(EMAIL_GREET_MR, $osC_Customer->getLastName());
87              } else {
88                $email_text = sprintf(EMAIL_GREET_MS, $osC_Customer->getLastName());
89              }
90           } else {
91             $email_text = sprintf(EMAIL_GREET_NONE, $osC_Customer->getName());
92           }
93
94           $email_text .= EMAIL_WELCOME . EMAIL_TEXT . EMAIL_CONTACT . EMAIL_WARNING;
95           tep_mail($osC_Customer->getName(), $osC_Customer->getEmailAddress(), EMAIL_SUBJECT, $email_text, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS);
96
97           return true;
98         } else {
99           $osC_Database->rollbackTransaction();
100         }
101       } else {
102         $osC_Database->rollbackTransaction();
103       }
104
105       return false;
106     }
107
hpdl
180
108     function saveEntry($data) {
109       global $osC_Database, $osC_Customer;
110
111       $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 where customers_id = :customers_id');
112       $Qcustomer->bindTable(':table_customers', TABLE_CUSTOMERS);
113       $Qcustomer->bindValue(':customers_gender', ((ACCOUNT_GENDER > -1) && isset($data['gender']) && (($data['gender'] == 'm') || ($data['gender'] == 'f'))) ? $data['gender'] : '');
114       $Qcustomer->bindValue(':customers_firstname', $data['firstname']);
115       $Qcustomer->bindValue(':customers_lastname', $data['lastname']);
116       $Qcustomer->bindValue(':customers_email_address', $data['email_address']);
117       $Qcustomer->bindValue(':customers_dob', (ACCOUNT_DATE_OF_BIRTH > -1) ? date('Ymd', $data['dob']) : '');
hpdl
184
118       $Qcustomer->bindInt(':customers_id', $osC_Customer->getID());
hpdl
180
119       $Qcustomer->execute();
120
121       if ($Qcustomer->affectedRows() === 1) {
122         $Qupdate = $osC_Database->query('update :table_customers_info set customers_info_date_account_last_modified = now() where customers_info_id = :customers_info_id');
123         $Qupdate->bindTable(':table_customers_info', TABLE_CUSTOMERS_INFO);
hpdl
184
124         $Qupdate->bindInt(':customers_info_id', $osC_Customer->getID());
hpdl
180
125         $Qupdate->execute();
126
127         return true;
128       }
129
130       return false;
131     }
132
hpdl
207
133     function savePassword($password, $customer_id = null) {
hpdl
181
134       global $osC_Database, $osC_Customer;
135
hpdl
207
136       if (is_numeric($customer_id) === false) {
137         $customer_id = $osC_Customer->getID();
138       }
139
hpdl
181
140       $Qcustomer = $osC_Database->query('update :table_customers set customers_password = :customers_password where customers_id = :customers_id');
141       $Qcustomer->bindTable(':table_customers', TABLE_CUSTOMERS);
142       $Qcustomer->bindValue(':customers_password', tep_encrypt_password($password));
hpdl
207
143       $Qcustomer->bindInt(':customers_id', $customer_id);
hpdl
181
144       $Qcustomer->execute();
145
146       if ($Qcustomer->affectedRows() === 1) {
147         $Qupdate = $osC_Database->query('update :table_customers_info set customers_info_date_account_last_modified = now() where customers_info_id = :customers_info_id');
148         $Qupdate->bindTable(':table_customers_info', TABLE_CUSTOMERS_INFO);
hpdl
207
149         $Qupdate->bindInt(':customers_info_id', $customer_id);
hpdl
181
150         $Qupdate->execute();
151
152         return true;
153       }
154
155       return false;
156     }
157
hpdl
176
158     function checkEntry($email_address) {
159       global $osC_Database;
160
161       $Qcheck = $osC_Database->query('select customers_id from :table_customers where customers_email_address = :customers_email_address limit 1');
162       $Qcheck->bindTable(':table_customers', TABLE_CUSTOMERS);
163       $Qcheck->bindValue(':customers_email_address', $email_address);
164       $Qcheck->execute();
165
166       if ($Qcheck->numberOfRows() === 1) {
167         return true;
168       }
169
170       return false;
171     }
172
hpdl
181
173     function checkPassword($password, $email_address = null) {
174       global $osC_Database, $osC_Customer;
hpdl
176
175
hpdl
181
176       if ($email_address === null) {
177         $Qcheck = $osC_Database->query('select customers_password from :table_customers where customers_id = :customers_id');
178         $Qcheck->bindTable(':table_customers', TABLE_CUSTOMERS);
hpdl
184
179         $Qcheck->bindInt(':customers_id', $osC_Customer->getID());
hpdl
181
180         $Qcheck->execute();
181       } else {
182         $Qcheck = $osC_Database->query('select customers_password from :table_customers where customers_email_address = :customers_email_address limit 1');
183         $Qcheck->bindTable(':table_customers', TABLE_CUSTOMERS);
184         $Qcheck->bindValue(':customers_email_address', $email_address);
185         $Qcheck->execute();
186       }
hpdl
176
187
188       if ($Qcheck->numberOfRows() === 1) {
189         if ( (strlen($password) > 0) && (strlen($Qcheck->value('customers_password')) > 0) ) {
190           $stack = explode(':', $Qcheck->value('customers_password'));
191
192           if (sizeof($stack) === 2) {
193             if (md5($stack[1] . $password) == $stack[0]) {
194               return true;
195             }
196           }
197         }
198       }
199
200       return false;
201     }
hpdl
180
202
203     function checkDuplicateEntry($email_address) {
204       global $osC_Database, $osC_Customer;
205
206       $Qcheck = $osC_Database->query('select customers_id from :table_customers where customers_email_address = :customers_email_address and customers_id != :customers_id limit 1');
207       $Qcheck->bindTable(':table_customers', TABLE_CUSTOMERS);
208       $Qcheck->bindValue(':customers_email_address', $email_address);
hpdl
184
209       $Qcheck->bindInt(':customers_id', $osC_Customer->getID());
hpdl
180
210       $Qcheck->execute();
211
212       if ($Qcheck->numberOfRows() === 1) {
213         return true;
214       }
215
216       return false;
217     }
hpdl
176
218   }
219 ?>