phpldapadmin/htdocs/rdelete.php

93 lines
2.8 KiB
PHP
Raw Normal View History

2009-06-30 09:22:30 +00:00
<?php
2009-06-30 10:41:18 +00:00
// $Header: /cvsroot/phpldapadmin/phpldapadmin/htdocs/rdelete.php,v 1.27 2007/03/18 03:14:52 wurley Exp $
2009-06-30 08:05:37 +00:00
2009-06-30 09:29:51 +00:00
/**
2009-06-30 08:05:37 +00:00
* Recursively deletes the specified DN and all of its children
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)
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 09:29:51 +00:00
if (! $ldapserver->haveAuthInfo())
2009-06-30 10:26:08 +00:00
pla_error(_('Not enough information to login to server. Please check your configuration.'));
2009-06-30 08:05:37 +00:00
2009-06-30 09:29:51 +00:00
$dn = $_POST['dn'];
if (! $dn)
2009-06-30 10:26:08 +00:00
pla_error(_('You must specify a DN'));
2009-06-30 08:07:14 +00:00
2009-06-30 10:26:08 +00:00
if (! $ldapserver->dnExists($dn))
pla_error(sprintf(_('No such entry: %s'),htmlspecialchars($dn)));
2009-06-30 08:05:37 +00:00
2009-06-30 09:22:30 +00:00
include './header.php';
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
echo '<body>';
printf('<h3 class="title">'._('Deleting %s').'</h3>',htmlspecialchars(get_rdn($dn)));
printf('<h3 class="subtitle">%s</h3>',_('Recursive delete progress'));
echo '<br /><br />';
echo '<small>';
2009-06-30 09:29:51 +00:00
2009-06-30 08:05:37 +00:00
flush();
2009-06-30 10:26:08 +00:00
# prevent script from bailing early on a long delete
2009-06-30 09:29:51 +00:00
@set_time_limit(0);
2009-06-30 08:05:37 +00:00
2009-06-30 09:29:51 +00:00
$del_result = pla_rdelete($ldapserver,$dn);
2009-06-30 10:26:08 +00:00
echo '</small><br />';
2009-06-30 08:05:37 +00:00
2009-06-30 09:29:51 +00:00
if ($del_result) {
2009-06-30 10:26:08 +00:00
echo '<script language="javascript">parent.left_frame.location.reload();</script>';
printf(_('Entry %s and sub-tree deleted successfully.'),'<b>'.htmlspecialchars($dn).'</b>');
2009-06-30 08:05:37 +00:00
} else {
2009-06-30 10:26:08 +00:00
pla_error(sprintf(_('Could not delete the entry: %s'),htmlspecialchars($dn)),
2009-06-30 09:40:37 +00:00
$ldapserver->error(),$ldapserver->errno());
2009-06-30 08:05:37 +00:00
}
2009-06-30 09:29:51 +00:00
function pla_rdelete($ldapserver,$dn) {
2009-06-30 10:26:08 +00:00
$children = $ldapserver->getContainerContents($dn);
2009-06-30 08:05:37 +00:00
2009-06-30 09:29:51 +00:00
if (! is_array($children) || count($children) == 0) {
2009-06-30 10:41:18 +00:00
printf('<span style="white-space: nowrap;">%s %s...',_('Deleting'),htmlspecialchars($dn));
2009-06-30 08:05:37 +00:00
flush();
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
if (run_hook('pre_entry_delete',array('server_id'=>$ldapserver->server_id,'dn'=>$dn)))
if ($ldapserver->delete($dn)) {
run_hook('post_entry_delete',array('server_id'=>$ldapserver->server_id,'dn'=>$dn));
2009-06-30 10:41:18 +00:00
printf(' <span style="color:green">%s</span></span><br />',_('Success'));
2009-06-30 09:29:51 +00:00
return true;
} else {
2009-06-30 10:26:08 +00:00
pla_error(sprintf(_('Failed to delete entry %s'),htmlspecialchars($dn)),
2009-06-30 09:40:37 +00:00
$ldapserver->error(),$ldapserver->errno());
2009-06-30 09:29:51 +00:00
}
2009-06-30 08:05:37 +00:00
} else {
2009-06-30 10:26:08 +00:00
foreach ($children as $child_dn)
2009-06-30 09:29:51 +00:00
pla_rdelete($ldapserver,$child_dn);
2009-06-30 10:41:18 +00:00
printf('<span style="white-space: nowrap;">%s %s...',_('Deleting'),htmlspecialchars($dn));
2009-06-30 08:05:37 +00:00
flush();
2009-06-30 10:26:08 +00:00
if (run_hook('pre_entry_delete',array('server_id'=>$ldapserver->server_id,'dn'=>$dn)))
if ($ldapserver->delete($dn)) {
run_hook('post_entry_delete',array('server_id'=>$ldapserver->server_id,'dn'=>$dn));
2009-06-30 10:41:18 +00:00
printf(' <span style="color:green">%s</span></span><br />',_('Success'));
2009-06-30 09:29:51 +00:00
return true;
} else {
2009-06-30 10:26:08 +00:00
pla_error(sprintf(_('Failed to delete entry %s'),htmlspecialchars($dn)),
2009-06-30 09:40:37 +00:00
$ldapserver->error(),$ldapserver->errno());
2009-06-30 09:29:51 +00:00
}
}
2009-06-30 08:05:37 +00:00
}
2009-06-30 09:29:51 +00:00
?>