From: Michael M Slusarz Date: Tue, 4 Aug 2009 04:23:05 +0000 (-0600) Subject: Move prefs.php code inside of API file. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=6113221d1ceafdf784834c9a7f46e6664725a990;p=horde.git Move prefs.php code inside of API file. --- diff --git a/ansel/lib/Api.php b/ansel/lib/Api.php index e4d600d38..5c33f44ed 100644 --- a/ansel/lib/Api.php +++ b/ansel/lib/Api.php @@ -22,6 +22,14 @@ class Ansel_Api extends Horde_Registry_Api 'type' => '{urn:horde}stringArray' ), + 'prefsHandle' => array( + 'args' => array( + 'item' => 'string', + 'updated' => 'boolean' + ), + 'type' => 'boolean' + ), + 'browse' => array( 'args' => array('path' => 'string'), 'type' => '{urn:horde}hashHash', @@ -221,6 +229,32 @@ class Ansel_Api extends Horde_Registry_Api } /** + * TODO + */ + public function prefsHandle($item, $updated) + { + switch ($item) { + case 'default_category_select': + $default_category = Horde_Util::getFormData('default_category_select'); + if (!is_null($default_category)) { + $GLOBALS['prefs']->setValue('default_category', $default_category); + return true; + } + break; + + case 'default_gallerystyle_select': + $default_style = Horde_Util::getFormData('default_gallerystyle_select'); + if (!is_null($default_style)) { + $GLOBALS['prefs']->setValue('default_gallerystyle', $default_style); + return true; + } + break; + } + + return $updated; + } + + /** * Browse through Ansel's gallery tree. * * @param string $path The level of the tree to browse. diff --git a/ansel/lib/Faces.php b/ansel/lib/Faces.php old mode 100755 new mode 100644 diff --git a/ansel/lib/prefs.php b/ansel/lib/prefs.php deleted file mode 100644 index 75b739ea5..000000000 --- a/ansel/lib/prefs.php +++ /dev/null @@ -1,33 +0,0 @@ -setValue('default_category', $default_category); - return true; - } - - return $updated; -} - -function handle_default_gallerystyle_select($updated) -{ - $default_style = Horde_Util::getFormData('default_gallerystyle_select'); - if (!is_null($default_style)) { - $GLOBALS['prefs']->setValue('default_gallerystyle', $default_style); - return true; - } - - return $updated; -} - - diff --git a/fima/lib/Api.php b/fima/lib/Api.php index 6500598b5..59cadd0f7 100644 --- a/fima/lib/Api.php +++ b/fima/lib/Api.php @@ -2,4 +2,47 @@ class Fima_Api extends Horde_Regsitry_Api { public $version = '1.0.1'; + + public $services = array( + 'prefsHandle' => array( + 'args' => array( + 'item' => 'string', + 'updated' => 'boolean' + ), + 'type' => 'boolean' + ) + ); + + /** + * TODO + */ + public function prefsHandle($item, $updated) + { + switch ($item) { + case 'ledgerselect': + $active_ledger = Horde_Util::getFormData('active_ledger'); + if (!is_null($active_ledger)) { + $ledgers = Fima::listLedgers(); + if (is_array($ledgers) && + array_key_exists($active_ledger, $ledgers)) { + $GLOBALS['prefs']->setValue('active_ledger', $active_ledger); + return true; + } + } + break; + + case 'closedperiodselect': + $period = Horde_Util::getFormData('closedperiod'); + if ((int)$period['year'] > 0 && (int)$period['month'] > 0) { + $period = mktime(0, 0, 0, $period['month'] + 1, 0, $period['year']); + } else { + $period = 0; + } + $GLOBALS['prefs']->setValue('closed_period', $period); + return true; + } + + return $updated; + } + } diff --git a/fima/lib/prefs.php b/fima/lib/prefs.php deleted file mode 100644 index 55e0c030b..000000000 --- a/fima/lib/prefs.php +++ /dev/null @@ -1,43 +0,0 @@ - - * - * See the enclosed file LICENSE for license information (ASL). If you - * did not receive this file, see http://www.horde.org/licenses/asl.php. - * - * @author Thomas Trethan - * @package Fima - */ - -function handle_ledgerselect($updated) -{ - global $prefs; - - $active_ledger = Horde_Util::getFormData('active_ledger'); - if (!is_null($active_ledger)) { - $ledgers = Fima::listLedgers(); - if (is_array($ledgers) && array_key_exists($active_ledger, $ledgers)) { - $prefs->setValue('active_ledger', $active_ledger); - $updated = true; - } - } - return $updated; -} - -function handle_closedperiodselect($updated) -{ - global $prefs; - - $period = Horde_Util::getFormData('closedperiod'); - if ((int)$period['year'] > 0 && (int)$period['month'] > 0) { - $period = mktime(0, 0, 0, $period['month'] + 1, 0, $period['year']); - } else { - $period = 0; - } - $prefs->setValue('closed_period', $period); - $updated = true; - - return $updated; -} diff --git a/gollem/lib/Api.php b/gollem/lib/Api.php index 6c2fd253a..b1a6e78e1 100644 --- a/gollem/lib/Api.php +++ b/gollem/lib/Api.php @@ -30,6 +30,14 @@ class Gollem_Api extends Horde_Registry_Api 'type' => '{urn:horde}hashHash' ), + 'prefsHandle' => array( + 'args' => array( + 'item' => 'string', + 'updated' => 'boolean' + ), + 'type' => 'boolean' + ), + 'browse' => array( 'args' => array('path' => 'string'), 'type' => '{urn:horde}hashHash', @@ -105,6 +113,49 @@ class Gollem_Api extends Horde_Registry_Api ); /** + * TODO + */ + public function perms() + { + static $perms = array(); + if (!empty($perms)) { + return $perms; + } + + require_once dirname(__FILE__) . '/base.load.php'; + require GOLLEM_BASE . '/config/backends.php'; + + $perms['tree']['gollem']['backends'] = false; + $perms['title']['gollem:backends'] = _("Backends"); + + // Run through every backend. + foreach ($backends as $backend => $curBackend) { + $perms['tree']['gollem']['backends'][$backend] = false; + $perms['title']['gollem:backends:' . $backend] = $curBackend['name']; + } + + return $perms; + } + + /** + * TODO + */ + public function prefsHandle($item, $updated) + { + switch ($item) { + case 'columnselect': + $columns = Horde_Util::getFormData('columns'); + if (!empty($columns)) { + $GLOBALS['prefs']->setValue('columns', $columns); + return true; + } + break; + } + + return $updated; + } + + /** * Browses through the VFS tree. * * Each VFS backend is listed as a directory at the top level. No modify @@ -491,28 +542,6 @@ class Gollem_Api extends Horde_Registry_Api } } - public function perms() - { - static $perms = array(); - if (!empty($perms)) { - return $perms; - } - - require_once dirname(__FILE__) . '/base.load.php'; - require GOLLEM_BASE . '/config/backends.php'; - - $perms['tree']['gollem']['backends'] = false; - $perms['title']['gollem:backends'] = _("Backends"); - - // Run through every backend. - foreach ($backends as $backend => $curBackend) { - $perms['tree']['gollem']['backends'][$backend] = false; - $perms['title']['gollem:backends:' . $backend] = $curBackend['name']; - } - - return $perms; - } - /** * Returns a link to the gollem file preview interface * diff --git a/gollem/lib/prefs.php b/gollem/lib/prefs.php deleted file mode 100644 index 229463447..000000000 --- a/gollem/lib/prefs.php +++ /dev/null @@ -1,20 +0,0 @@ - - * @package Gollem - */ - -function handle_columnselect($updated) -{ - $columns = Horde_Util::getFormData('columns'); - if (!empty($columns)) { - $GLOBALS['prefs']->setValue('columns', $columns); - return true; - } - return false; -} diff --git a/imp/lib/Api.php b/imp/lib/Api.php index 841247ee6..cfe6b3b2a 100644 --- a/imp/lib/Api.php +++ b/imp/lib/Api.php @@ -140,8 +140,7 @@ class IMP_Api extends Horde_Registry_Api ), 'changeLanguage' => array( - 'args' => array(), - 'type' => 'boolean' + 'args' => array() ), /* Cache display method. */ @@ -186,13 +185,32 @@ class IMP_Api extends Horde_Registry_Api 'credentials' => '{urn:horde}stringArray' ) ), + 'authRemoveUser' => array( 'args' => array( 'userId' => 'string' ) ), + 'authUserList' => array( 'type' => '{urn:horde}stringArray' + ), + + /* Prefs_UI methods. */ + 'prefsInit' => array( + 'args' => array() + ), + + 'prefsHandle' => array( + 'args' => array( + 'item' => 'string', + 'updated' => 'boolean' + ), + 'type' => 'boolean' + ), + + 'prefsCallback' => array( + 'args' => array() ) ); @@ -329,6 +347,313 @@ class IMP_Api extends Horde_Registry_Api } } + /** + * Code to run when viewing prefs for this application. + * + * @param string $group The prefGroup name. + */ + public function prefsInit($group) + { + /* Make sure we are authenticated here. */ + if (!Horde_Auth::isAuthenticated('imp')) { + // TODO: Handle this more gracefully? + throw new Horde_Exception(_("Not authenticated to imp")); + } + + /* Add necessary javascript files here (so they are added to the + * document HEAD. */ + switch ($group) { + case 'flags': + Horde::addScriptFile('colorpicker.js', 'horde', true); + Horde::addScriptFile('flagmanagement.js', 'imp', true); + + Horde::addInlineScript(array( + 'ImpFlagmanagement.new_prompt = ' . Horde_Serialize::serialize(_("Please enter the label for the new flag:"), Horde_Serialize::JSON, Horde_Nls::getCharset()), + 'ImpFlagmanagement.confirm_delete = ' . Horde_Serialize::serialize(_("Are you sure you want to delete this flag?"), Horde_Serialize::JSON, Horde_Nls::getCharset()) + )); + break; + } + } + + /** + * TODO + */ + public function prefsHandle($item, $updated) + { + switch ($item) { + case 'sentmailselect': + return $this->_prefsSentmailSelect($updated); + + case 'draftsselect': + return $updated | $this->_prefsHandleFolders($updated, 'drafts_folder', 'drafts', 'drafts_new'); + + case 'spamselect': + return $updated | $this->_prefsHandleFolders($updated, 'spam_folder', 'spam', 'spam_new'); + + case 'trashselect': + return $this->_prefsTrashSelect($updated); + + case 'sourceselect': + return $this->_prefsSourceSelect($updated); + + case 'initialpageselect': + $this->_prefsInitialPageSelect(); + return true; + + case 'encryptselect': + $this->_prefsEncryptSelect(); + return true; + + case 'defaultsearchselect': + $this->_prefsDefaultSearchSelect(); + return true; + + case 'soundselect': + return $GLOBALS['prefs']->setValue('nav_audio', Horde_Util::getFormData('nav_audio')); + + case 'flagmanagement': + $this->_prefsFlagManagement(); + return false; + } + } + + /** + * Do anything that we need to do as a result of certain preferences + * changing. + */ + public function prefsCallback() + { + global $prefs; + + /* Always check to make sure we have a valid trash folder if delete to + * trash is active. */ + if (($prefs->isDirty('use_trash') || $prefs->isDirty('trash_folder')) && + $prefs->getValue('use_trash') && + !$prefs->getValue('trash_folder') && + !$prefs->getValue('use_vtrash')) { + $GLOBALS['notification']->push(_("You have activated move to Trash but no Trash folder is defined. You will be unable to delete messages until you set a Trash folder in the preferences."), 'horde.warning'); + } + + if ($prefs->isDirty('use_vtrash') || $prefs->isDirty('use_vinbox')) { + $imp_search = new IMP_Search(); + $imp_search->initialize(true); + } + + if ($prefs->isDirty('subscribe') || $prefs->isDirty('tree_view')) { + $imp_folder = IMP_Folder::singleton(); + $imp_folder->clearFlistCache(); + $imaptree = IMP_Imap_Tree::singleton(); + $imaptree->init(); + } + + if ($prefs->isDirty('mail_domain')) { + $maildomain = preg_replace('/[^-\.a-z0-9]/i', '', $prefs->getValue('mail_domain')); + $prefs->setValue('maildomain', $maildomain); + if (!empty($maildomain)) { + $_SESSION['imp']['maildomain'] = $maildomain; + } + } + + if ($prefs->isDirty('compose_popup')) { + Horde::addInlineScript(array( + 'if (window.parent.frames.horde_menu) window.parent.frames.horde_menu.location.reload();' + )); + } + } + + /** + * TODO + */ + protected function _prefsSentmailSelect($updated) + { + if (!$GLOBALS['conf']['user']['allow_folders'] || + $GLOBALS['prefs']->isLocked('sent_mail_folder')) { + return $updated; + } + + $sent_mail_folder = Horde_Util::getFormData('sent_mail_folder'); + $sent_mail_new = Horde_String::convertCharset(Horde_Util::getFormData('sent_mail_new'), Horde_Nls::getCharset(), 'UTF7-IMAP'); + $sent_mail_default = $GLOBALS['prefs']->getValue('sent_mail_folder'); + + if (empty($sent_mail_folder) && !empty($sent_mail_new)) { + $sent_mail_folder = IMP::appendNamespace($sent_mail_new); + } elseif (($sent_mail_folder == '-1') && !empty($sent_mail_default)) { + $sent_mail_folder = IMP::appendNamespace($sent_mail_default); + } + + if (!empty($sent_mail_folder)) { + $imp_folder = IMP_Folder::singleton(); + if (!$imp_folder->exists($sent_mail_folder)) { + $imp_folder->create($sent_mail_folder, $GLOBALS['prefs']->getValue('subscribe')); + } + } + $GLOBALS['identity']->setValue('sent_mail_folder', IMP::folderPref($sent_mail_folder, false)); + + return true; + } + + /** + * TODO + */ + protected function _prefsHandlefolders($updated, $pref, $folder, $new) + { + if (!$GLOBALS['conf']['user']['allow_folders']) { + return $updated; + } + + $folder = Horde_Util::getFormData($folder); + if (isset($folder) && !$GLOBALS['prefs']->isLocked($pref)) { + $new = Horde_String::convertCharset(Horde_Util::getFormData($new), Horde_Nls::getCharset(), 'UTF7-IMAP'); + if ($folder == IMP::PREF_NO_FOLDER) { + $GLOBALS['prefs']->setValue($pref, ''); + } else { + if (empty($folder) && !empty($new)) { + $folder = IMP::appendNamespace($new); + $imp_folder = IMP_Folder::singleton(); + if (!$imp_folder->create($folder, $GLOBALS['prefs']->getValue('subscribe'))) { + $folder = null; + } + } + if (!empty($folder)) { + $GLOBALS['prefs']->setValue($pref, IMP::folderPref($folder, false)); + return true; + } + } + } + + return $updated; + } + + /** + * TODO + */ + protected function _prefsTrashSelect($updated) + { + global $prefs; + + if (Horde_Util::getFormData('trash') == IMP::PREF_VTRASH) { + if ($prefs->isLocked('use_vtrash')) { + return false; + } + + $prefs->setValue('use_vtrash', 1); + $prefs->setValue('trash_folder', ''); + } else { + if ($prefs->isLocked('trash_folder')) { + return false; + } + + $updated = $updated | $this->_prefsHandleFolders($updated, 'trash_folder', 'trash', 'trash_new'); + if ($updated) { + $prefs->setValue('use_vtrash', 0); + $prefs->setDirty('trash_folder', true); + } + } + + return $updated; + } + + /** + * TODO + */ + protected function _prefsSourceSelect($updated) + { + $search_sources = Horde_Util::getFormData('search_sources'); + if (!is_null($search_sources)) { + $GLOBALS['prefs']->setValue('search_sources', $search_sources); + unset($_SESSION['imp']['cache']['ac_ajax']); + $updated = true; + } + + $search_fields_string = Horde_Util::getFormData('search_fields_string'); + if (!is_null($search_fields_string)) { + $GLOBALS['prefs']->setValue('search_fields', $search_fields_string); + $updated = true; + } + + $add_source = Horde_Util::getFormData('add_source'); + if (!is_null($add_source)) { + $GLOBALS['prefs']->setValue('add_source', $add_source); + $updated = true; + } + + return $updated; + } + + /** + * TODO + */ + protected function _prefsInitialPageSelect() + { + $initial_page = Horde_Util::getFormData('initial_page'); + $GLOBALS['prefs']->setValue('initial_page', $initial_page); + } + + /** + * TODO + */ + protected function _prefsEncryptSelect() + { + $default_encrypt = Horde_Util::getFormData('default_encrypt'); + $GLOBALS['prefs']->setValue('default_encrypt', $default_encrypt); + } + + /** + * TODO + */ + protected function _prefsDefaultSearchSelect() + { + $default_search = Horde_Util::getFormData('default_search'); + $GLOBALS['prefs']->setValue('default_search', $default_search); + } + + /** + * TODO + */ + protected function _prefsFlagManagement() + { + $imp_flags = IMP_Imap_Flags::singleton(); + $action = Horde_Util::getFormData('flag_action'); + $data = Horde_Util::getFormData('flag_data'); + + if ($action == 'add') { + $imp_flags->addFlag($data); + return; + } + + $def_color = $GLOBALS['prefs']->getValue('msgflags_color'); + + // Don't set updated on these actions. User may want to do more actions. + foreach ($imp_flags->getList() as $key => $val) { + $md5 = hash('md5', $key); + + switch ($action) { + case 'delete': + if ($data == ('bg_' . $md5)) { + $imp_flags->deleteFlag($key); + } + break; + + default: + /* Change labels for user-defined flags. */ + if ($val['t'] == 'imapp') { + $label = Horde_Util::getFormData('label_' . $md5); + if (strlen($label) && ($label != $val['l'])) { + $imp_flags->updateFlag($key, array('l' => $label)); + } + } + + /* Change background for all flags. */ + $bg = strtolower(Horde_Util::getFormData('bg_' . $md5)); + if ((isset($val['b']) && ($bg != $val['b'])) || + (!isset($val['b']) && ($bg != $def_color))) { + $imp_flags->updateFlag($key, array('b' => $bg)); + } + break; + } + } + } + /* Horde_Auth_Application defined functions. */ /** diff --git a/imp/lib/prefs.php b/imp/lib/prefs.php deleted file mode 100644 index 646bb8be4..000000000 --- a/imp/lib/prefs.php +++ /dev/null @@ -1,261 +0,0 @@ -isLocked('sent_mail_folder')) { - $sent_mail_folder = Horde_Util::getFormData('sent_mail_folder'); - $sent_mail_new = Horde_String::convertCharset(Horde_Util::getFormData('sent_mail_new'), Horde_Nls::getCharset(), 'UTF7-IMAP'); - $sent_mail_default = $prefs->getValue('sent_mail_folder'); - if (empty($sent_mail_folder) && !empty($sent_mail_new)) { - $sent_mail_folder = IMP::appendNamespace($sent_mail_new); - } elseif (($sent_mail_folder == '-1') && !empty($sent_mail_default)) { - $sent_mail_folder = IMP::appendNamespace($sent_mail_default); - } - if (!empty($sent_mail_folder)) { - $imp_folder = IMP_Folder::singleton(); - if (!$imp_folder->exists($sent_mail_folder)) { - $imp_folder->create($sent_mail_folder, $prefs->getValue('subscribe')); - } - } - $identity->setValue('sent_mail_folder', IMP::folderPref($sent_mail_folder, false)); - $updated = true; - } - - return $updated; -} - -function handlefolders($updated, $pref, $folder, $new) -{ - global $conf, $prefs; - - if ($conf['user']['allow_folders']) { - $folder = Horde_Util::getFormData($folder); - if (isset($folder) && !$prefs->isLocked($pref)) { - $new = Horde_String::convertCharset(Horde_Util::getFormData($new), Horde_Nls::getCharset(), 'UTF7-IMAP'); - if ($folder == IMP::PREF_NO_FOLDER) { - $prefs->setValue($pref, ''); - } else { - if (empty($folder) && !empty($new)) { - $folder = IMP::appendNamespace($new); - $imp_folder = IMP_Folder::singleton(); - if (!$imp_folder->create($folder, $prefs->getValue('subscribe'))) { - $folder = null; - } - } - if (!empty($folder)) { - $prefs->setValue($pref, IMP::folderPref($folder, false)); - $updated = true; - } - } - } - } - - return $updated; -} - -function handle_draftsselect($updated) -{ - return $updated | handlefolders($updated, 'drafts_folder', 'drafts', 'drafts_new'); -} - -function handle_trashselect($updated) -{ - global $prefs; - $ret = true; - - if (Horde_Util::getFormData('trash') == IMP::PREF_VTRASH) { - if ($prefs->isLocked('use_vtrash')) { - $ret = false; - } else { - $prefs->setValue('use_vtrash', 1); - $prefs->setValue('trash_folder', ''); - } - } else { - if ($prefs->isLocked('trash_folder')) { - $ret = false; - } else { - $ret = $updated | handlefolders($updated, 'trash_folder', 'trash', 'trash_new'); - if ($ret) { - $prefs->setValue('use_vtrash', 0); - $prefs->setDirty('trash_folder', true); - } - } - } - - return $ret; -} - -function handle_sourceselect($updated) -{ - global $prefs; - - $search_sources = Horde_Util::getFormData('search_sources'); - if (!is_null($search_sources)) { - $prefs->setValue('search_sources', $search_sources); - unset($_SESSION['imp']['cache']['ac_ajax']); - $updated = true; - } - - $search_fields_string = Horde_Util::getFormData('search_fields_string'); - if (!is_null($search_fields_string)) { - $prefs->setValue('search_fields', $search_fields_string); - $updated = true; - } - - $add_source = Horde_Util::getFormData('add_source'); - if (!is_null($add_source)) { - $prefs->setValue('add_source', $add_source); - $updated = true; - } - - return $updated; -} - -function handle_initialpageselect($updated) -{ - $initial_page = Horde_Util::getFormData('initial_page'); - $GLOBALS['prefs']->setValue('initial_page', $initial_page); - return true; -} - -function handle_encryptselect($updated) -{ - $default_encrypt = Horde_Util::getFormData('default_encrypt'); - $GLOBALS['prefs']->setValue('default_encrypt', $default_encrypt); - return true; -} - -function handle_spamselect($updated) -{ - return $updated | handlefolders($updated, 'spam_folder', 'spam', 'spam_new'); -} - -function handle_defaultsearchselect($updated) -{ - $default_search = Horde_Util::getFormData('default_search'); - $GLOBALS['prefs']->setValue('default_search', $default_search); - return true; -} - -function handle_soundselect($updated) -{ - return $GLOBALS['prefs']->setValue('nav_audio', Horde_Util::getFormData('nav_audio')); -} - -function handle_flagmanagement($updated) -{ - $imp_flags = IMP_Imap_Flags::singleton(); - $action = Horde_Util::getFormData('flag_action'); - $data = Horde_Util::getFormData('flag_data'); - - if ($action == 'add') { - $imp_flags->addFlag($data); - return false; - } - - $def_color = $GLOBALS['prefs']->getValue('msgflags_color'); - - // Don't set updated on these actions. User may want to do more actions. - foreach ($imp_flags->getList() as $key => $val) { - $md5 = hash('md5', $key); - - switch ($action) { - case 'delete': - if ($data == ('bg_' . $md5)) { - $imp_flags->deleteFlag($key); - return false; - } - break; - - default: - /* Change labels for user-defined flags. */ - if ($val['t'] == 'imapp') { - $label = Horde_Util::getFormData('label_' . $md5); - if (strlen($label) && ($label != $val['l'])) { - $imp_flags->updateFlag($key, array('l' => $label)); - } - } - - /* Change background for all flags. */ - $bg = strtolower(Horde_Util::getFormData('bg_' . $md5)); - if ((isset($val['b']) && ($bg != $val['b'])) || - (!isset($val['b']) && ($bg != $def_color))) { - $imp_flags->updateFlag($key, array('b' => $bg)); - } - break; - } - } - - return false; -} - -function prefs_callback() -{ - global $prefs; - - /* Always check to make sure we have a valid trash folder if delete to - * trash is active. */ - if (($prefs->isDirty('use_trash') || $prefs->isDirty('trash_folder')) && - $prefs->getValue('use_trash') && - !$prefs->getValue('trash_folder') && - !$prefs->getValue('use_vtrash')) { - $GLOBALS['notification']->push(_("You have activated move to Trash but no Trash folder is defined. You will be unable to delete messages until you set a Trash folder in the preferences."), 'horde.warning'); - } - - if ($prefs->isDirty('use_vtrash') || $prefs->isDirty('use_vinbox')) { - $imp_search = new IMP_Search(); - $imp_search->initialize(true); - } - - if ($prefs->isDirty('subscribe') || $prefs->isDirty('tree_view')) { - $imp_folder = IMP_Folder::singleton(); - $imp_folder->clearFlistCache(); - $imaptree = IMP_Imap_Tree::singleton(); - $imaptree->init(); - } - - if ($prefs->isDirty('mail_domain')) { - $maildomain = preg_replace('/[^-\.a-z0-9]/i', '', $prefs->getValue('mail_domain')); - $prefs->setValue('maildomain', $maildomain); - if (!empty($maildomain)) { - $_SESSION['imp']['maildomain'] = $maildomain; - } - } - - if ($prefs->isDirty('compose_popup')) { - Horde::addInlineScript(array( - 'if (window.parent.frames.horde_menu) window.parent.frames.horde_menu.location.reload();' - )); - } -} - -/* Make sure we are authenticated here. */ -if (!Horde_Auth::isAuthenticated('imp')) { - // TODO: Handle this more gracefully - throw new Horde_Exception(_("Not authenticated to imp")); -} - -/* Add necessary javascript files here (so they are added to the document - * HEAD. */ -switch ($group) { -case 'flags': - Horde::addScriptFile('colorpicker.js', 'horde', true); - Horde::addScriptFile('flagmanagement.js', 'imp', true); - - Horde::addInlineScript(array( - 'ImpFlagmanagement.new_prompt = ' . Horde_Serialize::serialize(_("Please enter the label for the new flag:"), Horde_Serialize::JSON, Horde_Nls::getCharset()), - 'ImpFlagmanagement.confirm_delete = ' . Horde_Serialize::serialize(_("Are you sure you want to delete this flag?"), Horde_Serialize::JSON, Horde_Nls::getCharset()) - )); - break; -} diff --git a/kronolith/lib/Api.php b/kronolith/lib/Api.php index f7a594333..d02dab50e 100644 --- a/kronolith/lib/Api.php +++ b/kronolith/lib/Api.php @@ -12,13 +12,30 @@ class Kronolith_Api extends Horde_Registry_Api public $version = 'H3 (3.0-git)'; public $services = array( - 'show' => array( - 'link' => '%application%/event.php?calendar=|calendar|&eventID=|event|&uid=|uid|' + 'perms' => array( + 'args' => array(), + 'type' => '{urn:horde}hashHash' ), - 'perms' => array( + 'prefsInit' => array( 'args' => array(), - 'type' => '{urn:horde}stringArray' + 'type' => '{urn:horde}hashHash' + ), + + 'prefsHandle' => array( + 'args' => array( + 'item' => 'string', + 'updated' => 'boolean' + ), + 'type' => 'boolean' + ), + + 'prefsCallback' => array( + 'args' => array() + ), + + 'show' => array( + 'link' => '%application%/event.php?calendar=|calendar|&eventID=|event|&uid=|uid|' ), 'removeUserData' => array( @@ -71,7 +88,7 @@ class Kronolith_Api extends Horde_Registry_Api 'type' => '{urn:horde}hashHash' ), - 'list' => array( + 'listUids' => array( 'args' => array(), 'type' => '{urn:horde}stringArray' ), @@ -170,6 +187,219 @@ class Kronolith_Api extends Horde_Registry_Api } /** + * Code to run when viewing prefs for this application. + * + * @param string $group The prefGroup name. + * + * @return array A list of variables to export to the prefs display page. + */ + public function prefsInit($group) + { + $out = array(); + + if (!$GLOBALS['prefs']->isLocked('day_hour_start') || + !$GLOBALS['prefs']->isLocked('day_hour_end')) { + $out['day_hour_start_options'] = array(); + for ($i = 0; $i <= 48; ++$i) { + $out['day_hour_start_options'][$i] = date(($GLOBALS['prefs']->getValue('twentyFour')) ? 'G:i' : 'g:ia', mktime(0, $i * 30, 0)); + } + $out['day_hour_end_options'] = $out['day_hour_start_options']; + } + + if (!empty($GLOBALS['conf']['holidays']['enable'])) { + if (class_exists('Date_Holidays')) { + foreach (Date_Holidays::getInstalledDrivers() as $driver) { + if ($driver['id'] == 'Composite') { + continue; + } + $_prefs['holiday_drivers']['enum'][$driver['id']] = $driver['title']; + } + asort($_prefs['holiday_drivers']['enum']); + } else { + $GLOBALS['notification']->push(_("Holidays support is not available on this server."), 'horde.error'); + } + } + + return $out; + } + + /** + * TODO + */ + public function prefsHandle($item, $updated) + { + switch ($item) { + case 'remote_cal_management': + return $this->_prefsRemoteCalManagement($updated); + + case 'shareselect': + return $this->_prefsShareSelect($updated); + + case 'holiday_drivers': + $this->_prefsHolidayDrivers($updated); + return true; + + case 'sourceselect': + return $this->_prefsSourceSelect($updated); + + case 'fb_cals_select': + $this->_prefsFbCalsSelect($updated); + return true; + + case 'default_alarm_management': + $GLOBALS['prefs']->setValue('default_alarm', (int)Horde_Util::getFormData('alarm_value') * (int)Horde_Util::getFormData('alarm_unit')); + return true; + } + } + + /** + * TODO + */ + public function prefsCallback() + { + if ($GLOBALS['prefs']->isDirty('event_alarms')) { + $alarms = $GLOBALS['registry']->callByPackage('kronolith', 'listAlarms', array($_SERVER['REQUEST_TIME'])); + if (!is_a($alarms, 'PEAR_Error') && !empty($alarms)) { + $horde_alarm = Horde_Alarm::factory(); + foreach ($alarms as $alarm) { + $alarm['start'] = new Horde_Date($alarm['start']); + $alarm['end'] = new Horde_Date($alarm['end']); + $horde_alarm->set($alarm); + } + } + } + } + + /** + * TODO + */ + protected function _prefsRemoteCalManagement($updated) + { + $calName = Horde_Util::getFormData('remote_name'); + $calUrl = trim(Horde_Util::getFormData('remote_url')); + $calUser = trim(Horde_Util::getFormData('remote_user')); + $calPasswd = trim(Horde_Util::getFormData('remote_password')); + + $key = Horde_Auth::getCredential('password'); + if ($key) { + $calUser = base64_encode(Secret::write($key, $calUser)); + $calPasswd = base64_encode(Secret::write($key, $calPasswd)); + } + + $calActionID = Horde_Util::getFormData('remote_action', 'add'); + + if ($calActionID == 'add') { + if (!empty($calName) && !empty($calUrl)) { + $cals = unserialize($GLOBALS['prefs']->getValue('remote_cals')); + $cals[] = array('name' => $calName, + 'url' => $calUrl, + 'user' => $calUser, + 'password' => $calPasswd); + $GLOBALS['prefs']->setValue('remote_cals', serialize($cals)); + return $updated; + } + } elseif ($calActionID == 'delete') { + $cals = unserialize($GLOBALS['prefs']->getValue('remote_cals')); + foreach ($cals as $key => $cal) { + if ($cal['url'] == $calUrl) { + unset($cals[$key]); + break; + } + } + $GLOBALS['prefs']->setValue('remote_cals', serialize($cals)); + return $updated; + } elseif ($calActionID == 'edit') { + $cals = unserialize($GLOBALS['prefs']->getValue('remote_cals')); + foreach ($cals as $key => $cal) { + if ($cal['url'] == $calUrl) { + $cals[$key]['name'] = $calName; + $cals[$key]['url'] = $calUrl; + $cals[$key]['user'] = $calUser; + $cals[$key]['password'] = $calPasswd; + break; + } + } + $GLOBALS['prefs']->setValue('remote_cals', serialize($cals)); + return $updated; + } + + return false; + } + + /** + * TODO + */ + protected function _prefsShareSelect($updated) + { + $default_share = Horde_Util::getFormData('default_share'); + if (!is_null($default_share)) { + $sharelist = Kronolith::listCalendars(); + if ((is_array($sharelist)) > 0 && + isset($sharelist[$default_share])) { + $GLOBALS['prefs']->setValue('default_share', $default_share); + return true; + } + } + + return $updated; + } + + /** + * TODO + */ + protected function _prefsHolidayDrivers() + { + $holiday_driversSelected = Horde_Util::getFormData('holiday_drivers'); + $holiday_driversFiltered = array(); + + if (is_array($holiday_driversSelected)) { + foreach ($holiday_driversSelected as $holiday_driver) { + $holiday_driversFiltered[] = $holiday_driver; + } + } + + $GLOBALS['prefs']->setValue('holiday_drivers', serialize($holiday_driversFiltered)); + } + + /** + * TODO + */ + protected function _prefsSourceSelect($updated) + { + $search_sources = Horde_Util::getFormData('search_sources'); + if (!is_null($search_sources)) { + $GLOBALS['prefs']->setValue('search_sources', $search_sources); + $updated = true; + } + + $search_fields_string = Horde_Util::getFormData('search_fields_string'); + if (!is_null($search_fields_string)) { + $GLOBALS['prefs']->setValue('search_fields', $search_fields_string); + $updated = true; + } + + return $updated; + } + + /** + * TODO + */ + protected function _prefsHandleFbCalsSelect() + { + $fb_calsSelected = Horde_Util::getFormData('fb_cals'); + $fb_cals = Kronolith::listCalendars(); + $fb_calsFiltered = array(); + + if (isset($fb_calsSelected) && is_array($fb_calsSelected)) { + foreach ($fb_calsSelected as $fb_cal) { + $fb_calsFiltered[] = $fb_cal; + } + } + + $GLOBALS['prefs']->setValue('fb_cals', serialize($fb_calsFiltered)); + } + + /** * Removes user data. * * @param string $user Name of user to remove data for. diff --git a/kronolith/lib/prefs.php b/kronolith/lib/prefs.php deleted file mode 100644 index 859f7050c..000000000 --- a/kronolith/lib/prefs.php +++ /dev/null @@ -1,191 +0,0 @@ -getValue('remote_cals')); - $cals[] = array('name' => $calName, - 'url' => $calUrl, - 'user' => $calUser, - 'password' => $calPasswd); - $prefs->setValue('remote_cals', serialize($cals)); - return $updated; - } - } elseif ($calActionID == 'delete') { - $cals = unserialize($prefs->getValue('remote_cals')); - foreach ($cals as $key => $cal) { - if ($cal['url'] == $calUrl) { - unset($cals[$key]); - break; - } - } - $prefs->setValue('remote_cals', serialize($cals)); - return $updated; - } elseif ($calActionID == 'edit') { - $cals = unserialize($prefs->getValue('remote_cals')); - foreach ($cals as $key => $cal) { - if ($cal['url'] == $calUrl) { - $cals[$key]['name'] = $calName; - $cals[$key]['url'] = $calUrl; - $cals[$key]['user'] = $calUser; - $cals[$key]['password'] = $calPasswd; - break; - } - } - $prefs->setValue('remote_cals', serialize($cals)); - return $updated; - } - - return false; -} - -function handle_shareselect($updated) -{ - $default_share = Horde_Util::getFormData('default_share'); - if (!is_null($default_share)) { - $sharelist = Kronolith::listCalendars(); - if ((is_array($sharelist)) > 0 && isset($sharelist[$default_share])) { - $GLOBALS['prefs']->setValue('default_share', $default_share); - return true; - } - } - - return $updated; -} - -function handle_holiday_drivers($updated) -{ - $holiday_driversSelected = Horde_Util::getFormData('holiday_drivers'); - $holiday_driversFiltered = array(); - - if (is_array($holiday_driversSelected)) { - foreach ($holiday_driversSelected as $holiday_driver) { - $holiday_driversFiltered[] = $holiday_driver; - } - } - - $GLOBALS['prefs']->setValue('holiday_drivers', serialize($holiday_driversFiltered)); - return true; -} - -function handle_sourceselect($updated) -{ - global $prefs; - - $search_sources = Horde_Util::getFormData('search_sources'); - if ($search_sources !== null) { - $prefs->setValue('search_sources', $search_sources); - $updated = true; - } - - $search_fields_string = Horde_Util::getFormData('search_fields_string'); - if ($search_fields_string !== null) { - $prefs->setValue('search_fields', $search_fields_string); - $updated = true; - } - - return $updated; -} - -function handle_fb_cals_select($updated) -{ - $fb_calsSelected = Horde_Util::getFormData('fb_cals'); - $fb_cals = Kronolith::listCalendars(); - $fb_calsFiltered = array(); - - if (isset($fb_calsSelected) && is_array($fb_calsSelected)) { - foreach ($fb_calsSelected as $fb_cal) { - $fb_calsFiltered[] = $fb_cal; - } - } - - $GLOBALS['prefs']->setValue('fb_cals', serialize($fb_calsFiltered)); - return true; -} - -function handle_default_alarm_management($updated) -{ - $GLOBALS['prefs']->setValue('default_alarm', - (int)Horde_Util::getFormData('alarm_value') * (int)Horde_Util::getFormData('alarm_unit')); - return true; -} - -if (!$prefs->isLocked('day_hour_start') || !$prefs->isLocked('day_hour_end')) { - $day_hour_start_options = array(); - for ($i = 0; $i <= 48; ++$i) { - $day_hour_start_options[$i] = date(($prefs->getValue('twentyFour')) ? 'G:i' : 'g:ia', mktime(0, $i * 30, 0)); - } - $day_hour_end_options = $day_hour_start_options; -} - -/** - * Do anything that we need to do as a result of certain preferences - * changing. - */ -function prefs_callback() -{ - global $prefs; - - if ($GLOBALS['prefs']->isDirty('event_alarms')) { - $alarms = $GLOBALS['registry']->callByPackage('kronolith', 'listAlarms', array($_SERVER['REQUEST_TIME'])); - if (!is_a($alarms, 'PEAR_Error') && !empty($alarms)) { - $horde_alarm = Horde_Alarm::factory(); - foreach ($alarms as $alarm) { - $alarm['start'] = new Horde_Date($alarm['start']); - $alarm['end'] = new Horde_Date($alarm['end']); - $horde_alarm->set($alarm); - } - } - } - - /* If a maintenance option has been activated, we need to make sure the - * global Horde 'do_maintenance' pref is also active. */ - if (!$prefs->isLocked('do_maintenance') && - !$prefs->getValue('do_maintenance')) { - foreach (array('purge_events') as $val) { - if ($prefs->getValue($val)) { - $prefs->setValue('do_maintenance', true); - break; - } - } - } - -} - -if (!empty($GLOBALS['conf']['holidays']['enable'])) { - if (class_exists('Date_Holidays')) { - foreach (Date_Holidays::getInstalledDrivers() as $driver) { - if ($driver['id'] == 'Composite') { - continue; - } - $_prefs['holiday_drivers']['enum'][$driver['id']] = $driver['title']; - } - asort($_prefs['holiday_drivers']['enum']); - } else { - $notification->push(_("Holidays support is not available on this server."), 'horde.error'); - } -} diff --git a/nag/lib/Api.php b/nag/lib/Api.php index 68f9b9cb9..9b5057a3d 100644 --- a/nag/lib/Api.php +++ b/nag/lib/Api.php @@ -27,6 +27,14 @@ class Nag_Api extends Horde_Registry_Api 'type' => '{urn:horde}hashHash' ), + 'prefsHandle' => array( + 'args' => array( + 'item' => 'string', + 'updated' => 'boolean' + ), + 'type' => 'boolean' + ), + 'removeUserData' => array( 'args' => array('user' => 'string'), 'type' => 'boolean' @@ -202,6 +210,36 @@ class Nag_Api extends Horde_Registry_Api } /** + * TODO + */ + public function prefsHandle($item, $updated) + { + switch ($item) { + case 'tasklistselect': + $default_tasklist = Horde_Util::getFormData('default_tasklist'); + if (!is_null($default_tasklist)) { + $tasklists = Nag::listTasklists(); + if (is_array($tasklists) && + isset($tasklists[$default_tasklist])) { + $GLOBALS['prefs']->setValue('default_tasklist', $default_tasklist); + return true; + } + } + break; + + case 'showsummaryselect': + $GLOBALS['prefs']->setValue('summary_categories', Horde_Util::getFormData('summary_categories')); + return true; + + case 'defaultduetimeselect': + $GLOBALS['prefs']->setValue('default_due_time', Horde_Util::getFormData('default_due_time')); + return true; + } + + return $updated; + } + + /** * Removes user data. * * @param string $user Name of user to remove data for. diff --git a/nag/lib/prefs.php b/nag/lib/prefs.php deleted file mode 100644 index f0a39d97b..000000000 --- a/nag/lib/prefs.php +++ /dev/null @@ -1,35 +0,0 @@ -setValue('default_tasklist', $default_tasklist); - return true; - } - } - - return false; -} - -function handle_showsummaryselect($updated) -{ - $GLOBAL['prefs']->setValue('summary_categories', Horde_Util::getFormData('summary_categories')); - return true; -} - -function handle_defaultduetimeselect($updated) -{ - $GLOBALS['prefs']->setValue('default_due_time', Horde_Util::getFormData('default_due_time')); - return true; -} diff --git a/turba/lib/Api.php b/turba/lib/Api.php index 7fba43794..06705e8a5 100644 --- a/turba/lib/Api.php +++ b/turba/lib/Api.php @@ -28,6 +28,19 @@ class Turba_Api extends Horde_Registry_Api 'type' => '{urn:horde}hashHash' ), + 'prefsInit' => array( + 'args' => array(), + 'type' => '{urn:horde}hashHash' + ), + + 'prefsHandle' => array( + 'args' => array( + 'item' => 'string', + 'updated' => 'boolean' + ), + 'type' => 'boolean' + ), + 'removeUserData' => array( 'args' => array('user' => 'string'), 'type' => 'boolean' @@ -268,6 +281,95 @@ class Turba_Api extends Horde_Registry_Api ); /** + * Returns a list of available permissions. + * + * @return array An array describing all available permissions. + */ + public function perms() + { + static $perms = array(); + if (!empty($perms)) { + return $perms; + } + + require_once dirname(__FILE__) . '/base.php'; + require TURBA_BASE . '/config/sources.php'; + + $perms['tree']['turba']['sources'] = false; + $perms['title']['turba:sources'] = _("Sources"); + + // Run through every contact source. + foreach ($cfgSources as $source => $curSource) { + $perms['tree']['turba']['sources'][$source] = false; + $perms['title']['turba:sources:' . $source] = $curSource['title']; + $perms['tree']['turba']['sources'][$source]['max_contacts'] = false; + $perms['title']['turba:sources:' . $source . ':max_contacts'] = _("Maximum Number of Contacts"); + $perms['type']['turba:sources:' . $source . ':max_contacts'] = 'int'; + } + + return $perms; + } + + /** + * Code to run when viewing prefs for this application. + * + * @param string $group The prefGroup name. + * + * @return array A list of variables to export to the prefs display page. + */ + public function prefsInit($group) + { + $out = array(); + + /* Assign variables for select lists. */ + if (!$GLOBALS['prefs']->isLocked('default_dir')) { + require TURBA_BASE . '/config/sources.php'; + $out['default_dir_options'] = array(); + foreach ($cfgSources as $key => $info) { + $out['default_dir_options'][$key] = $info['title']; + } + } + + foreach (Turba::getAddressBooks() as $key => $curSource) { + if (empty($curSource['map']['__uid'])) { + continue; + } + if (!empty($curSource['browse'])) { + $GLOBALS['_prefs']['sync_books']['enum'][$key] = $curSource['title']; + } + $sync_books = @unserialize($GLOBALS['prefs']->getValue('sync_books')); + if (empty($sync_books)) { + $GLOBALS['prefs']->setValue('sync_books', serialize(array(Turba::getDefaultAddressbook()))); + } + } + + return $out; + } + + /** + * TODO + */ + public function prefsHandle($item, $updated) + { + switch ($item) { + case 'columnselect': + $columns = Horde_Util::getFormData('columns'); + if (!empty($columns)) { + $GLOBALS['prefs']->setValue('columns', $columns); + return true; + } + break; + + case 'addressbookselect': + $addressbooks = Horde_Util::getFormData('addressbooks'); + $GLOBALS['prefs']->setValue('addressbooks', str_replace("\r", '', $addressbooks)); + return true; + } + + return $updated; + } + + /** * Removes user data. * * @param string $user Name of user to remove data for. @@ -381,36 +483,6 @@ class Turba_Api extends Horde_Registry_Api } /** - * Returns a list of available permissions. - * - * @return array An array describing all available permissions. - */ - public function perms() - { - static $perms = array(); - if (!empty($perms)) { - return $perms; - } - - require_once dirname(__FILE__) . '/base.php'; - require TURBA_BASE . '/config/sources.php'; - - $perms['tree']['turba']['sources'] = false; - $perms['title']['turba:sources'] = _("Sources"); - - // Run through every contact source. - foreach ($cfgSources as $source => $curSource) { - $perms['tree']['turba']['sources'][$source] = false; - $perms['title']['turba:sources:' . $source] = $curSource['title']; - $perms['tree']['turba']['sources'][$source]['max_contacts'] = false; - $perms['title']['turba:sources:' . $source . ':max_contacts'] = _("Maximum Number of Contacts"); - $perms['type']['turba:sources:' . $source . ':max_contacts'] = 'int'; - } - - return $perms; - } - - /** * Returns a list of available sources. * * @param boolean $writeable Set to true to limit to writeable sources. diff --git a/turba/lib/prefs.php b/turba/lib/prefs.php deleted file mode 100644 index 349b3b7e8..000000000 --- a/turba/lib/prefs.php +++ /dev/null @@ -1,47 +0,0 @@ -setValue('columns', $columns); - return true; - } - - return false; -} - -function handle_addressbookselect($updated) -{ - $addressbooks = Horde_Util::getFormData('addressbooks'); - $GLOBALS['prefs']->setValue('addressbooks', str_replace("\r", '', $addressbooks)); - return true; -} - -/* Assign variables for select lists. */ -if (!$prefs->isLocked('default_dir')) { - $default_dir_options = array(); - foreach ($cfgSources as $key => $info) { - $default_dir_options[$key] = $info['title']; - } -} - -foreach (Turba::getAddressBooks() as $key => $curSource) { - if (empty($curSource['map']['__uid'])) { - continue; - } - if (!empty($curSource['browse'])) { - $_prefs['sync_books']['enum'][$key] = $curSource['title']; - } - $sync_books = @unserialize($prefs->getValue('sync_books')); - if (empty($sync_books)) { - $prefs->setValue('sync_books', - serialize(array(Turba::getDefaultAddressbook()))); - } -}