From: Ben Klang Date: Mon, 8 Mar 2010 22:41:47 +0000 (-0500) Subject: Shout: Fix account name display and selection X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=030af29d99616104e8eb60b9a8ea4cff372e9a85;p=horde.git Shout: Fix account name display and selection --- diff --git a/shout/devices.php b/shout/devices.php index 7d29db491..fc6e0b54c 100644 --- a/shout/devices.php +++ b/shout/devices.php @@ -14,12 +14,10 @@ $shout = Horde_Registry::appInit('shout'); require_once SHOUT_BASE . '/lib/Forms/DeviceForm.php'; -$account = $_SESSION['shout']['account']; +$curaccount = $_SESSION['shout']['curaccount']; $action = Horde_Util::getFormData('action'); $vars = Horde_Variables::getDefaultVariables(); -//$tabs = Shout::getTabs($account, $vars); - $RENDERER = new Horde_Form_Renderer(); $title = _("Devices: "); @@ -28,7 +26,7 @@ switch ($action) { case 'add': case 'edit': $vars = Horde_Variables::getDefaultVariables(); - $vars->set('account', $account); + $vars->set('account', $curaccount['code']); $Form = new DeviceDetailsForm($vars); // Show the list if the save was successful, otherwise back to edit. @@ -53,7 +51,7 @@ case 'edit': // Create a new add/edit form $devid = Horde_Util::getFormData('devid'); - $devices = $shout->devices->getDevices($account); + $devices = $shout->devices->getDevices($curaccount['code']); $vars = new Horde_Variables($devices[$devid]); $vars->set('action', $action); @@ -68,7 +66,7 @@ case 'delete': $devid = Horde_Util::getFormData('devid'); $vars = Horde_Variables::getDefaultVariables(); - $vars->set('account', $account); + $vars->set('account', $curaccount['code']); $Form = new DeviceDeleteForm($vars); $FormValid = $Form->validate($vars, true); @@ -86,7 +84,7 @@ case 'delete': } $vars = Horde_Variables::getDefaultVariables(array()); - $vars->set('account', $account); + $vars->set('account', $curaccount['code']); $Form = new DeviceDeleteForm($vars); break; @@ -99,7 +97,7 @@ default: // Fetch the (possibly updated) list of extensions try { - $devices = $shout->devices->getDevices($account); + $devices = $shout->devices->getDevices($curaccount['code']); } catch (Exception $e) { $notification->push($e); $devices = array(); diff --git a/shout/dialplan.php b/shout/dialplan.php index a2971718b..086d2c992 100644 --- a/shout/dialplan.php +++ b/shout/dialplan.php @@ -16,9 +16,9 @@ require_once SHOUT_BASE . '/lib/Forms/ExtensionForm.php'; $action = Horde_Util::getFormData('action'); $menu = Horde_Util::getFormData('menu'); -$account = $_SESSION['shout']['account']; +$curaccount['code'] = $_SESSION['shout']['curaccount']; -$menus = $shout->storage->getMenus($account); +$menus = $shout->storage->getMenus($curaccount['code']); switch($action) { case 'edit': diff --git a/shout/extensions.php b/shout/extensions.php index 29cc94bcd..a7e1b0322 100644 --- a/shout/extensions.php +++ b/shout/extensions.php @@ -15,9 +15,7 @@ $shout = Horde_Registry::appInit('shout'); require_once SHOUT_BASE . '/lib/Forms/ExtensionForm.php'; $action = Horde_Util::getFormData('action'); -$account = $_SESSION['shout']['account']; - -//$tabs = Shout::getTabs($account, $vars); +$curaccount = $_SESSION['shout']['curaccount']; $RENDERER = new Horde_Form_Renderer(); @@ -28,7 +26,7 @@ switch ($action) { case 'add': case 'edit': $vars = Horde_Variables::getDefaultVariables(); - $vars->set('account', $account); + $vars->set('account', $curaccount['code']); $Form = new ExtensionDetailsForm($vars); $FormValid = $Form->validate($vars, true); @@ -50,7 +48,7 @@ case 'edit': // Create a new add/edit form $extension = Horde_Util::getFormData('extension'); - $extensions = $shout->extensions->getExtensions($account); + $extensions = $shout->extensions->getExtensions($curaccount['code']); $vars = new Horde_Variables($extensions[$extension]); if ($action == 'edit') { $vars->set('oldextension', $extension); @@ -67,7 +65,7 @@ case 'delete': $extension = Horde_Util::getFormData('extension'); $vars = Horde_Variables::getDefaultVariables(); - $vars->set('account', $account); + $vars->set('account', $curaccount['code']); $Form = new ExtensionDeleteForm($vars); $FormValid = $Form->validate($vars, true); @@ -86,7 +84,7 @@ case 'delete': } $vars = Horde_Variables::getDefaultVariables(array()); - $vars->set('account', $account); + $vars->set('account', $curaccount['code']); $Form = new ExtensionDeleteForm($vars); break; @@ -100,7 +98,7 @@ default: // Fetch the (possibly updated) list of extensions try { - $extensions = $shout->extensions->getExtensions($account); + $extensions = $shout->extensions->getExtensions($curaccount['code']); } catch (Exception $e) { $notification->push($e); $extensions = array(); diff --git a/shout/lib/Application.php b/shout/lib/Application.php index bff3fd6c7..0e206158f 100644 --- a/shout/lib/Application.php +++ b/shout/lib/Application.php @@ -84,6 +84,7 @@ class Shout_Application extends Horde_Registry_Application } catch (Shout_Exception $e) { $GLOBALS['notification']->push($e); $accounts = false; + return false; } $account = Horde_Util::getFormData('account'); @@ -91,7 +92,7 @@ class Shout_Application extends Horde_Registry_Application $account = $_SESSION['shout']['account']; } - if (!empty($account) && !in_array($account, $accounts)) { + if (!empty($account) && !in_array($account, array_keys($accounts))) { // Requested account not available $GLOBALS['notification']->push(_("You do not have permission to access that account."), 'horde.error'); $account = false; @@ -100,7 +101,7 @@ class Shout_Application extends Horde_Registry_Application if (empty($account)) { if (count($accounts)) { // Default to the user's first account - $account = reset($accounts); + $account = reset(array_keys($accounts)); } else { // No account requested and/or no accounts available anyway $GLOBALS['notification']->push("Please select a account to continue.", 'horde.info'); @@ -108,7 +109,8 @@ class Shout_Application extends Horde_Registry_Application } } - $_SESSION['shout']['account'] = $account; + $_SESSION['shout']['accounts'] = $accounts; + $_SESSION['shout']['curaccount'] = $account; } /** diff --git a/shout/lib/Driver/Sql.php b/shout/lib/Driver/Sql.php index 74a1dace8..7d2426d43 100644 --- a/shout/lib/Driver/Sql.php +++ b/shout/lib/Driver/Sql.php @@ -48,7 +48,7 @@ class Shout_Driver_Sql extends Shout_Driver { $this->_connect(); - $sql = 'SELECT name, accountcode FROM accounts'; + $sql = 'SELECT name, code FROM accounts'; $vars = array(); $msg = 'SQL query in Shout_Driver_Sql#getAccounts(): ' . $sql; @@ -65,7 +65,7 @@ class Shout_Driver_Sql extends Shout_Driver $accounts = array(); while ($row && !($row instanceof PEAR_Error)) { - $accounts[$accountcode] = $row['name']; + $accounts[$row['code']] = $row['name']; $row = $result->fetchRow(DB_FETCHMODE_ASSOC); } @@ -82,7 +82,7 @@ class Shout_Driver_Sql extends Shout_Driver $this->_connect(); - $sql = 'SELECT accounts.accountcode AS account, menus.name AS name, ' . + $sql = 'SELECT accounts.code AS account, menus.name AS name, ' . 'menus.description AS description, menus.soundfile AS soundfile ' . 'FROM menus INNER JOIN accounts ON menus.account_id = accounts.id ' . 'WHERE accounts.accountcode = ?'; @@ -347,7 +347,7 @@ class Shout_Driver_Sql extends Shout_Driver } Horde::assertDriverConfig($this->_params, $this->_params['class'], - array('phptype', 'charset', 'table')); + array('phptype', 'charset')); if (!isset($this->_params['database'])) { $this->_params['database'] = ''; @@ -363,7 +363,7 @@ class Shout_Driver_Sql extends Shout_Driver $this->_write_db = DB::connect($this->_params, array('persistent' => !empty($this->_params['persistent']))); if ($this->_write_db instanceof PEAR_Error) { - throw Shout_Exception($this->_write_db); + throw new Shout_Exception($this->_write_db); } // Set DB portability options. diff --git a/shout/lib/Shout.php b/shout/lib/Shout.php index 9b2736da3..aa78d6cda 100644 --- a/shout/lib/Shout.php +++ b/shout/lib/Shout.php @@ -24,7 +24,7 @@ class Shout */ static public function getMenu($returnType = 'object') { - global $conf, $account, $section, $action; + global $conf, $curaccount, $section, $action; require_once 'Horde/Menu.php'; diff --git a/shout/templates/devices/list.inc b/shout/templates/devices/list.inc index b45b29d71..dae38654d 100644 --- a/shout/templates/devices/list.inc +++ b/shout/templates/devices/list.inc @@ -9,7 +9,7 @@ - Account: + Account:
diff --git a/shout/templates/dialplan/list.inc b/shout/templates/dialplan/list.inc index 2b948f02c..d154a4578 100644 --- a/shout/templates/dialplan/list.inc +++ b/shout/templates/dialplan/list.inc @@ -11,7 +11,7 @@ - Account: + Account:
diff --git a/shout/templates/extensions/list.inc b/shout/templates/extensions/list.inc index 9166a14f7..0a58f1aae 100644 --- a/shout/templates/extensions/list.inc +++ b/shout/templates/extensions/list.inc @@ -9,7 +9,7 @@ - Account: + Account:
diff --git a/shout/templates/menu.inc b/shout/templates/menu.inc index 25e1bf10d..d316b89cf 100644 --- a/shout/templates/menu.inc +++ b/shout/templates/menu.inc @@ -36,12 +36,12 @@ function accountSubmit(clear)