Index: contrib/image_attach/image_attach.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/image/contrib/image_attach/image_attach.module,v
retrieving revision 1.37
diff -u -p -r1.37 image_attach.module
--- contrib/image_attach/image_attach.module	12 Feb 2008 21:11:43 -0000	1.37
+++ contrib/image_attach/image_attach.module	12 Mar 2008 03:45:15 -0000
@@ -40,7 +40,6 @@ function image_attach_menu() {
   return $items;
 }
 
-
 function image_attach_admin_settings() {
   $form = array();
 
@@ -230,6 +229,8 @@ function image_attach_form_alter(&$form,
  * Implementation of hook_nodeapi().
  */
 function image_attach_nodeapi(&$node, $op, $teaser, $page) {
+  static $image;
+  
   // Make sure that if an image is deleted it is detached from any nodes.
   if ($node->type == 'image') {
     switch ($op) {
@@ -242,16 +243,20 @@ function image_attach_nodeapi(&$node, $o
     return;
   }
   switch ($op) {
-    case 'prepare':
+    
+    case 'validate':
 	  $validators = array(
 	    'file_validate_is_image' => array(),
 	  );
-      if (file_save_upload('image', $validators)) {
+	  
+      if($image = file_save_upload('image', $validators)) {
+        
         $image->title = $_POST['image_title'];
         $image->uid = $node->uid;
         $image->name = $node->name;
         $image->created = $node->created;
         $image->type = 'image';
+        
         // Set the node's defaults... (copied this from node and comment.module)
         $node_options = variable_get('node_options_image', array('status', 'promote'));
         $image->status = in_array('status', $node_options);
@@ -259,18 +264,14 @@ function image_attach_nodeapi(&$node, $o
         if (module_exists('comment')) {
           $image->comment = variable_get('comment_image', COMMENT_NODE_READ_WRITE);
         }
-        image_prepare($image, 'image');
-        if ($image->images) {
+        
+        // the following was mostly handled in image_prepare in Drupal 5
+        if ($image->filepath) {
+          $image->images[IMAGE_ORIGINAL] = $image->filepath;
           if (empty($image->title)) {
-            $image->title = basename($image->images[IMAGE_ORIGINAL]);
+            $image->title = basename($image->filepath);
           }
           node_validate($image);
-          if (!form_get_errors()) {
-            $image = node_submit($image);
-            node_save($image);
-            $node->iid = $image->nid;
-            $node->new_image = TRUE;
-          }
         }
       }
       elseif (!empty($_POST['iid'])) {
@@ -280,6 +281,11 @@ function image_attach_nodeapi(&$node, $o
 
     case 'insert':
     case 'update':
+      if($image) {
+        node_save($image);
+        $node->iid = $image->nid;
+        $node->new_image = TRUE;
+      }
       if (isset($node->iid)) {
         db_query("DELETE FROM {image_attach} WHERE nid=%d", $node->nid);
         if ($node->iid > 0) {
