phpldapadmin/htdocs/rename.php

70 lines
2.2 KiB
PHP
Raw Normal View History

2009-06-30 09:22:30 +00:00
<?php
// $Header$
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
* @package phpLDAPadmin
* @subpackage Page
2009-06-30 09:29:51 +00:00
*/
2009-06-30 09:29:51 +00:00
/**
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
# The DN we are working with
$request = array();
$request['dnSRC'] = get_request('dn','REQUEST');
$request['rdnDST'] = get_request('new_rdn','REQUEST');
$request['container'] = $app['server']->getContainer($request['dnSRC']);
2009-06-30 10:46:00 +00:00
# Error checking
2009-06-30 11:46:44 +00:00
if (! $_SESSION[APPCONFIG]->isCommandAvailable('entry_rename'))
error(sprintf('%s: %s',_('This operation is not permitted by the configuration'),_('rename entry')),'error','index.php');
if (! $app['server']->isBranchRenameEnabled()) {
# We search all children, not only the visible children in the tree
$children = $app['server']->getContainerContents($request['dnSRC'],null,0,'(objectClass=*)',LDAP_DEREF_NEVER);
2009-06-30 08:09:20 +00:00
2009-06-30 09:29:51 +00:00
if (count($children) > 0)
2009-06-30 11:52:55 +00:00
error(_('You cannot rename an entry which has children entries (eg, the rename operation is not allowed on non-leaf entries)'),'error','index.php');
2009-06-30 09:29:51 +00:00
}
$request['dnDST'] = sprintf('%s,%s',$request['rdnDST'],$request['container']);
2009-06-30 08:07:14 +00:00
if ($request['dnDST'] == $request['dnSRC'])
2009-06-30 11:52:55 +00:00
error(_('You did not change the RDN'),'error','index.php');
2009-06-30 08:07:14 +00:00
$rdnattr = array();
$rdnattr['SRC'] = explode('=',$request['dnSRC']);
$rdnattr['SRC'] = $rdnattr['SRC'][0];
2009-06-30 08:09:20 +00:00
$new_dn_value = explode('=',$request['rdnDST'],2);
$rdnattr['DST'] = $new_dn_value[0];
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 11:52:55 +00:00
error(_('Invalid RDN value'),'error','index.php');
2009-06-30 08:05:37 +00:00
$deleteoldrdn = $rdnattr['SRC'] == $rdnattr['DST'];
$success = $app['server']->rename($request['dnSRC'],$request['rdnDST'],$request['container'],$deleteoldrdn);
2009-06-30 08:09:20 +00:00
2009-06-30 10:26:08 +00:00
if ($success) {
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&template=%s',
$app['server']->getIndex(),rawurlencode($request['dnDST']),get_request('template','REQUEST'));
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);
} else {
system_message(array(
'title'=>_('Could not rename the entry.'),
'body'=>ldap_error_msg($app['server']->getErrorMessage(null),$app['server']->getErrorNum(null)),
'type'=>'error'));
2009-06-30 08:05:37 +00:00
}
2009-06-30 09:29:51 +00:00
?>