function domain_update_users in Domain Access 6.2
Same name and namespace in other branches
- 7.3 domain.module \domain_update_users()
- 7.2 domain.module \domain_update_users()
FormsAPI to handle the batch update of users.
1 string reference to 'domain_update_users'
- domain_form_user_admin_account_alter in ./
domain.module - Implement hook_form_alter().
File
- ./
domain.module, line 697 - Core module functions for the Domain Access suite.
Code
function domain_update_users($form, &$form_state) {
$values = $form_state['values'];
if ($values['operation'] != 'domain') {
return;
}
// Get the domains for this user, but ignore roles unless told to use them.
$add_roles = variable_get('domain_add_roles', 0);
// Loop through the selected accounts.
$domains = array_filter($values['domains']);
foreach ($values['accounts'] as $uid) {
// If appending values, do so here.
if (!empty($form_state['values']['behavior'])) {
$account = new stdClass();
$account->uid = $uid;
$current = domain_get_user_domains($account, $add_roles, TRUE);
// Behavior 1: add new domains.
if ($form_state['values']['behavior'] == 1) {
$domains += $current;
}
else {
foreach ($domains as $domain_id) {
if (isset($current[$domain_id])) {
unset($current[$domain_id]);
}
}
$domains = $current;
}
}
db_query("DELETE FROM {domain_editor} WHERE uid = %d", $uid);
foreach ($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);
}
}
}