From e27005b80da6485ab001e82394031f1e58f460fe Mon Sep 17 00:00:00 2001 From: Ben Klang Date: Fri, 1 Jan 2010 15:33:21 -0500 Subject: [PATCH] Add delete extension functionality --- shout/extensions.php | 26 ++++++++++++++++++++------ shout/lib/Forms/ExtensionForm.php | 26 ++++++++++++++++++++++++-- shout/templates/extensions/delete.inc | 8 ++++++++ shout/templates/extensions/edit.inc | 8 +++++++- 4 files changed, 59 insertions(+), 9 deletions(-) create mode 100644 shout/templates/extensions/delete.inc diff --git a/shout/extensions.php b/shout/extensions.php index da4a4d1c1..261f467be 100644 --- a/shout/extensions.php +++ b/shout/extensions.php @@ -25,6 +25,7 @@ switch ($action) { case 'add': case 'edit': $vars = Horde_Variables::getDefaultVariables(); + $vars->set('context', $context); $Form = new ExtensionDetailsForm($vars); $FormValid = $Form->validate($vars, true); @@ -32,7 +33,7 @@ case 'edit': if ($Form->isSubmitted() && $FormValid) { // Form is Valid and Submitted try { - $Form->execute($context); + $Form->execute(); $notification->push(_("User information updated."), 'horde.success'); $action = 'list'; @@ -59,13 +60,26 @@ case 'delete': $title .= sprintf(_("Delete Extension %s"), $extension); $extension = Horde_Util::getFormData('extension'); - $res = $shout->deleteUser($context, $extension); + $vars = Horde_Variables::getDefaultVariables(); + $vars->set('context', $context); + $Form = new ExtensionDeleteForm($vars); + + $FormValid = $Form->validate($vars, true); - if (!$res) { - echo "Failed!"; - print_r($res); + if ($Form->isSubmitted() && $FormValid) { + try { + $Form->execute(); + $notification->push(_("Extension Deleted.")); + } catch (Exception $e) { + $notification->push($e); + $action = 'list'; + } + } else { + $vars = Horde_Variables::getDefaultVariables(array()); + $Form = new ExtensionDeleteForm($vars); + $Form->open($RENDERER, $vars, Horde::applicationUrl('extensions.php'), 'post'); } - $notification->push("User Deleted."); + break; case 'list': diff --git a/shout/lib/Forms/ExtensionForm.php b/shout/lib/Forms/ExtensionForm.php index 3acb4d7a9..db2fd962f 100644 --- a/shout/lib/Forms/ExtensionForm.php +++ b/shout/lib/Forms/ExtensionForm.php @@ -51,11 +51,12 @@ class ExtensionDetailsForm extends Horde_Form { * @param string $context Context in which to execute this save * FIXME: is there a better way to get the $context and $shout_extensions? */ - function execute($context) + function execute() { global $shout_extensions; $extension = $this->_vars->get('extension'); + $context = $this->_vars->get('context'); // FIXME: Input Validation (Text::??) $details = array( @@ -66,7 +67,28 @@ class ExtensionDetailsForm extends Horde_Form { 'mailboxpin' => $this->_vars->get('mailboxpin'), ); - $res = $shout_extensions->saveExtension($context, $extension, $details); + $shout_extensions->saveExtension($context, $extension, $details); } +} + +class ExtensionDeleteForm extends Horde_Form +{ + function __construct(&$vars) + { + parent::__construct($vars, _("Delete Extension %s - Context: $context")); + + $this->addHidden('', 'context', 'text', true); + $this->addHidden('', 'extension', 'int', true); + $this->addHidden('', 'action', 'text', true); + $this->setButtons(array(_("Delete"), _("Cancel"))); + } + + function execute() + { + global $shout_extensions; + $context = $this->_vars->get('extension'); + $extension = $this->_vars->get('extension'); + $shout_extensions->deleteExtension($context, $extension); + } } \ No newline at end of file diff --git a/shout/templates/extensions/delete.inc b/shout/templates/extensions/delete.inc new file mode 100644 index 000000000..d3e6e3dc3 --- /dev/null +++ b/shout/templates/extensions/delete.inc @@ -0,0 +1,8 @@ +beginActive($Form->getTitle()); +$RENDERER->renderFormActive($Form, $vars); +$RENDERER->submit(); +$RENDERER->end(); +$Form->close($RENDERER); +?> +Extension: get('extension'); ?>
\ No newline at end of file diff --git a/shout/templates/extensions/edit.inc b/shout/templates/extensions/edit.inc index a95682f37..5ba2f592c 100644 --- a/shout/templates/extensions/edit.inc +++ b/shout/templates/extensions/edit.inc @@ -3,4 +3,10 @@ $RENDERER->beginActive($Form->getTitle()); $RENDERER->renderFormActive($Form, $vars); $RENDERER->submit(); $RENDERER->end(); -$Form->close($RENDERER); \ No newline at end of file +$Form->close($RENDERER); +$deleteUrl = Horde::applicationUrl('extensions.php'); +$params = array ('action' => 'delete', + 'extension' => $extension); +$deleteUrl = Horde_Util::addParameter($deleteUrl, $params); +?> +Delete Extension \ No newline at end of file -- 2.11.0