--- private_upload.module.orig	2009-09-18 13:39:05.000000000 -0700
+++ private_upload.module	2009-09-18 13:32:57.000000000 -0700
@@ -71,10 +71,17 @@ function private_upload_menu() {
     'access arguments' => array('administer site configuration'),
     'page callback' => '_private_upload_migrate_private',
     'type' => MENU_CALLBACK,
-  );    
+  );
+
   return $items;
 }
 
+/**
+ * hook_perm().
+ */
+function private_upload_perm() {
+  return array('download private files');
+}
 
 /**
  * hook_requrements().
@@ -239,7 +246,7 @@ function private_upload_file_download($f
                        "WHERE f.filepath = '%s'", $filepath);
     while($row = db_fetch_array($result)) {
       $node = node_load($row['nid']);
-      if (node_access('view', $node)) {
+      if (node_access('view', $node) && user_access('download private files')) {
         return; // Access is ok as far as we are concerned.
       }
     }
@@ -660,15 +667,50 @@ function theme_private_upload_form(&$for
  * Taken from theme_upload_attachments.
  */
 function theme_private_upload_attachments($files) {
-  $header = array(t('Attachment'), t('Size'));
+  // Modification from 5.x:
+  // $header = array(t('Attachment'), t('Size'));
+  $header = array(t('Attachment'), t('Size'), t('Public'));
   $rows = array();
-  if(is_array($files)) {
-    foreach ($files as $file) {
+  if(is_array($files)) {
+
+    // Sort $files by description
+    // Create temporary array
+    $temp = array();
+    // Populate temporary array with file descriptions
+    foreach($files as $fid => $file) {
+      $temp[$fid] = $file->description;
+    }
+    // Sort temporary file descriptions
+    asort($temp);
+    // Create empty array
+    $sorted_files = array();
+    // Put sorted file elements into $sorted_files array
+    foreach ($temp as $key => $row) {
+      $sorted_files[$key] = $files[$key];  
+    }
+
+    foreach ($sorted_files as $file) {
       $file = (object)$file;
       if ($file->list && !$file->remove) {
         $href = _private_upload_create_url($file); // this is the changed line
         $text = $file->description ? $file->description : $file->filename;
-        $rows[] = array(l($text, $href), format_size($file->filesize));
+        // Modification from 5.x:
+        // $rows[] = array(l($text, $href), format_size($file->filesize));
+		$public = '';
+        $pos = strpos($file->filepath, "/private");
+        // Modification from 5.x:
+        // Added Attributes below to allow the uploaded file to open in a separate window
+        $attributes = array();
+        $attributes['target'] = "_blank";
+		if ($pos === false) {
+		  $public = 'Public';
+          $rows[] = array(l($text, $href, $attributes), format_size($file->filesize), $public);
+	    } else {
+		  if (user_access('download private files')) {
+     		  $public = 'Private';
+              $rows[] = array(l($text, $href, $attributes), format_size($file->filesize), $public);
+		  }
+		}
       }
     }
     if (count($rows)) {
