hpdl
|
176
|
1
|
<?php
|
|
2
|
/*
|
hpdl
|
182
|
3
|
$Id: account.php 418 2006-01-28 12:46:34Z 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) {
|
hpdl
|
418
|
42
|
global $osC_Database, $osC_Session, $osC_Language, $osC_ShoppingCart, $osC_Customer, $osC_NavigationHistory;
|
hpdl
|
206
|
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
|
hpdl
|
418
|
79
|
$osC_ShoppingCart->synchronizeWithDatabase();
|
hpdl
|
206
|
80
|
|
|
81
|
$osC_NavigationHistory->removeCurrentPage();
|
|
82
|
|
|
83
|
// build the message content
|
|
84
|
if ((ACCOUNT_GENDER > -1) && isset($data['gender'])) {
|
|
85
|
if ($data['gender'] == 'm') {
|
hpdl
|
387
|
86
|
$email_text = sprintf($osC_Language->get('email_addressing_gender_male'), $osC_Customer->getLastName()) . "\n\n";
|
hpdl
|
206
|
87
|
} else {
|
hpdl
|
387
|
88
|
$email_text = sprintf($osC_Language->get('email_addressing_gender_female'), $osC_Customer->getLastName()) . "\n\n";
|
hpdl
|
206
|
89
|
}
|
|
90
|
} else {
|
hpdl
|
387
|
91
|
$email_text = sprintf($osC_Language->get('email_addressing_gender_unknown'), $osC_Customer->getName()) . "\n\n";
|
hpdl
|
206
|
92
|
}
|
|
93
|
|
hpdl
|
387
|
94
|
$email_text .= sprintf($osC_Language->get('email_create_account_body'), STORE_NAME, STORE_OWNER_EMAIL_ADDRESS);
|
hpdl
|
206
|
95
|
|
hpdl
|
387
|
96
|
tep_mail($osC_Customer->getName(), $osC_Customer->getEmailAddress(), sprintf($osC_Language->get('email_create_account_subject'), STORE_NAME), $email_text, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS);
|
|
97
|
|
hpdl
|
206
|
98
|
return true;
|
|
99
|
} else {
|
|
100
|
$osC_Database->rollbackTransaction();
|
|
101
|
}
|
|
102
|
} else {
|
|
103
|
$osC_Database->rollbackTransaction();
|
|
104
|
}
|
|
105
|
|
|
106
|
return false;
|
|
107
|
}
|
|
108
|
|
hpdl
|
180
|
109
|
function saveEntry($data) {
|
|
110
|
global $osC_Database, $osC_Customer;
|
|
111
|
|
|
112
|
$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');
|
|
113
|
$Qcustomer->bindTable(':table_customers', TABLE_CUSTOMERS);
|
|
114
|
$Qcustomer->bindValue(':customers_gender', ((ACCOUNT_GENDER > -1) && isset($data['gender']) && (($data['gender'] == 'm') || ($data['gender'] == 'f'))) ? $data['gender'] : '');
|
|
115
|
$Qcustomer->bindValue(':customers_firstname', $data['firstname']);
|
|
116
|
$Qcustomer->bindValue(':customers_lastname', $data['lastname']);
|
|
117
|
$Qcustomer->bindValue(':customers_email_address', $data['email_address']);
|
|
118
|
$Qcustomer->bindValue(':customers_dob', (ACCOUNT_DATE_OF_BIRTH > -1) ? date('Ymd', $data['dob']) : '');
|
hpdl
|
184
|
119
|
$Qcustomer->bindInt(':customers_id', $osC_Customer->getID());
|
hpdl
|
180
|
120
|
$Qcustomer->execute();
|
|
121
|
|
|
122
|
if ($Qcustomer->affectedRows() === 1) {
|
|
123
|
$Qupdate = $osC_Database->query('update :table_customers_info set customers_info_date_account_last_modified = now() where customers_info_id = :customers_info_id');
|
|
124
|
$Qupdate->bindTable(':table_customers_info', TABLE_CUSTOMERS_INFO);
|
hpdl
|
184
|
125
|
$Qupdate->bindInt(':customers_info_id', $osC_Customer->getID());
|
hpdl
|
180
|
126
|
$Qupdate->execute();
|
|
127
|
|
|
128
|
return true;
|
|
129
|
}
|
|
130
|
|
|
131
|
return false;
|
|
132
|
}
|
|
133
|
|
hpdl
|
207
|
134
|
function savePassword($password, $customer_id = null) {
|
hpdl
|
181
|
135
|
global $osC_Database, $osC_Customer;
|
|
136
|
|
hpdl
|
207
|
137
|
if (is_numeric($customer_id) === false) {
|
|
138
|
$customer_id = $osC_Customer->getID();
|
|
139
|
}
|
|
140
|
|
hpdl
|
181
|
141
|
$Qcustomer = $osC_Database->query('update :table_customers set customers_password = :customers_password where customers_id = :customers_id');
|
|
142
|
$Qcustomer->bindTable(':table_customers', TABLE_CUSTOMERS);
|
|
143
|
$Qcustomer->bindValue(':customers_password', tep_encrypt_password($password));
|
hpdl
|
207
|
144
|
$Qcustomer->bindInt(':customers_id', $customer_id);
|
hpdl
|
181
|
145
|
$Qcustomer->execute();
|
|
146
|
|
|
147
|
if ($Qcustomer->affectedRows() === 1) {
|
|
148
|
$Qupdate = $osC_Database->query('update :table_customers_info set customers_info_date_account_last_modified = now() where customers_info_id = :customers_info_id');
|
|
149
|
$Qupdate->bindTable(':table_customers_info', TABLE_CUSTOMERS_INFO);
|
hpdl
|
207
|
150
|
$Qupdate->bindInt(':customers_info_id', $customer_id);
|
hpdl
|
181
|
151
|
$Qupdate->execute();
|
|
152
|
|
|
153
|
return true;
|
|
154
|
}
|
|
155
|
|
|
156
|
return false;
|
|
157
|
}
|
|
158
|
|
hpdl
|
176
|
159
|
function checkEntry($email_address) {
|
|
160
|
global $osC_Database;
|
|
161
|
|
|
162
|
$Qcheck = $osC_Database->query('select customers_id from :table_customers where customers_email_address = :customers_email_address limit 1');
|
|
163
|
$Qcheck->bindTable(':table_customers', TABLE_CUSTOMERS);
|
|
164
|
$Qcheck->bindValue(':customers_email_address', $email_address);
|
|
165
|
$Qcheck->execute();
|
|
166
|
|
|
167
|
if ($Qcheck->numberOfRows() === 1) {
|
|
168
|
return true;
|
|
169
|
}
|
|
170
|
|
|
171
|
return false;
|
|
172
|
}
|
|
173
|
|
hpdl
|
181
|
174
|
function checkPassword($password, $email_address = null) {
|
|
175
|
global $osC_Database, $osC_Customer;
|
hpdl
|
176
|
176
|
|
hpdl
|
181
|
177
|
if ($email_address === null) {
|
|
178
|
$Qcheck = $osC_Database->query('select customers_password from :table_customers where customers_id = :customers_id');
|
|
179
|
$Qcheck->bindTable(':table_customers', TABLE_CUSTOMERS);
|
hpdl
|
184
|
180
|
$Qcheck->bindInt(':customers_id', $osC_Customer->getID());
|
hpdl
|
181
|
181
|
$Qcheck->execute();
|
|
182
|
} else {
|
|
183
|
$Qcheck = $osC_Database->query('select customers_password from :table_customers where customers_email_address = :customers_email_address limit 1');
|
|
184
|
$Qcheck->bindTable(':table_customers', TABLE_CUSTOMERS);
|
|
185
|
$Qcheck->bindValue(':customers_email_address', $email_address);
|
|
186
|
$Qcheck->execute();
|
|
187
|
}
|
hpdl
|
176
|
188
|
|
|
189
|
if ($Qcheck->numberOfRows() === 1) {
|
|
190
|
if ( (strlen($password) > 0) && (strlen($Qcheck->value('customers_password')) > 0) ) {
|
|
191
|
$stack = explode(':', $Qcheck->value('customers_password'));
|
|
192
|
|
|
193
|
if (sizeof($stack) === 2) {
|
|
194
|
if (md5($stack[1] . $password) == $stack[0]) {
|
|
195
|
return true;
|
|
196
|
}
|
|
197
|
}
|
|
198
|
}
|
|
199
|
}
|
|
200
|
|
|
201
|
return false;
|
|
202
|
}
|
hpdl
|
180
|
203
|
|
|
204
|
function checkDuplicateEntry($email_address) {
|
|
205
|
global $osC_Database, $osC_Customer;
|
|
206
|
|
|
207
|
$Qcheck = $osC_Database->query('select customers_id from :table_customers where customers_email_address = :customers_email_address and customers_id != :customers_id limit 1');
|
|
208
|
$Qcheck->bindTable(':table_customers', TABLE_CUSTOMERS);
|
|
209
|
$Qcheck->bindValue(':customers_email_address', $email_address);
|
hpdl
|
184
|
210
|
$Qcheck->bindInt(':customers_id', $osC_Customer->getID());
|
hpdl
|
180
|
211
|
$Qcheck->execute();
|
|
212
|
|
|
213
|
if ($Qcheck->numberOfRows() === 1) {
|
|
214
|
return true;
|
|
215
|
}
|
|
216
|
|
|
217
|
return false;
|
|
218
|
}
|
hpdl
|
176
|
219
|
}
|
|
220
|
?>
|