  |
1 | 1 | | <?php |
| |
2 | 2 | | /* |
  |
3 | | - | $Id: customer.php 151 2005-08-02 14:33:25Z mattice $ |
| |
| 3 | + | $Id: customer.php 368 2005-12-22 16:27:23Z hpdl $ |
|
4 | 4 | | |
| |
5 | 5 | | osCommerce, Open Source E-Commerce Solutions |
| |
6 | 6 | | http://www.oscommerce.com |
| |
7 | 7 | | |
  |
8 | | - | Copyright (c) 2004 osCommerce |
| |
| 8 | + | Copyright (c) 2005 osCommerce |
|
9 | 9 | | |
| |
10 | 10 | | Released under the GNU General Public License |
| |
11 | 11 | | */ |
| |
12 | 12 | | |
| |
13 | 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 | 14 | | |
  |
25 | | - | // class constructor |
| |
| 15 | + | /* Private variables */ |
| |
| 16 | + | |
| |
| 17 | + | var $_is_logged_on = false, |
| |
| 18 | + | $_data = array(); |
| |
| 19 | + | |
| |
| 20 | + | /* Class constructor */ |
| |
| 21 | + | |
|
26 | 22 | | function osC_Customer() { |
  |
27 | | - | $this->setIsLoggedOn(false); |
| |
| 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'])) { |
| |
| 24 | + | $this->setIsLoggedOn(true); |
| |
| 25 | + | $this->_data =& $_SESSION['osC_Customer_data']; |
| |
| 26 | + | } |
|
28 | 27 | | } |
| |
29 | 28 | | |
  |
30 | | - | // class methods |
| |
| 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; |
| |
| 37 | + | } |
| |
| 38 | + | |
| |
| 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 | + | |
|
31 | 143 | | function setCustomerData($customer_id = -1) { |
  |
32 | | - | if (is_numeric($customer_id) && ($customer_id > 0)) { |
| |
33 | | - | global $osC_Database; |
| |
| 144 | + | global $osC_Database; |
|
34 | 145 | | |
  |
| 146 | + | $this->_data = array(); |
| |
| 147 | + | |
| |
| 148 | + | if (is_numeric($customer_id) && ($customer_id > 0)) { |
|
35 | 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'); |
  |
36 | | - | $Qcustomer->bindRaw(':table_customers', TABLE_CUSTOMERS); |
| |
| 150 | + | $Qcustomer->bindTable(':table_customers', TABLE_CUSTOMERS); |
|
37 | 151 | | $Qcustomer->bindInt(':customers_id', $customer_id); |
| |
38 | 152 | | $Qcustomer->execute(); |
| |
39 | 153 | | |
| |
|
|
 |
… |
|
43 | 157 | | $this->setGender($Qcustomer->value('customers_gender')); |
| |
44 | 158 | | $this->setFirstName($Qcustomer->value('customers_firstname')); |
| |
45 | 159 | | $this->setLastName($Qcustomer->value('customers_lastname')); |
  |
46 | | - | $this->setFullName(); |
|
47 | 160 | | $this->setEmailAddress($Qcustomer->value('customers_email_address')); |
| |
48 | 161 | | |
| |
49 | 162 | | if (is_numeric($Qcustomer->value('customers_default_address_id')) && ($Qcustomer->value('customers_default_address_id') > 0)) { |
| |
50 | 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'); |
  |
51 | | - | $Qab->bindRaw(':table_address_book', TABLE_ADDRESS_BOOK); |
| |
| 164 | + | $Qab->bindTable(':table_address_book', TABLE_ADDRESS_BOOK); |
|
52 | 165 | | $Qab->bindInt(':address_book_id', $Qcustomer->value('customers_default_address_id')); |
| |
53 | 166 | | $Qab->bindInt(':customers_id', $customer_id); |
| |
54 | 167 | | $Qab->execute(); |
| |
|
|
 |
… |
|
65 | 178 | | |
| |
66 | 179 | | $Qcustomer->freeResult(); |
| |
67 | 180 | | } |
  |
| 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 | + | } |
|
68 | 187 | | } |
| |
69 | 188 | | |
| |
70 | 189 | | function setIsLoggedOn($state) { |
| |
71 | 190 | | if ($state === true) { |
  |
72 | | - | $this->is_logged_on = true; |
| |
| 191 | + | $this->_is_logged_on = true; |
|
73 | 192 | | } else { |
  |
74 | | - | $this->is_logged_on = false; |
| |
| 193 | + | $this->_is_logged_on = false; |
|
75 | 194 | | } |
| |
76 | 195 | | } |
| |
77 | 196 | | |
| |
78 | 197 | | function isLoggedOn() { |
  |
79 | | - | if ($this->is_logged_on === true) { |
| |
| 198 | + | if ($this->_is_logged_on === true) { |
|
80 | 199 | | return true; |
| |
81 | 200 | | } |
| |
82 | 201 | | |
| |
83 | 202 | | return false; |
| |
84 | 203 | | } |
| |
85 | 204 | | |
  |
86 | | - | function isGuest() { |
| |
87 | | - | return !$this->isLoggedOn(); |
| |
88 | | - | } |
| |
89 | | - | |
|
90 | 205 | | function setID($id) { |
  |
91 | | - | $this->id = $id; |
| |
| 206 | + | if (is_numeric($id) && ($id > 0)) { |
| |
| 207 | + | $this->_data['id'] = $id; |
| |
| 208 | + | } else { |
| |
| 209 | + | $this->_data['id'] = false; |
| |
| 210 | + | } |
|
92 | 211 | | } |
| |
93 | 212 | | |
| |
94 | 213 | | function setDefaultAddressID($id) { |
  |
95 | | - | $this->default_address_id = $id; |
| |
| 214 | + | if (is_numeric($id) && ($id > 0)) { |
| |
| 215 | + | $this->_data['default_address_id'] = $id; |
| |
| 216 | + | } else { |
| |
| 217 | + | $this->_data['default_address_id'] = false; |
| |
| 218 | + | } |
|
96 | 219 | | } |
| |
97 | 220 | | |
| |
98 | 221 | | function hasDefaultAddress() { |
  |
99 | | - | if (is_numeric($this->default_address_id) && ($this->default_address_id > 0)) { |
| |
| 222 | + | if (isset($this->_data['default_address_id']) && is_numeric($this->_data['default_address_id'])) { |
|
100 | 223 | | return true; |
  |
101 | | - | } else { |
| |
102 | | - | return false; |
|
103 | 224 | | } |
  |
| 225 | + | |
| |
| 226 | + | return false; |
|
104 | 227 | | } |
| |
105 | 228 | | |
| |
106 | 229 | | function setGender($gender) { |
  |
107 | | - | $this->gender = $gender; |
| |
| 230 | + | if ( (strtolower($gender) == 'm') || (strtolower($gender) == 'f') ) { |
| |
| 231 | + | $this->_data['gender'] = strtolower($gender); |
| |
| 232 | + | } else { |
| |
| 233 | + | $this->_data['gender'] = false; |
| |
| 234 | + | } |
|
108 | 235 | | } |
| |
109 | 236 | | |
  |
110 | | - | function setFirstName($firstname) { |
| |
111 | | - | $this->first_name = $firstname; |
| |
| 237 | + | function setFirstName($first_name) { |
| |
| 238 | + | $this->_data['first_name'] = $first_name; |
|
112 | 239 | | } |
| |
113 | 240 | | |
  |
114 | | - | function setLastName($lastname) { |
| |
115 | | - | $this->last_name = $lastname; |
| |
| 241 | + | function setLastName($last_name) { |
| |
| 242 | + | $this->_data['last_name'] = $last_name; |
|
116 | 243 | | } |
| |
117 | 244 | | |
  |
118 | | - | function setFullName($fullname = '') { |
| |
119 | | - | if (empty($fullname)) { |
| |
120 | | - | $this->full_name = $this->first_name . ' ' . $this->last_name; |
| |
121 | | - | } else { |
| |
122 | | - | $this->full_name = $fullname; |
| |
123 | | - | } |
| |
124 | | - | } |
| |
125 | | - | |
|
126 | 245 | | function setEmailAddress($email_address) { |
  |
127 | | - | $this->email_address = $email_address; |
| |
| 246 | + | $this->_data['email_address'] = $email_address; |
|
128 | 247 | | } |
| |
129 | 248 | | |
| |
130 | 249 | | function setCountryID($id) { |
  |
131 | | - | $this->country_id = $id; |
| |
| 250 | + | $this->_data['country_id'] = $id; |
|
132 | 251 | | } |
| |
133 | 252 | | |
| |
134 | 253 | | function setZoneID($id) { |
  |
135 | | - | $this->zone_id = $id; |
| |
| 254 | + | $this->_data['zone_id'] = $id; |
|
136 | 255 | | } |
  |
| 256 | + | |
| |
| 257 | + | function reset() { |
| |
| 258 | + | $this->_is_logged_on = false; |
| |
| 259 | + | $this->_data = array(); |
| |
| 260 | + | |
| |
| 261 | + | if (isset($_SESSION['osC_Customer_data'])) { |
| |
| 262 | + | unset($_SESSION['osC_Customer_data']); |
| |
| 263 | + | } |
| |
| 264 | + | } |
  |
137 | 265 | | } |
| |
138 | 266 | | ?> |