You are here

function _ldapdata_user_form in LDAP integration 6

Implements hook_user() categories operation. Only used for editable LDAP attributes with no Drupal equivalents.

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

File

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

Code

function _ldapdata_user_form(&$user, $category) {
  global $_ldapdata_ldap;

  // Force LDAP sync.
  _ldapdata_user_load($user, TRUE);
  $attributes = _ldapdata_ldap_info($user, 'ldapdata_rwattrs');
  if (!isset($user->ldap_dn) || $category != LDAPDATA_USER_DATA || _ldapdata_ldap_info($user, 'mapping_type') != LDAPDATA_MAP_ATTRIBUTES || !$attributes) {
    return;
  }
  $bind_info = _ldapdata_edition($user);
  if (!$_ldapdata_ldap
    ->connect($bind_info['dn'], $bind_info['pass'])) {
    watchdog('ldapdata', "User form: 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);
  $form['ldap_attributes'] = array(
    '#title' => t('LDAP attributes'),
    '#type' => 'fieldset',
  );
  foreach (_ldapdata_ldap_info($user, 'ldapdata_attrs') as $attr_name => $attr_info) {
    if (in_array($attr_name, $attributes)) {
      array_shift($attr_info);
      $value = isset($entry[drupal_strtolower($attr_name)]) ? $entry[drupal_strtolower($attr_name)][0] : '';
      $form['ldap_attributes']['ldap_' . $attr_name] = _ldapdata_attribute_form($value, $attr_info);
    }
  }
  $_ldapdata_ldap
    ->disconnect();
  return $form;
}