Quick Search:

View

Revision:

Diff

Diff from 1498 to:

Annotations

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