  |
1 | 1 | | <?php |
| |
2 | 2 | | /* |
  |
3 | | - | $Id: account.php 1498 2007-03-29 14:04:50Z hpdl $ |
| |
| 3 | + | $Id: account.php 1860 2009-03-06 23:25:01Z hpdl $ |
|
4 | 4 | | |
| |
5 | 5 | | osCommerce, Open Source E-Commerce Solutions |
| |
6 | 6 | | http://www.oscommerce.com |
| |
7 | 7 | | |
  |
8 | | - | Copyright (c) 2005 osCommerce |
| |
| 8 | + | Copyright (c) 2007 osCommerce |
|
9 | 9 | | |
| |
10 | 10 | | This program is free software; you can redistribute it and/or modify |
| |
11 | 11 | | it under the terms of the GNU General Public License v2 (1991) |
| |
12 | 12 | | as published by the Free Software Foundation. |
| |
13 | 13 | | */ |
| |
14 | 14 | | |
  |
| 15 | + | /** |
| |
| 16 | + | * The osC_Account class manages customer accounts |
| |
| 17 | + | */ |
| |
| 18 | + | |
|
15 | 19 | | class osC_Account { |
| |
16 | 20 | | |
  |
17 | | - | function &getEntry() { |
| |
| 21 | + | /** |
| |
| 22 | + | * Returns the account information for the current customer |
| |
| 23 | + | * |
| |
| 24 | + | * @access public |
| |
| 25 | + | * @return object |
| |
| 26 | + | */ |
| |
| 27 | + | |
| |
| 28 | + | public static function &getEntry() { |
|
18 | 29 | | global $osC_Database, $osC_Customer; |
| |
19 | 30 | | |
| |
20 | 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'); |
| |
|
|
 |
… |
|
25 | 36 | | return $Qaccount; |
| |
26 | 37 | | } |
| |
27 | 38 | | |
  |
28 | | - | function getID($email_address) { |
| |
| 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) { |
|
29 | 47 | | global $osC_Database; |
| |
30 | 48 | | |
| |
31 | 49 | | $Quser = $osC_Database->query('select customers_id from :table_customers where customers_email_address = :customers_email_address limit 1'); |
| |
32 | 50 | | $Quser->bindTable(':table_customers', TABLE_CUSTOMERS); |
| |
33 | 51 | | $Quser->bindValue(':customers_email_address', $email_address); |
| |
34 | 52 | | $Quser->execute(); |
| |
35 | 53 | | |
  |
36 | | - | if ($Quser->numberOfRows() === 1) { |
| |
| 54 | + | if ( $Quser->numberOfRows() === 1 ) { |
|
37 | 55 | | return $Quser->valueInt('customers_id'); |
| |
38 | 56 | | } |
| |
39 | 57 | | |
| |
40 | 58 | | return false; |
| |
41 | 59 | | } |
| |
42 | 60 | | |
  |
43 | | - | function createEntry($data) { |
| |
| 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) { |
|
44 | 70 | | global $osC_Database, $osC_Session, $osC_Language, $osC_ShoppingCart, $osC_Customer, $osC_NavigationHistory; |
| |
45 | 71 | | |
| |
46 | 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)'); |
| |
|
|
 |
… |
|
58 | 84 | | $Qcustomer->bindRaw(':date_account_created', 'now()'); |
| |
59 | 85 | | $Qcustomer->execute(); |
| |
60 | 86 | | |
  |
61 | | - | if ($Qcustomer->affectedRows() === 1) { |
| |
| 87 | + | if ( $Qcustomer->affectedRows() === 1 ) { |
|
62 | 88 | | $customer_id = $osC_Database->nextID(); |
| |
63 | 89 | | |
  |
64 | | - | if (SERVICE_SESSION_REGENERATE_ID == '1') { |
| |
| 90 | + | if ( SERVICE_SESSION_REGENERATE_ID == '1' ) { |
|
65 | 91 | | $osC_Session->recreate(); |
| |
66 | 92 | | } |
| |
67 | 93 | | |
| |
|
|
 |
… |
|
72 | 98 | | |
| |
73 | 99 | | $osC_NavigationHistory->removeCurrentPage(); |
| |
74 | 100 | | |
  |
75 | | - | // build the message content |
| |
76 | | - | if ((ACCOUNT_GENDER > -1) && isset($data['gender'])) { |
| |
77 | | - | if ($data['gender'] == 'm') { |
| |
| 101 | + | // build the welcome email content |
| |
| 102 | + | if ( (ACCOUNT_GENDER > -1) && isset($data['gender']) ) { |
| |
| 103 | + | if ( $data['gender'] == 'm' ) { |
|
78 | 104 | | $email_text = sprintf($osC_Language->get('email_addressing_gender_male'), $osC_Customer->getLastName()) . "\n\n"; |
| |
79 | 105 | | } else { |
| |
80 | 106 | | $email_text = sprintf($osC_Language->get('email_addressing_gender_female'), $osC_Customer->getLastName()) . "\n\n"; |
| |
|
|
 |
… |
|
93 | 119 | | return false; |
| |
94 | 120 | | } |
| |
95 | 121 | | |
  |
96 | | - | function saveEntry($data) { |
| |
| 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) { |
|
97 | 131 | | global $osC_Database, $osC_Customer; |
| |
98 | 132 | | |
| |
99 | 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'); |
| |
|
|
 |
… |
|
107 | 141 | | $Qcustomer->bindInt(':customers_id', $osC_Customer->getID()); |
| |
108 | 142 | | $Qcustomer->execute(); |
| |
109 | 143 | | |
  |
110 | | - | if ($Qcustomer->affectedRows() === 1) { |
| |
111 | | - | return true; |
| |
112 | | - | } |
| |
113 | | - | |
| |
114 | | - | return false; |
| |
| 144 | + | return ( $Qcustomer->affectedRows() === 1 ); |
|
115 | 145 | | } |
| |
116 | 146 | | |
  |
117 | | - | function savePassword($password, $customer_id = null) { |
| |
| 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) { |
|
118 | 157 | | global $osC_Database, $osC_Customer; |
| |
119 | 158 | | |
  |
120 | | - | if (is_numeric($customer_id) === false) { |
| |
| 159 | + | if ( !is_numeric($customer_id) ) { |
|
121 | 160 | | $customer_id = $osC_Customer->getID(); |
| |
122 | 161 | | } |
| |
123 | 162 | | |
| |
|
|
 |
… |
|
128 | 167 | | $Qcustomer->bindInt(':customers_id', $customer_id); |
| |
129 | 168 | | $Qcustomer->execute(); |
| |
130 | 169 | | |
  |
131 | | - | if ($Qcustomer->affectedRows() === 1) { |
| |
132 | | - | return true; |
| |
133 | | - | } |
| |
134 | | - | |
| |
135 | | - | return false; |
| |
| 170 | + | return ( $Qcustomer->affectedRows() === 1 ); |
|
136 | 171 | | } |
| |
137 | 172 | | |
  |
138 | | - | function checkEntry($email_address) { |
| |
| 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) { |
|
139 | 182 | | global $osC_Database; |
| |
140 | 183 | | |
| |
141 | 184 | | $Qcheck = $osC_Database->query('select customers_id from :table_customers where customers_email_address = :customers_email_address limit 1'); |
| |
142 | 185 | | $Qcheck->bindTable(':table_customers', TABLE_CUSTOMERS); |
| |
143 | 186 | | $Qcheck->bindValue(':customers_email_address', $email_address); |
| |
144 | 187 | | $Qcheck->execute(); |
| |
145 | 188 | | |
  |
146 | | - | if ($Qcheck->numberOfRows() === 1) { |
| |
147 | | - | return true; |
| |
148 | | - | } |
| |
149 | | - | |
| |
150 | | - | return false; |
| |
| 189 | + | return ( $Qcheck->numberOfRows() === 1 ); |
|
151 | 190 | | } |
| |
152 | 191 | | |
  |
153 | | - | function checkPassword($password, $email_address = null) { |
| |
| 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) { |
|
154 | 202 | | global $osC_Database, $osC_Customer; |
| |
155 | 203 | | |
  |
156 | | - | if ($email_address === null) { |
| |
| 204 | + | if ( empty($email_address) ) { |
|
157 | 205 | | $Qcheck = $osC_Database->query('select customers_password from :table_customers where customers_id = :customers_id'); |
| |
158 | 206 | | $Qcheck->bindTable(':table_customers', TABLE_CUSTOMERS); |
| |
159 | 207 | | $Qcheck->bindInt(':customers_id', $osC_Customer->getID()); |
| |
|
|
 |
… |
|
165 | 213 | | $Qcheck->execute(); |
| |
166 | 214 | | } |
| |
167 | 215 | | |
  |
168 | | - | if ($Qcheck->numberOfRows() === 1) { |
| |
| 216 | + | if ( $Qcheck->numberOfRows() === 1 ) { |
|
169 | 217 | | if ( (strlen($password) > 0) && (strlen($Qcheck->value('customers_password')) > 0) ) { |
| |
170 | 218 | | $stack = explode(':', $Qcheck->value('customers_password')); |
| |
171 | 219 | | |
  |
172 | | - | if (sizeof($stack) === 2) { |
| |
173 | | - | if (md5($stack[1] . $password) == $stack[0]) { |
| |
174 | | - | return true; |
| |
175 | | - | } |
| |
| 220 | + | if ( sizeof($stack) === 2 ) { |
| |
| 221 | + | return ( md5($stack[1] . $password) == $stack[0] ); |
|
176 | 222 | | } |
| |
177 | 223 | | } |
| |
178 | 224 | | } |
| |
179 | 225 | | |
| |
180 | 226 | | return false; |
| |
181 | 227 | | } |
| |
182 | 228 | | |
  |
183 | | - | function checkDuplicateEntry($email_address) { |
| |
| 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) { |
|
184 | 238 | | global $osC_Database, $osC_Customer; |
| |
185 | 239 | | |
| |
186 | 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'); |
| |
|
|
 |
… |
|
189 | 243 | | $Qcheck->bindInt(':customers_id', $osC_Customer->getID()); |
| |
190 | 244 | | $Qcheck->execute(); |
| |
191 | 245 | | |
  |
192 | | - | if ($Qcheck->numberOfRows() === 1) { |
| |
193 | | - | return true; |
| |
194 | | - | } |
| |
195 | | - | |
| |
196 | | - | return false; |
| |
| 246 | + | return ( $Qcheck->numberOfRows() === 1 ); |
  |
197 | 247 | | } |
| |
198 | 248 | | } |
| |
199 | 249 | | ?> |