2009-06-30 09:22:30 +00:00
|
|
|
<?php
|
2009-06-30 11:46:44 +00:00
|
|
|
// $Header: /cvsroot/phpldapadmin/phpldapadmin/htdocs/rename.php,v 1.33.2.1 2007/12/26 09:26:32 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())
|
2009-06-30 10:26:08 +00:00
|
|
|
pla_error(_('You cannot perform updates while server is in read-only mode'));
|
2009-06-30 10:46:00 +00:00
|
|
|
|
2009-06-30 11:46:44 +00:00
|
|
|
if (! $_SESSION[APPCONFIG]->isCommandAvailable('entry_rename'))
|
2009-06-30 10:46:00 +00:00
|
|
|
pla_error(sprintf('%s%s %s',_('This operation is not permitted by the configuration'),_(':'),_('rename entry')));
|
2009-06-30 08:09:20 +00:00
|
|
|
|
2009-06-30 09:29:51 +00:00
|
|
|
$dn = ($_POST['dn']);
|
|
|
|
if (! $ldapserver->isBranchRenameEnabled()) {
|
2009-06-30 10:46:00 +00:00
|
|
|
# we search all children, not only the visible children in the tree
|
2009-06-30 10:26:08 +00:00
|
|
|
$children = $ldapserver->getContainerContents($dn);
|
2009-06-30 09:29:51 +00:00
|
|
|
if (count($children) > 0)
|
2009-06-30 10:26:08 +00:00
|
|
|
pla_error(_('You cannot rename an entry which has children entries (eg, the rename operation is not allowed on non-leaf entries)'));
|
2009-06-30 09:29:51 +00:00
|
|
|
}
|
|
|
|
|
2009-06-30 10:26:08 +00:00
|
|
|
$new_rdn = ($_POST['new_rdn']);
|
2009-06-30 09:29:51 +00:00
|
|
|
$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)
|
2009-06-30 10:26:08 +00:00
|
|
|
pla_error(_('You did not change the RDN'));
|
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
|
|
|
$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]))
|
2009-06-30 10:26:08 +00:00
|
|
|
pla_error(_('Invalid RDN value'));
|
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 10:40:03 +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;
|
2009-06-30 10:40:03 +00:00
|
|
|
$success = $ldapserver->rename($dn,$new_rdn,$container,$deleteoldrdn);
|
2009-06-30 09:29:51 +00:00
|
|
|
|
|
|
|
} else {
|
2009-06-30 10:26:08 +00:00
|
|
|
pla_error(_('Could not rename the entry') );
|
2009-06-30 08:05:37 +00:00
|
|
|
}
|
2009-06-30 08:09:20 +00:00
|
|
|
|
2009-06-30 10:26:08 +00:00
|
|
|
if ($success) {
|
|
|
|
run_hook('post_rename_entry',array('server_id'=>$ldapserver->server_id,'old_dn'=>$dn,'new_dn'=>$new_dn_value));
|
|
|
|
|
2009-06-30 10:46:00 +00:00
|
|
|
$rename_message = sprintf('%s',_('Rename successful!'));
|
|
|
|
$redirect_url = sprintf('cmd.php?cmd=template_engine&server_id=%s&dn=%s',$ldapserver->server_id,rawurlencode($new_dn));
|
2009-06-30 08:05:37 +00:00
|
|
|
|
2009-06-30 10:46:00 +00:00
|
|
|
system_message(array(
|
|
|
|
'title'=>_('Rename Entry'),
|
|
|
|
'body'=>$rename_message,
|
|
|
|
'type'=>'info'),
|
|
|
|
$redirect_url);
|
2009-06-30 08:05:37 +00:00
|
|
|
}
|
2009-06-30 09:29:51 +00:00
|
|
|
?>
|