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['code']);
- $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]['name']));
- $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['code']);
- $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['code']);
- $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');
$notification->notify();
-require SHOUT_TEMPLATES . '/accounts/' . $action . '.inc';
+Shout::getAdminTabs();
require $registry->get('templates', 'horde') . '/common-footer.inc';
+
--- /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['code']);
+ $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]['name']));
+ $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['code']);
+ $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['code']);
+ $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();
+
+Shout::getAdminTabs();
+
+require SHOUT_TEMPLATES . '/accounts/' . $action . '.inc';
+
+require $registry->get('templates', 'horde') . '/common-footer.inc';
--- /dev/null
+<?php
+/**
+ * Copyright 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/NumberForm.php';
+
+$action = Horde_Util::getFormData('action');
+$curaccount = $_SESSION['shout']['curaccount'];
+
+$RENDERER = new Horde_Form_Renderer();
+
+$title = _("Numbers: ");
+
+switch ($action) {
+case 'add':
+case 'edit':
+ $vars = Horde_Variables::getDefaultVariables();
+ $Form = new NumberDetailsForm($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');
+ }
+
+ // FIXME: Preserve vars on edit
+
+ // 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['code']);
+ $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['code']);
+ $Form = new ExtensionDeleteForm($vars);
+
+ break;
+
+case 'list':
+default:
+ $action = 'list';
+ $title .= _("List Numbers");
+}
+
+try {
+ $numbers = $shout->storage->getNumbers();
+} catch (Exception $e) {
+ $notification->push($e);
+}
+
+
+Horde::addScriptFile('stripe.js', 'horde');
+Horde::addScriptFile('prototype.js', 'horde');
+
+require SHOUT_TEMPLATES . '/common-header.inc';
+require SHOUT_TEMPLATES . '/menu.inc';
+
+$notification->notify();
+
+Shout::getAdminTabs();
+
+require SHOUT_TEMPLATES . '/admin/numbers/' . $action . '.inc.php';
+
+require $registry->get('templates', 'horde') . '/common-footer.inc';
throw new Shout_Exception($row);
}
- $menus = array();
while ($row && !($row instanceof PEAR_Error)) {
$menu = $row['name'];
$menus[$menu] = array(
return true;
}
+ public function getNumbers()
+ {
+ $sql = 'SELECT numbers.id AS id, numbers.did AS did, ' .
+ 'accounts.code AS accountcode, menus.name AS menuName ' .
+ 'FROM numbers ' .
+ 'INNER JOIN accounts ON numbers.account_id = accounts.id ' .
+ 'INNER JOIN menus ON numbers.menu_id = menus.id';
+
+ $msg = 'SQL query in Shout_Driver_Sql#getNumbers(): ' . $sql;
+ Horde::logMessage($msg, 'DEBUG');
+ $result = $this->_db->query($sql, $args);
+ if ($result instanceof PEAR_Error) {
+ throw new Shout_Exception($result);
+ }
+
+ $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
+ if ($row instanceof PEAR_Error) {
+ throw new Shout_Exception($row);
+ }
+
+ $numbers = array();
+ while ($row && !($row instanceof PEAR_Error)) {
+ $id = $numbers['did'];
+ $numbers[$id] = $row;
+
+ /* Advance to the new row in the result set. */
+ $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
+ }
+
+ $result->free();
+ return $numbers;
+ }
+
/**
* Attempts to open a persistent connection to the SQL server.
*
--- /dev/null
+<?php
+/**
+ * $Id$
+ *
+ * Copyright 2010 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 NumberDetailsForm extends Horde_Form {
+
+ /**
+ * AccountDetailsForm constructor.
+ *
+ * @param mixed reference $vars
+ * @return boolean
+ */
+ function __construct(&$vars)
+ {
+ $action = $vars->get('action');
+ if ($action == 'edit') {
+ $title = _("Edit Number");
+ } else {
+ $title = _("Add Number");
+ }
+
+ parent::__construct($vars, $title);
+
+ $this->addHidden('', 'action', 'text', true);
+ //$this->addHidden('', 'oldaccount', 'text', false);
+ $this->addVariable(_("Telephone Number"), 'number', 'phone', true);
+
+ $shout = $GLOBALS['registry']->getApiInstance('shout', 'application');
+ $accounts = $shout->storage->getAccounts();
+ foreach ($accounts as $id => $info) {
+ $list[$id] = $info['name'];
+ }
+ $select = $this->addVariable(_("Account Code"), 'accountcode',
+ 'enum', false, false, null, array($list));
+ $action = &Horde_Form_Action::factory('reload');
+ $select->setAction($action);
+ $select->setOption('trackchange', true);
+
+ $accountcode = $vars->get('accountcode');
+ $menus = $shout->storage->getMenus($accountcode);
+ $list = array('' => _("-- none --"));
+ foreach ($menus as $id => $info) {
+ $list[$id] = $info['name'];
+ }
+ $this->addVariable(_("Menu"), 'menuName', 'enum', false,
+ false, null, array($list));
+ return true;
+ }
+
+ /**
+ * Process this form, saving its information to the backend.
+ */
+ function execute()
+ {
+ die("FIXME");
+ $shout = $GLOBALS['registry']->getApiInstance('shout', 'application');
+
+ $code = $this->_vars->get('code');
+ $name = $this->_vars->get('name');
+ $adminpin = $this->_vars->get('adminpin');
+ if (empty($adminpin)) {
+ $adminpin = rand(1000, 9999);
+ }
+
+ $shout->storage->saveAccount($code, $name, $adminpin);
+ }
+
+}
+
+class NumberDeleteForm extends Horde_Form
+{
+ function __construct(&$vars)
+ {
+ die("FIXME");
+ $extension = $vars->get('extension');
+ $account = $vars->get('account');
+
+ $title = _("Delete Extension %s - Account: %s");
+ $title = sprintf($title, $extension, $_SESSION['shout']['accounts'][$account]['name']);
+ 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()
+ {
+ die("FIXME");
+ $shout = $GLOBALS['registry']->getApiInstance('shout', 'application');
+ $account = $this->_vars->get('account');
+ $shout->storage->deleteAccount($account);
+ }
+}
return $res;
}
+ static public function getAdminTabs()
+ {
+ $tabname = Horde_Util::getFormData('tabname');
+ $tabs = new Horde_Ui_Tabs('view', Horde_Variables::getDefaultVariables());
+ $tabs->addTab(_("Telephone Numbers"),
+ Horde::applicationUrl('admin/numbers.php'),
+ array('tabname' => 'numbers', id => 'tabnumbers'));
+ $tabs->addTab(_("Accounts"),
+ Horde::applicationUrl('admin/accounts.php'),
+ array('tabname' => 'accounts', id => 'tabaccounts'));
+ if ($tabname === null) {
+ $tabname = 'numbers';
+ }
+
+ echo $tabs->render($tabname);
+ }
+
}
--- /dev/null
+<?php $Form->renderActive();
\ No newline at end of file
--- /dev/null
+<div id="adminNumberList">
+ <table width="100%" cellspacing="0" class="striped">
+ <tr>
+ <td class="uheader">Telephone Number</td>
+ <td class="uheader">Account Name</td>
+ <td class="uheader">Menu Name</td>
+ </tr>
+ <?php
+ $url = Horde::applicationUrl("admin/numbers.php");
+ $editurl = Horde_Util::addParameter($url, 'action', 'edit');
+ $deleteurl = Horde_Util::addParameter($url, 'action', 'delete');
+ foreach ($numbers as $numberinfo) {
+ $code = $acctinfo['code'];
+ ?>
+ <tr class="item" style="vertical-align: top">
+ <td>
+ <?php echo Horde::link(Horde_Util::addParameter($editurl,
+ array('account' => $code))); echo $code; echo '</a>'; ?>
+ </td>
+ <td>
+ <?php echo $acctinfo['name']; ?>
+ </td>
+ <td>
+ <?php echo $acctinfo['adminpin']; ?>
+ </td>
+ </tr>
+ <?php
+ }
+ ?>
+ </table>
+</div>
+<ul id="controls">
+ <?php
+ $addurl = Horde_Util::addParameter($url, 'action', 'add');
+ ?>
+ <li><a class="button" href="<?php echo $addurl; ?>">
+ <?php echo Horde::img('extension-add.png'); ?> New Number
+ </a>
+ </li>
+</ul>
\ No newline at end of file