? 486370-language-bug.patch
? 490846-admin.patch
? 490846-user-enable.patch
? domain_views/485762-views.patch
Index: domain.admin.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/domain/domain.admin.inc,v
retrieving revision 1.29
diff -u -p -r1.29 domain.admin.inc
--- domain.admin.inc	13 Jun 2009 20:02:39 -0000	1.29
+++ domain.admin.inc	14 Jun 2009 19:11:03 -0000
@@ -818,6 +818,50 @@ function domain_batch_form($form_state, 
 /**
  * FormsAPI
  */
+function theme_domain_admin_users_form($form) {
+  // Overview table:
+  $header = array(
+    theme('table_select_header_cell'),
+    array('data' => t('Username'), 'field' => 'u.name'),
+    array('data' => t('Status'), 'field' => 'u.status'),
+    t('Roles'),
+    t('Domains'),
+    array('data' => t('Member for'), 'field' => 'u.created', 'sort' => 'desc'),
+    array('data' => t('Last access'), 'field' => 'u.access'),
+    t('Operations')
+  );
+
+  $output = drupal_render($form['options']);
+  $output .= drupal_render($form['domain']);
+  if (isset($form['name']) && is_array($form['name'])) {
+    foreach (element_children($form['name']) as $key) {
+      $rows[] = array(
+        drupal_render($form['accounts'][$key]),
+        drupal_render($form['name'][$key]),
+        drupal_render($form['status'][$key]),
+        drupal_render($form['roles'][$key]),
+        drupal_render($form['user_domains'][$key]),
+        drupal_render($form['member_for'][$key]),
+        drupal_render($form['last_access'][$key]),
+        drupal_render($form['operations'][$key]),
+      );
+    }
+  }
+  else {
+    $rows[] = array(array('data' => t('No users available.'), 'colspan' => '7'));
+  }
+
+  $output .= theme('table', $header, $rows);
+  if ($form['pager']['#value']) {
+    $output .= drupal_render($form['pager']);
+  }
+
+  $output .= drupal_render($form);
+
+  return $output;}
+/**
+ * FormsAPI
+ */
 function theme_domain_batch_form($form) {
   $output = '';
   $output = drupal_render($form['message']);
Index: domain.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/domain/domain.module,v
retrieving revision 1.110
diff -u -p -r1.110 domain.module
--- domain.module	13 Jun 2009 20:02:39 -0000	1.110
+++ domain.module	14 Jun 2009 19:11:05 -0000
@@ -211,6 +211,10 @@ function domain_perm() {
  */
 function domain_theme() {
   $themes = array(
+    'domain_admin_users_form' => array(
+      'arguments' => array('form' => array()),
+      'file' => 'domain.admin.inc',
+    ),
     'domain_batch_form' => array(
       'arguments' => array('form' => array()),
       'file' => 'domain.admin.inc',
@@ -426,6 +430,112 @@ function domain_user($op, &$edit, &$acco
 }
 
 /**
+ * Implement hook_user_operations().
+ */
+function domain_user_operations() {
+  if (!user_access('assign domain editors')) {
+    return;
+  }
+  return array(
+    'domain' => array(
+      'label' => t('Assign users to domains'),
+      'callback' => 'domain_user_operation_assign',
+    ),
+  );
+}
+
+/**
+ * Implement hook_form_alter().
+ */
+function domain_form_user_admin_account_alter(&$form, $form_state) {
+  if (!user_access('assign domain editors')) {
+    return;
+  }
+  $options = array();
+  foreach (domain_domains() as $data) {
+    // Cannot pass zero in checkboxes.
+    ($data['domain_id'] == 0) ? $key = -1 : $key = $data['domain_id'];
+    // The domain must be valid.
+    if ($data['valid'] || user_access('administer domains')) {
+      $options[$key] = check_plain($data['sitename']);
+    }
+  }
+  $form['domain'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Affiliate editor options'),
+    '#collapsible' => TRUE,
+    '#collapsed' => TRUE,
+    '#prefix' => '<div class="description">'. t('If you select <em>Assign users to domains</em> above, you should confirm the <em>Affiliate editor options</em> settings below.') .'</div>',
+    '#weight' => -1,
+  );
+  $form['domain']['domains'] = array(
+    '#type' => 'checkboxes',
+    '#title' => t('Assign to'),
+    '#options' => $options,
+    '#required' => FALSE,
+    '#description' => t('Select which affiliates these users should belong to. <em>Note: this will erase any current assignment for the selsected users.</em>'),
+    '#default_value' => array(($_domain['domain_id'] == 0) ? -1 : $_domain['domain_id']), // Can't use 0 as a checkbox value.
+  );
+  // Add our domain elements.
+  foreach (array_keys($form['name']) as $uid) {
+    $form['user_domains'][$uid][0] = array('#value' => theme('item_list', _domain_user_list($uid)));
+  }
+  $form['#theme'] = 'domain_admin_users_form';
+  $form['#submit'][] = 'domain_update_users';
+}
+
+/**
+ * Helper function to get the names of all domains for a user.
+ *
+ * @param $uid
+ *   The user id.
+ * @return
+ * An array of domain names.
+ */
+function _domain_user_list($uid) {
+  $temp_account = new stdClass;
+  $temp_account->uid = $uid;
+  $list = domain_get_user_domains($temp_account, FALSE);
+  $domains = array();
+  foreach ($list as $domain_id) {
+    if ($domain_id == -1) {
+      $domain_id = 0;
+    }
+    $domains[] = check_plain(db_result(db_query("SELECT sitename FROM {domain} WHERE domain_id = %d ORDER BY domain_id ASC", $domain_id)));
+  }
+  return $domains;
+}
+
+/**
+ * Callback for domain_content_node_operations().
+ *
+ * This callback is required, but we actually do our action inside
+ * of domain_update_users().
+ */
+function domain_user_operation_assign($accounts) {
+}
+
+/**
+ * FormsAPI to handle the batch update of users.
+ */
+function domain_update_users($form, &$form_state) {
+  $values = $form_state['values'];
+  if ($values['operation'] != 'domain') {
+    return;
+  }
+  foreach ($values['accounts'] as $uid) {
+    db_query("DELETE FROM {domain_editor} WHERE uid = %d", $uid);
+    foreach (array_filter($values['domains']) as $domain_id) {
+      // Cannot use 0 as a checkbox.
+      if ($domain_id == -1) {
+        $domain_id = 0;
+      }
+      db_query("INSERT INTO {domain_editor} (uid, domain_id) VALUES (%d, %d)", $uid, $domain_id);
+    }
+  }
+}
+
+ /**
  * Implement hook_cron()
  *
  * This function invokes hook_domaincron() and allows
