hpdl
|
176
|
1
|
<?php
|
|
2
|
/*
|
hpdl
|
182
|
3
|
$Id: account.php 1860 2009-03-06 23:25:01Z hpdl $
|
hpdl
|
176
|
4
|
|
|
5
|
osCommerce, Open Source E-Commerce Solutions
|
|
6
|
http://www.oscommerce.com
|
|
7
|
|
hpdl
|
1860
|
8
|
Copyright (c) 2007 osCommerce
|
hpdl
|
176
|
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
|
176
|
13
|
*/
|
|
14
|
|
hpdl
|
1860
|
15
|
/**
|
|
16
|
* The osC_Account class manages customer accounts
|
|
17
|
*/
|
|
18
|
|
hpdl
|
176
|
19
|
class osC_Account {
|
|
20
|
|
hpdl
|
1860
|
21
|
/**
|
|
22
|
* Returns the account information for the current customer
|
|
23
|
*
|
|
24
|
* @access public
|
|
25
|
* @return object
|
|
26
|
*/
|
|
27
|
|
|
28
|
public static function &getEntry() {
|
hpdl
|
179
|
29
|
global $osC_Database, $osC_Customer;
|
|
30
|
|
hpdl
|
754
|
31
|
$Qaccount = $osC_Database->query('select customers_gender, customers_firstname, customers_lastname, date_format(customers_dob, "%Y") as customers_dob_year, date_format(customers_dob, "%m") as customers_dob_month, date_format(customers_dob, "%d") as customers_dob_date, customers_email_address from :table_customers where customers_id = :customers_id');
|
hpdl
|
179
|
32
|
$Qaccount->bindTable(':table_customers', TABLE_CUSTOMERS);
|
hpdl
|
184
|
33
|
$Qaccount->bindInt(':customers_id', $osC_Customer->getID());
|
hpdl
|
179
|
34
|
$Qaccount->execute();
|
|
35
|
|
|
36
|
return $Qaccount;
|
|
37
|
}
|
|
38
|
|
hpdl
|
1860
|
39
|
/**
|
|
40
|
* Returns the customer ID from a given email address
|
|
41
|
*
|
|
42
|
* @param string $email_address The customers email address
|
|
43
|
* @access public
|
|
44
|
*/
|
|
45
|
|
|
46
|
public static function getID($email_address) {
|
hpdl
|
179
|
47
|
global $osC_Database;
|
|
48
|
|
|
49
|
$Quser = $osC_Database->query('select customers_id from :table_customers where customers_email_address = :customers_email_address limit 1');
|
|
50
|
$Quser->bindTable(':table_customers', TABLE_CUSTOMERS);
|
|
51
|
$Quser->bindValue(':customers_email_address', $email_address);
|
|
52
|
$Quser->execute();
|
|
53
|
|
hpdl
|
1860
|
54
|
if ( $Quser->numberOfRows() === 1 ) {
|
hpdl
|
179
|
55
|
return $Quser->valueInt('customers_id');
|
|
56
|
}
|
|
57
|
|
|
58
|
return false;
|
|
59
|
}
|
|
60
|
|
hpdl
|
1860
|
61
|
/**
|
|
62
|
* Stores a new customer account entry in the database
|
|
63
|
*
|
|
64
|
* @param array $data An array containing the customers information
|
|
65
|
* @access public
|
|
66
|
* @return boolean
|
|
67
|
*/
|
|
68
|
|
|
69
|
public static function createEntry($data) {
|
hpdl
|
443
|
70
|
global $osC_Database, $osC_Session, $osC_Language, $osC_ShoppingCart, $osC_Customer, $osC_NavigationHistory;
|
hpdl
|
206
|
71
|
|
hpdl
|
814
|
72
|
$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, number_of_logons, date_account_created) values (:customers_firstname, :customers_lastname, :customers_email_address, :customers_newsletter, :customers_status, :customers_ip_address, :customers_password, :customers_gender, :customers_dob, :number_of_logons, :date_account_created)');
|
hpdl
|
206
|
73
|
$Qcustomer->bindTable(':table_customers', TABLE_CUSTOMERS);
|
|
74
|
$Qcustomer->bindValue(':customers_firstname', $data['firstname']);
|
|
75
|
$Qcustomer->bindValue(':customers_lastname', $data['lastname']);
|
|
76
|
$Qcustomer->bindValue(':customers_email_address', $data['email_address']);
|
|
77
|
$Qcustomer->bindValue(':customers_newsletter', (isset($data['newsletter']) && ($data['newsletter'] == '1') ? '1' : ''));
|
|
78
|
$Qcustomer->bindValue(':customers_status', '1');
|
hpdl
|
757
|
79
|
$Qcustomer->bindValue(':customers_ip_address', osc_get_ip_address());
|
|
80
|
$Qcustomer->bindValue(':customers_password', osc_encrypt_string($data['password']));
|
hpdl
|
206
|
81
|
$Qcustomer->bindValue(':customers_gender', (((ACCOUNT_GENDER > -1) && isset($data['gender']) && (($data['gender'] == 'm') || ($data['gender'] == 'f'))) ? $data['gender'] : ''));
|
hpdl
|
554
|
82
|
$Qcustomer->bindValue(':customers_dob', ((ACCOUNT_DATE_OF_BIRTH == '1') ? date('Ymd', $data['dob']) : ''));
|
hpdl
|
814
|
83
|
$Qcustomer->bindInt(':number_of_logons', 0);
|
|
84
|
$Qcustomer->bindRaw(':date_account_created', 'now()');
|
hpdl
|
206
|
85
|
$Qcustomer->execute();
|
|
86
|
|
hpdl
|
1860
|
87
|
if ( $Qcustomer->affectedRows() === 1 ) {
|
hpdl
|
206
|
88
|
$customer_id = $osC_Database->nextID();
|
|
89
|
|
hpdl
|
1860
|
90
|
if ( SERVICE_SESSION_REGENERATE_ID == '1' ) {
|
hpdl
|
814
|
91
|
$osC_Session->recreate();
|
|
92
|
}
|
hpdl
|
206
|
93
|
|
hpdl
|
814
|
94
|
$osC_Customer->setCustomerData($customer_id);
|
hpdl
|
206
|
95
|
|
|
96
|
// restore cart contents
|
hpdl
|
814
|
97
|
$osC_ShoppingCart->synchronizeWithDatabase();
|
hpdl
|
206
|
98
|
|
hpdl
|
814
|
99
|
$osC_NavigationHistory->removeCurrentPage();
|
hpdl
|
206
|
100
|
|
hpdl
|
1860
|
101
|
// build the welcome email content
|
|
102
|
if ( (ACCOUNT_GENDER > -1) && isset($data['gender']) ) {
|
|
103
|
if ( $data['gender'] == 'm' ) {
|
hpdl
|
814
|
104
|
$email_text = sprintf($osC_Language->get('email_addressing_gender_male'), $osC_Customer->getLastName()) . "\n\n";
|
|
105
|
} else {
|
|
106
|
$email_text = sprintf($osC_Language->get('email_addressing_gender_female'), $osC_Customer->getLastName()) . "\n\n";
|
|
107
|
}
|
|
108
|
} else {
|
|
109
|
$email_text = sprintf($osC_Language->get('email_addressing_gender_unknown'), $osC_Customer->getName()) . "\n\n";
|
|
110
|
}
|
hpdl
|
206
|
111
|
|
hpdl
|
814
|
112
|
$email_text .= sprintf($osC_Language->get('email_create_account_body'), STORE_NAME, STORE_OWNER_EMAIL_ADDRESS);
|
hpdl
|
206
|
113
|
|
hpdl
|
814
|
114
|
osc_email($osC_Customer->getName(), $osC_Customer->getEmailAddress(), sprintf($osC_Language->get('email_create_account_subject'), STORE_NAME), $email_text, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS);
|
hpdl
|
410
|
115
|
|
hpdl
|
814
|
116
|
return true;
|
hpdl
|
206
|
117
|
}
|
|
118
|
|
|
119
|
return false;
|
|
120
|
}
|
|
121
|
|
hpdl
|
1860
|
122
|
/**
|
|
123
|
* Update the current customer account record in the database
|
|
124
|
*
|
|
125
|
* @param array $data An array containing the customer account information
|
|
126
|
* @access public
|
|
127
|
* @return boolean
|
|
128
|
*/
|
|
129
|
|
|
130
|
public static function saveEntry($data) {
|
hpdl
|
180
|
131
|
global $osC_Database, $osC_Customer;
|
|
132
|
|
hpdl
|
814
|
133
|
$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, date_account_last_modified = :date_account_last_modified where customers_id = :customers_id');
|
hpdl
|
180
|
134
|
$Qcustomer->bindTable(':table_customers', TABLE_CUSTOMERS);
|
|
135
|
$Qcustomer->bindValue(':customers_gender', ((ACCOUNT_GENDER > -1) && isset($data['gender']) && (($data['gender'] == 'm') || ($data['gender'] == 'f'))) ? $data['gender'] : '');
|
|
136
|
$Qcustomer->bindValue(':customers_firstname', $data['firstname']);
|
|
137
|
$Qcustomer->bindValue(':customers_lastname', $data['lastname']);
|
|
138
|
$Qcustomer->bindValue(':customers_email_address', $data['email_address']);
|
hpdl
|
554
|
139
|
$Qcustomer->bindValue(':customers_dob', (ACCOUNT_DATE_OF_BIRTH == '1') ? date('Ymd', $data['dob']) : '');
|
hpdl
|
814
|
140
|
$Qcustomer->bindRaw(':date_account_last_modified', 'now()');
|
hpdl
|
184
|
141
|
$Qcustomer->bindInt(':customers_id', $osC_Customer->getID());
|
hpdl
|
180
|
142
|
$Qcustomer->execute();
|
|
143
|
|
hpdl
|
1860
|
144
|
return ( $Qcustomer->affectedRows() === 1 );
|
hpdl
|
180
|
145
|
}
|
|
146
|
|
hpdl
|
1860
|
147
|
/**
|
|
148
|
* Updates the password in a customers account
|
|
149
|
*
|
|
150
|
* @param string $password The new password
|
|
151
|
* @param integer $customer_id The ID of the customer account to update
|
|
152
|
* @access public
|
|
153
|
* @return boolean
|
|
154
|
*/
|
|
155
|
|
|
156
|
public static function savePassword($password, $customer_id = null) {
|
hpdl
|
181
|
157
|
global $osC_Database, $osC_Customer;
|
|
158
|
|
hpdl
|
1860
|
159
|
if ( !is_numeric($customer_id) ) {
|
hpdl
|
207
|
160
|
$customer_id = $osC_Customer->getID();
|
|
161
|
}
|
|
162
|
|
hpdl
|
814
|
163
|
$Qcustomer = $osC_Database->query('update :table_customers set customers_password = :customers_password, date_account_last_modified = :date_account_last_modified where customers_id = :customers_id');
|
hpdl
|
181
|
164
|
$Qcustomer->bindTable(':table_customers', TABLE_CUSTOMERS);
|
hpdl
|
757
|
165
|
$Qcustomer->bindValue(':customers_password', osc_encrypt_string($password));
|
hpdl
|
814
|
166
|
$Qcustomer->bindRaw(':date_account_last_modified', 'now()');
|
hpdl
|
207
|
167
|
$Qcustomer->bindInt(':customers_id', $customer_id);
|
hpdl
|
181
|
168
|
$Qcustomer->execute();
|
|
169
|
|
hpdl
|
1860
|
170
|
return ( $Qcustomer->affectedRows() === 1 );
|
hpdl
|
181
|
171
|
}
|
|
172
|
|
hpdl
|
1860
|
173
|
/**
|
|
174
|
* Checks if a customer account record exists with the provided e-mail address
|
|
175
|
*
|
|
176
|
* @param string $email_address The e-mail address to check for
|
|
177
|
* @access public
|
|
178
|
* @return boolean
|
|
179
|
*/
|
|
180
|
|
|
181
|
public static function checkEntry($email_address) {
|
hpdl
|
176
|
182
|
global $osC_Database;
|
|
183
|
|
|
184
|
$Qcheck = $osC_Database->query('select customers_id from :table_customers where customers_email_address = :customers_email_address limit 1');
|
|
185
|
$Qcheck->bindTable(':table_customers', TABLE_CUSTOMERS);
|
|
186
|
$Qcheck->bindValue(':customers_email_address', $email_address);
|
|
187
|
$Qcheck->execute();
|
|
188
|
|
hpdl
|
1860
|
189
|
return ( $Qcheck->numberOfRows() === 1 );
|
hpdl
|
176
|
190
|
}
|
|
191
|
|
hpdl
|
1860
|
192
|
/**
|
|
193
|
* Checks if a password matches the current or provided customer account
|
|
194
|
*
|
|
195
|
* @param string $password The unencrypted password to confirm
|
|
196
|
* @param string $email_address The email address of the customer account to check against
|
|
197
|
* @access public
|
|
198
|
* @return boolean
|
|
199
|
*/
|
|
200
|
|
|
201
|
public static function checkPassword($password, $email_address = null) {
|
hpdl
|
181
|
202
|
global $osC_Database, $osC_Customer;
|
hpdl
|
176
|
203
|
|
hpdl
|
1860
|
204
|
if ( empty($email_address) ) {
|
hpdl
|
181
|
205
|
$Qcheck = $osC_Database->query('select customers_password from :table_customers where customers_id = :customers_id');
|
|
206
|
$Qcheck->bindTable(':table_customers', TABLE_CUSTOMERS);
|
hpdl
|
184
|
207
|
$Qcheck->bindInt(':customers_id', $osC_Customer->getID());
|
hpdl
|
181
|
208
|
$Qcheck->execute();
|
|
209
|
} else {
|
|
210
|
$Qcheck = $osC_Database->query('select customers_password from :table_customers where customers_email_address = :customers_email_address limit 1');
|
|
211
|
$Qcheck->bindTable(':table_customers', TABLE_CUSTOMERS);
|
|
212
|
$Qcheck->bindValue(':customers_email_address', $email_address);
|
|
213
|
$Qcheck->execute();
|
|
214
|
}
|
hpdl
|
176
|
215
|
|
hpdl
|
1860
|
216
|
if ( $Qcheck->numberOfRows() === 1 ) {
|
hpdl
|
176
|
217
|
if ( (strlen($password) > 0) && (strlen($Qcheck->value('customers_password')) > 0) ) {
|
|
218
|
$stack = explode(':', $Qcheck->value('customers_password'));
|
|
219
|
|
hpdl
|
1860
|
220
|
if ( sizeof($stack) === 2 ) {
|
|
221
|
return ( md5($stack[1] . $password) == $stack[0] );
|
hpdl
|
176
|
222
|
}
|
|
223
|
}
|
|
224
|
}
|
|
225
|
|
|
226
|
return false;
|
|
227
|
}
|
hpdl
|
180
|
228
|
|
hpdl
|
1860
|
229
|
/**
|
|
230
|
* Checks if an e-mail address already exists in another customer account record
|
|
231
|
*
|
|
232
|
* @param string $email_address The e-mail address to check
|
|
233
|
* @access public
|
|
234
|
* @return boolean
|
|
235
|
*/
|
|
236
|
|
|
237
|
public static function checkDuplicateEntry($email_address) {
|
hpdl
|
180
|
238
|
global $osC_Database, $osC_Customer;
|
|
239
|
|
|
240
|
$Qcheck = $osC_Database->query('select customers_id from :table_customers where customers_email_address = :customers_email_address and customers_id != :customers_id limit 1');
|
|
241
|
$Qcheck->bindTable(':table_customers', TABLE_CUSTOMERS);
|
|
242
|
$Qcheck->bindValue(':customers_email_address', $email_address);
|
hpdl
|
184
|
243
|
$Qcheck->bindInt(':customers_id', $osC_Customer->getID());
|
hpdl
|
180
|
244
|
$Qcheck->execute();
|
|
245
|
|
hpdl
|
1860
|
246
|
return ( $Qcheck->numberOfRows() === 1 );
|
hpdl
|
180
|
247
|
}
|
hpdl
|
176
|
248
|
}
|
|
249
|
?>
|