Index: branches/1.1dev/bin/module_maker/form_template.cli.php
===================================================================
--- branches/1.1dev/bin/module_maker/form_template.cli.php	(revision 78)
+++ branches/1.1dev/bin/module_maker/form_template.cli.php	(revision 79)
@@ -1,3 +1,3 @@
-#!/usr/local/bin/php -q
+#!/usr/local/bin/php
 <?php
 /**
@@ -6,14 +6,12 @@
  */
 
-$CFG->enable_session = false;
-$CFG->log_screen_priority = LOG_DEBUG;
-error_reporting(E_ALL);
-require_once dirname(__FILE__) . '/../../config/boot.inc.php';
+// Get module maker configuration.
+require_once dirname(__FILE__) . '/_config.inc.php';
 
 // Test arguments.
-if ($_SERVER['argc'] == 2) {
-    $db_tbl = $_SERVER['argv'][1];
+if ($_SERVER['argc'] == 3) {
+    $db_tbl = $_SERVER['argv'][2];
 } else {
-    die(basename($_SERVER['argv'][0]) . " Warning: You must specify a DB table as the first argument.\n");
+    die(basename($_SERVER['argv'][0]) . " Warning: You must specify a DB table as the second argument.\n");
 }
 
Index: branches/1.1dev/bin/module_maker/list_template.cli.php
===================================================================
--- branches/1.1dev/bin/module_maker/list_template.cli.php	(revision 78)
+++ branches/1.1dev/bin/module_maker/list_template.cli.php	(revision 79)
@@ -1,3 +1,3 @@
-#!/usr/local/bin/php -q
+#!/usr/local/bin/php
 <?php
 /**
@@ -7,8 +7,6 @@
 
 
-$CFG->enable_session = false;
-$CFG->log_screen_priority = LOG_DEBUG;
-error_reporting(E_ALL);
-require_once dirname(__FILE__) . '/../../config/boot.inc.php';
+// Get module maker configuration.
+require_once dirname(__FILE__) . '/_config.inc.php';
 
 $op = null;
@@ -16,11 +14,11 @@
 
 // Test arguments.
-if ($_SERVER['argc'] == 2) {
-    $db_tbl = $_SERVER['argv'][1];
-} else if ($_SERVER['argc'] == 3) {
-    $db_tbl = $_SERVER['argv'][1];
-    $op = $_SERVER['argv'][2];
+if ($_SERVER['argc'] == 3) {
+    $db_tbl = $_SERVER['argv'][2];
+} else if ($_SERVER['argc'] == 4) {
+    $db_tbl = $_SERVER['argv'][2];
+    $op = $_SERVER['argv'][3];
 } else {
-    die(basename($_SERVER['argv'][0]) . " Warning: You must specify a DB table as the first argument.\n");
+    die(basename($_SERVER['argv'][0]) . " Warning: You must specify a DB table as the second argument.\n");
 }
 
Index: branches/1.1dev/bin/module_maker/module.cli.php
===================================================================
--- branches/1.1dev/bin/module_maker/module.cli.php	(revision 78)
+++ branches/1.1dev/bin/module_maker/module.cli.php	(revision 79)
@@ -1,3 +1,3 @@
-#!/usr/local/bin/php -q
+#!/usr/local/bin/php
 <?php
 /**
@@ -7,8 +7,6 @@
 
 
-$CFG->enable_session = false;
-$CFG->log_screen_priority = LOG_DEBUG;
-error_reporting(E_ALL);
-require_once dirname(__FILE__) . '/../../config/boot.inc.php';
+// Get module maker configuration.
+require_once dirname(__FILE__) . '/_config.inc.php';
 
 
@@ -18,12 +16,12 @@
 
 // Test for a single argument.
-if ($_SERVER['argc'] == 4 && $_SERVER['argv'][3] == 'clean') {
-    $module_name_singular = $_SERVER['argv'][1];
-    $module_name_plural = $_SERVER['argv'][2];
-} else if ($_SERVER['argc'] == 3) {
+if ($_SERVER['argc'] == 5 && $_SERVER['argv'][4] == 'clean') {
+    $module_name_singular = $_SERVER['argv'][2];
+    $module_name_plural = $_SERVER['argv'][3];
+} else if ($_SERVER['argc'] == 4) {
     // Normal operation.
-    $module_name_singular = $_SERVER['argv'][1];
-    $module_name_plural = $_SERVER['argv'][2];
-} else if ($_SERVER['argc'] == 2 && $_SERVER['argv'][1] == '_default_') {
+    $module_name_singular = $_SERVER['argv'][2];
+    $module_name_plural = $_SERVER['argv'][3];
+} else if ($_SERVER['argc'] == 3 && $_SERVER['argv'][2] == '_default_') {
     // Hacked mode: use these module names:
     $module_name_singular = 'event';
@@ -33,5 +31,7 @@
     die(basename($_SERVER['argv'][0]) . " Error: invalid arguments. Try like this:
     
-    " . basename($_SERVER['argv'][0]) . " <namesingular> <nameplural>
+    " . basename($_SERVER['argv'][0]) . " <sitedirectory> <namesingular> <nameplural>
+    
+E.g.: " . basename($_SERVER['argv'][0]) . " ~/Sites/www.asdf.com category categories
 
 There is also a secret _default_ option that uses options hard-coded into the script. Hack the script for more info.
@@ -48,5 +48,5 @@
 
 // Where deleted files go:
-$user_trash_folder = "/Users/" . get_current_user() . "/.Trash";
+$user_trash_folder = $_SERVER['HOME'] . '/.Trash';
 
 // Directories
@@ -77,8 +77,20 @@
 
 
-if ($_SERVER['argc'] == 4 && $_SERVER['argv'][3] == 'clean') {
-    cleanFiles();
+// Only after we've defined essential files can we clean.
+if ($_SERVER['argc'] == 5 && $_SERVER['argv'][4] == 'clean') {
+    echo "Beginning file cleanup\n";
+    trashFile("$admin_dir/$admin_script");
+    trashFile("$admin_tpl_dir/$admin_list_template");
+    trashFile("$admin_tpl_dir/$admin_form_template");
+    trashFile("$public_dir/$public_script");
+    trashFile("$public_tpl_dir/$public_list_template");
+    trashFile("$public_tpl_dir/$public_detail_template");
+    echo "End file cleanup\n";
     die;
 }
+
+// Go!
+echo 'Running Module Maker. Using database: ' . $CFG->database . "\n";
+
 
 /******************************************************************************
@@ -395,75 +407,32 @@
  *****************************************************************************/
 
-/**
- * Removes existing modules files. Danger!
- */
-function cleanFiles()
+function trashFile($file_path_name)
 {
     global $user_trash_folder;
-    global $admin_dir;
-    global $admin_script;
-    global $admin_tpl_dir;
-    global $admin_list_template;
-    global $admin_form_template;
-    global $public_dir;
-    global $public_script;
-    global $public_tpl_dir;
-    global $public_detail_template;
-    global $public_list_template;
-    
-    echo "Beginning file cleanup\n";
-
-    if (!dir($user_trash_folder)) {
-    	mkdir($user_trash_folder);
-    	chmod($user_trash_folder, 0777);
-    	echo "Attempting to create user trash folder: $user_trash_folder/\n";
+    static $file_prefix;
+
+    if (!isset($file_prefix)) {
+        $file_prefix = time();
+    } else {
+        $file_prefix++;
     }
-    if (!dir("$user_trash_folder/") || !is_writable("$user_trash_folder/")) {
+
+    // Make user trash folder.
+    if (!is_dir($user_trash_folder)) {
+        echo "Attempting to create user trash folder: $user_trash_folder/\n";
+        mkdir($user_trash_folder);
+        chmod($user_trash_folder, 0777);
+    }
+    if (!is_dir("$user_trash_folder") || !is_writable("$user_trash_folder")) {
         die("User trash directory not available: $user_trash_folder/\n");
     }
 
-    if (file_exists("$admin_dir/$admin_script")) {
-        rename("$admin_dir/$admin_script", "$user_trash_folder/$admin_script" . '_' . md5(microtime()));
-        printf("Moved to trash: %s\n", "$admin_dir/$admin_script");
+    // Move file to trash.
+    if (file_exists($file_path_name)) {
+        rename($file_path_name, sprintf('%s/%s_%s', $user_trash_folder, $file_prefix, basename($file_path_name)));
+        printf("Moved: %s -> %s\n", $file_path_name, sprintf('%s/%s_%s', $user_trash_folder, $file_prefix, basename($file_path_name)));
     } else {
-        printf("File not found: %s\n", "$admin_dir/$admin_script");
+        printf("File not found: %s\n", $file_path_name);
     }
-
-    if (file_exists("$admin_tpl_dir/$admin_list_template")) {
-        rename("$admin_tpl_dir/$admin_list_template", "$user_trash_folder/$admin_list_template" . '_' . md5(microtime()));
-        printf("Moved to trash: %s\n", "$admin_tpl_dir/$admin_list_template");
-    } else {
-        printf("File not found: %s\n", "$admin_tpl_dir/$admin_list_template");
-    }
-
-    if (file_exists("$admin_tpl_dir/$admin_form_template")) {
-        rename("$admin_tpl_dir/$admin_form_template", "$user_trash_folder/$admin_form_template" . '_' . md5(microtime()));
-        printf("Moved to trash: %s\n", "$admin_tpl_dir/$admin_form_template");
-    } else {
-        printf("File not found: %s\n", "$admin_tpl_dir/$admin_form_template");
-    }
-
-    if (file_exists("$public_dir/$public_script")) {
-        rename("$public_dir/$public_script", "$user_trash_folder/$public_script" . '_' . md5(microtime()));
-        printf("Moved to trash: %s\n", "$public_dir/$public_script");
-    } else {
-        printf("File not found: %s\n", "$public_dir/$public_script");
-    }
-
-    if (file_exists("$public_tpl_dir/$public_list_template")) {
-        rename("$public_tpl_dir/$public_list_template", "$user_trash_folder/$public_list_template" . '_' . md5(microtime()));
-        printf("Moved to trash: %s\n", "$public_tpl_dir/$public_list_template");
-    } else {
-        printf("File not found: %s\n", "$public_tpl_dir/$public_list_template");
-    }
-
-    if (file_exists("$public_tpl_dir/$public_detail_template")) {
-        rename("$public_tpl_dir/$public_detail_template", "$user_trash_folder/$public_detail_template" . '_' . md5(microtime()));
-        printf("Moved to trash: %s\n", "$public_tpl_dir/$public_detail_template");
-    } else {
-        printf("File not found: %s\n", "$public_tpl_dir/$public_detail_template");
-    }
-    
-    echo "End file cleanup\n";
 }
 
Index: branches/1.1dev/bin/module_maker/sql.cli.php
===================================================================
--- branches/1.1dev/bin/module_maker/sql.cli.php	(revision 78)
+++ branches/1.1dev/bin/module_maker/sql.cli.php	(revision 79)
@@ -6,8 +6,6 @@
  */
 
-$CFG->enable_session = false;
-$CFG->log_screen_priority = LOG_DEBUG;
-error_reporting(E_ALL);
-require_once dirname(__FILE__) . '/../../config/boot.inc.php';
+// Get module maker configuration.
+require_once dirname(__FILE__) . '/_config.inc.php';
 
 $op = null;
@@ -15,11 +13,11 @@
 
 // Test arguments.
-if ($_SERVER['argc'] == 2) {
-    $db_tbl = $_SERVER['argv'][1];
-} else if ($_SERVER['argc'] == 3) {
-    $db_tbl = $_SERVER['argv'][1];
-    $op = $_SERVER['argv'][2];
+if ($_SERVER['argc'] == 3) {
+    $db_tbl = $_SERVER['argv'][2];
+} else if ($_SERVER['argc'] == 4) {
+    $db_tbl = $_SERVER['argv'][2];
+    $op = $_SERVER['argv'][3];
 } else {
-    die(basename($_SERVER['argv'][0]) . " Warning: You must specify a DB table as the first argument.\n");
+    die(basename($_SERVER['argv'][0]) . " Warning: You must specify a DB table as the second argument.\n");
 }
 
Index: branches/1.1dev/bin/module_maker/validation.cli.php
===================================================================
--- branches/1.1dev/bin/module_maker/validation.cli.php	(revision 78)
+++ branches/1.1dev/bin/module_maker/validation.cli.php	(revision 79)
@@ -7,14 +7,12 @@
 
 
-$CFG->enable_session = false;
-$CFG->log_screen_priority = LOG_DEBUG;
-error_reporting(E_ALL);
-require_once dirname(__FILE__) . '/../../config/boot.inc.php';
+// Get module maker configuration.
+require_once dirname(__FILE__) . '/_config.inc.php';
 
 // Test arguments.
-if ($_SERVER['argc'] == 2) {
-    $db_tbl = $_SERVER['argv'][1];
+if ($_SERVER['argc'] == 3) {
+    $db_tbl = $_SERVER['argv'][2];
 } else {
-    die(basename($_SERVER['argv'][0]) . " Warning: You must specify a DB table as the first argument.\n");
+    die(basename($_SERVER['argv'][0]) . " Warning: You must specify a DB table as the second argument.\n");
 }
 
Index: branches/1.1dev/lib/App.inc.php
===================================================================
--- branches/1.1dev/lib/App.inc.php	(revision 78)
+++ branches/1.1dev/lib/App.inc.php	(revision 79)
@@ -104,5 +104,7 @@
     if (!is_dir($CFG->log_directory) || !is_writable($CFG->log_directory)) {
         // We must use trigger_error rather than calling logMsg, which might lead to an infinite loop.
-        trigger_error(sprintf('Codebase error: log directory (%s) not found or writable.', $CFG->log_directory), E_USER_ERROR);
+        trigger_error(sprintf('Codebase error: log directory not found or writable: %s', $CFG->log_directory), E_USER_NOTICE);
+        $CFG->log_directory = '/tmp';
+        $CFG->log_filename = sprintf('%s_%s.log', getenv('USER'), getenv('HTTP_HOST'));
     }
     
@@ -121,10 +123,10 @@
     
     // FILE ACTION
-    if ($priority <= $CFG->log_file_priority && $CFG->log_file_priority) {
+    if ($CFG->log_file_priority && $priority <= $CFG->log_file_priority) {
         error_log($event_str . "\n", 3, $CFG->log_directory . '/' . $CFG->log_filename);
     }
 
     // EMAIL ACTION
-    if ($priority <= $CFG->log_email_priority && $CFG->log_email_priority) {
+    if ($CFG->log_email_priority && $priority <= $CFG->log_email_priority) {
         if (empty($CFG->log_to_email)) {
             $CFG->log_to_email = 'bug@strangecode.com';
@@ -140,5 +142,5 @@
     
     // SMS ACTION
-    if ($priority <= $CFG->log_sms_priority && $CFG->log_sms_priority) {
+    if ($CFG->log_sms_priority && $priority <= $CFG->log_sms_priority) {
         if (empty($CFG->log_to_email)) {
             $CFG->log_to_sms = 'bug@strangecode.com';
@@ -150,5 +152,5 @@
 
     // SCREEN ACTION
-    if ($priority <= $CFG->log_screen_priority && $CFG->log_screen_priority) {
+    if ($CFG->log_screen_priority && $priority <= $CFG->log_screen_priority) {
         echo "[{$event['date']}] [{$event['type']}] [{$event['file:line']}] [{$event['message']}]\n";
     }
@@ -292,11 +294,20 @@
 }
 
-/**
- * Redirects a user by calling the dieURL(). It will use:
- * 1. the stored boomerang URL, it it exists
- * 2. the referring URL, it it exists.
- * 3. an empty string, which will force dieURL to use the default URL.
- */
-function dieBoomerangURL($id=null, $carry_args=null)
+/*
+* Redirects a user by calling App::dieURL(). It will use:
+* 1. the stored boomerang URL, it it exists
+* 2. a specified $default_url, it it exists
+* 3. the referring URL, it it exists.
+* 4. redirect_home_url configuration variable.
+*
+* @access   public
+* @param    string  $id             Identifier for this script.
+* @param    mixed   $carry_args     Additional arguments to carry in the URL automatically (see App::oHREF()).
+* @param    string  $default_url    A default URL if there is not a valid specified boomerang URL.
+* @return   bool                    False if the session is not running. No return otherwise.
+* @author   Quinn Comendant <quinn@strangecode.com>
+* @since    31 Mar 2006 19:17:00
+*/
+function dieBoomerangURL($id=null, $carry_args=null, $default_url=null)
 {
     // Get URL from stored boomerang. Allow non specific URL if ID not valid.
@@ -307,7 +318,8 @@
             $url = end($_SESSION['_boomerang']['url']);
         }
-    } else if (!refererIsMe() && !preg_match('/admin_common/', getenv('SCRIPT_NAME'))) {
+    } else if (isset($default_url)) {
+        $url = $default_url;
+    } else if (!refererIsMe()) {
         // Ensure that the redirecting page is not also the referrer.
-        // admin_common is an alias of 'admin', which confuses this function. Just here for local testing.
         $url = getenv('HTTP_REFERER');
     } else {
