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