You are here

function _ldapdata_user_submit in LDAP integration 6

Implements hook_user() submit operation.

2 calls to _ldapdata_user_submit()
ldapdata_avatarcrop_submit in ./ldapdata.module
Handle updating ldap when avatarcrop updates picture.
ldapdata_user in ./ldapdata.module
Implements hook_user().

File

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

Code

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

  // Only care about ldap authenticated users.
  if (!isset($user->ldap_authentified)) {
    return;
  }

  // Setup the global $_ldapdata_ldap object.
  if (!_ldapdata_init($user)) {
    return;
  }

  // Three cases here:
  //   1. User logged on and editing his LDAP entry attributes ($category == LDAPDATA_USER_DATA).
  //   2. User logged on and editing his Drupal account settings ($category == 'account').
  //   3. OBSOLETE FROM 4.7: Password lost and being updated (category == 'account').
  // Additionally:
  //   4. User logged on and editing his profile.module fields ($category == *any*).
  $writeout = array();
  $editables = _ldapdata_ldap_info($user, 'ldapdata_rwattrs');
  if ($category == LDAPDATA_USER_DATA && $editables) {

    // Case 1:
    $writeout = array_merge($writeout, _ldapdata_user_update_ldap_attributes($edit, $user));
  }
  elseif ($category == 'account') {

    // Cases 2 && 3:
    $writeout = array_merge($writeout, _ldapdata_user_update_drupal_account($edit, $user));
  }

  // And now, case 4:
  $writeout = array_merge($writeout, _ldapdata_user_update_profile($edit, $user));
  if ($writeout) {
    $bind_info = _ldapdata_edition($user);
    if (!$_ldapdata_ldap
      ->connect($bind_info['dn'], $bind_info['pass'])) {
      watchdog('ldapdata', "User update: user %name's data could not be updated in the LDAP directory", array(
        '%name' => $user->name,
      ), WATCHDOG_NOTICE);
      return;
    }
    if (!$_ldapdata_ldap
      ->writeAttributes($user->ldap_dn, $writeout)) {
      drupal_set_message(t('The data was not written to LDAP.'), 'error');
    }
  }
  $_ldapdata_ldap
    ->disconnect();
}