78,84c78,84
<             $image = node_load($node->iid);
<             if (node_access('view', $image)) {
<               $img = image_display($image, variable_get('image_attach_block_0_size', IMAGE_THUMBNAIL));
<               return array(
<                 'subject' => t('Attached Images'),
<                 'content' => l($img, "node/$node->iid", array('html' => TRUE)),
<               );
---
>             $output['subject'] = t('Attached Images');
>             foreach ($node->iid as $this_image) {
>               $image = node_load($this_image);
>               if (node_access('view', $image)) {
>                 $img = image_display($image, variable_get('image_attach_block_0_size', IMAGE_THUMBNAIL));
>                 $content .= '<div class="attached-image">'.l($img, "node/$this_image", array('html' => TRUE)).'</div>';
>               }
85a86,87
>             $output['content'] = $content;
>             return $output;
191,196c193,200
<         $image = node_load($node->iid);
<         $form['image_attach']['image_thumbnail'] = array(
<           '#type' => 'item',
<           '#title' => t('Thumbnail'),
<           '#value' => image_display($image, 'thumbnail')
<         );
---
>         foreach ($node->iid as $iid) {
>           $image = node_load($iid);
>           $form['image_attach']['image_thumbnail'][] = array(
>             '#type' => 'item',
>             '#title' => t('Thumbnail'),
>             '#value' => image_display($image, 'thumbnail')
>           );
>         }
204c208,210
<           '#description' => t('Choose an image already existing on the server if you do not upload a new one.')
---
>           '#description' => t('Choose an image already existing on the server if you do not upload a new one.'),
>           '#multiple' => TRUE,
>           '#size' => 6
213,216c219,224
<         $form['image_attach']['iid'] = array(
<           '#type' => 'hidden',
<           $value => empty($node->iid) ? NULL : $node->iid,
<         );
---
>         foreach ($node->iid as $iid) {
>           $form['image_attach']['iid'][] = array(
>             '#type' => 'hidden',
>             $value => empty($iid) ? NULL : $iid,
>           );
>         }
227a236,259
>       //additional submit button which adds image and brings you back to node edit
>       $form['image_attach']['image_attach_multiple'] = array(
>         '#type' => 'submit',
>         '#value' => t('Attach'),
>         '#submit' => array('image_attach_image_add_submit'),
>         '#validate' => array('image_attach_validate'),
>       );
>     }
>   }
> }
> 
> /**
>  * This submit function adds a new image and returns you to the
>  * node edit form directly afterwards, without creating the new node yet
>  */
> function image_attach_image_add_submit(&$form, &$form_state) {
>   // Rebuild the attached image data
>   if (isset($form_state['values']['iid'])) {
>   	db_query("DELETE FROM {image_attach} WHERE nid=%d", $form['nid']['#value']);
>     if (count($form_state['values']['iid'])) {
>       $form_state['values']['iid'] = is_array($form_state['values']['iid']) ? $form_state['values']['iid'] : array($form_state['values']['iid']);
>       foreach ($form_state['values']['iid'] as $iid) {
>         db_query("INSERT INTO {image_attach} (nid, iid) VALUES (%d, %d)", $form['nid']['#value'], $iid);
>       }
229a262,264
>   
>   // Rebuild the node edit form
>   node_form_submit_build_node($form, &$form_state);
238c273
< function image_attach_validate($form, &$form_state) {
---
> function image_attach_validate(&$form, &$form_state) {
248c283,284
<       form_set_value($form['image_attach']['iid'], $image->nid, $form_state);
---
>       // This line changed to append to array of images instead of reset the single value
>       $form_state['values']['iid'][$image->nid] = $image->nid;
273,274c309,313
<         if ($node->iid > 0) {
<           db_query("INSERT INTO {image_attach} (nid, iid) VALUES (%d, %d)", $node->nid, $node->iid);
---
>         if (count($node->iid)) {
>           $node->iid = is_array($node->iid) ? $node->iid : array($node->iid);
>           foreach ($node->iid as $iid) {
>             db_query("INSERT INTO {image_attach} (nid, iid) VALUES (%d, %d)", $node->nid, $iid);
>           }
284,285c323,328
<       $iid = db_result(db_query("SELECT iid FROM {image_attach} WHERE nid=%d", $node->nid));
<       return array('iid' => $iid);
---
>       $res = (db_query("SELECT iid FROM {image_attach} WHERE nid=%d", $node->nid));
>       $iids = array();
>       while($iid = db_fetch_array($res) ){
>         $iids[] = $iid['iid'];
>       }
>       return array('iid' => $iids);
289c332
<       if ($node->iid) {
---
>       if (count($node->iid)) {
291,294c334,343
<         $node->content['image_attach'] = array(
<           '#value' => theme("image_attach_{$teaser_or_body}", $node),
<           '#weight' => variable_get("image_attach_weight_{$teaser_or_body}_{$node->type}", 0),
<         );
---
>         $node->content['image_attach'] = array();
>         if ($teaser_or_body == 'teaser') {
>           $node->content['image_attach'][$node->iid[0]]['#value'] = theme("image_attach_{$teaser_or_body}", $node, $node->iid[0]);
>           $node->content['image_attach'][$node->iid[0]]['#weight'] = variable_get("image_attach_weight_{$teaser_or_body}_{$node->type}", 0);
>         } else {
>           foreach ($node->iid as $iid) {
>             $node->content['image_attach'][$iid]['#value'] = theme("image_attach_{$teaser_or_body}", $node, $iid);
>             $node->content['image_attach'][$iid]['#weight'] = variable_get("image_attach_weight_{$teaser_or_body}_{$node->type}", 0);
>           }
>         }
300c349
<       if ($node->iid && $image = node_load($node->iid)) {
---
>       if (count($node->iid) && $image = node_load($node->iid)) {
305c354
<             'url' => url("image/view/{$node->iid}/". IMAGE_PREVIEW, array('absolute' => TRUE)),
---
>             'url' => url("image/view/{$node->iid[0]}/". IMAGE_PREVIEW, array('absolute' => TRUE)),
348c397,398
< function theme_image_attach_teaser($node) {
---
> function theme_image_attach_teaser($node, $iid) {
>   $output = '';
353,354c403,404
< 
<     $image = node_load($node->iid);
---
>   
>     $image = node_load($iid);
357c407
<       return NULL;
---
>       return $output;
361,362c411,412
<     $output = '<div style="width: '. $info['width'] .'px" class="image-attach-teaser">';
<     $output .= l(image_display($image, $img_size), "node/$node->nid", array('html' => TRUE));
---
>     $output .= '<div style="width: '. $info['width'] .'px" class="image-attach-teaser">';
>     $output .= l(image_display($image, $img_size), "node/$iid", array('html' => TRUE));
364,365d413
< 
<     return $output;
366a415
>   return $output;
372c421,422
< function theme_image_attach_body($node) {
---
> function theme_image_attach_body($node, $iid) {
>   $output = '';
378,387c428,433
<     $image = node_load($node->iid);
<     if (!node_access('view', $image)) {
<       // If the image is restricted, don't show it as an attachment.
<       return NULL;
<     }
<     $info = image_get_info(file_create_path($image->images[$img_size]));
< 
<     $output = '<div style="width: '. $info['width'] .'px" class="image-attach-body">';
<     $output .= l(image_display($image, $img_size), "node/$node->iid", array('html' => TRUE));
<     $output .= '</div>'."\n";
---
>       $image = node_load($iid);
>       if (!node_access('view', $image)) {
>         // If the image is restricted, don't show it as an attachment.
>         continue;
>       }
>       $info = image_get_info(file_create_path($image->images[$img_size]));
389c435,437
<     return $output;
---
>       $output .= '<div style="width: '. $info['width'] .'px" class="image-attach-body">';
>       $output .= l(image_display($image, $img_size), "node/$iid", array('html' => TRUE));
>       $output .= '</div>'."\n";
390a439
>   return $output;
