From: Michael M Slusarz Date: Wed, 7 Apr 2010 13:04:06 +0000 (-0600) Subject: Improvements to addressbook pref handling X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=686d5ca6ac47356af4ec4620486adff71baecdce;p=horde.git Improvements to addressbook pref handling --- diff --git a/framework/Core/lib/Horde/Core/Prefs/Ui/Widgets.php b/framework/Core/lib/Horde/Core/Prefs/Ui/Widgets.php index 99f132555..6b1800b19 100644 --- a/framework/Core/lib/Horde/Core/Prefs/Ui/Widgets.php +++ b/framework/Core/lib/Horde/Core/Prefs/Ui/Widgets.php @@ -29,6 +29,12 @@ class Horde_Core_Prefs_Ui_Widgets /** * Create code needed for source selection. * + * Returns data in a form variable named 'sources'. If only one source + * was originally given, this variable will contain the list of selected + * values (JSON encoded). If multiple sources were given, this variable + * will contain a list of arrays; each subarray contains the source name + * and the list of selected values (JSON encoded). + * * @param Horde_Core_Prefs_Ui $ui The UI object. * @param array $data Data items: *
@@ -55,14 +61,14 @@ class Horde_Core_Prefs_Ui_Widgets
         foreach ($data['sources'] as $key => $val) {
             $selected = $unselected = array();
 
-            foreach ($data['selected'] as $key2 => $val2) {
+            foreach ($val['selected'] as $key2 => $val2) {
                 $selected[] = array(
                     'l' => $val2,
                     'v' => $key2
                 );
             }
 
-            foreach ($data['unselected'] as $key2 => $val2) {
+            foreach ($val['unselected'] as $key2 => $val2) {
                 $unselected[] = array(
                     'l' => $val2,
                     'v' => $key2
@@ -116,6 +122,11 @@ class Horde_Core_Prefs_Ui_Widgets
     /**
      * Create code needed for addressbook selection.
      *
+     * Returns data in form variables named sources and search_fields.
+     * Sources contains the list of selected addressbooks (JSON encoded).
+     * search_fields contains a hash containing sources as keys and an array
+     * of search fields as the value.
+     *
      * @param Horde_Core_Prefs_Ui $ui  The UI object.
      *
      * @return string  HTML UI code.
@@ -179,49 +190,36 @@ class Horde_Core_Prefs_Ui_Widgets
 
             $js = array();
             foreach (array_keys($readable) as $source) {
-                $tmp = array($source);
+                $tmp = $tmpsel = array();
 
                 try {
                     foreach ($registry->call('contacts/fields', array($source)) as $field) {
                         if ($field['search']) {
-                            $tmp[] = array($field['name'], $field['label'], isset($search['fields'][$source]) && in_array($field['name'], $search['fields'][$source]));
+                            $tmp[] = array(
+                                'name' => $field['name'],
+                                'label' => $field['label']
+                            );
+                            if (isset($search['fields'][$source]) &&
+                                in_array($field['name'], $search['fields'][$source])) {
+                                $tmpsel[] = $field['name'];
+                            }
                         }
                     }
                 } catch (Horde_Exception $e) {}
 
-                $js[] = $tmp;
+                $js[$source] = array(
+                    'entries' => $tmp,
+                    'selected' => $tmpsel
+                );
             }
 
             Horde::addInlineScript(array(
-                'HordeAddressbooksPrefs.fields = ' . Horde_Serialize::serialize($js, Horde_Serialize::JSON, Horde_Nls::getCharset())
+                'HordeAddressbooksPrefs.fields = ' . Horde_Serialize::serialize($js, Horde_Serialize::JSON, Horde_Nls::getCharset()),
+                'HordeAddressbooksPrefs.nonetext = ' . Horde_Serialize::serialize(_("No address book selected."), Horde_Serialize::JSON, Horde_Nls::getCharset())
             ));
         }
 
         return $out . $t->fetch(HORDE_TEMPLATES . '/prefs/addressbooks.html');
     }
 
-    /**
-     * Update prefs for addressbook selection.
-     *
-     * @param Horde_Core_Prefs_Ui $ui  The UI object.
-     *
-     * @return boolean  True if preferences were updated.
-     */
-    static public function addressbooksUpdate($ui)
-    {
-        $updated = false;
-
-        if (isset($ui->vars->sources)) {
-            $GLOBALS['prefs']->setValue('search_sources', implode("\t", Horde_Serialize::unserialize($ui->vars->sources, Horde_Serialize::JSON)));
-            $updated = true;
-        }
-
-        if (isset($ui->vars->search_fields_string)) {
-            $GLOBALS['prefs']->setValue('search_fields', $ui->vars->search_fields_string);
-            $updated = true;
-        }
-
-        return $updated;
-    }
-
 }
diff --git a/framework/Core/lib/Horde/Core/Prefs/Utils.php b/framework/Core/lib/Horde/Core/Prefs/Utils.php
deleted file mode 100644
index cd2603652..000000000
--- a/framework/Core/lib/Horde/Core/Prefs/Utils.php
+++ /dev/null
@@ -1,49 +0,0 @@
-
- * @category Horde
- * @package  Core
- */
-class Horde_Core_Prefs_Utils
-{
-    /**
-     * Determines parameters needed to do an address search
-     *
-     * @return array  An array with two keys: 'sources' and 'fields'.
-     */
-    static public function getAddressbookSearchParams()
-    {
-        $src = explode("\t", $GLOBALS['prefs']->getValue('search_sources'));
-        if ((count($src) == 1) && empty($src[0])) {
-            $src = array();
-        }
-
-        $fields = array();
-        if (($val = $GLOBALS['prefs']->getValue('search_fields'))) {
-            $field_arr = explode("\n", $val);
-            foreach ($field_arr as $field) {
-                $field = trim($field);
-                if (!empty($field)) {
-                    $tmp = explode("\t", $field);
-                    if (count($tmp) > 1) {
-                        $source = array_splice($tmp, 0, 1);
-                        $fields[$source[0]] = $tmp;
-                    }
-                }
-            }
-        }
-
-        return array(
-            'fields' => $fields,
-            'sources' => $src
-        );
-    }
-
-}
diff --git a/framework/Core/package.xml b/framework/Core/package.xml
index 2b5aa1c99..38d8e4f91 100644
--- a/framework/Core/package.xml
+++ b/framework/Core/package.xml
@@ -99,7 +99,6 @@ Application Framework.
         
         
        
-       
        
       
      
@@ -236,7 +235,6 @@ Application Framework.
    
    
    
-   
    
    
    
diff --git a/horde/js/addressbooksprefs.js b/horde/js/addressbooksprefs.js
index 675032a59..4daf8c858 100644
--- a/horde/js/addressbooksprefs.js
+++ b/horde/js/addressbooksprefs.js
@@ -7,80 +7,59 @@
 
 var HordeAddressbooksPrefs = {
 
-    // Variables set by other code: fields
+    // Variables set by other code: fields, nonetext
 
     updateSearchFields: function()
     {
-        var sv = this._getSelectedValue(false),
-            sf = $('search_fields');
+        var tmp,
+            sv = $F('selected_sources'),
+            sf = $('search_fields_select');
 
-        sf.update('');
-        this.fields.each(function(f) {
-            if (f[0] == sv) {
-                f.slice(1).each(function(o) {
-                    var tmp = new Option(o[1], o[0]);
-                    if (o[2]) {
-                        tmp.selected = true;
-                    }
-                    sf.insert(tmp);
-                });
-            }
-        });
+        sf.childElements().invoke('remove');
 
-        this.changeSearchFields();
-    },
-
-    _getSelectedValue: function(index)
-    {
-        var ss = $('selected_sources');
-        if (ss) {
-            if (index) {
-                return ss.selectedIndex;
-            }
-            if (ss.selectedIndex >= 0) {
-                return ss.options[ss.selectedIndex].value;
-            }
-            return '';
+        if (sv.size() == 1) {
+            tmp = this.fields.get(sv.first());
+            tmp.entries.each(function(o) {
+                var opt = new Option(o.label, o.name);
+                if (tmp.selected.include(o.name)) {
+                    opt.selected = true;
+                }
+                sf.insert(opt);
+            });
         } else {
-            return index ? 0 : this.fields[0][0];
+            tmp = new Option(this.nonetext, '');
+            tmp.disabled = true;
+            sf.insert(tmp);
         }
     },
 
     changeSearchFields: function()
     {
-        var data = [],
-            i = 0,
-            sf = $('search_fields'),
-            sv = this._getSelectedValue(true);
+        var tmp,
+            out = $H(),
+            sv = $F('selected_sources');
 
-        $A(sf.options).each(function(o) {
-            this.fields[sv][i][2] = o.selected;
-            ++i;
-        }.bind(this));
+        if (sv.size() == 1) {
+            tmp = this.fields.get(sv.first());
+            tmp.selected = $F('search_fields_select');
+            this.fields.set(sv.first(), tmp);
 
-        this.fields.each(function(f) {
-            var tmp = [ f[0] ];
-            f.slice(1).each(function(o) {
-                if (o[2]) {
-                    tmp.push(o[0]);
-                }
+            this.fields.each(function(f) {
+                out.set(f.key, f.value.selected);
             });
-            data.push(tmp.join("\t"));
-        });
-        $('search_fields_string').setValue(data.join("\n"));
+
+            $('search_fields').setValue(out.toJSON());
+        }
     },
 
     onDomLoad: function()
     {
-        this.updateSearchFields();
+        this.fields = $H(this.fields);
 
-        if ($('search_fields')) {
-            $('search_fields').observe('change', this.changeSearchFields.bind(this));
-        }
+        this.updateSearchFields();
 
-        if ($('selected_sources')) {
-            $('selected_sources').observe('change', this.updateSearchFields.bind(this));
-        }
+        $('search_fields_select').observe('change', this.changeSearchFields.bind(this));
+        $('selected_sources').observe('change', this.updateSearchFields.bind(this));
     }
 
 };
diff --git a/horde/js/sourceselect.js b/horde/js/sourceselect.js
index b34b958f7..d9897c189 100644
--- a/horde/js/sourceselect.js
+++ b/horde/js/sourceselect.js
@@ -34,6 +34,7 @@ var HordeSourceSelectPrefs = {
         $(from).childElements().each(function(c) {
             if (c.selected) {
                 c.remove();
+                c.selected = false;
                 $(to).insert(c);
             }
         });
diff --git a/horde/templates/prefs/addressbooks.html b/horde/templates/prefs/addressbooks.html
index 72602a69c..6dfa38423 100644
--- a/horde/templates/prefs/addressbooks.html
+++ b/horde/templates/prefs/addressbooks.html
@@ -10,12 +10,12 @@
  To select multiple fields, hold down the Control (PC) or Command (Mac) while clicking.
 
 
-
+
 
- - + +
diff --git a/imp/config/prefs.php.dist b/imp/config/prefs.php.dist index 6291b41e2..8bbadc2a0 100644 --- a/imp/config/prefs.php.dist +++ b/imp/config/prefs.php.dist @@ -1409,23 +1409,28 @@ $_prefs['sourceselect'] = array( 'type' => 'special' ); -// address book(s) to use when expanding addresses -// You can provide default values this way (note the \t and the double quotes): -// 'value' => "source_one\tsource_two" -// refer to turba/config/sources.php for possible source values +// Address book(s) to use when expanding addresses +// Refer to turba/config/sources.php for possible source values +// +// You can provide default values this way: +// 'value' => json_encode('source_one', 'source_two') $_prefs['search_sources'] = array( - 'value' => "" + 'value' => '' ); -// field(s) to use when expanding addresses -// This depends on the search_sources preference if you want to provide -// default values: -// 'value' => "source_one\tfield_one\tfield_two\nsource_two\tfield_three" +// Field(s) to use when expanding addresses +// Refer to turba/config/sources.php for possible source and field values +// +// If you want to provide a default value, this field depends on the +// search_sources preference. For example: +// 'value' => json_encode(array( +// 'source_one' => array('field_one', 'field_two'), +// 'source_two' => array('field_three') +// )) // will search the fields 'field_one' and 'field_two' in source_one and // 'field_three' in source_two. -// refer to turba/config/sources.php for possible source and field values $_prefs['search_fields'] = array( - 'value' => "" + 'value' => '' ); // address book to use for adding addresses diff --git a/imp/contacts.php b/imp/contacts.php index ebeef8217..b9c63f1a9 100644 --- a/imp/contacts.php +++ b/imp/contacts.php @@ -40,7 +40,7 @@ if (!isset($vars->formname)) { $vars->formname = 'compose'; } -$search_params = Horde_Core_Prefs_Utils::getAddressbookSearchParams(); +$search_params = IMP::getAddressbookSearchParams(); $apiargs = array( 'addresses' => array($vars->search), 'addressbooks' => array($vars->source), diff --git a/imp/lib/Ajax/Imple/ContactAutoCompleter.php b/imp/lib/Ajax/Imple/ContactAutoCompleter.php index cad00ec61..b43131c4d 100644 --- a/imp/lib/Ajax/Imple/ContactAutoCompleter.php +++ b/imp/lib/Ajax/Imple/ContactAutoCompleter.php @@ -40,7 +40,7 @@ class IMP_Ajax_Imple_ContactAutoCompleter extends Horde_Ajax_Imple_AutoCompleter if ($ac_browser && !isset($_SESSION['imp']['cache']['ac_ajax'])) { $success = $use_ajax = true; - $sparams = Horde_Core_Prefs_Utils::getAddressbookSearchParams(); + $sparams = IMP::getAddressbookSearchParams(); foreach ($sparams['fields'] as $val) { array_map('strtolower', $val); sort($val); diff --git a/imp/lib/Compose.php b/imp/lib/Compose.php index c7851a0fd..49b4760a6 100644 --- a/imp/lib/Compose.php +++ b/imp/lib/Compose.php @@ -2838,7 +2838,7 @@ class IMP_Compose */ static public function getAddressList($search = '') { - $sparams = Horde_Core_Prefs_Utils::getAddressbookSearchParams(); + $sparams = IMP::getAddressbookSearchParams(); try { $res = $GLOBALS['registry']->call('contacts/search', array($search, $sparams['sources'], $sparams['fields'], false)); } catch (Horde_Exception $e) { diff --git a/imp/lib/Crypt/Pgp.php b/imp/lib/Crypt/Pgp.php index 4db65f36c..f5266606a 100644 --- a/imp/lib/Crypt/Pgp.php +++ b/imp/lib/Crypt/Pgp.php @@ -226,7 +226,7 @@ class IMP_Crypt_Pgp extends Horde_Crypt_Pgp */ public function listPublicKeys() { - $params = Horde_Core_Prefs_Utils::getAddressbookSearchParams(); + $params = IMP::getAddressbookSearchParams(); if (empty($params['sources'])) { return array(); } @@ -243,7 +243,7 @@ class IMP_Crypt_Pgp extends Horde_Crypt_Pgp */ public function deletePublicKey($email) { - $params = Horde_Core_Prefs_Utils::getAddressbookSearchParams(); + $params = IMP::getAddressbookSearchParams(); return $GLOBALS['registry']->call('contacts/deleteField', array($email, self::PUBKEY_FIELD, $params['sources'])); } diff --git a/imp/lib/Crypt/Smime.php b/imp/lib/Crypt/Smime.php index ae8e79a4d..76e144503 100644 --- a/imp/lib/Crypt/Smime.php +++ b/imp/lib/Crypt/Smime.php @@ -162,7 +162,7 @@ class IMP_Crypt_Smime extends Horde_Crypt_Smime } catch (Horde_Exception_HookNotSet $e) { } - $params = Horde_Core_Prefs_Utils::getAddressbookSearchParams(); + $params = IMP::getAddressbookSearchParams(); try { $key = $GLOBALS['registry']->call('contacts/getField', array($address, self::PUBKEY_FIELD, $params['sources'], false, true)); @@ -191,7 +191,7 @@ class IMP_Crypt_Smime extends Horde_Crypt_Smime */ public function listPublicKeys() { - $params = Horde_Core_Prefs_Utils::getAddressbookSearchParams(); + $params = IMP::getAddressbookSearchParams(); if (empty($params['sources'])) { return array(); } diff --git a/imp/lib/IMP.php b/imp/lib/IMP.php index 8f4aa098d..9d731744f 100644 --- a/imp/lib/IMP.php +++ b/imp/lib/IMP.php @@ -1137,4 +1137,27 @@ class IMP return 'RedBox.overlay = false; RedBox.showHtml(\'' . addcslashes($t_html, "'/") . '\');'; } + /** + * 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 + ); + } + } diff --git a/imp/lib/LoginTasks/SystemTask/UpgradeFromImp4.php b/imp/lib/LoginTasks/SystemTask/UpgradeFromImp4.php index 5d99b1c5f..80ec99d24 100644 --- a/imp/lib/LoginTasks/SystemTask/UpgradeFromImp4.php +++ b/imp/lib/LoginTasks/SystemTask/UpgradeFromImp4.php @@ -24,27 +24,59 @@ class IMP_LoginTasks_SystemTask_UpgradeFromImp4 extends Horde_LoginTasks_SystemT */ public function execute() { + $this->_upgradeAbookPrefs(); $this->_upgradeForwardPrefs(); $this->_upgradeSortPrefs(); $this->_upgradeVirtualFolders(); } /** + * Upgrade to the new addressbook preferences. + */ + protected function _upgradeAbookPrefs() + { + global $prefs; + + $src = $prefs->getValue('search_sources'); + if (!is_array(json_decode($src))) { + $prefs->setValue('search_sources', json_encode(explode("\t", $src))); + } + + $val = $prefs->getValue('search_fields'); + if (!is_array(json_decode($val, true))) { + $fields = array(); + foreach (explode("\n", $val) as $field) { + $field = trim($field); + if (!empty($field)) { + $tmp = explode("\t", $field); + if (count($tmp) > 1) { + $source = array_splice($tmp, 0, 1); + $fields[$source[0]] = $tmp; + } + } + } + $prefs->setValue('search_fields', $fields); + } + } + + /** * Upgrade to the new forward preferences. */ protected function _upgradeForwardPrefs() { - switch ($GLOBALS['prefs']->getValue('forward_default')) { + global $prefs; + + switch ($prefs->getValue('forward_default')) { case 'forward_attachments': - $GLOBALS['prefs']->setValue('forward_default', 'both'); + $prefs->setValue('forward_default', 'both'); break; case 'forward_all': - $GLOBALS['prefs']->setValue('forward_default', 'attach'); + $prefs->setValue('forward_default', 'attach'); break; case 'forward_body': - $GLOBALS['prefs']->setValue('forward_default', 'body'); + $prefs->setValue('forward_default', 'body'); break; case 'attach': @@ -54,8 +86,8 @@ class IMP_LoginTasks_SystemTask_UpgradeFromImp4 extends Horde_LoginTasks_SystemT break; default: - $GLOBALS['prefs']->setValue('forward_default', 'attach'); - $GLOBALS['prefs']->setDefault('forward_default', true); + $prefs->setValue('forward_default', 'attach'); + $prefs->setDefault('forward_default', true); break; } } @@ -65,8 +97,10 @@ class IMP_LoginTasks_SystemTask_UpgradeFromImp4 extends Horde_LoginTasks_SystemT */ protected function _upgradeSortPrefs() { + global $prefs; + $update = false; - $sortpref = @unserialize($GLOBALS['prefs']->getValue('sortpref')); + $sortpref = @unserialize($prefs->getValue('sortpref')); foreach ($sortpref as $key => $val) { $sb = $this->_newSortbyValue($val['b']); if (!is_null($sb)) { @@ -76,12 +110,12 @@ class IMP_LoginTasks_SystemTask_UpgradeFromImp4 extends Horde_LoginTasks_SystemT } if ($update) { - $GLOBALS['prefs']->setValue('sortpref', serialize($sortpref)); + $prefs->setValue('sortpref', serialize($sortpref)); } - $sb = $this->_newSortbyValue($GLOBALS['prefs']->getValue('sortby')); + $sb = $this->_newSortbyValue($prefs->getValue('sortby')); if (!is_null($sb)) { - $GLOBALS['prefs']->setValue('sortby', $sb); + $prefs->setValue('sortby', $sb); } } diff --git a/imp/lib/Mime/Viewer/Html.php b/imp/lib/Mime/Viewer/Html.php index a44bcc1b0..051ec7adc 100644 --- a/imp/lib/Mime/Viewer/Html.php +++ b/imp/lib/Mime/Viewer/Html.php @@ -310,7 +310,7 @@ class IMP_Horde_Mime_Viewer_Html extends Horde_Mime_Viewer_Html return false; } - $params = Horde_Core_Prefs_Utils::getAddressbookSearchParams(); + $params = IMP::getAddressbookSearchParams(); $headers = $this->_params['contents']->getHeaderOb(); /* Try to get back a result from the search. */ diff --git a/imp/lib/Prefs/Ui.php b/imp/lib/Prefs/Ui.php index 6b43e957f..ef679685d 100644 --- a/imp/lib/Prefs/Ui.php +++ b/imp/lib/Prefs/Ui.php @@ -382,10 +382,7 @@ class IMP_Prefs_Ui return $prefs->setValue('nav_audio', $ui->vars->nav_audio); case 'sourceselect': - if (isset($ui->vars->sources)) { - unset($_SESSION['imp']['cache']['ac_ajax']); - } - return Horde_Core_Prefs_Ui_Widgets::addressbooksUpdate($ui); + return $this->_updateSource($ui); case 'spamselect': return $this->_updateSpecialFolders('spam_folder', $vars->spam, $vars->spam_new, $ui); @@ -1321,6 +1318,35 @@ class IMP_Prefs_Ui return $t->fetch(IMP_TEMPLATES . '/prefs/sound.html'); } + /* Addressbook selection. */ + + /** + * Update address book related preferences. + * + * @param Horde_Core_Prefs_Ui $ui The UI object. + * + * @return boolean True if preferences were updated. + */ + protected function _updateSource($ui) + { + global $prefs; + + $updated = false; + + if (isset($ui->vars->sources)) { + $prefs->setValue('search_sources', $ui->vars->sources); + unset($_SESSION['imp']['cache']['ac_ajax']); + $updated = true; + } + + if (isset($ui->vars->search_fields)) { + $prefs->setValue('search_fields', $ui->vars->search_fields); + $updated = true; + } + + return $updated; + } + /* Spam selection. */ /** diff --git a/kronolith/config/prefs.php.dist b/kronolith/config/prefs.php.dist index 86004744b..587e74c67 100644 --- a/kronolith/config/prefs.php.dist +++ b/kronolith/config/prefs.php.dist @@ -314,23 +314,28 @@ $_prefs['display_contact'] = array( // address book selection widget $_prefs['sourceselect'] = array('type' => 'special'); -// address book(s) to use when expanding addresses -// You can provide default values this way (note the \t and the double quotes): -// 'value' => "source_one\tsource_two" -// refer to turba/config/sources.php for possible source values +// Address book(s) to use when expanding addresses +// Refer to turba/config/sources.php for possible source values +// +// You can provide default values this way: +// 'value' => json_encode('source_one', 'source_two') $_prefs['search_sources'] = array( - 'value' => "" + 'value' => '' ); -// field(s) to use when expanding addresses -// This depends on the search_sources preference if you want to provide -// default values: -// 'value' => "source_one\tfield_one\tfield_two\nsource_two\tfield_three" +// Field(s) to use when expanding addresses +// Refer to turba/config/sources.php for possible source and field values +// +// If you want to provide a default value, this field depends on the +// search_sources preference. For example: +// 'value' => json_encode(array( +// 'source_one' => array('field_one', 'field_two'), +// 'source_two' => array('field_three') +// )) // will search the fields 'field_one' and 'field_two' in source_one and // 'field_three' in source_two. -// refer to turba/config/sources.php for possible source and field values $_prefs['search_fields'] = array( - 'value' => "" + 'value' => '' ); $_prefs['fb_url'] = array( diff --git a/kronolith/contacts.php b/kronolith/contacts.php index 2a64ed181..c2e901383 100644 --- a/kronolith/contacts.php +++ b/kronolith/contacts.php @@ -33,15 +33,9 @@ $apiargs['addresses'] = array($search); $apiargs['addressbooks'] = array($source); $apiargs['fields'] = array(); -if ($search_fields_pref = $prefs->getValue('search_fields')) { - foreach (explode("\n", $search_fields_pref) as $s) { - $s = trim($s); - $s = explode("\t", $s); - if (!empty($s[0]) && ($s[0] == $source)) { - $apiargs['fields'][array_shift($s)] = $s; - break; - } - } +$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]; } if ($search || $prefs->getValue('display_contact')) { diff --git a/kronolith/lib/Ajax/Imple/ContactAutoCompleter.php b/kronolith/lib/Ajax/Imple/ContactAutoCompleter.php index bce74599d..38666c35a 100644 --- a/kronolith/lib/Ajax/Imple/ContactAutoCompleter.php +++ b/kronolith/lib/Ajax/Imple/ContactAutoCompleter.php @@ -75,24 +75,14 @@ class Kronolith_Ajax_Imple_ContactAutoCompleter extends Horde_Ajax_Imple_AutoCom $search = reset(array_filter(array_map('trim', Horde_Mime_Address::explode($addrString, ',;')))); - $src = explode("\t", $GLOBALS['prefs']->getValue('search_sources')); - if ((count($src) == 1) && empty($src[0])) { + $src = json_decode($GLOBALS['prefs']->getValue('search_sources')); + if (!is_array($src)) { $src = array(); } - $fields = array(); - if (($val = $GLOBALS['prefs']->getValue('search_fields'))) { - $field_arr = explode("\n", $val); - foreach ($field_arr as $field) { - $field = trim($field); - if (!empty($field)) { - $tmp = explode("\t", $field); - if (count($tmp) > 1) { - $source = array_splice($tmp, 0, 1); - $fields[$source[0]] = $tmp; - } - } - } + $fields = json_decode($GLOBALS['prefs']->getValue('search_fields'), true); + if (!is_array($fields)) { + $fields = array(); } try { diff --git a/kronolith/lib/Application.php b/kronolith/lib/Application.php index b48eb621b..f82f4ae7c 100644 --- a/kronolith/lib/Application.php +++ b/kronolith/lib/Application.php @@ -227,7 +227,7 @@ class Kronolith_Application extends Horde_Registry_Application return $this->_prefsRemoteCalManagement($ui); case 'sourceselect': - return Horde_Core_Prefs_Ui_Widgets::addressbooksUpdate($ui); + return $this->_prefsSourceselect($ui); } return false; @@ -359,6 +359,32 @@ class Kronolith_Application extends Horde_Registry_Application } /** + * Update address book related preferences. + * + * @param Horde_Core_Prefs_Ui $ui The UI object. + * + * @return boolean True if preferences were updated. + */ + protected function _prefsSourceselect($ui) + { + global $prefs; + + $updated = false; + + if (isset($ui->vars->sources)) { + $prefs->setValue('search_sources', $ui->vars->sources); + $updated = true; + } + + if (isset($ui->vars->search_fields)) { + $prefs->setValue('search_fields', $ui->vars->search_fields); + $updated = true; + } + + return $updated; + } + + /** * Removes user data. * * @param string $user Name of user to remove data for. diff --git a/kronolith/lib/LoginTasks/SystemTask/UpgradeFromKronolith2.php b/kronolith/lib/LoginTasks/SystemTask/UpgradeFromKronolith2.php new file mode 100644 index 000000000..0849769e1 --- /dev/null +++ b/kronolith/lib/LoginTasks/SystemTask/UpgradeFromKronolith2.php @@ -0,0 +1,59 @@ + + * @package Kronolith + */ +class Kronolith_LoginTasks_SystemTask_UpgradeFromKronolith2 extends Horde_LoginTasks_SystemTask +{ + /** + * The interval at which to run the task. + * + * @var integer + */ + public $interval = Horde_LoginTasks::ONCE; + + /** + * Perform all functions for this task. + */ + public function execute() + { + $this->_upgradeAbookPrefs(); + } + + /** + * Upgrade to the new addressbook preferences. + */ + protected function _upgradeAbookPrefs() + { + global $prefs; + + $src = $prefs->getValue('search_sources'); + if (!is_array(json_decode($src))) { + $prefs->setValue('search_sources', json_encode(explode("\t", $src))); + } + + $val = $prefs->getValue('search_fields'); + if (!is_array(json_decode($val, true))) { + $fields = array(); + foreach (explode("\n", $val) as $field) { + $field = trim($field); + if (!empty($field)) { + $tmp = explode("\t", $field); + if (count($tmp) > 1) { + $source = array_splice($tmp, 0, 1); + $fields[$source[0]] = $tmp; + } + } + } + $prefs->setValue('search_fields', $fields); + } + } + +} diff --git a/whups/config/prefs.php.dist b/whups/config/prefs.php.dist index 32cae0784..dcc34a2aa 100644 --- a/whups/config/prefs.php.dist +++ b/whups/config/prefs.php.dist @@ -143,21 +143,27 @@ $_prefs['comment_sort_dir'] = array( // address book selection widget $_prefs['sourceselect'] = array('type' => 'special'); -// address book(s) to use when expanding addresses -// You can provide default values this way (note the \t and the double quotes): -// 'value' => "source_one\tsource_two" -// refer to turba/config/sources.php for possible source values +// Address book(s) to use when expanding addresses +// Refer to turba/config/sources.php for possible source values +// +// You can provide default values this way: +// 'value' => json_encode('source_one', 'source_two') + $_prefs['search_sources'] = array( - 'value' => "" + 'value' => '' ); -// field(s) to use when expanding addresses -// This depends on the search_sources preference if you want to provide -// default values: -// 'value' => "source_one\tfield_one\tfield_two\nsource_two\tfield_three" +// Field(s) to use when expanding addresses +// Refer to turba/config/sources.php for possible source and field values +// +// If you want to provide a default value, this field depends on the +// search_sources preference. For example: +// 'value' => json_encode(array( +// 'source_one' => array('field_one', 'field_two'), +// 'source_two' => array('field_three') +// )) // will search the fields 'field_one' and 'field_two' in source_one and // 'field_three' in source_two. -// refer to turba/config/sources.php for possible source and field values $_prefs['search_fields'] = array( - 'value' => "" + 'value' => '' ); diff --git a/whups/lib/Ajax/Imple/ContactAutoCompleter.php b/whups/lib/Ajax/Imple/ContactAutoCompleter.php index 5fe3ae230..990e8d29b 100644 --- a/whups/lib/Ajax/Imple/ContactAutoCompleter.php +++ b/whups/lib/Ajax/Imple/ContactAutoCompleter.php @@ -134,27 +134,21 @@ class Whups_Ajax_Imple_ContactAutoCompleter extends Horde_Ajax_Imple_AutoComplet */ static public function getAddressSearchParams() { - $src = explode("\t", $GLOBALS['prefs']->getValue('search_sources')); - if ((count($src) == 1) && empty($src[0])) { + $src = json_decode($GLOBALS['prefs']->getValue('search_sources')); + if (!is_array($src)) { $src = array(); } - $fields = array(); - if (($val = $GLOBALS['prefs']->getValue('search_fields'))) { - $field_arr = explode("\n", $val); - foreach ($field_arr as $field) { - $field = trim($field); - if (!empty($field)) { - $tmp = explode("\t", $field); - if (count($tmp) > 1) { - $source = array_splice($tmp, 0, 1); - $fields[$source[0]] = $tmp; - } - } - } + + $fields = json_decode($GLOBALS['prefs']->getValue('search_fields'), true); + if (!is_array($fields)) { + $fields = array(); } - return array('sources' => $src, 'fields' => $fields); + return array( + 'fields' => $fields, + 'sources' => $src + ); } } diff --git a/whups/lib/Application.php b/whups/lib/Application.php index aa18dbb46..6e7963477 100644 --- a/whups/lib/Application.php +++ b/whups/lib/Application.php @@ -172,7 +172,15 @@ class Whups_Application extends Horde_Registry_Application switch ($item) { case 'sourceselect': - $updated = Horde_Core_Prefs_Ui_Widgets::addressbooksUpdate($ui); + if (isset($ui->vars->sources)) { + $prefs->setValue('search_sources', $ui->vars->sources); + $updated = true; + } + + if (isset($ui->vars->search_fields)) { + $prefs->setValue('search_fields', $ui->vars->search_fields); + $updated = true; + } break; } diff --git a/whups/lib/LoginTasks/SystemTask/UpgradeFromWhups1 b/whups/lib/LoginTasks/SystemTask/UpgradeFromWhups1 new file mode 100644 index 000000000..d0601c07f --- /dev/null +++ b/whups/lib/LoginTasks/SystemTask/UpgradeFromWhups1 @@ -0,0 +1,59 @@ + + * @package Whups + */ +class Whups_LoginTasks_SystemTask_UpgradeFromWhups1 extends Horde_LoginTasks_SystemTask +{ + /** + * The interval at which to run the task. + * + * @var integer + */ + public $interval = Horde_LoginTasks::ONCE; + + /** + * Perform all functions for this task. + */ + public function execute() + { + $this->_upgradeAbookPrefs(); + } + + /** + * Upgrade to the new addressbook preferences. + */ + protected function _upgradeAbookPrefs() + { + global $prefs; + + $src = $prefs->getValue('search_sources'); + if (!is_array(json_decode($src))) { + $prefs->setValue('search_sources', json_encode(explode("\t", $src))); + } + + $val = $prefs->getValue('search_fields'); + if (!is_array(json_decode($val, true))) { + $fields = array(); + foreach (explode("\n", $val) as $field) { + $field = trim($field); + if (!empty($field)) { + $tmp = explode("\t", $field); + if (count($tmp) > 1) { + $source = array_splice($tmp, 0, 1); + $fields[$source[0]] = $tmp; + } + } + } + $prefs->setValue('search_fields', $fields); + } + } + +}