Index: trunk/bin/module_maker/_config.inc.php
===================================================================
--- trunk/bin/module_maker/_config.inc.php	(revision 124)
+++ trunk/bin/module_maker/_config.inc.php	(revision 136)
@@ -30,5 +30,4 @@
 
 $app =& App::getInstance('module_maker');
-
 $app->setParam(array(
     'site_name' => 'Module Maker',
@@ -43,8 +42,13 @@
     'log_screen_priority' => LOG_DEBUG,
 ));
-
 require_once 'global/db_auth.inc.php';
 
+// Start application-based functionality: database, session, environment, ini setup, etc.
+// Most configuration parameters must be set before starting the App.
 $app->start();
 
+// Global DB object. Automatically preconfigured by $app->start().
+$db =& DB::getInstance();
+
+
 ?>
Index: trunk/bin/module_maker/form_template.cli.php
===================================================================
--- trunk/bin/module_maker/form_template.cli.php	(revision 124)
+++ trunk/bin/module_maker/form_template.cli.php	(revision 136)
@@ -17,5 +17,5 @@
 
 // Get DB tables.
-$qid = DB::query("SHOW TABLES");
+$qid = $db->query("SHOW TABLES");
 while (list($row) = mysql_fetch_row($qid)) {
     $tables[] = $row;
@@ -24,9 +24,9 @@
 // Make sure requested table is in database.
 if (!in_array($db_tbl, $tables)) {
-    die(sprintf("%s Warning: %s does not exist in database %s. Please select one of: \n\n%s\n\n", basename($_SERVER['argv'][0]), $db_tbl, App::getParam('db_name'), join("\n", $tables)));
+    die(sprintf("%s Warning: %s does not exist in database %s. Please select one of: \n\n%s\n\n", basename($_SERVER['argv'][0]), $db_tbl, $app->getParam('db_name'), join("\n", $tables)));
 }
 
 // Get DB table column info.
-$qid = DB::query("DESCRIBE " . DB::escapeString($db_tbl));
+$qid = $db->query("DESCRIBE " . $db->escapeString($db_tbl));
 while ($row = mysql_fetch_row($qid)) {
     $cols[] = $row;
@@ -65,7 +65,7 @@
 <label for="$field"<\x3fphp \$fv->err('$field') \x3f>><\x3fphp echo _("$title"); \x3f></label>
 <select name="$field" id="$field" class="sc-small"><\x3fphp printSelectForm('<##>_tbl', "CONCAT(<##>_id, '&mdash;', <##>)", '$field', \$frm['$field'], true, 'ORDER BY $field ASC'); \x3f></select>
-    <span class="commanditem commandtext"><a href="<\x3fphp echo App::oHREF('<##>.php?op=add&boomerang=true'); \x3f>" onClick="javascript:return confirm('<\x3fphp echo _("Notice: You are about to leave this form page and any changes you may have made without saving will be lost."); \x3f>')"><\x3fphp echo _("Add <##>") \x3f></a></span>
+    <span class="commanditem commandtext"><a href="<\x3fphp echo \$app->oHREF('<##>.php?op=add&boomerang=true'); \x3f>" onClick="javascript:return confirm('<\x3fphp echo _("Notice: You are about to leave this form page and any changes you may have made without saving will be lost."); \x3f>')"><\x3fphp echo _("Add <##>") \x3f></a></span>
     <\x3fphp if ('' != \$frm['<##>_id']) { \x3f>
-    <span class="commanditem commandtext"><a href="<\x3fphp echo App::oHREF('<##>.php?op=edit&boomerang=true&<##>_id=' . \$frm['<##>_id']); \x3f>" onClick="javascript:return confirm('<\x3fphp echo _("Notice: You are about to leave this form page and any changes you may have made without saving will be lost."); \x3f>')"><\x3fphp echo sprintf(_("Edit <##> <em>%s</em>"), \$frm['<##>']) \x3f></a></span>
+    <span class="commanditem commandtext"><a href="<\x3fphp echo \$app->oHREF('<##>.php?op=edit&boomerang=true&<##>_id=' . \$frm['<##>_id']); \x3f>" onClick="javascript:return confirm('<\x3fphp echo _("Notice: You are about to leave this form page and any changes you may have made without saving will be lost."); \x3f>')"><\x3fphp echo sprintf(_("Edit <##> <em>%s</em>"), \$frm['<##>']) \x3f></a></span>
     <\x3fphp } \x3f>
 E_O_F;
Index: trunk/bin/module_maker/list_template.cli.php
===================================================================
--- trunk/bin/module_maker/list_template.cli.php	(revision 124)
+++ trunk/bin/module_maker/list_template.cli.php	(revision 136)
@@ -30,5 +30,5 @@
 
 // Get DB tables.
-$qid = DB::query("SHOW TABLES");
+$qid = $db->query("SHOW TABLES");
 while (list($row) = mysql_fetch_row($qid)) {
     $tables[] = $row;
@@ -37,9 +37,9 @@
 // Make sure requested table is in database.
 if (!in_array($db_tbl, $tables)) {
-    die(sprintf("%s Warning: %s does not exist in database %s. Please select one of: \n\n%s\n\n", basename($_SERVER['argv'][0]), $db_tbl, App::getParam('db_name'), join("\n", $tables)));
+    die(sprintf("%s Warning: %s does not exist in database %s. Please select one of: \n\n%s\n\n", basename($_SERVER['argv'][0]), $db_tbl, $app->getParam('db_name'), join("\n", $tables)));
 }
 
 // Get DB table column info.
-$qid = DB::query("DESCRIBE " . DB::escapeString($db_tbl));
+$qid = $db->query("DESCRIBE " . $db->escapeString($db_tbl));
 while ($row = mysql_fetch_row($qid)) {
     $cols[] = $row;
@@ -80,11 +80,11 @@
             $listrows[] = "<\x3fphp echo strlen(\$list[\$i]['$field'])<50 \x3f oTxt(\$list[\$i]['$field'], true) : oTxt(trim(substr(\$list[\$i]['$field'], 0, 50)) . '...'); \x3f>";
         } else if (preg_match('/.*(begin|start).*date.*/i', $field)) {
-            $listrows[] = "<\x3fphp echo '0000-00-00' == \$list[\$i]['$field'] ? '' : date(App::getParam('date_format'), strtotime(\$list[\$i]['$field'])); \x3f>";
+            $listrows[] = "<\x3fphp echo '0000-00-00' == \$list[\$i]['$field'] ? '' : date(\$app->getParam('date_format'), strtotime(\$list[\$i]['$field'])); \x3f>";
         } else if (preg_match('/.*(end|expire).*date.*/i', $field)) {
-            $listrows[] = "<\x3fphp echo '9999-12-31' == \$list[\$i]['$field'] ? '' : date(App::getParam('date_format'), strtotime(\$list[\$i]['$field'])); \x3f>";
+            $listrows[] = "<\x3fphp echo '9999-12-31' == \$list[\$i]['$field'] ? '' : date(\$app->getParam('date_format'), strtotime(\$list[\$i]['$field'])); \x3f>";
         } else if (preg_match('/datetime/i', $type)) {
-            $listrows[] = "<\x3fphp echo '0000-00-00 00:00:00' == \$list[\$i]['$field'] ? '' : date(App::getParam('date_format'), strtotime(\$list[\$i]['$field'])); \x3f>";
+            $listrows[] = "<\x3fphp echo '0000-00-00 00:00:00' == \$list[\$i]['$field'] ? '' : date(\$app->getParam('date_format'), strtotime(\$list[\$i]['$field'])); \x3f>";
         } else if (preg_match('/date/i', $type)) {
-            $listrows[] = "<\x3fphp echo '0000-00-00' == \$list[\$i]['$field'] ? '' : date(App::getParam('date_format'), strtotime(\$list[\$i]['$field'])); \x3f>";
+            $listrows[] = "<\x3fphp echo '0000-00-00' == \$list[\$i]['$field'] ? '' : date(\$app->getParam('date_format'), strtotime(\$list[\$i]['$field'])); \x3f>";
         } else if (preg_match('/(amount|_rate)/i', $field)) {
             $listrows[] = "<\x3fphp printf('$%01.2f', \$list[\$i]['$field']); \x3f>";
@@ -110,6 +110,6 @@
 <div id="commandbox">
 <form action="<\x3fphp echo \$_SERVER['PHP_SELF']; \x3f>" method="get">
-<\x3fphp App::printHiddenSession(false); \x3f>
-    <span class="sc-nowrap commandtext"><a href="<\x3fphp echo App::oHREF(\$_SERVER['PHP_SELF'] . '?op=add'); \x3f>"><\x3fphp echo _("Add <##>"); \x3f></a></span>
+<\x3fphp \$app->printHiddenSession(false); \x3f>
+    <span class="sc-nowrap commandtext"><a href="<\x3fphp echo \$app->oHREF(\$_SERVER['PHP_SELF'] . '?op=add'); \x3f>"><\x3fphp echo _("Add <##>"); \x3f></a></span>
     <br />
 
@@ -149,6 +149,6 @@
     <\x3fphp for (\$i = 0; \$i <= \$page->last_item - \$page->first_item && \$page->total_items > 0; \$i++) { \x3f>
     <tr>
-        <td class="sc-nowrap"><a title="<\x3fphp printf(_("Edit %s"), oTxt(\$list[\$i]['<##>'])) \x3f>" href="<\x3fphp echo App::oHREF(\$_SERVER['PHP_SELF'] . '?op=edit&$primary_key=' . \$list[\$i]['$primary_key']); \x3f>"><img src="/admin/_widgets/edit.gif" alt="Edit" width="14" height="18" border="0"></a> &nbsp;</td>
-        <td class="sc-nowrap"><a title="<\x3fphp printf(_("Versions of %s"), oTxt(\$list[\$i]['<##>'])) \x3f>" href="<\x3fphp echo App::oHREF("/admin/versions.php?record_table=$db_tbl&record_key=$primary_key&boomerang=true&record_val=" . \$list[\$i]['$primary_key']); \x3f>"><img src="/admin/_widgets/subcategory.gif" alt="" width="18" height="14" border="0" /></a> &nbsp;</td>
+        <td class="sc-nowrap"><a title="<\x3fphp printf(_("Edit %s"), oTxt(\$list[\$i]['<##>'])) \x3f>" href="<\x3fphp echo \$app->oHREF(\$_SERVER['PHP_SELF'] . '?op=edit&$primary_key=' . \$list[\$i]['$primary_key']); \x3f>"><img src="/admin/_widgets/edit.gif" alt="Edit" width="14" height="18" border="0"></a> &nbsp;</td>
+        <td class="sc-nowrap"><a title="<\x3fphp printf(_("Versions of %s"), oTxt(\$list[\$i]['<##>'])) \x3f>" href="<\x3fphp echo \$app->oHREF("/admin/versions.php?record_table=$db_tbl&record_key=$primary_key&boomerang=true&record_val=" . \$list[\$i]['$primary_key']); \x3f>"><img src="/admin/_widgets/subcategory.gif" alt="" width="18" height="14" border="0" /></a> &nbsp;</td>
 
 E_O_F;
@@ -164,5 +164,5 @@
 
 echo isset($op) ? '' : <<<E_O_F
-        <td class="sc-nowrap" align="right"><a title="<\x3fphp printf(_("Delete %s"), oTxt(\$list[\$i]['<##>'])) \x3f>" href="<\x3fphp echo App::oHREF(\$_SERVER['PHP_SELF'] . "?op=del&$primary_key=" . \$list[\$i]['$primary_key']); \x3f>" onClick="javascript:return confirm('<\x3fphp printf(_("Are you sure you want to delete the record %s? This action is permanent and cannot be undone."), oTxt(\$list[\$i]['<##>'])) \x3f>')"><img src="/admin/_widgets/delete.gif" alt="Delete" width="16" height="17" border="0"></a> &nbsp;</td>
+        <td class="sc-nowrap" align="right"><a title="<\x3fphp printf(_("Delete %s"), oTxt(\$list[\$i]['<##>'])) \x3f>" href="<\x3fphp echo \$app->oHREF(\$_SERVER['PHP_SELF'] . "?op=del&$primary_key=" . \$list[\$i]['$primary_key']); \x3f>" onClick="javascript:return confirm('<\x3fphp printf(_("Are you sure you want to delete the record %s? This action is permanent and cannot be undone."), oTxt(\$list[\$i]['<##>'])) \x3f>')"><img src="/admin/_widgets/delete.gif" alt="Delete" width="16" height="17" border="0"></a> &nbsp;</td>
     </tr>
     <\x3fphp } \x3f>
Index: trunk/bin/module_maker/module.cli.php
===================================================================
--- trunk/bin/module_maker/module.cli.php	(revision 124)
+++ trunk/bin/module_maker/module.cli.php	(revision 136)
@@ -129,5 +129,5 @@
 
 // Get DB tables.
-$qid = DB::query("SHOW TABLES");
+$qid = $db->query("SHOW TABLES");
 while (list($row) = mysql_fetch_row($qid)) {
     $tables[] = $row;
@@ -136,10 +136,10 @@
 // Make sure requested table is in database.
 if (!in_array($db_tbl, $tables)) {
-    die(sprintf("%s Warning: %s does not exist in database %s. Please select one of: \n\n%s\n\n", basename($_SERVER['argv'][0]), $db_tbl, App::getParam('db_name'), join("\n", $tables)));
+    die(sprintf("%s Warning: %s does not exist in database %s. Please select one of: \n\n%s\n\n", basename($_SERVER['argv'][0]), $db_tbl, $app->getParam('db_name'), join("\n", $tables)));
 }
 
 // Ensure requested table contains columns.
 // Get DB table column info.
-$qid = DB::query("DESCRIBE " . DB::escapeString($db_tbl));
+$qid = $db->query("DESCRIBE " . $db->escapeString($db_tbl));
 while ($row = mysql_fetch_row($qid)) {
     $cols[] = $row;
@@ -266,5 +266,5 @@
         // If file upload errors, redirect to edit operation for the inserted record.
         if (\$upload->anyErrors() || false === \$new_file) {
-            App::dieURL(\$_SERVER['PHP_SELF'] . '?op=edit&%PRIMARY_KEY%=' . \$%PRIMARY_KEY%);
+            \$app->dieURL(\$_SERVER['PHP_SELF'] . '?op=edit&%PRIMARY_KEY%=' . \$%PRIMARY_KEY%);
         }
 E_O_F;
@@ -300,5 +300,5 @@
 
 $search['date'] = '/%DATE%/';
-$replace['date'] = date(App::getParam('date_format'));
+$replace['date'] = date($app->getParam('date_format'));
 
 $search['name_plural'] = '/%NAME_PLURAL%/';
Index: trunk/bin/module_maker/skel/adm_form.ihtml
===================================================================
--- trunk/bin/module_maker/skel/adm_form.ihtml	(revision 124)
+++ trunk/bin/module_maker/skel/adm_form.ihtml	(revision 136)
@@ -2,5 +2,5 @@
 
 %ADMIN_FORM_TAG_INIT%
-<?php App::printHiddenSession(); ?>
+<?php $app->printHiddenSession(); ?>
 <input type="hidden" name="op" value="<?php echo $frm['new_op']; ?>" />
 <input type="hidden" name="%PRIMARY_KEY%" value="<?php echo $frm['%PRIMARY_KEY%']; ?>" />
Index: trunk/bin/module_maker/skel/adm_list.ihtml
===================================================================
--- trunk/bin/module_maker/skel/adm_list.ihtml	(revision 124)
+++ trunk/bin/module_maker/skel/adm_list.ihtml	(revision 136)
@@ -4,6 +4,6 @@
 <div id="commandbox">
 <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="get">
-<?php App::printHiddenSession(false); ?>
-    <span class="sc-nowrap commandtext"><a href="<?php echo App::oHREF($_SERVER['PHP_SELF'] . '?op=add'); ?>"><?php echo _("Add %ITEM_TITLE%"); ?></a></span>
+<?php $app->printHiddenSession(false); ?>
+    <span class="sc-nowrap commandtext"><a href="<?php echo $app->oHREF($_SERVER['PHP_SELF'] . '?op=add'); ?>"><?php echo _("Add %ITEM_TITLE%"); ?></a></span>
     <br />
 
@@ -17,5 +17,5 @@
 
 <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
-<?php App::printHiddenSession(); ?>
+<?php $app->printHiddenSession(); ?>
 <?php include 'list_info.ihtml'; ?>
 <table class="list">
@@ -28,8 +28,8 @@
     <?php for ($i = 0; $i <= $page->last_item - $page->first_item && $page->total_items > 0; $i++) { ?>
     <tr>
-        <td class="sc-padleft sc-nowrap"><a title="<?php printf(_("Edit %s"), oTxt($list[$i]['<##>'])) ?>" href="<?php echo App::oHREF($_SERVER['PHP_SELF'] . '?op=edit&%PRIMARY_KEY%=' . $list[$i]['%PRIMARY_KEY%']); ?>"><img src="/admin/_widgets/edit.gif" alt="Edit" width="14" height="18" border="0"></a> &nbsp;</td>
-        <td class="sc-padleft sc-nowrap"><a title="<?php printf(_("Versions of %s"), oTxt($list[$i]['<##>'])) ?>" href="<?php echo App::oHREF('/admin/versions.php?record_table=%DB_TBL%&record_key=%PRIMARY_KEY%&boomerang=true&record_val=' . $list[$i]['%PRIMARY_KEY%']); ?>"><img src="/admin/_widgets/subcategory.gif" alt="" width="18" height="14" border="0" /></a> &nbsp;</td>
+        <td class="sc-padleft sc-nowrap"><a title="<?php printf(_("Edit %s"), oTxt($list[$i]['<##>'])) ?>" href="<?php echo $app->oHREF($_SERVER['PHP_SELF'] . '?op=edit&%PRIMARY_KEY%=' . $list[$i]['%PRIMARY_KEY%']); ?>"><img src="/admin/_widgets/edit.gif" alt="Edit" width="14" height="18" border="0"></a> &nbsp;</td>
+        <td class="sc-padleft sc-nowrap"><a title="<?php printf(_("Versions of %s"), oTxt($list[$i]['<##>'])) ?>" href="<?php echo $app->oHREF('/admin/versions.php?record_table=%DB_TBL%&record_key=%PRIMARY_KEY%&boomerang=true&record_val=' . $list[$i]['%PRIMARY_KEY%']); ?>"><img src="/admin/_widgets/subcategory.gif" alt="" width="18" height="14" border="0" /></a> &nbsp;</td>
 %ADM_LIST_ROWS%
-        <td class="sc-padleft sc-nowrap" align="right"><a title="<?php printf(_("Delete %s"), oTxt($list[$i]['<##>'])) ?>" href="<?php echo App::oHREF($_SERVER['PHP_SELF'] . "?op=del&%PRIMARY_KEY%=" . $list[$i]['%PRIMARY_KEY%']); ?>" onClick="javascript:return confirm('<?php printf(_("Are you sure you want to delete the record %s? This action is permanent and cannot be undone."), oTxt($list[$i]['<##>'])) ?>')"><img src="/admin/_widgets/delete.gif" alt="Delete" width="16" height="17" border="0"></a> &nbsp;</td>
+        <td class="sc-padleft sc-nowrap" align="right"><a title="<?php printf(_("Delete %s"), oTxt($list[$i]['<##>'])) ?>" href="<?php echo $app->oHREF($_SERVER['PHP_SELF'] . "?op=del&%PRIMARY_KEY%=" . $list[$i]['%PRIMARY_KEY%']); ?>" onClick="javascript:return confirm('<?php printf(_("Are you sure you want to delete the record %s? This action is permanent and cannot be undone."), oTxt($list[$i]['<##>'])) ?>')"><img src="/admin/_widgets/delete.gif" alt="Delete" width="16" height="17" border="0"></a> &nbsp;</td>
     </tr>
     <?php } ?>
Index: trunk/bin/module_maker/skel/admin.php
===================================================================
--- trunk/bin/module_maker/skel/admin.php	(revision 124)
+++ trunk/bin/module_maker/skel/admin.php	(revision 136)
@@ -11,5 +11,5 @@
 $auth->requireLogin();
 // $auth->requireAccessClearance(ZONE_ADMIN_%NAME_UPPER%);
-App::sslOn();
+$app->sslOn();
 
 require_once 'codebase/lib/PageNumbers.inc.php';
@@ -33,4 +33,6 @@
 $fv = new FormValidator();
 
+$cache =& SessionCache::getInstance();
+
 %SORT_ORDER%
 
@@ -41,6 +43,6 @@
 
 // Search limiters retain their values between page requests.
-App::carryQuery('search_query');
-App::carryQuery('filter_<##>');
+$app->carryQuery('search_query');
+$app->carryQuery('filter_<##>');
 %ADMIN_UPLOAD_CONFIG%
 /******************************************************************************
@@ -51,10 +53,10 @@
 // allows us to remember which page we came from so we can go back there.
 if (getFormData('boomerang', false) && isset($_SERVER['HTTP_REFERER'])) {
-    App::setBoomerangURL($_SERVER['HTTP_REFERER'], '%NAME_PLURAL%');
+    $app->setBoomerangURL($_SERVER['HTTP_REFERER'], '%NAME_PLURAL%');
 }
 
 if (getFormData('break_list_cache', false)) {
     // Break the cache because we are changing the list data.
-    SessionCache::breakCache($_SERVER['PHP_SELF']);
+    $cache->delete($_SERVER['PHP_SELF']);
 }
 
@@ -81,10 +83,10 @@
 //     $auth->requireAccessClearance(ZONE_ADMIN_%NAME_UPPER%_FUNC_DELETE);
     deleteRecord(getFormData('%PRIMARY_KEY%'));%ADMIN_UPLOAD_DEL%
-    if (App::validBoomerangURL('%NAME_PLURAL%')) {
+    if ($app->validBoomerangURL('%NAME_PLURAL%')) {
         // Display boomerang page.
-        App::dieBoomerangURL('%NAME_PLURAL%');
+        $app->dieBoomerangURL('%NAME_PLURAL%');
     }
     // Display default page.
-    App::dieURL($_SERVER['PHP_SELF']);
+    $app->dieURL($_SERVER['PHP_SELF']);
     break;
 
@@ -92,10 +94,10 @@
 //     $auth->requireAccessClearance(ZONE_ADMIN_%NAME_UPPER%_FUNC_ADD);
     if (getFormdata('cancel', false)) {
-        if (App::validBoomerangURL('%NAME_PLURAL%')) {
+        if ($app->validBoomerangURL('%NAME_PLURAL%')) {
             // Display boomerang page.
-            App::dieBoomerangURL('%NAME_PLURAL%');
+            $app->dieBoomerangURL('%NAME_PLURAL%');
         }
         // Display default page.
-        App::dieURL($_SERVER['PHP_SELF']);
+        $app->dieURL($_SERVER['PHP_SELF']);
     }
     validateInput();
@@ -109,11 +111,11 @@
         if (getFormdata('repeat', false)) {
             // Display function again.
-            App::dieURL($_SERVER['PHP_SELF'] . '?op=add');
-        } else if (App::validBoomerangURL('%NAME_PLURAL%')) {
+            $app->dieURL($_SERVER['PHP_SELF'] . '?op=add');
+        } else if ($app->validBoomerangURL('%NAME_PLURAL%')) {
             // Display boomerang page.
-            App::dieBoomerangURL('%NAME_PLURAL%');
+            $app->dieBoomerangURL('%NAME_PLURAL%');
         }
         // Display default page.
-        App::dieURL($_SERVER['PHP_SELF']);
+        $app->dieURL($_SERVER['PHP_SELF']);
     }
     break;
@@ -122,6 +124,6 @@
 //     $auth->requireAccessClearance(ZONE_ADMIN_%NAME_UPPER%_FUNC_EDIT);
     if (getFormdata('reset', false)) {
-        App::raiseMsg(_("Saved values have been reloaded."), MSG_NOTICE, __FILE__, __LINE__);
-        App::dieURL($_SERVER['PHP_SELF'] . '?op=edit&%PRIMARY_KEY%=' . getFormData('%PRIMARY_KEY%'));
+        $app->raiseMsg(_("Saved values have been reloaded."), MSG_NOTICE, __FILE__, __LINE__);
+        $app->dieURL($_SERVER['PHP_SELF'] . '?op=edit&%PRIMARY_KEY%=' . getFormData('%PRIMARY_KEY%'));
     }
     if (getFormdata('cancel', false)) {
@@ -129,10 +131,10 @@
         $lock->select('%DB_TBL%', '%PRIMARY_KEY%', getFormData('%PRIMARY_KEY%'));
         $lock->remove();
-        if (App::validBoomerangURL('%NAME_PLURAL%')) {
+        if ($app->validBoomerangURL('%NAME_PLURAL%')) {
             // Display boomerang page.
-            App::dieBoomerangURL('%NAME_PLURAL%');
+            $app->dieBoomerangURL('%NAME_PLURAL%');
         }
         // Display default page.
-        App::dieURL($_SERVER['PHP_SELF']);
+        $app->dieURL($_SERVER['PHP_SELF']);
     }
     validateInput();
@@ -146,16 +148,16 @@
         if (getFormdata('repeat', false)) {
             // Display edit function with next available ID.
-            $qid = DB::query("SELECT %PRIMARY_KEY% FROM %DB_TBL% WHERE %PRIMARY_KEY% > '" . DB::escapeString(getFormData('%PRIMARY_KEY%')) . "' ORDER BY %PRIMARY_KEY% ASC LIMIT 1");
+            $qid = $db->query("SELECT %PRIMARY_KEY% FROM %DB_TBL% WHERE %PRIMARY_KEY% > '" . $db->escapeString(getFormData('%PRIMARY_KEY%')) . "' ORDER BY %PRIMARY_KEY% ASC LIMIT 1");
             if (list($next_id) = mysql_fetch_row($qid)) {
-                App::dieURL($_SERVER['PHP_SELF'] . '?op=edit&%PRIMARY_KEY%=' . $next_id);
+                $app->dieURL($_SERVER['PHP_SELF'] . '?op=edit&%PRIMARY_KEY%=' . $next_id);
             } else {
-                App::raiseMsg(_("Cannot edit next, the end of the list was reached"), MSG_NOTICE, __FILE__, __LINE__);
+                $app->raiseMsg(_("Cannot edit next, the end of the list was reached"), MSG_NOTICE, __FILE__, __LINE__);
             }
-        } else if (App::validBoomerangURL('%NAME_PLURAL%')) {
+        } else if ($app->validBoomerangURL('%NAME_PLURAL%')) {
             // Display boomerang page.
-            App::dieBoomerangURL('%NAME_PLURAL%');
+            $app->dieBoomerangURL('%NAME_PLURAL%');
         }
         // Display default page.
-        App::dieURL($_SERVER['PHP_SELF']);
+        $app->dieURL($_SERVER['PHP_SELF']);
     }
     break;
@@ -164,5 +166,5 @@
 //     $auth->requireAccessClearance(ZONE_ADMIN_PROGRAMS_FUNC_REORDER);
     updateRank(getFormData('rank'));
-    App::dieURL($_SERVER['PHP_SELF']);
+    $app->dieURL($_SERVER['PHP_SELF']);
     break;
 
@@ -207,5 +209,6 @@
 {
     global $lock;
-
+	$db =& DB::getInstance();
+	
     $lock->select('%DB_TBL%', '%PRIMARY_KEY%', $id);
     if ($lock->isLocked() && !$lock->isMine()) {
@@ -214,13 +217,13 @@
 
     // Get the information for the form.
-    $qid = DB::query("
+    $qid = $db->query("
         SELECT *
         FROM %DB_TBL%
-        WHERE %PRIMARY_KEY% = '" . DB::escapeString($id) . "'
+        WHERE %PRIMARY_KEY% = '" . $db->escapeString($id) . "'
     ");
     if (!$frm = mysql_fetch_assoc($qid)) {
-        App::logMsg('Could not find record with %PRIMARY_KEY%: ' . $id, LOG_WARNING, __FILE__, __LINE__);
-        App::raiseMsg(sprintf(_("The requested record %s could not be found."), $id), MSG_ERR, __FILE__, __LINE__);
-        App::dieBoomerangURL();
+        $app->logMsg('Could not find record with %PRIMARY_KEY%: ' . $id, LOG_WARNING, __FILE__, __LINE__);
+        $app->raiseMsg(sprintf(_("The requested record %s could not be found."), $id), MSG_ERR, __FILE__, __LINE__);
+        $app->dieBoomerangURL();
     }
 
@@ -246,5 +249,7 @@
 {
     global $lock;
-
+	$db =& DB::getInstance();
+	$cache =& SessionCache::getInstance();
+	
     $lock->select('%DB_TBL%', '%PRIMARY_KEY%', $id);
     if ($lock->isLocked() && !$lock->isMine()) {
@@ -253,22 +258,22 @@
 
     // Break the cache because we are changing the list data.
-    SessionCache::breakCache($_SERVER['PHP_SELF']);
+    $cache->delete($_SERVER['PHP_SELF']);
 
     // Get the information for this object.
-    $qid = DB::query("
+    $qid = $db->query("
         SELECT <##>
         FROM %DB_TBL%
-        WHERE %PRIMARY_KEY% = '" . DB::escapeString($id) . "'
+        WHERE %PRIMARY_KEY% = '" . $db->escapeString($id) . "'
     ");
     if (! list($name) = mysql_fetch_row($qid)) {
-        App::logMsg('Could not find record with %PRIMARY_KEY%: ' . $id, LOG_WARNING, __FILE__, __LINE__);
-        App::raiseMsg(sprintf(_("The requested record %s could not be found."), $id), MSG_ERR, __FILE__, __LINE__);
-        App::dieBoomerangURL();
+        $app->logMsg('Could not find record with %PRIMARY_KEY%: ' . $id, LOG_WARNING, __FILE__, __LINE__);
+        $app->raiseMsg(sprintf(_("The requested record %s could not be found."), $id), MSG_ERR, __FILE__, __LINE__);
+        $app->dieBoomerangURL();
     }
 
     // Delete the record.
-    DB::query("DELETE FROM %DB_TBL% WHERE %PRIMARY_KEY% = '" . DB::escapeString($id) . "'");
-
-    App::raiseMsg(sprintf(_("The %ITEM_TITLE% <strong>%s</strong> has been deleted."), $name), MSG_SUCCESS, __FILE__, __LINE__);
+    $db->query("DELETE FROM %DB_TBL% WHERE %PRIMARY_KEY% = '" . $db->escapeString($id) . "'");
+
+    $app->raiseMsg(sprintf(_("The %ITEM_TITLE% <strong>%s</strong> has been deleted."), $name), MSG_SUCCESS, __FILE__, __LINE__);
 
     // Unlock record.
@@ -279,10 +284,12 @@
 {
     global $auth;
-
+	$db =& DB::getInstance();
+	$cache =& SessionCache::getInstance();
+	
     // Break the cache because we are changing the list data.
-    SessionCache::breakCache($_SERVER['PHP_SELF']);
+    $cache->delete($_SERVER['PHP_SELF']);
 
 %INSERT%
-    $last_insert_id = mysql_insert_id(DB::getDBH());
+    $last_insert_id = mysql_insert_id($db->getDBH());
 
     // Create version.
@@ -290,5 +297,5 @@
     $version->create('%DB_TBL%', '%PRIMARY_KEY%', $last_insert_id, $frm['<##>']);
 
-    App::raiseMsg(sprintf(_("The %ITEM_TITLE% <strong>%s</strong> has been added."), $frm['<##>']), MSG_SUCCESS, __FILE__, __LINE__);
+    $app->raiseMsg(sprintf(_("The %ITEM_TITLE% <strong>%s</strong> has been added."), $frm['<##>']), MSG_SUCCESS, __FILE__, __LINE__);
 
     return $last_insert_id;
@@ -297,6 +304,8 @@
 function updateRecord($frm)
 {
-    global $auth, $lock;
-
+	global $auth, $lock;
+	$app =& App::getInstance();
+    $cache =& SessionCache::getInstance();
+    
     $lock->select('%DB_TBL%', '%PRIMARY_KEY%', $frm['%PRIMARY_KEY%']);
     if ($lock->isLocked() && !$lock->isMine()) {
@@ -305,5 +314,5 @@
 
     // Break the cache because we are changing the list data.
-    SessionCache::breakCache($_SERVER['PHP_SELF']);
+    $cache->delete($_SERVER['PHP_SELF']);
 
 %UPDATE%
@@ -313,5 +322,5 @@
     $version->create('%DB_TBL%', '%PRIMARY_KEY%', $frm['%PRIMARY_KEY%'], $frm['<##>']);
 
-    App::raiseMsg(sprintf(_("The %ITEM_TITLE% <strong>%s</strong> has been updated."), $frm['<##>']), MSG_SUCCESS, __FILE__, __LINE__);
+    $app->raiseMsg(sprintf(_("The %ITEM_TITLE% <strong>%s</strong> has been updated."), $frm['<##>']), MSG_SUCCESS, __FILE__, __LINE__);
 
     // Unlock record.
@@ -323,5 +332,8 @@
     global $page;
     global $so;
-
+	$db =& DB::getInstance();
+	$prefs =& Prefs::getInstance();
+	$cache =& SessionCache::getInstance();
+	
     $where_clause = '';
 
@@ -336,9 +348,9 @@
     if (getFormData('filter_<##>', false)) {
         // Limit by filter.
-        $where_clause .= (empty($where_clause) ? 'WHERE' : 'AND') . " <##> = '" . DB::escapeString(getFormData('filter_<##>')) . "'";
+        $where_clause .= (empty($where_clause) ? 'WHERE' : 'AND') . " <##> = '" . $db->escapeString(getFormData('filter_<##>')) . "'";
     }
 
     // Count the total number of records so we can do something about the page numbers.
-    $qid = DB::query("
+    $qid = $db->query("
         SELECT COUNT(*)
         FROM %DB_TBL%
@@ -371,15 +383,15 @@
     // without knowing the hash.
     $cache_hash = md5($sql . '|' . $page->total_items);
-    if (Prefs::getValue('cache_hash', $_SERVER['PHP_SELF']) != $cache_hash) {
-        SessionCache::breakCache($_SERVER['PHP_SELF']);
-        Prefs::setValue('cache_hash', $cache_hash, $_SERVER['PHP_SELF']);
-    }
-
-    if (SessionCache::isCached($_SERVER['PHP_SELF'])) {
+    if ($prefs->get('cache_hash', $_SERVER['PHP_SELF']) != $cache_hash) {
+        $cache->delete($_SERVER['PHP_SELF']);
+        $prefs->set('cache_hash', $cache_hash, $_SERVER['PHP_SELF']);
+    }
+
+    if ($cache->exists($_SERVER['PHP_SELF'])) {
         // Get the cached results.
-        $list = SessionCache::getCache($_SERVER['PHP_SELF']);
+        $list = $cache->get($_SERVER['PHP_SELF']);
     } else {
         // If the list is not already cached, query now.
-        $qid = DB::query($sql);
+        $qid = $db->query($sql);
         // Fill an array with the items for this page.
         while ($row = mysql_fetch_assoc($qid)) {
@@ -389,5 +401,5 @@
         if (isset($list) && !empty($list)) {
             // Cache the results.
-            SessionCache::putCache($list, $_SERVER['PHP_SELF']);
+            $cache->set($list, $_SERVER['PHP_SELF']);
         }
     }
@@ -398,11 +410,14 @@
 function updateRank($ranks)
 {
+	$db =& DB::getInstance();
+	$cache =& SessionCache::getInstance();
+	
     if (!is_array($ranks)) {
-        App::logMsg('Saving rank failed, data posted is not an array: ' . $ranks, LOG_ERR, __FILE__, __LINE__);
+        $app->logMsg('Saving rank failed, data posted is not an array: ' . $ranks, LOG_ERR, __FILE__, __LINE__);
         return false;
     }
 
     // Break the cache because we are changing the list data.
-    SessionCache::breakCache($_SERVER['PHP_SELF']);
+    $cache->delete($_SERVER['PHP_SELF']);
 
     // Count the ranks with invalid numbers
@@ -416,14 +431,14 @@
             $unspecified_counter++;
         }
-        DB::query("
+        $db->query("
             UPDATE %DB_TBL% SET
-                rank = '" . DB::escapeString($new_rank) . "'
-            WHERE %PRIMARY_KEY% = '" . DB::escapeString($id) . "'
+                rank = '" . $db->escapeString($new_rank) . "'
+            WHERE %PRIMARY_KEY% = '" . $db->escapeString($id) . "'
         ");
     }
 
-    App::raiseMsg(_("Records have been reordered with the new rank."), MSG_SUCCESS, __FILE__, __LINE__);
+    $app->raiseMsg(_("Records have been reordered with the new rank."), MSG_SUCCESS, __FILE__, __LINE__);
     if ($unspecified_counter > 0) {
-        App::raiseMsg(sprintf(_("%s items with unspecified ranks were automatically assigned a rank of 10000."), $unspecified_counter), MSG_NOTICE, __FILE__, __LINE__);
+        $app->raiseMsg(sprintf(_("%s items with unspecified ranks were automatically assigned a rank of 10000."), $unspecified_counter), MSG_NOTICE, __FILE__, __LINE__);
     }
 }
Index: trunk/bin/module_maker/skel/public.ihtml
===================================================================
--- trunk/bin/module_maker/skel/public.ihtml	(revision 124)
+++ trunk/bin/module_maker/skel/public.ihtml	(revision 136)
@@ -1,4 +1,4 @@
 <p><?php echo nl2br(fancyTxt(oTxt($item['content'], true))); ?></p>
-<p><em><?php echo sprintf(_("Published %s"), date(App::getParam('date_format'), strtotime($item['<##>']))); ?></em></p>
+<p><em><?php echo sprintf(_("Published %s"), date($app->getParam('date_format'), strtotime($item['<##>']))); ?></em></p>
 
 <!--
Index: trunk/bin/module_maker/skel/public.php
===================================================================
--- trunk/bin/module_maker/skel/public.php	(revision 124)
+++ trunk/bin/module_maker/skel/public.php	(revision 136)
@@ -34,7 +34,7 @@
 
     // Get requested record.
-    $qid = DB::query("
+    $qid = $db->query("
         SELECT * FROM %DB_TBL%
-        WHERE %PRIMARY_KEY% = '" . DB::escapeString(getFormData('%PRIMARY_KEY%')) . "'
+        WHERE %PRIMARY_KEY% = '" . $db->escapeString(getFormData('%PRIMARY_KEY%')) . "'
         AND publish = 'true'
         <##>AND (publish_date <= CURDATE() OR publish_date = '0000-00-00')
@@ -42,13 +42,13 @@
     ");
     if (!$item = mysql_fetch_assoc($qid)) {
-        App::raiseMsg(_("Sorry that %ITEM_TITLE% could not be found"), MSG_WARNING, __FILE__, __LINE__);
-        App::dieBoomerangURL();
+        $app->raiseMsg(_("Sorry that %ITEM_TITLE% could not be found"), MSG_WARNING, __FILE__, __LINE__);
+        $app->dieBoomerangURL();
     }
 
     // Update the hit counter for this record.
-    DB::query("
+    $db->query("
         UPDATE %DB_TBL%
         SET hit_count = hit_count + 1
-        WHERE %PRIMARY_KEY% = '" . DB::escapeString(getFormData('%PRIMARY_KEY%')) . "'
+        WHERE %PRIMARY_KEY% = '" . $db->escapeString(getFormData('%PRIMARY_KEY%')) . "'
     ");
 
@@ -61,5 +61,5 @@
     // Get the DEFAULT list.
     $%NAME_SINGULAR%_list = array();
-    $qid = DB::query("
+    $qid = $db->query("
         SELECT *
         FROM %DB_TBL%
@@ -79,5 +79,5 @@
     // Get the FEATURED list.
     $featured_list = array();
-    $qid = DB::query("
+    $qid = $db->query("
         SELECT *
         FROM %DB_TBL%
@@ -92,5 +92,5 @@
     // Get the POPULAR list.
     $popular_list = array();
-    $qid = DB::query("
+    $qid = $db->query("
         SELECT *
         FROM %DB_TBL%
@@ -104,5 +104,5 @@
     // Get the RECENT list.
     $recent_list = array();
-    $qid = DB::query("
+    $qid = $db->query("
         SELECT *
         FROM %DB_TBL%
Index: trunk/bin/module_maker/skel/public_list.ihtml
===================================================================
--- trunk/bin/module_maker/skel/public_list.ihtml	(revision 124)
+++ trunk/bin/module_maker/skel/public_list.ihtml	(revision 136)
@@ -5,13 +5,13 @@
         ?>
         <?php if (strlen(trim($%NAME_SINGULAR%_list[$i]['content'])) > 0) { // Link only if content is available. ?>
-            <h4><a href="<?php echo App::oHREF('/%PUBLIC_SCRIPT%?%PRIMARY_KEY%=' . $%NAME_SINGULAR%_list[$i]['%PRIMARY_KEY%']); ?>"><?php echo fancyTxt(oTxt($%NAME_SINGULAR%_list[$i]['title'])); ?></a></h4>
+            <h4><a href="<?php echo $app->oHREF('/%PUBLIC_SCRIPT%?%PRIMARY_KEY%=' . $%NAME_SINGULAR%_list[$i]['%PRIMARY_KEY%']); ?>"><?php echo fancyTxt(oTxt($%NAME_SINGULAR%_list[$i]['title'])); ?></a></h4>
         <?php } else { ?>
             <h4><?php echo fancyTxt(oTxt($%NAME_SINGULAR%_list[$i]['title'])); ?></h4>
         <?php } ?>
         <p>
-        <em><?php echo date(App::getParam('date_format'), strtotime($%NAME_SINGULAR%_list[$i]['<##>'])); ?></em> &mdash; <?php echo nl2br(fancyTxt(oTxt($%NAME_SINGULAR%_list[$i]['summary'], true))); ?>
+        <em><?php echo date($app->getParam('date_format'), strtotime($%NAME_SINGULAR%_list[$i]['<##>'])); ?></em> &mdash; <?php echo nl2br(fancyTxt(oTxt($%NAME_SINGULAR%_list[$i]['summary'], true))); ?>
 
         <?php if (strlen(trim($%NAME_SINGULAR%_list[$i]['content'])) > 0) { // Link only if content is available. ?>
-            <br /><a href="<?php echo App::oHREF('/%PUBLIC_SCRIPT%?%PRIMARY_KEY%=' . $%NAME_SINGULAR%_list[$i]['%PRIMARY_KEY%']); ?>"><?php echo _("Read more"); ?></a>
+            <br /><a href="<?php echo $app->oHREF('/%PUBLIC_SCRIPT%?%PRIMARY_KEY%=' . $%NAME_SINGULAR%_list[$i]['%PRIMARY_KEY%']); ?>"><?php echo _("Read more"); ?></a>
         <?php } ?>
         </p>
@@ -32,5 +32,5 @@
     <?php
     foreach ($featured_list as $item) {
-        ?><h4><a href="<?php echo App::oHREF('/%PUBLIC_SCRIPT%?%PRIMARY_KEY%=' . $item['%PRIMARY_KEY%']); ?>"><?php echo fancyTxt(oTxt($item['title'])); ?></a></h4><?php
+        ?><h4><a href="<?php echo $app->oHREF('/%PUBLIC_SCRIPT%?%PRIMARY_KEY%=' . $item['%PRIMARY_KEY%']); ?>"><?php echo fancyTxt(oTxt($item['title'])); ?></a></h4><?php
     }
 }
@@ -44,5 +44,5 @@
     <?php
     foreach ($popular_list as $item) {
-        ?><h4><a href="<?php echo App::oHREF('/%PUBLIC_SCRIPT%?%PRIMARY_KEY%=' . $item['%PRIMARY_KEY%']); ?>"><?php echo fancyTxt(oTxt($item['title'])); ?></a> </h4><?php
+        ?><h4><a href="<?php echo $app->oHREF('/%PUBLIC_SCRIPT%?%PRIMARY_KEY%=' . $item['%PRIMARY_KEY%']); ?>"><?php echo fancyTxt(oTxt($item['title'])); ?></a> </h4><?php
     }
 }
@@ -56,5 +56,5 @@
     <?php
     foreach ($recent_list as $item) {
-        ?><h4><a href="<?php echo App::oHREF('/%PUBLIC_SCRIPT%?%PRIMARY_KEY%=' . $item['%PRIMARY_KEY%']); ?>"><?php echo fancyTxt(oTxt($item['title'])); ?></a> </h4><?php
+        ?><h4><a href="<?php echo $app->oHREF('/%PUBLIC_SCRIPT%?%PRIMARY_KEY%=' . $item['%PRIMARY_KEY%']); ?>"><?php echo fancyTxt(oTxt($item['title'])); ?></a> </h4><?php
     }
 }
Index: trunk/bin/module_maker/sql.cli.php
===================================================================
--- trunk/bin/module_maker/sql.cli.php	(revision 124)
+++ trunk/bin/module_maker/sql.cli.php	(revision 136)
@@ -30,5 +30,5 @@
 
 // Get DB tables.
-$qid = DB::query("SHOW TABLES");
+$qid = $db->query("SHOW TABLES");
 while (list($row) = mysql_fetch_row($qid)) {
     $tables[] = $row;
@@ -37,5 +37,5 @@
 // Make sure requested table is in database.
 if (!in_array($db_tbl, $tables)) {
-    die(sprintf("%s Warning: %s does not exist in database %s. Please select one of: \n\n%s\n\n", basename($_SERVER['argv'][0]), $db_tbl, App::getParam('db_name'), join("\n", $tables)));
+    die(sprintf("%s Warning: %s does not exist in database %s. Please select one of: \n\n%s\n\n", basename($_SERVER['argv'][0]), $db_tbl, $app->getParam('db_name'), join("\n", $tables)));
 }
 
@@ -46,5 +46,5 @@
 
 // Get DB table column info.
-$qid = DB::query("DESCRIBE " . DB::escapeString($db_tbl));
+$qid = $db->query("DESCRIBE " . $db->escapeString($db_tbl));
 while ($row = mysql_fetch_row($qid)) {
     $cols[] = $row;
@@ -76,5 +76,5 @@
         } else if ('added_by_user_id' == $field || 'modified_by_user_id' == $field) {
             // Toggle types.
-            $c[$field] = "'\" . DB::escapeString(\$auth->getVal('user_id')) . \"'";
+            $c[$field] = "'\" . \$db->escapeString(\$auth->getVal('user_id')) . \"'";
         } else if ('added_datetime' == $field || 'modified_datetime' == $field) {
             // DB record insertion datetime.
@@ -82,5 +82,5 @@
         } else {
             // Default. Just insert data.
-            $c[$field] = "'\" . DB::escapeString(\$frm['$field']) . \"'";
+            $c[$field] = "'\" . \$db->escapeString(\$frm['$field']) . \"'";
         }
     }
@@ -107,5 +107,5 @@
 echo <<<E_O_F
     // Insert record data.
-    DB::query("
+    \$db->query("
         INSERT INTO $db_tbl (
             $db_keys
@@ -133,7 +133,7 @@
 echo <<<E_O_F
     // Update record data.
-    DB::query("
+    \$db->query("
         UPDATE $db_tbl SET$key_eq_val
-        WHERE $primary_key = '" . DB::escapeString(\$frm['$primary_key']) . "'
+        WHERE $primary_key = '" . \$db->escapeString(\$frm['$primary_key']) . "'
     ");
 E_O_F;
@@ -148,5 +148,5 @@
 $delim = 'WHERE';
 if (!empty($primary_key)) {
-    $where_clause = "            $delim $primary_key = '\" . DB::escapeString(\$frm['$primary_key']) . \"'\n";
+    $where_clause = "            $delim $primary_key = '\" . \$db->escapeString(\$frm['$primary_key']) . \"'\n";
     $delim = 'AND';
 }
@@ -155,10 +155,10 @@
         continue;
     }
-    $where_clause .= "            $delim $k = '\" . DB::escapeString(\$frm['$k']) . \"'\n";
+    $where_clause .= "            $delim $k = '\" . \$db->escapeString(\$frm['$k']) . \"'\n";
     $delim = 'AND';
 }
 echo <<<E_O_F
         // Delete record data.
-        DB::query("
+        \$db->query("
             DELETE FROM $db_tbl
 $where_clause        ");
@@ -183,9 +183,9 @@
 if (!isset($op) || 'search' == $op) {
 $search_skip_columns = array('added_datetime', 'added_by_user_id', 'modified_datetime', 'modified_by_user_id', 'publish', 'featured');
-$search_columns = $db_tbl . '.' . join(" LIKE '%\" . DB::escapeString(\$qry_words[\$i]) . \"%'\n                    OR $db_tbl.", array_diff(array_keys($c), $search_skip_columns));
+$search_columns = $db_tbl . '.' . join(" LIKE '%\" . \$db->escapeString(\$qry_words[\$i]) . \"%'\n                    OR $db_tbl.", array_diff(array_keys($c), $search_skip_columns));
 echo <<<E_O_F
             \$where_clause .= (empty(\$where_clause) ? 'WHERE' : 'AND') . "
                 (
-                    $search_columns LIKE '%" . DB::escapeString(\$qry_words[\$i]) . "%'
+                    $search_columns LIKE '%" . \$db->escapeString(\$qry_words[\$i]) . "%'
                 )
             ";
Index: trunk/bin/module_maker/validation.cli.php
===================================================================
--- trunk/bin/module_maker/validation.cli.php	(revision 124)
+++ trunk/bin/module_maker/validation.cli.php	(revision 136)
@@ -17,5 +17,5 @@
 
 // Get DB tables.
-$qid = DB::query("SHOW TABLES");
+$qid = $db->query("SHOW TABLES");
 while (list($row) = mysql_fetch_row($qid)) {
     $tables[] = $row;
@@ -24,9 +24,9 @@
 // Make sure requested table is in database.
 if (!in_array($db_tbl, $tables)) {
-    die(sprintf("%s Warning: %s does not exist in database %s. Please select one of: \n\n%s\n\n", basename($_SERVER['argv'][0]), $db_tbl, App::getParam('db_name'), join("\n", $tables)));
+    die(sprintf("%s Warning: %s does not exist in database %s. Please select one of: \n\n%s\n\n", basename($_SERVER['argv'][0]), $db_tbl, $app->getParam('db_name'), join("\n", $tables)));
 }
 
 // Get DB table column info.
-$qid = DB::query("DESCRIBE " . DB::escapeString($db_tbl));
+$qid = $db->query("DESCRIBE " . $db->escapeString($db_tbl));
 while ($row = mysql_fetch_row($qid)) {
     $cols[] = $row;
@@ -277,11 +277,14 @@
 // natsort($o);
 
+// Remove last empty element.
+if ('' == end($o)) {
+    array_pop($o);
+}
+
 echo "function validateInput()
 {
     global \$fv;
 
-    ";
-echo join("\n    ", $o);
-echo "
+    " . join("\n    ", $o) . "
 }";
 ?>
