Quick Search:

View

Revision:

Diff

Diff from 814 to:

Annotations

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

Annotated File View

hpdl
176
1 <?php
2 /*
hpdl
182
3   $Id: account.php 814 2006-08-27 15:28:23Z 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
hpdl
754
18       $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
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
443
42       global $osC_Database, $osC_Session, $osC_Language, $osC_ShoppingCart, $osC_Customer, $osC_NavigationHistory;
hpdl
206
43
hpdl
814
44       $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
45       $Qcustomer->bindTable(':table_customers', TABLE_CUSTOMERS);
46       $Qcustomer->bindValue(':customers_firstname', $data['firstname']);
47       $Qcustomer->bindValue(':customers_lastname', $data['lastname']);
48       $Qcustomer->bindValue(':customers_email_address', $data['email_address']);
49       $Qcustomer->bindValue(':customers_newsletter', (isset($data['newsletter']) && ($data['newsletter'] == '1') ? '1' : ''));
50       $Qcustomer->bindValue(':customers_status', '1');
hpdl
757
51       $Qcustomer->bindValue(':customers_ip_address', osc_get_ip_address());
52       $Qcustomer->bindValue(':customers_password', osc_encrypt_string($data['password']));
hpdl
206
53       $Qcustomer->bindValue(':customers_gender', (((ACCOUNT_GENDER > -1) && isset($data['gender']) && (($data['gender'] == 'm') || ($data['gender'] == 'f'))) ? $data['gender'] : ''));
hpdl
554
54       $Qcustomer->bindValue(':customers_dob', ((ACCOUNT_DATE_OF_BIRTH == '1') ? date('Ymd', $data['dob']) : ''));
hpdl
814
55       $Qcustomer->bindInt(':number_of_logons', 0);
56       $Qcustomer->bindRaw(':date_account_created', 'now()');
hpdl
206
57       $Qcustomer->execute();
58
59       if ($Qcustomer->affectedRows() === 1) {
60         $customer_id = $osC_Database->nextID();
61
hpdl
814
62         if (SERVICE_SESSION_REGENERATE_ID == '1') {
63           $osC_Session->recreate();
64         }
hpdl
206
65
hpdl
814
66         $osC_Customer->setCustomerData($customer_id);
hpdl
206
67
68 // restore cart contents
hpdl
814
69         $osC_ShoppingCart->synchronizeWithDatabase();
hpdl
206
70
hpdl
814
71         $osC_NavigationHistory->removeCurrentPage();
hpdl
206
72
73 // build the message content
hpdl
814
74         if ((ACCOUNT_GENDER > -1) && isset($data['gender'])) {
75            if ($data['gender'] == 'm') {
76              $email_text = sprintf($osC_Language->get('email_addressing_gender_male'), $osC_Customer->getLastName()) . "\n\n";
77            } else {
78              $email_text = sprintf($osC_Language->get('email_addressing_gender_female'), $osC_Customer->getLastName()) . "\n\n";
79            }
80         } else {
81           $email_text = sprintf($osC_Language->get('email_addressing_gender_unknown'), $osC_Customer->getName()) . "\n\n";
82         }
hpdl
206
83
hpdl
814
84         $email_text .= sprintf($osC_Language->get('email_create_account_body'), STORE_NAME, STORE_OWNER_EMAIL_ADDRESS);
hpdl
206
85
hpdl
814
86         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
87
hpdl
814
88         return true;
hpdl
206
89       }
90
91       return false;
92     }
93
hpdl
180
94     function saveEntry($data) {
95       global $osC_Database, $osC_Customer;
96
hpdl
814
97       $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
98       $Qcustomer->bindTable(':table_customers', TABLE_CUSTOMERS);
99       $Qcustomer->bindValue(':customers_gender', ((ACCOUNT_GENDER > -1) && isset($data['gender']) && (($data['gender'] == 'm') || ($data['gender'] == 'f'))) ? $data['gender'] : '');
100       $Qcustomer->bindValue(':customers_firstname', $data['firstname']);
101       $Qcustomer->bindValue(':customers_lastname', $data['lastname']);
102       $Qcustomer->bindValue(':customers_email_address', $data['email_address']);
hpdl
554
103       $Qcustomer->bindValue(':customers_dob', (ACCOUNT_DATE_OF_BIRTH == '1') ? date('Ymd', $data['dob']) : '');
hpdl
814
104       $Qcustomer->bindRaw(':date_account_last_modified', 'now()');
hpdl
184
105       $Qcustomer->bindInt(':customers_id', $osC_Customer->getID());
hpdl
180
106       $Qcustomer->execute();
107
108       if ($Qcustomer->affectedRows() === 1) {
109         return true;
110       }
111
112       return false;
113     }
114
hpdl
207
115     function savePassword($password, $customer_id = null) {
hpdl
181
116       global $osC_Database, $osC_Customer;
117
hpdl
207
118       if (is_numeric($customer_id) === false) {
119         $customer_id = $osC_Customer->getID();
120       }
121
hpdl
814
122       $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
123       $Qcustomer->bindTable(':table_customers', TABLE_CUSTOMERS);
hpdl
757
124       $Qcustomer->bindValue(':customers_password', osc_encrypt_string($password));
hpdl
814
125       $Qcustomer->bindRaw(':date_account_last_modified', 'now()');
hpdl
207
126       $Qcustomer->bindInt(':customers_id', $customer_id);
hpdl
181
127       $Qcustomer->execute();
128
129       if ($Qcustomer->affectedRows() === 1) {
130         return true;
131       }
132
133       return false;
134     }
135
hpdl
176
136     function checkEntry($email_address) {
137       global $osC_Database;
138
139       $Qcheck = $osC_Database->query('select customers_id from :table_customers where customers_email_address = :customers_email_address limit 1');
140       $Qcheck->bindTable(':table_customers', TABLE_CUSTOMERS);
141       $Qcheck->bindValue(':customers_email_address', $email_address);
142       $Qcheck->execute();
143
144       if ($Qcheck->numberOfRows() === 1) {
145         return true;
146       }
147
148       return false;
149     }
150
hpdl
181
151     function checkPassword($password, $email_address = null) {
152       global $osC_Database, $osC_Customer;
hpdl
176
153
hpdl
181
154       if ($email_address === null) {
155         $Qcheck = $osC_Database->query('select customers_password from :table_customers where customers_id = :customers_id');
156         $Qcheck->bindTable(':table_customers', TABLE_CUSTOMERS);
hpdl
184
157         $Qcheck->bindInt(':customers_id', $osC_Customer->getID());
hpdl
181
158         $Qcheck->execute();
159       } else {
160         $Qcheck = $osC_Database->query('select customers_password from :table_customers where customers_email_address = :customers_email_address limit 1');
161         $Qcheck->bindTable(':table_customers', TABLE_CUSTOMERS);
162         $Qcheck->bindValue(':customers_email_address', $email_address);
163         $Qcheck->execute();
164       }
hpdl
176
165
166       if ($Qcheck->numberOfRows() === 1) {
167         if ( (strlen($password) > 0) && (strlen($Qcheck->value('customers_password')) > 0) ) {
168           $stack = explode(':', $Qcheck->value('customers_password'));
169
170           if (sizeof($stack) === 2) {
171             if (md5($stack[1] . $password) == $stack[0]) {
172               return true;
173             }
174           }
175         }
176       }
177
178       return false;
179     }
hpdl
180
180
181     function checkDuplicateEntry($email_address) {
182       global $osC_Database, $osC_Customer;
183
184       $Qcheck = $osC_Database->query('select customers_id from :table_customers where customers_email_address = :customers_email_address and customers_id != :customers_id limit 1');
185       $Qcheck->bindTable(':table_customers', TABLE_CUSTOMERS);
186       $Qcheck->bindValue(':customers_email_address', $email_address);
hpdl
184
187       $Qcheck->bindInt(':customers_id', $osC_Customer->getID());
hpdl
180
188       $Qcheck->execute();
189
190       if ($Qcheck->numberOfRows() === 1) {
191         return true;
192       }
193
194       return false;
195     }
hpdl
176
196   }
197 ?>