function simple_ldap_user_form_user_admin_account_alter in Simple LDAP 7.2
Same name and namespace in other branches
- 7 simple_ldap_user/simple_ldap_user.module \simple_ldap_user_form_user_admin_account_alter()
Implements hook_form_FORM_ID_alter().
Overrides the built-in user module's list of users, setting accounts to "blocked" if there is no matching LDAP account.
File
- simple_ldap_user/
simple_ldap_user.module, line 64 - Main simple_ldap_user module file.
Code
function simple_ldap_user_form_user_admin_account_alter(&$form, &$form_state, $form_id) {
// Update the user array.
foreach ($form['accounts']['#options'] as $uid => $user) {
// Don't mess with user/1.
if ($uid == 1) {
continue;
}
// Verify active users. Blocked users may be provisioned to LDAP when they
// are set to active, so they are left alone here.
if ($user['status'] == 'active') {
// Load the user objects.
$drupal_user = user_load($uid);
$ldap_user = SimpleLdapUser::singleton($drupal_user->name);
// Check whether the user exists in LDAP.
if (!$ldap_user->exists) {
$form['accounts']['#options'][$uid]['status'] = 'blocked';
}
// Check whether the user is disabled (Active Directory only).
// http://support.microsoft.com/kb/305144
if ($ldap_user->server->type == 'Active Directory') {
if (isset($ldap_user->useraccountcontrol[0]) && (int) $ldap_user->useraccountcontrol[0] & 2) {
$form['accounts']['#options'][$uid]['status'] = 'blocked';
}
}
}
}
}