Index: trunk/lib/Upload.inc.php
===================================================================
--- trunk/lib/Upload.inc.php	(revision 118)
+++ trunk/lib/Upload.inc.php	(revision 119)
@@ -8,16 +8,13 @@
  * @author  Quinn Comendant <quinn@strangecode.com>
  * @requires App.inc.php
- * @version 1.3
+ * @version 1.4
  */
 
-// Message Types.
-define('UPLOAD_MSG_ERR', MSG_ERR);
-define('UPLOAD_MSG_ERROR', MSG_ERROR);
-define('UPLOAD_MSG_WARNING', MSG_WARNING);
-define('UPLOAD_MSG_NOTICE', MSG_NOTICE);
-define('UPLOAD_MSG_SUCCESS', MSG_SUCCESS);
-define('UPLOAD_MSG_ALL', MSG_SUCCESS + MSG_NOTICE + MSG_WARNING + MSG_ERROR);
-
-require_once dirname(__FILE__) . '/App.inc.php';
+// Upload error types.
+define('UPLOAD_USER_ERR_EMPTY_FILE', 100);
+define('UPLOAD_USER_ERR_NOT_UPLOADED_FILE', 101);
+define('UPLOAD_USER_ERR_INVALID_EXTENSION', 102);
+define('UPLOAD_USER_ERR_NOT_UNIQUE', 103);
+define('UPLOAD_USER_ERR_MOVE_FAILED', 104);
 
 class Upload {
@@ -27,5 +24,5 @@
 
         // Which messages do we pass to raiseMsg?
-        'display_messages' => UPLOAD_MSG_ALL,
+        'display_messages' => MSG_ALL,
 
         // Existing files will be overwritten when there is a name conflict?
@@ -116,5 +113,5 @@
         if (!$this->getParam('upload_path')) {
             App::logMsg(sprintf('Upload directory not set before processing.'), LOG_ERR, __FILE__, __LINE__);
-            $this->raiseMsg(_("There was a problem with the file upload. Please try again later."), MSG_ERR, __FILE__, __LINE__);
+            $this->_raiseMsg(_("There was a problem with the file upload. Please try again later."), MSG_ERR, __FILE__, __LINE__);
             return false;
         }
@@ -123,5 +120,5 @@
         if (!isset($_FILES[$form_name])) {
             App::logMsg(sprintf(_("Form element %s does not exist."), $form_name), LOG_ERR, __FILE__, __LINE__);
-            $this->raiseMsg(_("There was a problem with the file upload. Please try again later."), MSG_ERR, __FILE__, __LINE__);
+            $this->_raiseMsg(_("There was a problem with the file upload. Please try again later."), MSG_ERR, __FILE__, __LINE__);
             return false;
         }
@@ -162,5 +159,5 @@
                     // Valid custom file name.
                     $file_name = $custom_file_name;
-                    $this->raiseMsg(sprintf(_("The file <strong>%s</strong> has been renamed to <strong>%s</strong>."), $files['name'][$i], $file_name), MSG_NOTICE, __FILE__, __LINE__);
+                    $this->_raiseMsg(sprintf(_("The file <strong>%s</strong> has been renamed to <strong>%s</strong>."), $files['name'][$i], $file_name), MSG_NOTICE, __FILE__, __LINE__);
                     App::logMsg(sprintf('Using custom file name: %s', $file_name), LOG_DEBUG, __FILE__, __LINE__);
                 } else {
@@ -174,5 +171,5 @@
                     // Valid custom file name.
                     $file_name = $custom_file_name[$i];
-                    $this->raiseMsg(sprintf(_("The file <strong>%s</strong> has been renamed to <strong>%s</strong>."), $files['name'][$i], $file_name), MSG_NOTICE, __FILE__, __LINE__);
+                    $this->_raiseMsg(sprintf(_("The file <strong>%s</strong> has been renamed to <strong>%s</strong>."), $files['name'][$i], $file_name), MSG_NOTICE, __FILE__, __LINE__);
                     App::logMsg(sprintf('Using custom file name: %s', $file_name), LOG_DEBUG, __FILE__, __LINE__);
                 } else {
@@ -200,32 +197,32 @@
             if (UPLOAD_ERR_INI_SIZE === $files['error'][$i]) {
                 if ($this->getParam('display_messages')) {
-                $this->raiseMsg(sprintf(_("The file <strong>%s</strong> failed uploading: it exceeds the maximum allowed upload file size of %s."), $file_name, ini_get('upload_max_filesize')), MSG_ERR, __FILE__, __LINE__);
+                $this->_raiseMsg(sprintf(_("The file <strong>%s</strong> failed uploading: it exceeds the maximum allowed upload file size of %s."), $file_name, ini_get('upload_max_filesize')), MSG_ERR, __FILE__, __LINE__);
                 }
                 App::logMsg(sprintf(_("The file %s failed uploading with PHP error %s UPLOAD_ERR_INI_SIZE (currently %s)."), $files['error'][$i], $file_name, ini_get('upload_max_filesize')), LOG_ERR, __FILE__, __LINE__);
-                $this->errors[] = $file_name;
+                $this->errors[] = array('filename' => $file_name, 'errortype' => UPLOAD_ERR_INI_SIZE);
                 continue;
             }
             if (UPLOAD_ERR_FORM_SIZE === $files['error'][$i]) {
-                $this->raiseMsg(sprintf(_("The file <strong>%s</strong> failed uploading: it exceeds the maximum allowed upload file size of %s."), $file_name, $_POST['MAX_FILE_SIZE']), MSG_ERR, __FILE__, __LINE__);
+                $this->_raiseMsg(sprintf(_("The file <strong>%s</strong> failed uploading: it exceeds the maximum allowed upload file size of %s."), $file_name, $_POST['MAX_FILE_SIZE']), MSG_ERR, __FILE__, __LINE__);
                 App::logMsg(sprintf(_("The file %s failed uploading with PHP error %s UPLOAD_ERR_FORM_SIZE (currently %s)."), $files['error'][$i], $file_name, $_POST['MAX_FILE_SIZE']), LOG_ERR, __FILE__, __LINE__);
-                $this->errors[] = $file_name;
+                $this->errors[] = array('filename' => $file_name, 'errortype' => UPLOAD_ERR_FORM_SIZE);
                 continue;
             }
             if (UPLOAD_ERR_PARTIAL === $files['error'][$i]) {
-                $this->raiseMsg(sprintf(_("The file <strong>%s</strong> failed uploading: it was only partially uploaded."), $file_name), MSG_ERR, __FILE__, __LINE__);
+                $this->_raiseMsg(sprintf(_("The file <strong>%s</strong> failed uploading: it was only partially uploaded."), $file_name), MSG_ERR, __FILE__, __LINE__);
                 App::logMsg(sprintf(_("The file %s failed uploading with PHP error %s UPLOAD_ERR_PARTIAL."), $files['error'][$i], $file_name), LOG_ERR, __FILE__, __LINE__);
-                $this->errors[] = $file_name;
+                $this->errors[] = array('filename' => $file_name, 'errortype' => UPLOAD_ERR_PARTIAL);
                 continue;
             }
             if (UPLOAD_ERR_NO_FILE === $files['error'][$i]) {
-                $this->raiseMsg(sprintf(_("The file <strong>%s</strong> failed uploading: no file was uploaded."), $file_name), MSG_ERR, __FILE__, __LINE__);
+                $this->_raiseMsg(sprintf(_("The file <strong>%s</strong> failed uploading: no file was uploaded."), $file_name), MSG_ERR, __FILE__, __LINE__);
                 App::logMsg(sprintf(_("The file %s failed uploading with PHP error %s UPLOAD_ERR_NO_FILE."), $files['error'][$i], $file_name), LOG_ERR, __FILE__, __LINE__);
-                $this->errors[] = $file_name;
+                $this->errors[] = array('filename' => $file_name, 'errortype' => UPLOAD_ERR_NO_FILE);
                 continue;
             }
             if (UPLOAD_ERR_NO_TMP_DIR === $files['error'][$i]) {
-                $this->raiseMsg(sprintf(_("The file <strong>%s</strong> failed uploading: temporary upload directory missing."), $file_name), MSG_ERR, __FILE__, __LINE__);
+                $this->_raiseMsg(sprintf(_("The file <strong>%s</strong> failed uploading: temporary upload directory missing."), $file_name), MSG_ERR, __FILE__, __LINE__);
                 App::logMsg(sprintf(_("The file %s failed uploading with PHP error %s UPLOAD_ERR_NO_TMP_DIR."), $files['error'][$i], $file_name), LOG_ERR, __FILE__, __LINE__);
-                $this->errors[] = $file_name;
+                $this->errors[] = array('filename' => $file_name, 'errortype' => UPLOAD_ERR_NO_TMP_DIR);
                 continue;
             }
@@ -233,15 +230,15 @@
             // Check to be sure it's an uploaded file.
             if (!is_uploaded_file($files['tmp_name'][$i])) {
-                $this->raiseMsg(sprintf(_("The file <strong>%s</strong> failed uploading."), $file_name), MSG_ERR, __FILE__, __LINE__);
+                $this->_raiseMsg(sprintf(_("The file <strong>%s</strong> failed uploading."), $file_name), MSG_ERR, __FILE__, __LINE__);
                 App::logMsg(sprintf(_("The file %s failed is_uploaded_file."), $file_name), LOG_ERR, __FILE__, __LINE__);
-                $this->errors[] = $file_name;
+                $this->errors[] = array('filename' => $file_name, 'errortype' => UPLOAD_USER_ERR_NOT_UPLOADED_FILE);
                 continue;
             }
 
             // Check to be sure the file is not empty.
-            if ($files['size'][$i] < 1) {
-                $this->raiseMsg(sprintf(_("The file <strong>%s</strong> failed uploading: it contains zero bytes."), $file_name), MSG_ERR, __FILE__, __LINE__);
+            if ($files['size'][$i] <= 0) {
+                $this->_raiseMsg(sprintf(_("The file <strong>%s</strong> failed uploading: it contains zero bytes."), $file_name), MSG_ERR, __FILE__, __LINE__);
                 App::logMsg(sprintf(_("The uploaded file %s contains zero bytes."), $file_name), LOG_ERR, __FILE__, __LINE__);
-                $this->errors[] = $file_name;
+                $this->errors[] = array('filename' => $file_name, 'errortype' => UPLOAD_USER_ERR_EMPTY_FILE);
                 continue;
             }
@@ -249,7 +246,7 @@
             // Check to be sure the file has a valid file name extension.
             if (!in_array(strtolower($this->getFilenameExtension($file_name)), $this->getParam('valid_file_extensions'))) {
-                $this->raiseMsg(sprintf(_("The file <strong>%s</strong> failed uploading: it is an unrecognized type. Files must have one of the following file name extensions: %s."), $file_name, join(', ', $this->getParam('valid_file_extensions'))), MSG_ERR, __FILE__, __LINE__);
+                $this->_raiseMsg(sprintf(_("The file <strong>%s</strong> failed uploading: it is an unrecognized type. Files must have one of the following file name extensions: %s."), $file_name, join(', ', $this->getParam('valid_file_extensions'))), MSG_ERR, __FILE__, __LINE__);
                 App::logMsg(sprintf(_("The uploaded file %s has an unrecognized file name extension."), $file_name), LOG_WARNING, __FILE__, __LINE__);
-                $this->errors[] = $file_name;
+                $this->errors[] = array('filename' => $file_name, 'errortype' => UPLOAD_USER_ERR_INVALID_EXTENSION);
                 continue;
             }
@@ -257,7 +254,7 @@
             // Check to be sure the file has a unique file name.
             if (!$this->getParam('allow_overwriting') && $this->exists($file_name)) {
-                $this->raiseMsg(sprintf(_("The file <strong>%s</strong> failed uploading: a file with that name already exists."), $file_name), MSG_ERR, __FILE__, __LINE__);
+                $this->_raiseMsg(sprintf(_("The file <strong>%s</strong> failed uploading: a file with that name already exists."), $file_name), MSG_ERR, __FILE__, __LINE__);
                 App::logMsg(sprintf(_("The uploaded file %s doesn't have a unique filename."), $file_name), LOG_WARNING, __FILE__, __LINE__);
-                $this->errors[] = $file_name;
+                $this->errors[] = array('filename' => $file_name, 'errortype' => UPLOAD_USER_ERR_NOT_UNIQUE);
                 continue;
             }
@@ -267,8 +264,8 @@
                 chmod($file_path_name, $this->getParam('dest_file_perms'));
                 App::logMsg(sprintf('File uploaded: %s', $file_path_name), LOG_INFO, __FILE__, __LINE__);
-                $this->raiseMsg(sprintf(_("The file <strong>%s</strong> uploaded successfully."), $file_name), MSG_SUCCESS, __FILE__, __LINE__);
+                $this->_raiseMsg(sprintf(_("The file <strong>%s</strong> uploaded successfully."), $file_name), MSG_SUCCESS, __FILE__, __LINE__);
                 if (!isset($custom_file_name) && $files['name'][$i] != $file_name) {
                     // Notify user if uploaded file name was modified (unless a custom file name will be used anyways).
-                    $this->raiseMsg(sprintf(_("The file <strong>%s</strong> was renamed to <strong>%s</strong>."), $files['name'][$i], $file_name), MSG_NOTICE, __FILE__, __LINE__);
+                    $this->_raiseMsg(sprintf(_("The file <strong>%s</strong> was renamed to <strong>%s</strong>."), $files['name'][$i], $file_name), MSG_NOTICE, __FILE__, __LINE__);
                 }
                 $new_file_names[] = array(
@@ -279,7 +276,7 @@
                 continue;
             } else {
-                $this->raiseMsg(sprintf(_("The file <strong>%s</strong> failed uploading."), $file_name), MSG_ERR, __FILE__, __LINE__);
+                $this->_raiseMsg(sprintf(_("The file <strong>%s</strong> failed uploading."), $file_name), MSG_ERR, __FILE__, __LINE__);
                 App::logMsg(sprintf(_("Moving file failed: %s -> %s"), $files['tmp_name'][$i], $file_path_name), LOG_ALERT, __FILE__, __LINE__);
-                $this->errors[] = $file_name;
+                $this->errors[] = array('filename' => $file_name, 'errortype' => UPLOAD_USER_ERR_MOVE_FAILED);
                 continue;
             }
@@ -313,5 +310,5 @@
             App::logMsg(sprintf('Deleted file: %s', $file_path_name), LOG_INFO, __FILE__, __LINE__);
         } else {
-            $this->raiseMsg(sprintf(_("The file <strong>%s</strong> could not be deleted."), $file_name), MSG_ERR, __FILE__, __LINE__);
+            $this->_raiseMsg(sprintf(_("The file <strong>%s</strong> could not be deleted."), $file_name), MSG_ERR, __FILE__, __LINE__);
             App::logMsg(sprintf(_("Failed deleting file: %s"), $file_path_name), LOG_ERR, __FILE__, __LINE__);
             return false;
@@ -339,13 +336,13 @@
         if (file_exists($old_file_path_name)) {
             if (rename($old_file_path_name, $new_file_path_name)) {
-                $this->raiseMsg(sprintf(_("The file <strong>%s</strong> has been renamed to <strong>%s</strong>."), basename($old_file_path_name), basename($new_file_path_name)), MSG_NOTICE, __FILE__, __LINE__);
+                $this->_raiseMsg(sprintf(_("The file <strong>%s</strong> has been renamed to <strong>%s</strong>."), basename($old_file_path_name), basename($new_file_path_name)), MSG_NOTICE, __FILE__, __LINE__);
                 App::logMsg(sprintf('File renamed from %s to %s', $old_file_path_name, $new_file_path_name), LOG_DEBUG, __FILE__, __LINE__);
             } else {
-                $this->raiseMsg(sprintf(_("Error renaming file to %s"), $new_file_path_name), MSG_WARNING, __FILE__, __LINE__);
+                $this->_raiseMsg(sprintf(_("Error renaming file to %s"), $new_file_path_name), MSG_WARNING, __FILE__, __LINE__);
                 App::logMsg(sprintf(_("Error renaming file to %s"), $new_file_path_name), LOG_WARNING, __FILE__, __LINE__);
                 return false;
             }
         } else {
-            $this->raiseMsg(sprintf(_("Couldn't rename nonexistent file <strong>%s</strong>."), $old_name), MSG_WARNING, __FILE__, __LINE__);
+            $this->_raiseMsg(sprintf(_("Couldn't rename nonexistent file <strong>%s</strong>."), $old_name), MSG_WARNING, __FILE__, __LINE__);
             App::logMsg(sprintf(_("Error renaming nonexistent file: %s"), $old_file_path_name), LOG_WARNING, __FILE__, __LINE__);
             return false;
@@ -455,7 +452,7 @@
      * @param string $line    __LINE__.
      */
-    function raiseMsg($message, $type, $file, $line)
-    {
-        if ($this->getParam('display_messages') === true || (is_int($this->getParam('display_messages')) && $this->getParam('display_messages') >= $type)) {
+    function _raiseMsg($message, $type, $file, $line)
+    {
+        if ($this->getParam('display_messages') === true || (is_int($this->getParam('display_messages')) && $this->getParam('display_messages') & $type > 0)) {
             App::raiseMsg($message, $type, $file, $line);
         }
