Move addressbook param code back to the applications
authorMichael M Slusarz <slusarz@curecanti.org>
Wed, 7 Apr 2010 14:32:02 +0000 (08:32 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Wed, 7 Apr 2010 14:32:02 +0000 (08:32 -0600)
framework/Core/lib/Horde/Core/Prefs/Ui/Widgets.php
imp/lib/Prefs/Ui.php
kronolith/contacts.php
kronolith/lib/Ajax/Imple/ContactAutoCompleter.php
kronolith/lib/Application.php
kronolith/lib/Kronolith.php
whups/lib/Ajax/Imple/ContactAutoCompleter.php
whups/lib/Application.php
whups/lib/Whups.php

index 7c8c487..2efd02a 100644 (file)
@@ -122,9 +122,16 @@ class Horde_Core_Prefs_Ui_Widgets
      * search_fields contains a hash containing sources as keys and an array
      * of search fields as the value.
      *
+     * @param array $data  Data items:
+     * <pre>
+     * 'fields' - (array) Hash containing addressbook sources as keys and an
+     *            array of search fields as values.
+     * 'sources' - (array) List of selected addressbooks.
+     * </pre>
+     *
      * @return string  HTML UI code.
      */
-    static public function addressbooks()
+    static public function addressbooks($data)
     {
         global $prefs, $registry;
 
@@ -151,20 +158,18 @@ class Horde_Core_Prefs_Ui_Widgets
             $writeable = array();
         }
 
-        $search = Horde_Core_Prefs_Utils::getAddressbookSearchParams();
-
         if (count($readable) == 1) {
             // Only one source, no need to display the selection widget
-            $search['sources'] = array_keys($readable);
+            $data['sources'] = array_keys($readable);
         }
 
-        foreach ($search['sources'] as $source) {
+        foreach ($data['sources'] as $source) {
             if (!empty($readable[$source])) {
                 $selected[$source] = $readable[$source];
             }
         }
 
-        foreach (array_diff(array_keys($readable), $search['sources']) as $val) {
+        foreach (array_diff(array_keys($readable), $data['sources']) as $val) {
             $unselected[$val] = $readable[$val];
         }
 
@@ -192,8 +197,8 @@ class Horde_Core_Prefs_Ui_Widgets
                                 'name' => $field['name'],
                                 'label' => $field['label']
                             );
-                            if (isset($search['fields'][$source]) &&
-                                in_array($field['name'], $search['fields'][$source])) {
+                            if (isset($data['fields'][$source]) &&
+                                in_array($field['name'], $data['fields'][$source])) {
                                 $tmpsel[] = $field['name'];
                             }
                         }
index 7c1e65d..e583faf 100644 (file)
@@ -308,7 +308,11 @@ class IMP_Prefs_Ui
             return $this->_sound();
 
         case 'sourceselect':
-            return Horde_Core_Prefs_Ui_Widgets::addressbooks();
+            $search = IMP::getAddressbookSearchParams();
+            return Horde_Core_Prefs_Ui_Widgets::addressbooks(array(
+                'fields' => $search['fields'],
+                'sources' => $search['sources']
+            ));
 
         case 'spamselect':
             return $this->_spam();
index c2e9013..0b7ea8d 100644 (file)
@@ -33,9 +33,9 @@ $apiargs['addresses'] = array($search);
 $apiargs['addressbooks'] = array($source);
 $apiargs['fields'] = array();
 
-$search_fields_pref = json_decode($prefs->getValue('search_fields'), true);
-if (!empty($search_fields_pref) && isset($search_fields_pref[$source])) {
-    $apiargs['fields'][$source] = $search_fields_pref[$source];
+$searchpref = Kronolith::getAddressbookSearchParams();
+if (isset($searchpref[$source])) {
+    $apiargs['fields'][$source] = $searchpref[$source];
 }
 
 if ($search || $prefs->getValue('display_contact')) {
index 38666c3..cfc6cc6 100644 (file)
@@ -75,18 +75,10 @@ class Kronolith_Ajax_Imple_ContactAutoCompleter extends Horde_Ajax_Imple_AutoCom
 
         $search = reset(array_filter(array_map('trim', Horde_Mime_Address::explode($addrString, ',;'))));
 
-        $src = json_decode($GLOBALS['prefs']->getValue('search_sources'));
-        if (!is_array($src)) {
-            $src = array();
-        }
-
-        $fields = json_decode($GLOBALS['prefs']->getValue('search_fields'), true);
-        if (!is_array($fields)) {
-            $fields = array();
-        }
+        $searchpref = Kronolith::getAddressbookSearchParams();
 
         try {
-            $res = $GLOBALS['registry']->call('contacts/search', array($search, $src, $fields, true));
+            $res = $GLOBALS['registry']->call('contacts/search', array($search, $searchpref['sources'], $searchpref['fields'], true));
         } catch (Horde_Exception $e) {
             Horde::logMessage($e, 'ERR');
             return array();
index e30bcfa..15cde7d 100644 (file)
@@ -202,7 +202,11 @@ class Kronolith_Application extends Horde_Registry_Application
             return $this->_defaultAlarmManagement($ui);
 
         case 'sourceselect':
-            return Horde_Core_Prefs_Ui_Widgets::addressbooks();
+            $search = Kronolith::getAddressbookSearchParams();
+            return Horde_Core_Prefs_Ui_Widgets::addressbooks(array(
+                'fields' => $search['fields'],
+                'sources' => $search['sources']
+            ));
         }
 
         return '';
index b531df2..5176135 100644 (file)
@@ -2721,4 +2721,27 @@ class Kronolith
         }
     }
 
+    /**
+     * Determines parameters needed to do an address search
+     *
+     * @return array  An array with two keys: 'fields' and 'sources'.
+     */
+    static public function getAddressbookSearchParams()
+    {
+        $src = json_decode($GLOBALS['prefs']->getValue('search_sources'));
+        if (empty($src)) {
+            $src = array();
+        }
+
+        $fields = json_decode($GLOBALS['prefs']->getValue('search_fields'), true);
+        if (empty($fields)) {
+            $fields = array();
+        }
+
+        return array(
+            'fields' => $fields,
+            'sources' => $src
+        );
+    }
+
 }
index 990e8d2..9699a8b 100644 (file)
@@ -96,7 +96,7 @@ class Whups_Ajax_Imple_ContactAutoCompleter extends Horde_Ajax_Imple_AutoComplet
      */
     static public function getAddressList($search = '')
     {
-        $sparams = self::getAddressSearchParams();
+        $sparams = Whups::getAddressbookSearchParams();
         try {
             $res = $GLOBALS['registry']->call('contacts/search', array($search, $sparams['sources'], $sparams['fields'], false));
         } catch (Horde_Exception $e) {
@@ -127,28 +127,4 @@ class Whups_Ajax_Imple_ContactAutoCompleter extends Horde_Ajax_Imple_AutoComplet
         return $search;
     }
 
-    /**
-     * Determines parameters needed to do an address search
-     *
-     * @return array  An array with two keys: 'sources' and 'fields'.
-     */
-    static public function getAddressSearchParams()
-    {
-        $src = json_decode($GLOBALS['prefs']->getValue('search_sources'));
-        if (!is_array($src)) {
-            $src = array();
-        }
-
-
-        $fields = json_decode($GLOBALS['prefs']->getValue('search_fields'), true);
-        if (!is_array($fields)) {
-            $fields = array();
-        }
-
-        return array(
-            'fields' => $fields,
-            'sources' => $src
-        );
-    }
-
 }
index 34cc3f1..b6adab6 100644 (file)
@@ -152,7 +152,11 @@ class Whups_Application extends Horde_Registry_Application
     {
         switch ($item) {
         case 'sourceselect':
-            return Horde_Core_Prefs_Ui_Widgets::addressbooks();
+            $search = Whups::getAddressbookSearchParams();
+            return Horde_Core_Prefs_Ui_Widgets::addressbooks(array(
+                'fields' => $search['fields'],
+                'sources' => $search['sources']
+            ));
         }
 
         return '';
index 1e35641..61a02c8 100644 (file)
@@ -998,4 +998,27 @@ class Whups {
             : array();
     }
 
+    /**
+     * Determines parameters needed to do an address search
+     *
+     * @return array  An array with two keys: 'sources' and 'fields'.
+     */
+    static public function getAddressbookSearchParams()
+    {
+        $src = json_decode($GLOBALS['prefs']->getValue('search_sources'));
+        if (!is_array($src)) {
+            $src = array();
+        }
+
+        $fields = json_decode($GLOBALS['prefs']->getValue('search_fields'), true);
+        if (!is_array($fields)) {
+            $fields = array();
+        }
+
+        return array(
+            'fields' => $fields,
+            'sources' => $src
+        );
+    }
+
 }