/**
* 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:
* <pre>
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
/**
* 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.
$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;
- }
-
}
+++ /dev/null
-<?php
-/**
- * Collection of prefs UI utilities for use with common preferences.
- *
- * Copyright 2010 The Horde Project (http://www.horde.org/)
- *
- * See the enclosed file COPYING for license information (LGPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
- *
- * @author Michael Slusarz <slusarz@horde.org>
- * @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
- );
- }
-
-}
<file name="Widgets.php" role="php" />
</dir> <!-- /lib/Horde/Core/Prefs/Ui -->
<file name="Ui.php" role="php" />
- <file name="Utils.php" role="php" />
</dir> <!-- /lib/Horde/Core/Prefs -->
</dir> <!-- /lib/Horde/Core -->
<file name="ErrorHandler.php" role="php" />
<install name="lib/Horde/Core/Notification/Status.php" as="Horde/Core/Notification/Status.php" />
<install name="lib/Horde/Core/Prefs/Ui/Widgets.php" as="Horde/Core/Prefs/Ui/Widgets.php" />
<install name="lib/Horde/Core/Prefs/Ui.php" as="Horde/Core/Prefs/Ui.php" />
- <install name="lib/Horde/Core/Prefs/Utils.php" as="Horde/Core/Prefs/Utils.php" />
<install name="lib/Horde/ErrorHandler.php" as="Horde/ErrorHandler.php" />
<install name="lib/Horde/Exception/HookNotSet.php" as="Horde/Exception/HookNotSet.php" />
<install name="lib/Horde/Help.php" as="Horde/Help.php" />
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));
}
};
$(from).childElements().each(function(c) {
if (c.selected) {
c.remove();
+ c.selected = false;
$(to).insert(c);
}
});
<gettext>To select multiple fields, hold down the Control (PC) or Command (Mac) while clicking.</gettext>
</div>
-<input type="hidden" name="search_fields_string" id="search_fields_string" />
+<input type="hidden" name="search_fields" id="search_fields" />
<table>
<tr>
<td>
- <label for="search_fields" class="hidden"><gettext>Fields to search</gettext></label>
- <select id="search_fields" name="search_fields" multiple="multiple" size="5"></select>
+ <label for="search_fields_select" class="hidden"><gettext>Fields to search</gettext></label>
+ <select id="search_fields_select" name="search_fields_select" multiple="multiple" size="5"></select>
</td>
</tr>
</table>
'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
$vars->formname = 'compose';
}
-$search_params = Horde_Core_Prefs_Utils::getAddressbookSearchParams();
+$search_params = IMP::getAddressbookSearchParams();
$apiargs = array(
'addresses' => array($vars->search),
'addressbooks' => array($vars->source),
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);
*/
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) {
*/
public function listPublicKeys()
{
- $params = Horde_Core_Prefs_Utils::getAddressbookSearchParams();
+ $params = IMP::getAddressbookSearchParams();
if (empty($params['sources'])) {
return array();
}
*/
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']));
}
} 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));
*/
public function listPublicKeys()
{
- $params = Horde_Core_Prefs_Utils::getAddressbookSearchParams();
+ $params = IMP::getAddressbookSearchParams();
if (empty($params['sources'])) {
return array();
}
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
+ );
+ }
+
}
*/
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':
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;
}
}
*/
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)) {
}
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);
}
}
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. */
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);
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. */
/**
// 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(
$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')) {
$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 {
return $this->_prefsRemoteCalManagement($ui);
case 'sourceselect':
- return Horde_Core_Prefs_Ui_Widgets::addressbooksUpdate($ui);
+ return $this->_prefsSourceselect($ui);
}
return false;
}
/**
+ * 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.
--- /dev/null
+<?php
+/**
+ * Login system task for automated upgrade tasks.
+ *
+ * Copyright 2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (GPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
+ *
+ * @author Michael Slusarz <slusarz@horde.org>
+ * @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);
+ }
+ }
+
+}
// 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' => ''
);
*/
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
+ );
}
}
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;
}
--- /dev/null
+<?php
+/**
+ * Login system task for automated upgrade tasks.
+ *
+ * Copyright 2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file LICENSE for license information (BSD). If you
+ * did not receive this file, see http://www.horde.org/licenses/bsdl.php.
+ *
+ * @author Michael Slusarz <slusarz@horde.org>
+ * @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);
+ }
+ }
+
+}