--- userplus.module.orig	Thu Nov 13 18:43:04 2008
+++ userplus.module	Wed Feb 25 12:27:17 2009
@@ -87,6 +87,20 @@ function userplus_add_users() {
 
   $form['user'] = array('#tree' => true);
   $form['role'] = array('#tree' => true);
+  $form['profile'] = array('#tree' => true);
+
+  if (module_exists('profile')) {
+    $result = db_query('SELECT fid, name, title, type FROM {profile_fields} WHERE required = %d ORDER BY category, weight', 1);
+	  while ($record = db_fetch_object($result)) {
+        $profile_field[$record->name] = array(
+     	  '#type' => $record->type,
+     	  '#size' => 16,
+     	  '#maxlength' => 64,
+     	  '#default_value' => '',
+     	);
+
+ 	  }
+    }
 
   $max_add_users = variable_get('userplus_max_add_users', 12);
 
@@ -107,6 +121,12 @@ function userplus_add_users() {
             '#size' => 16,
             '#maxlength' => 32);
 
+	if (is_array($profile_field)) {
+		foreach ($profile_field as $pf_name => $pf) {
+			$form['profile'][$i][$pf_name] = $pf;
+		}
+	}
+
     foreach ($roles as $role_rid => $role_name) {
       $form['role'][$i][$role_rid] =
         array('#type' => 'checkbox',
@@ -143,6 +163,12 @@ function userplus_add_users_submit($form
           }
         }
 
+      	if ($form_state['values']['profile']) {
+	      	foreach ($form_state['values']['profile'][$i] as $pf_name => $pf_value) {
+		      	$u['profile'][$pf_name] = $pf_value;
+	      	}
+  	   }
+
         // HACK - We're going to need a unique id for any form errors, so use this index...
         //
         // Note that when the errors show up on the page, there won't be any information
@@ -214,6 +240,11 @@ function userplus_add_users_submit($form
           'status' => 1
         )
       );
+
+      if (is_array($u['profile'])) {
+      	profile_save_profile($u['profile'], $account, NULL, TRUE);
+  	  }
+
       // Send mail to user, liberally copied from user_register_submit
       if ($form_state['values']['notify']) {
         // Add plain text password into user account to generate mail tokens.
@@ -238,6 +269,12 @@ function userplus_add_users_submit($form
 
 function theme_userplus_add_users($form) {
   $header = array('', 'username', 'e-mail address', 'password');
+  if (module_exists('profile')) {
+    $result = db_query('SELECT title FROM {profile_fields} WHERE required = %d ORDER BY category, weight', 1);
+    while ($record = db_fetch_object($result)) {
+    	$header[] = $record->title;
+	}
+   }
   
   foreach (element_children($form['role_names']) as $rid) {
     $header[] = $form['role_names'][$rid]['#value'];
@@ -252,6 +289,11 @@ function theme_userplus_add_users($form)
     $row[] = drupal_render($user['name']);
     $row[] = drupal_render($user['mail']);
     $row[] = drupal_render($user['pass']);
+    if (is_array($form['profile'])) {
+	    foreach (element_children($form['profile'][$i]) as $pf_name) {
+			$row[] = drupal_render($form['profile'][$i][$pf_name]);
+		}
+	}
 
     foreach (element_children($form['role'][$i]) as $role_rid) {
       $row[] = drupal_render($form['role'][$i][$role_rid]);
