Fix domain detection.
authorJan Schneider <jan@horde.org>
Wed, 8 Dec 2010 18:16:05 +0000 (19:16 +0100)
committerJan Schneider <jan@horde.org>
Wed, 8 Dec 2010 18:16:05 +0000 (19:16 +0100)
vilma/lib/Application.php
vilma/lib/Vilma.php

index f7dd28f..60cd0c3 100644 (file)
@@ -45,8 +45,21 @@ class Vilma_Application extends Horde_Registry_Application
         $this->driver = Vilma_Driver::singleton();
 
         // Get the currently active domain, possibly storing a change into the
-        // session
-        $this->curdomain = Vilma::getCurDomain();
+        // session.
+        // Domain is passed in by ID, which may or may not be the
+        // the same as the actual DNS domain name.
+        $domain_id = Horde_Util::getFormData('domain_id');
+
+        if (!empty($domain_id)) {
+            $domain = $this->driver->getDomain($domain_id);
+            if (!is_a($domain, 'PEAR_Error') &&
+                !empty($domain['domain_name'])) {
+                $this->curdomain = $domain;
+                Vilma::setCurDomain($domain);
+            }
+        } elseif ($domain = $GLOBALS['session']->get('vilma', 'domain')) {
+            $this->curdomain = $domain;
+        }
     }
 
     public function perms()
index f824e33..f19bdb0 100644 (file)
@@ -84,35 +84,6 @@ class Vilma
     }
 
     /**
-     * Attempt to determine the current domain name based on current user or
-     * a domain_id passed in by form.
-     *
-     * @return mixed string domain on success, false on failure, PEAR::Error on error
-     */
-    function getCurDomain()
-    {
-        // Domain is passed in by ID, which may or may not be the
-        // the same as the actual DNS domain name
-        $domain_id = Horde_Util::getFormData('domain_id');
-
-        if (!empty($domain_id)) {
-            // FIXME: Make sure this only runs once per page-load
-            $domain = $GLOBALS['vilma_driver']->getDomain($domain_id);
-            if (is_a($domain, 'PEAR_Error')) {
-                return $domain;
-            }
-            if (empty($domain['domain_name'])) {
-                $domain = false;
-            }
-            Vilma::setCurDomain($domain);
-        } elseif (!($domain = $GLOBALS['session']->get('vilma', 'domain'))) {
-            $domain = false;
-        }
-
-        return $domain;
-    }
-
-    /**
      * Set the current domain
      */
     function setCurDomain($domain)
@@ -169,7 +140,7 @@ class Vilma
 
         $menu->add(Horde::url('domains/index.php'), _("_Domains"), 'domain.png');
 
-        if (Vilma::getCurDomain()) {
+        if ($GLOBALS['vilma']->curdomain) {
             $domain = $GLOBALS['session']->get('vilma', 'domain');
             $url = Horde::url('users/index.php');
             $tmp = Horde_Util::addParameter($url, 'domain_id', $domain['domain_id']);