// Address books to be displayed in the address book selection widget
// and in the Browse menu item. The address book name is stored using
-// the source key from sources.php (e.g. "localsql"). Separate
-// entries with "\n" , e. g. 'value' => "localsql\nlocalldap" (the
-// double quotes are REQUIRED). If 'value' is empty (''), all address
-// books that the user has permissions to will be listed.
+// the source key from sources.php (e.g. "localsql").
+// You can provide default values this way:
+// 'value' => json_encode('source_one', 'source_two')
+// If 'value' is empty (''), all address books that the user has permissions
+// to will be listed.
$_prefs['addressbooks'] = array(
'value' => ''
);
case 'addressbookselect':
$data = Horde_Core_Prefs_Ui_Widgets::sourceUpdate($ui);
if (isset($data['sources'])) {
- $ui->setValue('addressbooks', Horde_Serialize::unserialize($data['sources'], Horde_Serialize::JSON));
+ $ui->setValue('addressbooks', $data['sources']);
return true;
}
break;
unset($_SESSION['turba']['source']);
}
- $abooks = explode("\n", $GLOBALS['prefs']->getValue('addressbooks'));
+ $abooks = json_decode($GLOBALS['prefs']->getValue('addressbooks'));
if (($pos = array_search($this->_addressbook->getName(), $abooks)) !== false) {
unset($abooks[$pos]);
- $GLOBALS['prefs']->setValue('addressbooks', implode("\n", $abooks));
+ $GLOBALS['prefs']->setValue('addressbooks', json_encode($abooks));
}
return true;
--- /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 Turba
+ */
+class Turba_LoginTasks_SystemTask_UpgradeFromTurba2 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;
+
+ $abooks = $prefs->getValue('addressbooks');
+ if (!is_array(json_decode($abooks))) {
+ $abooks = @explode("\n", $abooks);
+ if (empty($abooks)) {
+ $abooks = array();
+ }
+
+ return $prefs->setValue('addressbooks', json_encode($abooks));
+ }
+ }
+
+}
{
global $prefs;
- $abooks = explode("\n", $prefs->getValue('addressbooks'));
+ $abooks = $prefs->getValue('addressbooks');
+ if (is_array(json_decode($abooks))) {
+ return;
+ }
+
+ $abooks = explode("\n", $abooks);
if (is_array($abooks) && !empty($abooks[0])) {
$new_prefs = array();
foreach ($abooks as $abook) {
$new_prefs[] = $this->_updateShareName($abook);
}
- return $prefs->setValue('addressbooks', implode("\n", $new_prefs));
+ return $prefs->setValue('addressbooks', json_encode($new_prefs));
}
return true;
*/
function getAddressBookOrder()
{
- $i = 0;
- $lines = explode("\n", $GLOBALS['prefs']->getValue('addressbooks'));
- $temp = $lines;
+ $lines = json_decode($GLOBALS['prefs']->getValue('addressbooks'));
$addressbooks = array();
- foreach ($lines as $line) {
- $line = trim($line);
- if ($line && isset($GLOBALS['cfgSources'][$line])) {
- $addressbooks[$line] = $i++;
+
+ if (!empty($lines)) {
+ $i = 0;
+ foreach ($lines as $line) {
+ $line = trim($line);
+ if ($line && isset($GLOBALS['cfgSources'][$line])) {
+ $addressbooks[$line] = $i++;
+ }
}
}
return $addressbooks;
*/
function getDefaultAddressBook()
{
- $lines = explode("\n", $GLOBALS['prefs']->getValue('addressbooks'));
- foreach ($lines as $line) {
- $line = trim($line);
- if ($line && isset($GLOBALS['cfgSources'][$line])) {
- return $line;
+ $lines = json_decode($GLOBALS['prefs']->getValue('addressbooks'));
+ if (!empty($lines)) {
+ foreach ($lines as $line) {
+ $line = trim($line);
+ if ($line && isset($GLOBALS['cfgSources'][$line])) {
+ return $line;
+ }
}
}
/* Add the new addressbook to the user's list of visible address
* books. */
$prefs = $GLOBALS['prefs']->getValue('addressbooks');
- if ($prefs) {
- $prefs = explode("\n", $prefs);
- if (array_search($share_id, $prefs) === false) {
- $prefs[] = $share_id;
- $GLOBALS['prefs']->setValue('addressbooks', implode("\n", $prefs));
- }
+ if (array_search($share_id, $prefs) === false) {
+ $prefs[] = $share_id;
+ $GLOBALS['prefs']->setValue('addressbooks', json_encode($prefs));
}
return $share;
$GLOBALS['copymoveSources'] = array();
$GLOBALS['cfgSources'] = $cfgSources;
- $this->setPref('addressbooks', '_test_sql');
+ $this->setPref('addressbooks', json_encode(array('_test_sql')));
}
function getPage()
$GLOBALS['copymoveSources'] = array();
$GLOBALS['cfgSources'] = $cfgSources;
- $this->setPref('addressbooks', '_test_sql');
+ $this->setPref('addressbooks', json_encode(array('_test_sql')));
}
function getPage()