You are here

function ldaphelp_users_list in LDAP integration 6

Generate a list of all Drupal users marked as ldap_authentified.

Parameters

string $verify If not null, verify that the LDAP info matches the: Drupal account info.

1 string reference to 'ldaphelp_users_list'
ldaphelp_menu in ldaphelp/ldaphelp.module
Implementation of hook_menu().

File

ldaphelp/ldaphelp.module, line 420
The ldaphelp module is a module to help admins debug ldap_integration modules.

Code

function ldaphelp_users_list($verify = NULL) {
  $header = array(
    "User Name",
    'LDAP Server',
    'LDAP DN',
    'PUID Status',
  );
  $verify = isset($verify);
  if ($verify) {
    $header[] = "Verified";
  }
  $rows = array();
  $result = db_query("SELECT uid, name, data FROM {users} WHERE status = %d ORDER BY name ASC", 1);
  while ($row = db_fetch_array($result)) {
    $data = unserialize($row['data']);
    if ($data['ldap_authentified']) {
      $name = l($row['name'], "user/{$row['uid']}");
      $dn = $data['ldap_dn'];
      $server = ldapauth_server_load($data['ldap_config']);
      $using_puid = false;
      if (!empty($server)) {
        $sid = $server->machine_name;
        $puid = NULL;
        $using_puid = !empty($server->puid_attr);
        $puid_status = t('Not Used');
        if ($using_puid) {
          $user_info = ldapauth_userinfo_load_by_uid($row['uid']);
          if (!empty($user_info) && isset($user_info->puid)) {
            $puid_status = t('Set');
            $puid = $user_info->puid;
          }
          else {
            $puid_status = t("Not set");
          }
        }
        if ($verify) {
          $verified = ldaphelp_ldap_user_verify($data['ldap_config'], $data['ldap_dn'], $puid);
        }
      }
      else {
        $sid = t("Invalid Server Id");
        $puid_status = t('No server');
        $verified = t("No server");
      }
      $row = array(
        $name,
        $sid,
        $dn,
        $puid_status,
      );
      if ($verify) {
        $row[] = $verified;
      }
      $rows[] = $row;
    }
  }
  $output = "<p>" . t('This is a list of local Drupal users who have been marked as "LDAP Authenticated". The server and dn info are from the Drupal user data.') . "</p><p>" . t('The PUID status indicates if the user (and server) is using the Persistent Unique ID (PUID) and if it is set or not.') . "</p><p>" . t('Note that since the local data may be out of sync with the LDAP server, the verified option can be selected to verify that the local user data matchs the LDAP information.  If a user is not found, this indicates that the user has either been deleted from LDAP or their lDAP user entry was moved since their last login.') . "</p>";
  $output .= theme_table($header, $rows);
  return $output;
}