Quick Search:

View

Revision:

Diff

Diff from 1498 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 1498 2007-03-29 14:04:50Z hpdl $
hpdl
176
4
5   osCommerce, Open Source E-Commerce Solutions
6   http://www.oscommerce.com
7
8   Copyright (c) 2005 osCommerce
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
15   class osC_Account {
16
hpdl
179
17     function &getEntry() {
18       global $osC_Database, $osC_Customer;
19
hpdl
754
20       $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
21       $Qaccount->bindTable(':table_customers', TABLE_CUSTOMERS);
hpdl
184
22       $Qaccount->bindInt(':customers_id', $osC_Customer->getID());
hpdl
179
23       $Qaccount->execute();
24
25       return $Qaccount;
26     }
27
28     function getID($email_address) {
29       global $osC_Database;
30
31       $Quser = $osC_Database->query('select customers_id from :table_customers where customers_email_address = :customers_email_address limit 1');
32       $Quser->bindTable(':table_customers', TABLE_CUSTOMERS);
33       $Quser->bindValue(':customers_email_address', $email_address);
34       $Quser->execute();
35
36       if ($Quser->numberOfRows() === 1) {
37         return $Quser->valueInt('customers_id');
38       }
39
40       return false;
41     }
42
hpdl
206
43     function createEntry($data) {
hpdl
443
44       global $osC_Database, $osC_Session, $osC_Language, $osC_ShoppingCart, $osC_Customer, $osC_NavigationHistory;
hpdl
206
45
hpdl
814
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, 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
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');
hpdl
757
53       $Qcustomer->bindValue(':customers_ip_address', osc_get_ip_address());
54       $Qcustomer->bindValue(':customers_password', osc_encrypt_string($data['password']));
hpdl
206
55       $Qcustomer->bindValue(':customers_gender', (((ACCOUNT_GENDER > -1) && isset($data['gender']) && (($data['gender'] == 'm') || ($data['gender'] == 'f'))) ? $data['gender'] : ''));
hpdl
554
56       $Qcustomer->bindValue(':customers_dob', ((ACCOUNT_DATE_OF_BIRTH == '1') ? date('Ymd', $data['dob']) : ''));
hpdl
814
57       $Qcustomer->bindInt(':number_of_logons', 0);
58       $Qcustomer->bindRaw(':date_account_created', 'now()');
hpdl
206
59       $Qcustomer->execute();
60
61       if ($Qcustomer->affectedRows() === 1) {
62         $customer_id = $osC_Database->nextID();
63
hpdl
814
64         if (SERVICE_SESSION_REGENERATE_ID == '1') {
65           $osC_Session->recreate();
66         }
hpdl
206
67
hpdl
814
68         $osC_Customer->setCustomerData($customer_id);
hpdl
206
69
70 // restore cart contents
hpdl
814
71         $osC_ShoppingCart->synchronizeWithDatabase();
hpdl
206
72
hpdl
814
73         $osC_NavigationHistory->removeCurrentPage();
hpdl
206
74
75 // build the message content
hpdl
814
76         if ((ACCOUNT_GENDER > -1) && isset($data['gender'])) {
77            if ($data['gender'] == 'm') {
78              $email_text = sprintf($osC_Language->get('email_addressing_gender_male'), $osC_Customer->getLastName()) . "\n\n";
79            } else {
80              $email_text = sprintf($osC_Language->get('email_addressing_gender_female'), $osC_Customer->getLastName()) . "\n\n";
81            }
82         } else {
83           $email_text = sprintf($osC_Language->get('email_addressing_gender_unknown'), $osC_Customer->getName()) . "\n\n";
84         }
hpdl
206
85
hpdl
814
86         $email_text .= sprintf($osC_Language->get('email_create_account_body'), STORE_NAME, STORE_OWNER_EMAIL_ADDRESS);
hpdl
206
87
hpdl
814
88         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
89
hpdl
814
90         return true;
hpdl
206
91       }
92
93       return false;
94     }
95
hpdl
180
96     function saveEntry($data) {
97       global $osC_Database, $osC_Customer;
98
hpdl
814
99       $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
100       $Qcustomer->bindTable(':table_customers', TABLE_CUSTOMERS);
101       $Qcustomer->bindValue(':customers_gender', ((ACCOUNT_GENDER > -1) && isset($data['gender']) && (($data['gender'] == 'm') || ($data['gender'] == 'f'))) ? $data['gender'] : '');
102       $Qcustomer->bindValue(':customers_firstname', $data['firstname']);
103       $Qcustomer->bindValue(':customers_lastname', $data['lastname']);
104       $Qcustomer->bindValue(':customers_email_address', $data['email_address']);
hpdl
554
105       $Qcustomer->bindValue(':customers_dob', (ACCOUNT_DATE_OF_BIRTH == '1') ? date('Ymd', $data['dob']) : '');
hpdl
814
106       $Qcustomer->bindRaw(':date_account_last_modified', 'now()');
hpdl
184
107       $Qcustomer->bindInt(':customers_id', $osC_Customer->getID());
hpdl
180
108       $Qcustomer->execute();
109
110       if ($Qcustomer->affectedRows() === 1) {
111         return true;
112       }
113
114       return false;
115     }
116
hpdl
207
117     function savePassword($password, $customer_id = null) {
hpdl
181
118       global $osC_Database, $osC_Customer;
119
hpdl
207
120       if (is_numeric($customer_id) === false) {
121         $customer_id = $osC_Customer->getID();
122       }
123
hpdl
814
124       $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
125       $Qcustomer->bindTable(':table_customers', TABLE_CUSTOMERS);
hpdl
757
126       $Qcustomer->bindValue(':customers_password', osc_encrypt_string($password));
hpdl
814
127       $Qcustomer->bindRaw(':date_account_last_modified', 'now()');
hpdl
207
128       $Qcustomer->bindInt(':customers_id', $customer_id);
hpdl
181
129       $Qcustomer->execute();
130
131       if ($Qcustomer->affectedRows() === 1) {
132         return true;
133       }
134
135       return false;
136     }
137
hpdl
176
138     function checkEntry($email_address) {
139       global $osC_Database;
140
141       $Qcheck = $osC_Database->query('select customers_id from :table_customers where customers_email_address = :customers_email_address limit 1');
142       $Qcheck->bindTable(':table_customers', TABLE_CUSTOMERS);
143       $Qcheck->bindValue(':customers_email_address', $email_address);
144       $Qcheck->execute();
145
146       if ($Qcheck->numberOfRows() === 1) {
147         return true;
148       }
149
150       return false;
151     }
152
hpdl
181
153     function checkPassword($password, $email_address = null) {
154       global $osC_Database, $osC_Customer;
hpdl
176
155
hpdl
181
156       if ($email_address === null) {
157         $Qcheck = $osC_Database->query('select customers_password from :table_customers where customers_id = :customers_id');
158         $Qcheck->bindTable(':table_customers', TABLE_CUSTOMERS);
hpdl
184
159         $Qcheck->bindInt(':customers_id', $osC_Customer->getID());
hpdl
181
160         $Qcheck->execute();
161       } else {
162         $Qcheck = $osC_Database->query('select customers_password 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       }
hpdl
176
167
168       if ($Qcheck->numberOfRows() === 1) {
169         if ( (strlen($password) > 0) && (strlen($Qcheck->value('customers_password')) > 0) ) {
170           $stack = explode(':', $Qcheck->value('customers_password'));
171
172           if (sizeof($stack) === 2) {
173             if (md5($stack[1] . $password) == $stack[0]) {
174               return true;
175             }
176           }
177         }
178       }
179
180       return false;
181     }
hpdl
180
182
183     function checkDuplicateEntry($email_address) {
184       global $osC_Database, $osC_Customer;
185
186       $Qcheck = $osC_Database->query('select customers_id from :table_customers where customers_email_address = :customers_email_address and customers_id != :customers_id limit 1');
187       $Qcheck->bindTable(':table_customers', TABLE_CUSTOMERS);
188       $Qcheck->bindValue(':customers_email_address', $email_address);
hpdl
184
189       $Qcheck->bindInt(':customers_id', $osC_Customer->getID());
hpdl
180
190       $Qcheck->execute();
191
192       if ($Qcheck->numberOfRows() === 1) {
193         return true;
194       }
195
196       return false;
197     }
hpdl
176
198   }
199 ?>