Index: trunk/bin/install.sh
===================================================================
--- trunk/bin/install.sh	(revision 51)
+++ 	(revision )
@@ -1,22 +1,0 @@
-#!/bin/sh
-
-# Codebase installation script accompanies wwwsync to help install 
-# of codebase enabled sites.
-# Quinn Comendant <quinn@strangecode.com> 25 Dec 2004 
-
-sitebase=`expr $0 : "\(.*\)/codebase/bin/install.sh"`;
-
-# Ensure log directory exists and is writable.
-if [ ! -d "$sitebase/log" ]; then
-    mkdir "$sitebase/log";
-fi
-chmod 777 "$sitebase/log";
-
-# If old log locations exists, copy to new directory.
-if [ `ls -1 $sitebase/codebase/logs/ | wc -l` -gt 0 ]; then
-    echo "Moving logs to new log directory: $sitebase/log/";
-    mv -vfb $sitebase/codebase/logs/* $sitebase/log/;
-fi
-
-# Write site install date.
-echo `date '+%Y-%m-%d %H:%M:%S'` >> "$sitebase/wwwsynclog";
Index: trunk/lib/App.inc.php
===================================================================
--- trunk/lib/App.inc.php	(revision 51)
+++ trunk/lib/App.inc.php	(revision 53)
@@ -162,5 +162,5 @@
     function setParam($param=null)
     {
-        if (!isset($this) || !is_a($this, 'App')) {
+        if (!isset($this) || !is_a($this, 'App') && !is_subclass_of($this, 'App')) {
             $this =& App::getInstance();
         }
@@ -181,5 +181,5 @@
     function &getParam($param=null)
     {
-        if (!isset($this) || !is_a($this, 'App')) {
+        if (!isset($this) || !is_a($this, 'App') && !is_subclass_of($this, 'App')) {
             $this =& App::getInstance();
         }
@@ -356,5 +356,5 @@
     function raiseMsg($message, $type=MSG_NOTICE, $file=null, $line=null)
     {
-        if (!isset($this) || !is_a($this, 'App')) {
+        if (!isset($this) || !is_a($this, 'App') && !is_subclass_of($this, 'App')) {
             $this =& App::getInstance();
         }
@@ -391,5 +391,5 @@
     function getRaisedMessages()
     {
-        if (!isset($this) || !is_a($this, 'App')) {
+        if (!isset($this) || !is_a($this, 'App') && !is_subclass_of($this, 'App')) {
             $this =& App::getInstance();
         }
@@ -415,5 +415,5 @@
     function clearRaisedMessages()
     {
-        if (!isset($this) || !is_a($this, 'App')) {
+        if (!isset($this) || !is_a($this, 'App') && !is_subclass_of($this, 'App')) {
             $this =& App::getInstance();
         }
@@ -435,5 +435,5 @@
     function printRaisedMessages()
     {
-        if (!isset($this) || !is_a($this, 'App')) {
+        if (!isset($this) || !is_a($this, 'App') && !is_subclass_of($this, 'App')) {
             $this =& App::getInstance();
         }
@@ -493,5 +493,5 @@
         static $previous_events = array();
 
-        if (!isset($this) || !is_a($this, 'App')) {
+        if (!isset($this) || !is_a($this, 'App') && !is_subclass_of($this, 'App')) {
             $this =& App::getInstance();
         }
@@ -537,4 +537,5 @@
             'type'      => $this->logPriorityToString($priority),
             'file:line' => "$file : $line",
+            'url'       => (isset($_SERVER['PHP_SELF']) ? $_SERVER['PHP_SELF'] : ''),
             'message'   => $message
         );
@@ -611,5 +612,5 @@
     function carryQuery($query_key)
     {
-        if (!isset($this) || !is_a($this, 'App')) {
+        if (!isset($this) || !is_a($this, 'App') && !is_subclass_of($this, 'App')) {
             $this =& App::getInstance();
         }
@@ -643,5 +644,5 @@
     function url($url, $carry_args=null, $always_include_sid=false)
     {
-        if (!isset($this) || !is_a($this, 'App')) {
+        if (!isset($this) || !is_a($this, 'App') && !is_subclass_of($this, 'App')) {
             $this =& App::getInstance();
         }
@@ -738,5 +739,5 @@
     function oHREF($url, $carry_args=null, $always_include_sid=false)
     {
-        if (!isset($this) || !is_a($this, 'App')) {
+        if (!isset($this) || !is_a($this, 'App') && !is_subclass_of($this, 'App')) {
             $this =& App::getInstance();
         }
@@ -762,5 +763,5 @@
     function printHiddenSession($carry_args=null)
     {
-        if (!isset($this) || !is_a($this, 'App')) {
+        if (!isset($this) || !is_a($this, 'App') && !is_subclass_of($this, 'App')) {
             $this =& App::getInstance();
         }
@@ -824,5 +825,5 @@
     function dieURL($url, $carry_args=null, $always_include_sid=false)
     {
-        if (!isset($this) || !is_a($this, 'App')) {
+        if (!isset($this) || !is_a($this, 'App') && !is_subclass_of($this, 'App')) {
             $this =& App::getInstance();
         }
@@ -863,5 +864,5 @@
     function dieBoomerangURL($id=null, $carry_args=null)
     {
-        if (!isset($this) || !is_a($this, 'App')) {
+        if (!isset($this) || !is_a($this, 'App') && !is_subclass_of($this, 'App')) {
             $this =& App::getInstance();
         }
@@ -908,5 +909,5 @@
     function setBoomerangURL($url=null, $id=null)
     {
-        if (!isset($this) || !is_a($this, 'App')) {
+        if (!isset($this) || !is_a($this, 'App') && !is_subclass_of($this, 'App')) {
             $this =& App::getInstance();
         }
@@ -949,5 +950,5 @@
     function getBoomerangURL($id=null)
     {
-        if (!isset($this) || !is_a($this, 'App')) {
+        if (!isset($this) || !is_a($this, 'App') && !is_subclass_of($this, 'App')) {
             $this =& App::getInstance();
         }
@@ -977,5 +978,5 @@
     function deleteBoomerangURL($id=null)
     {
-        if (!isset($this) || !is_a($this, 'App')) {
+        if (!isset($this) || !is_a($this, 'App') && !is_subclass_of($this, 'App')) {
             $this =& App::getInstance();
         }
@@ -1002,5 +1003,5 @@
     function validBoomerangURL($id=null, $use_nonspecificboomerang=false)
     {
-        if (!isset($this) || !is_a($this, 'App')) {
+        if (!isset($this) || !is_a($this, 'App') && !is_subclass_of($this, 'App')) {
             $this =& App::getInstance();
         }
@@ -1030,15 +1031,15 @@
 
         if ('' == $url) {
-            $this->logMsg(sprintf('validBoomerangURL(%s) not valid, empty!', $id), LOG_NOTICE, __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_NOTICE, __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_NOTICE, __FILE__, __LINE__);
+            $this->logMsg(sprintf('validBoomerangURL(%s) not valid, boomerang_time too short: %s', $id, time() - $boomerang_time), LOG_DEBUG, __FILE__, __LINE__);
             return false;
         }
@@ -1054,5 +1055,5 @@
     function sslOn()
     {
-        if (!isset($this) || !is_a($this, 'App')) {
+        if (!isset($this) || !is_a($this, 'App') && !is_subclass_of($this, 'App')) {
             $this =& App::getInstance();
         }
@@ -1065,5 +1066,5 @@
         }
 
-        if ('on' != getenv('HTTPS') && $this->getParam('ssl_enabled') && in_array('mod_ssl', $modules)) {
+        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.
@@ -1079,5 +1080,5 @@
     function sslOff()
     {
-        if ('on' == getenv('HTTPS')) {
+        if ('' != getenv('HTTPS')) {
             $this->dieURL('http://' . getenv('HTTP_HOST') . getenv('REQUEST_URI'), null, true);
         }
Index: trunk/lib/Captcha.inc.php
===================================================================
--- trunk/lib/Captcha.inc.php	(revision 51)
+++ trunk/lib/Captcha.inc.php	(revision 53)
@@ -8,8 +8,21 @@
  * @author  Quinn Comendant <quinn@strangecode.com>
  * @version 1.0
+-------------------------------------------------------------------------------------
+// Example.
+
+// Instantiate new Captcha. This automatically generates a new 4-digit captcha number.
+$captcha = new Captcha();
+
+<!-- HTML form for captcha -->
+<label for="sc-captcha"><?php echo _("Reverse Turing Test") ?></label>
+<p class="help"><?php echo _("Please type the following number to prove you are a human. This is a measure to prevent spam robots from submitting this form.") ?></p>
+<pre style="font-size: 0.5em;"><?php $captcha->printAsciiNumber() ?></pre>
+<?php $captcha->printForm() ?>
+-------------------------------------------------------------------------------------
  */
 class Captcha {
 
     var $secret_key = 'some random seed text for the md5';
+    var $random_number;
     var $ascii_numbers = array(
         array(
@@ -95,4 +108,16 @@
         )
     );
+    
+    /**
+     * Constructor. Initialized new random number.
+     *
+     * @access  public
+     * @author  Quinn Comendant <quinn@strangecode.com>
+     * @since   20 Jan 2006 13:08:22
+     */
+    function Captcha()
+    {
+        $this->random_number = $this->_getRandomNumber();
+    }
 
     /**
@@ -129,4 +154,17 @@
 
     /**
+     * Prints the captcha ASCII numbers.
+     *
+     * @access  public
+     * @author  Quinn Comendant <quinn@strangecode.com>
+     * @since   07 Dec 2005 22:09:04
+     */
+    function printAsciiNumber()
+    {
+        $ascii = $this->getAsciiNumber($this->random_number);
+        ?><pre name="sc-captcha" id="sc-captcha"><?php echo $ascii ?></pre><?php
+    }
+
+    /**
      * Prints a form to enter captcha, including the required hidden hash form.
      *
@@ -137,13 +175,8 @@
     function printForm()
     {
-        $number = $this->_getRandomNumber();
-        $hash = $this->_getMD5key($number);
-        $ascii = $this->getAsciiNumber($number);
+        $hash = $this->_getMD5key($this->random_number);
         ?>
-        <label for="sc-captcha"><?php echo _("Reverse Turing Test") ?></label>
-        <p class="help"><?php echo _("Please type the following number to prove you are a human. This is a measure to prevent spam robots from submitting this form.") ?></p>
-        <pre style="font-size: 0.5em;"><?php echo $ascii ?></pre>
-        <input name="sc-captcha" id="sc-captcha" type="text" />
-        <input name="sc-captcha-hash" type="hidden" value="<?php echo $hash ?>" />
+        <input name="sc-captcha-input" id="sc-captcha-input" type="text" />
+        <input name="sc-captcha-hash" id="sc-captcha-hash" type="hidden" value="<?php echo $hash ?>" />
         <?php
     }
@@ -160,5 +193,5 @@
     function valid()
     {
-        $number = getFormData('sc-captcha');
+        $number = getFormData('sc-captcha-input');
         $hash = getFormData('sc-captcha-hash');
 
Index: trunk/lib/DB.inc.php
===================================================================
--- trunk/lib/DB.inc.php	(revision 51)
+++ trunk/lib/DB.inc.php	(revision 53)
@@ -85,5 +85,5 @@
     function setParam($params)
     {
-        if (!isset($this) || !is_a($this, 'DB')) {
+        if (!isset($this) || !is_a($this, 'DB') && !is_subclass_of($this, 'DB')) {
             $this =& DB::getInstance();
         }
@@ -108,5 +108,5 @@
     function getParam($param)
     {
-        if (!isset($this) || !is_a($this, 'DB')) {
+        if (!isset($this) || !is_a($this, 'DB') && !is_subclass_of($this, 'DB')) {
             $this =& DB::getInstance();
         }
@@ -129,5 +129,5 @@
     function connect()
     {
-        if (!isset($this) || !is_a($this, 'DB')) {
+        if (!isset($this) || !is_a($this, 'DB') && !is_subclass_of($this, 'DB')) {
             $this =& DB::getInstance();
         }
@@ -142,4 +142,6 @@
             // Select database
             mysql_select_db($this->getParam('db_name'), $this->dbh);
+        } else {
+            App::logMsg(sprintf('mysql_connect failed.', null), LOG_ERR, __FILE__, __LINE__);
         }
 
@@ -183,5 +185,5 @@
     function close()
     {
-        if (!isset($this) || !is_a($this, 'DB')) {
+        if (!isset($this) || !is_a($this, 'DB') && !is_subclass_of($this, 'DB')) {
             $this =& DB::getInstance();
         }
@@ -204,5 +206,5 @@
     function getDBH()
     {
-        if (!isset($this) || !is_a($this, 'DB')) {
+        if (!isset($this) || !is_a($this, 'DB') && !is_subclass_of($this, 'DB')) {
             $this =& DB::getInstance();
         }
@@ -239,5 +241,5 @@
         static $_query_count = 0;
 
-        if (!isset($this) || !is_a($this, 'DB')) {
+        if (!isset($this) || !is_a($this, 'DB') && !is_subclass_of($this, 'DB')) {
             $this =& DB::getInstance();
         }
@@ -285,5 +287,5 @@
     function tableExists($table, $use_cached_results=true)
     {
-        if (!isset($this) || !is_a($this, 'DB')) {
+        if (!isset($this) || !is_a($this, 'DB') && !is_subclass_of($this, 'DB')) {
             $this =& DB::getInstance();
         }
@@ -319,5 +321,5 @@
     function columnExists($table, $columns, $strict=true, $use_cached_results=true)
     {
-        if (!isset($this) || !is_a($this, 'DB')) {
+        if (!isset($this) || !is_a($this, 'DB') && !is_subclass_of($this, 'DB')) {
             $this =& DB::getInstance();
         }
Index: trunk/lib/Email.inc.php
===================================================================
--- trunk/lib/Email.inc.php	(revision 51)
+++ trunk/lib/Email.inc.php	(revision 53)
@@ -280,5 +280,5 @@
         // Ensure message was successfully accepted for delivery.
         if (!mail($final_to, $this->_params['subject'], $final_body, $final_headers, $envelope_sender_header)) {
-            App::logMsg(sprintf('Email failure with parameters: %s, %s, %s, %s', $this->_params['to'], $this->_params['subject'], str_replace("\r\n", '', $final_headers), $envelope_sender_header), LOG_NOTICE, __FILE__, __LINE__);
+            App::logMsg(sprintf('Email failure with parameters: %s, %s, %s, %s', $this->_params['to'], $this->_params['subject'], str_replace("\r\n", ', ', $final_headers), $envelope_sender_header), LOG_NOTICE, __FILE__, __LINE__);
             return false;
         }
Index: trunk/lib/PageNumbers.inc.php
===================================================================
--- trunk/lib/PageNumbers.inc.php	(revision 51)
+++ trunk/lib/PageNumbers.inc.php	(revision 53)
@@ -248,5 +248,5 @@
         $page_numbers = array();
 
-        for ($i = 1; $i < $this->total_pages; $i++) {
+        for ($i = 1; $i <= $this->total_pages; $i++) {
             $page_numbers[] = array(
                 'number' => $i,
Index: trunk/lib/SessionCache.inc.php
===================================================================
--- trunk/lib/SessionCache.inc.php	(revision 51)
+++ trunk/lib/SessionCache.inc.php	(revision 53)
@@ -44,5 +44,5 @@
     function setParam($params)
     {
-        if (!isset($this) || !is_a($this, 'SessionCache')) {
+        if (!isset($this) || !is_a($this, 'SessionCache') && !is_subclass_of($this, 'SessionCache')) {
             $this =& SessionCache::getInstance();
         }
@@ -65,5 +65,5 @@
     function getParam($param)
     {
-        if (!isset($this) || !is_a($this, 'SessionCache')) {
+        if (!isset($this) || !is_a($this, 'SessionCache') && !is_subclass_of($this, 'SessionCache')) {
             $this =& SessionCache::getInstance();
         }
@@ -95,5 +95,5 @@
     function putCache($var, $var_id, $force_it_in=false)
     {
-        if (!isset($this) || !is_a($this, 'SessionCache')) {
+        if (!isset($this) || !is_a($this, 'SessionCache') && !is_subclass_of($this, 'SessionCache')) {
             $this =& SessionCache::getInstance();
         }
@@ -149,5 +149,5 @@
     function getCache($var_id)
     {
-        if (!isset($this) || !is_a($this, 'SessionCache')) {
+        if (!isset($this) || !is_a($this, 'SessionCache') && !is_subclass_of($this, 'SessionCache')) {
             $this =& SessionCache::getInstance();
         }
@@ -179,5 +179,5 @@
     function isCached($var_id)
     {
-        if (!isset($this) || !is_a($this, 'SessionCache')) {
+        if (!isset($this) || !is_a($this, 'SessionCache') && !is_subclass_of($this, 'SessionCache')) {
             $this =& SessionCache::getInstance();
         }
Index: trunk/lib/TemplateGlue.inc.php
===================================================================
--- trunk/lib/TemplateGlue.inc.php	(revision 51)
+++ trunk/lib/TemplateGlue.inc.php	(revision 53)
@@ -235,5 +235,5 @@
     // in the array keys.
     $ps_value_count = array_count_values($preselected);
-    if ($ps_value_count['on'] == sizeof($preselected)) {
+    if (isset($ps_value_count['on']) && $ps_value_count['on'] == sizeof($preselected)) {
         $preselected = array_keys($preselected);
     }
@@ -270,5 +270,5 @@
         }
         // Print a cell with basic named checkboxes.
-        ?><td><input type="radio" name="<?php echo $db_col; ?>" id="<?php echo $db_col; ?>" value="<?php echo $v ?>"<?php echo $checked; ?> /><label for="<?php echo $db_col ?>"><?php echo oTxt($v); ?></label></td>
+        ?><td><input type="radio" name="<?php echo $db_col; ?>" id="<?php echo $db_col . '-' . $v; ?>" value="<?php echo $v ?>"<?php echo $checked; ?> /><label class="sc-label-secondary" for="<?php echo $db_col . '-' . $v ?>"><?php echo oTxt($v); ?></label></td>
         <?php
     }
Index: trunk/lib/Utilities.inc.php
===================================================================
--- trunk/lib/Utilities.inc.php	(revision 51)
+++ trunk/lib/Utilities.inc.php	(revision 53)
@@ -200,5 +200,5 @@
  * @return  string   Encoded email.
  */
-function encodeEmail($email, $at='-at-', $dot='-dot-')
+function encodeEmail($email, $at=' at ', $dot=' dot ')
 {
     $search = array('/@/', '/\./');
Index: trunk/services/lock.php
===================================================================
--- trunk/services/lock.php	(revision 51)
+++ trunk/services/lock.php	(revision 53)
@@ -15,5 +15,7 @@
     $boom_url = strpos(getFormData('boomerang'), '/') !== false ? getFormData('boomerang') : $_SERVER['HTTP_REFERER'];
     App::setBoomerangURL($boom_url, 'lock');
-    App::setBoomerangURL($_SERVER['HTTP_REFERER'], 'cancel-lock');
+    if (isset($_SERVER['HTTP_REFERER'])) {
+        App::setBoomerangURL($_SERVER['HTTP_REFERER'], 'cancel-lock');
+    }
 }
 
Index: trunk/tests/run_tests.sh
===================================================================
--- trunk/tests/run_tests.sh	(revision 51)
+++ trunk/tests/run_tests.sh	(revision 53)
@@ -7,4 +7,4 @@
 for foo in *Test.php; 
 do
-    php $foo;
+    /usr/local/bin/php $foo;
 done;
