* fix bug 7930: return the resulting selected array in the methods buildStaticInfoSel...
authorfranzholz <franzholz@735d13b6-9817-0410-8766-e36946ffe9aa>
Sat, 7 Jun 2008 12:42:22 +0000 (12:42 +0000)
committerfranzholz <franzholz@735d13b6-9817-0410-8766-e36946ffe9aa>
Sat, 7 Jun 2008 12:42:22 +0000 (12:42 +0000)
* new method needsInit which tells if the object has already been initialised
* fix bug 8347: Vorarlberg is correct for VB in Austria
* fix bug 8594: no default zone must be used if it does not fit to the default country

git-svn-id: https://svn.typo3.org/TYPO3v4/Extensions/static_info_tables/trunk@9297 735d13b6-9817-0410-8766-e36946ffe9aa

ChangeLog
class.tx_staticinfotables_div.php
doc/manual.sxw
ext_localconf.php
ext_tables.sql
ext_tables_static+adt.sql
pi1/class.tx_staticinfotables_pi1.php

index 4bc9796..5d4781c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2008-06-07  Franz Holzinger  <contact@fholzinger.com>
+       * fix bug 7930: return the resulting selected array in the methods buildStaticInfoSelector and optionsConstructor
+       * new method needsInit which tells if the object has already been initialised
+       * fix bug 8347: Vorarlberg is correct for VB in Austria
+       * fix bug 8594: no default zone must be used if it does not fit to the default country
+
 2008-04-26  Franz Holzinger  <contact@fholzinger.com>
        * fix bug 7930: default values for country zones and currencies have been wrong
        * move static_taxes into a separate extension static_info_tables_taxes
 2008-04-26  Franz Holzinger  <contact@fholzinger.com>
        * fix bug 7930: default values for country zones and currencies have been wrong
        * move static_taxes into a separate extension static_info_tables_taxes
index 33c095f..dda195d 100644 (file)
@@ -132,26 +132,27 @@ class tx_staticinfotables_div {
         *
         * @param       string          table name
         * @param       string          iso code
         *
         * @param       string          table name
         * @param       string          iso code
-        * @param       boolean         If set (default) the TCA definition of the table should be loaded with t3lib_div::loadTCA(). It will be needed to set it to false if you call this function from inside of tca.php
-        * @param       [type]          $index: ...
+        * @param       boolean         If set (default) the TCA definition of the table should be loaded with t3lib_div::loadTCA(). It will be needed to set it to FALSE if you call this function from inside of tca.php
+        * @param       integer         index in the table's isocode_field array in the global variable 
+        *                                 $GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][STATIC_INFO_TABLES_EXTkey]['tables']
         * @return      string          field name
         */
         * @return      string          field name
         */
-       function getIsoCodeField($table, $isoCode, $loadTCA=TRUE, $index=0) {
+       function getIsoCodeField($table, $isoCode, $bLoadTCA=TRUE, $index=0) {
                global $TCA;
                global $TCA;
+               $rc = FALSE;
 
 
-               if ($isoCode && $table && ($isoCodeField = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][STATIC_INFO_TABLES_EXTkey]['tables'][$table]['isocode_field'][$index])) {
-                       if ($loadTCA) {
+               if ($isoCode && $table && (($isoCodeField = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][STATIC_INFO_TABLES_EXTkey]['tables'][$table]['isocode_field'][$index]) != '')) {
+                       if ($bLoadTCA) {
                                t3lib_div::loadTCA($table);
                        }
                                t3lib_div::loadTCA($table);
                        }
-
                        $type = tx_staticinfotables_div::isoCodeType($isoCode);
                        $type = tx_staticinfotables_div::isoCodeType($isoCode);
-
                        $isoCodeField = str_replace ('##', $type, $isoCodeField);
                        $isoCodeField = str_replace ('##', $type, $isoCodeField);
+
                        if (is_array($TCA[$table]['columns'][$isoCodeField])) {
                        if (is_array($TCA[$table]['columns'][$isoCodeField])) {
-                               return $isoCodeField;
+                               $rc = $isoCodeField;
                        }
                }
                        }
                }
-               return FALSE;
+               return $rc;
        }
 
 
        }
 
 
@@ -298,7 +299,6 @@ class tx_staticinfotables_div {
                                        }
                                }
                        }
                                        }
                                }
                        }
-
                        if (is_object($TSFE)) {
                                $enableFields = $TSFE->sys_page->enableFields($table);
                        } else {
                        if (is_object($TSFE)) {
                                $enableFields = $TSFE->sys_page->enableFields($table);
                        } else {
@@ -497,15 +497,6 @@ class tx_staticinfotables_div {
                        if ($uid) {
                                        // update record from hotlist table
                                $newRow = array('sorting' => 'sorting+1');
                        if ($uid) {
                                        // update record from hotlist table
                                $newRow = array('sorting' => 'sorting+1');
-//                             $res = $GLOBALS['TYPO3_DB']->exec_UPDATEquery(
-//                                             'tx_staticinfotables_hotlist',
-//                                             'uid_local='.$uid.
-//                                                     ' AND application='.$GLOBALS['TYPO3_DB']->fullQuoteStr($app,'tx_staticinfotables_hotlist').
-//                                                     ' AND tablenames='.$GLOBALS['TYPO3_DB']->fullQuoteStr($table,'tx_staticinfotables_hotlist').
-//                                                     t3lib_BEfunc::deleteClause('tx_staticinfotables_hotlist'),
-//                                             $newRow
-//                                     );
-
                                // the dumb update function does not allow to use sorting+1 - that's why this trick is necessary
 
                                $GLOBALS['TYPO3_DB']->sql_query(str_replace('"sorting+1"', 'sorting+1', $GLOBALS['TYPO3_DB']->UPDATEquery(
                                // the dumb update function does not allow to use sorting+1 - that's why this trick is necessary
 
                                $GLOBALS['TYPO3_DB']->sql_query(str_replace('"sorting+1"', 'sorting+1', $GLOBALS['TYPO3_DB']->UPDATEquery(
@@ -607,7 +598,7 @@ class tx_staticinfotables_div {
         * It has been copied here in order not to depend on this class library only for this function.
         *
         * @param       array           extension keys which have TCA additions to load
         * It has been copied here in order not to depend on this class library only for this function.
         *
         * @param       array           extension keys which have TCA additions to load
-        * @return      [type]          ...
+        * @return      void
         */
        function loadTcaAdditions($ext_keys){
                global $_EXTKEY, $TCA;
         */
        function loadTcaAdditions($ext_keys){
                global $_EXTKEY, $TCA;
index be1448d..f0bd0cf 100644 (file)
Binary files a/doc/manual.sxw and b/doc/manual.sxw differ
index 961b62f..09d35ec 100644 (file)
@@ -81,7 +81,9 @@ $labelTable = array(
        ),
 );
 
        ),
 );
 
+
 if (isset($GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][STATIC_INFO_TABLES_EXTkey]['tables']) && is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][STATIC_INFO_TABLES_EXTkey]['tables']))       {
 if (isset($GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][STATIC_INFO_TABLES_EXTkey]['tables']) && is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][STATIC_INFO_TABLES_EXTkey]['tables']))       {
+
        $GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][STATIC_INFO_TABLES_EXTkey]['tables'] = array_merge ($labelTable, $GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][STATIC_INFO_TABLES_EXTkey]['tables']);
 } else {
        $GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][STATIC_INFO_TABLES_EXTkey]['tables'] = $labelTable;
        $GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][STATIC_INFO_TABLES_EXTkey]['tables'] = array_merge ($labelTable, $GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][STATIC_INFO_TABLES_EXTkey]['tables']);
 } else {
        $GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][STATIC_INFO_TABLES_EXTkey]['tables'] = $labelTable;
index 47ee22b..29a2e52 100644 (file)
@@ -11,6 +11,7 @@ CREATE TABLE static_territories (
   UNIQUE uid (uid)
 );
 
   UNIQUE uid (uid)
 );
 
+
 #
 # Table structure for table "static_countries"
 #
 #
 # Table structure for table "static_countries"
 #
index f58c8d8..73b9f95 100644 (file)
@@ -436,7 +436,7 @@ INSERT INTO static_country_zones VALUES ('99', '0', 'AT', 'AUT', '40', 'KN', 'K
 INSERT INTO static_country_zones VALUES ('100', '0', 'AT', 'AUT', '40', 'ST', 'Steiermark', '');
 INSERT INTO static_country_zones VALUES ('101', '0', 'AT', 'AUT', '40', 'TI', 'Tirol', '');
 INSERT INTO static_country_zones VALUES ('102', '0', 'AT', 'AUT', '40', 'BL', 'Burgenland', '');
 INSERT INTO static_country_zones VALUES ('100', '0', 'AT', 'AUT', '40', 'ST', 'Steiermark', '');
 INSERT INTO static_country_zones VALUES ('101', '0', 'AT', 'AUT', '40', 'TI', 'Tirol', '');
 INSERT INTO static_country_zones VALUES ('102', '0', 'AT', 'AUT', '40', 'BL', 'Burgenland', '');
-INSERT INTO static_country_zones VALUES ('103', '0', 'AT', 'AUT', '40', 'VB', 'Voralberg', '');
+INSERT INTO static_country_zones VALUES ('103', '0', 'AT', 'AUT', '40', 'VB', 'Vorarlberg', '');
 INSERT INTO static_country_zones VALUES ('104', '0', 'CH', 'CHE', '756', 'AG', 'Aargau', '');
 INSERT INTO static_country_zones VALUES ('105', '0', 'CH', 'CHE', '756', 'AI', 'Appenzell Innerrhoden', '');
 INSERT INTO static_country_zones VALUES ('106', '0', 'CH', 'CHE', '756', 'AR', 'Appenzell Ausserrhoden', '');
 INSERT INTO static_country_zones VALUES ('104', '0', 'CH', 'CHE', '756', 'AG', 'Aargau', '');
 INSERT INTO static_country_zones VALUES ('105', '0', 'CH', 'CHE', '756', 'AI', 'Appenzell Innerrhoden', '');
 INSERT INTO static_country_zones VALUES ('106', '0', 'CH', 'CHE', '756', 'AR', 'Appenzell Ausserrhoden', '');
index 4777101..f8fc26f 100644 (file)
@@ -2,7 +2,7 @@
 /***************************************************************
 *  Copyright notice
 *
 /***************************************************************
 *  Copyright notice
 *
-*  (c) 2004-2008 Stanislas Rolland <stanislas.rolland(arobas)fructifor.ca>
+*  (c) 2004-2008 Stanislas Rolland <stanislas.rolland(arobas)sjbr.ca>
 *  All rights reserved
 *
 *  This script is part of the Typo3 project. The Typo3 project is
 *  All rights reserved
 *
 *  This script is part of the Typo3 project. The Typo3 project is
@@ -30,7 +30,7 @@
  *
  * $Id$
  *
  *
  * $Id$
  *
- * @author     Stanislas Rolland <stanislas.rolland(arobas)fructifor.ca>
+ * @author     Stanislas Rolland <stanislas.rolland(arobas)sjbr.ca>
  */
 
 /**
  */
 
 /**
@@ -84,6 +84,17 @@ class tx_staticinfotables_pi1 extends tslib_pibase {
                'TAXES'         => 'static_taxes',
                'SUBTAXES'      => 'static_taxes'
        );
                'TAXES'         => 'static_taxes',
                'SUBTAXES'      => 'static_taxes'
        );
+       var $bHasBeenInitialised = FALSE;
+
+       /**
+        * Returns info if the tx_staticinfotables_pi1 object has already been initialised.
+        * You need to initialise this object only once.
+        *
+        * @return      boolean         Always returns true
+        */
+       function needsInit ()   {
+               return !$this->bHasBeenInitialised;
+       }
 
        /**
         * Initializing the class: sets the language based on the TS configuration language property
 
        /**
         * Initializing the class: sets the language based on the TS configuration language property
@@ -101,13 +112,13 @@ class tx_staticinfotables_pi1 extends tslib_pibase {
                if (!$this->currency)   {
                        $this->currency = (trim($this->conf['currencyCode'])) ? trim($this->conf['currencyCode']) : 'EUR';
                }
                if (!$this->currency)   {
                        $this->currency = (trim($this->conf['currencyCode'])) ? trim($this->conf['currencyCode']) : 'EUR';
                }
-                       //If not set, we use the Euro
+                       //If nothing is set, we use the Euro because TYPO3 is spread more in this area
                if (!$this->getStaticInfoName('CURRENCIES', $this->currency)) {
                        $this->currency = 'EUR';
                }
                $this->currencyInfo = $this->loadCurrencyInfo($this->currency);
                if (!$this->getStaticInfoName('CURRENCIES', $this->currency)) {
                        $this->currency = 'EUR';
                }
                $this->currencyInfo = $this->loadCurrencyInfo($this->currency);
-
                $this->defaultCountry = $conf['countryCode'];
                $this->defaultCountry = $conf['countryCode'];
+
                if (!$this->defaultCountry)     {
                        $this->defaultCountry = trim($this->conf['countryCode']);
                }
                if (!$this->defaultCountry)     {
                        $this->defaultCountry = trim($this->conf['countryCode']);
                }
@@ -119,8 +130,12 @@ class tx_staticinfotables_pi1 extends tslib_pibase {
                if (!$this->defaultCountryZone) {
                        $this->defaultCountryZone = trim($this->conf['countryZoneCode']);
                }
                if (!$this->defaultCountryZone) {
                        $this->defaultCountryZone = trim($this->conf['countryZoneCode']);
                }
-               if (!$this->getStaticInfoName('SUBDIVISIONS', $this->defaultCountryZone, $this->defaultCountry)) {
-                       $this->defaultCountryZone = 'NRW';
+               if (!$this->getStaticInfoName('SUBDIVISIONS', $this->defaultCountryZone, $this->defaultCountry))        { 
+                       if ($this->defaultCountry == 'DEU') {
+                               $this->defaultCountryZone = 'NRW';
+                       } else {
+                               $this->defaultCountryZone = '';
+                       }
                }
 
                $this->defaultLanguage = $conf['languageCode'];
                }
 
                $this->defaultLanguage = $conf['languageCode'];
@@ -130,31 +145,33 @@ class tx_staticinfotables_pi1 extends tslib_pibase {
                if (!$this->getStaticInfoName('LANGUAGES', $this->defaultLanguage)) {
                        $this->defaultLanguage = 'EN';
                }
                if (!$this->getStaticInfoName('LANGUAGES', $this->defaultLanguage)) {
                        $this->defaultLanguage = 'EN';
                }
-               return true;
+               $this->bHasBeenInitialised = TRUE;
+               return TRUE;
        }
 
        /**
         * Getting the name of a country, country subdivision, currency, language, tax
         *
         * @param       string          Defines the type of entry of the requested name: 'TERRIRORIES', 'COUNTRIES', 'SUBDIVISIONS', 'CURRENCIES', 'LANGUAGES', 'TAXES', 'SUBTAXES'
        }
 
        /**
         * Getting the name of a country, country subdivision, currency, language, tax
         *
         * @param       string          Defines the type of entry of the requested name: 'TERRIRORIES', 'COUNTRIES', 'SUBDIVISIONS', 'CURRENCIES', 'LANGUAGES', 'TAXES', 'SUBTAXES'
-        * @param       string          The ISO alpha-3 code of a territory, country or currency, or the ISO alpha-2 code of a language or the code of a country subdivision
         * @param       string          The ISO alpha-3 code of a territory, country or currency, or the ISO alpha-2 code of a language or the code of a country subdivision, can be a comma ',' separated string, then all the single items are looked up and returned
         * @param       string          The value of the country code (cn_iso_3) for which a name of type 'SUBDIVISIONS', 'TAXES' or 'SUBTAXES' is requested (meaningful only in these cases)
         * @param       string          The ISO alpha-3 code of a territory, country or currency, or the ISO alpha-2 code of a language or the code of a country subdivision, can be a comma ',' separated string, then all the single items are looked up and returned
         * @param       string          The value of the country code (cn_iso_3) for which a name of type 'SUBDIVISIONS', 'TAXES' or 'SUBTAXES' is requested (meaningful only in these cases)
-        * @param       string          The value of the country subdivision code for which a name of type 'SUB_TAXES' is requested (meaningful only in this case)
-        * @param       [type]          $self: ...
+        * @param       string          The value of the country subdivision code for which a name of type 'SUBTAXES' is requested (meaningful only in this case)
+        * @param       boolean         local name only - if set local title is returned
         * @return      string          The name of the object in the current language
         */
         * @return      string          The name of the object in the current language
         */
-       function getStaticInfoName($type='COUNTRIES', $code, $country='', $countrySubdivision='', $self=0) {
+       function getStaticInfoName($type='COUNTRIES', $code, $country='', $countrySubdivision='', $local=FALSE) {
                global $TYPO3_DB, $TSFE;
 
                if (in_array($type, $this->types) && trim($code)) {
                        $codeArray = t3lib_div::trimExplode(',',($code));
                global $TYPO3_DB, $TSFE;
 
                if (in_array($type, $this->types) && trim($code)) {
                        $codeArray = t3lib_div::trimExplode(',',($code));
-
                        $table = $this->tables[$type];
                        $table = $this->tables[$type];
+                       if (!$table)    {
+                               return FALSE;
+                       }
                        $lang = $this->getCurrentLanguage();
                        $lang = $this->getCurrentLanguage();
-                       $isoCode = array();
-                       $isoCode[] = trim($code);
-
+                       if (!t3lib_extMgm::isLoaded(STATIC_INFO_TABLES_EXTkey.'_'.strtolower($lang)))   {
+                               $lang = '';
+                       }
                        $nameArray = array();
                        foreach ($codeArray as $tmpisoCode)     {
                                $isoCodeArray = array();
                        $nameArray = array();
                        foreach ($codeArray as $tmpisoCode)     {
                                $isoCodeArray = array();
@@ -164,23 +181,27 @@ class tx_staticinfotables_pi1 extends tslib_pibase {
                                        case 'TERRITORIES':
                                        case 'COUNTRIES':
                                        case 'CURRENCIES':
                                        case 'TERRITORIES':
                                        case 'COUNTRIES':
                                        case 'CURRENCIES':
-                                               $name = tx_staticinfotables_div::getTitleFromIsoCode($table, $isoCodeArray, $lang);
+                                               $name = tx_staticinfotables_div::getTitleFromIsoCode($table, $isoCodeArray, $lang, $local);
                                                break;
                                        case 'SUBDIVISIONS':
                                        case 'TAXES':
                                                $isoCodeArray[] = trim($country) ? trim($country) : $this->defaultCountry;
                                                break;
                                        case 'SUBDIVISIONS':
                                        case 'TAXES':
                                                $isoCodeArray[] = trim($country) ? trim($country) : $this->defaultCountry;
-                                               $name = tx_staticinfotables_div::getTitleFromIsoCode($table, $isoCodeArray, $lang);
+                                               $name = tx_staticinfotables_div::getTitleFromIsoCode($table, $isoCodeArray, $lang, $local);
                                                break;
                                        case 'SUBTAXES':
                                                $isoCodeArray[] = trim($country) ? trim($country) : $this->defaultCountry;
                                                $isoCodeArray[] = trim($countrySubdivision) ? trim($countrySubdivision) : $this->defaultCountryZone;
                                                break;
                                        case 'SUBTAXES':
                                                $isoCodeArray[] = trim($country) ? trim($country) : $this->defaultCountry;
                                                $isoCodeArray[] = trim($countrySubdivision) ? trim($countrySubdivision) : $this->defaultCountryZone;
-                                               $name = tx_staticinfotables_div::getTitleFromIsoCode($table, $isoCodeArray, $lang);
+                                               $name = tx_staticinfotables_div::getTitleFromIsoCode($table, $isoCodeArray, $lang, $local);
                                                break;
                                        case 'LANGUAGES':
                                                $isoCodeArray = t3lib_div::trimExplode( '_', $code, 1);
                                                break;
                                        case 'LANGUAGES':
                                                $isoCodeArray = t3lib_div::trimExplode( '_', $code, 1);
-                                               $name = tx_staticinfotables_div::getTitleFromIsoCode($table, $isoCodeArray, $lang, $self);
+                                               $name = tx_staticinfotables_div::getTitleFromIsoCode($table, $isoCodeArray, $lang, $local);
                                                break;
                                }
                                                break;
                                }
+                               if (!$name && $lang != 'EN')    {
+                                       // use the default English name if there is not text in another language
+                                       $name = tx_staticinfotables_div::getTitleFromIsoCode($table, $isoCodeArray, '', $local);
+                               }
                                $nameArray[] = $TSFE->csConv($name, $GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$this->extKey]['charset']);
                        }
                        $rc = implode(',',$nameArray);
                                $nameArray[] = $TSFE->csConv($name, $GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$this->extKey]['charset']);
                        }
                        $rc = implode(',',$nameArray);
@@ -206,9 +227,10 @@ class tx_staticinfotables_pi1 extends tslib_pibase {
         * @param       boolean         $local: If set, we are looking for the "local" title field
         * @param       array           additional array to be merged as key => value pair
         * @param       int             max elements that can be selected. Default: 1
         * @param       boolean         $local: If set, we are looking for the "local" title field
         * @param       array           additional array to be merged as key => value pair
         * @param       int             max elements that can be selected. Default: 1
+        * @param       array           out: resulting selected array with the ISO alpha-3 code of the countries
         * @return      string          A set of HTML <select> and <option> tags
         */
         * @return      string          A set of HTML <select> and <option> tags
         */
-       function buildStaticInfoSelector($type='COUNTRIES', $name='', $class='', $selectedArray=array(), $country='', $submit=0, $id='', $title='', $addWhere='', $lang='', $local=FALSE, $mergeArray=array(), $size=1) {
+       function buildStaticInfoSelector($type='COUNTRIES', $name='', $class='', $selectedArray=array(), $country='', $submit=0, $id='', $title='', $addWhere='', $lang='', $local=FALSE, $mergeArray=array(), $size=1, &$outSelectedArray=array())     {
                global $TSFE;
 
                if ($size > 1) {
                global $TSFE;
 
                if ($size > 1) {
@@ -274,7 +296,7 @@ class tx_staticinfotables_pi1 extends tslib_pibase {
                        uasort($nameArray, 'strcoll');
                }
                if(count($nameArray) > 0)       {
                        uasort($nameArray, 'strcoll');
                }
                if(count($nameArray) > 0)       {
-                       $selector .= $this->optionsConstructor($nameArray, $selectedArray);
+                       $selector .= $this->optionsConstructor($nameArray, $selectedArray, $outSelectedArray);
                        $selector .= '</select>'.chr(10);
                } else {
                        $selector = '';
                        $selector .= '</select>'.chr(10);
                } else {
                        $selector = '';
@@ -320,7 +342,6 @@ class tx_staticinfotables_pi1 extends tslib_pibase {
                        $where = '1=1';
                }
                $where .= ($addWhere ? ' AND '.$addWhere : '');
                        $where = '1=1';
                }
                $where .= ($addWhere ? ' AND '.$addWhere : '');
-
                $res = $TYPO3_DB->exec_SELECTquery(
                        $labelFields,
                        $table,
                $res = $TYPO3_DB->exec_SELECTquery(
                        $labelFields,
                        $table,
@@ -328,6 +349,7 @@ class tx_staticinfotables_pi1 extends tslib_pibase {
                );
 
                while ($row = $TYPO3_DB->sql_fetch_assoc($res)) {
                );
 
                while ($row = $TYPO3_DB->sql_fetch_assoc($res)) {
+
                        foreach ($titleFields as $titleField) {
                                if ($row[$titleField]) {
                                        $nameArray[$row['cn_iso_3']] = $TSFE->csConv($row[$titleField], $GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$this->extKey]['charset']);
                        foreach ($titleFields as $titleField) {
                                if ($row[$titleField]) {
                                        $nameArray[$row['cn_iso_3']] = $TSFE->csConv($row[$titleField], $GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$this->extKey]['charset']);
@@ -474,20 +496,26 @@ class tx_staticinfotables_pi1 extends tslib_pibase {
         *
         * @param       array           An array where the values will be the texts of an <option> tags and keys will be the values of the tags
         * @param       string          A pre-selected value: if the value appears as a key, the <option> tag will bear a 'selected' attribute
         *
         * @param       array           An array where the values will be the texts of an <option> tags and keys will be the values of the tags
         * @param       string          A pre-selected value: if the value appears as a key, the <option> tag will bear a 'selected' attribute
+        * @param       array           out: resulting selected array with the ISO alpha-3 code of the countries
         * @return      string          A string of HTML <option> tags
         */
         * @return      string          A string of HTML <option> tags
         */
-       function optionsConstructor($nameArray, $selectedArray=array()) {
+       function optionsConstructor($nameArray, $selectedArray=array(), &$outSelectedArray=array()) {
                global $TSFE;
 
                $options = '';
                foreach($nameArray as $value => $name)  {
                global $TSFE;
 
                $options = '';
                foreach($nameArray as $value => $name)  {
+
                        $options  .= '<option value="'.$value.'"';
                        if (in_array($value, $selectedArray))   {
                                $options  .= ' selected="selected"';
                        $options  .= '<option value="'.$value.'"';
                        if (in_array($value, $selectedArray))   {
                                $options  .= ' selected="selected"';
+                               $outSelectedArray[] = $value;
                        }
                        $options  .= '>'.$name.'</option>'.chr(10);
                }
                        }
                        $options  .= '>'.$name.'</option>'.chr(10);
                }
-
+               if (!isset($outSelectedArray) || count($outSelectedArray) == 0) {
+                       reset ($nameArray);
+                       $outSelectedArray = array(key($nameArray));
+               }
                return $options;
        }
 
                return $options;
        }
 
@@ -562,21 +590,23 @@ class tx_staticinfotables_pi1 extends tslib_pibase {
        /**
         * Formatting an address in the format specified
         *
        /**
         * Formatting an address in the format specified
         *
+        * @param       string          A delimiter for the fields of the returned address
         * @param       string          A street address
         * @param       string          A city
         * @param       string          A country subdivision code (zn_code)
         * @param       string          A ISO alpha-3 country code (cn_iso_3)
         * @param       string          A zip code
         * @param       string          A street address
         * @param       string          A city
         * @param       string          A country subdivision code (zn_code)
         * @param       string          A ISO alpha-3 country code (cn_iso_3)
         * @param       string          A zip code
-        * @param       [type]          $countryCode: ...
         * @return      string          The formated address using the country address format (cn_address_format)
         */
        function formatAddress($delim, $streetAddress, $city, $zip, $subdivisionCode='', $countryCode='')       {
                global $TYPO3_DB;
 
                $formatedAddress = '';
         * @return      string          The formated address using the country address format (cn_address_format)
         */
        function formatAddress($delim, $streetAddress, $city, $zip, $subdivisionCode='', $countryCode='')       {
                global $TYPO3_DB;
 
                $formatedAddress = '';
+               $countryCode = ($countryCode ? trim($countryCode) : $this->defaultCountry);
+               $subdivisionCode = ($subdivisionCode ? trim($subdivisionCode) : ($countryCode == $this->defaultCountry ? $this->defaultCountryZone : ''));
 
                        // Get country name
 
                        // Get country name
-               $countryName = $this->getStaticInfoName('COUNTRIES', (($countryCode)?$countryCode:$this->defaultCountry));
+               $countryName = $this->getStaticInfoName('COUNTRIES', $countryCode);
                if (!$countryName) {
                        return $formatedAddress;
                }
                if (!$countryName) {
                        return $formatedAddress;
                }
@@ -585,14 +615,14 @@ class tx_staticinfotables_pi1 extends tslib_pibase {
                $res = $TYPO3_DB->exec_SELECTquery(
                        'cn_address_format',
                        'static_countries',
                $res = $TYPO3_DB->exec_SELECTquery(
                        'cn_address_format',
                        'static_countries',
-                       'cn_iso_3='.$TYPO3_DB->fullQuoteStr(trim((($countryCode)?$countryCode:$this->defaultCountry)),'static_countries')
+                       'cn_iso_3='.$TYPO3_DB->fullQuoteStr($countryCode,'static_countries')
                );
                $row = $TYPO3_DB->sql_fetch_assoc($res);
                $TYPO3_DB->sql_free_result($res);
                $addressFormat = $row['cn_address_format'];
 
                        // Get country subdivision name
                );
                $row = $TYPO3_DB->sql_fetch_assoc($res);
                $TYPO3_DB->sql_free_result($res);
                $addressFormat = $row['cn_address_format'];
 
                        // Get country subdivision name
-               $countrySubdivisionName = $this->getStaticInfoName('SUBDIVISIONS', (($subdivisionCode)?$subdivisionCode:$this->defaultCountryZone), (($countryCode)?$countryCode:$this->defaultCountry));
+               $countrySubdivisionName = $this->getStaticInfoName('SUBDIVISIONS', $subdivisionCode, $countryCode);
 
                        // Format the address
                $formatedAddress = $this->conf['addressFormat.'][$addressFormat];
 
                        // Format the address
                $formatedAddress = $this->conf['addressFormat.'][$addressFormat];