You are here

function _ldapdata_user_update_drupal_account in LDAP integration 6

Find out which Drupal attributes should be synced back to LDAP..

Parameters

$edit: A submitted form data.

$user: A user object.

Return value

An associated array of attributes to write to LDAP.

1 call to _ldapdata_user_update_drupal_account()
_ldapdata_user_submit in ./ldapdata.module
Implements hook_user() submit operation.

File

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

Code

function _ldapdata_user_update_drupal_account(&$edit, &$user) {
  global $_ldapdata_ldap;
  $writeout = array();
  if (isset($user->ldap_dn) && _ldapdata_ldap_info($user, 'mapping_type') == LDAPDATA_MAP_ATTRIBUTES) {

    // Case 2: updating account data.
    $d2l_map = _ldapdata_reverse_mappings($user->ldap_config);
    foreach ($edit as $key => $value) {
      if ($ldap_attr = isset($d2l_map[$key]) ? $d2l_map[$key] : NULL) {
        if ($key == 'pass') {
          if ($value) {
            $writeout[$ldap_attr] = encode_password($value);
          }
        }
        elseif ($key == 'mail') {
          if (LDAPAUTH_ALTER_EMAIL_FIELD != LDAPAUTH_EMAIL_FIELD_REMOVE) {
            $writeout[$ldap_attr] = $value;
          }
        }
        elseif ($key == 'picture') {
          if ($value) {
            if ($fhandle = fopen($value, 'r')) {
              $writeout[$ldap_attr] = fread($fhandle, filesize($value));
            }
            else {
              watchdog('ldapdata', "Could not open user picture file for reading.  File=%file", array(
                '%file' => $value,
              ), WATCHDOG_WARNING);
            }
          }
          else {
            $writeout[$ldap_attr] = '';
          }
        }
        else {
          $writeout[$ldap_attr] = $value;
        }
      }
    }
  }
  return $writeout;
}