2
// $Header: /cvsroot/phpldapadmin/phpldapadmin/htdocs/rename.php,v 1.33.2.3 2008/12/12 12:20:22 wurley Exp $
5
3
* Renames a DN to a different name.
7
* Variables that come in via common.php
9
* Variables that come in as POST vars:
10
* - dn (rawurlencoded)
13
5
* @package phpLDAPadmin
18
12
require './common.php';
20
if ($ldapserver->isReadOnly())
21
error(_('You cannot perform updates while server is in read-only mode'),'error','index.php');
23
if (! $_SESSION[APPCONFIG]->isCommandAvailable('entry_rename'))
24
error(sprintf('%s%s %s',_('This operation is not permitted by the configuration'),_(':'),_('rename entry')),'error','index.php');
26
$dn = get_request('dn');
27
if (! $ldapserver->isBranchRenameEnabled()) {
28
# we search all children, not only the visible children in the tree
29
$children = $ldapserver->getContainerContents($dn);
14
# The DN we are working with
16
$request['dnSRC'] = get_request('dn','REQUEST');
17
$request['rdnDST'] = get_request('new_rdn','REQUEST');
18
$request['container'] = $app['server']->getContainer($request['dnSRC']);
21
if (! $app['server']->isBranchRenameEnabled()) {
22
# We search all children, not only the visible children in the tree
23
$children = $app['server']->getContainerContents($request['dnSRC'],null,0,'(objectClass=*)',LDAP_DEREF_NEVER);
30
25
if (count($children) > 0)
31
26
error(_('You cannot rename an entry which has children entries (eg, the rename operation is not allowed on non-leaf entries)'),'error','index.php');
34
$new_rdn = get_request('new_rdn');
35
$container = get_container($dn);
36
$new_dn = sprintf('%s,%s',$new_rdn,$container);
29
$request['dnDST'] = sprintf('%s,%s',$request['rdnDST'],$request['container']);
31
if ($request['dnDST'] == $request['dnSRC'])
39
32
error(_('You did not change the RDN'),'error','index.php');
41
$old_dn_attr = explode('=',$dn);
42
$old_dn_attr = $old_dn_attr[0];
35
$rdnattr['SRC'] = explode('=',$request['dnSRC']);
36
$rdnattr['SRC'] = $rdnattr['SRC'][0];
44
$new_dn_value = explode('=',$new_rdn,2);
38
$new_dn_value = explode('=',$request['rdnDST'],2);
39
$rdnattr['DST'] = $new_dn_value[0];
46
41
if (count($new_dn_value) != 2 || ! isset($new_dn_value[1]))
47
42
error(_('Invalid RDN value'),'error','index.php');
49
$new_dn_attr = $new_dn_value[0];
50
$new_dn_value = $new_dn_value[1];
52
$success = run_hook('pre_rename_entry',array('server_id'=>$ldapserver->server_id,'old_dn'=>$dn,'new_dn'=>$new_dn_value));
57
$deleteoldrdn = $old_dn_attr == $new_dn_attr;
58
$success = $ldapserver->rename($dn,$new_rdn,$container,$deleteoldrdn);
61
error(_('Could not rename the entry'),'error','index.php');
65
run_hook('post_rename_entry',array('server_id'=>$ldapserver->server_id,'old_dn'=>$dn,'new_dn'=>$new_dn_value));
44
$deleteoldrdn = $rdnattr['SRC'] == $rdnattr['DST'];
45
$success = $app['server']->rename($request['dnSRC'],$request['rdnDST'],$request['container'],$deleteoldrdn);
67
48
$rename_message = sprintf('%s',_('Rename successful!'));
68
$redirect_url = sprintf('cmd.php?cmd=template_engine&server_id=%s&dn=%s',$ldapserver->server_id,rawurlencode($new_dn));
49
$redirect_url = sprintf('cmd.php?cmd=template_engine&server_id=%s&dn=%s&template=%s',
50
$app['server']->getIndex(),rawurlencode($request['dnDST']),get_request('template','REQUEST'));
70
52
system_message(array(
71
53
'title'=>_('Rename Entry'),
72
54
'body'=>$rename_message,
60
'title'=>_('Could not rename the entry.'),
61
'body'=>ldap_error_msg($app['server']->getErrorMessage(null),$app['server']->getErrorNum(null)),