You are here

function _ldapdata_user_view in LDAP integration 6

Implements hook_user() view operation.

1 call to _ldapdata_user_view()
ldapdata_user in ./ldapdata.module
Implements hook_user().

File

./ldapdata.module, line 497
ldapdata provides data maping against ldap server.

Code

function _ldapdata_user_view(&$user) {
  global $_ldapdata_ldap;

  // Only care about ldap authenticated users.
  if (!isset($user->ldap_authentified)) {
    return;
  }
  $ldapdata_attrs = _ldapdata_ldap_info($user, 'ldapdata_attrs');
  if (empty($ldapdata_attrs)) {

    // No LDAP attributes defined, we're done.
    return;
  }

  // Setup the global $_ldapdata_ldap object.
  if (!_ldapdata_init($user)) {
    return;
  }
  $bind_info = _ldapdata_edition($user);
  if (!$_ldapdata_ldap
    ->connect($bind_info['dn'], $bind_info['pass'])) {
    watchdog('ldapdata', "User view: user %name's data could not be read in the LDAP directory", array(
      '%name' => $user->name,
    ), WATCHDOG_WARNING);
    return;
  }
  $entry = ldapauth_user_lookup_by_dn($_ldapdata_ldap, $user->ldap_dn, LDAPAUTH_SYNC_CONTEXT_UPDATE_DRUPAL_USER);
  $allowed_attrs = _ldapdata_ldap_info($user, 'ldapdata_roattrs');
  $items = array();
  $i = 0;
  foreach ($ldapdata_attrs as $attr_name => $attr_info) {
    if (in_array($attr_name, $allowed_attrs)) {
      $item = array(
        '#type' => 'user_profile_item',
        '#title' => t($attr_info[2]),
        '#value' => theme('ldapdata_ldap_attribute', $entry[drupal_strtolower($attr_name)][0], $attr_info[0]),
        '#weight' => $i++,
      );
      $items[$attr_name] = $item;
    }
  }
  if (!empty($items)) {
    $user->content[t('LDAP attributes')] = array_merge(array(
      '#type' => 'user_profile_category',
      '#title' => t('LDAP attributes'),
      '#attributes' => array(
        'class' => 'ldapdata-entry',
      ),
      '#weight' => LDAPDATA_PROFILE_WEIGHT,
    ), $items);
  }
}