? file_import-744000.patch
Index: file_import.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/file_import/file_import.module,v
retrieving revision 1.2.2.2
diff -u -p -r1.2.2.2 file_import.module
--- file_import.module	21 Apr 2009 00:00:49 -0000	1.2.2.2
+++ file_import.module	17 Mar 2010 01:48:46 -0000
@@ -28,11 +28,11 @@ function file_import_theme() {
 function file_import_help($path, $arg) {
   switch ($section) {
     case 'admin/content/file_import':
-      $output = '<p>'. t("Import multiple files and save them as node attachments. The files will be moved from their default location.") .'<br/>'
+      $output = '<p>'. t("Import multiple files and save them as node attachments. The files will be moved from their default location.") .'<br />'
         . t("Searching for files in %dirpath.", array('%dirpath' => realpath(variable_get('file_import_path', file_directory_path() .'/import')))) .'</p>';
       return $output;
     case 'node/%/file_import':
-      $output = '<p>'. t("Import multiple files and save them as node attachments. The files will be moved from their default location.") .'<br/>'
+      $output = '<p>'. t("Import multiple files and save them as node attachments. The files will be moved from their default location.") .'<br />'
         . t("Searching for files in %dirpath.", array('%dirpath' => realpath(variable_get('file_import_path', file_directory_path() .'/import')))) .'</p>';
       return $output;
     case 'admin/settings/file_import':
@@ -82,7 +82,7 @@ function file_import_menu() {
     'page callback' => 'drupal_get_form',
     'page arguments' => array('file_import_form', 1),
     'access callback' => 'file_import_access',
-    'access arguments' => array(1),
+    'access arguments' => array('import files'),
     'type' => MENU_LOCAL_TASK,
     'weight' => 5
   );
@@ -94,7 +94,7 @@ function file_import_menu() {
  * Checks for node's file import tab access.
  */
 function file_import_access($node) {
-  return variable_get('file_import_tab', TRUE) && file_import_access_node($node);
+  return variable_get('file_import_tab', TRUE) && user_access('import files') && file_import_access_node($node);
 }
 
 /**
@@ -266,13 +266,13 @@ function file_import_title_operations_fo
     '#type' => 'button',
     '#value' => t('Clear titles'),
     '#id' => 'clear_titles',
-    '#suffix' => '<br/><br/>',
+    '#suffix' => '<br /><br />',
   );
   $form['ops']['other']['cfl_titles'] = array(
     '#type' => 'button',
     '#value' => t('Capitalize first letter'),
     '#id' => 'cfl_titles',
-    '#suffix' => '<br/>',
+    '#suffix' => '<br />',
   );
   $form['ops']['other']['cfla_titles'] = array(
     '#type' => 'button',
@@ -313,6 +313,8 @@ function file_import_form_validate($form
  * File import's form submit function. Most of the magic goes here.
  */
 function file_import_form_submit($form, &$form_state) {
+  if (user_access('import files')) {
+  global $user;  
   $dirpath = variable_get('file_import_path', file_directory_path() .'/import');
   if (file_check_directory($dirpath)) {
     $i = 0;
@@ -361,7 +363,8 @@ function file_import_form_submit($form, 
             }
           }
           if (file_move($filename, $new_filename)) {
-            db_query("INSERT INTO {files} (filename, filepath, filemime, filesize, status, timestamp) VALUES ('%s', '%s', '%s', %d, %d, %d)",
+            db_query("INSERT INTO {files} (uid, filename, filepath, filemime, filesize, status, timestamp) VALUES (%d, '%s', '%s', '%s', %d, %d, %d)",
+              $user->uid,
               $origname,
               $filename,
               content_type($filename),
@@ -371,8 +374,9 @@ function file_import_form_submit($form, 
 
             if (!db_error()) {
               $fid = db_last_insert_id('files', 'fid');
-              db_query("INSERT INTO {upload} (fid, vid, description, list) VALUES (%d, %d, '%s', %d)",
+              db_query("INSERT INTO {upload} (fid, nid, vid, description, list) VALUES (%d, %d, %d, '%s', %d)",
                 $fid, 
+                $nid,
                 $vid, 
                 $form_state['values']['title'][$index],
                 $list);
@@ -397,6 +401,7 @@ function file_import_form_submit($form, 
       drupal_set_message(t('No files were imported.'));
     }
   }
+  }
 }
 
 /**
@@ -524,31 +529,33 @@ function file_import_autocomplete($strin
 function content_type($name) { 
     // Defines the content type based upon the extension of the file 
     $contenttype  = 'application/octet-stream'; 
-    $contenttypes = array( 'html' => 'text/html', 
-                           'htm'  => 'text/html', 
-                           'txt'  => 'text/plain', 
-                           'gif'  => 'image/gif', 
-                           'jpg'  => 'image/jpeg', 
-                           'png'  => 'image/png', 
-                           'sxw'  => 'application/vnd.sun.xml.writer', 
-                           'sxg'  => 'application/vnd.sun.xml.writer.global', 
-                           'sxd'  => 'application/vnd.sun.xml.draw', 
-                           'sxc'  => 'application/vnd.sun.xml.calc', 
-                           'sxi'  => 'application/vnd.sun.xml.impress', 
-                           'xls'  => 'application/vnd.ms-excel', 
-                           'ppt'  => 'application/vnd.ms-powerpoint', 
-                           'doc'  => 'application/msword', 
-                           'rtf'  => 'text/rtf', 
-                           'zip'  => 'application/zip', 
-                           'mp3'  => 'audio/mpeg', 
-                           'pdf'  => 'application/pdf', 
-                           'tgz'  => 'application/x-gzip', 
-                           'gz'   => 'application/x-gzip', 
-                           'vcf'  => 'text/vcf' ); 
+    $contenttypes = array('html' => 'text/html', 
+                          'htm'  => 'text/html', 
+                          'txt'  => 'text/plain', 
+                          'gif'  => 'image/gif', 
+                          'jpg'  => 'image/jpeg', 
+                          'png'  => 'image/png', 
+                          'sxw'  => 'application/vnd.sun.xml.writer', 
+                          'sxg'  => 'application/vnd.sun.xml.writer.global', 
+                          'sxd'  => 'application/vnd.sun.xml.draw', 
+                          'sxc'  => 'application/vnd.sun.xml.calc', 
+                          'sxi'  => 'application/vnd.sun.xml.impress', 
+                          'xls'  => 'application/vnd.ms-excel', 
+                          'ppt'  => 'application/vnd.ms-powerpoint', 
+                          'doc'  => 'application/msword', 
+                          'rtf'  => 'text/rtf', 
+                          'zip'  => 'application/zip', 
+                          'mp3'  => 'audio/mpeg', 
+                          'pdf'  => 'application/pdf', 
+                          'tgz'  => 'application/x-gzip', 
+                          'gz'   => 'application/x-gzip', 
+                          'vcf'  => 'text/vcf'); 
 
     $name = ereg_replace("§", " ", $name); 
     foreach ($contenttypes as $type_ext => $type_name) { 
-        if (preg_match ("/$type_ext$/i",  $name)) $contenttype = $type_name; 
+        if (preg_match ("/$type_ext$/i",  $name)) {
+          $contenttype = $type_name;
+        }
     } 
     return $contenttype; 
 }
