~ubuntu-branches/debian/wheezy/phpldapadmin/wheezy

« back to all changes in this revision

Viewing changes to htdocs/rename.php

  • Committer: Bazaar Package Importer
  • Author(s): Fabio Tranchitella
  • Date: 2010-04-10 10:12:22 UTC
  • mfrom: (1.2.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20100410101222-3xyuhy4a7usewxla
Tags: 1.2.0.5-1
* New upstream release. (Closes: #571672, #549464)
* debian/po/ru.po: added. (Closes: #536402)
* applied patch to fix lintian warnings. (Closes: #531649)
* Removed debian/patches that have been merged upstream.
* Do not build-depend anymore on dpatch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
<?php
2
 
// $Header: /cvsroot/phpldapadmin/phpldapadmin/htdocs/rename.php,v 1.33.2.3 2008/12/12 12:20:22 wurley Exp $
3
 
 
4
2
/**
5
3
 * Renames a DN to a different name.
6
4
 *
7
 
 * Variables that come in via common.php
8
 
 *  - server_id
9
 
 * Variables that come in as POST vars:
10
 
 *  - dn (rawurlencoded)
11
 
 *  - new_rdn
12
 
 *
13
5
 * @package phpLDAPadmin
 
6
 * @subpackage Page
14
7
 */
 
8
 
15
9
/**
16
10
 */
17
11
 
18
12
require './common.php';
19
13
 
20
 
if ($ldapserver->isReadOnly())
21
 
        error(_('You cannot perform updates while server is in read-only mode'),'error','index.php');
22
 
 
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');
25
 
 
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
 
15
$request = array();
 
16
$request['dnSRC'] = get_request('dn','REQUEST');
 
17
$request['rdnDST'] = get_request('new_rdn','REQUEST');
 
18
$request['container'] = $app['server']->getContainer($request['dnSRC']);
 
19
 
 
20
# Error checking
 
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);
 
24
 
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');
32
27
}
33
28
 
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']);
37
30
 
38
 
if ($new_dn == $dn)
 
31
if ($request['dnDST'] == $request['dnSRC'])
39
32
        error(_('You did not change the RDN'),'error','index.php');
40
33
 
41
 
$old_dn_attr = explode('=',$dn);
42
 
$old_dn_attr = $old_dn_attr[0];
 
34
$rdnattr = array();
 
35
$rdnattr['SRC'] = explode('=',$request['dnSRC']);
 
36
$rdnattr['SRC'] = $rdnattr['SRC'][0];
43
37
 
44
 
$new_dn_value = explode('=',$new_rdn,2);
 
38
$new_dn_value = explode('=',$request['rdnDST'],2);
 
39
$rdnattr['DST'] = $new_dn_value[0];
45
40
 
46
41
if (count($new_dn_value) != 2 || ! isset($new_dn_value[1]))
47
42
        error(_('Invalid RDN value'),'error','index.php');
48
43
 
49
 
$new_dn_attr = $new_dn_value[0];
50
 
$new_dn_value = $new_dn_value[1];
51
 
 
52
 
$success = run_hook('pre_rename_entry',array('server_id'=>$ldapserver->server_id,'old_dn'=>$dn,'new_dn'=>$new_dn_value));
53
 
 
54
 
if ($success) {
55
 
        $success = false;
56
 
 
57
 
        $deleteoldrdn = $old_dn_attr == $new_dn_attr;
58
 
        $success = $ldapserver->rename($dn,$new_rdn,$container,$deleteoldrdn);
59
 
 
60
 
} else {
61
 
        error(_('Could not rename the entry'),'error','index.php');
62
 
}
63
 
 
64
 
if ($success) {
65
 
        run_hook('post_rename_entry',array('server_id'=>$ldapserver->server_id,'old_dn'=>$dn,'new_dn'=>$new_dn_value));
66
 
 
 
44
$deleteoldrdn = $rdnattr['SRC'] == $rdnattr['DST'];
 
45
$success = $app['server']->rename($request['dnSRC'],$request['rdnDST'],$request['container'],$deleteoldrdn);
 
46
 
 
47
if ($success) {
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'));
69
51
 
70
52
        system_message(array(
71
53
                'title'=>_('Rename Entry'),
72
54
                'body'=>$rename_message,
73
55
                'type'=>'info'),
74
56
                $redirect_url);
 
57
 
 
58
} else {
 
59
        system_message(array(
 
60
                'title'=>_('Could not rename the entry.'),
 
61
                'body'=>ldap_error_msg($app['server']->getErrorMessage(null),$app['server']->getErrorNum(null)),
 
62
                'type'=>'error'));
75
63
}
76
64
?>