Index: branches/2.0singleton/lib/App.inc.php
===================================================================
--- branches/2.0singleton/lib/App.inc.php	(revision 132)
+++ branches/2.0singleton/lib/App.inc.php	(revision 135)
@@ -7,5 +7,5 @@
  *
  * @author  Quinn Comendant <quinn@strangecode.com>
- * @version 2.0
+ * @version 2.1
  */
 
@@ -22,6 +22,6 @@
 class App {
 
-    // Name of this application.
-    var $app = '_app_';
+    // Namespace of this application instance.
+    var $ns;
 
     // If $app->start has run successfully.
@@ -34,5 +34,5 @@
     var $_carry_queries = array();
 
-    // Hash of global application parameters.
+    // Dictionary of global application parameters.
     var $_params = array();
 
@@ -99,5 +99,5 @@
 
         // General application log.
-        'log_filename' => 'app_error_log',
+        'log_filename' => 'app_log',
 
         // Logging priority can be any of the following, or false to deactivate:
@@ -128,14 +128,15 @@
      * This method enforces the singleton pattern for this class. Only one application is running at a time.
      *
-     * @return  object  Reference to the global SessionCache object.
+     * $param   string  $namespace  Name of this application.
+     * @return  object  Reference to the global Cache object.
      * @access  public
      * @static
      */
-    function &getInstance($app=null)
+    function &getInstance($namespace='')
     {
         static $instance = null;
 
         if ($instance === null) {
-            $instance = new App($app);
+            $instance = new App($namespace);
         }
 
@@ -146,9 +147,8 @@
      * Constructor.
      */
-    function App($app=null)
-    {
-        if (isset($app)) {
-            $this->app .= $app;
-        }
+    function App($namespace='')
+    {
+        // Set namespace of application instance.
+        $this->ns = '_app_' . $namespace;
 
         // Initialize default parameters.
@@ -164,11 +164,7 @@
     function setParam($param=null)
     {
-        if (!isset($_this) || !is_a($_this, 'App') && !is_subclass_of($_this, 'App')) {
-            $_this =& App::getInstance();
-        }
-
         if (isset($param) && is_array($param)) {
             // Merge new parameters with old overriding only those passed.
-            $_this->_params = array_merge($_this->_params, $param);
+            $this->_params = array_merge($this->_params, $param);
         }
     }
@@ -181,14 +177,10 @@
      * @return  mixed               Parameter value, or null if not existing.
      */
-    function &getParam($param=null)
-    {
-        if (!isset($_this) || !is_a($_this, 'App') && !is_subclass_of($_this, 'App')) {
-            $_this =& App::getInstance();
-        }
-
+    function getParam($param=null)
+    {
         if ($param === null) {
-            return $_this->_params;
-        } else if (isset($_this->_params[$param])) {
-            return $_this->_params[$param];
+            return $this->_params;
+        } else if (isset($this->_params[$param])) {
+            return $this->_params[$param];
         } else {
             trigger_error(sprintf('Parameter is not set: %s', $param), E_USER_NOTICE);
@@ -239,9 +231,7 @@
             }
 
-            // The only instance of the DB object.
+            // There will ever only be one instance of the DB object, and here is where it is instantiated.
             require_once dirname(__FILE__) . '/DB.inc.php';
-
             $this->db =& DB::getInstance();
-
             $this->db->setParam(array(
                 'db_server' => $this->getParam('db_server'),
@@ -270,10 +260,4 @@
         if (true === $this->getParam('enable_session')) {
 
-            // Set the session ID to one provided in GET/POST. This is necessary for linking
-            // between domains and keeping the same session.
-            if ($ses = getFormData($this->getParam('session_name'), false)) {
-                session_id($ses);
-            }
-
             if (true === $this->getParam('enable_db_session_handler') && true === $this->getParam('enable_db')) {
                 // Database session handling.
@@ -295,8 +279,8 @@
             session_start();
 
-            if (!isset($_SESSION[$this->app])) {
+            if (!isset($_SESSION[$this->ns])) {
                 // Access session data using: $_SESSION['...'].
                 // Initialize here _after_ session has started.
-                $_SESSION[$this->app] = array(
+                $_SESSION[$this->ns] = array(
                     'messages' => array(),
                     'boomerang' => array('url'),
@@ -360,12 +344,8 @@
     function raiseMsg($message, $type=MSG_NOTICE, $file=null, $line=null)
     {
-        if (!isset($_this) || !is_a($_this, 'App') && !is_subclass_of($_this, 'App')) {
-            $_this =& App::getInstance();
-        }
-
         $message = trim($message);
 
-        if (!$_this->running || '' == $message) {
-            $_this->logMsg(sprintf('Canceled method call %s, application not running or message is an empty string.', __FUNCTION__), LOG_DEBUG, __FILE__, __LINE__);
+        if (!$this->running || '' == $message) {
+            $this->logMsg(sprintf('Canceled method call %s, application not running or message is an empty string.', __FUNCTION__), LOG_NOTICE, __FILE__, __LINE__);
             return false;
         }
@@ -373,14 +353,14 @@
         // Save message in session under unique key to avoid duplicate messages.
         $msg_id = md5($type . $message . $file . $line);
-        $_SESSION[$_this->app]['messages'][$msg_id] = array(
+        $_SESSION[$this->ns]['messages'][$msg_id] = array(
             'type'    => $type,
             'message' => $message,
             'file'    => $file,
             'line'    => $line,
-            'count'   => (isset($_SESSION[$_this->app]['messages'][$msg_id]['count']) ? (1 + $_SESSION[$_this->app]['messages'][$msg_id]['count']) : 1)
+            'count'   => (isset($_SESSION[$this->ns]['messages'][$msg_id]['count']) ? (1 + $_SESSION[$this->ns]['messages'][$msg_id]['count']) : 1)
         );
 
         if (!in_array($type, array(MSG_NOTICE, MSG_SUCCESS, MSG_WARNING, MSG_ERR))) {
-            $_this->logMsg(sprintf('Invalid MSG_* type: %s', $type), LOG_DEBUG, __FILE__, __LINE__);
+            $this->logMsg(sprintf('Invalid MSG_* type: %s', $type), LOG_NOTICE, __FILE__, __LINE__);
         }
     }
@@ -396,15 +376,11 @@
     function getRaisedMessages()
     {
-        if (!isset($_this) || !is_a($_this, 'App') && !is_subclass_of($_this, 'App')) {
-            $_this =& App::getInstance();
-        }
-
-        if (!$_this->running) {
-            $_this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_DEBUG, __FILE__, __LINE__);
+        if (!$this->running) {
+            $this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_NOTICE, __FILE__, __LINE__);
             return false;
         }
         
         $output = array();
-        while (isset($_SESSION[$_this->app]['messages']) && $message = array_shift($_SESSION[$_this->app]['messages'])) {
+        while (isset($_SESSION[$this->ns]['messages']) && $message = array_shift($_SESSION[$this->ns]['messages'])) {
             $output[] = $message;
         }
@@ -421,14 +397,10 @@
     function clearRaisedMessages()
     {
-        if (!isset($_this) || !is_a($_this, 'App') && !is_subclass_of($_this, 'App')) {
-            $_this =& App::getInstance();
-        }
-
-        if (!$_this->running) {
-            $_this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_DEBUG, __FILE__, __LINE__);
+        if (!$this->running) {
+            $this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_NOTICE, __FILE__, __LINE__);
             return false;
         }
         
-        $_SESSION[$_this->app]['messages'] = array();
+        $_SESSION[$this->ns]['messages'] = array();
     }
 
@@ -442,16 +414,12 @@
     function printRaisedMessages()
     {
-        if (!isset($_this) || !is_a($_this, 'App') && !is_subclass_of($_this, 'App')) {
-            $_this =& App::getInstance();
-        }
-
-        if (!$_this->running) {
-            $_this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_DEBUG, __FILE__, __LINE__);
-            return false;
-        }
-
-        while (isset($_SESSION[$_this->app]['messages']) && $message = array_shift($_SESSION[$_this->app]['messages'])) {
+        if (!$this->running) {
+            $this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_NOTICE, __FILE__, __LINE__);
+            return false;
+        }
+
+        while (isset($_SESSION[$this->ns]['messages']) && $message = array_shift($_SESSION[$this->ns]['messages'])) {
             ?><div class="sc-msg"><?php
-            if (error_reporting() > 0 && $_this->getParam('display_errors')) {
+            if (error_reporting() > 0 && $this->getParam('display_errors')) {
                 echo "\n<!-- [" . $message['file'] . ' : ' . $message['line'] . '] -->';
             }
@@ -501,19 +469,15 @@
         static $previous_events = array();
 
-        if (!isset($_this) || !is_a($_this, 'App') && !is_subclass_of($_this, 'App')) {
-            $_this =& App::getInstance();
-        }
-
         // If priority is not specified, assume the worst.
-        if (!$_this->logPriorityToString($priority)) {
-            $_this->logMsg(sprintf('Log priority %s not defined. (Message: %s)', $priority, $message), LOG_EMERG, $file, $line);
+        if (!$this->logPriorityToString($priority)) {
+            $this->logMsg(sprintf('Log priority %s not defined. (Message: %s)', $priority, $message), LOG_EMERG, $file, $line);
             $priority = LOG_EMERG;
         }
 
         // If log file is not specified, don't log to a file.
-        if (!$_this->getParam('log_directory') || !$_this->getParam('log_filename') || !is_dir($_this->getParam('log_directory')) || !is_writable($_this->getParam('log_directory'))) {
-            $_this->setParam(array('log_file_priority' => false));
+        if (!$this->getParam('log_directory') || !$this->getParam('log_filename') || !is_dir($this->getParam('log_directory')) || !is_writable($this->getParam('log_directory'))) {
+            $this->setParam(array('log_file_priority' => false));
             // We must use trigger_error to report this problem rather than calling $app->logMsg, which might lead to an infinite loop.
-            trigger_error(sprintf('Codebase error: log directory (%s) not found or writable.', $_this->getParam('log_directory')), E_USER_NOTICE);
+            trigger_error(sprintf('Codebase error: log directory (%s) not found or writable.', $this->getParam('log_directory')), E_USER_NOTICE);
         }
 
@@ -531,5 +495,5 @@
             $previous_events[$msg_id]++;
             if ($previous_events[$msg_id] == 2) {
-                $_this->logMsg(sprintf('%s (Event repeated %s or more times)', $message, $previous_events[$msg_id]), $priority, $file, $line);
+                $this->logMsg(sprintf('%s (Event repeated %s or more times)', $message, $previous_events[$msg_id]), $priority, $file, $line);
             }
             return false;
@@ -543,5 +507,5 @@
             'remote ip' => getRemoteAddr(),
             'pid'       => (substr(PHP_OS, 0, 3) != 'WIN' ? posix_getpid() : ''),
-            'type'      => $_this->logPriorityToString($priority),
+            'type'      => $this->logPriorityToString($priority),
             'file:line' => "$file : $line",
             'url'       => (isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : ''),
@@ -550,11 +514,11 @@
 
         // FILE ACTION
-        if ($_this->getParam('log_file_priority') && $priority <= $_this->getParam('log_file_priority')) {
+        if ($this->getParam('log_file_priority') && $priority <= $this->getParam('log_file_priority')) {
             $event_str = '[' . join('] [', $event) . ']';
-            error_log($event_str . "\n", 3, $_this->getParam('log_directory') . '/' . $_this->getParam('log_filename'));
+            error_log($event_str . "\n", 3, $this->getParam('log_directory') . '/' . $this->getParam('log_filename'));
         }
 
         // EMAIL ACTION
-        if ($_this->getParam('log_email_priority') && $priority <= $_this->getParam('log_email_priority')) {
+        if ($this->getParam('log_email_priority') && $priority <= $this->getParam('log_email_priority')) {
             $subject = sprintf('[%s %s] %s', getenv('HTTP_HOST'), $event['type'], $message);
             $email_msg = sprintf("A %s log event occured on %s\n\n", $event['type'], getenv('HTTP_HOST'));
@@ -563,17 +527,17 @@
                 $email_msg .= sprintf("%-11s%s\n", $k, $v);
             }
-            mail($_this->getParam('log_to_email_address'), $subject, $email_msg, $headers, '-f codebase@strangecode.com');
+            mail($this->getParam('log_to_email_address'), $subject, $email_msg, $headers, '-f codebase@strangecode.com');
         }
 
         // SMS ACTION
-        if ($_this->getParam('log_sms_priority') && $priority <= $_this->getParam('log_sms_priority')) {
+        if ($this->getParam('log_sms_priority') && $priority <= $this->getParam('log_sms_priority')) {
             $subject = sprintf('[%s %s]', getenv('HTTP_HOST'), $priority);
             $sms_msg = sprintf('%s [%s:%s]', $event['message'], basename($file), $line);
             $headers = "From: codebase@strangecode.com";
-            mail($_this->getParam('log_to_sms_address'), $subject, $sms_msg, $headers, '-f codebase@strangecode.com');
+            mail($this->getParam('log_to_sms_address'), $subject, $sms_msg, $headers, '-f codebase@strangecode.com');
         }
 
         // SCREEN ACTION
-        if ($_this->getParam('log_screen_priority') && $priority <= $_this->getParam('log_screen_priority')) {
+        if ($this->getParam('log_screen_priority') && $priority <= $this->getParam('log_screen_priority')) {
             echo "[{$event['date']}] [{$event['type']}] [{$event['file:line']}] [{$event['message']}]\n";
         }
@@ -620,12 +584,8 @@
     function carryQuery($query_key)
     {
-        if (!isset($_this) || !is_a($_this, 'App') && !is_subclass_of($_this, 'App')) {
-            $_this =& App::getInstance();
-        }
-
         // If not already set, and there is a non-empty value provided in the request...
-        if (!isset($_this->_carry_queries[$query_key]) && getFormData($query_key, false)) {
+        if (!isset($this->_carry_queries[$query_key]) && getFormData($query_key, false)) {
             // Copy the value of the specified query argument into the _carry_queries array.
-            $_this->_carry_queries[$query_key] = getFormData($query_key);
+            $this->_carry_queries[$query_key] = getFormData($query_key);
         }
     }
@@ -652,10 +612,6 @@
     function url($url, $carry_args=null, $always_include_sid=false)
     {
-        if (!isset($_this) || !is_a($_this, 'App') && !is_subclass_of($_this, 'App')) {
-            $_this =& App::getInstance();
-        }
-
-        if (!$_this->running) {
-            $_this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_DEBUG, __FILE__, __LINE__);
+        if (!$this->running) {
+            $this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_NOTICE, __FILE__, __LINE__);
             return false;
         }
@@ -691,5 +647,5 @@
         if ($do_carry_queries) {
             // Join the global _carry_queries and local one_time_carry_queries.
-            $query_args = urlEncodeArray(array_merge($_this->_carry_queries, $one_time_carry_queries));
+            $query_args = urlEncodeArray(array_merge($this->_carry_queries, $one_time_carry_queries));
             foreach ($query_args as $key=>$val) {
                 // Check value is set and value does not already exist in the url.
@@ -715,7 +671,7 @@
                     (
                         !isset($_COOKIE[session_name()])
-                        || !$_this->getParam('session_use_cookies')
+                        || !$this->getParam('session_use_cookies')
                     )
-                    && $_this->getParam('enable_session')
+                    && $this->getParam('enable_session')
                     && isMyDomain($url)
                     &&
@@ -748,9 +704,5 @@
     function oHREF($url, $carry_args=null, $always_include_sid=false)
     {
-        if (!isset($_this) || !is_a($_this, 'App') && !is_subclass_of($_this, 'App')) {
-            $_this =& App::getInstance();
-        }
-
-        $url = $_this->url($url, $carry_args, $always_include_sid);
+        $url = $this->url($url, $carry_args, $always_include_sid);
 
         // Replace any & not followed by an html or unicode entity with it's &amp; equivalent.
@@ -772,10 +724,6 @@
     function printHiddenSession($carry_args=null)
     {
-        if (!isset($_this) || !is_a($_this, 'App') && !is_subclass_of($_this, 'App')) {
-            $_this =& App::getInstance();
-        }
-
-        if (!$_this->running) {
-            $_this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_DEBUG, __FILE__, __LINE__);
+        if (!$this->running) {
+            $this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_NOTICE, __FILE__, __LINE__);
             return false;
         }
@@ -808,7 +756,7 @@
             // Join the global _carry_queries and local one_time_carry_queries.
             // urlencode is not used here, not for form data!
-            $query_args = array_merge($_this->_carry_queries, $one_time_carry_queries);
+            $query_args = array_merge($this->_carry_queries, $one_time_carry_queries);
             foreach ($query_args as $key=>$val) {
-                echo '<input type="hidden" name="' . $key . '" value="' . $val . '" />';
+                printf('<input type="hidden" name="%s" value="%s" />', $key, $val);
             }
         }
@@ -816,5 +764,5 @@
         // Include the SID if cookies are disabled.
         if (!isset($_COOKIE[session_name()]) && !ini_get('session.use_trans_sid')) {
-            echo '<input type="hidden" name="' . session_name() . '" value="' . session_id() . '" />';
+            printf('<input type="hidden" name="%s" value="%s" />', session_name(), session_id());
         }
     }
@@ -829,5 +777,5 @@
      *                                          or FALSE to prevent carrying queries. Can be any of the following formats:
      *                                          -array('key1', key2', key3')  <-- to save these keys if in the form data.
-     *                                          -array('key1'=>'value', key2'='value')  <-- to set keys to default values if not present in form data.
+     *                                          -array('key1' => 'value', key2' => 'value')  <-- to set keys to default values if not present in form data.
      *                                          -false  <-- To not carry any queries. If URL already has queries those will be retained.
      * @param   bool    $always_include_sid     Force session id to be added to Location header.
@@ -835,10 +783,6 @@
     function dieURL($url, $carry_args=null, $always_include_sid=false)
     {
-        if (!isset($_this) || !is_a($_this, 'App') && !is_subclass_of($_this, 'App')) {
-            $_this =& App::getInstance();
-        }
-
-        if (!$_this->running) {
-            $_this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_DEBUG, __FILE__, __LINE__);
+        if (!$this->running) {
+            $this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_NOTICE, __FILE__, __LINE__);
             return false;
         }
@@ -846,5 +790,5 @@
         if ('' == $url) {
             // If URL is not specified, use the redirect_home_url.
-            $url = $_this->getParam('redirect_home_url');
+            $url = $this->getParam('redirect_home_url');
         }
 
@@ -856,12 +800,12 @@
         }
 
-        $url = $_this->url($url, $carry_args, $always_include_sid);
+        $url = $this->url($url, $carry_args, $always_include_sid);
 
         header(sprintf('Location: %s', $url));
-        $_this->logMsg(sprintf('dieURL: %s', $url), LOG_DEBUG, __FILE__, __LINE__);
+        $this->logMsg(sprintf('dieURL: %s', $url), LOG_DEBUG, __FILE__, __LINE__);
 
         // End this application.
         // Recommended, although I'm not sure it's necessary: http://cn2.php.net/session_write_close
-        $_this->stop();
+        $this->stop();
         die;
     }
@@ -884,24 +828,20 @@
     function dieBoomerangURL($id=null, $carry_args=null, $default_url=null)
     {
-        if (!isset($_this) || !is_a($_this, 'App') && !is_subclass_of($_this, 'App')) {
-            $_this =& App::getInstance();
-        }
-
-        if (!$_this->running) {
-            $_this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_DEBUG, __FILE__, __LINE__);
+        if (!$this->running) {
+            $this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_NOTICE, __FILE__, __LINE__);
             return false;
         }
 
         // Get URL from stored boomerang. Allow non specific URL if ID not valid.
-        if ($_this->validBoomerangURL($id, true)) {
-            if (isset($id) && isset($_SESSION[$_this->app]['boomerang']['url'][$id])) {
-                $url = $_SESSION[$_this->app]['boomerang']['url'][$id];
-                $_this->logMsg(sprintf('dieBoomerangURL(%s) found: %s', $id, $url), LOG_DEBUG, __FILE__, __LINE__);
+        if ($this->validBoomerangURL($id, true)) {
+            if (isset($id) && isset($_SESSION[$this->ns]['boomerang']['url'][$id])) {
+                $url = $_SESSION[$this->ns]['boomerang']['url'][$id];
+                $this->logMsg(sprintf('dieBoomerangURL(%s) found: %s', $id, $url), LOG_DEBUG, __FILE__, __LINE__);
             } else {
-                $url = end($_SESSION[$_this->app]['boomerang']['url']);
-                $_this->logMsg(sprintf('dieBoomerangURL(%s) using: %s', $id, $url), LOG_DEBUG, __FILE__, __LINE__);
+                $url = end($_SESSION[$this->ns]['boomerang']['url']);
+                $this->logMsg(sprintf('dieBoomerangURL(%s) using: %s', $id, $url), LOG_DEBUG, __FILE__, __LINE__);
             }
             // Delete stored boomerang.
-            $_this->deleteBoomerangURL($id);
+            $this->deleteBoomerangURL($id);
         } else if (isset($default_url)) {
             $url = $default_url;
@@ -909,15 +849,15 @@
             // Ensure that the redirecting page is not also the referrer.
             $url = getenv('HTTP_REFERER');
-            $_this->logMsg(sprintf('dieBoomerangURL(%s) using referrer: %s', $id, $url), LOG_DEBUG, __FILE__, __LINE__);
+            $this->logMsg(sprintf('dieBoomerangURL(%s) using referrer: %s', $id, $url), LOG_DEBUG, __FILE__, __LINE__);
         } else {
             // If URL is not specified, use the redirect_home_url.
-            $url = $_this->getParam('redirect_home_url');
-            $_this->logMsg(sprintf('dieBoomerangURL(%s) not found, using redirect_home_url: %s', $id, $url), LOG_DEBUG, __FILE__, __LINE__);
+            $url = $this->getParam('redirect_home_url');
+            $this->logMsg(sprintf('dieBoomerangURL(%s) not found, using redirect_home_url: %s', $id, $url), LOG_DEBUG, __FILE__, __LINE__);
         }
 
         // A redirection will never happen immediately twice.
         // Set the time so ensure this doesn't happen.
-        $_SESSION[$_this->app]['boomerang']['time'] = time();
-        $_this->dieURL($url, $carry_args);
+        $_SESSION[$this->ns]['boomerang']['time'] = time();
+        $this->dieURL($url, $carry_args);
     }
 
@@ -931,10 +871,6 @@
     function setBoomerangURL($url=null, $id=null)
     {
-        if (!isset($_this) || !is_a($_this, 'App') && !is_subclass_of($_this, 'App')) {
-            $_this =& App::getInstance();
-        }
-
-        if (!$_this->running) {
-            $_this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_DEBUG, __FILE__, __LINE__);
+        if (!$this->running) {
+            $this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_NOTICE, __FILE__, __LINE__);
             return false;
         }
@@ -946,20 +882,20 @@
             $url = preg_replace('/boomerang=[\w]+/', '', $url);
 
-            if (isset($_SESSION[$_this->app]['boomerang']['url']) && is_array($_SESSION[$_this->app]['boomerang']['url']) && !empty($_SESSION[$_this->app]['boomerang']['url'])) {
+            if (isset($_SESSION[$this->ns]['boomerang']['url']) && is_array($_SESSION[$this->ns]['boomerang']['url']) && !empty($_SESSION[$this->ns]['boomerang']['url'])) {
                 // If the URL currently exists in the boomerang array, delete.
-                while ($existing_key = array_search($url, $_SESSION[$_this->app]['boomerang']['url'])) {
-                    unset($_SESSION[$_this->app]['boomerang']['url'][$existing_key]);
+                while ($existing_key = array_search($url, $_SESSION[$this->ns]['boomerang']['url'])) {
+                    unset($_SESSION[$this->ns]['boomerang']['url'][$existing_key]);
                 }
             }
 
             if (isset($id)) {
-                $_SESSION[$_this->app]['boomerang']['url'][$id] = $url;
+                $_SESSION[$this->ns]['boomerang']['url'][$id] = $url;
             } else {
-                $_SESSION[$_this->app]['boomerang']['url'][] = $url;
-            }
-            $_this->logMsg(sprintf('setBoomerangURL(%s): %s', $id, $url), LOG_DEBUG, __FILE__, __LINE__);
+                $_SESSION[$this->ns]['boomerang']['url'][] = $url;
+            }
+            $this->logMsg(sprintf('setBoomerangURL(%s): %s', $id, $url), LOG_DEBUG, __FILE__, __LINE__);
             return true;
         } else {
-            $_this->logMsg(sprintf('setBoomerangURL(%s) is empty!', $id, $url), LOG_NOTICE, __FILE__, __LINE__);
+            $this->logMsg(sprintf('setBoomerangURL(%s) is empty!', $id, $url), LOG_NOTICE, __FILE__, __LINE__);
             return false;
         }
@@ -973,21 +909,17 @@
     function getBoomerangURL($id=null)
     {
-        if (!isset($_this) || !is_a($_this, 'App') && !is_subclass_of($_this, 'App')) {
-            $_this =& App::getInstance();
-        }
-
-        if (!$_this->running) {
-            $_this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_DEBUG, __FILE__, __LINE__);
+        if (!$this->running) {
+            $this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_NOTICE, __FILE__, __LINE__);
             return false;
         }
 
         if (isset($id)) {
-            if (isset($_SESSION[$_this->app]['boomerang']['url'][$id])) {
-                return $_SESSION[$_this->app]['boomerang']['url'][$id];
+            if (isset($_SESSION[$this->ns]['boomerang']['url'][$id])) {
+                return $_SESSION[$this->ns]['boomerang']['url'][$id];
             } else {
                 return '';
             }
-        } else if (is_array($_SESSION[$_this->app]['boomerang']['url'])) {
-            return end($_SESSION[$_this->app]['boomerang']['url']);
+        } else if (is_array($_SESSION[$this->ns]['boomerang']['url'])) {
+            return end($_SESSION[$this->ns]['boomerang']['url']);
         } else {
             return false;
@@ -1002,19 +934,15 @@
     function deleteBoomerangURL($id=null)
     {
-        if (!isset($_this) || !is_a($_this, 'App') && !is_subclass_of($_this, 'App')) {
-            $_this =& App::getInstance();
-        }
-
-        if (!$_this->running) {
-            $_this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_DEBUG, __FILE__, __LINE__);
-            return false;
-        }
-
-        $_this->logMsg(sprintf('deleteBoomerangURL(%s): %s', $id, $_this->getBoomerangURL($id)), LOG_DEBUG, __FILE__, __LINE__);
-
-        if (isset($id) && isset($_SESSION[$_this->app]['boomerang']['url'][$id])) {
-            unset($_SESSION[$_this->app]['boomerang']['url'][$id]);
-        } else if (is_array($_SESSION[$_this->app]['boomerang']['url'])) {
-            array_pop($_SESSION[$_this->app]['boomerang']['url']);
+        if (!$this->running) {
+            $this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_NOTICE, __FILE__, __LINE__);
+            return false;
+        }
+
+        $this->logMsg(sprintf('deleteBoomerangURL(%s): %s', $id, $this->getBoomerangURL($id)), LOG_DEBUG, __FILE__, __LINE__);
+
+        if (isset($id) && isset($_SESSION[$this->ns]['boomerang']['url'][$id])) {
+            unset($_SESSION[$this->ns]['boomerang']['url'][$id]);
+        } else if (is_array($_SESSION[$this->ns]['boomerang']['url'])) {
+            array_pop($_SESSION[$this->ns]['boomerang']['url']);
         }
     }
@@ -1028,15 +956,11 @@
     function validBoomerangURL($id=null, $use_nonspecificboomerang=false)
     {
-        if (!isset($_this) || !is_a($_this, 'App') && !is_subclass_of($_this, 'App')) {
-            $_this =& App::getInstance();
-        }
-
-        if (!$_this->running) {
-            $_this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_DEBUG, __FILE__, __LINE__);
-            return false;
-        }
-
-        if (!isset($_SESSION[$_this->app]['boomerang']['url'])) {
-            $_this->logMsg(sprintf('validBoomerangURL(%s) no boomerang URL set.', $id), LOG_DEBUG, __FILE__, __LINE__);
+        if (!$this->running) {
+            $this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_NOTICE, __FILE__, __LINE__);
+            return false;
+        }
+
+        if (!isset($_SESSION[$this->ns]['boomerang']['url'])) {
+            $this->logMsg(sprintf('validBoomerangURL(%s) no boomerang URL set.', $id), LOG_DEBUG, __FILE__, __LINE__);
             return false;
         }
@@ -1045,32 +969,32 @@
         // a boomerang redirection will always occur at least several seconds after the last boomerang redirect
         // or a boomerang being set.
-        $boomerang_time = isset($_SESSION[$_this->app]['boomerang']['time']) ? $_SESSION[$_this->app]['boomerang']['time'] : 0;
+        $boomerang_time = isset($_SESSION[$this->ns]['boomerang']['time']) ? $_SESSION[$this->ns]['boomerang']['time'] : 0;
 
         $url = '';
-        if (isset($id) && isset($_SESSION[$_this->app]['boomerang']['url'][$id])) {
-            $url = $_SESSION[$_this->app]['boomerang']['url'][$id];
+        if (isset($id) && isset($_SESSION[$this->ns]['boomerang']['url'][$id])) {
+            $url = $_SESSION[$this->ns]['boomerang']['url'][$id];
         } else if (!isset($id) || $use_nonspecificboomerang) {
             // Use non specific boomerang if available.
-            $url = end($_SESSION[$_this->app]['boomerang']['url']);
-        }
-
-        $_this->logMsg(sprintf('validBoomerangURL(%s) testing: %s', $id, $url), LOG_DEBUG, __FILE__, __LINE__);
+            $url = end($_SESSION[$this->ns]['boomerang']['url']);
+        }
+
+        $this->logMsg(sprintf('validBoomerangURL(%s) testing: %s', $id, $url), LOG_DEBUG, __FILE__, __LINE__);
 
         if ('' == $url) {
-            $_this->logMsg(sprintf('validBoomerangURL(%s) not valid, empty!', $id), LOG_DEBUG, __FILE__, __LINE__);
+            $this->logMsg(sprintf('validBoomerangURL(%s) not valid, empty!', $id), LOG_DEBUG, __FILE__, __LINE__);
             return false;
         }
         if ($url == absoluteMe()) {
             // The URL we are directing to is the current page.
-            $_this->logMsg(sprintf('validBoomerangURL(%s) not valid, same as absoluteMe: %s', $id, $url), LOG_DEBUG, __FILE__, __LINE__);
+            $this->logMsg(sprintf('validBoomerangURL(%s) not valid, same as absoluteMe: %s', $id, $url), LOG_DEBUG, __FILE__, __LINE__);
             return false;
         }
         if ($boomerang_time >= (time() - 2)) {
             // Last boomerang direction was more than 2 seconds ago.
-            $_this->logMsg(sprintf('validBoomerangURL(%s) not valid, boomerang_time too short: %s', $id, time() - $boomerang_time), LOG_DEBUG, __FILE__, __LINE__);
-            return false;
-        }
-
-        $_this->logMsg(sprintf('validBoomerangURL(%s) is valid: %s', $id, $url), LOG_DEBUG, __FILE__, __LINE__);
+            $this->logMsg(sprintf('validBoomerangURL(%s) not valid, boomerang_time too short: %s', $id, time() - $boomerang_time), LOG_DEBUG, __FILE__, __LINE__);
+            return false;
+        }
+
+        $this->logMsg(sprintf('validBoomerangURL(%s) is valid: %s', $id, $url), LOG_DEBUG, __FILE__, __LINE__);
         return true;
     }
@@ -1082,8 +1006,4 @@
     function sslOn()
     {
-        if (!isset($_this) || !is_a($_this, 'App') && !is_subclass_of($_this, 'App')) {
-            $_this =& App::getInstance();
-        }
-
         if (function_exists('apache_get_modules')) {
             $modules = apache_get_modules();
@@ -1093,8 +1013,8 @@
         }
 
-        if ('' == getenv('HTTPS') && $_this->getParam('ssl_enabled') && in_array('mod_ssl', $modules)) {
-            $_this->raiseMsg(sprintf(_("Secure SSL connection made to %s"), $_this->getParam('ssl_domain')), MSG_NOTICE, __FILE__, __LINE__);
+        if ('' == getenv('HTTPS') && $this->getParam('ssl_enabled') && in_array('mod_ssl', $modules)) {
+            $this->raiseMsg(sprintf(_("Secure SSL connection made to %s"), $this->getParam('ssl_domain')), MSG_NOTICE, __FILE__, __LINE__);
             // Always append session because some browsers do not send cookie when crossing to SSL URL.
-            $_this->dieURL('https://' . $_this->getParam('ssl_domain') . getenv('REQUEST_URI'), null, true);
+            $this->dieURL('https://' . $this->getParam('ssl_domain') . getenv('REQUEST_URI'), null, true);
         }
     }
Index: branches/2.0singleton/lib/Auth_File.inc.php
===================================================================
--- branches/2.0singleton/lib/Auth_File.inc.php	(revision 132)
+++ branches/2.0singleton/lib/Auth_File.inc.php	(revision 135)
@@ -1,4 +1,7 @@
 <?php
 /**
+ * Auth_File.inc.php
+ * code by strangecode :: www.strangecode.com :: this document contains copyrighted information
+ *
  * The Auth_File:: class provides a htpasswd file implementation for
  * authentication.
@@ -100,5 +103,5 @@
             return $this->_params[$param];
         } else {
-            $app->logMsg(sprintf('Parameter is not set: %s', $param), LOG_DEBUG, __FILE__, __LINE__);
+            $app->logMsg(sprintf('Parameter is not set: %s', $param), LOG_NOTICE, __FILE__, __LINE__);
             return null;
         }
Index: branches/2.0singleton/lib/Auth_SQL.inc.php
===================================================================
--- branches/2.0singleton/lib/Auth_SQL.inc.php	(revision 132)
+++ branches/2.0singleton/lib/Auth_SQL.inc.php	(revision 135)
@@ -239,5 +239,5 @@
             return $this->_params[$param];
         } else {
-            $app->logMsg(sprintf('Parameter is not set: %s', $param), LOG_DEBUG, __FILE__, __LINE__);
+            $app->logMsg(sprintf('Parameter is not set: %s', $param), LOG_NOTICE, __FILE__, __LINE__);
             return null;
         }
Index: branches/2.0singleton/lib/AuthorizeNet.inc.php
===================================================================
--- branches/2.0singleton/lib/AuthorizeNet.inc.php	(revision 132)
+++ branches/2.0singleton/lib/AuthorizeNet.inc.php	(revision 135)
@@ -1,3 +1,15 @@
 <?php
+/**
+ * AuthorizeNet.inc.php
+ * code by strangecode :: www.strangecode.com :: this document contains copyrighted information
+ *
+ * The AuthorizeNet class provides an abstract interface for communicating
+ * with authorize.net's AIM interface. Supports Auth.Net v3.1
+ *
+ * @author  Quinn Comendant <quinn@strangecode.com>
+ * @version 1.0
+ * @date 2004-04-06
+ */
+ 
 // Example usage
 // require_once 'codebase/lib/AuthorizeNet.inc.php';
@@ -14,5 +26,5 @@
 //     'x_Exp_Date' => '042008',
 //     'x_Invoice_Num' => '100',
-//     'x_Address' => '10 rue Levouv',
+//     'x_Address' => '10 rue LevouvÃ©',
 //     'x_City' => 'SomeCity',
 //     'x_State' => 'CA',
@@ -27,17 +39,6 @@
 // }
 
-/**
- * The AuthorizeNet class provides an abstract interface for communicating
- * with authorize.net's AIM interface. Supports Auth.Net v3.1
- *
- * @author  Quinn Comendant <quinn@strangecode.com>
- * @version 1.0
- * @date 2004-04-06
- */
-
-require_once dirname(__FILE__) . '/Utilities.inc.php';
-
-class AuthorizeNet
-{
+class AuthorizeNet {
+
     var $post_url = ''; // The URL to post data to.
     var $md5_hash_value = ','; // A custom value for the response delimination character.
@@ -156,5 +157,5 @@
             return $this->_params[$param];
         } else {
-            $app->logMsg(sprintf('Parameter is not set: %s', $param), LOG_DEBUG, __FILE__, __LINE__);
+            $app->logMsg(sprintf('Parameter is not set: %s', $param), LOG_NOTICE, __FILE__, __LINE__);
             return null;
         }
Index: branches/2.0singleton/lib/CSS.inc.php
===================================================================
--- branches/2.0singleton/lib/CSS.inc.php	(revision 132)
+++ branches/2.0singleton/lib/CSS.inc.php	(revision 135)
@@ -52,5 +52,5 @@
             return $this->_params[$param];
         } else {
-            $app->logMsg(sprintf('Parameter is not set: %s', $param), LOG_DEBUG, __FILE__, __LINE__);
+            $app->logMsg(sprintf('Parameter is not set: %s', $param), LOG_NOTICE, __FILE__, __LINE__);
             return null;
         }
Index: branches/2.0singleton/lib/DB.inc.php
===================================================================
--- branches/2.0singleton/lib/DB.inc.php	(revision 132)
+++ branches/2.0singleton/lib/DB.inc.php	(revision 135)
@@ -4,16 +4,16 @@
  * code by strangecode :: www.strangecode.com :: this document contains copyrighted information
  *
- * DB abstraction layer.
+ * Very lightweight DB semi-abstraction layer. Mainly to catch errors with mysql_query, with some goodies.
  *
  * @author  Quinn Comendant <quinn@strangecode.com>
- * @version 1.0.1
+ * @version 2.1
  */
 
 class DB {
 
-    // If DB::connect has successfully opened a db connection.
+    // If $db->connect has successfully opened a db connection.
     var $_connected = false;
 
-    // Database handler.
+    // Database handle.
     var $dbh;
 
@@ -30,8 +30,12 @@
         'db_pass' => null,
 
-        // Debugging.
-        'db_always_debug' => false, // TRUE = display all SQL queries.
-        'db_debug' => false, // TRUE = display db errors.
-        'db_die_on_failure' => false, // TRUE = script stops on db error.
+        // Display all SQL queries.
+        'db_always_debug' => false,
+
+        // Display db errors.
+        'db_debug' => false,
+        
+        // Script stops on db error.
+        'db_die_on_failure' => false,
     );
 
@@ -49,5 +53,5 @@
      * This method enforces the singleton pattern for this class.
      *
-     * @return  object  Reference to the global SessionCache object.
+     * @return  object  Reference to the global DB object.
      * @access  public
      * @static
@@ -65,33 +69,17 @@
 
     /**
-     * Constructor.
-     */
-    function DB()
-    {
-        // Initialize default params.
+     * Set (or overwrite existing) parameters by passing an array of new parameters.
+     *
+     * @access public
+     *
+     * @param  array    $params     Array of parameters (key => val pairs).
+     */
+    function setParam($params)
+    {
+		$app =& App::getInstance();
+    
         if (isset($params) && is_array($params)) {
             // Merge new parameters with old overriding only those passed.
             $this->_params = array_merge($this->_params, $params);
-        }
-    }
-
-    /**
-     * Set (or overwrite existing) parameters by passing an array of new parameters.
-     *
-     * @access public
-     *
-     * @param  array    $params     Array of parameters (key => val pairs).
-     */
-    function setParam($params)
-    {
-		$app =& App::getInstance();
-    
-        if (!isset($_this) || !is_a($_this, 'DB') && !is_subclass_of($_this, 'DB')) {
-            $_this =& DB::getInstance();
-        }
-
-        if (isset($params) && is_array($params)) {
-            // Merge new parameters with old overriding only those passed.
-            $_this->_params = array_merge($_this->_params, $params);
         } else {
             $app->logMsg(sprintf('Parameters are not an array: %s', $params), LOG_ERR, __FILE__, __LINE__);
@@ -100,11 +88,9 @@
 
     /**
-     * Return the value of a parameter.
-     *
-     * @access  public
-     *
-     * @param   string  $param      The key of the parameter to return.
-     *
-     * @return  mixed               Parameter value.
+     * Return the value of a parameter, if it exists.
+     *
+     * @access public
+     * @param string $param        Which parameter to return.
+     * @return mixed               Configured parameter value.
      */
     function getParam($param)
@@ -112,12 +98,8 @@
 		$app =& App::getInstance();
     
-        if (!isset($_this) || !is_a($_this, 'DB') && !is_subclass_of($_this, 'DB')) {
-            $_this =& DB::getInstance();
-        }
-
-        if (isset($_this->_params[$param])) {
-            return $_this->_params[$param];
+        if (isset($this->_params[$param])) {
+            return $this->_params[$param];
         } else {
-            $app->logMsg(sprintf('Parameter is not set: %s', $param), LOG_DEBUG, __FILE__, __LINE__);
+            $app->logMsg(sprintf('Parameter is not set: %s', $param), LOG_NOTICE, __FILE__, __LINE__);
             return null;
         }
@@ -135,9 +117,5 @@
 		$app =& App::getInstance();
     
-        if (!isset($_this) || !is_a($_this, 'DB') && !is_subclass_of($_this, 'DB')) {
-            $_this =& DB::getInstance();
-        }
-
-        if (!$_this->getParam('db_name') || !$_this->getParam('db_user') || !$_this->getParam('db_pass')) {
+        if (!$this->getParam('db_name') || !$this->getParam('db_user') || !$this->getParam('db_pass')) {
             $app->logMsg('Database credentials missing.', LOG_EMERG, __FILE__, __LINE__);
             return false;
@@ -145,23 +123,21 @@
 
         // Connect to database. Always create a new link to the server.
-        if ($_this->dbh = mysql_connect($_this->getParam('db_server'), $_this->getParam('db_user'), $_this->getParam('db_pass'), true)) {
+        if ($this->dbh = mysql_connect($this->getParam('db_server'), $this->getParam('db_user'), $this->getParam('db_pass'), true)) {
             // Select database
-            mysql_select_db($_this->getParam('db_name'), $_this->dbh);
+            mysql_select_db($this->getParam('db_name'), $this->dbh);
         }
 
         // Test for connection errors.
-        if (!$_this->dbh || mysql_error($_this->dbh)) {
-            $mysql_error_msg = $_this->dbh ? 'Codebase MySQL error: (' . mysql_errno($_this->dbh) . ') ' . mysql_error($_this->dbh) : 'Codebase MySQL error: Could not connect to server.';
+        if (!$this->dbh || mysql_error($this->dbh)) {
+            $mysql_error_msg = $this->dbh ? 'Codebase MySQL error: (' . mysql_errno($this->dbh) . ') ' . mysql_error($this->dbh) : 'Codebase MySQL error: Could not connect to server.';
             $app->logMsg($mysql_error_msg, LOG_EMERG, __FILE__, __LINE__);
 
             // Print helpful or pretty error?
-            if ($_this->getParam('db_debug')) {
+            if ($this->getParam('db_debug')) {
                 echo $mysql_error_msg . "\n";
-            } else {
-                echo _("This page is temporarily unavailable. It should be back up in a few minutes.");
             }
 
             // Die or continue without connection?
-            if ($_this->getParam('db_die_on_failure')) {
+            if ($this->getParam('db_die_on_failure')) {
                 echo "\n\n<!-- Script execution stopped out of embarrassment. -->";
                 die;
@@ -172,8 +148,8 @@
 
         // DB connection success!
-        $_this->_connected = true;
+        $this->_connected = true;
 
         // Tell MySQL what character set we're useing. Available only on MySQL verions > 4.01.01.
-        $_this->query("/*!40101 SET NAMES '" . $_this->mysql_character_sets[strtolower($app->getParam('character_set'))] . "' */");
+        $this->query("/*!40101 SET NAMES '" . $this->mysql_character_sets[strtolower($app->getParam('character_set'))] . "' */");
 
         return true;
@@ -189,13 +165,9 @@
     function close()
     {
-        if (!isset($_this) || !is_a($_this, 'DB') && !is_subclass_of($_this, 'DB')) {
-            $_this =& DB::getInstance();
-        }
-
-        if (!$_this->_connected) {
-            return false;
-        }
-
-        mysql_close($_this->dbh);
+        if (!$this->_connected) {
+            return false;
+        }
+
+        return mysql_close($this->dbh);
     }
 
@@ -210,13 +182,9 @@
     function getDBH()
     {
-        if (!isset($_this) || !is_a($_this, 'DB') && !is_subclass_of($_this, 'DB')) {
-            $_this =& DB::getInstance();
-        }
-
-        if (!$_this->_connected) {
-            return false;
-        }
-
-        return $_this->dbh;
+        if (!$this->_connected) {
+            return false;
+        }
+
+        return $this->dbh;
     }
 
@@ -244,8 +212,5 @@
     function escapeString($string)
     {
-        if (!isset($_this) || !is_a($_this, 'DB') && !is_subclass_of($_this, 'DB')) {
-            $_this =& DB::getInstance();
-        }
-        return mysql_real_escape_string($string, $_this->dbh);
+        return mysql_real_escape_string($string, $this->dbh);
     }
 
@@ -264,9 +229,5 @@
         static $_query_count = 0;
 
-        if (!isset($_this) || !is_a($_this, 'DB') && !is_subclass_of($_this, 'DB')) {
-            $_this =& DB::getInstance();
-        }
-
-        if (!$_this->_connected) {
+        if (!$this->_connected) {
            return false;
         }
@@ -274,20 +235,20 @@
         $_query_count++;
         $debugqry = preg_replace("/\n[\t ]+/", "\n", $query);
-        if ($_this->getParam('db_always_debug') || $debug) {
+        if ($this->getParam('db_always_debug') || $debug) {
             echo "<!-- ----------------- Query $_query_count ---------------------\n$debugqry\n-->\n";
         }
 
         // Execute!
-        $qid = mysql_query($query, $_this->dbh);
+        $qid = mysql_query($query, $this->dbh);
 
         // Error checking.
-        if (!$qid || mysql_error($_this->dbh)) {
-            if ($_this->getParam('db_debug')) {
-                echo '<pre style="padding:2em; background:#ddd; font:9px monaco;">' . wordwrap(mysql_error($_this->dbh)) . '<hr>' . htmlspecialchars($debugqry) . '</pre>';
+        if (!$qid || mysql_error($this->dbh)) {
+            if ($this->getParam('db_debug')) {
+                echo '<pre style="padding:2em; background:#ddd; font:9px monaco;">' . wordwrap(mysql_error($this->dbh)) . '<hr>' . htmlspecialchars($debugqry) . '</pre>';
             } else {
                 echo _("This page is temporarily unavailable. It should be back up in a few minutes.");
             }
-            $app->logMsg(sprintf('MySQL error %s: %s in query: %s', mysql_errno($_this->dbh), mysql_error($_this->dbh), $debugqry), LOG_EMERG, __FILE__, __LINE__);
-            if ($_this->getParam('db_die_on_failure')) {
+            $app->logMsg(sprintf('MySQL error %s: %s in query: %s', mysql_errno($this->dbh), mysql_error($this->dbh), $debugqry), LOG_EMERG, __FILE__, __LINE__);
+            if ($this->getParam('db_die_on_failure')) {
                 echo "\n\n<!-- Script execution stopped out of embarrassment. -->";
                 die;
@@ -312,23 +273,19 @@
 		$app =& App::getInstance();
     
-        if (!isset($_this) || !is_a($_this, 'DB') && !is_subclass_of($_this, 'DB')) {
-            $_this =& DB::getInstance();
-        }
-
-        if (!$_this->_connected) {
-            return false;
-        }
-
-        if (!isset($_this->existing_tables) || !$use_cached_results) {
-            $_this->existing_tables = array();
-            $qid = $_this->query("SHOW TABLES");
+        if (!$this->_connected) {
+            return false;
+        }
+
+        if (!isset($this->existing_tables) || !$use_cached_results) {
+            $this->existing_tables = array();
+            $qid = $this->query("SHOW TABLES");
             while (list($row) = mysql_fetch_row($qid)) {
-                $_this->existing_tables[] = $row;
-            }
-        }
-        if (in_array($table, $_this->existing_tables)) {
+                $this->existing_tables[] = $row;
+            }
+        }
+        if (in_array($table, $this->existing_tables)) {
             return true;
         } else {
-            $app->logMsg(sprintf('nonexistent DB table: %s.%s', $_this->getParam('db_name'), $table), LOG_ALERT, __FILE__, __LINE__);
+            $app->logMsg(sprintf('nonexistent DB table: %s.%s', $this->getParam('db_name'), $table), LOG_ALERT, __FILE__, __LINE__);
             return false;
         }
@@ -346,14 +303,10 @@
     function columnExists($table, $columns, $strict=true, $use_cached_results=true)
     {
-        if (!isset($_this) || !is_a($_this, 'DB') && !is_subclass_of($_this, 'DB')) {
-            $_this =& DB::getInstance();
-        }
-
-        if (!$_this->_connected) {
+        if (!$this->_connected) {
             return false;
         }
 
         // Ensure the table exists.
-        if (!$_this->tableExists($table, $use_cached_results)) {
+        if (!$this->tableExists($table, $use_cached_results)) {
             return false;
         }
@@ -364,10 +317,10 @@
         }
 
-        if (!isset($_this->table_columns[$table]) || !$use_cached_results) {
+        if (!isset($this->table_columns[$table]) || !$use_cached_results) {
             // Populate and cache array of current columns for this table.
-            $_this->table_columns[$table] = array();
-            $qid = $_this->query("DESCRIBE $table");
+            $this->table_columns[$table] = array();
+            $qid = $this->query("DESCRIBE $table");
             while ($row = mysql_fetch_row($qid)) {
-                $_this->table_columns[$table][] = $row[0];
+                $this->table_columns[$table][] = $row[0];
             }
         }
@@ -376,9 +329,9 @@
             // Do an exact comparison of table schemas.
             sort($columns);
-            sort($_this->table_columns[$table]);
-            return $_this->table_columns[$table] == $columns;
+            sort($this->table_columns[$table]);
+            return $this->table_columns[$table] == $columns;
         } else {
             // Only check that the specified columns are available in the table.
-            $match_columns = array_intersect($_this->table_columns[$table], $columns);
+            $match_columns = array_intersect($this->table_columns[$table], $columns);
             sort($columns);
             sort($match_columns);
Index: branches/2.0singleton/lib/DBSessionHandler.inc.php
===================================================================
--- branches/2.0singleton/lib/DBSessionHandler.inc.php	(revision 132)
+++ branches/2.0singleton/lib/DBSessionHandler.inc.php	(revision 135)
@@ -3,6 +3,7 @@
  * DBSessionHandler.inc.php
  * Code by Strangecode :: www.strangecode.com :: This document contains copyrighted information.
+ * 
  * @author  Quinn Comendant <quinn@strangecode.com>
- * @version 1.3
+ * @version 2.1
  * @since   1999
  */
@@ -13,8 +14,4 @@
 
     var $_params = array(
-        'db_server' => 'localhost',
-        'db_name' => '',
-        'db_user' => '',
-        'db_pass' => '',
         'db_table' => 'session_tbl',
         'create_table' => true, // Automatically create table and verify columns. Better set to false after site launch.
@@ -30,5 +27,5 @@
      * @since   18 Jul 2005 11:02:50
      */
-    function DBSessionHandler($db=null, $params=array())
+    function DBSessionHandler($db, $params=array())
     {
 		$app =& App::getInstance();
@@ -36,55 +33,32 @@
         $this->_params = array_merge($this->_params, $params);
 
-        if (isset($db)) {
-            if (is_a($db, 'DB')) {
-                if ($db->isConnected()) {
-                    // Use existing db connection.
-                    $this->db =& $db;
-                } else {
-                    $app->logMsg(sprintf('Provided DB object is not connected. %s', mysql_error($db->dbh)), LOG_ERR, __FILE__, __LINE__);
+        if (!method_exists($db, 'isConnected')) {
+            $app->logMsg(sprintf('Provided object (%s) is not a valid DB object.', get_class($db)), LOG_ERR, __FILE__, __LINE__);
+        } else {
+            if (!$db->isConnected()) {
+                $app->logMsg('Provided DB object is not connected.', LOG_ERR, __FILE__, __LINE__);
+            } else {
+                // OK! We have a valid, connected DB object.
+                $this->db =& $db;
+
+                // Get create tables config from global context.
+                if (!is_null($app->getParam('db_create_tables'))) {
+                    $this->_params['create_table'] = $app->getParam('db_create_tables');
                 }
-            } else {
-                $app->logMsg(sprintf('Provided DB object is not valid. %s', gettype($db)), LOG_ERR, __FILE__, __LINE__);
+
+                // Ensure db table is fit.
+                $this->initDB();
+
+                ini_set('session.save_handler', 'user');
+                session_set_save_handler(
+                    array(&$this, 'dbSessionOpen'),
+                    array(&$this, 'dbSessionClose'),
+                    array(&$this, 'dbSessionRead'),
+                    array(&$this, 'dbSessionWrite'),
+                    array(&$this, 'dbSessionDestroy'),
+                    array(&$this, 'dbSessionGarbage')
+                );
             }
-        } else {
-            // Create our own new db connection.
-            require_once dirname(__FILE__) . '/DB.inc.php';
-
-            $this->db =& new DB();
-            $this->db->setParam(array(
-                'db_server' => $this->_params['db_server'],
-                'db_name' => $this->_params['db_name'],
-                'db_user' => $this->_params['db_user'],
-                'db_pass' => $this->_params['db_pass'],
-                'db_always_debug' => $this->_params['db_always_debug'],
-                'db_debug' => $this->_params['db_debug'],
-                'db_die_on_failure' => $this->_params['db_die_on_failure'],
-            ));
-
-            // Connect to database.
-            $this->db->connect();
         }
-
-        if (!isset($this) || !is_a($this->db, 'DB') || !$this->db->isConnected()) {
-            trigger_error('Invalid DB object or unable to connect to database.', E_USER_ERROR);
-        }
-
-        // Get create tables config from global context.
-        if (!is_null($app->getParam('db_create_tables'))) {
-            $this->_params['create_table'] = $app->getParam('db_create_tables');
-        }
-
-        // Ensure db table is fit.
-        $this->initDB();
-
-        ini_set('session.save_handler', 'user');
-        session_set_save_handler(
-            array(&$this, 'dbSessionOpen'),
-            array(&$this, 'dbSessionClose'),
-            array(&$this, 'dbSessionRead'),
-            array(&$this, 'dbSessionWrite'),
-            array(&$this, 'dbSessionDestroy'),
-            array(&$this, 'dbSessionGarbage')
-        );
     }
 
Index: branches/2.0singleton/lib/Email.inc.php
===================================================================
--- branches/2.0singleton/lib/Email.inc.php	(revision 132)
+++ branches/2.0singleton/lib/Email.inc.php	(revision 135)
@@ -8,5 +8,6 @@
  * @author  Quinn Comendant <quinn@strangecode.com>
  * @version 1.0
--------------------------------------------------------------------------------------
+ * 
+ 
 // Example.
 $email = new Email(array(
@@ -28,5 +29,6 @@
     $app->logMsg(sprintf('Error sending confirmation email to address %s', $frm['email']), LOG_NOTICE, __FILE__, __LINE__);
 }
--------------------------------------------------------------------------------------
+
+ * 
  */
 class Email {
Index: branches/2.0singleton/lib/FormValidator.inc.php
===================================================================
--- branches/2.0singleton/lib/FormValidator.inc.php	(revision 132)
+++ branches/2.0singleton/lib/FormValidator.inc.php	(revision 135)
@@ -23,6 +23,5 @@
  * $fv->validatePhone('phone1');
  */
-class FormValidator
-{
+class FormValidator {
 
     // Array filling with error messages.
Index: branches/2.0singleton/lib/Google_API.inc.php
===================================================================
--- branches/2.0singleton/lib/Google_API.inc.php	(revision 132)
+++ branches/2.0singleton/lib/Google_API.inc.php	(revision 135)
@@ -1,4 +1,7 @@
 <?php
 /**
+ * Google_API.inc.php
+ * code by strangecode :: www.strangecode.com :: this document contains copyrighted information
+ *
  * Interface to the Google API using SOAP/Client.php.
  *
@@ -25,13 +28,5 @@
 require_once 'SOAP/Client.php';
 
-
-/**
-* PHP Interface to the Google API
-*
-* @author  Sebastian Bergmann <sb@sebastian-bergmann.de>
-* @access  public
-*/
-class Google_API
-{
+class Google_API {
 
     /**
Index: branches/2.0singleton/lib/Hierarchy.inc.php
===================================================================
--- branches/2.0singleton/lib/Hierarchy.inc.php	(revision 132)
+++ branches/2.0singleton/lib/Hierarchy.inc.php	(revision 135)
@@ -2,8 +2,6 @@
 /**
  * Hierarchy.inc.php
- * Code by Strangecode :: www.strangecode.com :: This document contains copyrighted information
- */
-
-/**
+ * code by strangecode :: www.strangecode.com :: this document contains copyrighted information
+ * 
  * Objective: This class provides the tools to organize pieces of data into a
  * hierarchy of nodes. Any form of data (article, product, image) can be
Index: branches/2.0singleton/lib/Image.inc.php
===================================================================
--- branches/2.0singleton/lib/Image.inc.php	(revision 132)
+++ branches/2.0singleton/lib/Image.inc.php	(revision 135)
@@ -2,5 +2,6 @@
 /**
  * Image.inc.php
- * Code by Strangecode :: www.strangecode.com :: This document contains copyrighted information.
+ * code by strangecode :: www.strangecode.com :: this document contains copyrighted information
+ *
  * @author  Quinn Comendant <quinn@strangecode.com>
  * @version 1.1
Index: branches/2.0singleton/lib/ImageThumb.inc.php
===================================================================
--- branches/2.0singleton/lib/ImageThumb.inc.php	(revision 132)
+++ branches/2.0singleton/lib/ImageThumb.inc.php	(revision 135)
@@ -2,5 +2,5 @@
 /**
  * ImageThumb.inc.php
- * Code by Strangecode :: www.strangecode.com :: This document contains copyrighted information
+ * code by strangecode :: www.strangecode.com :: this document contains copyrighted information
  *
  * @author   Quinn Comendant <quinn@strangecode.com>
@@ -131,9 +131,9 @@
     {
 		$app =& App::getInstance();
-
+    
         if (isset($this->_params[$param])) {
             return $this->_params[$param];
         } else {
-            $app->logMsg(sprintf('Parameter is not set: %s', $param), LOG_DEBUG, __FILE__, __LINE__);
+            $app->logMsg(sprintf('Parameter is not set: %s', $param), LOG_NOTICE, __FILE__, __LINE__);
             return null;
         }
Index: branches/2.0singleton/lib/MCVE.inc.php
===================================================================
--- branches/2.0singleton/lib/MCVE.inc.php	(revision 132)
+++ branches/2.0singleton/lib/MCVE.inc.php	(revision 135)
@@ -1,4 +1,7 @@
 <?php
 /**
+ * MCVE.inc.php
+ * code by strangecode :: www.strangecode.com :: this document contains copyrighted information
+ *
  * The MCVE:: class provides functions for communicating with a MCVE server.
  *
Index: branches/2.0singleton/lib/Nav.inc.php
===================================================================
--- branches/2.0singleton/lib/Nav.inc.php	(revision 132)
+++ branches/2.0singleton/lib/Nav.inc.php	(revision 135)
@@ -1,4 +1,7 @@
 <?php
 /**
+ * Nav.inc.php
+ * code by strangecode :: www.strangecode.com :: this document contains copyrighted information
+ *
  * The Nav:: class provides a system for working with navigation elements.
  * Currently it supports storing page titles and URLs for printing breadcrumbs
Index: branches/2.0singleton/lib/PEdit.inc.php
===================================================================
--- branches/2.0singleton/lib/PEdit.inc.php	(revision 132)
+++ branches/2.0singleton/lib/PEdit.inc.php	(revision 135)
@@ -1,4 +1,7 @@
 <?php
 /**
+ * PEdit.inc.php
+ * code by strangecode :: www.strangecode.com :: this document contains copyrighted information
+ *
  * PEdit:: provides a mechanism to store text in php variables
  * which will be printed to the client browser under normal
@@ -11,5 +14,11 @@
  * To use, include this file, initialize variables,
  * and call printing/editing functions where you want data and forms to
- * show up. Below is an example of use:
+ * show up.
+ * 
+ * @author  Quinn Comendant <quinn@strangecode.com>
+ * @concept Beau Smith <beau@beausmith.com>
+ * @version 2.0 
+ * 
+ * Example of use:
  
  // Initialize PEdit object.
@@ -37,7 +46,4 @@
  $pedit->formEnd();
 
- * @author  Quinn Comendant <quinn@strangecode.com>
- * @concept Beau Smith <beau@beausmith.com>
- * @version 2.0
  */
 class PEdit {
@@ -115,5 +121,5 @@
     {
 		$app =& App::getInstance();
-
+    
         if (isset($this->_params[$param])) {
             return $this->_params[$param];
Index: branches/2.0singleton/lib/PageNumbers.inc.php
===================================================================
--- branches/2.0singleton/lib/PageNumbers.inc.php	(revision 132)
+++ branches/2.0singleton/lib/PageNumbers.inc.php	(revision 135)
@@ -81,8 +81,8 @@
             $this->_per_page = $per_page;
             if ($save_value) {
-                $prefs->setValue('items_per_page', $this->_per_page, $_SERVER['PHP_SELF']);
+                $prefs->set('items_per_page', $this->_per_page, $_SERVER['PHP_SELF']);
             }
         } else if ($save_value && $prefs->exists('items_per_page', $_SERVER['PHP_SELF'])) {
-            $this->_per_page = (int)$prefs->getValue('items_per_page', $_SERVER['PHP_SELF']);
+            $this->_per_page = (int)$prefs->get('items_per_page', $_SERVER['PHP_SELF']);
         } else if (is_numeric($default) && $default > 0) {
             $this->_per_page = $default;
@@ -109,8 +109,8 @@
             }
             if ($save_value) {
-                $prefs->setValue('page_number', $this->current_page, $_SERVER['PHP_SELF']);
+                $prefs->set('page_number', $this->current_page, $_SERVER['PHP_SELF']);
             }
         } else if ($save_value && $prefs->exists('page_number', $_SERVER['PHP_SELF'])) {
-            $this->current_page = (int)$prefs->getValue('page_number', $_SERVER['PHP_SELF']);
+            $this->current_page = (int)$prefs->get('page_number', $_SERVER['PHP_SELF']);
         }
         $this->set_page_number_initialized = true;
Index: branches/2.0singleton/lib/PayPal.inc.php
===================================================================
--- branches/2.0singleton/lib/PayPal.inc.php	(revision 132)
+++ branches/2.0singleton/lib/PayPal.inc.php	(revision 135)
@@ -1,4 +1,7 @@
 <?php
 /**
+ * PayPal.inc.php
+ * code by strangecode :: www.strangecode.com :: this document contains copyrighted information
+ *
  * The PayPal:: class provides functions for creating PayPal buttons and for
  * receiving PayPal's Instant Payment Notification (IPN) service.
@@ -233,9 +236,9 @@
     {
 		$app =& App::getInstance();
-
+    
         if (isset($this->_params[$param])) {
             return $this->_params[$param];
         } else {
-            $app->logMsg(sprintf('Parameter is not set: %s', $param), LOG_DEBUG, __FILE__, __LINE__);
+            $app->logMsg(sprintf('Parameter is not set: %s', $param), LOG_NOTICE, __FILE__, __LINE__);
             return null;
         }
Index: branches/2.0singleton/lib/Prefs.inc.php
===================================================================
--- branches/2.0singleton/lib/Prefs.inc.php	(revision 132)
+++ branches/2.0singleton/lib/Prefs.inc.php	(revision 135)
@@ -1,42 +1,28 @@
 <?php
 /**
+ * Prefs.inc.php
+ * code by strangecode :: www.strangecode.com :: this document contains copyrighted information
+ *
  * Prefs:: provides an API for saving arbitrary values in a user's session.
- * Database save routines to come.
  *
- * @inspiration  Horde 2.0's Prefs class. This one is much simpler, but
- *               the API for the methods that exist are sort of like Horde's
- *               in case we want to be more like it in the future.
  * @author  Quinn Comendant <quinn@strangecode.com>
- * @version 1.1
+ * @version 2.1
  */
 class Prefs {
 
-    /**
-     * Where these preferences can be used. To differentiate between preferences
-     * for a specific script, application, or global.
-     * @var string $scope
-     */
-    var $scope = 'global';
-
-    /**
-     * Indicator whether we save in the database or not.
-     * @var boolean $_perpetual
-     */
-    var $_perpetual = false;
-
-    /**
-     * Hash containing connection parameters.
-     * @var array $params
-     */
-    var $params = array();
-
+    // Namespace of preferences.
+    var $ns;
 
     /**
      * Prefs constructor.
      */
-    function Prefs($dbh=false, $params=array())
+    function Prefs($ns='')
     {
-        $this->params = $params;
-        $_perpetual = false; // Until database routines are completed.
+        $this->ns = '_pref_' . $ns;
+        
+        // Initialized the prefs array.
+        if (!isset($_SESSION[$this->ns])) {
+            $_SESSION[$this->ns] = array();
+        }
     }
 
@@ -45,39 +31,12 @@
      * is not set already.
      *
-     * @param  string $pref      The name of the preference to modify.
+     * @param  string $key       The name of the preference to modify.
      * @param  string $val       The new value for this preference.
-     * @param  string $scope     The scope for this preference.
-     *
-     * @return boolean  True if the value was successfully set.
      */
-    function setDefault($pref, $val, $scope=null)
+    function default($key, $val)
     {
-        if (!isset($scope)) {
-            $scope =& $this->scope;
-        }
-
-        // No empty values allowed.
-        if ('' == $pref || '' == $val || '' == $scope) {
-            return false;
-        }
-
-        // Initialized the prefs array.
-        if (!isset($_SESSION['_prefs'])) {
-            $_SESSION['_prefs'] = array();
-        }
-
-        // In case boolean or null values are passed as a string.
-        if ($val == 'true') {
-            $val = true;
-        } else if ($val == 'false') {
-            $val = false;
-        } else if ($val == 'null') {
-            $val = null;
-        }
-
         // Set it only if not set already.
-        if (!isset($_SESSION['_prefs'][$scope][$pref])) {
-            $_SESSION['_prefs'][$scope][$pref] = $val;
-            return true;
+        if (!isset($_SESSION[$this->ns][$key])) {
+            $_SESSION[$this->ns][$key] = $val;
         }
     }
@@ -86,37 +45,10 @@
      * Sets the given preferences to the specific value,
      *
-     * @param  string $pref      The name of the preference to modify.
+     * @param  string $key       The name of the preference to modify.
      * @param  string $val       The new value for this preference.
-     * @param  string $scope     The scope for this preference.
-     *
-     * @return boolean  True if the value was successfully set.
      */
-    function setValue($pref, $val, $scope=null)
+    function set($key, $val)
     {
-        if (!isset($scope)) {
-            $scope =& $this->scope;
-        }
-
-        // No empty values allowed.
-        if ('' == $pref || '' == $val || '' == $scope) {
-            return false;
-        }
-
-        // Initialized the prefs array.
-        if (!isset($_SESSION['_prefs'])) {
-            $_SESSION['_prefs'] = array();
-        }
-
-        // In case boolean or null values are passed as a string.
-        if ($val == 'true') {
-            $val = true;
-        } else if ($val == 'false') {
-            $val = false;
-        } else if ($val == 'null') {
-            $val = null;
-        }
-
-        $_SESSION['_prefs'][$scope][$pref] = $val;
-        return true;
+        $_SESSION[$this->ns][$key] = $val;
     }
 
@@ -124,16 +56,11 @@
      * Returns the value of the requested preference.
      *
-     * @param string $pref      The name of the preference to retrieve.
-     * @param string $scope     The scope for this preference.
+     * @param string $key       The name of the preference to retrieve.
      *
      * @return string           The value of the preference.
      */
-    function getValue($pref, $scope=null)
+    function get($key)
     {
-        if (!isset($scope)) {
-            $scope =& $this->scope;
-        }
-
-        return (isset($_SESSION['_prefs'][$scope][$pref])) ? $_SESSION['_prefs'][$scope][$pref] : null;
+        return (isset($_SESSION[$this->ns][$key])) ? $_SESSION[$this->ns][$key] : null;
     }
 
@@ -141,17 +68,12 @@
      * To see if a preference has been set.
      *
-     * @param string $pref      The name of the preference to check.
-     * @param string $scope     The scope for this preference.
+     * @param string $key       The name of the preference to check.
      *
      * @return boolean          True if the preference isset and not empty
      *                          false otherwise.
      */
-    function exists($pref, $scope=null)
+    function exists($key)
     {
-        if (!isset($scope)) {
-            $scope =& $this->scope;
-        }
-
-        return isset($_SESSION['_prefs'][$scope][$pref]);
+        return isset($_SESSION[$this->ns][$key]);
     }
 
@@ -159,77 +81,11 @@
      * Clear a set preference value.
      *
-     * @param string $pref      The name of the preference to check.
-     * @param string $scope     The scope for this preference.
+     * @param string $key       The name of the preference to check.
      */
-    function clearValue($pref, $scope=null)
+    function delete($key)
     {
-        if (!isset($scope)) {
-            $scope =& $this->scope;
+        if (isset($_SESSION[$this->ns][$key])) {
+            unset($_SESSION[$this->ns][$key]);
         }
-
-        if (isset($_SESSION['_prefs'][$scope][$pref])) {
-            unset($_SESSION['_prefs'][$scope][$pref]);
-        }
-    }
-
-    /**
-     * Retrieves the requested set of preferences from the user's database
-     * entry.
-     *
-     * @param optional array $prefs  An array listing the preferences to
-     *                     retrieve. If not specified, retrieve all of the
-     *                     preferences listed in the $prefs hash.
-     *
-     * @return mixed       True on success or a PEAR_Error object on failure.
-     */
-    function retrieve()
-    {
-        // Check that we don't have the preferences loaded yet.
-        if ($_SESSION['_prefs']['loaded'] == true || !$_perpetual) {
-            return true;
-        }
-
-        // FIXME: Database query goes here....
-        return false;
-
-        $_SESSION['_prefs']['loaded'] = true;
-    }
-
-    /**
-     * Stores preferences to SQL server.
-     *
-     * @param array $prefs (optional) An array listing the preferences to be
-     *                     stored.  If not specified, store all of the
-     *                     preferences listed in the $prefs hash.
-     *
-     * @return mixed       True on success or a PEAR_Error object on failure.
-     */
-    function store($prefs=array())
-    {
-		$app =& App::getInstance();
-
-        // If we are not storing prefs in perpetually.
-        if (!$_perpetual) {
-            return true;
-        }
-
-        /*
-         * If a list of preferences to store hasn't been provided in
-         * $prefs, assume all preferences are desired.
-         */
-        if (empty($prefs)) {
-            $prefs =& $_SESSION['_prefs'];
-        } else if ($_SESSION['_prefs']['loaded'] == true) {
-            $prefs = array_merge($_SESSION['_prefs'], $prefs);
-        }
-
-        if (!is_array($prefs) || empty($prefs)) {
-            $app->raiseMsg(_("No preferences are available."), MSG_ERR, __FILE__, __LINE__);
-            $app->dieBoomerangURL();
-        }
-
-        // FIXME: Database query goes here....
-        return false;
-
     }
 
@@ -237,12 +93,10 @@
      * Perform cleanup operations.
      */
-    function cleanup()
+    function clear()
     {
-        $_SESSION['_prefs'] = array();
+        $_SESSION[$this->ns] = array();
     }
 }
 
 
-
-
 ?>
Index: branches/2.0singleton/lib/RecordLock.inc.php
===================================================================
--- branches/2.0singleton/lib/RecordLock.inc.php	(revision 132)
+++ branches/2.0singleton/lib/RecordLock.inc.php	(revision 135)
@@ -1,8 +1,11 @@
 <?php
 /**
+ * RecordLock.inc.php
+ * code by strangecode :: www.strangecode.com :: this document contains copyrighted information
+ *
  * The RecordLock:: class provides a system for locking abstract DB rows.
  *
  * @author  Quinn Comendant <quinn@strangecode.com>
- * @version 2.0
+ * @version 2.1
  */
 class RecordLock {
@@ -32,11 +35,11 @@
     function &getInstance($auth_object)
     {
-        static $instances = array();
-
-        if (!isset($instances[$auth_object->getVal('auth_name')])) {
-            $instances[$auth_object->getVal('auth_name')] = new RecordLock($auth_object);
-        }
-
-        return $instances[$auth_object->getVal('auth_name')];
+        static $instance = null;
+
+        if ($instance === null) {
+            $instance = new RecordLock($auth_object);
+        }
+
+        return $instance;
     }
 
@@ -44,5 +47,5 @@
      * Constructor. Pass an Auth object on which to perform user lookups.
      *
-     * @param mixed  $auth_object  An Auth_SQL object.
+     * @param mixed  $auth_object  An Auth_SQL or Auth_FILE object.
      */
     function RecordLock($auth_object)
@@ -50,6 +53,6 @@
 		$app =& App::getInstance();
 
-        if (!is_a($auth_object, 'Auth_SQL')) {
-            trigger_error('Constructor not provided a valid Auth_SQL object.', E_USER_ERROR);
+        if (!method_exists($auth_object, 'getVal') || !method_exists($auth_object, 'getUsername')) {
+            trigger_error('Constructor not provided a valid Auth_* object.', E_USER_ERROR);
         }
 
@@ -125,18 +128,18 @@
 
     /**
-     * Return the value of a param setting.
-     *
-     * @access  public
-     * @param   string  $params Which param to return.
-     * @return  mixed   Configured param value.
+     * Return the value of a parameter, if it exists.
+     *
+     * @access public
+     * @param string $param        Which parameter to return.
+     * @return mixed               Configured parameter value.
      */
     function getParam($param)
     {
 		$app =& App::getInstance();
-
+    
         if (isset($this->_params[$param])) {
             return $this->_params[$param];
         } else {
-            $app->logMsg(sprintf('Parameter is not set: %s', $param), LOG_DEBUG, __FILE__, __LINE__);
+            $app->logMsg(sprintf('Parameter is not set: %s', $param), LOG_NOTICE, __FILE__, __LINE__);
             return null;
         }
Index: branches/2.0singleton/lib/RecordVersion.inc.php
===================================================================
--- branches/2.0singleton/lib/RecordVersion.inc.php	(revision 132)
+++ branches/2.0singleton/lib/RecordVersion.inc.php	(revision 135)
@@ -1,4 +1,7 @@
 <?php
 /**
+ * RecordVersion.inc.php
+ * code by strangecode :: www.strangecode.com :: this document contains copyrighted information
+ *
  * The RecordVersion:: class provides a system for saving, reviewing, and
  * restoring versions of a record of any DB table. All the data in the record is
@@ -14,5 +17,4 @@
  * @version 2.1
  */
-
 class RecordVersion {
 
@@ -33,5 +35,5 @@
      * This method enforces the singleton pattern for this class.
      *
-     * @return  object  Reference to the global RecordVersion object.
+     * @return  object  Reference to the global RecordLock object.
      * @access  public
      * @static
@@ -39,11 +41,11 @@
     function &getInstance($auth_object)
     {
-        static $instances = array();
-
-        if (!isset($instances[$auth_object->getVal('auth_name')])) {
-            $instances[$auth_object->getVal('auth_name')] = new RecordVersion($auth_object);
-        }
-
-        return $instances[$auth_object->getVal('auth_name')];
+        static $instance = null;
+
+        if ($instance === null) {
+            $instance = new RecordLock($auth_object);
+        }
+
+        return $instance;
     }
 
@@ -57,6 +59,6 @@
 		$app =& App::getInstance();
 
-        if (!is_a($auth_object, 'Auth_SQL')) {
-            trigger_error('Constructor not provided a valid Auth_SQL object.', E_USER_ERROR);
+        if (!method_exists($auth_object, 'getVal') || !method_exists($auth_object, 'getUsername')) {
+            trigger_error('Constructor not provided a valid Auth_* object.', E_USER_ERROR);
         }
 
@@ -136,18 +138,18 @@
 
     /**
-     * Return the value of a param setting.
-     *
-     * @access  public
-     * @param   string  $params Which param to return.
-     * @return  mixed   Configured param value.
+     * Return the value of a parameter, if it exists.
+     *
+     * @access public
+     * @param string $param        Which parameter to return.
+     * @return mixed               Configured parameter value.
      */
     function getParam($param)
     {
 		$app =& App::getInstance();
-
+    
         if (isset($this->_params[$param])) {
             return $this->_params[$param];
         } else {
-            $app->logMsg(sprintf('Parameter is not set: %s', $param), LOG_DEBUG, __FILE__, __LINE__);
+            $app->logMsg(sprintf('Parameter is not set: %s', $param), LOG_NOTICE, __FILE__, __LINE__);
             return null;
         }
Index: branches/2.0singleton/lib/ScriptTimer.inc.php
===================================================================
--- branches/2.0singleton/lib/ScriptTimer.inc.php	(revision 132)
+++ branches/2.0singleton/lib/ScriptTimer.inc.php	(revision 135)
@@ -1,8 +1,7 @@
 <?php
 /**
- * ScriptTimer.inc.php 
- * Code by Strangecode :: www.strangecode.com :: This document contains copyrighted information
+ * ScriptTimer.inc.php
+ * code by strangecode :: www.strangecode.com :: this document contains copyrighted information
  */
- 
 class ScriptTimer {
 
Index: branches/2.0singleton/lib/SessionCache.inc.php
===================================================================
--- branches/2.0singleton/lib/SessionCache.inc.php	(revision 132)
+++ branches/2.0singleton/lib/SessionCache.inc.php	(revision 135)
@@ -1,15 +1,20 @@
 <?php
 /**
- * SessionCache.inc.php
+ * Cache.inc.php
+ * code by strangecode :: www.strangecode.com :: this document contains copyrighted information
+ *
  * Provides an API for storing a limited amount of data
  * intended to have a short lifetime in a user's session.
  *
- * Code by Strangecode :: www.strangecode.com :: This document contains copyrighted information.
  * @author  Quinn Comendant <quinn@strangecode.com>
- * @version 1.2
+ * @version 2.1
  * @since   2001
  */
-class SessionCache
-{
+ 
+// Flags.
+define('CACHE_IGNORE_SIZE', 1);
+
+class Cache {
+
     var $_params = array(
         'enabled' => true,
@@ -22,13 +27,14 @@
      * This method enforces the singleton pattern for this class.
      *
-     * @return  object  Reference to the global SessionCache object.
+     * @return  object  Reference to the global Cache object.
      * @access  public
      * @static
      */
-    function &getInstance() {
+    function &getInstance()
+    {
         static $instance = null;
 
         if ($instance === null) {
-            $instance = new SessionCache();
+            $instance = new Cache();
         }
 
@@ -46,11 +52,7 @@
 		$app =& App::getInstance();
 
-        if (!isset($_this) || !is_a($_this, 'SessionCache') && !is_subclass_of($_this, 'SessionCache')) {
-            $_this =& SessionCache::getInstance();
-        }
-
         if (isset($params) && is_array($params)) {
             // Merge new parameters with old overriding only those passed.
-            $_this->_params = array_merge($_this->_params, $params);
+            $this->_params = array_merge($this->_params, $params);
         } else {
             $app->logMsg(sprintf('Parameters are not an array: %s', $params), LOG_ERR, __FILE__, __LINE__);
@@ -68,13 +70,9 @@
     {
 		$app =& App::getInstance();
-
-        if (!isset($_this) || !is_a($_this, 'SessionCache') && !is_subclass_of($_this, 'SessionCache')) {
-            $_this =& SessionCache::getInstance();
-        }
-
-        if (isset($_this->_params[$param])) {
-            return $_this->_params[$param];
-        } else {
-            $app->logMsg(sprintf('Parameter is not set: %s', $param), LOG_DEBUG, __FILE__, __LINE__);
+    
+        if (isset($this->_params[$param])) {
+            return $this->_params[$param];
+        } else {
+            $app->logMsg(sprintf('Parameter is not set: %s', $param), LOG_NOTICE, __FILE__, __LINE__);
             return null;
         }
@@ -82,43 +80,39 @@
 
     /**
-     * Stores a new variable in the session cache. The $var_id is is md5'ed
+     * Stores a new variable in the session cache. The $key is is md5'ed
      * because if a variable id is a very large integer, the array_shift function
-     * will reset the key to the next largest int key. Weird behaviour I can't
+     * will reset the key to the next largest int key. Weird behavior I can't
      * understand. $session_cache[32341234123] will become $session_cache[0]
      * for example. Usage warning: if the variable is too big to fit, or is
      * old and discarded, you must provide alternative ways of accessing the data.
      *
+     * @param str   $key        An identifier for the cached object.
      * @param mixed $var          The var to store in the session cache.
-     * @param str   $var_id       An identifyer for the cached object.
-     * @param bool  $force_it_in  If we have something really big that we
-     *                            still want to cache, setting this true
-     *                            allows this.
-     *
-     * @return string        The $var_id, or false if the object was too big to cache.
-     */
-    function putCache($var, $var_id, $force_it_in=false)
+     * @param bool  $flags      If we have something really big that we
+     *                            still want to cache, setting this to
+     *                            CACHE_IGNORE_SIZE allows this.
+     *
+     * @return bool               True on success, false otherwise.
+     */
+    function set($key, $var, $flags=0)
     {
 		$app =& App::getInstance();
 
-        if (!isset($_this) || !is_a($_this, 'SessionCache') && !is_subclass_of($_this, 'SessionCache')) {
-            $_this =& SessionCache::getInstance();
-        }
-
-        if (!$_this->getParam('enabled')) {
-            $app->logMsg(sprintf('SessionCache not enabled, not saving data.', null), LOG_DEBUG, __FILE__, __LINE__);
-            return false;
-        }
-
-        $var_id = md5($var_id);
+        if (!$this->getParam('enabled')) {
+            $app->logMsg(sprintf('Cache not enabled, not saving data.', null), LOG_DEBUG, __FILE__, __LINE__);
+            return false;
+        }
+
+        $key = md5($key);
         $serialized_var = serialize($var);
         $serialized_var_len = strlen($serialized_var);
 
-        if ($serialized_var_len >= $_this->getParam('soft_limit') && !$force_it_in) {
-            $app->logMsg(sprintf('Serialized variable (%s bytes) more than soft_limit (%s bytes).', $serialized_var_len, $_this->getParam('soft_limit')), LOG_NOTICE, __FILE__, __LINE__);
-            return false;
-        }
-
-        if ($serialized_var_len >= $_this->getParam('hard_limit')) {
-            $app->logMsg(sprintf('Serialized variable (%s bytes) more than hard_limit (%s bytes).', $serialized_var_len, $_this->getParam('hard_limit')), LOG_NOTICE, __FILE__, __LINE__);
+        if ($flags & CACHE_IGNORE_SIZE > 0 && $serialized_var_len >= $this->getParam('soft_limit')) {
+            $app->logMsg(sprintf('Serialized variable (%s bytes) more than soft_limit (%s bytes).', $serialized_var_len, $this->getParam('soft_limit')), LOG_NOTICE, __FILE__, __LINE__);
+            return false;
+        }
+
+        if ($serialized_var_len >= $this->getParam('hard_limit')) {
+            $app->logMsg(sprintf('Serialized variable (%s bytes) more than hard_limit (%s bytes).', $serialized_var_len, $this->getParam('hard_limit')), LOG_NOTICE, __FILE__, __LINE__);
             return false;
         }
@@ -127,12 +121,12 @@
             $_SESSION['_session_cache'] = array();
         } else {
-            unset($_SESSION['_session_cache'][$var_id]);
+            unset($_SESSION['_session_cache'][$key]);
             // Continue to prune the cache if it's length is too long for the new variable to fit, but keep at least MIN_ITEMS at least.
-            while (strlen(serialize($_SESSION['_session_cache'])) + $serialized_var_len >= $_this->getParam('soft_limit')
-            && sizeof($_SESSION['_session_cache']) >= $_this->getParam('min_items')) {
+            while (strlen(serialize($_SESSION['_session_cache'])) + $serialized_var_len >= $this->getParam('soft_limit')
+            && sizeof($_SESSION['_session_cache']) >= $this->getParam('min_items')) {
                 array_shift($_SESSION['_session_cache']);
             }
         }
-        $_SESSION['_session_cache'][$var_id] =& $serialized_var;
+        $_SESSION['_session_cache'][$key] =& $serialized_var;
 
         if ($serialized_var_len >= 1024000) {
@@ -140,5 +134,5 @@
         }
 
-        return $var_id;
+        return true;
     }
 
@@ -149,26 +143,22 @@
      * first.
      *
-     * @param string $var_id  The identifyer for the datum to retrieve.
+     * @param string $key  The key for the datum to retrieve.
      *
      * @return mixed          The requested datum, or false on failure.
      */
-    function getCache($var_id)
-    {
-        if (!isset($_this) || !is_a($_this, 'SessionCache') && !is_subclass_of($_this, 'SessionCache')) {
-            $_this =& SessionCache::getInstance();
-        }
-
-        if (!$_this->getParam('enabled')) {
-            return false;
-        }
-
-        $var_id = md5($var_id);
-        if (isset($_SESSION['_session_cache'][$var_id])) {
+    function get($key)
+    {
+        if (!$this->getParam('enabled')) {
+            return false;
+        }
+
+        $key = md5($key);
+        if (isset($_SESSION['_session_cache'][$key])) {
             // Move the accessed cached datum to the top of the stack. Maybe somebody knows a better way to do this?
-            $tmp =& $_SESSION['_session_cache'][$var_id];
-            unset($_SESSION['_session_cache'][$var_id]);
-            $_SESSION['_session_cache'][$var_id] =& $tmp;
+            $tmp =& $_SESSION['_session_cache'][$key];
+            unset($_SESSION['_session_cache'][$key]);
+            $_SESSION['_session_cache'][$key] =& $tmp;
             // Return the unserialized datum.
-            return unserialize($_SESSION['_session_cache'][$var_id]);
+            return unserialize($_SESSION['_session_cache'][$key]);
         } else {
             return false;
@@ -179,20 +169,16 @@
      * Tells you if the object is cached.
      *
-     * @param string $var_id  The ID of the object to check.
+     * @param string $key  The key of the object to check.
      *
      * @return bool           The return from isset().
      */
-    function isCached($var_id)
-    {
-        if (!isset($_this) || !is_a($_this, 'SessionCache') && !is_subclass_of($_this, 'SessionCache')) {
-            $_this =& SessionCache::getInstance();
-        }
-
-        if (!$_this->getParam('enabled')) {
-            return false;
-        }
-
-        $var_id = md5($var_id);
-        return isset($_SESSION['_session_cache'][$var_id]);
+    function exists($key)
+    {
+        if (!$this->getParam('enabled')) {
+            return false;
+        }
+
+        $key = md5($key);
+        return isset($_SESSION['_session_cache'][$key]);
     }
 
@@ -200,17 +186,17 @@
      * Tells you if the object is cached.
      *
-     * @param string $var_id  The ID of the object to check.
+     * @param string $key  The key of the object to check.
      *
      * @return bool           The return from isset().
      */
-    function breakCache($var_id)
-    {
-        $var_id = md5($var_id);
-        if (isset($_SESSION['_session_cache'][$var_id])) {
-            unset($_SESSION['_session_cache'][$var_id]);
-        }
-    }
-
-// END SessionCache
+    function delete($key)
+    {
+        $key = md5($key);
+        if (isset($_SESSION['_session_cache'][$key])) {
+            unset($_SESSION['_session_cache'][$key]);
+        }
+    }
+
+// END Cache
 }
 
Index: branches/2.0singleton/lib/SortOrder.inc.php
===================================================================
--- branches/2.0singleton/lib/SortOrder.inc.php	(revision 132)
+++ branches/2.0singleton/lib/SortOrder.inc.php	(revision 135)
@@ -78,7 +78,7 @@
         if (!empty($new_sort_by)) {
             $this->sort_by = $new_sort_by;
-            $prefs->setValue('sort_by', $this->sort_by, $_SERVER['PHP_SELF']);
+            $prefs->set('sort_by', $this->sort_by, $_SERVER['PHP_SELF']);
         } else if ($prefs->exists('sort_by', $_SERVER['PHP_SELF'])) {
-            $this->sort_by = $prefs->getValue('sort_by', $_SERVER['PHP_SELF']);
+            $this->sort_by = $prefs->get('sort_by', $_SERVER['PHP_SELF']);
         } else {
             $this->sort_by = $default_sort;
@@ -92,7 +92,7 @@
         if (!empty($new_order)) {
             $this->order = $new_order;
-            $prefs->setValue('sort_order', $this->order, $_SERVER['PHP_SELF']);
+            $prefs->set('sort_order', $this->order, $_SERVER['PHP_SELF']);
         } else if ($prefs->exists('sort_order', $_SERVER['PHP_SELF'])) {
-            $this->order = $prefs->getValue('sort_order', $_SERVER['PHP_SELF']);
+            $this->order = $prefs->get('sort_order', $_SERVER['PHP_SELF']);
         } else {
             $this->order = $default_order;
@@ -116,5 +116,5 @@
         if (isset($sort)) {
             $this->sort_by = $sort;
-            $prefs->setValue('sort_by', $this->sort_by, $_SERVER['PHP_SELF']);
+            $prefs->set('sort_by', $this->sort_by, $_SERVER['PHP_SELF']);
         }
 
@@ -122,5 +122,5 @@
         if (isset($order)) {
             $this->order = $order;
-            $prefs->setValue('sort_order', $this->order, $_SERVER['PHP_SELF']);
+            $prefs->set('sort_order', $this->order, $_SERVER['PHP_SELF']);
         }
     }
Index: branches/2.0singleton/lib/SpellCheck.inc.php
===================================================================
--- branches/2.0singleton/lib/SpellCheck.inc.php	(revision 132)
+++ branches/2.0singleton/lib/SpellCheck.inc.php	(revision 135)
@@ -116,9 +116,9 @@
     {
 		$app =& App::getInstance();
-
+    
         if (isset($this->_params[$param])) {
             return $this->_params[$param];
         } else {
-            $app->logMsg(sprintf('Parameter is not set: %s', $param), LOG_DEBUG, __FILE__, __LINE__);
+            $app->logMsg(sprintf('Parameter is not set: %s', $param), LOG_NOTICE, __FILE__, __LINE__);
             return null;
         }
Index: branches/2.0singleton/lib/Upload.inc.php
===================================================================
--- branches/2.0singleton/lib/Upload.inc.php	(revision 132)
+++ branches/2.0singleton/lib/Upload.inc.php	(revision 135)
@@ -96,9 +96,9 @@
     {
 		$app =& App::getInstance();
-
+    
         if (isset($this->_params[$param])) {
             return $this->_params[$param];
         } else {
-            $app->logMsg(sprintf('Parameter is not set: %s', $param), LOG_DEBUG, __FILE__, __LINE__);
+            $app->logMsg(sprintf('Parameter is not set: %s', $param), LOG_NOTICE, __FILE__, __LINE__);
             return null;
         }
