--- image_import.module	2005-11-19 22:31:19.000000000 -0500
+++ image_import.module.new	2006-05-31 17:45:11.000000000 -0400
@@ -49,7 +49,7 @@ function image_import_help($section) {
       $html = '<p>' . t('This feature is designed to allow you to import many images into a gallery in one step, rather than creating them one-at-a-time. This only makes sense if the images share common attributes, such as relating to the same set of topics and being part of the same gallery or album. To create multiple galleries, you will need to repeat all the steps in these instructions for each gallery.');
       $html .= '<p>' . t('The %formlink provides specific instructions for filling in the form to do an import. This additional help explains the overall process in more detail than will fit on the import page itself.', array('%formlink'=>l(t('image import form'), 'node/add/image_import', array('title'=>t('Begin importing your images')))));
       $html .= '<p>' . t('Here are the steps for importing all the images for one gallery. This may seem complicated the first time you do it, but remember that you can import a large number of images at once, so in the long run this feature will save you a lot of time. Also, the steps become easier once you have done this a couple of times.') . '<ol>';
-      $html .= '<li><p>' . t('If it does not already exist, make sure you or the site administrator create the directory &quot;%dir&quot; underneath the top-level directory for this site. If you are not the site administrator, that person will need to tell you how to access that directory for uploading your files.', array('%dir'=>$path)); 
+      $html .= '<li><p>' . t('If it does not already exist, make sure you or the site administrator create the directory &quot;%dir&quot; underneath the top-level directory for this site. If you are not the site administrator, that person will need to tell you how to access that directory for uploading your files.', array('%dir'=>$path));
       if ($can_override) {
         $html .= '<p>' . t(' (Your user privileges allow you to override the import directory path, but whatever directory you choose must be located underneath the top-level directory for the web site and must be readable and writeable by the web server.)');
       }
@@ -355,9 +355,6 @@ function image_import_menu($may_cache) {
     $items[] = array('path' => 'node/add/image_import', 'title' => t('import images'),
       'callback' => '_image_import_add',
       'access' => user_access('import images'));
-    $items[] = array('path' => 'admin/settings/image_import', 'title' => t('image_import'),
-      'callback' => 'image_import_settings',
-      'access' => user_access('administer site configuration'));
 //    $items[] = array('path' => 'admin/settings/image_import/legacy', 'title' => t('import from legacy image.module'),
 //      'callback' => 'image_import_legacy',
 //      'access' => ($user->uid == 1));
@@ -391,7 +388,7 @@ function _image_import_form() {
 
   if (is_array($_POST['edit'])) {
     // Assume precheck if the button to actually do it was *not* pressed
-    $precheck = empty($_POST['submit_import']);
+    $precheck = $_POST['op']!='Import images'?1:0;
     $status = image_import_import($precheck);
     // Some options set from POST or from system-wide defaults
     $delete_after = $_POST['edit']['delete_after'];
@@ -409,9 +406,10 @@ function _image_import_form() {
   $html = '<p>' . t('An explanation of how to import images is available on the %helplink page.',array('%helplink'=>l(t('detailed instructions'),'node/add/image_import/help')));
 
   $form = array();
-  if ($taxonomy_form = taxonomy_node_form($dummy_node)) {
+  /*if ($taxonomy_form = taxonomy_node_form($dummy_node)) {
     $form += $taxonomy_form;
-  }
+  }*/
+
   $form['advanced'] = array(
     '#type' => 'fieldset',
     '#title' => t('Advanced settings'),
@@ -463,7 +461,15 @@ function _image_import_form() {
     '#value' => t('Import images'),
   );
 
-  $html .= drupal_get_form('image_import_add', $form);
+  /* added the following to trick taxonomy_form_alter into adding the categories form element */
+  $node = new stdclass();
+  $node->type = 'image';
+  $form['#node'] = $node;
+  $form['type'] = array('#value' => 'image');
+  /* end of trick */
+
+  // changed the form_id to contain the fragment _node_form; also needed to trick taxonomy_form_alter
+  $html .= drupal_get_form('image_node_form', $form);
   return $html;
 }
 
@@ -610,6 +616,7 @@ function image_import_import($precheck_o
       return IMAGE_IMPORT_STATUS_ABORT;
     }
     $terms =& _image_import_extract_tids($_POST['edit']['taxonomy']);
+
     if (! is_array($terms) || count($terms) < 1) {
       drupal_set_message(t('No categories selected for images; aborting.'),'error');
       return IMAGE_IMPORT_STATUS_ABORT;
@@ -784,11 +791,15 @@ function image_import_import_one($file, 
   $node->moderate = in_array('moderate', $nodeoptions) ? 1 : 0;
   $node->comment  = variable_get('comment_image_import',0);
 
+$node->taxonomy = $terms;
+
   if (! image_import_do_node($node, $path)) {
     return IMAGE_IMPORT_STATUS_ERROR;
   }
+
   $nid = $node->nid;
-  taxonomy_node_save($nid, $terms);
+
+  //taxonomy_node_save($nid, $terms);
   if ($debug) drupal_set_message(t('DEBUG: Saved taxonomy for node nid=%nid',array('%nid'=>$nid)),'debug');
   _image_build_derivatives($node, FALSE);
   if ($debug) drupal_set_message(t('DEBUG: Built derivatives for node nid=%nid',array('%nid'=>$nid)),'debug');
@@ -796,7 +807,7 @@ function image_import_import_one($file, 
   if ($do_delete) {
     $cap_ok = file_exists($caption_path) ? file_delete($caption_path) : FALSE;
     if ($cap_ok) drupal_set_message(t('Deleted caption file %p',array('%p'=>$caption_path)),'status');
-    $img_ok = file_exists($path)   ? file_delete($path) : FALSE; 
+    $img_ok = file_exists($path)   ? file_delete($path) : FALSE;
     if ($img_ok) drupal_set_message(t('Deleted image file %p',array('%p'=>$path)),'status');
   }
 
@@ -838,8 +849,11 @@ function image_import_do_node(&$node, $p
   }
   $node->file = $node->images['_original'] = $new_path;
 
-  if ($nid = node_submit($node)) {
-    $node->nid = $nid;
+  // saving a node - first step is to validate
+  $node = node_submit($node);
+  if ($node->validated) {
+    // ... then we save the node
+    node_save($node);
     if ($debug) drupal_set_message(t('DEBUG: Saved node nid=%nid',array('%nid'=>$nid)),'debug');
     watchdog('image import',t('Imported "%p" as node %nid',array('%p'=>$path, '%nid'=>$nid)), WATCHDOG_NOTICE, l(t('view'),"node/$nid"));
   } else {
@@ -855,8 +869,8 @@ function image_import_do_node(&$node, $p
  */
 function &_image_import_get_file_object($filepath) {
   $info = image_get_info($filepath);
-  $file = new StdClass(); 
-  $file->filename = trim(basename($filepath), '.'); 
+  $file = new StdClass();
+  $file->filename = trim(basename($filepath), '.');
   $file->filemime = $info['mime_type'];
   $file->filepath = $filepath;
   $file->error = '';
