Index: trunk/lib/FormValidator.inc.php
===================================================================
--- trunk/lib/FormValidator.inc.php	(revision 121)
+++ trunk/lib/FormValidator.inc.php	(revision 136)
@@ -4,5 +4,5 @@
  * Code by Strangecode :: www.strangecode.com :: This document contains copyrighted information
  *
- * The FormValidator:: class provides a method for validating input from
+ * The FormValidator class provides a method for validating input from
  * http requests and displaying errors.
  *
@@ -10,19 +10,27 @@
  * @version   1.8
  *
- * Examples of use:
- *
- * require_once 'codebase/lib/FormValidator.inc.php';
- * $fv = new FormValidator();
- *
- * $fv->isEmpty('location_name', _("<strong>Location name</strong> cannot be blank."));
- * $fv->checkRegex('cc_exp', '/^\d{4}$|^$/', true, _("CC exp date must be in MMYY format."));
- * $fv->isInteger('client_id', _("<strong>Client id</strong> must be an integer."));
- * $fv->numericRange('client_id', -32768, 32767, _("<strong>Client id</strong> must be a number between -32768 and 32767."));
- * $fv->stringLength('zip', 0, 255, _("<strong>Zip</strong> must contain less than 256 characters."));
- * $fv->validateEmail('invoice_email');
- * $fv->validatePhone('phone1');
+ * Example of use:
+---------------------------------------------------------------------
+// The object that validates form input.
+require_once 'codebase/lib/FormValidator.inc.php';
+$fv = new FormValidator();
+
+$fv->isEmpty('field_name', sprintf(_("%s cannot be blank."), _("Field name")));
+$fv->stringLength('field_name', 0, 255, sprintf(_("%s must be %f-to-%f characters in length."), _("Field name"), 0, 255));
+$fv->isInteger('field_name', sprintf(_("%s must be an integer."), _("Field name")));
+$fv->checkRegex('field_name', '/^\d{4}$|^$/', true, sprintf(_("%s must be in MMYY format."), _("Field name")));
+$fv->numericRange('field_name', 0, 65535, sprintf(_("%s must be a number between %f and %f."), _("Field name"), 0, 65535));
+$fv->validatePhone('field_name');
+$fv->validateEmail('field_name');
+$fv->validateStrDate('field_name', sprintf(_("%s must be a valid date in YYYY-MM-DD format."), _("Field name")));
+if (is_null($var)) {
+    $fv->addError('field_name', sprintf(_("%s is invalid."), _("Field name")));
+}
+if ($fv->anyErrors()) {
+    // Errors!
+}
+---------------------------------------------------------------------
  */
-class FormValidator
-{
+class FormValidator {
 
     // Array filling with error messages.
@@ -103,28 +111,29 @@
     function printErrorMessages()
     {
+        $app =& App::getInstance();
         if ($this->anyErrors()) {
             ?><div class="sc-msg"><?php
             $errors = $this->getErrorList();
-            foreach ($errors as $err) {
-                if (!empty($err['message']) && is_string($err['message'])) {
-                    if (error_reporting() > 0 && isset($err['file']) && isset($err['line'])) {
-                        echo "\n<!-- [" . $err['file'] . ' : ' . $err['line'] . '] -->';
+            foreach ($errors as $e) {
+                if ('' != $e['message'] && is_string($e['message'])) {
+                    if (error_reporting() > 0 && $app->getParam('display_errors') && isset($e['file']) && isset($e['line'])) {
+                        echo "\n<!-- [" . $e['file'] . ' : ' . $e['line'] . '] -->';
                     }
-                    switch ($err['type']) {
+                    switch ($e['type']) {
                     case MSG_ERR:
-                        echo '<div class="sc-msg-error">' . $err['message'] . '</div>';
+                        echo '<div class="sc-msg-error">' . $e['message'] . '</div>';
                         break;
 
                     case MSG_WARNING:
-                        echo '<div class="sc-msg-warning">' . $err['message'] . '</div>';
+                        echo '<div class="sc-msg-warning">' . $e['message'] . '</div>';
                         break;
 
                     case MSG_SUCCESS:
-                        echo '<div class="sc-msg-success">' . $err['message'] . '</div>';
+                        echo '<div class="sc-msg-success">' . $e['message'] . '</div>';
                         break;
 
                     case MSG_NOTICE:
                     default:
-                        echo '<div class="sc-msg-notice">' . $err['message'] . '</div>';
+                        echo '<div class="sc-msg-notice">' . $e['message'] . '</div>';
                         break;
                     }
@@ -389,4 +398,6 @@
     function validateEmail($form_name)
     {
+		$app =& App::getInstance();
+    
         $email = getFormData($form_name);
         if ('' == trim($email)) {
@@ -400,5 +411,5 @@
         if (!preg_match($e->getParam('regex'), $email, $e_parts)) {
             $this->addError($form_name, sprintf(_("<strong>%s</strong> is not a valid email address."), oTxt($email)));
-            App::logMsg(sprintf('The email address %s is not valid.', getFormData($form_name)), LOG_DEBUG, __FILE__, __LINE__);
+            $app->logMsg(sprintf('The email address %s is not valid.', getFormData($form_name)), LOG_DEBUG, __FILE__, __LINE__);
             return false;
         }
@@ -412,5 +423,5 @@
         if (strlen($local) > 64 || strlen($domain) > 191) {
             $this->addError($form_name, sprintf(_("<strong>Email address</strong> must contain less than 256 characters."), oTxt($email)));
-            App::logMsg(sprintf('The email address %s must contain less than 256 characters.', getFormData($form_name)), LOG_DEBUG, __FILE__, __LINE__);
+            $app->logMsg(sprintf('The email address %s must contain less than 256 characters.', getFormData($form_name)), LOG_DEBUG, __FILE__, __LINE__);
             return false;
         }
@@ -420,5 +431,5 @@
         if ((ip2long($domain) == '-1' || ip2long($domain) === false) && function_exists('checkdnsrr') && !checkdnsrr($domain . '.', 'MX') && gethostbyname($domain) == $domain) {
             $this->addError($form_name, sprintf(_("<strong>%s</strong> is not a valid email domain name"), oTxt($domain)));
-            App::logMsg(sprintf('The email address %s contains an invalid email domain name (%s).', getFormData($form_name), $domain), LOG_INFO, __FILE__, __LINE__);
+            $app->logMsg(sprintf('The email address %s contains an invalid email domain name (%s).', getFormData($form_name), $domain), LOG_INFO, __FILE__, __LINE__);
             return false;
         }
@@ -454,7 +465,9 @@
     function validateStrDate($form_name, $msg='')
     {
+		$app =& App::getInstance();
+    
         if (($timestamp = strtotime(getFormData($form_name, '0'))) === -1) {
             $this->addError($form_name, $msg);
-            App::logMsg(sprintf('The string date %s is not valid.', getFormData($form_name)), LOG_DEBUG, __FILE__, __LINE__);
+            $app->logMsg(sprintf('The string date %s is not valid.', getFormData($form_name)), LOG_DEBUG, __FILE__, __LINE__);
             return false;
         } else {
@@ -530,5 +543,5 @@
         for ($i=0; $i<$num; $i++) {
             // Get each digit.
-            $digit = substr($cc_num,$i,1);
+            $digit = substr($cc_num, $i, 1);
 
             //  If it's an odd digit, double it.
@@ -539,5 +552,5 @@
             //  If the result is two digits, add them.
             if (strlen($digit) == 2) {
-                $digit = substr($digit,0,1) + substr($digit,1,1);
+                $digit = substr($digit, 0, 1) + substr($digit, 1, 1);
             }
 
@@ -556,5 +569,5 @@
 
     /**
-     * Check whether uploaded file is valid.
+     * Check whether a file was selected for uploading. If file is missing, it's an error.
      *
      * @param  string $form_name the name of the incoming form variable
@@ -565,5 +578,5 @@
     function validateFile($form_name, $msg='')
     {
-        if (isset($_FILES[$form_name]['tmp_name']) && '' == trim($_FILES[$form_name]['tmp_name'])) {
+        if (!isset($_FILES[$form_name]['tmp_name']) || '' == trim($_FILES[$form_name]['tmp_name'])) {
             $this->addError($form_name, $msg);
             return false;
