Merge patches from Daniel Collins <dev@studiodccreative.com>
authorBen Klang <ben@alkaloid.net>
Thu, 17 Dec 2009 19:21:44 +0000 (14:21 -0500)
committerBen Klang <ben@alkaloid.net>
Thu, 17 Dec 2009 19:21:44 +0000 (14:21 -0500)
Fixes several bugs in Alias/Forward handling

vilma/lib/Forms/EditAliasForm.php [new file with mode: 0644]
vilma/lib/Forms/EditForwardForm.php [new file with mode: 0644]
vilma/users/editAlias.php [new file with mode: 0644]
vilma/users/editForward.php [new file with mode: 0644]

diff --git a/vilma/lib/Forms/EditAliasForm.php b/vilma/lib/Forms/EditAliasForm.php
new file mode 100644 (file)
index 0000000..cf45d0e
--- /dev/null
@@ -0,0 +1,42 @@
+<?php
+/**
+ * Copyright 2006-2007 Alkaloid Networks <http://www.alkaloid.net>
+ *
+ * See the enclosed file LICENSE for license information (BSD). If you did
+ * did not receive this file, see http://cvs.horde.org/co.php/vilma/LICENSE.
+ *
+ * $Horde: vilma/lib/Forms/EditUserForm.php,v 1.6 2009/05/27 23:57:32 bklang Exp $
+ *
+ * @author  Ben Klang <ben@alkaloid.net>
+ * @package Vilma
+ */
+
+class EditAliasForm extends Horde_Form {
+
+    function EditAliasForm(&$vars)
+    {
+        global $vilma_driver;
+
+        $type = $vars->get('type');
+        $editing = ($vars->get('mode') == 'edit');
+        if ($editing) {
+            $title = sprintf(_("Edit Alias \"%s\" for \"%s\""), $vars->get('alias_address'), $vars->get('address'));
+        } else {
+            $title = sprintf(_("New Alias for %s"), $vars->get('address'));
+        }
+        parent::Horde_Form($vars, $title);
+
+        /* Set up the form. */
+        $this->setButtons(true, true);
+        $this->addHidden('', 'address', 'text', false);
+        $this->addHidden('', 'mode', 'text', false);
+        $this->addHidden('', 'id', 'text', false);
+        if ($editing) {
+            $this->addHidden('', 'alias', 'text', false);
+        }
+        $name = "Alias Address";
+        $type = $vars->get('type');
+        $this->addVariable(_($name), 'alias_address', 'email', true, false, _("The email address to add as an alias for this user.  Note that the server must be configured to receive mail for the domain contained in this address."));
+    }
+
+}
diff --git a/vilma/lib/Forms/EditForwardForm.php b/vilma/lib/Forms/EditForwardForm.php
new file mode 100644 (file)
index 0000000..6792cc9
--- /dev/null
@@ -0,0 +1,42 @@
+<?php
+/**
+ * Copyright 2006-2007 Alkaloid Networks <http://www.alkaloid.net>
+ *
+ * See the enclosed file LICENSE for license information (BSD). If you did
+ * did not receive this file, see http://cvs.horde.org/co.php/vilma/LICENSE.
+ *
+ * $Horde: vilma/lib/Forms/EditUserForm.php,v 1.6 2009/05/27 23:57:32 bklang Exp $
+ *
+ * @author  Daniel Collins <horde_dev@argentproductions.com>
+ * @package Vilma
+ */
+
+class EditForwardForm extends Horde_Form {
+
+    function EditForwardForm(&$vars)
+    {
+        global $vilma_driver;
+
+        $type = $vars->get('type');
+        $editing = ($vars->get('mode') == 'edit');
+        if ($editing) {
+            $title = sprintf(_("Edit Forward \"%s\" for \"%s\""), $vars->get('forward_address'), $vars->get('address'));
+        } else {
+            $title = sprintf(_("New Forward for %s"), $vars->get('address'));
+        }
+        parent::Horde_Form($vars, $title);
+
+        /* Set up the form. */
+        $this->setButtons(true, true);
+        $this->addHidden('', 'address', 'text', false);
+        $this->addHidden('', 'mode', 'text', false);
+        $this->addHidden('', 'id', 'text', false);
+        if ($editing) {
+            $this->addHidden('', 'forward', 'text', false);
+        }
+        $name = "Forward Address";
+        $type = $vars->get('type');
+        $this->addVariable(_($name), 'forward_address', 'email', true, false, _("The email address to add as an forward for this user.  Note that the server must be configured to receive mail for the domain contained in this address."));
+    }
+
+}
diff --git a/vilma/users/editAlias.php b/vilma/users/editAlias.php
new file mode 100644 (file)
index 0000000..42403f7
--- /dev/null
@@ -0,0 +1,117 @@
+<?php
+/**
+ * The Vilma script to add/edit aliases.
+ *
+ * $Horde: vilma/users/edit.php,v 1.42 2009/05/27 23:57:33 daniel Exp $
+ *
+ * Copyright 2003-2009 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file LICENSE for license information (BSD). If you did
+ * did not receive this file, see http://cvs.horde.org/co.php/vilma/LICENSE.
+ *
+ * @author Daniel Collins <horde_dev@argentproductions.com>
+ */
+
+@define('VILMA_BASE', dirname(__FILE__) . '/..');
+require_once VILMA_BASE . '/lib/base.php';
+require_once 'Horde/Form.php';
+require_once 'Horde/Variables.php';
+
+require_once VILMA_BASE . '/lib/Forms/EditAliasForm.php';
+
+/* Only admin should be using this. */
+if (!Vilma::hasPermission($domain)) {
+    Horde::authenticationFailureRedirect();
+}
+$vars = Variables::getDefaultVariables();
+
+/* If the form is submitted, $vars['mode'] will be set. Catch this and process the submission so that the displayed form accurately indicates the result of the transaction. */
+if ($vars->exists('mode')) {
+  Horde::logMessage("Submit Detected: " . print_r(serialize($vars), true), __FILE__, __LINE__, PEAR_LOG_DEBUG);
+  $form = &new EditAliasForm($vars);
+  
+  if ($form->validate($vars)) {
+      $form->getInfo($vars, $info);
+      $alias_id = $vilma_driver->saveAlias($info);
+      if (is_a($alias_id, 'PEAR_Error')) {
+          Horde::logMessage($user_id, __FILE__, __LINE__, PEAR_LOG_ERR);
+          $notification->push(sprintf(_("Error saving alias. %s"), $alias_id->getMessage()), 'horde.error');
+          // remove the mode, and rearrange the alias information to clean up the form.
+          $vars->remove('mode');
+          $vars->add('retry', true);
+          if ($vars->exists('alias')) {
+            $vars->remove('alias_address');
+          } elseif ($vars->exists('address')) {
+            $vars->remove('alias_address');
+            $vars->remove('alias');
+          }
+      } else {
+          $notification->push(_("Alias saved."), 'horde.success');
+          $url = Util::addParameter(Horde::applicationUrl('users/index.php'), 'domain_id', $domain['id'], false);
+          header('Location: ' . $url);
+          exit;
+      }
+  }
+} // if
+
+/* Check if a form is being edited. */
+if (!$vars->exists('mode') || $vars->getExists('retry')) {
+  Horde::logMessage("No-Submit Detected: " . print_r(serialize($vars), true), __FILE__, __LINE__, PEAR_LOG_DEBUG);
+    if ($vars->exists("alias")) {
+        $alias = $vars->get("alias");
+        Horde::logMessage("Alias Detected: $alias", __FILE__, __LINE__, PEAR_LOG_DEBUG);
+
+        $addrInfo = $vilma_driver->getAddressInfo($alias,'alias');
+        Horde::logMessage("addrInfo contains: " . print_r($addrInfo, true), __FILE__, __LINE__, PEAR_LOG_DEBUG);
+        if (is_a($addrInfo, 'PEAR_Error')) {
+            $notification->push(sprintf(_("Error reading address information from backend: %s"), $addrInfo->getMessage()), 'horde.error');
+            $url = '/users/index.php';
+            require VILMA_BASE . $url; 
+            exit;
+        }
+        $address = $vilma_driver->getAddressInfo($addrInfo['destination']);
+        Horde::logMessage("address Info contains: " . print_r($address, true), __FILE__, __LINE__, PEAR_LOG_DEBUG);
+        $vars = new Variables($address);
+        $vars->set('mode', 'edit');
+        $vars->add('alias_address', $alias);
+        $vars->add('alias', $alias);
+        $vars->add('address', $address['address']);
+    } elseif ($vars->exists("address")) {
+        $tmp_address = $vars->get("address");
+        Horde::logMessage("Address Detected: $tmp_address", __FILE__, __LINE__, PEAR_LOG_DEBUG);
+
+        $address = $vilma_driver->getAddressInfo($tmp_address, 'all');
+        Horde::logMessage("addrInfo contains: " . print_r($addrInfo, true), __FILE__, __LINE__, PEAR_LOG_DEBUG);
+        $vars = new Variables($address);
+        $vars->set('mode', 'new');
+    }
+
+    $form = &new EditAliasForm($vars);
+/*
+    if ($form->validate($vars)) {
+        $form->getInfo($vars, $info);
+        $alias_id = $vilma_driver->saveAlias($info);
+        if (is_a($alias_id, 'PEAR_Error')) {
+            Horde::logMessage($user_id, __FILE__, __LINE__, PEAR_LOG_ERR);
+            $notification->push(sprintf(_("Error saving alias. %s"), $alias_id->getMessage()), 'horde.error');
+        } else {
+            $notification->push(_("Alias saved."), 'horde.success');
+        }
+    }
+*/
+}
+
+
+/* Render the form. */
+require_once 'Horde/Form/Renderer.php';
+$renderer = &new Horde_Form_Renderer();
+
+$main = Util::bufferOutput(array($form, 'renderActive'), $renderer, $vars, 'editAlias.php', 'post');
+
+$template->set('main', $main);
+$template->set('menu', Vilma::getMenu('string'));
+$template->set('notify', Util::bufferOutput(array($notification, 'notify'), array('listeners' => 'status')));
+
+require VILMA_TEMPLATES . '/common-header.inc';
+echo $template->fetch(VILMA_TEMPLATES . '/main/main.html');
+require $registry->get('templates', 'horde') . '/common-footer.inc';
diff --git a/vilma/users/editForward.php b/vilma/users/editForward.php
new file mode 100644 (file)
index 0000000..8fc0d28
--- /dev/null
@@ -0,0 +1,114 @@
+<?php
+/**
+ * The Vilma script to add/edit forwardes.
+ *
+ * $Horde: vilma/users/edit.php,v 1.42 2009/05/27 23:57:33 daniel Exp $
+ *
+ * Copyright 2003-2009 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file LICENSE for license information (BSD). If you did
+ * did not receive this file, see http://cvs.horde.org/co.php/vilma/LICENSE.
+ *
+ * @author Daniel Collins <horde_dev@argentproductions.com>
+ */
+
+@define('VILMA_BASE', dirname(__FILE__) . '/..');
+require_once VILMA_BASE . '/lib/base.php';
+require_once 'Horde/Form.php';
+require_once 'Horde/Variables.php';
+
+require_once VILMA_BASE . '/lib/Forms/EditForwardForm.php';
+
+/* Only admin should be using this. */
+if (!Vilma::hasPermission($domain)) {
+    Horde::authenticationFailureRedirect();
+}
+$vars = Variables::getDefaultVariables();
+
+/* If the form is submitted, $vars['mode'] will be set. Catch this and process the submission so that the displayed form accurately indicates the result of the transaction. */
+if ($vars->exists('mode')) {
+  Horde::logMessage("Submit Detected: " . print_r(serialize($vars), true), __FILE__, __LINE__, PEAR_LOG_DEBUG);
+  $form = &new EditForwardForm($vars);
+  if ($form->validate($vars)) {
+      $form->getInfo($vars, $info);
+      $forward_id = $vilma_driver->saveForward($info);
+      if (is_a($forward_id, 'PEAR_Error')) {
+          Horde::logMessage($user_id, __FILE__, __LINE__, PEAR_LOG_ERR);
+          $notification->push(sprintf(_("Error saving forward. %s"), $forward_id->getMessage()), 'horde.error');
+          // remove the mode, and rearrange the forward information to clean up the form.
+          $vars->remove('mode');
+          $vars->add('retry', true);
+          if ($vars->exists('forward')) {
+            $vars->remove('forward_address');
+          } elseif ($vars->exists('address')) {
+            $vars->remove('forward_address');
+            $vars->remove('forward');
+          }
+      } else {
+          $notification->push(_("forward saved."), 'horde.success');
+      }
+  }
+} // if
+
+/* Check if a form is being edited. */
+if (!$vars->exists('mode') || $vars->getExists('retry')) {
+  Horde::logMessage("No-Submit Detected: " . print_r(serialize($vars), true), __FILE__, __LINE__, PEAR_LOG_DEBUG);
+    if ($vars->exists("forward")) {
+        $forward = $vars->get("forward");
+        Horde::logMessage("Forward Detected: $forward", __FILE__, __LINE__, PEAR_LOG_DEBUG);
+
+        $addrInfo = $vilma_driver->getAddressInfo($forward,'forward');
+        Horde::logMessage("addrInfo contains: " . print_r($addrInfo, true), __FILE__, __LINE__, PEAR_LOG_DEBUG);
+        if (is_a($addrInfo, 'PEAR_Error')) {
+            $notification->push(sprintf(_("Error reading address information from backend: %s"), $addrInfo->getMessage()), 'horde.error');
+            $url = '/users/index.php';
+            require VILMA_BASE . $url; 
+            exit;
+        }
+        $address = $vilma_driver->getAddressInfo($addrInfo['destination']);
+        Horde::logMessage("address Info contains: " . print_r($address, true), __FILE__, __LINE__, PEAR_LOG_DEBUG);
+        $vars = new Variables($address);
+        $vars->set('mode', 'edit');
+        $vars->add('forward_address', $forward);
+        $vars->add('forward', $forward);
+        $vars->add('address', $address['address']);
+    } elseif ($vars->exists("address")) {
+        $tmp_address = $vars->get("address");
+        Horde::logMessage("Address Detected: $tmp_address", __FILE__, __LINE__, PEAR_LOG_DEBUG);
+
+        $address = $vilma_driver->getAddressInfo($tmp_address, 'all');
+        Horde::logMessage("addrInfo contains: " . print_r($addrInfo, true), __FILE__, __LINE__, PEAR_LOG_DEBUG);
+        $vars = new Variables($address);
+        $vars->set('mode', 'new');
+    }
+
+    $form = &new EditforwardForm($vars);
+/*
+    if ($form->validate($vars)) {
+        $form->getInfo($vars, $info);
+        $forward_id = $vilma_driver->saveforward($info);
+        if (is_a($forward_id, 'PEAR_Error')) {
+            Horde::logMessage($user_id, __FILE__, __LINE__, PEAR_LOG_ERR);
+            $notification->push(sprintf(_("Error saving forward. %s"), $forward_id->getMessage()), 'horde.error');
+        } else {
+            $notification->push(_("forward saved."), 'horde.success');
+        }
+    }
+*/
+}
+
+
+/* Render the form. */
+require_once 'Horde/Form/Renderer.php';
+$renderer = &new Horde_Form_Renderer();
+
+$main = Util::bufferOutput(array($form, 'renderActive'), $renderer, $vars, 'editForward.php', 'post');
+
+$template->set('main', $main);
+$template->set('menu', Vilma::getMenu('string'));
+$template->set('notify', Util::bufferOutput(array($notification, 'notify'), array('listeners' => 'status')));
+
+require VILMA_TEMPLATES . '/common-header.inc';
+echo $template->fetch(VILMA_TEMPLATES . '/main/main.html');
+require $registry->get('templates', 'horde') . '/common-footer.inc';