From: Ben Klang Date: Mon, 29 Mar 2010 01:44:32 +0000 (-0400) Subject: Shout: fix adding and editing conference rooms X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=ff7a8752491d4aa19017f120ed5ecf2f69a007a5;p=horde.git Shout: fix adding and editing conference rooms --- diff --git a/shout/conferences.php b/shout/conferences.php index afa57b1e1..16152bccd 100644 --- a/shout/conferences.php +++ b/shout/conferences.php @@ -33,8 +33,6 @@ case 'edit': 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'); @@ -50,17 +48,18 @@ case 'edit': } // 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'); @@ -86,7 +85,6 @@ case 'delete': $vars = Horde_Variables::getDefaultVariables(array()); $vars->set('account', $curaccount); $Form = new DeviceDeleteForm($vars); - break; case 'list': diff --git a/shout/lib/Driver/Sql.php b/shout/lib/Driver/Sql.php index c7af303db..4319e3037 100644 --- a/shout/lib/Driver/Sql.php +++ b/shout/lib/Driver/Sql.php @@ -427,14 +427,13 @@ class Shout_Driver_Sql extends Shout_Driver 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); } @@ -446,7 +445,7 @@ class Shout_Driver_Sql extends Shout_Driver $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. */ @@ -457,6 +456,33 @@ class Shout_Driver_Sql extends Shout_Driver 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. * diff --git a/shout/lib/Forms/ConferenceForm.php b/shout/lib/Forms/ConferenceForm.php index e69de29bb..9e9eb2e81 100644 --- a/shout/lib/Forms/ConferenceForm.php +++ b/shout/lib/Forms/ConferenceForm.php @@ -0,0 +1,95 @@ +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 diff --git a/shout/templates/conferences/edit.inc b/shout/templates/conferences/edit.inc new file mode 100644 index 000000000..28410e8bd --- /dev/null +++ b/shout/templates/conferences/edit.inc @@ -0,0 +1,2 @@ +renderActive($RENDERER, $vars, Horde::applicationUrl('conferences.php'), 'post'); diff --git a/shout/templates/conferences/list.inc b/shout/templates/conferences/list.inc index 151a228bc..6d02315b6 100644 --- a/shout/templates/conferences/list.inc +++ b/shout/templates/conferences/list.inc @@ -11,33 +11,31 @@ Options $info) { - - $url = Horde::applicationUrl("conferences.php"); - $url = Horde_Util::addParameter($url, + $editurl = Horde_Util::addParameter($editurl, array( 'roomno' => $roomno, ) ); - - ?> - - - - - - - - - - - - - - - + + + '; ?> + + + '; ?> + + + + + + + + +