function domain_user in Domain Access 6.2
Same name and namespace in other branches
- 5 domain.module \domain_user()
Implement hook_user()
Attached domain_id records to all registering users. These are used to determine which 'domain_editor' group that users with the 'edit domain nodes' and 'delete domain nodes' permissions are in.
5 string references to 'domain_user'
- domain_prefix_disallow in domain_prefix/
domain_prefix.admin.inc - Names of tables explicitly not allowed to be copied
- domain_user_configure_form in domain_user/
domain_user.admin.inc - FormsAPI for module settings
- domain_user_install in domain_user/
domain_user.install - Implement hook_install()
- domain_user_uninstall in domain_user/
domain_user.install - Implement hook_uninstall()
- domain_user_user in domain_user/
domain_user.module - Implement hook_user()
File
- ./
domain.module, line 466 - Core module functions for the Domain Access suite.
Code
function domain_user($op, &$edit, &$account, $category = NULL) {
switch ($op) {
case 'load':
$domains = domain_get_user_domains($account);
$account->domain_user = $domains;
break;
case 'form':
case 'register':
if (is_null($category) || $category == 'account') {
global $_domain;
$result = db_query("SELECT domain_id, subdomain, sitename, scheme FROM {domain}");
$options = array();
// Get the domains for this user, but ignore roles unless told to use them.
$add_roles = variable_get('domain_add_roles', 0);
// In the register case, we take the 'new user' settings.
if ($op == 'register') {
$add_roles = TRUE;
}
$account->domain_user = domain_get_user_domains($account, $add_roles, TRUE);
// By default, the requesting domain is assigned on registration.
if (empty($account->uid)) {
$_domain['domain_id'] == 0 ? $default = array(
-1,
) : ($default = array(
$_domain['domain_id'] => $_domain['domain_id'],
));
}
else {
$default = $account->domain_user;
}
$options[-1] = variable_get('domain_sitename', variable_get('site_name', 'Drupal'));
while ($data = db_fetch_array($result)) {
$options[$data['domain_id']] = check_plain($data['sitename']);
}
// Replace the zero record to -1.
unset($options[0]);
$format = domain_select_format();
if (user_access('assign domain editors')) {
$form['domain_user'] = array(
'#type' => 'fieldset',
'#title' => t('Domain access'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'#weight' => 1,
);
$form['domain_user']['domain_user'] = array(
'#type' => empty($format) ? 'checkboxes' : 'select',
'#options' => $options,
'#title' => t('Domain access settings'),
'#description' => t('Select the affiliates that this user belongs to. Used to grant editing permissions for users with the "edit domain nodes" permission.'),
'#default_value' => $default,
);
if ($format) {
$form['domain_user']['domain_user']['#multiple'] = TRUE;
$form['domain_user']['domain_user']['#size'] = count($options) > 10 ? 10 : count($options);
}
}
else {
$form['domain_user'] = array(
'#type' => 'value',
'#value' => $default,
);
}
return $form;
}
break;
case 'validate':
return array(
'domain_user' => $edit['domain_user'],
);
break;
case 'insert':
case 'update':
// If our field element is missing, do nothing.
if (!isset($edit['domain_user'])) {
return;
}
// Clear and reset the {domain_editor} table.
db_query("DELETE FROM {domain_editor} WHERE uid = %d", $account->uid);
if (empty($edit['domain_user'])) {
return;
}
foreach ($edit['domain_user'] as $domain_id => $status) {
if ($status != 0) {
// Convert the -1 checkboxes to a zero.
if ($domain_id == -1) {
$domain_id = 0;
}
db_query("INSERT INTO {domain_editor} (uid, domain_id) VALUES (%d, %d)", $account->uid, $domain_id);
}
}
// Clear the $edit field.
$edit['domain_user'] = NULL;
break;
case 'view':
if (user_access('assign domain editors')) {
$account->content['domain'] = array(
'#type' => 'user_profile_category',
'#weight' => 10,
'#title' => t('Domain status'),
);
if (empty($account->domain_user)) {
$output = t('This user is not assigned to a domain.');
}
else {
$output = '<ul>';
foreach ($account->domain_user as $id) {
if (abs($id) > 0) {
if ($id > 0) {
$domain = domain_lookup($id);
$output .= '<li>' . check_plain($domain['sitename']) . '</li>';
}
else {
$output .= '<li>' . check_plain(variable_get('domain_sitename', variable_get('site_name', 'Drupal'))) . '</li>';
}
}
}
$output .= '</ul>';
}
$account->content['domain']['domain_settings'] = array(
'#type' => 'user_profile_item',
'#title' => t('Domain settings'),
'#value' => $output,
);
}
break;
case 'delete':
db_query("DELETE FROM {domain_editor} WHERE uid = %d", $account->uid);
break;
}
}