  |
5 | 5 | | osCommerce, Open Source E-Commerce Solutions |
| |
6 | 6 | | http://www.oscommerce.com |
| |
7 | 7 | | |
  |
8 | | - | Copyright (c) 2005 osCommerce |
| |
| 8 | + | Copyright (c) 2007 osCommerce |
|
9 | 9 | | |
| |
10 | 10 | | This program is free software; you can redistribute it and/or modify |
| |
11 | 11 | | it under the terms of the GNU General Public License v2 (1991) |
| |
12 | 12 | | as published by the Free Software Foundation. |
| |
13 | 13 | | */ |
| |
14 | 14 | | |
  |
| 15 | + | /** |
| |
| 16 | + | * The osC_AddressBook class handles customer address book related functions |
| |
| 17 | + | */ |
| |
| 18 | + | |
|
15 | 19 | | class osC_AddressBook { |
| |
16 | 20 | | |
  |
17 | | - | function &getListing() { |
| |
| 21 | + | /** |
| |
| 22 | + | * Returns the address book entries for the current customer |
| |
| 23 | + | * |
| |
| 24 | + | * @access public |
| |
| 25 | + | * @return array |
| |
| 26 | + | */ |
| |
| 27 | + | |
| |
| 28 | + | public static function &getListing() { |
|
18 | 29 | | global $osC_Database, $osC_Customer; |
| |
19 | 30 | | |
| |
20 | 31 | | $Qaddresses = $osC_Database->query('select ab.address_book_id, ab.entry_firstname as firstname, ab.entry_lastname as lastname, ab.entry_company as company, ab.entry_street_address as street_address, ab.entry_suburb as suburb, ab.entry_city as city, ab.entry_postcode as postcode, ab.entry_state as state, ab.entry_zone_id as zone_id, ab.entry_country_id as country_id, z.zone_code as zone_code, c.countries_name as country_title from :table_address_book ab left join :table_zones z on (ab.entry_zone_id = z.zone_id), :table_countries c where ab.customers_id = :customers_id and ab.entry_country_id = c.countries_id order by ab.entry_firstname, ab.entry_lastname'); |
| |
|
|
 |
… |
|
27 | 38 | | return $Qaddresses; |
| |
28 | 39 | | } |
| |
29 | 40 | | |
  |
30 | | - | function &getEntry($id) { |
| |
| 41 | + | /** |
| |
| 42 | + | * Returns a specific address book entry for the current customer |
| |
| 43 | + | * |
| |
| 44 | + | * @param int $id The ID of the address book entry to return |
| |
| 45 | + | * @access public |
| |
| 46 | + | * @return array |
| |
| 47 | + | */ |
| |
| 48 | + | |
| |
| 49 | + | public static function &getEntry($id) { |
|
31 | 50 | | global $osC_Database, $osC_Customer; |
| |
32 | 51 | | |
| |
33 | 52 | | $Qentry = $osC_Database->query('select entry_gender, entry_company, entry_firstname, entry_lastname, entry_street_address, entry_suburb, entry_postcode, entry_city, entry_state, entry_zone_id, entry_country_id, entry_telephone, entry_fax from :table_address_book where address_book_id = :address_book_id and customers_id = :customers_id'); |
| |
|
|
 |
… |
|
39 | 58 | | return $Qentry; |
| |
40 | 59 | | } |
| |
41 | 60 | | |
  |
42 | | - | function checkEntry($id) { |
| |
| 61 | + | /** |
| |
| 62 | + | * Verify the address book entry belongs to the current customer |
| |
| 63 | + | * |
| |
| 64 | + | * @param int $id The ID of the address book entry to verify |
| |
| 65 | + | * @access public |
| |
| 66 | + | * @return boolean |
| |
| 67 | + | */ |
| |
| 68 | + | |
| |
| 69 | + | public static function checkEntry($id) { |
|
43 | 70 | | global $osC_Database, $osC_Customer; |
| |
44 | 71 | | |
| |
45 | 72 | | $Qentry = $osC_Database->query('select address_book_id from :table_address_book where address_book_id = :address_book_id and customers_id = :customers_id'); |
| |
|
|
 |
… |
|
48 | 75 | | $Qentry->bindInt(':customers_id', $osC_Customer->getID()); |
| |
49 | 76 | | $Qentry->execute(); |
| |
50 | 77 | | |
  |
51 | | - | if ($Qentry->numberOfRows() === 1) { |
| |
52 | | - | return true; |
| |
53 | | - | } |
| |
54 | | - | |
| |
55 | | - | return false; |
| |
| 78 | + | return ( $Qentry->numberOfRows() === 1 ); |
|
56 | 79 | | } |
| |
57 | 80 | | |
  |
58 | | - | function numberOfEntries() { |
| |
| 81 | + | /** |
| |
| 82 | + | * Return the number of address book entries the current customer has |
| |
| 83 | + | * |
| |
| 84 | + | * @access public |
| |
| 85 | + | * @return integer |
| |
| 86 | + | */ |
| |
| 87 | + | |
| |
| 88 | + | public static function numberOfEntries() { |
|
59 | 89 | | global $osC_Database, $osC_Customer; |
| |
60 | 90 | | |
| |
61 | 91 | | static $total_entries; |
| |
62 | 92 | | |
  |
63 | | - | if ( !is_numeric($total_entries) ) { |
| |
| 93 | + | if ( !isset($total_entries) ) { |
|
64 | 94 | | $Qaddresses = $osC_Database->query('select count(*) as total from :table_address_book where customers_id = :customers_id'); |
| |
65 | 95 | | $Qaddresses->bindTable(':table_address_book', TABLE_ADDRESS_BOOK); |
| |
66 | 96 | | $Qaddresses->bindInt(':customers_id', $osC_Customer->getID()); |
| |
|
|
 |
… |
|
72 | 102 | | return $total_entries; |
| |
73 | 103 | | } |
| |
74 | 104 | | |
  |
75 | | - | function saveEntry($data, $id = '') { |
| |
| 105 | + | /** |
| |
| 106 | + | * Save an address book entry |
| |
| 107 | + | * |
| |
| 108 | + | * @param array $data An array containing the address book information |
| |
| 109 | + | * @param int $id The ID of the address book entry to update (if this is not provided, a new address book entry is created) |
| |
| 110 | + | * @access public |
| |
| 111 | + | * @return boolean |
| |
| 112 | + | */ |
| |
| 113 | + | |
| |
| 114 | + | public static function saveEntry($data, $id = '') { |
|
76 | 115 | | global $osC_Database, $osC_Customer; |
| |
77 | 116 | | |
| |
78 | 117 | | $updated_record = false; |
| |
79 | 118 | | |
  |
80 | | - | if (is_numeric($id)) { |
| |
| 119 | + | if ( is_numeric($id) ) { |
|
81 | 120 | | $Qab = $osC_Database->query('update :table_address_book set customers_id = :customers_id, entry_gender = :entry_gender, entry_company = :entry_company, entry_firstname = :entry_firstname, entry_lastname = :entry_lastname, entry_street_address = :entry_street_address, entry_suburb = :entry_suburb, entry_postcode = :entry_postcode, entry_city = :entry_city, entry_state = :entry_state, entry_country_id = :entry_country_id, entry_zone_id = :entry_zone_id, entry_telephone = :entry_telephone, entry_fax = :entry_fax where address_book_id = :address_book_id and customers_id = :customers_id'); |
| |
82 | 121 | | $Qab->bindInt(':address_book_id', $id); |
| |
83 | 122 | | $Qab->bindInt(':customers_id', $osC_Customer->getID()); |
| |
84 | 123 | | } else { |
| |
85 | 124 | | $Qab = $osC_Database->query('insert into :table_address_book (customers_id, entry_gender, entry_company, entry_firstname, entry_lastname, entry_street_address, entry_suburb, entry_postcode, entry_city, entry_state, entry_country_id, entry_zone_id, entry_telephone, entry_fax) values (:customers_id, :entry_gender, :entry_company, :entry_firstname, :entry_lastname, :entry_street_address, :entry_suburb, :entry_postcode, :entry_city, :entry_state, :entry_country_id, :entry_zone_id, :entry_telephone, :entry_fax)'); |
| |
86 | 125 | | } |
  |
| 126 | + | |
|
87 | 127 | | $Qab->bindTable(':table_address_book', TABLE_ADDRESS_BOOK); |
| |
88 | 128 | | $Qab->bindInt(':customers_id', $osC_Customer->getID()); |
| |
89 | 129 | | $Qab->bindValue(':entry_gender', ((ACCOUNT_GENDER > -1) && isset($data['gender']) && (($data['gender'] == 'm') || ($data['gender'] == 'f'))) ? $data['gender'] : ''); |
| |
|
|
 |
… |
|
101 | 141 | | $Qab->bindValue(':entry_fax', (ACCOUNT_FAX > -1) ? $data['fax'] : ''); |
| |
102 | 142 | | $Qab->execute(); |
| |
103 | 143 | | |
  |
104 | | - | if ($Qab->affectedRows() === 1) { |
| |
| 144 | + | if ( $Qab->affectedRows() === 1 ) { |
|
105 | 145 | | $updated_record = true; |
| |
106 | 146 | | } |
| |
107 | 147 | | |
  |
108 | | - | if (isset($data['primary']) && ($data['primary'] === true)) { |
| |
109 | | - | if (is_numeric($id) === false) { |
| |
| 148 | + | if ( isset($data['primary']) && ($data['primary'] === true) ) { |
| |
| 149 | + | if ( !is_numeric($id) ) { |
|
110 | 150 | | $id = $osC_Database->nextID(); |
| |
111 | 151 | | } |
| |
112 | 152 | | |
  |
113 | | - | if (osC_AddressBook::setPrimaryAddress($id)) { |
| |
| 153 | + | if ( osC_AddressBook::setPrimaryAddress($id) ) { |
|
114 | 154 | | $osC_Customer->setCountryID($data['country']); |
| |
115 | 155 | | $osC_Customer->setZoneID(($data['zone_id'] > 0) ? (int)$data['zone_id'] : '0'); |
| |
116 | 156 | | $osC_Customer->setDefaultAddressID($id); |
| |
117 | 157 | | |
  |
118 | | - | if ($updated_record === false) { |
| |
| 158 | + | if ( $updated_record === false ) { |
|
119 | 159 | | $updated_record = true; |
| |
120 | 160 | | } |
| |
121 | 161 | | } |
| |
122 | 162 | | } |
| |
123 | 163 | | |
  |
124 | | - | if ($updated_record === true) { |
| |
| 164 | + | if ( $updated_record === true ) { |
|
125 | 165 | | return true; |
| |
126 | 166 | | } |
| |
127 | 167 | | |
| |
128 | 168 | | return false; |
| |
129 | 169 | | } |
| |
130 | 170 | | |
  |
131 | | - | function setPrimaryAddress($id) { |
| |
| 171 | + | /** |
| |
| 172 | + | * Set the address book entry as the primary address for the current customer |
| |
| 173 | + | * |
| |
| 174 | + | * @param int $id The ID of the address book entry |
| |
| 175 | + | * @access public |
| |
| 176 | + | * @return boolean |
| |
| 177 | + | */ |
| |
| 178 | + | |
| |
| 179 | + | public static function setPrimaryAddress($id) { |
|
132 | 180 | | global $osC_Database, $osC_Customer; |
| |
133 | 181 | | |
  |
134 | | - | if (is_numeric($id) && ($id > 0)) { |
| |
| 182 | + | if ( is_numeric($id) && ($id > 0) ) { |
|
135 | 183 | | $Qupdate = $osC_Database->query('update :table_customers set customers_default_address_id = :customers_default_address_id where customers_id = :customers_id'); |
| |
136 | 184 | | $Qupdate->bindTable(':table_customers', TABLE_CUSTOMERS); |
| |
137 | 185 | | $Qupdate->bindInt(':customers_default_address_id', $id); |
| |
138 | 186 | | $Qupdate->bindInt(':customers_id', $osC_Customer->getID()); |
| |
139 | 187 | | $Qupdate->execute(); |
| |
140 | 188 | | |
  |
141 | | - | if ($Qupdate->affectedRows() === 1) { |
| |
142 | | - | return true; |
| |
143 | | - | } |
| |
| 189 | + | return ( $Qupdate->affectedRows() === 1 ); |
|
144 | 190 | | } |
| |
145 | 191 | | |
| |
146 | 192 | | return false; |
| |
147 | 193 | | } |
| |
148 | 194 | | |
  |
149 | | - | function deleteEntry($id) { |
| |
| 195 | + | /** |
| |
| 196 | + | * Delete an address book entry |
| |
| 197 | + | * |
| |
| 198 | + | * @param int $id The ID of the address book entry to delete |
| |
| 199 | + | * @access public |
| |
| 200 | + | * @return boolean |
| |
| 201 | + | */ |
| |
| 202 | + | |
| |
| 203 | + | public static function deleteEntry($id) { |
|
150 | 204 | | global $osC_Database, $osC_Customer; |
| |
151 | 205 | | |
| |
152 | 206 | | $Qdelete = $osC_Database->query('delete from :table_address_book where address_book_id = :address_book_id and customers_id = :customers_id'); |
| |
|
|
 |
… |
|
155 | 209 | | $Qdelete->bindInt(':customers_id', $osC_Customer->getID()); |
| |
156 | 210 | | $Qdelete->execute(); |
| |
157 | 211 | | |
  |
158 | | - | if ($Qdelete->affectedRows() === 1) { |
| |
159 | | - | return true; |
| |
160 | | - | } |
| |
161 | | - | |
| |
162 | | - | return false; |
| |
| 212 | + | return ( $Qdelete->affectedRows() === 1 ); |
  |
163 | 213 | | } |
| |
164 | 214 | | } |
| |
165 | 215 | | ?> |