if ($Form->isSubmitted() && $Form->isValid()) {
// Form is Valid and Submitted
try {
- $devid = Horde_Util::getFormData('devid');
-
$Form->execute();
$notification->push(_("Conference information saved."),
'horde.success');
}
// Create a new add/edit form
- $devid = Horde_Util::getFormData('devid');
- $devices = $shout->devices->getDevices($curaccount);
- $vars = new Horde_Variables($devices[$devid]);
+ $roomno = Horde_Util::getFormData('roomno');
+ $conferences = $shout->storage->getConferences($curaccount);
+ $vars = new Horde_Variables($conferences[$roomno]);
$vars->set('action', $action);
+
$Form = new ConferenceDetailsForm($vars);
// Make sure we get the right template below.
$action = 'edit';
-
break;
+
case 'delete':
$title .= sprintf(_("Delete Devices %s"), $extension);
$devid = Horde_Util::getFormData('devid');
$vars = Horde_Variables::getDefaultVariables(array());
$vars->set('account', $curaccount);
$Form = new DeviceDeleteForm($vars);
-
break;
case 'list':
public function getConferences($account)
{
- $sql = 'SELECT id, room_number, name, pin, options ' .
+ $sql = 'SELECT id, room_number AS roomno, name, pin, options ' .
'FROM conferences ' .
'WHERE account_id = (SELECT id FROM accounts WHERE code = ?);';
$args = array($account);
$msg = 'SQL query in Shout_Driver_Sql#getConferences(): ' . $sql;
Horde::logMessage($msg, 'DEBUG');
- $sth = $this->_db->prepare($sql);
- $result = $this->_db->execute($sth, $args);
+ $result = $this->_db->query($sql, $args);
if ($result instanceof PEAR_Error) {
throw new Shout_Exception($result);
}
$conferences = array();
while ($row && !($row instanceof PEAR_Error)) {
- $roomno = $row['room_number'];
+ $roomno = $row['roomno'];
$conferences[$roomno] = $row;
/* Advance to the new row in the result set. */
return $conferences;
}
+ public function saveConference($account, $roomno, $details)
+ {
+ if (isset($details['oldroomno'])) {
+ // This is an edit
+ $sql = 'UPDATE conferences ' .
+ 'SET room_number = ?, name = ?, pin = ? ' .
+ 'WHERE room_number = ? AND account_id = ' .
+ '(SELECT id FROM accounts WHERE code = ?)';
+ $args = array($roomno, $details['name'], $details['pin'],
+ $details['oldroomno'], $account);
+ } else {
+ $sql = 'INSERT INTO conferences ' .
+ '(room_number, name, pin, account_id) ' .
+ 'VALUES (?, ?, ?, (SELECT id FROM accounts WHERE code = ?))';
+ $args = array($roomno, $details['name'], $details['pin'], $account);
+ }
+
+ $msg = 'SQL query in Shout_Driver_Sql#saveConference(): ' . $sql;
+ Horde::logMessage($msg, 'DEBUG');
+ $result = $this->_db->query($sql, $args);
+ if ($result instanceof PEAR_Error) {
+ throw new Shout_Exception($result);
+ }
+
+ return true;
+ }
+
/**
* Attempts to open a persistent connection to the SQL server.
*
+<?php
+/**
+ * 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.
+ *
+ * @package Shout
+ */
+
+class ConferenceDetailsForm extends Horde_Form {
+
+ function __construct(&$vars)
+ {
+ if ($vars->exists('roomno')) {
+ $formtitle = "Edit Conference Room";
+ $roomno = $vars->get('roomno');
+ $this->addHidden('', 'oldroomno', 'text', true);
+ $vars->set('oldroomno', $roomno);
+ $edit = true;
+ } else {
+ $formtitle = "Create Conference Room";
+ $edit = false;
+ }
+
+ $curaccount = $_SESSION['shout']['curaccount'];
+ $accountname = $vars->account;
+ $title = sprintf(_("$formtitle - Account: %s"), $accountname);
+ parent::__construct($vars, $title);
+
+ $this->addHidden('', 'action', 'text', true);
+ $this->addVariable(_("Room Name"), 'name', 'text', true);
+ $this->addVariable(_("Room Number"), 'roomno', 'number', true);
+ $this->addVariable(_("PIN"), 'pin', 'number', false);
+ return true;
+ }
+
+ public function execute()
+ {
+ $shout = $GLOBALS['registry']->getApiInstance('shout', 'application');
+
+ $action = $this->_vars->get('action');
+ $account = $this->_vars->get('account');
+ $roomno = $this->_vars->get('roomno');
+ $details = array(
+ 'name' => $this->_vars->get('name'),
+ 'pin' => $this->_vars->get('pin')
+ );
+
+
+ // For safety, we force the device ID and password rather than rely
+ // on the form to pass them around.
+ if ($action != 'add') { // $action must be 'edit'
+ $oldroomno = $this->_vars->get('oldroomno');
+ $conferences = $shout->storage->getConferences($account);
+ if (!isset($conferences[$roomno])) {
+ // The device requested doesn't already exist. This can't
+ // be a valid edit.
+ throw new Shout_Exception(_("That conference room does not exist."),
+ 'horde.error');
+ }
+ $details['oldroomno'] = $oldroomno;
+ }
+
+ $shout->storage->saveConference($account, $roomno, $details);
+ }
+
+}
+
+class ConferenceDeleteForm extends Horde_Form
+{
+ function __construct(&$vars)
+ {
+ $devid = $vars->get('devid');
+ $account = $vars->get('account');
+
+ $title = _("FIXME Delete Device %s - Account: %s");
+ $title = sprintf($title, $devid, $_SESSION['shout']['accounts'][$account]);
+ parent::__construct($vars, $title);
+
+ $this->addHidden('', 'account', 'text', true);
+ $this->addHidden('', 'devid', 'text', true);
+ $this->addHidden('', 'action', 'text', true);
+ $this->setButtons(array(_("Delete"), _("Cancel")));
+ }
+
+ function execute()
+ {
+ $shout = $GLOBALS['registry']->getApiInstance('shout', 'application');
+ $account = $this->_vars->get('account');
+ $devid = $this->_vars->get('devid');
+ $shout->devices->deleteDevice($account, $devid);
+ }
+}
\ No newline at end of file
--- /dev/null
+<?php
+$Form->renderActive($RENDERER, $vars, Horde::applicationUrl('conferences.php'), 'post');
<td class="uheader">Options</td>
</tr>
<?php
+ $url = Horde::applicationUrl("conferences.php");
$editurl = Horde_Util::addParameter($url, 'action', 'edit');
$deleteurl = Horde_Util::addParameter($url, 'action', 'delete');
foreach ($conferences as $roomno => $info) {
-
- $url = Horde::applicationUrl("conferences.php");
- $url = Horde_Util::addParameter($url,
+ $editurl = Horde_Util::addParameter($editurl,
array(
'roomno' => $roomno,
)
);
-
- ?>
- <tr class="item">
- <td>
- <?php echo Horde::link($editurl); echo $info['name']; ?></a>
- </td>
- <td>
- <?php echo $roomno; ?>
- </td>
- <td>
- <?php echo $info['pin']; ?>
- </td>
- <td>
- <?php echo Horde::link($editurl); echo $info['options']; ?></a>
- </td>
- </tr>
- <?php
+ ?>
+ <tr class="item">
+ <td>
+ <?php echo Horde::link($editurl); echo $info['name']; echo '</a>'; ?>
+ </td>
+ <td>
+ <?php echo Horde::link($editurl); echo $roomno; echo '</a>'; ?>
+ </td>
+ <td>
+ <?php echo $info['pin']; ?>
+ </td>
+ <td>
+ <?php echo $info['options']; ?>
+ </td>
+ </tr>
+ <?php
}
?>
</table>