hpdl
|
1
|
1
|
<?php
|
|
2
|
/*
|
hpdl
|
153
|
3
|
$Id: customer.php 184 2005-09-07 14:48:20Z hpdl $
|
hpdl
|
1
|
4
|
|
|
5
|
osCommerce, Open Source E-Commerce Solutions
|
|
6
|
http://www.oscommerce.com
|
|
7
|
|
|
8
|
Copyright (c) 2004 osCommerce
|
|
9
|
|
|
10
|
Released under the GNU General Public License
|
|
11
|
*/
|
|
12
|
|
|
13
|
class osC_Customer {
|
|
14
|
var $is_logged_on,
|
|
15
|
$id,
|
|
16
|
$gender,
|
|
17
|
$first_name,
|
|
18
|
$last_name,
|
|
19
|
$full_name,
|
|
20
|
$email_address,
|
|
21
|
$default_address_id,
|
|
22
|
$country_id,
|
|
23
|
$zone_id;
|
|
24
|
|
hpdl
|
184
|
25
|
/* Private variables */
|
|
26
|
|
|
27
|
var $_is_logged_on = false,
|
|
28
|
$_data = array();
|
|
29
|
|
|
30
|
/* Public methods */
|
|
31
|
|
|
32
|
function getID() {
|
|
33
|
if (isset($this->_data['id']) && is_numeric($this->_data['id'])) {
|
|
34
|
return $this->_data['id'];
|
|
35
|
}
|
|
36
|
|
|
37
|
return false;
|
hpdl
|
1
|
38
|
}
|
|
39
|
|
hpdl
|
184
|
40
|
function getFirstName() {
|
|
41
|
static $first_name = null;
|
|
42
|
|
|
43
|
if (is_null($first_name)) {
|
|
44
|
if (isset($this->_data['first_name'])) {
|
|
45
|
$first_name = $this->_data['first_name'];
|
|
46
|
}
|
|
47
|
}
|
|
48
|
|
|
49
|
return $first_name;
|
|
50
|
}
|
|
51
|
|
|
52
|
function getLastName() {
|
|
53
|
static $last_name = null;
|
|
54
|
|
|
55
|
if (is_null($last_name)) {
|
|
56
|
if (isset($this->_data['last_name'])) {
|
|
57
|
$last_name = $this->_data['last_name'];
|
|
58
|
}
|
|
59
|
}
|
|
60
|
|
|
61
|
return $last_name;
|
|
62
|
}
|
|
63
|
|
|
64
|
function getName() {
|
|
65
|
static $name = '';
|
|
66
|
|
|
67
|
if (empty($name)) {
|
|
68
|
if (isset($this->_data['first_name'])) {
|
|
69
|
$name .= $this->_data['first_name'];
|
|
70
|
}
|
|
71
|
|
|
72
|
if (isset($this->_data['last_name'])) {
|
|
73
|
if (empty($name) === false) {
|
|
74
|
$name .= ' ';
|
|
75
|
}
|
|
76
|
|
|
77
|
$name .= $this->_data['last_name'];
|
|
78
|
}
|
|
79
|
}
|
|
80
|
|
|
81
|
return $name;
|
|
82
|
}
|
|
83
|
|
|
84
|
function getGender() {
|
|
85
|
static $gender = null;
|
|
86
|
|
|
87
|
if (is_null($gender)) {
|
|
88
|
if (isset($this->_data['gender'])) {
|
|
89
|
$gender = $this->_data['gender'];
|
|
90
|
}
|
|
91
|
}
|
|
92
|
|
|
93
|
return $gender;
|
|
94
|
}
|
|
95
|
|
|
96
|
function getEmailAddress() {
|
|
97
|
static $email_address = null;
|
|
98
|
|
|
99
|
if (is_null($email_address)) {
|
|
100
|
if (isset($this->_data['email_address'])) {
|
|
101
|
$email_address = $this->_data['email_address'];
|
|
102
|
}
|
|
103
|
}
|
|
104
|
|
|
105
|
return $email_address;
|
|
106
|
}
|
|
107
|
|
|
108
|
function getCountryID() {
|
|
109
|
static $country_id = null;
|
|
110
|
|
|
111
|
if (is_null($country_id)) {
|
|
112
|
if (isset($this->_data['country_id'])) {
|
|
113
|
$country_id = $this->_data['country_id'];
|
|
114
|
}
|
|
115
|
}
|
|
116
|
|
|
117
|
return $country_id;
|
|
118
|
}
|
|
119
|
|
|
120
|
function getZoneID() {
|
|
121
|
static $zone_id = null;
|
|
122
|
|
|
123
|
if (is_null($zone_id)) {
|
|
124
|
if (isset($this->_data['zone_id'])) {
|
|
125
|
$zone_id = $this->_data['zone_id'];
|
|
126
|
}
|
|
127
|
}
|
|
128
|
|
|
129
|
return $zone_id;
|
|
130
|
}
|
|
131
|
|
|
132
|
function getDefaultAddressID() {
|
|
133
|
static $id = null;
|
|
134
|
|
|
135
|
if (is_null($id)) {
|
|
136
|
if (isset($this->_data['default_address_id'])) {
|
|
137
|
$id = $this->_data['default_address_id'];
|
|
138
|
}
|
|
139
|
}
|
|
140
|
|
|
141
|
return $id;
|
|
142
|
}
|
|
143
|
|
hpdl
|
1
|
144
|
function setCustomerData($customer_id = -1) {
|
|
145
|
if (is_numeric($customer_id) && ($customer_id > 0)) {
|
|
146
|
global $osC_Database;
|
|
147
|
|
|
148
|
$Qcustomer = $osC_Database->query('select customers_gender, customers_firstname, customers_lastname, customers_email_address, customers_default_address_id from :table_customers where customers_id = :customers_id');
|
|
149
|
$Qcustomer->bindRaw(':table_customers', TABLE_CUSTOMERS);
|
|
150
|
$Qcustomer->bindInt(':customers_id', $customer_id);
|
|
151
|
$Qcustomer->execute();
|
|
152
|
|
|
153
|
if ($Qcustomer->numberOfRows() === 1) {
|
|
154
|
$this->setIsLoggedOn(true);
|
|
155
|
$this->setID($customer_id);
|
|
156
|
$this->setGender($Qcustomer->value('customers_gender'));
|
|
157
|
$this->setFirstName($Qcustomer->value('customers_firstname'));
|
|
158
|
$this->setLastName($Qcustomer->value('customers_lastname'));
|
|
159
|
$this->setFullName();
|
|
160
|
$this->setEmailAddress($Qcustomer->value('customers_email_address'));
|
|
161
|
|
|
162
|
if (is_numeric($Qcustomer->value('customers_default_address_id')) && ($Qcustomer->value('customers_default_address_id') > 0)) {
|
|
163
|
$Qab = $osC_Database->query('select entry_country_id, entry_zone_id from :table_address_book where address_book_id = :address_book_id and customers_id = :customers_id');
|
hpdl
|
184
|
164
|
$Qab->bindTable(':table_address_book', TABLE_ADDRESS_BOOK);
|
hpdl
|
1
|
165
|
$Qab->bindInt(':address_book_id', $Qcustomer->value('customers_default_address_id'));
|
|
166
|
$Qab->bindInt(':customers_id', $customer_id);
|
|
167
|
$Qab->execute();
|
|
168
|
|
|
169
|
if ($Qab->numberOfRows() === 1) {
|
|
170
|
$this->setCountryID($Qab->value('entry_country_id'));
|
|
171
|
$this->setZoneID($Qab->value('entry_zone_id'));
|
|
172
|
$this->setDefaultAddressID($Qcustomer->value('customers_default_address_id'));
|
|
173
|
|
|
174
|
$Qab->freeResult();
|
|
175
|
}
|
|
176
|
}
|
|
177
|
}
|
|
178
|
|
|
179
|
$Qcustomer->freeResult();
|
|
180
|
}
|
|
181
|
}
|
|
182
|
|
|
183
|
function setIsLoggedOn($state) {
|
|
184
|
if ($state === true) {
|
hpdl
|
184
|
185
|
$this->_is_logged_on = true;
|
hpdl
|
1
|
186
|
} else {
|
hpdl
|
184
|
187
|
$this->_is_logged_on = false;
|
hpdl
|
1
|
188
|
}
|
|
189
|
}
|
|
190
|
|
|
191
|
function isLoggedOn() {
|
hpdl
|
184
|
192
|
if ($this->_is_logged_on === true) {
|
hpdl
|
1
|
193
|
return true;
|
|
194
|
}
|
|
195
|
|
|
196
|
return false;
|
|
197
|
}
|
|
198
|
|
|
199
|
function isGuest() {
|
|
200
|
return !$this->isLoggedOn();
|
|
201
|
}
|
|
202
|
|
|
203
|
function setID($id) {
|
|
204
|
$this->id = $id;
|
hpdl
|
184
|
205
|
|
|
206
|
if (is_numeric($id) && ($id > 0)) {
|
|
207
|
$this->_data['id'] = $id;
|
|
208
|
} else {
|
|
209
|
$this->_data['id'] = false;
|
|
210
|
}
|
hpdl
|
1
|
211
|
}
|
|
212
|
|
|
213
|
function setDefaultAddressID($id) {
|
|
214
|
$this->default_address_id = $id;
|
hpdl
|
184
|
215
|
|
|
216
|
if (is_numeric($id) && ($id > 0)) {
|
|
217
|
$this->_data['default_address_id'] = $id;
|
|
218
|
} else {
|
|
219
|
$this->_data['default_address_id'] = false;
|
|
220
|
}
|
hpdl
|
1
|
221
|
}
|
|
222
|
|
|
223
|
function hasDefaultAddress() {
|
hpdl
|
184
|
224
|
if (isset($this->_data['default_address_id']) && is_numeric($this->_data['default_address_id'])) {
|
hpdl
|
1
|
225
|
return true;
|
|
226
|
}
|
hpdl
|
184
|
227
|
|
|
228
|
return false;
|
hpdl
|
1
|
229
|
}
|
|
230
|
|
|
231
|
function setGender($gender) {
|
|
232
|
$this->gender = $gender;
|
hpdl
|
184
|
233
|
|
|
234
|
if ( (strtolower($gender) == 'm') || (strtolower($gender) == 'f') ) {
|
|
235
|
$this->_data['gender'] = strtolower($gender);
|
|
236
|
} else {
|
|
237
|
$this->_data['gender'] = false;
|
|
238
|
}
|
hpdl
|
1
|
239
|
}
|
|
240
|
|
hpdl
|
184
|
241
|
function setFirstName($first_name) {
|
|
242
|
$this->first_name = $first_name;
|
|
243
|
|
|
244
|
$this->_data['first_name'] = $first_name;
|
hpdl
|
1
|
245
|
}
|
|
246
|
|
hpdl
|
184
|
247
|
function setLastName($last_name) {
|
|
248
|
$this->last_name = $last_name;
|
|
249
|
|
|
250
|
$this->_data['last_name'] = $last_name;
|
hpdl
|
1
|
251
|
}
|
|
252
|
|
|
253
|
function setFullName($fullname = '') {
|
|
254
|
if (empty($fullname)) {
|
|
255
|
$this->full_name = $this->first_name . ' ' . $this->last_name;
|
|
256
|
} else {
|
|
257
|
$this->full_name = $fullname;
|
|
258
|
}
|
|
259
|
}
|
|
260
|
|
|
261
|
function setEmailAddress($email_address) {
|
|
262
|
$this->email_address = $email_address;
|
hpdl
|
184
|
263
|
|
|
264
|
$this->_data['email_address'] = $email_address;
|
hpdl
|
1
|
265
|
}
|
|
266
|
|
|
267
|
function setCountryID($id) {
|
|
268
|
$this->country_id = $id;
|
hpdl
|
184
|
269
|
|
|
270
|
$this->_data['country_id'] = $id;
|
hpdl
|
1
|
271
|
}
|
|
272
|
|
|
273
|
function setZoneID($id) {
|
|
274
|
$this->zone_id = $id;
|
hpdl
|
184
|
275
|
|
|
276
|
$this->_data['zone_id'] = $id;
|
hpdl
|
1
|
277
|
}
|
|
278
|
}
|
|
279
|
?>
|