public function saveAction()
{
- return null;
+ try {
+ $shout = $_GLOBALS['shout'] = Horde_Registry::appInit('shout');
+ $vars = $this->_vars;
+ if (!($action = $vars->get('action'))) {
+ throw new Shout_Exception("Invalid action requested.");
+ }
+ $account = $_SESSION['shout']['curaccount'];
+ $digit = $vars->get('digit');
+ $menu = $vars->get('menu');
+ $action = $vars->get('action');
+ $actions = Shout::getMenuActions();
+ if (!isset($actions[$action])) {
+ throw new Shout_Exception('Invalid action requested.');
+ }
+ $args = array();
+ foreach ($action[$action]['args'] as $name => $info) {
+ $args[$name] = $vars->get($name);
+ }
+ $shout->dialplan->saveMenuAction($account, $menu, $action, $args);
+ } catch (Exception $e) {
+ //FIXME: Create a way to notify the user of the failure.
+ Horde::logMessage($e->getMessage(), __FILE__, __LINE__, PEAR_LOG_ERR);
+ return false;
+ }
}
public function responseType()
*
* @param array $params A hash containing connection parameters.
*/
- function __construct($params = array())
+ public function __construct($params = array())
{
parent::__construct($params);
$this->_connect();
return $menus;
}
- function saveMenu($account, $details)
+ public function saveMenu($account, $details)
{
$menus = $this->getMenus($account);
if (isset($details['oldname'])) {
$msg = 'SQL query in Shout_Driver_Sql#saveMenu(): ' . $sql;
Horde::logMessage($msg, __FILE__, __LINE__, PEAR_LOG_DEBUG);
- $result = $this->_db->query($sql, $values);
+ $result = $this->_write_db->query($sql, $values);
if ($result instanceof PEAR_Error) {
throw new Shout_Exception($result);
}
return true;
}
- function getMenuActions($account, $menu)
+ public function getMenuActions($account, $menu)
{
static $menuActions;
if (!empty($menuActions[$menu])) {
return $menuActions[$menu];
}
+ public function saveMenuAction($account, $menu, $digit, $action, $args)
+ {
+ // Remove any existing action
+ $sql = 'DELETE FROM menu_entries WHERE digit = ?';
+ $values = array($digit);
+ $msg = 'SQL query in Shout_Driver_Sql#saveMenuAction(): ' . $sql;
+ Horde::logMessage($msg, __FILE__, __LINE__, PEAR_LOG_DEBUG);
+ $result = $this->_write_db->query($sql, $values);
+ if ($result instanceof PEAR_Error) {
+ throw new Shout_Exception($result);
+ }
+
+ $sql = 'INSERT INTO menu_entries (menu_id, digit, action_id, args) ' .
+ 'VALUES((SELECT id FROM menus WHERE account_id = ' .
+ '(SELECT id FROM accounts WHERE code = ?) AND name = ?), ?, ' .
+ '(SELECT id FROM actions WHERE name = ?), ?)';
+ $yamlargs = Horde_Yaml::dump($args);
+ $values = array($account, $menu, $digit, $action, $yamlargs);
+ $msg = 'SQL query in Shout_Driver_Sql#saveMenuAction(): ' . $sql;
+ Horde::logMessage($msg, __FILE__, __LINE__, PEAR_LOG_DEBUG);
+ $result = $this->_write_db->query($sql, $values);
+ if ($result instanceof PEAR_Error) {
+ throw new Shout_Exception($result);
+ }
+
+ return true;
+ }
+
/**
* Get a list of devices for a given account
*