isReadOnly())
error(_('You cannot perform updates while server is in read-only mode'),'error','index.php');
/***************/
/* get entry */
/***************/
$entry = array();
$entry['dn']['string'] = get_request('dn');
$entry['dn']['encode'] = rawurlencode($entry['dn']['string']);
if (! $entry['dn']['string'] || ! $ldapserver->dnExists($entry['dn']['string']))
error(sprintf(_('The entry (%s) does not exist.'),htmlspecialchars($entry['dn']['string'])),'error','index.php');
$tree = get_cached_item($ldapserver->server_id,'tree');
$entry['ldap'] = null;
if ($tree) {
$entry['ldap'] = $tree->getEntry($entry['dn']['string']);
if (! $entry['ldap'])
$tree->addEntry($entry['dn']['string']);
$entry['ldap'] = $tree->getEntry($entry['dn']['string']);
}
if (! $entry['ldap'] || $entry['ldap']->isReadOnly())
error(sprintf(_('The entry (%s) is in readonly mode.'),htmlspecialchars($entry['dn']['string'])),'error','index.php');
/***************/
/* old values */
/***************/
$entry['values']['old'] = array();
foreach ($entry['ldap']->getAttributes() as $old_attr) {
$name = $old_attr->getName();
$entry['values']['old'][$name] = array();
foreach ($old_attr->getValues() as $old_val) {
if (strlen($old_val) > 0)
$entry['values']['old'][$name][] = $old_val;
}
}
/***************/
/* new values */
/***************/
eval('$reader = new '.$_SESSION[APPCONFIG]->GetValue('appearance','entry_reader').'($ldapserver);');
$entry['ldap']->accept($reader);
$entry['values']['new'] = array();
foreach ($entry['ldap']->getAttributes() as $new_attr) {
if ($new_attr->hasBeenModified()) {
$name = $new_attr->getName();
if (!isset($entry['values']['old'][$name]))
$entry['values']['old'][$name] = array();
$entry['values']['new'][$name] = array();
foreach ($new_attr->getValues() as $i => $new_val) {
if ($new_attr instanceof BinaryAttribute) {
$n = $new_attr->getFileName($i);
$p = $new_attr->getFilePath($i);
$new_val = md5("$n|$p");
}
if (strlen($new_val) > 0)
$entry['values']['new'][$name][] = $new_val;
}
}
}
/************************/
/* objectClass deletion */
/************************/
$oc_to_delete = array();
$attr_to_delete = array();
// if objectClass attribute is modified
if (isset($entry['values']['new']['objectClass'])) {
if (!isset($entry['values']['old']['objectClass']))
error(_('An entry should have one structural objectClass.'),'error','index.php');
// deleted objectClasses
foreach ($entry['values']['old']['objectClass'] as $oldOC) {
if (!in_array($oldOC, $entry['values']['new']['objectClass'])) {
$oc_to_delete[] = $oldOC;
}
}
// search the attributes used by each deleted objecClass
// we must maybe delete these attributes
foreach ($oc_to_delete as $oc) {
$soc = $ldapserver->getSchemaObjectClass($oc);
if ($soc) {
$ocs = $ldapserver->SchemaObjectClasses();
$ma = $soc->getMustAttrs($ocs);
foreach ($ma as $a) {
if (!isset($attr_to_delete[$a->getName()])) {
$attr_to_delete[$a->getName()] = $a;
}
}
$ma = $soc->getMayAttrs($ocs);
foreach ($ma as $a) {
if (!isset($attr_to_delete[$a->getName()])) {
$attr_to_delete[$a->getName()] = $a;
}
}
}
}
// if an attribute is still used by an objectClass we don't delete,
// we don't delete this attribute
foreach ($attr_to_delete as $name => $ad) {
$found = false;
$at = $ldapserver->getSchemaAttribute($name);
foreach ($at->getUsedInObjectClasses() as $oc) {
if (in_array($oc, $entry['values']['new']['objectClass'])) {
$found = true;
break;
}
}
if (!$found) {
foreach ($at->getRequiredByObjectClasses() as $oc) {
if (in_array($oc, $entry['values']['new']['objectClass'])) {
$found = true;
break;
}
}
}
if ($found) {
unset($attr_to_delete[$name]);
} else {
if (isset($entry['values']['old'][$name]) && (count($entry['values']['old'][$name]) > 0)) {
$found = true;
} else {
foreach ($entry['values']['new'] as $attr_name => $attr_values) {
if ($name == $attr_name) {
$found = true;
break;
}
}
}
if (!$found) {
unset($attr_to_delete[$name]);
} else {
$entry['values']['new'][$name] = array();
$attr_to_delete[$name] = $name;
}
}
}
}
/****************/
/* update array */
/****************/
eval('$writer = new '.$_SESSION[APPCONFIG]->GetValue('appearance','entry_writer').'($ldapserver);');
$writer->draw('Title',$entry['ldap']);
$writer->draw('Subtitle',$entry['ldap']);
echo "\n\n";
run_hook('pre_update_array_processing',
array('server_id'=>$ldapserver->server_id,'dn'=>$entry['dn']['string'],'old_values'=>$entry['values']['old'],'new_values'=>$entry['values']['new']));
/***************/
/* confirm */
/***************/
if (count($entry['values']['new']) > 0) {
echo '
';
echo '
%s%s | ',_('The deletion of objectClass(es)'),_(':')); printf('%s | ',implode(', ', $oc_to_delete)); echo '
%s%s | ',_('will delete the attribute(s)'),_(':')); echo ''; $i = 0; foreach ($attr_to_delete as $attr) { if ($i++ != 0) echo ', '; echo $_SESSION[APPCONFIG]->getFriendlyHTML($attr); } echo ' |