Index: trunk/bin/module_maker/validation.cli.php
===================================================================
--- trunk/bin/module_maker/validation.cli.php	(revision 815)
+++ trunk/bin/module_maker/validation.cli.php	(revision 1)
@@ -1,37 +1,10 @@
-#!/usr/bin/env php
+#!/usr/local/bin/php -q
 <?php
 /**
- * The Strangecode Codebase - a general application development framework for PHP
- * For details visit the project site: <http://trac.strangecode.com/codebase/>
- * Copyright 2001-2012 Strangecode, LLC
- *
- * This file is part of The Strangecode Codebase.
- *
- * The Strangecode Codebase is free software: you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as published by the
- * Free Software Foundation, either version 3 of the License, or (at your option)
- * any later version.
- *
- * The Strangecode Codebase is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
- * details.
- *
- * You should have received a copy of the GNU General Public License along with
- * The Strangecode Codebase. If not, see <http://www.gnu.org/licenses/>.
+ * validation.cli.php
+ * Code by Strangecode :: www.strangecode.com :: This document contains copyrighted information
  */
 
-/**
- * validation.cli.php
- */
-
-if ($_SERVER['argc'] > 1 && isset($_SERVER['argv'][1]) && '' != $_SERVER['argv'][1] && is_dir($_SERVER['argv'][1])) {
-    // First arg is path to current site. Realpath removes trailing /s
-    define('COMMON_BASE', realpath($_SERVER['argv'][1]));
-} else {
-    die("Error: First argument must be the directory path to an existing site (ex: /home/sc/www.strangecode.com).\n");
-}
-
-include_once dirname(__FILE__) . '/../_config.inc.php';
+include_once dirname(__FILE__) . '/_config.inc.php';
 
 // Test arguments.
@@ -44,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;
@@ -51,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 " . addslashes($db_tbl));
 while ($row = mysql_fetch_row($qid)) {
     $cols[] = $row;
@@ -61,28 +34,26 @@
 
 // Exclude these fields.
-$exclude = array('added_by_user_id', 'added_datetime', 'hit_count', 'modified_datetime', 'modified_by_user_id');
+$exclude = array('added_by_admin_id', 'added_datetime', 'hit_count', 'modified_datetime', 'modified_by_admin_id');
 
 // Loop through columns
 if (is_array($cols) && !empty($cols)) {
-
+    
     $o = array();
 
     foreach ($cols as $col) {
-
+    
         // Human readable.
         $field = $col[0];
         $title = ucfirst(str_replace('_', ' ', $field));
-        $type = preg_replace('/^(\w+).*$/', '$1', $col[1]);
-        $max_dig = preg_replace('/^\w+\((\d+)(?:,\d+)?\).*$/', '$1', $col[1]);
-        $max_dec = preg_replace('/^\w+\((?:\d+)(?:,(\d+))?\).*$/', '$1', $col[1]);
+        $type = preg_replace('/^(\w+).*$/', '\\1', $col[1]);
         $is_primary_key = ('PRI' == $col[3]);
-        $unsigned = preg_match('/\s+unsigned\s*$/i', $col[1]);
-
+        $unsigned = preg_match('/\s*unsigned\s*$/i', $col[1]);
+        
         if (in_array($field, $exclude)) {
             continue;
         }
-
+        
         // ----------- isEmpty ------------
-        $o[] = "\$fv->notEmpty('$field', sprintf(_(\"%s cannot be blank.\"), _(\"$title\")));";
+        $o[] = "\$fv->isEmpty('$field', _(\"<strong>$title</strong> cannot be blank.\"));";
 
         // ----------- stringLength ------------
@@ -97,5 +68,5 @@
             $len_type = 'setenum';
             break;
-
+            
         case 'date' :
         case 'datetime' :
@@ -106,5 +77,5 @@
             $max_length = 127;
             break;
-
+            
         case 'tinytext' :
         case 'tinyblob' :
@@ -112,7 +83,7 @@
         case 'varchar' :
             $len_type = 'string';
-            $max_length = '' != $max_dig ? $max_dig : 255;
-            break;
-
+            $max_length = 255;
+            break;
+            
         case 'text' :
         case 'blob' :
@@ -120,5 +91,5 @@
             $max_length = 65535;
             break;
-
+            
         case 'mediumtext' :
         case 'mediumblob' :
@@ -126,5 +97,5 @@
             $max_length = 16777215;
             break;
-
+            
         case 'longtext' :
         case 'longblob' :
@@ -132,12 +103,7 @@
             $max_length = 4294967295;
             break;
-
+            
+        case 'tinyint' :
         case 'bit' :
-            $len_type = 'num';
-            $min = 0;
-            $max = '' != $max_dig ? $max_dig : 64;
-            break;
-
-        case 'tinyint' :
         case 'bool' :
             $len_type = 'num';
@@ -150,5 +116,5 @@
             }
             break;
-
+            
         case 'smallint' :
             $len_type = 'num';
@@ -161,5 +127,5 @@
             }
             break;
-
+            
         case 'mediumint' :
             $len_type = 'num';
@@ -172,5 +138,5 @@
             }
             break;
-
+            
         case 'int' :
         case 'integer' :
@@ -184,5 +150,5 @@
             }
             break;
-
+            
         case 'bigint' :
             $len_type = 'num';
@@ -195,36 +161,22 @@
             }
             break;
-
+            
         case 'float' :
             $len_type = 'num';
-            if ($unsigned) {
-                $min = 0;
-                $max = 3.40282E+38;
-            } else {
-                $min = -3.40282E+38;
-                $max = 3.40282E+38;
-            }
-            break;
-
+            $min = -3.40282E+38;
+            $max = 3.40282E+38;
+            break;
+            
         case 'double' :
         case 'double precision' :
-            $len_type = 'num';
-            if ($unsigned) {
-                $min = 0;
-                $max = 1.7976931348623157E+308;
-            } else {
-                $min = -1.7976931348623157E+308;
-                $max = 1.7976931348623157E+308;
-            }
-            break;
-
         case 'real' :
         case 'decimal' :
         case 'dec' :
         case 'numeric' :
-        case 'fixed' :
-            $len_type = 'decimal'; // This doesn't match anything, on purpose.
-            break;
-
+            $len_type = 'num';
+            $min = -1.79769E+308;
+            $max = 1.79769E+308;
+            break;
+            
         default :
             $len_type = null;
@@ -232,24 +184,24 @@
         }
         if ($max_length > 0 && $len_type == 'setenum') {
-            $o[] = "\$fv->stringLength('$field', 0, $max_length, sprintf(_(\"%s has an invalid selection.\"), _(\"$title\")));";
+            $o[] = "\$fv->stringLength('$field', 0, $max_length, _(\"<strong>$title</strong> has an invalid selection.\"));";
         }
         if ($max_length > 0 && $len_type == 'string') {
-            $o[] = "\$fv->stringLength('$field', 0, $max_length, sprintf(_(\"%s must be %d-to-%d characters in length.\"), _(\"$title\"), 0, $max_length));";
+            $o[] = "\$fv->stringLength('$field', 0, $max_length, _(\"<strong>$title</strong> must contain less than " . ($max_length+1) . " characters.\"));";
         }
         if ($len_type == 'num') {
-            $o[] = "\$fv->numericRange('$field', $min, $max, sprintf(_(\"%s must be a number between %d and %d.\"), _(\"$title\"), $min, $max));";
-        }
-
+            $o[] = "\$fv->numericRange('$field', $min, $max, _(\"<strong>$title</strong> must be a valid number between $min and $max.\"));";
+        }
+        
         // ----------- type check ------------
         switch ($type) {
 
         case 'enum' :
-
+        
         case 'set' :
             break;
-
+        
         case 'char' :
         case 'varchar' :
-
+        
         case 'tinytext' :
         case 'text' :
@@ -262,5 +214,5 @@
 //             $o[] = "\$fv->isString('$field', _(\"<strong>$title</strong> must be a string.\"));"; // Pretty useless
             break;
-
+        
         case 'tinyint' :
         case 'bit' :
@@ -272,50 +224,41 @@
         case 'bigint' :
             $negative_ok = $unsigned ? '' : ', true';
-            $o[] = "\$fv->isInteger('$field', sprintf(_(\"%s must be an integer.\"), _(\"$title\"))$negative_ok);";
-            break;
-
+            $o[] = "\$fv->isInteger('$field', _(\"<strong>$title</strong> must be an integer.\")$negative_ok);";
+            break;
+        
+        case 'float' :
         case 'float' :
         case 'double' :
-            $negative_ok = $unsigned ? '' : ', true';
-            $o[] = "\$fv->isFloat('$field', sprintf(_(\"%s must be a valid number.\"), _(\"$title\"))$negative_ok);";
-            break;
-
+        case 'double' :
         case 'real' :
         case 'decimal' :
         case 'dec' :
         case 'numeric' :
-        case 'float' :
-            if ($unsigned) {
-                $negative_ok = 'false';
-            } else {
-                $negative_ok = 'true';
-            }
-            $negative_ok = $unsigned ? 'false' : 'true';
-            $o[] = "\$fv->isDecimal('$field', $max_dig, $max_dec, false, sprintf(_(\"%s must be a number with a maximum of %d integer digits and %d fractional digits, e.g., {EX}.\"), _(\"$title\"), {$max_dig}-{$max_dec}, $max_dec), MSG_ERR, __FILE__, __LINE__);";
-            break;
-
+            $negative_ok = $unsigned ? '' : ', true';
+            $o[] = "\$fv->isFloat('$field', _(\"<strong>$title</strong> must be a valid number.\")$negative_ok);";
+            break;
+        
         case 'date' :
         case 'datetime' :
-            // \$fv->validateStrDate('$field', sprintf(_(\"%s must be a valid date in YYYY-MM-DD format.\"), _(\"$title\")));
-            $o[] = "\$fv->validateStrDate('$field', sprintf(_(\"%s must be a valid date in YYYY-MM-DD format.\"), _(\"$title\")));";
-            $o[] = "\$fv->checkRegex('$field', '/^\d{4}-\d{2}-\d{2}$/', true, sprintf(_(\"%s must be in YYYY-MM-DD format.\"), _(\"$title\")));";
-            break;
-
+            $o[] = "\$fv->validateStrDate('$field', _(\"<strong>$title</strong> must be a valid date in YYYY-MM-DD format.\"));";
+            $o[] = "\$fv->checkRegex('$field', '/^\d{4}-\d{2}-\d{2}$/', true, _(\"<strong>$title</strong> must be a valid date in YYYY-MM-DD format.\"));";
+            break;
+            
         case 'timestamp' :
-            $o[] = "\$fv->checkRegex('$field', '/^\d{14}$/', true, sprintf(_(\"%s must be a valid mysql timestamp in YYYYMMDDhhmmss format.\"), _(\"$title\")));";
-            break;
-
+            $o[] = "\$fv->checkRegex('$field', '/^\d{14}$/', true, _(\"<strong>$title</strong> must be a valid mysql timestamp in YYYYMMDDhhmmss format.\"));";
+            break;
+            
         case 'time' :
-            $o[] = "\$fv->checkRegex('$field', '/^\d{1,3}:\d{2}:\d{2}$/', true, sprintf(_(\"%s must be a valid time in hh:mm:ss format.\"), _(\"$title\")));";
-            break;
-
+            $o[] = "\$fv->checkRegex('$field', '/^\d{1,3}:\d{2}:\d{2}$/', true, _(\"<strong>$title</strong> must be a valid time in hh:mm:ss format.\"));";
+            break;
+        
         case 'year' :
-            $o[] = "\$fv->checkRegex('$field', '/^\d{4}$/', true, sprintf(_(\"%s must be a valid year in YYYY format.\"), _(\"$title\")));";
-            break;
-
+            $o[] = "\$fv->checkRegex('$field', '/^\d{4}$/', true, _(\"<strong>$title</strong> must be a valid year in YYYY format.\"));";
+            break;
+        
         default :
             break;
         }
-
+        
         if (preg_match('/email/', $field)) {
             $o[] = "\$fv->validateEmail('$field');";
@@ -323,5 +266,5 @@
             $o[] = "\$fv->validatePhone('$field');";
         }
-
+        
         // Blank between cols?
         $o[] = '';
@@ -334,13 +277,11 @@
 // natsort($o);
 
-// Remove last empty element.
-if ('' == end($o)) {
-    array_pop($o);
-}
-
 echo "function validateInput()
-{
+{    
     global \$fv;
 
-    " . join("\n    ", $o) . "
+    ";
+echo join("\n    ", $o);
+echo "
 }";
+?>
