phpldapadmin/htdocs/rename.php

123 lines
3.4 KiB
PHP
Raw Normal View History

2009-06-30 09:22:30 +00:00
<?php
2009-06-30 09:29:51 +00:00
// $Header: /cvsroot/phpldapadmin/phpldapadmin/rename.php,v 1.27 2005/09/25 16:11:44 wurley Exp $
2009-06-30 08:05:37 +00:00
2009-06-30 09:29:51 +00:00
/**
* Renames a DN to a different name.
2009-06-30 08:05:37 +00:00
*
2009-06-30 09:29:51 +00:00
* Variables that come in via common.php
* - server_id
2009-06-30 08:05:37 +00:00
* Variables that come in as POST vars:
* - dn (rawurlencoded)
* - new_rdn
2009-06-30 09:29:51 +00:00
*
* @package phpLDAPadmin
*/
/**
2009-06-30 08:05:37 +00:00
*/
2009-06-30 09:29:51 +00:00
require './common.php';
2009-06-30 08:05:37 +00:00
2009-06-30 09:29:51 +00:00
if ($ldapserver->isReadOnly())
pla_error($lang['no_updates_in_read_only_mode']);
if (! $ldapserver->haveAuthInfo())
pla_error($lang['not_enough_login_info']);
2009-06-30 08:09:20 +00:00
2009-06-30 09:29:51 +00:00
$dn = ($_POST['dn']);
$new_rdn = ($_POST['new_rdn']);
2009-06-30 08:05:37 +00:00
2009-06-30 09:29:51 +00:00
if (! $ldapserver->isBranchRenameEnabled()) {
$children = get_container_contents($ldapserver,$dn,1);
if (count($children) > 0)
pla_error($lang['non_leaf_nodes_cannot_be_renamed']);
}
$container = get_container($dn);
$new_dn = sprintf('%s,%s',$new_rdn,$container);
2009-06-30 08:07:14 +00:00
2009-06-30 09:29:51 +00:00
if ($new_dn == $dn)
pla_error($lang['no_rdn_change']);
2009-06-30 08:07:14 +00:00
2009-06-30 09:29:51 +00:00
$old_dn_attr = explode('=',$dn);
$old_dn_attr = $old_dn_attr[0];
2009-06-30 08:09:20 +00:00
2009-06-30 09:29:51 +00:00
$old_dn_value = pla_explode_dn($dn);
$old_dn_value = explode('=',$old_dn_value[0],2);
$old_dn_value = $old_dn_value[1];
2009-06-30 08:05:37 +00:00
2009-06-30 09:29:51 +00:00
$new_dn_value = explode('=',$new_rdn,2);
2009-06-30 08:09:20 +00:00
2009-06-30 09:29:51 +00:00
if (count($new_dn_value) != 2 || ! isset($new_dn_value[1]))
pla_error($lang['invalid_rdn']);
2009-06-30 08:05:37 +00:00
2009-06-30 09:29:51 +00:00
$new_dn_attr = $new_dn_value[0];
2009-06-30 08:09:20 +00:00
$new_dn_value = $new_dn_value[1];
2009-06-30 09:29:51 +00:00
$success = run_hook ('pre_rename_entry', array ('server_id' => $ldapserver->server_id,
'old_dn' => $dn, 'new_dn' => $new_dn_value ) );
2009-06-30 08:09:20 +00:00
2009-06-30 09:29:51 +00:00
if ($success) {
$success = false;
2009-06-30 08:09:20 +00:00
2009-06-30 09:29:51 +00:00
$deleteoldrdn = $old_dn_attr == $new_dn_attr;
if (! @ldap_rename($ldapserver->connect(), $dn, $new_rdn, $container, $deleteoldrdn ) ) {
pla_error($lang['could_not_rename'], ldap_error($ldapserver->connect() ),
ldap_errno($ldapserver->connect() ), false );
} else
$success = true;
} else {
pla_error($lang['could_not_rename'] );
2009-06-30 08:05:37 +00:00
}
2009-06-30 08:09:20 +00:00
2009-06-30 09:29:51 +00:00
if ($success ) {
run_hook ('post_rename_entry', array ('server_id' => $ldapserver->server_id, 'old_dn' => $dn,
'new_dn' => $new_dn_value ) );
if (array_key_exists('tree', $_SESSION ) ) {
2009-06-30 08:05:37 +00:00
$tree = $_SESSION['tree'];
$tree_icons = $_SESSION['tree_icons'];
$old_dn = $dn;
// gotta search the whole tree for the entry (must be a leaf node since RDN changes
// cannot occur on parents)
2009-06-30 09:29:51 +00:00
foreach ($tree[$ldapserver->server_id] as $parent_dn => $children ) {
foreach ($children as $i => $child_dn ) {
if (0 == strcasecmp($child_dn, $old_dn ) )
$tree[$ldapserver->server_id][$parent_dn][$i] = $new_dn;
2009-06-30 08:05:37 +00:00
}
}
2009-06-30 09:29:51 +00:00
2009-06-30 08:05:37 +00:00
// Update the icon tree to reflect the change (remove the old DN and add the new one)
2009-06-30 09:29:51 +00:00
$tree_icons[ $ldapserver->server_id ][ $new_dn ] = $tree_icons[ $ldapserver->server_id ][ $old_dn ];
unset($tree_icons[ $ldapserver->server_id ][ $old_dn ] );
2009-06-30 08:05:37 +00:00
$_SESSION['tree'] = $tree;
$_SESSION['tree_icons'] = $tree_icons;
session_write_close();
2009-06-30 09:29:51 +00:00
$edit_url = sprintf('edit.php?server_id=%s&dn=%s',$ldapserver->server_id,rawurlencode("$new_rdn,$container"));
?>
2009-06-30 08:05:37 +00:00
<html>
<head>
<!-- refresh the tree view (with the new DN renamed)
and redirect to the edit_dn page -->
<script language="javascript">
parent.left_frame.location.reload();
location.href='<?php echo $edit_url; ?>';
</script>
2009-06-30 09:22:30 +00:00
<!-- If the JavaScript didn't work, here's a meta tag to do the job -->
2009-06-30 08:05:37 +00:00
<meta http-equiv="refresh" content="0; url=<?php echo $edit_url; ?>" />
</head>
<body>
2009-06-30 09:22:30 +00:00
<?php echo $lang['redirecting']; ?> <a href="<?php echo $edit_url; ?>"><?php echo $lang['here']; ?></a>
2009-06-30 08:05:37 +00:00
</body>
</html>
2009-06-30 09:29:51 +00:00
<?php }
2009-06-30 08:05:37 +00:00
}
2009-06-30 09:29:51 +00:00
?>