Shout: Fix account name display and selection
authorBen Klang <ben@alkaloid.net>
Mon, 8 Mar 2010 22:41:47 +0000 (17:41 -0500)
committerBen Klang <ben@alkaloid.net>
Mon, 8 Mar 2010 23:24:15 +0000 (18:24 -0500)
shout/devices.php
shout/dialplan.php
shout/extensions.php
shout/lib/Application.php
shout/lib/Driver/Sql.php
shout/lib/Shout.php
shout/templates/devices/list.inc
shout/templates/dialplan/list.inc
shout/templates/extensions/list.inc
shout/templates/menu.inc

index 7d29db4..fc6e0b5 100644 (file)
@@ -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();
index a297171..086d2c9 100644 (file)
@@ -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':
index 29cc94b..a7e1b03 100644 (file)
@@ -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();
index bff3fd6..0e20615 100644 (file)
@@ -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;
     }
 
     /**
index 74a1dac..7d2426d 100644 (file)
@@ -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.
index 9b2736d..aa78d6c 100644 (file)
@@ -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';
 
index b45b29d..dae3865 100644 (file)
@@ -9,7 +9,7 @@
             </a>
         </li>
     </ul>
-    Account: <?php echo $account; ?>
+    Account: <?php echo $curaccount['name']; ?>
 </div>
 
 <div id="extensionList">
index 2b948f0..d154a45 100644 (file)
@@ -11,7 +11,7 @@
             </a>
         </li>
     </ul>
-    Account: <?php echo $account; ?>
+    Account: <?php echo $_SESSION['shout']['accounts'][$curaccount]; ?>
 </div>
 
 <div id="extensionList">
index 9166a14..0a58f1a 100644 (file)
@@ -9,7 +9,7 @@
             </a>
         </li>
     </ul>
-    Account: <?php echo $account; ?>
+    Account: <?php echo $_SESSION['shout']['accounts'][$curaccount]; ?>
 </div>
 
 <div id="extensionList">
index 25e1bf1..d316b89 100644 (file)
@@ -36,12 +36,12 @@ function accountSubmit(clear)
    <label for="account" accesskey="<?php echo $accesskey ?>">
     <select id="account" name="account" onchange="accountSubmit()">
      <?php
-        foreach ($accounts as $c) {
-            print "<option value=\"$c\"";
-            if ($c == $account) {
+        foreach ($accounts as $account => $name) {
+            print "<option value=\"$account\"";
+            if ($account == $curaccount) {
                 print " selected";
             }
-            print ">$c</option>\n";
+            print ">$name</option>\n";
         }
      ?>
     </select>