Quick Search:

View

Revision:

Diff

Diff from 1026 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)) {
hpdl
829
20         $Qaddress = $osC_Database->query('select 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.address_book_id = :address_book_id and ab.entry_country_id = c.countries_id');
hpdl
732
21         $Qaddress->bindTable(':table_address_book', TABLE_ADDRESS_BOOK);
hpdl
829
22         $Qaddress->bindTable(':table_zones', TABLE_ZONES);
23         $Qaddress->bindTable(':table_countries', TABLE_COUNTRIES);
hpdl
732
24         $Qaddress->bindInt(':address_book_id', $address);
25         $Qaddress->execute();
26
27         $address = $Qaddress->toArray();
28       }
29
30       $firstname = $lastname = '';
31
32       if (isset($address['firstname']) && !empty($address['firstname'])) {
33         $firstname = $address['firstname'];
34         $lastname = $address['lastname'];
35       } elseif (isset($address['name']) && !empty($address['name'])) {
36         $firstname = $address['name'];
37       }
38
39       $state = $address['state'];
hpdl
829
40       $state_code = $address['zone_code'];
hpdl
732
41
42       if (isset($address['zone_id']) && is_numeric($address['zone_id']) && ($address['zone_id'] > 0)) {
43         $state = osC_Address::getZoneName($address['zone_id']);
44         $state_code = osC_Address::getZoneCode($address['zone_id']);
45       }
46
hpdl
829
47       $country = $address['country_title'];
hpdl
732
48
hpdl
829
49       if (empty($country) && isset($address['country_id']) && is_numeric($address['country_id']) && ($address['country_id'] > 0)) {
hpdl
732
50         $country = osC_Address::getCountryName($address['country_id']);
51       }
52
53       if (isset($address['format'])) {
54         $address_format = $address['format'];
55       } elseif (isset($address['country_id']) && is_numeric($address['country_id']) && ($address['country_id'] > 0)) {
56         $address_format = osC_Address::getFormat($address['country_id']);
57       }
58
59       if (empty($address_format)) {
60         $address_format = ":name\n:street_address\n:postcode :city\n:country";
61       }
62
63       $find_array = array('/\:name\b/',
64                           '/\:street_address\b/',
65                           '/\:suburb\b/',
66                           '/\:city\b/',
67                           '/\:postcode\b/',
68                           '/\:state\b/',
69                           '/\:state_code\b/',
70                           '/\:country\b/');
71
72       $replace_array = array(osc_output_string_protected($firstname . ' ' . $lastname),
73                              osc_output_string_protected($address['street_address']),
74                              osc_output_string_protected($address['suburb']),
75                              osc_output_string_protected($address['city']),
76                              osc_output_string_protected($address['postcode']),
77                              osc_output_string_protected($state),
78                              osc_output_string_protected($state_code),
79                              osc_output_string_protected($country));
80
81       $formated = preg_replace($find_array, $replace_array, $address_format);
82
83       if ( (ACCOUNT_COMPANY > -1) && !empty($address['company']) ) {
84         $company = osc_output_string_protected($address['company']);
85
86         $formated = $company . $new_line . $formated;
87       }
88
89       if ($new_line != "\n") {
90         $formated = str_replace("\n", $new_line, $formated);
91       }
92
93       return $formated;
94     }
95
96     function getCountries() {
97       global $osC_Database;
98
99       static $_countries;
100
101       if (!isset($_countries)) {
102         $_countries = array();
103
104         $Qcountries = $osC_Database->query('select * from :table_countries order by countries_name');
105         $Qcountries->bindTable(':table_countries', TABLE_COUNTRIES);
106         $Qcountries->execute();
107
108         while ($Qcountries->next()) {
109           $_countries[] = array('id' => $Qcountries->valueInt('countries_id'),
110                                 'name' => $Qcountries->value('countries_name'),
111                                 'iso_2' => $Qcountries->value('countries_iso_code_2'),
112                                 'iso_3' => $Qcountries->value('countries_iso_code_3'),
113                                 'format' => $Qcountries->value('address_format'));
114         }
115
116         $Qcountries->freeResult();
117       }
118
119       return $_countries;
120     }
121
122     function getCountryName($id) {
123       global $osC_Database;
124
125       $Qcountry = $osC_Database->query('select countries_name from :table_countries where countries_id = :countries_id');
126       $Qcountry->bindTable(':table_countries', TABLE_COUNTRIES);
127       $Qcountry->bindInt(':countries_id', $id);
128       $Qcountry->execute();
129
130       return $Qcountry->value('countries_name');
131     }
132
133     function getCountryIsoCode2($id) {
134       global $osC_Database;
135
136       $Qcountry = $osC_Database->query('select countries_iso_code_2 from :table_countries where countries_id = :countries_id');
137       $Qcountry->bindTable(':table_countries', TABLE_COUNTRIES);
138       $Qcountry->bindInt(':countries_id', $id);
139       $Qcountry->execute();
140
141       return $Qcountry->value('countries_iso_code_2');
142     }
143
144     function getCountryIsoCode3($id) {
145       global $osC_Database;
146
147       $Qcountry = $osC_Database->query('select countries_iso_code_3 from :table_countries where countries_id = :countries_id');
148       $Qcountry->bindTable(':table_countries', TABLE_COUNTRIES);
149       $Qcountry->bindInt(':countries_id', $id);
150       $Qcountry->execute();
151
152       return $Qcountry->value('countries_iso_code_3');
153     }
154
155     function getFormat($id) {
156       global $osC_Database;
157
158       $Qcountry = $osC_Database->query('select address_format from :table_countries where countries_id = :countries_id');
159       $Qcountry->bindTable(':table_countries', TABLE_COUNTRIES);
160       $Qcountry->bindInt(':countries_id', $id);
161       $Qcountry->execute();
162
163       return $Qcountry->value('address_format');
164     }
165
166     function getZoneName($id) {
167       global $osC_Database;
168
169       $Qzone = $osC_Database->query('select zone_name from :table_zones where zone_id = :zone_id');
170       $Qzone->bindTable(':table_zones', TABLE_ZONES);
171       $Qzone->bindInt(':zone_id', $id);
172       $Qzone->execute();
173
174       return $Qzone->value('zone_name');
175     }
176
177     function getZoneCode($id) {
178       global $osC_Database;
179
180       $Qzone = $osC_Database->query('select zone_code from :table_zones where zone_id = :zone_id');
181       $Qzone->bindTable(':table_zones', TABLE_ZONES);
182       $Qzone->bindInt(':zone_id', $id);
183       $Qzone->execute();
184
185       return $Qzone->value('zone_code');
186     }
hpdl
743
187
hpdl
1026
188     function getZones($id = null) {
hpdl
743
189       global $osC_Database;
190
191       $zones_array = array();
192
hpdl
1026
193       $Qzones = $osC_Database->query('select z.zone_id, z.zone_country_id, z.zone_name, c.countries_name from :table_zones z, :table_countries c where');
194
195       if (!empty($id)) {
196         $Qzones->appendQuery('z.zone_country_id = :zone_country_id and');
197         $Qzones->bindInt(':zone_country_id', $id);
198       }
199
200       $Qzones->appendQuery('z.zone_country_id = c.countries_id order by c.countries_name, z.zone_name');
201       $Qzones->bindTable(':table_countries', TABLE_COUNTRIES);
hpdl
743
202       $Qzones->bindTable(':table_zones', TABLE_ZONES);
203       $Qzones->execute();
204
205       while ($Qzones->next()) {
206         $zones_array[] = array('id' => $Qzones->valueInt('zone_id'),
hpdl
1026
207                                'name' => $Qzones->value('zone_name'),
208                                'country_id' => $Qzones->valueInt('zone_country_id'),
209                                'country_name' => $Qzones->value('countries_name'));
hpdl
743
210       }
211
212       return $zones_array;
213     }
hpdl
732
214   }
215 ?>