Quick Search:

View

Revision:

Diff

Diff from 1497 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 1497 2007-03-29 13:40:05Z 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
hpdl
1497
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
1
13 */
14
15   class osC_Customer {
16
hpdl
184
17 /* Private variables */
18
19     var $_is_logged_on = false,
20         $_data = array();
21
hpdl
201
22 /* Class constructor */
23
24     function osC_Customer() {
hpdl
202
25       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
26         $this->setIsLoggedOn(true);
27         $this->_data =& $_SESSION['osC_Customer_data'];
28       }
29     }
30
hpdl
184
31 /* Public methods */
32
33     function getID() {
34       if (isset($this->_data['id']) && is_numeric($this->_data['id'])) {
35         return $this->_data['id'];
36       }
37
38       return false;
hpdl
1
39     }
40
hpdl
184
41     function getFirstName() {
42       static $first_name = null;
43
44       if (is_null($first_name)) {
45         if (isset($this->_data['first_name'])) {
46           $first_name = $this->_data['first_name'];
47         }
48       }
49
50       return $first_name;
51     }
52
53     function getLastName() {
54       static $last_name = null;
55
56       if (is_null($last_name)) {
57         if (isset($this->_data['last_name'])) {
58           $last_name = $this->_data['last_name'];
59         }
60       }
61
62       return $last_name;
63     }
64
65     function getName() {
66       static $name = '';
67
68       if (empty($name)) {
69         if (isset($this->_data['first_name'])) {
70           $name .= $this->_data['first_name'];
71         }
72
73         if (isset($this->_data['last_name'])) {
74           if (empty($name) === false) {
75             $name .= ' ';
76           }
77
78           $name .= $this->_data['last_name'];
79         }
80       }
81
82       return $name;
83     }
84
85     function getGender() {
86       static $gender = null;
87
88       if (is_null($gender)) {
89         if (isset($this->_data['gender'])) {
90           $gender = $this->_data['gender'];
91         }
92       }
93
94       return $gender;
95     }
96
97     function getEmailAddress() {
98       static $email_address = null;
99
100       if (is_null($email_address)) {
101         if (isset($this->_data['email_address'])) {
102           $email_address = $this->_data['email_address'];
103         }
104       }
105
106       return $email_address;
107     }
108
109     function getCountryID() {
110       static $country_id = null;
111
112       if (is_null($country_id)) {
113         if (isset($this->_data['country_id'])) {
114           $country_id = $this->_data['country_id'];
115         }
116       }
117
118       return $country_id;
119     }
120
121     function getZoneID() {
122       static $zone_id = null;
123
124       if (is_null($zone_id)) {
125         if (isset($this->_data['zone_id'])) {
126           $zone_id = $this->_data['zone_id'];
127         }
128       }
129
130       return $zone_id;
131     }
132
133     function getDefaultAddressID() {
134       static $id = null;
135
136       if (is_null($id)) {
137         if (isset($this->_data['default_address_id'])) {
138           $id = $this->_data['default_address_id'];
139         }
140       }
141
142       return $id;
143     }
144
hpdl
1
145     function setCustomerData($customer_id = -1) {
hpdl
201
146       global $osC_Database;
147
148       $this->_data = array();
149
hpdl
1
150       if (is_numeric($customer_id) && ($customer_id > 0)) {
151         $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
152         $Qcustomer->bindTable(':table_customers', TABLE_CUSTOMERS);
hpdl
1
153         $Qcustomer->bindInt(':customers_id', $customer_id);
154         $Qcustomer->execute();
155
156         if ($Qcustomer->numberOfRows() === 1) {
157           $this->setIsLoggedOn(true);
158           $this->setID($customer_id);
159           $this->setGender($Qcustomer->value('customers_gender'));
160           $this->setFirstName($Qcustomer->value('customers_firstname'));
161           $this->setLastName($Qcustomer->value('customers_lastname'));
162           $this->setEmailAddress($Qcustomer->value('customers_email_address'));
163
164           if (is_numeric($Qcustomer->value('customers_default_address_id')) && ($Qcustomer->value('customers_default_address_id') > 0)) {
165             $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
166             $Qab->bindTable(':table_address_book', TABLE_ADDRESS_BOOK);
hpdl
1
167             $Qab->bindInt(':address_book_id', $Qcustomer->value('customers_default_address_id'));
168             $Qab->bindInt(':customers_id', $customer_id);
169             $Qab->execute();
170
171             if ($Qab->numberOfRows() === 1) {
172               $this->setCountryID($Qab->value('entry_country_id'));
173               $this->setZoneID($Qab->value('entry_zone_id'));
174               $this->setDefaultAddressID($Qcustomer->value('customers_default_address_id'));
175
176               $Qab->freeResult();
177             }
178           }
179         }
180
181         $Qcustomer->freeResult();
182       }
hpdl
201
183
184       if (sizeof($this->_data) > 0) {
185         $_SESSION['osC_Customer_data'] = $this->_data;
186       } elseif (isset($_SESSION['osC_Customer_data'])) {
187         $this->reset();
188       }
hpdl
1
189     }
190
191     function setIsLoggedOn($state) {
192       if ($state === true) {
hpdl
184
193         $this->_is_logged_on = true;
hpdl
1
194       } else {
hpdl
184
195         $this->_is_logged_on = false;
hpdl
1
196       }
197     }
198
199     function isLoggedOn() {
hpdl
184
200       if ($this->_is_logged_on === true) {
hpdl
1
201         return true;
202       }
203
204       return false;
205     }
206
207     function setID($id) {
hpdl
184
208       if (is_numeric($id) && ($id > 0)) {
209         $this->_data['id'] = $id;
210       } else {
211         $this->_data['id'] = false;
212       }
hpdl
1
213     }
214
215     function setDefaultAddressID($id) {
hpdl
184
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) {
hpdl
184
232       if ( (strtolower($gender) == 'm') || (strtolower($gender) == 'f') ) {
233         $this->_data['gender'] = strtolower($gender);
234       } else {
235         $this->_data['gender'] = false;
236       }
hpdl
1
237     }
238
hpdl
184
239     function setFirstName($first_name) {
240       $this->_data['first_name'] = $first_name;
hpdl
1
241     }
242
hpdl
184
243     function setLastName($last_name) {
244       $this->_data['last_name'] = $last_name;
hpdl
1
245     }
246
247     function setEmailAddress($email_address) {
hpdl
184
248       $this->_data['email_address'] = $email_address;
hpdl
1
249     }
250
251     function setCountryID($id) {
hpdl
184
252       $this->_data['country_id'] = $id;
hpdl
1
253     }
254
255     function setZoneID($id) {
hpdl
184
256       $this->_data['zone_id'] = $id;
hpdl
1
257     }
hpdl
201
258
259     function reset() {
260       $this->_is_logged_on = false;
261       $this->_data = array();
262
hpdl
203
263       if (isset($_SESSION['osC_Customer_data'])) {
264         unset($_SESSION['osC_Customer_data']);
265       }
hpdl
201
266     }
hpdl
1
267   }
268 ?>