Shout: Fix displaying dialplan editor
authorBen Klang <ben@alkaloid.net>
Mon, 8 Mar 2010 23:15:27 +0000 (18:15 -0500)
committerBen Klang <ben@alkaloid.net>
Mon, 8 Mar 2010 23:24:19 +0000 (18:24 -0500)
...and while we're at it, optimize away one unnecessary AJAX call.

shout/lib/Ajax/Application.php
shout/lib/Driver/Sql.php
shout/templates/dialplan/edit.inc

index fee3d14..a5f50ac 100644 (file)
@@ -34,7 +34,7 @@ class Shout_Ajax_Application extends Horde_Ajax_Application_Base
     {
         $vars = $this->_vars;
         $shout = Horde_Registry::appInit('shout');
-        $account = $_SESSION['shout']['account'];
+        $account = $_SESSION['shout']['curaccount'];
         try {
             $shout = $GLOBALS['registry']->getApiInstance('shout', 'application');
             $shout->extensions->addDestination($account, $vars->extension, $vars->type, $vars->destination);
@@ -54,7 +54,7 @@ class Shout_Ajax_Application extends Horde_Ajax_Application_Base
     {
         $vars = $this->_vars;
         $shout = Horde_Registry::appInit('shout');
-        $account = $_SESSION['shout']['account'];
+        $account = $_SESSION['shout']['curaccount'];
         try {
             // FIXME: Use Form?
             $shout = $GLOBALS['registry']->getApiInstance('shout', 'application');
@@ -93,25 +93,27 @@ class Shout_Ajax_Application extends Horde_Ajax_Application_Base
         try {
             $vars = $this->_vars;
             $shout = Horde_Registry::appInit('shout');
-            $account = $_SESSION['shout']['account'];
+            $account = $_SESSION['shout']['curaccount'];
             $menus = $shout->storage->getMenus($account);
             $menu = $vars->menu;
             if (!isset($menus[$menu])) {
                 Horde::logMessage("User requested a menu that does not exist.", __FILE__, __LINE__, PEAR_LOG_ERR);
-                $notification->push(_("That menu does not exist."), 'horde.error');
-                $action = 'list';
+                //$GLOBALS['notification']->push(_("That menu does not exist."), 'horde.error');
                 // FIXME notifications
                 return false;
             }
+
             $data['meta'] = $menus[$menu];
             $data['actions'] = $shout->dialplan->getMenuActions($account, $menu);
             return $data;
         } catch (Exception $e) {
             //FIXME: Create a way to notify the user of the failure.
+            die(var_dump($e));
             Horde::logMessage($e->getMessage(), __FILE__, __LINE__, PEAR_LOG_ERR);
             return false;
         }
     }
+
     /**
      * TODO
      */
@@ -120,7 +122,7 @@ class Shout_Ajax_Application extends Horde_Ajax_Application_Base
         try {
             $vars = $this->_vars;
             $GLOBALS['shout'] = Horde_Registry::appInit('shout');
-            $account = $_SESSION['shout']['account'];
+            $account = $_SESSION['shout']['curaccount'];
             $actions = Shout::getMenuActions($contex, $menu);
             return $actions;
         } catch (Exception $e) {
@@ -138,7 +140,7 @@ class Shout_Ajax_Application extends Horde_Ajax_Application_Base
                 throw new Shout_Exception("Invalid action requested.");
             }
             $GLOBALS['shout'] = Horde_Registry::appInit('shout');
-            $account = $_SESSION['shout']['account'];
+            $account = $_SESSION['shout']['curaccount'];
             $actions = Shout::getMenuActions();
             $action = $actions[$action];
             $form = new Horde_Form($vars, $action['description'], 'editActionForm');
index 839d21f..303e442 100644 (file)
@@ -102,11 +102,11 @@ class Shout_Driver_Sql extends Shout_Driver
 
         $menus[$account] = array();
         while ($row && !($row instanceof PEAR_Error)) {
-            $menu = $row['menu_name'];
+            $menu = $row['name'];
             $menus[$account][$menu] = array(
                 'name' => $menu,
-                'description' => $row['menu_description'],
-                'soundfile' => $row['menu_soundfile']
+                'description' => $row['description'],
+                'soundfile' => $row['soundfile']
             );
             $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
         }
@@ -121,18 +121,18 @@ class Shout_Driver_Sql extends Shout_Driver
             return $menuActions[$menu];
         }
 
-        $sql = "SELECT accounts.accountcode AS account, menus.name AS description, " .
+        $sql = "SELECT accounts.code AS account, menus.name AS description, " .
                "actions.name AS action, menu_entries.digit AS digit, " . 
                "menu_entries.args AS args FROM menu_entries " .
                "INNER JOIN menus ON menu_entries.menu_id = menus.id " .
                "INNER JOIN actions ON menu_entries.action_id = actions.id " .
                "INNER JOIN accounts ON menus.account_id = accounts.id " .
-               "WHERE accounts.accountcode = ? AND menus.name = ?";
-        $values = array($account, $menuid);
+               "WHERE accounts.code = ? AND menus.name = ?";
+        $values = array($account, $menu);
 
         $msg = 'SQL query in Shout_Driver_Sql#getMenuActions(): ' . $sql;
         Horde::logMessage($msg, __FILE__, __LINE__, PEAR_LOG_DEBUG);
-        $result = $this->_db->query($sql, $vars);
+        $result = $this->_db->query($sql, $values);
         if ($result instanceof PEAR_Error) {
             throw new Shout_Exception($result);
         }
@@ -152,7 +152,8 @@ class Shout_Driver_Sql extends Shout_Driver
             $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
         }
         $result->free();
-        return $menus[$menu];
+
+        return $menuActions[$menu];
     }
 
     /**
index b1543a8..712a331 100644 (file)
@@ -31,7 +31,7 @@
 var ajax_url = '<?php echo Horde::getServiceLink('ajax', 'shout') ?>';
 var menu = '<?php echo $menu['name']; ?>';
 var menuInfo = $H();
-var menuActions = $H();
+var menuActions = $H(<?php echo Horde_Serialize::serialize(Shout::getMenuActions(), Horde_Serialize::JSON, Horde_Nls::getCharset()); ?>);
 var curDigit = null;
 
 function editAction(digit)
@@ -191,13 +191,5 @@ new Ajax.Request(ajax_url + 'getMenuInfo',
         refreshMenu();
     }
 });
-new Ajax.Request(ajax_url + 'getMenuActions',
-{
-    method: 'post',
-    onSuccess: function(r) {
-        menuActions = $H(r.responseJSON.response);
-        refreshMenu();
-    }
-});
 // -->
 </script>
\ No newline at end of file