You are here

function cas_ldap_list in CAS Attributes 7

Same name and namespace in other branches
  1. 6.3 cas_ldap.admin.inc \cas_ldap_list()

Lists available CAS Attributes.

1 string reference to 'cas_ldap_list'
cas_ldap_menu in ./cas_ldap.module
Implements hook_menu().

File

./cas_ldap.admin.inc, line 11
Provides settings pages for the CAS LDAP module.

Code

function cas_ldap_list() {
  $cas_attr_ldap_server = variable_get('cas_attributes_ldap_server', NULL);
  if (empty($cas_attr_ldap_server)) {

    // No CAS server configured.
    return t('An <a href="@url">LDAP server</a> must be selected.', array(
      '@url' => url('admin/config/people/cas/attributes'),
    ));
  }
  $ldap_server = ldap_servers_get_servers($cas_attr_ldap_server, 'enabled', TRUE);
  if (empty($ldap_server->testingDrupalUsername)) {
    return t('Please configure the LDAP server\'s <a href="@url">testing Drupal username</a>.', array(
      '@url' => url('admin/config/people/ldap/servers/edit/' . $ldap_server->sid),
    ));
  }
  $header = array(
    'Token',
    'Value',
  );
  $rows = array();
  $attributes = cas_ldap_attributes($ldap_server->testingDrupalUsername);
  foreach ($attributes as $attribute => $value) {
    if (is_numeric($attribute)) {
      continue;
    }
    if (is_array($value)) {
      $value = $value[0];
    }
    $rows[] = array(
      t('[cas:ldap:@attribute]', array(
        '@attribute' => drupal_strtolower($attribute),
      )),
      check_plain($value),
    );
  }
  if (empty($rows)) {
    $rows[] = array(
      'data' => array(
        array(
          'data' => t('No LDAP attributes were returned by the LDAP server. Please ensure the <a href="@url">LDAP server</a> is configured correctly.', array(
            '@url' => url('admin/config/people/ldap/servers/edit/' . $ldap_server->sid),
          )),
          'colspan' => 2,
        ),
      ),
    );
  }
  return theme('table', array(
    'header' => $header,
    'rows' => $rows,
  ));
}