--- /dev/null
+<?php
+/**
+ * Copyright 2005-2010 Alkaloid Networks LLC (http://projects.alkaloid.net)
+ *
+ * See the enclosed file COPYING for license information (BSD). If you
+ * did not receive this file, see
+ * http://www.opensource.org/licenses/bsd-license.php.
+ *
+ * @author Ben Klang <ben@alkaloid.net>
+ */
+
+require_once dirname(__FILE__) . '/lib/Application.php';
+$shout = Horde_Registry::appInit('shout');
+
+require_once SHOUT_BASE . '/lib/Forms/AccountForm.php';
+
+$action = Horde_Util::getFormData('action');
+$curaccount = $_SESSION['shout']['curaccount'];
+
+$RENDERER = new Horde_Form_Renderer();
+
+$title = _("Accounts: ");
+
+switch ($action) {
+case 'add':
+case 'edit':
+ $vars = Horde_Variables::getDefaultVariables();
+ $vars->set('account', $curaccount);
+ $Form = new AccountDetailsForm($vars);
+
+ if ($Form->isSubmitted() && $Form->validate($vars, true)) {
+ // Form is Valid and Submitted
+ try {
+ $Form->execute();
+ $notification->push(_("Account information saved."),
+ 'horde.success');
+ $action = 'list';
+ } catch (Exception $e) {
+ $notification->push($e);
+ }
+ break;
+ } elseif ($Form->isSubmitted()) {
+ $notification->push(_("Problem processing the form. Please check below and try again."), 'horde.warning');
+ }
+
+ // Create a new add/edit form
+ $account = Horde_Util::getFormData('extension');
+ $accounts = $shout->storage->getAccounts();
+ $vars = new Horde_Variables(array('code' => $account, 'name' => $accounts[$account]));
+ $vars->set('action', $action);
+
+ // Make sure we get the right template below.
+ $action = 'edit';
+ break;
+
+case 'delete':
+ $title .= sprintf(_("Delete Extension %s"), $extension);
+ $extension = Horde_Util::getFormData('extension');
+
+ $vars = Horde_Variables::getDefaultVariables();
+ $vars->set('account', $curaccount);
+ $Form = new ExtensionDeleteForm($vars);
+
+ $FormValid = $Form->validate($vars, true);
+
+ if ($Form->isSubmitted() && $FormValid) {
+ try {
+ $Form->execute();
+ $notification->push(_("Extension Deleted."));
+ $action = 'list';
+ } catch (Exception $e) {
+ $notification->push($e);
+ }
+ } elseif ($Form->isSubmitted()) {
+ // Submitted but not valid
+ $notification->push(_("Problem processing the form. Please check below and try again."), 'horde.warning');
+ }
+
+ $vars = Horde_Variables::getDefaultVariables(array());
+ $vars->set('account', $curaccount);
+ $Form = new ExtensionDeleteForm($vars);
+
+ break;
+
+case 'list':
+default:
+ $action = 'list';
+ $title .= _("List Accounts");
+}
+
+
+// Fetch the (possibly updated) list of extensions
+try {
+ $accounts = $shout->storage->getAccounts();
+} catch (Exception $e) {
+ $notification->push($e);
+ $extensions = array();
+}
+
+Horde::addScriptFile('stripe.js', 'horde');
+Horde::addScriptFile('prototype.js', 'horde');
+
+require SHOUT_TEMPLATES . '/common-header.inc';
+require SHOUT_TEMPLATES . '/menu.inc';
+
+$notification->notify();
+
+require SHOUT_TEMPLATES . '/accounts/' . $action . '.inc';
+
+require $registry->get('templates', 'horde') . '/common-footer.inc';
return $accounts;
}
+ public function saveAccount($code, $name)
+ {
+ $this->_connect();
+
+ if (isset($details['oldname'])) {
+ if (!isset($menus[$details['oldname']])) {
+ throw new Shout_Exception(_("Old account not found. Edit aborted."));
+ } else {
+ throw new Shout_Exception(_("Unsupported operation."));
+ $sql = 'UPDATE accounts SET code = ?, name =? WHERE code = ?';
+ }
+ } else {
+ $sql = 'INSERT INTO accounts (code, name) VALUES (?,?)';
+ }
+
+ $vars = array($code, $name);
+
+ $msg = 'SQL query in Shout_Driver_Sql#getAccounts(): ' . $sql;
+ Horde::logMessage($msg, 'DEBUG');
+ $result = $this->_db->query($sql, $vars);
+ if ($result instanceof PEAR_Error) {
+ throw new Shout_Exception($result);
+ }
+
+ }
+
public function getMenus($account)
{
$this->_connect();
--- /dev/null
+<?php
+/**
+ * $Id$
+ *
+ * Copyright 2005-2009 Alkaloid Networks LLC (http://projects.alkaloid.net)
+ *
+ * See the enclosed file LICENSE for license information (BSD). If you
+ * did not receive this file, see
+ * http://www.opensource.org/licenses/bsd-license.php.
+ *
+ * @author Ben Klang <ben@alkaloid.net>
+ * @package Shout
+ */
+
+class AccountDetailsForm extends Horde_Form {
+
+ /**
+ * AccountDetailsForm constructor.
+ *
+ * @param mixed reference $vars
+ * @return boolean
+ */
+ function __construct(&$vars)
+ {
+ $account = $_SESSION['shout']['curaccount'];
+ $action = $vars->get('action');
+ if ($action == 'edit') {
+ $formtitle = "Edit Account";
+ $vars->set('oldaccount', $account);
+ } else {
+ $formtitle = "Add Account";
+ }
+
+ $accountname = $_SESSION['shout']['accounts'][$curaccount];
+ $title = sprintf(_("$formtitle %s"), $accountname);
+ parent::__construct($vars, $title);
+
+ $this->addHidden('', 'action', 'text', true);
+ //$this->addHidden('', 'oldaccount', 'text', false);
+ $this->addVariable(_("Account Name"), 'name', 'text', true);
+ $this->addVariable(_("Account Code"), 'code', 'text', true);
+
+ return true;
+ }
+
+ /**
+ * Process this form, saving its information to the backend.
+ */
+ function execute()
+ {
+ $shout = $GLOBALS['registry']->getApiInstance('shout', 'application');
+
+ $code = $this->_vars->get('code');
+ $name = $this->_vars->get('name');
+
+ $shout->storage->saveAccount($code, $name);;
+ }
+
+}
+
+class AccountDeleteForm extends Horde_Form
+{
+ function __construct(&$vars)
+ {
+ $extension = $vars->get('extension');
+ $account = $vars->get('account');
+
+ $title = _("Delete Extension %s - Account: %s");
+ $title = sprintf($title, $extension, $_SESSION['shout']['accounts'][$account]);
+ parent::__construct($vars, $title);
+
+ $this->addHidden('', 'account', 'text', true);
+ $this->addHidden('', 'extension', 'int', true);
+ $this->addHidden('', 'action', 'text', true);
+ $this->setButtons(array(_("Delete"), _("Cancel")));
+ }
+
+ function execute()
+ {
+ $shout = $GLOBALS['registry']->getApiInstance('shout', 'application');
+ $account = $this->_vars->get('account');
+ $shout->storage->deleteAccount($account);
+ }
+}
*/
static public function getMenu($returnType = 'object')
{
- global $conf, $curaccount, $section, $action;
-
- require_once 'Horde/Menu.php';
-
$menu = new Horde_Menu(Horde_Menu::MASK_ALL);
$menu->add(Horde::applicationUrl('dialplan.php'), _("Incoming Calls"), "dialplan.png");
$menu->add(Horde::applicationUrl('devices.php'), _("Devices"), "shout.png");
$menu->add(Horde::applicationUrl('recordings.php'), _("Recordings"), "recordings.png");
+ /* Administration. */
+ if (Horde_Auth::isAdmin('shout:admin')) {
+ $menu->add(Horde::applicationUrl('admin.php'), _("_Admin"), 'admin.png');
+ }
+
if ($returnType == 'object') {
return $menu;
} else {
--- /dev/null
+<?php
+$Form->renderActive($RENDERER, $vars, Horde::applicationUrl('admin.php'), 'post');
+
+if ($vars->get('action') == 'edit') {
+ $deleteUrl = Horde::applicationUrl('admin.php');
+ $params = array ('action' => 'delete',
+ 'account' => $account);
+ $deleteUrl = Horde_Util::addParameter($deleteUrl, $params);
+ echo '<a href="' . $deleteUrl . '">Delete Account</a>';
+}
--- /dev/null
+<div class="header">
+ <ul id="controls">
+ <?php
+ $addurl = Horde::applicationUrl('admin.php');
+ $addurl = Horde_Util::addParameter($addurl, 'action', 'add');
+ ?>
+ <li><a href="<?php echo $addurl; ?>">
+ <?php echo Horde::img('add-extension.png'); ?> New Account
+ </a>
+ </li>
+ </ul>
+ Account: <?php echo $_SESSION['shout']['accounts'][$curaccount]; ?>
+</div>
+
+<div id="extensionList">
+ <table width="100%" cellspacing="0" class="striped">
+ <tr>
+ <td class="uheader">Account Code</td>
+ <td id ="destinationsCol" class="uheader">Account Name</td>
+ </tr>
+ <?php
+ foreach ($accounts as $code => $name) {
+
+ $url = Horde::applicationUrl("admin.php");
+ $url = Horde_Util::addParameter($url,
+ array(
+ 'account' => $code,
+ )
+ );
+ $editurl = Horde_Util::addParameter($url, 'action', 'edit');
+ $deleteurl = Horde_Util::addParameter($url, 'action', 'delete');
+ ?>
+ <tr class="item" style="vertical-align: top">
+ <td>
+ <?php echo Horde::link($editurl); echo $code; ?></a>
+ </td>
+ <td>
+ <?php echo $name; ?>
+ </td>
+ </tr>
+ <?php
+ }
+ ?>
+ </table>
+</div>