From 9f5af176984da8c31b7e3dcba65c650251ae00ec Mon Sep 17 00:00:00 2001 From: Ben Klang Date: Fri, 29 Jan 2010 21:18:41 -0500 Subject: [PATCH] Shout: Improve automatic selection of context --- shout/lib/Application.php | 24 ++++++++++++++---------- shout/templates/menu.inc | 5 +++++ 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/shout/lib/Application.php b/shout/lib/Application.php index 210996198..eb4b0cdb1 100644 --- a/shout/lib/Application.php +++ b/shout/lib/Application.php @@ -80,18 +80,22 @@ class Shout_Application extends Horde_Registry_Application $contexts = false; } - if (count($contexts) == 1) { - // Default to the user's only context - if (!empty($context) && $context != $contexts[0]) { - $GLOBALS['notification']->push(_("You do not have permission to access that context."), 'horde.error'); - } - $context = $contexts[0]; - } elseif (!empty($context) && !in_array($context, $contexts)) { + $context = Horde_Util::getFormData('context'); + if (!empty($context) && !in_array($context, $contexts)) { + // Requested context not available $GLOBALS['notification']->push(_("You do not have permission to access that context."), 'horde.error'); $context = false; - } elseif (!empty($context)) { - $GLOBALS['notification']->push("Please select a context to continue.", 'horde.info'); - $context = false; + } + + if (empty($context)) { + if (count($contexts)) { + // Default to the user's first context + $context = reset($contexts); + } else { + // No context requested and/or no contexts available anyway + $GLOBALS['notification']->push("Please select a context to continue.", 'horde.info'); + $context = false; + } } $_SESSION['shout']['context'] = $context; diff --git a/shout/templates/menu.inc b/shout/templates/menu.inc index 070329a4a..7c08e9ece 100644 --- a/shout/templates/menu.inc +++ b/shout/templates/menu.inc @@ -9,6 +9,11 @@ $menu_view = $prefs->getValue('menu_view'); contexts->getContexts(); +} catch (Exception $e) { + $contexts = array(); +} if (count($contexts) > 1) { ?>