Quick Search:

View

Revision:

Diff

Diff from 203 to:

Annotations

Annotate by Age | Author | Mixed | None
/fisheye/browse/osCommerce/branches/hpdl/oscommerce/includes/classes/customer.php

Annotated File View

hpdl
1
1 <?php
2 /*
hpdl
153
3   $Id: customer.php 203 2005-09-23 14:17:59Z 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
hpdl
201
20 /* Class constructor */
21
22     function osC_Customer() {
hpdl
202
23       if (isset($_SESSION['osC_Customer_data']) && is_array($_SESSION['osC_Customer_data']) && isset($_SESSION['osC_Customer_data']['id']) && is_numeric($_SESSION['osC_Customer_data']['id'])) {
hpdl
201
24         $this->setIsLoggedOn(true);
25         $this->_data =& $_SESSION['osC_Customer_data'];
26       }
27     }
28
hpdl
184
29 /* Public methods */
30
31     function getID() {
32       if (isset($this->_data['id']) && is_numeric($this->_data['id'])) {
33         return $this->_data['id'];
34       }
35
36       return false;
hpdl
1
37     }
38
hpdl
184
39     function getFirstName() {
40       static $first_name = null;
41
42       if (is_null($first_name)) {
43         if (isset($this->_data['first_name'])) {
44           $first_name = $this->_data['first_name'];
45         }
46       }
47
48       return $first_name;
49     }
50
51     function getLastName() {
52       static $last_name = null;
53
54       if (is_null($last_name)) {
55         if (isset($this->_data['last_name'])) {
56           $last_name = $this->_data['last_name'];
57         }
58       }
59
60       return $last_name;
61     }
62
63     function getName() {
64       static $name = '';
65
66       if (empty($name)) {
67         if (isset($this->_data['first_name'])) {
68           $name .= $this->_data['first_name'];
69         }
70
71         if (isset($this->_data['last_name'])) {
72           if (empty($name) === false) {
73             $name .= ' ';
74           }
75
76           $name .= $this->_data['last_name'];
77         }
78       }
79
80       return $name;
81     }
82
83     function getGender() {
84       static $gender = null;
85
86       if (is_null($gender)) {
87         if (isset($this->_data['gender'])) {
88           $gender = $this->_data['gender'];
89         }
90       }
91
92       return $gender;
93     }
94
95     function getEmailAddress() {
96       static $email_address = null;
97
98       if (is_null($email_address)) {
99         if (isset($this->_data['email_address'])) {
100           $email_address = $this->_data['email_address'];
101         }
102       }
103
104       return $email_address;
105     }
106
107     function getCountryID() {
108       static $country_id = null;
109
110       if (is_null($country_id)) {
111         if (isset($this->_data['country_id'])) {
112           $country_id = $this->_data['country_id'];
113         }
114       }
115
116       return $country_id;
117     }
118
119     function getZoneID() {
120       static $zone_id = null;
121
122       if (is_null($zone_id)) {
123         if (isset($this->_data['zone_id'])) {
124           $zone_id = $this->_data['zone_id'];
125         }
126       }
127
128       return $zone_id;
129     }
130
131     function getDefaultAddressID() {
132       static $id = null;
133
134       if (is_null($id)) {
135         if (isset($this->_data['default_address_id'])) {
136           $id = $this->_data['default_address_id'];
137         }
138       }
139
140       return $id;
141     }
142
hpdl
1
143     function setCustomerData($customer_id = -1) {
hpdl
201
144       global $osC_Database;
145
146       $this->_data = array();
147
hpdl
1
148       if (is_numeric($customer_id) && ($customer_id > 0)) {
149         $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');
hpdl
201
150         $Qcustomer->bindTable(':table_customers', TABLE_CUSTOMERS);
hpdl
1
151         $Qcustomer->bindInt(':customers_id', $customer_id);
152         $Qcustomer->execute();
153
154         if ($Qcustomer->numberOfRows() === 1) {
155           $this->setIsLoggedOn(true);
156           $this->setID($customer_id);
157           $this->setGender($Qcustomer->value('customers_gender'));
158           $this->setFirstName($Qcustomer->value('customers_firstname'));
159           $this->setLastName($Qcustomer->value('customers_lastname'));
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       }
hpdl
201
181
182       if (sizeof($this->_data) > 0) {
183         $_SESSION['osC_Customer_data'] = $this->_data;
184       } elseif (isset($_SESSION['osC_Customer_data'])) {
185         $this->reset();
186       }
hpdl
1
187     }
188
189     function setIsLoggedOn($state) {
190       if ($state === true) {
hpdl
184
191         $this->_is_logged_on = true;
hpdl
1
192       } else {
hpdl
184
193         $this->_is_logged_on = false;
hpdl
1
194       }
195     }
196
197     function isLoggedOn() {
hpdl
184
198       if ($this->_is_logged_on === true) {
hpdl
1
199         return true;
200       }
201
202       return false;
203     }
204
205     function setID($id) {
hpdl
184
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) {
hpdl
184
214       if (is_numeric($id) && ($id > 0)) {
215         $this->_data['default_address_id'] = $id;
216       } else {
217         $this->_data['default_address_id'] = false;
218       }
hpdl
1
219     }
220
221     function hasDefaultAddress() {
hpdl
184
222       if (isset($this->_data['default_address_id']) && is_numeric($this->_data['default_address_id'])) {
hpdl
1
223         return true;
224       }
hpdl
184
225
226       return false;
hpdl
1
227     }
228
229     function setGender($gender) {
hpdl
184
230       if ( (strtolower($gender) == 'm') || (strtolower($gender) == 'f') ) {
231         $this->_data['gender'] = strtolower($gender);
232       } else {
233         $this->_data['gender'] = false;
234       }
hpdl
1
235     }
236
hpdl
184
237     function setFirstName($first_name) {
238       $this->_data['first_name'] = $first_name;
hpdl
1
239     }
240
hpdl
184
241     function setLastName($last_name) {
242       $this->_data['last_name'] = $last_name;
hpdl
1
243     }
244
245     function setEmailAddress($email_address) {
hpdl
184
246       $this->_data['email_address'] = $email_address;
hpdl
1
247     }
248
249     function setCountryID($id) {
hpdl
184
250       $this->_data['country_id'] = $id;
hpdl
1
251     }
252
253     function setZoneID($id) {
hpdl
184
254       $this->_data['zone_id'] = $id;
hpdl
1
255     }
hpdl
201
256
257     function reset() {
258       $this->_is_logged_on = false;
259       $this->_data = array();
260
hpdl
203
261       if (isset($_SESSION['osC_Customer_data'])) {
262         unset($_SESSION['osC_Customer_data']);
263       }
hpdl
201
264     }
hpdl
1
265   }
266 ?>