Quick Search:

Mode

Context

Displaying 3 lines of context. None | Less | More | Full

Other Diffs

Ignore

Blank Lines Whitespace:

Diff

1497
 
1669
 
1669
 
address.php
_> 55   osCommerce, Open Source E-Commerce Solutions
  66   http://www.oscommerce.com
  77 
<> 8 -  Copyright (c) 2006 osCommerce
   8+  Copyright (c) 2007 osCommerce
99 
  1010   This program is free software; you can redistribute it and/or modify
  1111   it under the terms of the GNU General Public License v2 (1991)
  1212   as published by the Free Software Foundation.
  1313 */
  1414 
<>  15+/**
   16+ * The osC_Address class handles address related functions such as the format and country and zone information
   17+ */
   18+
1519   class osC_Address {
<> 16 -    function format($address, $new_line = "\n") {
   20+
   21+/**
   22+ * Correctly format an address to the address format rule assigned to its country
   23+ *
   24+ * @param array $address An array (or address_book ID) containing the address information
   25+ * @param string $new_line The string to break new lines with
   26+ * @access public
   27+ * @return string
   28+ */
   29+
   30+    public static function format($address, $new_line = null) {
1731       global $osC_Database;
  1832 
  1933       $address_format = '';
  2034 
<> 21 -      if (is_numeric($address)) {
   35+      if ( is_numeric($address) ) {
2236         $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');
  2337         $Qaddress->bindTable(':table_address_book', TABLE_ADDRESS_BOOK);
  2438         $Qaddress->bindTable(':table_zones', TABLE_ZONES);
     
 !
3145 
  3246       $firstname = $lastname = '';
  3347 
<> 34 -      if (isset($address['firstname']) && !empty($address['firstname'])) {
   48+      if ( isset($address['firstname']) && !empty($address['firstname']) ) {
3549         $firstname = $address['firstname'];
  3650         $lastname = $address['lastname'];
<> 37 -      } elseif (isset($address['name']) && !empty($address['name'])) {
   51+      } elseif ( isset($address['name']) && !empty($address['name']) ) {
3852         $firstname = $address['name'];
  3953       }
  4054 
  4155       $state = $address['state'];
  4256       $state_code = $address['zone_code'];
  4357 
<> 44 -      if (isset($address['zone_id']) && is_numeric($address['zone_id']) && ($address['zone_id'] > 0)) {
   58+      if ( isset($address['zone_id']) && is_numeric($address['zone_id']) && ($address['zone_id'] > 0) ) {
4559         $state = osC_Address::getZoneName($address['zone_id']);
  4660         $state_code = osC_Address::getZoneCode($address['zone_id']);
  4761       }
  4862 
  4963       $country = $address['country_title'];
  5064 
<> 51 -      if (empty($country) && isset($address['country_id']) && is_numeric($address['country_id']) && ($address['country_id'] > 0)) {
   65+      if ( empty($country) && isset($address['country_id']) && is_numeric($address['country_id']) && ($address['country_id'] > 0) ) {
5266         $country = osC_Address::getCountryName($address['country_id']);
  5367       }
  5468 
<> 55 -      if (isset($address['format'])) {
   69+      if ( isset($address['format']) ) {
5670         $address_format = $address['format'];
<> 57 -      } elseif (isset($address['country_id']) && is_numeric($address['country_id']) && ($address['country_id'] > 0)) {
   71+      } elseif ( isset($address['country_id']) && is_numeric($address['country_id']) && ($address['country_id'] > 0) ) {
5872         $address_format = osC_Address::getFormat($address['country_id']);
  5973       }
  6074 
<> 61 -      if (empty($address_format)) {
   75+      if ( empty($address_format) ) {
6276         $address_format = ":name\n:street_address\n:postcode :city\n:country";
  6377       }
  6478 
     
 !
8397       $formated = preg_replace($find_array, $replace_array, $address_format);
  8498 
  8599       if ( (ACCOUNT_COMPANY > -1) && !empty($address['company']) ) {
<> 86 -        $company = osc_output_string_protected($address['company']);
  87 -
  88 -        $formated = $company . $new_line . $formated;
   100+        $formated = osc_output_string_protected($address['company']) . "\n" . $formated;
89101       }
  90102 
<> 91 -      if ($new_line != "\n") {
   103+      if ( !empty($new_line) ) {
92104         $formated = str_replace("\n", $new_line, $formated);
  93105       }
  94106 
  95107       return $formated;
  96108     }
  97109 
<> 98 -    function getCountries() {
   110+/**
   111+ * Return all countries in an array
   112+ *
   113+ * @access public
   114+ * @return array
   115+ */
   116+
   117+    public static function getCountries() {
99118       global $osC_Database;
  100119 
<> 101 -      static $_countries;
   120+      static $countries;
102121 
<> 103 -      if (!isset($_countries)) {
  104 -        $_countries = array();
   122+      if ( !isset($countries) ) {
   123+        $countries = array();
105124 
  106125         $Qcountries = $osC_Database->query('select * from :table_countries order by countries_name');
  107126         $Qcountries->bindTable(':table_countries', TABLE_COUNTRIES);
  108127         $Qcountries->execute();
  109128 
<> 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'));
   129+        while ( $Qcountries->next() ) {
   130+          $countries[] = array('id' => $Qcountries->valueInt('countries_id'),
   131+                               'name' => $Qcountries->value('countries_name'),
   132+                               'iso_2' => $Qcountries->value('countries_iso_code_2'),
   133+                               'iso_3' => $Qcountries->value('countries_iso_code_3'),
   134+                               'format' => $Qcountries->value('address_format'));
116135         }
  117136 
  118137         $Qcountries->freeResult();
  119138       }
  120139 
<> 121 -      return $_countries;
   140+      return $countries;
122141     }
  123142 
<> 124 -    function getCountryName($id) {
   143+/**
   144+ * Return the country name
   145+ *
   146+ * @param int $id The ID of the country
   147+ * @access public
   148+ * @return string
   149+ */
   150+
   151+    public static function getCountryName($id) {
125152       global $osC_Database;
  126153 
  127154       $Qcountry = $osC_Database->query('select countries_name from :table_countries where countries_id = :countries_id');
     
 !
132159       return $Qcountry->value('countries_name');
  133160     }
  134161 
<> 135 -    function getCountryIsoCode2($id) {
   162+/**
   163+ * Return the country 2 character ISO code
   164+ *
   165+ * @param int $id The ID of the country
   166+ * @access public
   167+ * @return string
   168+ */
   169+
   170+    public static function getCountryIsoCode2($id) {
136171       global $osC_Database;
  137172 
  138173       $Qcountry = $osC_Database->query('select countries_iso_code_2 from :table_countries where countries_id = :countries_id');
     
 !
143178       return $Qcountry->value('countries_iso_code_2');
  144179     }
  145180 
<> 146 -    function getCountryIsoCode3($id) {
   181+/**
   182+ * Return the country 3 character ISO code
   183+ *
   184+ * @param int $id The ID of the country
   185+ * @access public
   186+ * @return string
   187+ */
   188+
   189+    public static function getCountryIsoCode3($id) {
147190       global $osC_Database;
  148191 
  149192       $Qcountry = $osC_Database->query('select countries_iso_code_3 from :table_countries where countries_id = :countries_id');
     
 !
154197       return $Qcountry->value('countries_iso_code_3');
  155198     }
  156199 
<> 157 -    function getFormat($id) {
   200+/**
   201+ * Return the address format rule for the country
   202+ *
   203+ * @param int $id The ID of the country
   204+ * @access public
   205+ * @return string
   206+ */
   207+
   208+    public static function getFormat($id) {
158209       global $osC_Database;
  159210 
  160211       $Qcountry = $osC_Database->query('select address_format from :table_countries where countries_id = :countries_id');
     
 !
165216       return $Qcountry->value('address_format');
  166217     }
  167218 
<> 168 -    function getZoneName($id) {
   219+/**
   220+ * Return the zone name
   221+ *
   222+ * @param int $id The ID of the zone
   223+ * @access public
   224+ * @return string
   225+ */
   226+
   227+    public static function getZoneName($id) {
169228       global $osC_Database;
  170229 
  171230       $Qzone = $osC_Database->query('select zone_name from :table_zones where zone_id = :zone_id');
     
 !
176235       return $Qzone->value('zone_name');
  177236     }
  178237 
<> 179 -    function getZoneCode($id) {
   238+/**
   239+ * Return the zone code
   240+ *
   241+ * @param int $id The ID of the zone
   242+ * @access public
   243+ * @return string
   244+ */
   245+
   246+    public static function getZoneCode($id) {
180247       global $osC_Database;
  181248 
  182249       $Qzone = $osC_Database->query('select zone_code from :table_zones where zone_id = :zone_id');
     
 !
187254       return $Qzone->value('zone_code');
  188255     }
  189256 
<> 190 -    function getZones($id = null) {
   257+/**
   258+ * Return the zones belonging to a country, or all zones
   259+ *
   260+ * @param int $id The ID of the country
   261+ * @access public
   262+ * @return array
   263+ */
   264+
   265+    public static function getZones($id = null) {
191266       global $osC_Database;
  192267 
  193268       $zones_array = array();
  194269 
  195270       $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');
  196271 
<> 197 -      if (!empty($id)) {
   272+      if ( !empty($id) ) {
198273         $Qzones->appendQuery('z.zone_country_id = :zone_country_id and');
  199274         $Qzones->bindInt(':zone_country_id', $id);
  200275       }
     
 !
204279       $Qzones->bindTable(':table_zones', TABLE_ZONES);
  205280       $Qzones->execute();
  206281 
<> 207 -      while ($Qzones->next()) {
   282+      while ( $Qzones->next() ) {
<_ 208283         $zones_array[] = array('id' => $Qzones->valueInt('zone_id'),
  209284                                'name' => $Qzones->value('zone_name'),
  210285                                'country_id' => $Qzones->valueInt('zone_country_id'),