You are here

function LDAPInterface::writeAttributes in LDAP integration 6

Same name and namespace in other branches
  1. 5.2 ldap_integration/LDAPInterface.php \LDAPInterface::writeAttributes()
  2. 5 ldap_integration/LDAPInterface.php \LDAPInterface::writeAttributes()

File

includes/LDAPInterface.inc, line 267
LDAPInterface class definition.

Class

LDAPInterface
@file LDAPInterface class definition.

Code

function writeAttributes($dn, $attributes) {
  foreach ($attributes as $key => $cur_val) {
    if ($cur_val == '') {
      unset($attributes[$key]);
      $old_value = $this
        ->retrieveAttribute($dn, $key);
      if (isset($old_value)) {
        ldap_mod_del($this->connection, $dn, array(
          $key => $old_value,
        ));
      }
    }

    //Encodes password for use in Active Directory // http://drupal.org/node/339821
    if ($key == "unicodePwd") {
      $cur_val = "\"" . $cur_val . "\"";
      $attributes[$key] = mb_convert_encoding($cur_val, "UTF-16LE");
    }
    if (is_array($cur_val)) {
      foreach ($cur_val as $mv_key => $mv_cur_val) {
        if ($mv_cur_val == '') {
          unset($attributes[$key][$mv_key]);
        }
        else {
          $attributes[$key][$mv_key] = $mv_cur_val;
        }
      }
    }
  }
  return ldap_modify($this->connection, $dn, $attributes);
}