Quick Search:

View

Revision:

Diff

Diff from 732 to:

Annotations

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

Annotated File View

hpdl
732
1 <?php
2 /*
3   $Id: $
4
5   osCommerce, Open Source E-Commerce Solutions
6   http://www.oscommerce.com
7
8   Copyright (c) 2006 osCommerce
9
10   Released under the GNU General Public License
11 */
12
13   class osC_Address {
14     function format($address, $new_line = "\n") {
15       global $osC_Database;
16
17       $address_format = '';
18
19       if (is_numeric($address)) {
20         $Qaddress = $osC_Database->query('select entry_firstname as firstname, entry_lastname as lastname, entry_company as company, entry_street_address as street_address, entry_suburb as suburb, entry_city as city, entry_postcode as postcode, entry_state as state, entry_zone_id as zone_id, entry_country_id as country_id from :table_address_book where address_book_id = :address_book_id');
21         $Qaddress->bindTable(':table_address_book', TABLE_ADDRESS_BOOK);
22         $Qaddress->bindInt(':address_book_id', $address);
23         $Qaddress->execute();
24
25         $address = $Qaddress->toArray();
26       }
27
28       $firstname = $lastname = '';
29
30       if (isset($address['firstname']) && !empty($address['firstname'])) {
31         $firstname = $address['firstname'];
32         $lastname = $address['lastname'];
33       } elseif (isset($address['name']) && !empty($address['name'])) {
34         $firstname = $address['name'];
35       }
36
37       $state = $address['state'];
38       $state_code = $address['state_code'];
39
40       if (isset($address['zone_id']) && is_numeric($address['zone_id']) && ($address['zone_id'] > 0)) {
41         $state = osC_Address::getZoneName($address['zone_id']);
42         $state_code = osC_Address::getZoneCode($address['zone_id']);
43       }
44
45       $country = $address['country'];
46
47       if (isset($address['country_id']) && is_numeric($address['country_id']) && ($address['country_id'] > 0)) {
48         $country = osC_Address::getCountryName($address['country_id']);
49       }
50
51       if (isset($address['format'])) {
52         $address_format = $address['format'];
53       } elseif (isset($address['country_id']) && is_numeric($address['country_id']) && ($address['country_id'] > 0)) {
54         $address_format = osC_Address::getFormat($address['country_id']);
55       }
56
57       if (empty($address_format)) {
58         $address_format = ":name\n:street_address\n:postcode :city\n:country";
59       }
60
61       $find_array = array('/\:name\b/',
62                           '/\:street_address\b/',
63                           '/\:suburb\b/',
64                           '/\:city\b/',
65                           '/\:postcode\b/',
66                           '/\:state\b/',
67                           '/\:state_code\b/',
68                           '/\:country\b/');
69
70       $replace_array = array(osc_output_string_protected($firstname . ' ' . $lastname),
71                              osc_output_string_protected($address['street_address']),
72                              osc_output_string_protected($address['suburb']),
73                              osc_output_string_protected($address['city']),
74                              osc_output_string_protected($address['postcode']),
75                              osc_output_string_protected($state),
76                              osc_output_string_protected($state_code),
77                              osc_output_string_protected($country));
78
79       $formated = preg_replace($find_array, $replace_array, $address_format);
80
81       if ( (ACCOUNT_COMPANY > -1) && !empty($address['company']) ) {
82         $company = osc_output_string_protected($address['company']);
83
84         $formated = $company . $new_line . $formated;
85       }
86
87       if ($new_line != "\n") {
88         $formated = str_replace("\n", $new_line, $formated);
89       }
90
91       return $formated;
92     }
93
94     function getCountries() {
95       global $osC_Database;
96
97       static $_countries;
98
99       if (!isset($_countries)) {
100         $_countries = array();
101
102         $Qcountries = $osC_Database->query('select * from :table_countries order by countries_name');
103         $Qcountries->bindTable(':table_countries', TABLE_COUNTRIES);
104         $Qcountries->execute();
105
106         while ($Qcountries->next()) {
107           $_countries[] = array('id' => $Qcountries->valueInt('countries_id'),
108                                 'name' => $Qcountries->value('countries_name'),
109                                 'iso_2' => $Qcountries->value('countries_iso_code_2'),
110                                 'iso_3' => $Qcountries->value('countries_iso_code_3'),
111                                 'format' => $Qcountries->value('address_format'));
112         }
113
114         $Qcountries->freeResult();
115       }
116
117       return $_countries;
118     }
119
120     function getCountryName($id) {
121       global $osC_Database;
122
123       $Qcountry = $osC_Database->query('select countries_name from :table_countries where countries_id = :countries_id');
124       $Qcountry->bindTable(':table_countries', TABLE_COUNTRIES);
125       $Qcountry->bindInt(':countries_id', $id);
126       $Qcountry->execute();
127
128       return $Qcountry->value('countries_name');
129     }
130
131     function getCountryIsoCode2($id) {
132       global $osC_Database;
133
134       $Qcountry = $osC_Database->query('select countries_iso_code_2 from :table_countries where countries_id = :countries_id');
135       $Qcountry->bindTable(':table_countries', TABLE_COUNTRIES);
136       $Qcountry->bindInt(':countries_id', $id);
137       $Qcountry->execute();
138
139       return $Qcountry->value('countries_iso_code_2');
140     }
141
142     function getCountryIsoCode3($id) {
143       global $osC_Database;
144
145       $Qcountry = $osC_Database->query('select countries_iso_code_3 from :table_countries where countries_id = :countries_id');
146       $Qcountry->bindTable(':table_countries', TABLE_COUNTRIES);
147       $Qcountry->bindInt(':countries_id', $id);
148       $Qcountry->execute();
149
150       return $Qcountry->value('countries_iso_code_3');
151     }
152
153     function getFormat($id) {
154       global $osC_Database;
155
156       $Qcountry = $osC_Database->query('select address_format from :table_countries where countries_id = :countries_id');
157       $Qcountry->bindTable(':table_countries', TABLE_COUNTRIES);
158       $Qcountry->bindInt(':countries_id', $id);
159       $Qcountry->execute();
160
161       return $Qcountry->value('address_format');
162     }
163
164     function getZoneName($id) {
165       global $osC_Database;
166
167       $Qzone = $osC_Database->query('select zone_name from :table_zones where zone_id = :zone_id');
168       $Qzone->bindTable(':table_zones', TABLE_ZONES);
169       $Qzone->bindInt(':zone_id', $id);
170       $Qzone->execute();
171
172       return $Qzone->value('zone_name');
173     }
174
175     function getZoneCode($id) {
176       global $osC_Database;
177
178       $Qzone = $osC_Database->query('select zone_code from :table_zones where zone_id = :zone_id');
179       $Qzone->bindTable(':table_zones', TABLE_ZONES);
180       $Qzone->bindInt(':zone_id', $id);
181       $Qzone->execute();
182
183       return $Qzone->value('zone_code');
184     }
185   }
186 ?>