Fix country handling for AS.
authorMichael J. Rubinsky <mrubinsk@horde.org>
Tue, 11 May 2010 15:33:12 +0000 (11:33 -0400)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Tue, 11 May 2010 15:33:12 +0000 (11:33 -0400)
Use the localized name of the country when sending to the device, and
assume the value coming from the device is also the localized name.

turba/lib/Driver.php

index 982598c..8547bf7 100644 (file)
@@ -2340,7 +2340,7 @@ class Turba_Driver
                 $message->homepostalcode = Horde_String::convertCharset($hash['homePostalCode'], $charset, 'utf-8');
                 break;
             case 'homeCountry':
-                $message->homecountry = Horde_String::convertCharset($hash['homeCountry'], $charset, 'utf-8');
+                $message->homecountry = Horde_String::convertCharset(self::getCountry($hash['homeCountry']), $charset, 'utf-8');
                 break;
             case 'workStreet':
                 $message->businessstreet = Horde_String::convertCharset($hash['workStreet'], $charset, 'utf-8');
@@ -2450,12 +2450,10 @@ class Turba_Driver
             'homecity' => 'homeCity',
             'homestate' => 'homeProvince',
             'homepostalcode' => 'homePostalCode',
-            'homecountry' => 'homeCountry',
             'businessstreet' => 'workStreet',
             'businesscity' => 'workCity',
             'businessstate' => 'workProvince',
             'businesspostalcode' => 'workPostalCode',
-            'businesscountry' => 'workCountry',
             'jobtitle' => 'title',
             'companyname' => 'company',
             'department' => 'department',
@@ -2517,6 +2515,19 @@ class Turba_Driver
             $hash['anniversary'] = null;
         }
 
+        /* Countries */
+        include 'Horde/Nls/Countries.php';
+        $country = array_search($message->homecountry, $countries);
+        if ($country === false) {
+            $country = Horde_String::convertCharset($message->homecountry, 'utf-8', $charset);
+        }
+        $hash['homeCountry'] = $country;
+        $country = array_search($message->businesscountry, $countries);
+        if ($country === false) {
+            $country = Horde_String::convertCharset($message->businesscountry, 'utf-8', $charset);
+        }
+        $hash['workCountry'] = $country;
+
         return $hash;
     }