diff -rupN userplus/userplus_domain/README.txt userplus_new/userplus_domain/README.txt
--- userplus/userplus_domain/README.txt	1970-01-01 10:00:00.000000000 +1000
+++ userplus_domain/README.txt	2010-01-25 11:30:31.575719010 +1100
@@ -0,0 +1,38 @@
+*******************************************************
+    README.txt for userplus_domain.module for Drupal
+*******************************************************
+
+This module was developed by Agileware (www.agileware.net) to add support for
+the domain module (www.drupal.org/project/domain) to userplus.
+
+The userplus domain module supplements the userplus module with the
+following features:
+
+   1. "assign user domains" while "adding multiple users" on a single form
+   2. "assign user domains" to multiple users on a single form
+
+CONFIGURATION:
+
+PERMISSIONS:
+Userplus domain adds two new permissions:
+Both permissions allow users to assign user domains on both the "add multiple users"
+and "assign user domains" pages.
+* assign any domains via userplus - This allows the user to assign users to any
+  domains on the system.
+* assign own domains via userplus - This allows the user to assign users to any
+  domains they are a member of.
+
+NOTE: * The "assign any domains via userplus" permission overrides the
+        "assign own domains via userplus" permission.
+      * Access is also granted with the "administer user" permission.
+        This will give permissions equal to "assign own domains via userplus"
+
+SETTINGS:
+On the admin/settings/userplus form, you can also configure the domains
+that will appear on each of the "add multiple users" and "assign user domains"
+forms.
+
+NOTES:
+The module also honors the "user defaults" domain settings (admin/build/domain/roles).
+This means that some domain checkboxes might be pre-selected and disabled depending
+on your settings on that page.
diff -rupN userplus/userplus_domain/userplus_domain.info userplus_new/userplus_domain/userplus_domain.info
--- userplus/userplus_domain/userplus_domain.info	1970-01-01 10:00:00.000000000 +1000
+++ userplus_domain/userplus_domain.info	2010-01-25 11:24:00.030719538 +1100
@@ -0,0 +1,6 @@
+; $Id$
+name = Userplus domain
+description = Adds domain support for userplus
+dependencies[] = userplus
+dependencies[] = domain
+core = 6.x
diff -rupN userplus/userplus_domain/userplus_domain.module userplus_new/userplus_domain/userplus_domain.module
--- userplus/userplus_domain/userplus_domain.module	1970-01-01 10:00:00.000000000 +1000
+++ userplus_domain/userplus_domain.module	2010-01-25 11:27:40.725719281 +1100
@@ -0,0 +1,280 @@
+<?php
+// $Id$
+
+/**
+ * @file
+ * Adds domain support for the userplus module
+ */
+
+/**
+ * Implementation of hook_menu().
+ */
+function userplus_domain_menu() {
+  $items = array();
+
+  $items['admin/user/userplus/userdomains'] = array(
+    'title' => 'assign user domains',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('userplus_domain_admin_userdomains'),
+    'access callback' => 'userplus_domain_access_callback',
+    'type' => MENU_LOCAL_TASK,
+    'weight' => 1
+  );
+
+  return $items;
+}
+
+/**
+ * If the user has 'administer users' permissions, or either of the
+ * userplus_domain permissions they may access the assign user domains page.
+ */
+function userplus_domain_access_callback() {
+  return user_access('administer users') ||
+         user_access('assign any domains via userplus') ||
+         user_access('assign own domains via userplus');
+}
+
+/**
+ * Implementation of hook_perm().
+ */
+function userplus_domain_perm() {
+  return array(
+    'assign any domains via userplus',
+    'assign own domains via userplus',
+  );
+}
+
+/**
+ * Implementation of hook_theme().
+ */
+function userplus_domain_theme() {
+  return array(
+    'userplus_domain_admin_userdomains' => array(
+      'arguments' => array('form' => array()),
+    ),
+  );
+}
+
+/**
+ * Admin form for mass adding users to domains.
+ */
+function userplus_domain_admin_userdomains() {
+  // Compile user/domainp array:
+  $result = pager_query('SELECT uid, name
+                         FROM {users}
+                         WHERE uid > 0
+                         ORDER BY name',
+                         variable_get('userplus_max_show_user_domains', 25));
+
+  $users = array();
+  while ($user = db_fetch_object($result)) {
+    $users[$user->uid] = $user->name;
+  }
+
+  $result = db_query('SELECT uid, domain_id
+                      FROM {domain_editor}
+                      WHERE uid > 0
+                      ORDER BY uid');
+
+  $users_domains = array();
+  while ($user_domain = db_fetch_object($result)) {
+    $users_domains[$user_domain->uid][$user_domain->domain_id] = $user_domain->domain_id;
+  }
+
+  $result = db_query('SELECT domain_id, sitename
+                      FROM {domain}
+                      ORDER BY sitename');
+
+  $domain_names = array();
+  while ($domain = db_fetch_object($result)) {
+    $domain_names[$domain->domain_id] = $domain->sitename;
+  }
+  // If the user is only allowed to add users to domains they are in.
+  if (!user_access('assign any domains via userplus')) {
+    global $user;
+    $current_user_domains = empty($user->domain_user) ? array() : $user->domain_user;
+    $domain_names = array_intersect_key($domain_names, $current_user_domains);
+  }
+
+  $form['user'] = array('#tree' => TRUE);
+
+  // Make sure to honor domain's role default settings
+  $default_domains = userplus_domain_get_role_defaults($users);
+
+  $weight = 1;
+  foreach ($users as $uid => $user_name) {
+    foreach ($domain_names as $domain_id => $sitename) {
+      $checked = array_key_exists($uid, $users_domains) ? array_key_exists($domain_id, $users_domains[$uid]) : FALSE;
+      // Make sure domain's default roles are checked and can't be changed
+      $checked = $checked || array_key_exists($domain_id, $default_domains[$uid]);
+      $disabled = array_key_exists($domain_id, $default_domains[$uid]);
+
+      $form['user'][$uid][$domain_id] = array(
+        '#type' => 'checkbox',
+        '#title' => $domain_name,
+        '#default_value' => $checked,
+        '#disabled' => $disabled,
+        '#weight' => $weight++,
+      );
+    }
+  }
+
+  // Stick the role names in the form so we can use them in the theme function...
+  $form['domains'] = array(
+    '#value' => $domain_names,
+  );
+  // Stick the user names in the form so we can use them in the theme function...
+  $form['usernames'] = array(
+    '#value' => $users,
+  );
+  // Stick the initial user-domain mappings in there so we can use them in the submit handler...
+  $form['usersdomains'] = array(
+    '#type' => 'hidden',
+    '#value' => serialize($users_domains),
+  );
+
+  $form['submit'] = array(
+    '#type' => 'submit',
+    '#value' => t('Save domains'),
+  );
+
+  return $form;
+}
+
+/**
+ * Theme function for userplus_domain_admin_userdomains() form.
+ *
+ * @ingroup themeable
+ */
+function theme_userplus_domain_admin_userdomains($form) {
+  $rows = array();
+
+  // Render group overview:
+  $header = array(t('User'));
+  foreach ($form['domains']['#value'] as $domain_id => $name) {
+    $header[] = $name;
+  }
+
+  foreach (element_children($form['user']) as $uid) {
+    unset($row);
+    $row[] = array('data' => l($form['usernames']['#value'][$uid], "user/$uid/edit"), 'class' => 'username');
+    foreach (element_children($form['user'][$uid]) as $domain_id) {
+      unset($form['user'][$uid][$domain_id]['#title']);
+      $row[] = drupal_render($form['user'][$uid][$domain_id]);
+    }
+    $rows[] = $row;
+  }
+
+  $output = theme('table', $header, $rows, array('id' => 'users-domains'));
+  $output .= '<br \>';
+
+  // Make sure the values we were just passing throught don't try to print
+  $form['domains']['#printed'] = TRUE;
+  $form['usernames']['#printed'] = TRUE;
+  $output .= drupal_render($form);
+
+  $output .= theme('pager', NULL, variable_get('userplus_max_show_user_domains', 25));
+
+  return $output;
+}
+
+/**
+ * Submit function for userplus_domain_admin_userdomains() form.
+ */
+function userplus_domain_admin_userdomains_submit($form, &$form_state) {
+  // Get the original domain membership data from when
+  // the form was initially loaded...
+  $users_domains = unserialize($form_state['values']['usersdomains']);
+  // Remove subscriptions for only those users that have been
+  // unsubscribed, and create subscriptions for only those users
+  // who are newly subscribed...
+  if (isset($form_state['values']['user']) && is_array($form_state['values']['user'])) {
+    foreach ($form_state['values']['user'] as $uid => $domains) {
+      foreach ($domains as $domain_id => $state) {
+        if ($state == 0) {
+          if (array_key_exists($uid, $users_domains) && array_key_exists($domain_id, $users_domains[$uid])) {
+            userplus_domain_remove_user_domain($uid, $domain_id);
+          }
+        }
+        else {
+          if (!array_key_exists($uid, $users_domains) || !array_key_exists($domain_id, $users_domains[$uid])) {
+            userplus_domain_add_user_domain($uid, $domain_id);
+          }
+        }
+      }
+    }
+  }
+
+  drupal_set_message(t('The changes have been saved.'));
+
+  // Clear the cached pages and menus:
+  cache_clear_all();
+  menu_rebuild();
+
+  drupal_goto($_GET['q'], drupal_get_destination());
+}
+
+/**
+ * Helper function for adding a domain to a user.
+ * This is here because domain has no such helper function.
+ */
+function userplus_domain_add_user_domain($uid, $domain_id) {
+  db_query("INSERT INTO {domain_editor} (uid, domain_id) VALUES (%d, %d)", $uid, $domain_id);
+}
+
+/**
+ * Helper function for removing a domain from a user.
+ */
+function userplus_domain_remove_user_domain($uid, $domain_id) {
+  db_query("DELETE FROM {domain_editor} WHERE uid = %d AND domain_id = %d", $uid, $domain_id);
+}
+
+/**
+ * Helper function to get user role domain defaults.
+ * @param $users - An array of users in the form array($uid => $user_name).
+ *   If the array is empty it will return the defaults for a new user.
+ */
+function userplus_domain_get_role_defaults($users = array()) {
+  $add_roles = variable_get('domain_add_roles', 0);
+  $default_domains = array();
+  $defaults = variable_get('domain_roles', array());
+
+  if (empty($users)) {
+    $users[0] = 'new user';
+  }
+
+  foreach ($users as $uid => $user_name) {
+    $default_domains[$uid] = array();
+    // We still have to get the defaults for new users even if $add_roles is zero
+    if ($add_roles || $uid == 0) {
+      if ($uid == 0) {
+        $roles = array(0);
+      }
+      else {
+        $roles = array(1 => 1);
+        $default_domains[$uid] = array();
+
+        $roles_result = db_query('SELECT * FROM {users_roles} WHERE uid = %d', $uid);
+        while ($role = db_fetch_array($roles_result)) {
+          $roles[$role['rid']] = $role['rid'];
+        }
+      }
+
+      foreach ($roles as $rid) {
+        $filter = array();
+        if (isset($defaults[$rid])) {
+          $filter = array_filter($defaults[$rid]);
+        }
+        if (!empty($filter)) {
+          foreach ($filter as $domain_id => $status) {
+            if ($status) {
+              $default_domains[$uid][$domain_id] = $domain_id;
+            }
+          }
+        }
+      }
+    }
+  }
+
+  return $default_domains;
+}
diff -rupN userplus/userplus.install userplus_new/userplus.install
--- userplus/userplus.install	2009-11-17 11:13:15.000000000 +1100
+++ userplus.install	2010-01-22 17:23:11.000000000 +1100
@@ -12,6 +12,9 @@ function userplus_uninstall() {
     'userplus_max_show_user_roles',
     'userplus_show_required_profile_fields',
     'userplus_show_required_content_profile_fields',
+    'userplus_add_multiple_domains',
+    'userplus_assign_domains',
+    'userplus_max_show_user_domains',
   );
 
   foreach ($variables as $var) {
diff -rupN userplus/userplus.module userplus_new/userplus.module
--- userplus/userplus.module	2009-11-18 09:16:34.000000000 +1100
+++ userplus.module	2010-01-25 11:31:33.104718299 +1100
@@ -112,8 +112,36 @@ function userplus_add_users() {
     }
   }
 
+  // Get domains
+  $domains = array();
+  $allowable_domains = array();
+  $default_domains = array();
+  if (module_exists('userplus_domain') &&
+     (user_access('administer users') || user_access('assign any domains via userplus') || user_access('assign own domains via userplus'))) {
+    $domains = domain_domains();
+    // If the user is only allowed to add users to domains they are in.
+    if (!user_access('assign any domains via userplus')) {
+      global $user;
+      $current_user_domains = empty($user->domain_user) ? array() : $user->domain_user;
+      $domains = array_intersect_key($domains, $current_user_domains);
+    }
+    $allowable_domains = variable_get('userplus_add_multiple_domains', array());
+    // Make sure to honor domain's role default settings
+    $default_domains = userplus_domain_get_role_defaults();
+
+    foreach ($domains as $domain_id => $domain) {
+      if (array_key_exists($domain_id, $allowable_domains)) {
+        $form['domain_names'][$domain_id] = array(
+          '#type' => 'value',
+          '#value' => $domain['sitename'],
+        );
+      }
+    }
+  }
+
   $form['user'] = array('#tree' => TRUE);
   $form['role'] = array('#tree' => TRUE);
+  $form['domain'] = array('#tree' => TRUE);
   $form['profile'] = array('#tree' => TRUE);
   $form['content_profile'] = array('#tree' => TRUE);
 
@@ -229,6 +257,19 @@ function userplus_add_users() {
                 '#default_value' => FALSE);
       }
     }
+
+
+
+    foreach ($domains as $domain_id => $domain) {
+      if (array_key_exists($domain_id, $allowable_domains)) {
+        $domain_role_default = isset($default_domains[0][$domain_id]) ? TRUE : FALSE;
+        $form['domain'][$i][$domain_id] = array(
+          '#type' => 'checkbox',
+          '#default_value' => $domain_role_default,
+          '#disabled' => variable_get('domain_add_roles', 0) && $domain_role_default,
+        );
+      }
+    }
   }
 
   $form['notify'] = array(
@@ -260,6 +301,15 @@ function userplus_add_users_submit($form
           }
         }
 
+        // Domains
+        if ($form_state['values']['domain']) {
+          foreach ($form_state['values']['domain'][$i] as $domain_id => $domain_checked) {
+            if ($domain_checked) {
+              $u['domain_user'][$domain_id] = $domain_id;
+            }
+          }
+        }
+
         if (array_key_exists('profile', $form_state['values']) &&
             array_key_exists('profile_categories', $form_state['values']) &&
             array_key_exists('profile_field_map', $form_state['values'])) {
@@ -346,6 +396,7 @@ function userplus_add_users_submit($form
           'init' => $u['mail'],
           'mail' => $u['mail'],
           'roles' => $u['roles'],
+          'domain_user' => $u['domain_user'],
           'status' => 1
         )
       );
@@ -425,6 +476,9 @@ function theme_userplus_add_users($form)
   foreach (element_children($form['role_names']) as $rid) {
     $header[] = $form['role_names'][$rid]['#value'];
   }
+  foreach (element_children($form['domain_names']) as $domain_id) {
+    $header[] = $form['domain_names'][$domain_id]['#value'];
+  }
 
   foreach (element_children($form['user']) as $i) {
     $user = $form['user'][$i];
@@ -453,6 +507,9 @@ function theme_userplus_add_users($form)
     foreach (element_children($form['role'][$i]) as $role_rid) {
       $row[] = drupal_render($form['role'][$i][$role_rid]);
     }
+    foreach (element_children($form['domain'][$i]) as $domain_id) {
+      $row[] = drupal_render($form['domain'][$i][$domain_id]);
+    }
 
     $rows[] = $row;
   }
@@ -773,6 +830,22 @@ function userplus_admin_settings() {
     '#description' => t('When adding new users with userplus, only these roles should be available.  Administrators may always add additional roles to users at a later time.'),
   );
 
+  if (module_exists('userplus_domain')) {
+    $domains = domain_domains();
+    foreach ($domains as $domain) {
+      $domain_options[$domain['domain_id']] = $domain['sitename'];
+    }
+
+    $form['add-multiple-users']['userplus_add_multiple_domains'] = array(
+      '#type' => 'select',
+      '#title' => t('Select the domains that should appear on the form'),
+      '#default_value' => variable_get('userplus_add_multiple_domains', array()),
+      '#multiple' => TRUE,
+      '#options' => $domain_options,
+      '#description' => t('When adding new users with userplus, only these domains should be available.  Administrators may always add additional domains to users at a later time.'),
+    );
+  }
+
   if (module_exists('profile')) {
     $form['add-multiple-users']['userplus_show_required_profile_fields'] = array(
       '#type' => 'checkbox',
@@ -834,6 +907,32 @@ function userplus_admin_settings() {
     );
   }
 
+  if (module_exists('userplus_domain')) {
+    // "assign user domain" settings
+    $form['assign-user-domains'] = array(
+      '#type' => 'fieldset',
+      '#collapsible' => TRUE,
+      '#title' => t('"assign user domains" settings'),
+      '#description' => t('These settings affect the operation of the !page page.', array('!page' => l('assign user domains', 'admin/user/userplus/userdomains'))),
+    );
+    $form['assign-user-domains']['userplus_max_show_user_domains'] = array(
+      '#type' => 'textfield',
+      '#title' => t('Number of users to show per page'),
+      '#default_value' => variable_get('userplus_max_show_user_domains', '25'),
+      '#size' => 4,
+      '#maxlength' => 6,
+      '#description' => t('The number of users that will appear per page.'),
+    );
+    $form['assign-user-domains']['userplus_assign_domains'] = array(
+      '#type' => 'select',
+      '#title' => t('Select the domains that should appear on the form'),
+      '#default_value' => variable_get('userplus_assign_domains', array()),
+      '#multiple' => TRUE,
+      '#options' => $domain_options,
+      '#description' => t('When assigning roles with userplus, only these roles should be available.'),
+    );
+  }
+
   return system_settings_form($form);
 }
 
