/**
* Update the entry on the directory server
*
* This will evaluate all changes made so far and send them
* to the directory server.
* Please note, that if you make changes to objectclasses wich
* have mandatory attributes set, update() will currently fail.
* Remove the entry from the server and readd it as new in such cases.
* This also will deal with problems with setting structural object classes.
*
* @param Net_LDAP2 $ldap If passed, a call to setLDAP() is issued prior update, thus switching the LDAP-server. This is for perl-ldap interface compliance
*
* @access public
* @return true|Net_LDAP2_Error
* @todo Entry rename with a DN containing special characters needs testing!
*/
public function update($ldap = null)
{
if ($ldap) {
$msg = $this->setLDAP($ldap);
if (Net_LDAP2::isError($msg)) {
return PEAR::raiseError('You passed an invalid $ldap variable to update()');
}
}
// ensure we have a valid LDAP object
$ldap =& $this->getLDAP();
if (!$ldap instanceof Net_LDAP2) {
return PEAR::raiseError("The entries LDAP object is not valid");
}
// Get and check link
$link = $ldap->getLink();
if (!is_resource($link)) {
return PEAR::raiseError("Could not update entry: internal LDAP link is invalid");
}
/*
* Delete the entry
*/
if (true === $this->_delete) {
return $ldap->delete($this);
}
/*
* New entry
*/
if (true === $this->_new) {
$msg = $ldap->add($this);
if (Net_LDAP2::isError($msg)) {
return $msg;
}
$this->_new = false;
$this->_changes['add'] = array();
$this->_changes['delete'] = array();
$this->_changes['replace'] = array();
$this->_original = $this->_attributes;
$return = true;
return $return;
}
/*
* Rename/move entry
*/
if (false == is_null($this->_newdn)) {
if ($ldap->getLDAPVersion() !== 3) {
return PEAR::raiseError("Renaming/Moving an entry is only supported in LDAPv3");
}
// make dn relative to parent (needed for ldap rename)
$parent = Net_LDAP2_Util::ldap_explode_dn($this->_newdn, array('casefolding' => 'none', 'reverse' => false, 'onlyvalues' => false));
if (Net_LDAP2::isError($parent)) {
return $parent;
}
$child = array_shift($parent);
// maybe the dn consist of a multivalued RDN, we must build the dn in this case
// because the $child-RDN is an array!
if (is_array($child)) {
$child = Net_LDAP2_Util::canonical_dn($child);
}
$parent = Net_LDAP2_Util::canonical_dn($parent);
// rename/move
if (false == @ldap_rename($link, $this->_dn, $child, $parent, true)) {
return PEAR::raiseError("Entry not renamed: " . @ldap_error($link), @ldap_errno($link));
}
// reflect changes to local copy
$this->_dn = $this->_newdn;
$this->_newdn = null;
}
/*
* Carry out modifications to the entry
*/
// ADD
foreach ($this->_changes["add"] as $attr => $value) {
// if attribute exists, add new values
if ($this->exists($attr)) {
if (false === @ldap_mod_add($link, $this->dn(), array($attr => $value))) {
return PEAR::raiseError("Could not add new values to attribute {$attr}: " . @ldap_error($link), @ldap_errno($link));
}
} else {
// new attribute
if (false === @ldap_modify($link, $this->dn(), array($attr => $value))) {
return PEAR::raiseError("Could not add new attribute {$attr}: " . @ldap_error($link), @ldap_errno($link));
}
}
// all went well here, I guess
//.........这里部分代码省略.........
/**
* Updates the entry on the directory server.
*
* This will evaluate all changes made so far and send them to the
* directory server.
*
* If you make changes to objectclasses wich have mandatory attributes set,
* update() will currently fail. Remove the entry from the server and readd
* it as new in such cases. This also will deal with problems with setting
* structural object classes.
*
* @todo Entry rename with a DN containing special characters needs testing!
*
* @throws Horde_Ldap_Exception
*/
public function update()
{
/* Ensure we have a valid LDAP object. */
$ldap = $this->getLDAP();
/* Get and check link. */
$link = $ldap->getLink();
if (!is_resource($link)) {
throw new Horde_Ldap_Exception('Could not update entry: internal LDAP link is invalid');
}
/* Delete the entry. */
if ($this->_delete) {
return $ldap->delete($this);
}
/* New entry. */
if ($this->_new) {
$ldap->add($this);
$this->_new = false;
$this->_changes['add'] = array();
$this->_changes['delete'] = array();
$this->_changes['replace'] = array();
$this->_original = $this->_attributes;
return;
}
/* Rename/move entry. */
if (!is_null($this->_newdn)) {
if ($ldap->getVersion() != 3) {
throw new Horde_Ldap_Exception('Renaming/Moving an entry is only supported in LDAPv3');
}
/* Make DN relative to parent (needed for LDAP rename). */
$parent = Horde_Ldap_Util::explodeDN($this->_newdn, array('casefolding' => 'none', 'reverse' => false, 'onlyvalues' => false));
$child = array_shift($parent);
/* Maybe the DN consist of a multivalued RDN, we must build the DN
* in this case because the $child RDN is an array. */
if (is_array($child)) {
$child = Horde_Ldap_Util::canonicalDN($child);
}
$parent = Horde_Ldap_Util::canonicalDN($parent);
/* Rename/move. */
if (!@ldap_rename($link, $this->_dn, $child, $parent, true)) {
throw new Horde_Ldap_Exception('Entry not renamed: ' . @ldap_error($link), @ldap_errno($link));
}
/* Reflect changes to local copy. */
$this->_dn = $this->_newdn;
$this->_newdn = null;
}
/* Carry out modifications to the entry. */
foreach ($this->_changes['add'] as $attr => $value) {
/* If attribute exists, add new values. */
if ($this->exists($attr)) {
if (!@ldap_mod_add($link, $this->dn(), array($attr => $value))) {
throw new Horde_Ldap_Exception('Could not add new values to attribute ' . $attr . ': ' . @ldap_error($link), @ldap_errno($link));
}
} else {
/* New attribute. */
if (!@ldap_modify($link, $this->dn(), array($attr => $value))) {
throw new Horde_Ldap_Exception('Could not add new attribute ' . $attr . ': ' . @ldap_error($link), @ldap_errno($link));
}
}
unset($this->_changes['add'][$attr]);
}
foreach ($this->_changes['delete'] as $attr => $value) {
/* In LDAPv3 you need to specify the old values for deleting. */
if (is_null($value) && $ldap->getVersion() == 3) {
$value = $this->_original[$attr];
}
if (!@ldap_mod_del($link, $this->dn(), array($attr => $value))) {
throw new Horde_Ldap_Exception('Could not delete attribute ' . $attr . ': ' . @ldap_error($link), @ldap_errno($link));
}
unset($this->_changes['delete'][$attr]);
}
foreach ($this->_changes['replace'] as $attr => $value) {
if (!@ldap_modify($link, $this->dn(), array($attr => $value))) {
throw new Horde_Ldap_Exception('Could not replace attribute ' . $attr . ' values: ' . @ldap_error($link), @ldap_errno($link));
}
unset($this->_changes['replace'][$attr]);
}
/* All went well, so $_attributes (local copy) becomes $_original
* (server). */
$this->_original = $this->_attributes;
}
开发者ID:raz0rsdge,项目名称:horde,代码行数:95,代码来源:Entry.php
示例5: syncGroup
//.........这里部分代码省略.........
} else {
if (!is_array($value) && $value != '') {
$entry[$key] = $value;
}
}
}
$result = ldap_add($conn, $dn, $entry);
if ($result !== true) {
$result = ldap_add($conn, $dn, $entry);
self::$errors['warning'][] = ldap_error($conn);
return false;
} else {
++self::$success['added'];
return true;
}
}
$ldapinfo = null;
$count = $entry ? ldap_count_entries($conn, $entry) : 0;
if ($count > 0) {
$firstentry = ldap_first_entry($conn, $entry);
$attr = ldap_get_attributes($conn, $firstentry);
if (!empty($attr) && $attr['count'] > 0) {
foreach ($reqattr as $key) {
unset($attr[$key]['count']);
if (isset($attr[$key][0])) {
if (count($attr[$key]) <= 1) {
$ldapinfo[$key] = $attr[$key][0];
} else {
$ldapinfo[$key] = $attr[$key];
}
} else {
$ldapinfo[$key] = null;
}
}
}
}
// If there was no database entry, and there was no ldap entry, nothing to do
if (empty($dbinfo) && empty($ldapinfo)) {
return true;
}
// If there was no database entry, but there was an ldap entry, delete the ldap entry
if (!empty($ldapinfo) && empty($dbinfo)) {
$dn = "cn=" . $ldapinfo['cn'] . ",ou=groups," . $hubLDAPBaseDN;
$result = ldap_delete($conn, $dn);
if ($result !== true) {
self::$errors['warning'][] = ldap_error($conn);
return false;
} else {
++self::$success['deleted'];
return true;
}
}
// Otherwise update the ldap entry
$entry = array();
if (!empty($ldapinfo['memberUid']) && !is_array($ldapinfo['memberUid'])) {
$ldapinfo['memberUid'] = array($ldapinfo['memberUid']);
}
foreach ($dbinfo as $key => $value) {
if ($ldapinfo[$key] != $dbinfo[$key]) {
if ($dbinfo[$key] === null) {
$entry[$key] = array();
} else {
$entry[$key] = $dbinfo[$key];
}
}
}
if (empty($entry)) {
++self::$success['unchanged'];
return true;
}
$dn = "cn=" . $ldapinfo['cn'] . ",ou=groups," . $hubLDAPBaseDN;
// See if we're changing cn...if so, we need to do a rename
if (array_key_exists('cn', $entry)) {
$result = ldap_rename($conn, $dn, 'cn=' . $entry['cn'], 'ou=groups,' . $hubLDAPBaseDN, true);
// Set aside new uid and unset from attributes needing to be changed
$newCn = $entry['cn'];
unset($entry['cn']);
// See if we have any items left
if (empty($entry)) {
if ($result !== true) {
self::$errors['warning'][] = ldap_error($conn);
return false;
} else {
++self::$success['modified'];
return true;
}
}
// Build new dn
$dn = "cn=" . $newCn . ",ou=groups," . $hubLDAPBaseDN;
}
// Now do the modify
$result = ldap_modify($conn, $dn, $entry);
if ($result !== true) {
self::$errors['warning'][] = ldap_error($conn);
return false;
} else {
++self::$success['modified'];
return true;
}
}
/**
* Modify the name of an entry
*
* The entry specified by $dn is renamed/moved. The new RDN is specified by $newrdn and the
* parent/superior entry is specified by $newparent. If the parameter $deleteoldrdn is TRUE
* the old RDN value(s) is removed, else the old RDN value(s) is retained as non-distinguished
* values of the entry.
*
* @link http://www.php.net/ldap_rename
* @param string $dn The entry to be renamed/moved
* @param string $newrdn The new RDN
* @param string $newparent The DN of the new parent
* @param boolean $deleteoldrdn Do we delete the old RDN?
* @return boolean Success
*/
function rename($dn, $newrdn, $newparent, $deleteoldrdn)
{
if ($this->version != 3) {
$this->ldapErrno = -1;
$this->ldapError = "ldap_rename requires version 3 of the LDAP protocol";
return false;
}
if (@ldap_rename($this->connection, $dn, $newrdn, $newparent, $deleteoldrdn)) {
return true;
}
$this->setErrVars();
return false;
}
开发者ID:ruNovel,项目名称:sams2,代码行数:28,代码来源:ldap.php
示例7: rename
/**
* Rename the entry
*
* @param string $dn The DN of the entry at the moment
* @param string $newdn The DN of the entry should be (only cn=newvalue)
* @param string $newparent The full DN of the parent (null by default)
* @param boolean $deleteolddn Delete the old values (default)
*
* @return boolean Result of operation
*
* @since 12.1
*/
public function rename($dn, $newdn, $newparent, $deleteolddn)
{
return @ldap_rename($this->_resource, $dn, $newdn, $newparent, $deleteolddn);
}
/**
* Renames a LDAP entity.
*
* @throws \gossi\ldap\LdapException If the rename fails.
* @param String $dn The distinguished name of a LDAP entity.
* @param String $newrdn The new RDN.
* @param String $newparent The new parent/superior entry.
* @param boolean $deleteoldrdn If true the old RDN value(s) is removed, else the old RDN value(s) is retained as non-distinguished values of the entry.
* @return boolean Returns true on success or false on failure.
*/
public function rename($dn, $newrdn, $newparent, $deleteoldrdn)
{
$success = ldap_rename($this->conn, $dn, $newrdn, $newparent, $deleteoldrdn);
if (ldap_errno($this->conn)) {
throw new LdapException(ldap_error($this->conn), ldap_errno($this->conn));
}
return $success;
}
/**
* Save an extension to the LDAP tree
*
* @param string $account Account to which the user should be added
*
* @param string $extension Extension to be saved
*
* @param array $details Phone numbers, PIN, options, etc to be saved
*
* @return TRUE on success, PEAR::Error object on error
* @throws Shout_Exception
*/
public function saveExtension($account, $extension, $details)
{
// Check permissions
parent::saveExtension($account, $extension, $details);
// FIXME: Fix and uncomment the below
// // Check to ensure the extension is unique within this account
// $filter = "(&(objectClass=AstVoicemailMailbox)(context=$account))";
// $reqattrs = array('dn', $ldapKey);
// $res = @ldap_search($this->_LDAP, $this->_params['basedn'],
// $filter, $reqattrs);
// if ($res === false) {
// $msg = sprintf('LDAP Error (%s): %s', ldap_errno($this->_LDAP),
// ldap_error($this->_LDAP));
// Horde::log($msg, 'ERR');
// throw new Shout_Exception(_("Error while searching the directory. Details have been logged for the administrator."));
// }
// if (($res['count'] != 1) ||
// ($res['count'] != 0 &&
// !in_array($res[0][$ldapKey], $details[$appKey]))) {
// throw new Shout_Exception(_("Duplicate extension found. Not saving changes."));
// }
// FIXME: Quote these strings
$uid = $extension . '@' . $account;
$entry = array('objectClass' => array('top', 'account', 'AsteriskVoicemail', 'AsteriskUser'), 'uid' => $uid, 'cn' => $details['name'], 'AstVoicemailEmail' => $details['email'], 'AstVoicemailMailbox' => $extension, 'AstVoicemailPassword' => $details['mailboxpin'], 'AstContext' => $account);
$rdn = 'uid=' . $uid;
$dn = $rdn . ',' . $this->_params['basedn'];
if (!empty($details['oldextension'])) {
// This is a change to an existing extension
// First, identify the DN to modify
// FIXME: Quote these strings
$olddn = $this->_getExtensionDn($account, $extension);
// If the extension has changed we need to perform an object rename
if ($extension != $details['oldextension']) {
$res = ldap_rename($this->_LDAP, $olddn, $rdn, $this->_params['basedn'], true);
if ($res === false) {
$msg = sprintf('LDAP Error (%s): %s', ldap_errno($this->_LDAP), ldap_error($this->_LDAP));
Horde::log($msg, 'ERR');
throw new Shout_Exception(_("Error while modifying the directory. Details have been logged for the administrator."));
}
}
// Now apply the changes
// Avoid changing the objectClass, just in case
unset($entry['objectClass']);
$res = ldap_modify($this->_LDAP, $dn, $entry);
if ($res === false) {
$msg = sprintf('LDAP Error (%s): %s', ldap_errno($this->_LDAP), ldap_error($this->_LDAP));
Horde::log($msg, 'ERR');
throw new Shout_Exception(_("Error while modifying the directory. Details have been logged for the administrator."));
}
return true;
} else {
// This is an add of a new extension
$res = ldap_add($this->_LDAP, $dn, $entry);
if ($res === false) {
$msg = sprintf('LDAP Error (%s): %s', ldap_errno($this->_LDAP), ldap_error($this->_LDAP));
Horde::log($msg, 'ERR');
throw new Shout_Exception(_("Error while modifying the directory. Details have been logged for the administrator."));
}
return true;
}
// Catch-all. We should not get here.
throw new Shout_Exception(_("Unspecified error."));
}
开发者ID:jubinpatel,项目名称:horde,代码行数:75,代码来源:Ldap.php
示例12: save
//.........这里部分代码省略.........
I2CE::raiseError("Trying to save a child node in LDAP where parent is not in LDAP");
return false;
}
$parentFormObj->populate();
if (!($base_dn = $parentFormObj->getAttribute('ldap_dn'))) {
I2CE::raiseError("No DN for parent");
return false;
}
}
if (!$base_dn) {
I2CE::raiseError("No base dn is set");
return false;
}
$dn = vsprintf($printf, $printf_vals) . ',' . $base_dn;
$attributes = array();
if (!$options->setIfIsSet($attributes, "save/attributes", true) || !is_array($attributes) || count($attributes) == 0) {
I2CE::raiseError("No attributes set under " . $options->getPath(false) . '/save/attributes');
return false;
}
$details = array();
foreach ($attributes as $attribute => $attribute_def) {
$val = false;
if (is_string($attribute_def)) {
if (($fieldObj = $formObj->getField($attribute_def)) instanceof I2CE_FormField) {
$val = $fieldObj->getDBValue();
}
} else {
if (!is_array($attribute_def)) {
continue;
} else {
if (array_key_exists('eval', $attribute_def) && is_string($attribute_def['eval'] = $attribute_def['eval']) && strlen($attribute_def['eval']) > 0) {
$data = array();
foreach ($formObj->getFieldNames() as $field) {
if (!($fieldObj = $formObj->getField($field)) instanceof I2CE_FormField) {
$data[$field] = null;
continue;
}
$data[$field] = $fieldObj->getDBValue();
}
@eval('$val = ' . $attribute_def['eval'] . ';');
} else {
if (array_key_exists('printf', $attribute_def) && is_string($printf = $attribute_def['printf']) && strlen($printf) > 0 && array_key_exists('printf_args', $attribute_def) && is_array($printf_args = $attribute_def['printf_args']) && count($printf_args) > 0) {
$printf_vals = array();
foreach ($printf_args as $arg => $field) {
if (($fieldObj = $formObj->getField($field)) instanceof I2CE_FormField) {
$dbval = $fieldObj->getDBValue();
} else {
$dbval = '';
}
$printf_vals[$arg] = $dbval;
}
$val = vsprintf($printf, $printf_vals);
}
}
}
}
if ($val === false || !is_scalar($val) || is_string($val) && strlen(trim($val)) == 0) {
continue;
}
$details[$attribute] = $val;
}
if ($id != '0') {
if ($old_dn != $dn) {
$new_basedn = ldap_explode_dn($dn, 0);
unset($new_basedn['count']);
$new_rdn = array_shift($new_basedn);
$new_basedn = implode(",", $new_basedn);
if (!@ldap_rename($connection, $old_dn, $new_rdn, $new_basedn, false)) {
I2CE::raiseError("Could not rename {$old_dn} to {$dn} with {$new_rdn} and {$new_basedn}");
return false;
}
}
if (!@ldap_modify($connection, $dn, $details)) {
I2CE::raiseError("Could not modify {$dn} with detail: " . print_r($details, true));
return false;
}
} else {
$details['objectClass'] = $objectClass;
if (!@ldap_add($connection, $dn, $details)) {
I2CE::raiseError("Could not add {$dn} with detail: " . print_r($details, true));
return false;
}
$r1 = @ldap_read($connection, $dn, 'objectClass=' . $objectClass, array($read_id));
if (!$r1) {
I2CE::raiseError("Could not read newly saved form under {$dn}");
return false;
}
if (!($entry = ldap_first_entry($connection, $r1))) {
I2CE::raiseError("no entry under {$dn} for reading id after save");
return false;
}
$result = $this->getEntryAttributes($connection, $entry, array('id' => $read_id), false);
if (!array_key_exists('id', $result) || !$result['id']) {
I2CE::raiseError("Could not read id attribute {$read_id} after save");
return false;
}
$formObj->setId($result['id']);
}
return true;
}
private function modify_entry_attributes($subject_dn, $attributes)
{
if (is_array($attributes['rename']) && !empty($attributes['rename'])) {
$olddn = $attributes['rename']['dn'];
$newrdn = $attributes['rename']['new_rdn'];
$new_parent = $attributes['rename']['new_parent'];
$this->_debug("C: Rename {$olddn} to {$newrdn},{$new_parent}");
// Note: for some reason the operation fails if RDN contains special characters
// and last argument of ldap_rename() is set to TRUE. That's why we use FALSE.
// However, we need to modify RDN attribute value later, otherwise it
// will contain an array of previous and current values
for ($i = 1; $i >= 0; $i--) {
$result = ldap_rename($this->conn, $olddn, $newrdn, $new_parent, $i == 1);
if ($result) {
break;
}
}
if ($result) {
$this->_debug("S: OK");
if ($new_parent) {
$subject_dn = $newrdn . ',' . $new_parent;
} else {
$old_parent_dn_components = ldap_explode_dn($olddn, 0);
unset($old_parent_dn_components["count"]);
$old_rdn = array_shift($old_parent_dn_components);
$old_parent_dn = implode(",", $old_parent_dn_components);
$subject_dn = $newrdn . ',' . $old_parent_dn;
}
// modify RDN attribute value, see note above
if (!$i && empty($attributes['replace'][$attr])) {
list($attr, $val) = explode('=', $newrdn, 2);
$attributes['replace'][$attr] = self::quote_string($val, true, true);
}
} else {
$this->_debug("S: " . ldap_error($this->conn));
$this->_warning("LDAP: Failed to rename {$olddn} to {$newrdn},{$new_parent}. " . ldap_error($this->conn));
return false;
}
}
if (is_array($attributes['replace']) && !empty($attributes['replace'])) {
$this->_debug("C: Mod-Replace {$subject_dn}: " . json_encode($attributes['replace']));
$result = ldap_mod_replace($this->conn, $subject_dn, $attributes['replace']);
if ($result) {
$this->_debug("S: OK");
} else {
$this->_debug("S: " . ldap_error($this->conn));
$this->_warning("LDAP: Failed to replace attributes on {$subject_dn}: " . json_encode($attributes['replace']));
return false;
}
}
if (is_array($attributes['del']) && !empty($attributes['del'])) {
$this->_debug("C: Mod-Delete {$subject_dn}: " . json_encode($attributes['del']));
$result = ldap_mod_del($this->conn, $subject_dn, $attributes['del']);
if ($result) {
$this->_debug("S: OK");
} else {
$this->_debug("S: " . ldap_error($this->conn));
$this->_warning("LDAP: Failed to delete attributes on {$subject_dn}: " . json_encode($attributes['del']));
return false;
}
}
if (is_array($attributes['add']) && !empty($attributes['add'])) {
$this->_debug("C: Mod-Add {$subject_dn}: " . json_encode($attributes['add']));
$result = ldap_mod_add($this->conn, $subject_dn, $attributes['add']);
if ($result) {
$this->_debug("S: OK");
} else {
$this->_debug("S: " . ldap_error($this->conn));
$this->_warning("LDAP: Failed to add attributes on {$subject_dn}: " . json_encode($attributes['add']));
return false;
}
}
return true;
}
开发者ID:cretzu89,项目名称:EPESI,代码行数:74,代码来源:LDAP3.php
示例16: move
/**
* Moves/renames current node/entry.
*
* If $newParent is given this entry/node is moved in LDAP tree to its new
* position.
*
* @example
*
* DN of entry: cn=John Doe,ou=people,dc=example,dc=com
* RDN of same entry: cn=John Doe
*
* @throws protocol_exception
* @param string $newRDN relative DN of current entry
* @param node $newParent node entry entry is subordinated to on moving, omit to rename locally
* @param boolean $keepPreviousRDN true to keep previous RDN as "normal" attribute
* @return node current instance
*/
public function move($newRDN, node $newParent = null, $keepPreviousRDN = true)
{
if ($this->isAdjusting()) {
throw new protocol_exception('must not move while adjusting entry', $this->link, $this->getDN());
}
if ($newParent) {
$superRDN = $newParent->getDN();
} else {
$superRDN = trim(preg_replace('/^[^,]+,/', '', $this->getDN()));
}
if (!@ldap_rename($this->link, $this->getDN(), $newRDN, $superRDN, !!$keepPreviousRDN)) {
throw new protocol_exception('failed to move entry', $this->link, $this->getDN());
}
return $this;
}
开发者ID:cepharum,项目名称:txf,代码行数:32,代码来源:node.php
示例17: update
/**
* Update a specific contact record
*
* @param mixed Record identifier
* @param array Hash array with save data
* @return boolean True on success, False on error
*/
function update($id, $save_cols)
{
$record = $this->get_record($id, true);
$result = $this->get_result();
$record = $result->first();
$newdata = array();
$replacedata = array();
$deletedata = array();
foreach ($save_cols as $col => $val) {
$fld = $this->_map_field($col);
if ($fld) {
// The field does exist compare it to the ldap record.
if ($record[$col] != $val) {
// Changed, but find out how.
if (!isset($record[$col])) {
// Field was not set prior, need to add it.
$newdata[$fld] = $val;
} elseif ($val == '') {
// Field supplied is empty, verify that it is not required.
if (!in_array($fld, $this->prop['required_fields'])) {
// It is not, safe to clear.
$deletedata[$fld] = $record[$col];
}
// end if
} else {
// The data was modified, save it out.
$replacedata[$fld] = $val;
}
// end else
}
// end if
}
// end if
}
// end foreach
$dn = base64_decode($id);
// Update the entry as required.
if (!empty($deletedata)) {
// Delete the fields.
$this->_debug("C: Delete [dn: {$dn}]: " . print_r($deletedata, true));
if (!ldap_mod_del($this->conn, $dn, $deletedata)) {
$this->_debug("S: " . ldap_error($this->conn));
return false;
}
$this->_debug("S: OK");
}
// end if
if (!empty($replacedata)) {
// Handle RDN change
if ($replacedata[$this->prop['LDAP_rdn']]) {
$newdn = $this->prop['LDAP_rdn'] . '=' . rcube_ldap::quote_string($replacedata[$this->prop['LDAP_rdn']], true) . ',' . $this->prop['base_dn'];
if ($dn != $newdn) {
$newrdn = $this->prop['LDAP_rdn'] . '=' . rcube_ldap::quote_string($replacedata[$this->prop['LDAP_rdn']], true);
unset($replacedata[$this->prop['LDAP_rdn']]);
}
}
// Replace the fields.
if (!empty($replacedata)) {
$this->_debug("C: Replace [dn: {$dn}]: " . print_r($replacedata, true));
if (!ldap_mod_replace($this->conn, $dn, $replacedata)) {
$this->_debug("S: " . ldap_error($this->conn));
return false;
}
$this->_debug("S: OK");
}
// end if
}
// end if
if (!empty($newdata)) {
// Add the fields.
$this->_debug("C: Add [dn: {$dn}]: " . print_r($newdata, true));
if (!ldap_mod_add($this->conn, $dn, $newdata)) {
$this->_debug("S: " . ldap_error($this->conn));
return false;
}
$this->_debug("S: OK");
}
// end if
// Handle RDN change
if (!empty($newrdn)) {
$this->_debug("C: Rename [dn: {$dn}] [dn: {$newrdn}]");
if (@ldap_rename($this->conn, $dn, $newrdn, NULL, TRUE)) {
$this->_debug("S: " . ldap_error($this->conn));
return base64_encode($newdn);
}
$this->_debug("S: OK");
}
return true;
}
请发表评论