diff -urp user_import/supported/content_profile.inc user_import_enhanced/supported/content_profile.inc
--- user_import/supported/content_profile.inc	2009-10-24 17:10:47.000000000 -0400
+++ user_import_enhanced/supported/content_profile.inc	2010-02-26 19:43:14.000000000 -0500
@@ -2,32 +2,70 @@
 // $Id: content_profile.inc,v 1.1 2009/10/24 21:10:47 MegaGrunt Exp $
 
 // Functionality depends on node_import and CCK.
-if (module_exists('node_import') && module_exists('content')) {
+$required_modules = array('node_import','content');
+$all_modules_present = TRUE;
+foreach($required_modules as $test_for_this_mod){
+  if(!module_exists($test_for_this_mod)){
+    $all_modules_present = FALSE;
+    drupal_set_message(t('Please enable %module module!', array('%module' => $test_for_this_mod)),'warning');
+  }
+}
 
-  // Load the required API files.
-  include_once('./'. drupal_get_path('module', 'node_import') . '/node_import.api.php');
-  include_once('./'. drupal_get_path('module', 'node_import') . '/node_import.inc');
 
 
-  /**
+if ($all_modules_present) {
+
+  // Load the required API files.
+  //  This isn't present any longer  include_once('./'. drupal_get_path('module', 'node_import') . '/node_import.api.php');
+  include_once('./'. drupal_get_path('module', 'node_import') . '/node_import.inc');
+  include_once('./'. drupal_get_path('module', 'content') . '/includes/content.crud.inc');
+  /*
    * Implementation of hook_user_import_form_field_match(). Add supported Content Profile fields into our dropdown list.
    */
   function content_profile_user_import_form_field_match() {
     $options = array();
-		$options['content_profile'] = array();
-		$field_options = array();  
+    $options['content_profile'] = array();
+    $field_options = array();  
     $contentprofile_types = content_profile_get_types();
 
     foreach ($contentprofile_types as $type => $data) {
       $fields = node_import_fields('node:' . $type, TRUE);
-
       // Give fields a more descriptive title.
       foreach (array_keys($fields) as $key) {
-        if (strstr($key, 'cck:field_')) { 
-          $field_options["$type $key"] = t('Content Profile: (!type) !key ', array('!key' => $fields[$key]['title'], '!type' => $type)); 
+        if (strstr($key, 'cck:field_')) {
+          // if this is a CCK field
+           
+          // lets check and see if it is a Node Reference field.   If so, provide a few options:
+          $key_details = explode(':',$key);
+          if($key_details[2] == 'nid'){
+            // option to set the NID value equal to the NID of the Node that has the value the spreadsheet equal to the title field of the Node.
+            if($fields[$key]['has_multiple']){
+              // if this is a multi value field, indicate as much in the field key so that the key can store the import column name in it
+              $field_options["$type $key:nodetitle_equals_value:multiple"] =t('CP: (!type) !key - Ref Node with title = value (M)', array('!key' => $fields[$key]['title'], '!type' => $type)); 
+            }else{
+              $field_options["$type $key:nodetitle_equals_value:single"]   =t('CP: (!type) !key - Ref Node with title = value', array('!key' => $fields[$key]['title'], '!type' => $type)); 
+            }
+            // option to set the NID value equal to the NID for the Node with the node title as the value in the header of the spreadsheet.  Only set this value if the number '1' appears in the column.
+            if($fields[$key]['has_multiple']){
+              // if this is a multi value field, indicate as much in the field key so that the key can store the import column name in it
+              $field_options["$type $key:nodetitle_equals_header_if_1:multiple"] =t('CP: (!type) !key - Ref Node with title = header if value =1 (M)', array('!key' => $fields[$key]['title'], '!type' => $type)); 
+            }else{
+              $field_options["$type $key:nodetitle_equals_header_if_1:single"]   =t('CP: (!type) !key - Ref Node with title = header if value =1', array('!key' => $fields[$key]['title'], '!type' => $type)); 
+            }
+
+          }  // done if node column points to a node id
+
+          // option to set the NID value (and other value types) directly from the file (currently the only option.)
+          if($fields[$key]['has_multiple']){
+          // if this is a multi value field, indicate as much in the field key so that the key can store the import column name in it
+            $field_options["$type $key:direct_from_value:multiple"]       =t('CP: (!type) !key (M)', array('!key' => $fields[$key]['title'], '!type' => $type)); 
+          }else{
+            $field_options["$type $key:direct_from_value:single"]         =t('CP: (!type) !key ',    array('!key' => $fields[$key]['title'], '!type' => $type)); 
+          }
+
         }
       }
-			
+      			
       // skip merge if there are no fields on the content type
       if (!empty($field_options)) {
         $options['content_profile'] = array_merge($options['content_profile'], $field_options);
@@ -35,10 +73,13 @@ if (module_exists('node_import') && modu
     }
     
     /* We do not support taxonomy yet */
-
     return $options;
   }
 
+
+
+
+
   /**
    * Implementation of hook_user_import_form_update_user().
    */
@@ -55,11 +96,16 @@ if (module_exists('node_import') && modu
     return trim($data[$column_id]);
   }
 
+
+
+
+
+
   /**
    * Implementation of hook_user_import_after_save().
    */
   function content_profile_user_import_after_save($settings, $account, $password, $fields, $updated, $update_setting_per_module) {
- 
+    
     if (!is_array($fields['content_profile'])) return;
     
     // check if it's an existing user and if content profile is to be updated 
@@ -74,26 +120,36 @@ if (module_exists('node_import') && modu
     } 
 
     $contentprofile_types = content_profile_get_types();
-    
     // process each $content profile
     foreach ($contentprofile_types as $type => $configuration) {
-      content_profile_user_import_node($type, $contentprofile, $account, $fields, $updated, $update_setting_per_module['content_profile']);
+      content_profile_user_import_node($type, $contentprofile, $account, $fields, $updated, $update_setting_per_module['content_profile'],$settings['field_match']);
     }
 
     return;
   }
+  
+  
+
+
 
+
+
+
+
+
+  
+  
+  
   /**
    *  callback to create or update a node if appropriate
    */
-  function content_profile_user_import_node($type, $content_profile, $account, $fields, $updated, $update_setting) {
-  
+  function content_profile_user_import_node($type, $content_profile, $account, $fields, $updated, $update_setting, $field_match) {
+    
     if (empty($content_profile[$type])) return;  // pass only those, which are used
- 
     $errors = array();      
     $title_empty = time();
 
-    if ($updated) { 
+    if ($updated) {  // get existing data for this user 
       $node = node_load(array('type' => $type, 'uid' => $account->uid));
     }
 
@@ -104,43 +160,288 @@ if (module_exists('node_import') && modu
       $node->title = $title_empty; 
     } 
 
-    // Assign the mapped fields to the $node.    
-    foreach ($content_profile[$type] as $column_id => $column_data) {
-	
-    	$field_data = explode(':', $column_id);
-    	$field_name = !empty($field_data[1]) ? $field_data[1] : $column_id; 
-      $field_key = !empty($field_data[2]) ? $field_data[2] : 'value';
-      $field_value = array(0 => array($field_key => $column_data[0]));
+       
+    if($updated && $update_setting == UPDATE_REPLACE) {
 
-      if (!$updated) {
-        $node->{$field_name} = $field_value;
+      foreach ($content_profile[$type] as $column_id => $column_data) {
+      // begin iterating through content_profile fields and clear any multiple valued fields (single value fields will just be changed below)
+        $field_data              =  explode(':', $column_id);
+        $field_name              = $field_data[1]; 
+        $field_multiple          = $field_data[4];
+      
+        if($field_multiple == 'multiple'){
+          $node->{$field_name} = Array();  
+        }
       }
-      elseif ($updated && $update_setting == UPDATE_ADD) {
+    }
 
-        $current_content = content_format($field_name, $node->{$field_name}[0], 'default', $node);
 
-        if (empty($current_content) && !empty($column_data[0])) { 
-					$node->{$field_name} = $field_value;
+    foreach ($content_profile[$type] as $column_id => $column_data) {
+      // begin iterating through content_profile fields
+
+      $field_data              =  explode(':', $column_id);
+      $field_name              = $field_data[1]; 
+      $field_format              = $field_data[2];  //  value, nid, etc.   ?????
+      $field_assignment_method = $field_data[3];
+      $field_multiple          = $field_data[4];
+      $field_column_header     = $field_data[5];
+                  
+      $field_details = content_field_instance_read(array('field_name' => $field_data[1]));
+
+      $field_type = $field_details[0]['type'];
+
+      if($field_type == 'nodereference'){
+        // get list of referenceable types and set up list
+        $referenceable_types = $field_details[0]['referenceable_types'];
+        $referenceable_types_in_statement = '';
+        foreach ($referenceable_types as $typename => $typesetting) {
+          settype($typesetting, "string");   // typesetting is an object?, make it a string
+
+          if($typename != $typesetting){
+             //    continue;
+          }else{
+             if($referenceable_types_in_statement == '')
+              $referenceable_types_in_statement .= "'" .   $typename . "'";
+            else
+              $referenceable_types_in_statement .= ", '" . $typename . "'";
+          }
+          
         }
-      }
-      elseif ($updated && $update_setting == UPDATE_REPLACE) {
-        $node->{$field_name} = $field_value; 
+      } // done if type nodereference
+         
+      // if no referenceable types, continue
+      if($referenceable_types = '')
+         continue;
+      
+      if(!$updated) {  
+        // this record is for a totally new user being imported
+  
+        switch($field_assignment_method){    
+          case 'direct_from_value':
+            $field_key =   !empty($field_format) ? $field_format : 'value';
+            if($field_multiple == 'single'){  
+              $node->{$field_name} = array(0 => array($field_key => $column_data[0]));   
+            }else{
+              // just add this node to the list
+              $node->{$field_name}[] = array($field_key => $column_data[0]);   
+            }
+  
+          break;
+          case 'nodetitle_equals_header_if_1':
+            if(  $column_data[0] == 1){
+  
+              // look up the nid for this column name and reset the field_value to that
+              // $column_header = $field_match[$row]['column_name'];
+
+        
+              $sql = "SELECT nid FROM {node} WHERE type IN (" . $referenceable_types_in_statement . ") AND title = '%s'";
+                  
+              $nid = db_result(db_query($sql,$field_column_header));
+              //  throw an error if NODE wasn't found
+              if(!$nid)
+                user_import_errors(t('Node with matching title of type(s) ') . '<i>' .$referenceable_types_in_statement . '</i>' . 
+                        t(' not found for column header ') . '<i>' .  $field_column_header . '</i>' . t('.') );
+              // ok, now see if this nid is set in this node;  if not, set it
+              if($field_multiple == 'single'){  
+                $node->{$field_name} = Array(0 => array('nid' => $nid));  
+               
+              }else{
+                // just add this node to the list
+                $node->{$field_name}[] = Array('nid' => $nid);  
+              }
+            }
+          break;
+          case 'nodetitle_equals_value':
+              // look up the nid for this value in the CSV file
+        
+              $sql = "SELECT nid FROM {node} WHERE type IN (" . $referenceable_types_in_statement . ") AND title = '%s'";
+                  
+              $nid = db_result(db_query($sql,$column_data[0]));
+              //  throw an error if NODE wasn't found
+              if(!$nid){
+
+                user_import_errors(t('Node with matching title of type(s) ') . '<i>' . $referenceable_types_in_statement . '</i>' . 
+                        t(' not found for value ') . '<i>' . $column_data[0] . '</i>' . t('.') );
+              }
+              // ok, now see if this nid is set in this node;  if not, set it
+              if($field_multiple == 'single'){  
+                $current_content = content_format($field_name, $node->{$field_name}[0], 'default', $node);
+                if (empty($current_content) && !empty($nid)) { 
+		  $node->{$field_name} = Array(0 => array('nid' => $nid));  
+               }             
+              }else{
+                // just add this node to the list
+                $node->{$field_name}[] = Array('nid' => $nid);  
+              }
+                  
+
+          break;
+          }  // done switch
+
+            
+      } elseif ($updated && $update_setting == UPDATE_ADD) {   // add but don't update     
+        // we are adding nodereference values to this record
+         
+        switch($field_assignment_method){    
+          case 'direct_from_value':
+
+            $field_key =   !empty($field_format) ? $field_format : 'value';
+       
+            $current_content = content_format($field_name, $node->{$field_name}[0], 'default', $node);
+            if($field_multiple == 'single'){ 
+              if (empty($current_content) && !empty($column_data[0])) {  
+                $node->{$field_name} = array(0 => array($field_key => $column_data[0]));
+              }
+            }else{  // multiple -- don't need to check if it is empty   
+               // check and see if this nid is already in the list before adding it
+               if(!in_array( array($field_key => $column_data[0]), $node->{$field_name}))
+                 $node->{$field_name}[] =  array($field_key => $column_data[0]);
+            }	  
+          break;
+          case 'nodetitle_equals_header_if_1':
+
+            if( /* $type == 'nodereference' && */  $column_data[0] == 1){
+  
+              // look up the nid for this column name and reset the field_value to that
+              // $column_header = $field_match[$row]['column_name'];
+              $sql = "SELECT nid FROM {node} WHERE type IN (" . $referenceable_types_in_statement . ") AND title = '%s'";
+                  
+              $nid = db_result(db_query($sql,$field_column_header));
+              //  throw an error if NODE wasn't found
+              if(!$nid)
+                user_import_errors(t('Node with matching title of type(s) ') . '<i>' .  $referenceable_types_in_statement . '</i>' . 
+                        t(' not found for column header ') . '<i>' .  $field_column_header . '</i>' .  t('.') );
+              // ok, now see if this nid is set in this node;  if not, set it
+              if($field_multiple == 'single'){  
+                $current_content = content_format($field_name, $node->{$field_name}[0], 'default', $node);
+                if (empty($current_content) && !empty($nid)) { 
+		  $node->{$field_name} = Array(0 => array('nid' => $nid));  
+                }             
+              }else{  // multiple
+                // check and see if this nid is already in the list before adding it
+                if(!in_array(Array('nid' => $nid), $node->{$field_name}))
+                  $node->{$field_name}[] = Array('nid' => $nid);  
+
+             }
+            }
+          break;
+          case 'nodetitle_equals_value':
+              // look up the nid for this value in the CSV file
+        
+              $sql = "SELECT nid FROM {node} WHERE type IN (" . $referenceable_types_in_statement . ") AND title = '%s'";
+                  
+              $nid = db_result(db_query($sql,$column_data[0]));
+              //  throw an error if NODE wasn't found
+              if(!$nid){
+                user_import_errors(t('Node with matching title of type(s) ') . '<i>' . $referenceable_types_in_statement . '</i>' . 
+                    t(' not found for value ') . '<i>' . $column_data[0] . '</i>' . t('.') );
+              }
+
+              // ok, now see if this nid is set in this node;  if not, set it
+              if($field_multiple == 'single'){  
+                $current_content = content_format($field_name, $node->{$field_name}[0], 'default', $node);
+                if (empty($current_content) && !empty($nid)) { 
+		  $node->{$field_name} = Array(0 => array('nid' => $nid));  
+                }             
+              }else{
+                if(!in_array(Array('nid' => $nid), $node->{$field_name}))
+                   $node->{$field_name}[] = Array('nid' => $nid);  
+
+                  
+              }
+            
+
+          break;
+        }  // done switch
+
+
+       }elseif ($updated && $update_setting == UPDATE_REPLACE) {
+         
+         // already cleared out existing settings for the multiple value fields
+         // so we're doing the same thing here that we would do if this was a non-updated node
+ 
+        switch($field_assignment_method){    
+          case 'direct_from_value':
+            $field_key =   !empty($field_format) ? $field_format : 'value';
+            if($field_multiple == 'single'){  
+              $node->{$field_name} = array(0 => array($field_key => $column_data[0]));
+            }else{
+              // just add this node to the list
+              $node->{$field_name}[] = array($field_key => $column_data[0]);
+            }
+          
+          break;
+          case 'nodetitle_equals_header_if_1':
+
+            if(  $column_data[0] == 1){
+  
+              // look up the nid for this column name and reset the field_value to that
+              // $column_header = $field_match[$row]['column_name'];
+
+        
+              $sql = "SELECT nid FROM {node} WHERE type IN (" . $referenceable_types_in_statement . ") AND title = '%s'";
+                  
+              $nid = db_result(db_query($sql,$field_column_header));
+              //  throw an error if NODE wasn't found
+              if(!$nid)
+                user_import_errors(t('Node with matching title of type(s) ') . '<i>' . $referenceable_types_in_statement . '</i>' . 
+                        t(' not found for column header ') . '<i>' . $field_column_header . '</i>' . t('.') );
+              // ok, now see if this nid is set in this node;  if not, set it
+              if($field_multiple == 'single'){  
+                $node->{$field_name} = Array(0 => array('nid' => $nid));
+               
+              }else{
+                // just add this node to the list
+                $node->{$field_name}[] = Array('nid' => $nid);  
+              }
+            }
+          break;
+          case 'nodetitle_equals_value':
+              // look up the nid for this value in the CSV file
+        
+              $sql = "SELECT nid FROM {node} WHERE type IN (" . $referenceable_types_in_statement . ") AND title = '%s'";
+                  
+              $nid = db_result(db_query($sql,$column_data[0]));
+              //  throw an error if NODE wasn't found
+              if(!$nid){
+                user_import_errors(t('Node with matching title of type(s) ') . '<i>' . $referenceable_types_in_statement . '</i>' . 
+                        t(' not found for value ') .'<i>' .  $column_data[0] .'</i>' . t('.') );
+              }else{
+                // ok, now see if this nid is set in this node;  if not, set it
+                if($field_multiple == 'single'){  
+                  $current_content = content_format($field_name, $node->{$field_name}[0], 'default', $node);
+                  if (empty($current_content) && !empty($nid)) { 
+	  	    $node->{$field_name} = Array(0 => array('nid' => $nid));
+                  }        
+                }else{
+                  if(!in_array(Array('nid' => $nid), $node->{$field_name}))
+                    $node->{$field_name}[] = Array('nid' => $nid);  
+                }
+              }
+
+          break;
+        }  // done switch
+
+
+
       }  
-    }
+      $row++;
+    }  // done iterating through the content_profile fields 
     
-		// not actually checking for errors at the moment, but lete's leave this in for when we do
+	// not actually checking for errors at the moment, but lets leave this in for when we do
     if (empty($errors)) {
       $node->uid = $account->uid;
       $node->name = $account->name;
 
+
       // Assign a default title if one has not already been mapped.
       if (!isset($node->title) || empty($node->title) || $node->title == $title_empty) {
         $node->title = $node->name;
       }
-      
+
       $node = node_submit($node); 
       
-      // make sure author is not changed when submited (hapens if existing node)
+      // make sure author is not changed when submited (happens if existing node)
       $node->uid = $account->uid;
       $node->name = $account->name;
        
@@ -157,6 +458,5 @@ if (module_exists('node_import') && modu
     } 
   }
 
-} else {
-  drupal_set_message(t('Please enable %module module!', array('%module' => 'node_import')));
-}
+}  // done if all modules present
+
diff -urp user_import/supported/user_import.inc user_import_enhanced/supported/user_import.inc
--- user_import/supported/user_import.inc	2009-03-21 18:32:42.000000000 -0400
+++ user_import_enhanced/supported/user_import.inc	2010-02-26 20:04:55.000000000 -0500
@@ -19,8 +19,10 @@ function user_import_user_import_form_fi
  * Implementation of hook_user_import_after_save().
  */
 function user_import_user_import_after_save($settings, $account, $password, $fields, $updated, $update_setting_per_module) {
-  if (!empty($settings['send_email']) && !$updated) {
-		_user_import_send_email($account, 
+  
+  if (!empty($settings['send_email']) &&  (!$updated || ($update_setting_per_module['send_email_existing'] == SEND_EMAIL_EXISTING)) ) {
+
+  	_user_import_send_email($account, 
 														$password, 
 														$fields, 
 														$settings['options']['subject'], 
@@ -31,6 +33,10 @@ function user_import_user_import_after_s
 	} 
 }
 
+
+
+
+
 // Send email when account is created    
 function _user_import_send_email($account, $password, $profile, $subject, $body, $format, $css, $subscribed) {
 
@@ -128,6 +134,15 @@ function _user_import_edit_settings_fiel
       '#default_value' => $import['send_email'],
       '#description' => t('Send email to users when their account is created.'),
   );
+
+  /*
+  $form['optional']['send_email_existing'] = array(
+      '#type' => 'checkbox',
+      '#title' => t('Send Email to Existing Users'),
+      '#default_value' => $import['send_email_existing'],
+      '#description' => t('Send email users who already have an account on the system.  No password can be sent. Option above must be checked for this to work.'),
+  );
+  */
   
   $form['optional']['username_space'] = array(
       '#type' => 'checkbox',
@@ -319,3 +334,14 @@ function _user_import_publication_email(
     }
   }  
 }
+
+
+
+/**
+ * Implementation of hook_user_import_form_update_user().
+ */
+function user_import_user_import_form_update_user() {
+  $form['send_email_existing'] = 
+    array('title' => t('Send Email'), 'description' => t('Affected: no data changed but sends email to existing users as well.  No password can be sent. Option to send email must be checked for this to work.'), 'send_email_existing' => TRUE);
+  return $form;
+}
\ No newline at end of file
diff -urp user_import/user_import.module user_import_enhanced/user_import.module
--- user_import/user_import.module	2009-09-20 07:58:10.000000000 -0400
+++ user_import_enhanced/user_import.module	2010-02-26 21:44:37.000000000 -0500
@@ -5,10 +5,13 @@
 define ('UPDATE_NONE', 0);
 define ('UPDATE_REPLACE', 1);
 define ('UPDATE_ADD', 2);
+define ('SEND_EMAIL_EXISTING',3);
+
+include_once('./'. drupal_get_path('module', 'content') . '/includes/content.crud.inc');
 
 /**
  * @file
- * Import or update users with data from a comma separated file (csv).
+ * Import or update users with data from a comma separated file (CSV).
  */
 
 /**
@@ -41,7 +44,7 @@ function user_import_theme() {
 function user_import_help($path, $arg) {
   switch ($path) {
     case 'admin/user/user_import':
-      return t("Import or update users from a comma separated file (csv). Click 'Import' to start a new import.");
+      return t("Import or update users from a comma separated file (CSV). Click 'Import' to start a new import.");
   }
 }
 
@@ -58,7 +61,7 @@ function user_import_perm() {
 function user_import_menu() {
   $items['admin/user/user_import'] = array(
       'title' => 'User Imports',
-      'description' => 'Import or update users from a comma separated file (csv).',
+      'description' => 'Import or update users from a comma separated file (CSV).',
       'page callback' => 'user_import_list',
       'access arguments' => array('import users'),
       );
@@ -161,7 +164,7 @@ function user_import_configure_form() { 
         '#default_value' =>  variable_get('user_import_line_max', 1000),
         '#size' => 10,
         '#maxlength' => 10,
-        '#description' => t('The default is set at 1,000 characters, if a line in your csv is longer than this you should set a higher maximum here. Setting higher maximums will slow down imports.'),
+        '#description' => t('The default is set at 1,000 characters, if a line in your CSV is longer than this you should set a higher maximum here. Setting higher maximums will slow down imports.'),
     );
     
     
@@ -381,7 +384,14 @@ function user_import_edit($form_state, $
 
     foreach ($update_user as $module => $display) {
       
-      $options = array(UPDATE_NONE => t('No Update'), UPDATE_REPLACE => t('Replace Data'), UPDATE_ADD => t('Add Data'));
+      $options = array(UPDATE_NONE => t('No Update'), UPDATE_REPLACE => t('Replace Data'), UPDATE_ADD => t('Add Data'), SEND_EMAIL_EXISTING => t('Send Email to Existing Users'));
+      if ($display['send_email_existing']){         
+        unset($options[UPDATE_ADD]);
+        unset($options[UPDATE_REPLACE]);
+      }else{
+        unset($options[SEND_EMAIL_EXISTING]);
+      }
+
       if ($display['exclude_add'] == TRUE) unset($options[UPDATE_ADD]);
       if ($display['exclude_replace'] == TRUE) unset($options[UPDATE_REPLACE]);
          
@@ -410,7 +420,7 @@ function user_import_edit($form_state, $
       '#type' => 'submit', 
       '#value' => t('Import'),
       '#weight' => 100,
-			'#submit' => array('user_import_import_submit', 'user_import_edit_submit'),
+      '#submit' => array('user_import_import_submit', 'user_import_edit_submit'),
   );
   
   $form['cancel'] = array(
@@ -442,7 +452,10 @@ function user_import_edit_validate($form
 
     // check each field is unique
     if ($values['field_match'] != '0' && $values['field_match'] != '-------------' && in_array($values['field_match'], $fields)) {
-      form_set_error('field_match', t('Database fields can only be matched to one column of the csv file.'));
+      $column_info = explode(':',$values['field_match']);
+      $column_details = content_field_instance_read(array('field_name' => $column_info[1]));  
+      if(!$column_details[0]['multiple'])
+        form_set_error('field_match', t('Database fields can only be matched to one column of the CSV file unless the destination is a multivalue CCK field.'));
     }
  
     $fields[$values['field_match']] = $values['field_match'];
@@ -451,7 +464,7 @@ function user_import_edit_validate($form
     if ($values['field_match'] == 'user-email') $email = TRUE;
   }
 
-  if (!$email) form_set_error('email', t('One column of the csv file must be set as the email address.'));
+  if (!$email) form_set_error('email', t('One column of the CSV file must be set as the email address.'));
 
   if ($form_state['values']['name']) {
      $form_state['values']['name'] = rtrim($form_state['values']['name']);
@@ -520,8 +533,8 @@ function user_import_test_submit($form, 
  * 
  */
 function user_import_import_submit($form, &$form_state) {
-	$form_state['values']['setting'] = 'import'; 
-	drupal_set_message (t('Imported'));
+  $form_state['values']['setting'] = 'import'; 
+  drupal_set_message (t('Imported'));
 }
 
 /**
@@ -529,9 +542,10 @@ function user_import_import_submit($form
  */
 function user_import_edit_submit($form, &$form_state) {
 
-	if ($form_state['values']['setting'] == 'file set') $filepath = file_move($form_state['values']['filepath'], file_directory_path() . '/' . $form_state['values']['filename']);
-	if (!empty($form_state['values']['og_id'])) $form_state['values']['groups'][$form_state['values']['og_id']] = $form_state['values']['og_id'];
-	$form_state['values']['options']['ftp'] = $form_state['values']['ftp'];
+  if ($form_state['values']['setting'] == 'file set') 
+    $filepath = file_move($form_state['values']['filepath'], file_directory_path() . '/' . $form_state['values']['filename']);
+  if (!empty($form_state['values']['og_id'])) $form_state['values']['groups'][$form_state['values']['og_id']] = $form_state['values']['og_id'];
+  $form_state['values']['options']['ftp'] = $form_state['values']['ftp'];
   $form_state['values'] = _user_import_settings_save($form_state['values']);
   $form_state['values']['save']['update'] = NULL;
   $form_state['values']['import_template_id'] = NULL;
@@ -785,7 +799,7 @@ function theme_user_import_list() {
 
 function theme_user_import_edit($form) {
  
-  $header = array(t('csv column'), t('Drupal fields'), t('username'), t('abbreviate'));
+  $header = array(t('CSV column'), t('Drupal fields'), t('username'), t('abbreviate'));
 
   foreach (element_children($form['field_match']) as $key) {
 
@@ -937,7 +951,7 @@ function _user_import_file_open($filepat
   $handle = @fopen($filepath, "r");
                     
   if (!$handle) {
-    form_set_error('file', t("Could not find the csv file '%filename'", array('%filename' => $filename)), 'error');
+    form_set_error('file', t("Could not find the CSV file '%filename'", array('%filename' => $filename)), 'error');
     return t("Please add your file again."); 
   }
 
@@ -1013,7 +1027,7 @@ function user_import_form_field_match(&$
 
   // add default and email address options
   $user_fields[0] = '-------------';
-  $additional_user_fields = module_invoke_all('user_import_form_field_match');
+  $additional_user_fields = module_invoke_all('user_import_form_field_match');  //get hooks from other functions
  
   foreach ($additional_user_fields as $type => $type_options) {
     if (is_array($type_options)) {
@@ -1029,7 +1043,8 @@ function user_import_form_field_match(&$
   $sort = array(t('no'), 1, 2, 3, 4);
   
   if (empty($data_row)) return; 
-    
+  
+  $user_fields_orig = $user_fields;  
   foreach ($data_row as $data_cell) {        
 
       $form['field_match'][$row]= array(
@@ -1040,6 +1055,26 @@ function user_import_form_field_match(&$
           '#value' => check_plain(drupal_substr($data_cell, 0, 40)),
       );
   
+      // load $settings with the header name for this column in the import field
+      // this alows for us to set the values for the user import
+      $form['field_match'][$row]['column_name'] = array(
+           '#type' => 'hidden',
+           '#default_value' => check_plain($data_cell),
+      );
+      
+      $user_fields = $user_fields_orig; // reset $user_fields to have any has_multiples that it might need
+      foreach ($user_fields as $field_id => $label){      
+        if(!strncmp('content_profile-',$field_id,16)){
+
+          unset($user_fields[$field_id]);
+          $new_field_id = $field_id . ':' . check_plain($data_cell); 
+          // ok, here is the new $field_id, lets put it into the $user_fields array 
+          $user_fields[$new_field_id] = $label;
+          asort($user_fields);
+        } // done if this is a content_profile field
+      } // done iterating through dropdown choices   
+
+
       $form['field_match'][$row]['field_match'] = array( 
           '#type' => 'select',
           '#default_value' => ($import['field_match'][$row]['field_match']) ? $import['field_match'][$row]['field_match'] : $user_fields[0],
@@ -1148,7 +1183,7 @@ function _user_import_profile($key = 'fi
     if (!module_exists('profile')) return; 
     
     static $fields_static;
-		$fields = array();
+    $fields = array();
     
     // avoid making more than one database call for profile info
     if (empty($fields_static)) {
@@ -1205,7 +1240,7 @@ function _user_import_settings_save($set
     $settings['options']['subscribed'] = $settings['subscribed'];
     $settings['options']['update_user'] = $settings['update_user'];
 
-		$settings['options']['roles_new'] = $settings['roles_new'];
+    $settings['options']['roles_new'] = $settings['roles_new'];
     
     // Update settings for existing import
     if ($settings['import_id']) {
@@ -1445,12 +1480,12 @@ function _user_import_process($settings)
                 }
             
                 $settings['processed']++;
-            }
+            }  // done if first line skip
        
             $settings['pointer'] = ftell($handle);
-        
+            $errors = user_import_errors();  // Need to retrieve the errors here to get error reporting to work for new code of content profile
             // save lines that have fatal errors
-            if (!empty($errors)) _user_import_errors_display_save($settings['import_id'], $fields, $account['email'], $errors);
+            if (!empty($errors)) _user_import_errors_display_save($settings['import_id'], $fields, $account->email, $errors);
         }
     }
     
