--- image_attach.module	Fri Mar  2 19:50:18 2007
+++ image_attach.module.combined	Fri Mar  2 19:46:12 2007
@@ -51,6 +51,14 @@ function image_attach_admin_settings() {
     '#description' => t('When enabled, will allow existing image nodes to be attached instead of uploading new images.')
   );
 
+  $form['image_attach_limit_user'] = array(
+    '#type' => 'radios',
+    '#title' => t('Limit images to current user'),
+    '#default_value' => variable_get('image_attach_limit_user', 0),
+    '#options' => array(0 => 'Disabled', 1 => 'Enabled'),
+    '#description' => t('When enabled, will only list images from the current user.')
+  );
+
   return system_settings_form($form);
 }
 
@@ -159,9 +167,11 @@ function image_attach_nodeapi(&$node, $o
       break;
     case 'insert':
     case 'update':
-      if ($node->iid) {
+      if (isset($node->iid)) {
         db_query("DELETE FROM {image_attach} WHERE nid=%d", $node->nid);
-        db_query("INSERT INTO {image_attach} (nid, iid) VALUES (%d, %d)", $node->nid, $node->iid);
+        if ($node->iid > 0) {
+          db_query("INSERT INTO {image_attach} (nid, iid) VALUES (%d, %d)", $node->nid, $node->iid);
+        }
       }
       break;
     case 'delete':
@@ -192,8 +202,17 @@ function image_attach_nodeapi(&$node, $o
  * Fetch an array of all candidate referenced nodes, for use in presenting the selection form to the user.
  */
 function _image_attach_get_image_nodes() {
-  $rows = array(0 => '');
-  $result = db_query(db_rewrite_sql("SELECT n.nid, n.title FROM {node} n WHERE n.status=1 AND type='image' ORDER BY n.sticky DESC, n.title ASC"));
+  $rows = array(0 => 'None');
+  global $user;
+  if (variable_get('image_attach_limit_user', 0)) {
+    $where = "type='image' AND n.uid=". $user->uid;
+  }
+  else {
+    $where = "n.status=1 AND type='image'";
+  }
+
+  $result = db_query(db_rewrite_sql("SELECT n.nid, n.title FROM {node} n WHERE ". $where . " ORDER BY n.sticky DESC, n.title ASC"));
+
   if (db_num_rows($result) == 0) {
       return array();
   }
@@ -328,4 +347,5 @@ function theme_image_attach_body($node){
   $output .= l(image_display($image, 'thumbnail'), "node/$node->nid", array(), NULL, NULL, FALSE, TRUE);
   $output .= '</div>'."\n";
   return $output;
-}
\ No newline at end of file
+}
+
