Add delete extension functionality
authorBen Klang <ben@alkaloid.net>
Fri, 1 Jan 2010 20:33:21 +0000 (15:33 -0500)
committerBen Klang <ben@alkaloid.net>
Fri, 1 Jan 2010 20:33:21 +0000 (15:33 -0500)
shout/extensions.php
shout/lib/Forms/ExtensionForm.php
shout/templates/extensions/delete.inc [new file with mode: 0644]
shout/templates/extensions/edit.inc

index da4a4d1..261f467 100644 (file)
@@ -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':
index 3acb4d7..db2fd96 100644 (file)
@@ -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 (file)
index 0000000..d3e6e3d
--- /dev/null
@@ -0,0 +1,8 @@
+<?php
+$RENDERER->beginActive($Form->getTitle());
+$RENDERER->renderFormActive($Form, $vars);
+$RENDERER->submit();
+$RENDERER->end();
+$Form->close($RENDERER);
+?>
+Extension: <?php echo $vars->get('extension'); ?><br>
\ No newline at end of file
index a95682f..5ba2f59 100644 (file)
@@ -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);
+?>
+<a href="<?php echo $deleteUrl; ?>">Delete Extension</a>
\ No newline at end of file