alecpl
2009-08-29 ea18c594a525d28aa5156d13cac3e24f2c9267cf
program/include/rcube_ldap.php
@@ -413,7 +413,7 @@
    $newentry['objectClass'] = $this->prop['LDAP_Object_Classes'];
    foreach ($save_cols as $col => $val) {
      $fld = $this->_map_field($col);
      if ($fld != '') {
      if ($fld && $val) {
        // The field does exist, add it to the entry.
        $newentry[$fld] = $val;
      } // end if
@@ -457,7 +457,7 @@
    $deletedata = array();
    foreach ($save_cols as $col => $val) {
      $fld = $this->_map_field($col);
      if ($fld != '') {
      if ($fld) {
        // The field does exist compare it to the ldap record.
        if ($record[$col] != $val) {
          // Changed, but find out how.
@@ -480,31 +480,42 @@
      } // end if
    } // end foreach
    // Update the entry as required.
    $dn = base64_decode($id);
    // Update the entry as required.
    if (!empty($deletedata)) {
      // Delete the fields.
      $res = ldap_mod_del($this->conn, $dn, $deletedata);
      if ($res === FALSE) {
      if (!ldap_mod_del($this->conn, $dn, $deletedata))
        return false;
      } // end if
    } // end if
    if (!empty($replacedata)) {
      // Handle RDN change
      if ($replacedata[$this->prop['LDAP_rdn']]) {
        $newdn = $this->prop['LDAP_rdn'].'='.$replacedata[$this->prop['LDAP_rdn']].','.$this->prop['base_dn'];
        if ($dn != $newdn) {
          $newrdn = $this->prop['LDAP_rdn'].'='.$replacedata[$this->prop['LDAP_rdn']];
          unset($replacedata[$this->prop['LDAP_rdn']]);
        }
      }
      // Replace the fields.
      $res = ldap_mod_replace($this->conn, $dn, $replacedata);
      if ($res === FALSE) {
        return false;
      if (!empty($replacedata)) {
        if (!ldap_mod_replace($this->conn, $dn, $replacedata))
          return false;
      } // end if
    } // end if
    if (!empty($newdata)) {
      // Add the fields.
      $res = ldap_mod_add($this->conn, $dn, $newdata);
      if ($res === FALSE) {
      if (!ldap_mod_add($this->conn, $dn, $newdata))
        return false;
      } // end if
    } // end if
    // Handle RDN change
    if (!empty($newrdn)) {
      if (@ldap_rename($this->conn, $dn, $newrdn, NULL, TRUE))
        return base64_encode($newdn);
    }
    return true;
  }
@@ -559,6 +570,8 @@
   */
  function _ldap2result($rec)
  {
    global $RCMAIL;
    $out = array();
    
    if ($rec['dn'])
@@ -566,8 +579,12 @@
    
    foreach ($this->fieldmap as $rf => $lf)
    {
      if ($rec[$lf]['count'])
        $out[$rf] = $rec[$lf][0];
      if ($rec[$lf]['count']) {
        if ($rf == 'email' && !strpos($rec[$lf][0], '@'))
          $out[$rf] = sprintf('%s@%s', $rec[$lf][0] , $RCMAIL->config->mail_domain($_SESSION['imap_host']));
        else
          $out[$rf] = $rec[$lf][0];
      }
    }
    
    return $out;