phpldapadmin/htdocs/rdelete.php

90 lines
2.5 KiB
PHP
Raw Permalink Normal View History

2009-06-30 09:22:30 +00:00
<?php
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
*
* @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
$request = array();
$request['dn'] = get_request('dn','REQUEST',true);
2009-06-30 08:05:37 +00:00
2009-07-06 05:19:42 +00:00
if (! is_array($request['dn']))
$request['dn'] = array($request['dn']);
$request['parent'] = array();
foreach ($request['dn'] as $dn)
if (! $app['server']->dnExists($dn))
system_message(array(
'title'=>_('Entry does not exist'),
'body'=>sprintf('%s (%s)',_('Unable to delete entry, it does not exist'),$dn),
'type'=>'error'));
else
array_push($request['parent'],$dn);
printf('<h3 class="title">%s</h3>',_('Delete LDAP entries'));
2009-06-30 10:26:08 +00:00
printf('<h3 class="subtitle">%s</h3>',_('Recursive delete progress'));
2009-06-30 09:29:51 +00:00
2009-06-30 10:46:00 +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-07-06 05:19:42 +00:00
foreach ($request['parent'] as $dn) {
echo '<br /><br />';
echo '<small>';
$result = pla_rdelete($app['server'],$dn);
echo '</small><br />';
if ($result) {
printf(_('Entry %s and sub-tree deleted successfully.'),'<b>'.$dn.'</b>');
} else {
system_message(array(
'title'=>_('Could not delete the entry.').sprintf(' (%s)',pretty_print_dn($request['dn'])),
'body'=>ldap_error_msg($app['server']->getErrorMessage(null),$app['server']->getErrorNum(null)),
'type'=>'error'));
}
2009-06-30 08:05:37 +00:00
}
function pla_rdelete($server,$dn) {
# We delete all children, not only the visible children in the tree
$children = $server->getContainerContents($dn,null,0,'(objectClass=*)',LDAP_DEREF_NEVER);
2009-06-30 08:05:37 +00:00
2009-06-30 09:29:51 +00:00
if (! is_array($children) || count($children) == 0) {
printf('<span style="white-space: nowrap;">%s %s...',_('Deleting'),$dn);
2009-06-30 09:29:51 +00:00
if ($server->delete($dn)) {
printf(' <span style="color:green">%s</span></span><br />',_('Success'));
return true;
2009-06-30 09:29:51 +00:00
} else {
system_message(array(
'title'=>_('Could not delete the entry.').sprintf(' (%s)',pretty_print_dn($dn)),
'body'=>ldap_error_msg($server->getErrorMessage(null),$server->getErrorNum(null)),
'type'=>'error'));
}
2009-06-30 10:46:00 +00:00
2009-06-30 08:05:37 +00:00
} else {
2009-06-30 10:26:08 +00:00
foreach ($children as $child_dn)
pla_rdelete($server,$child_dn);
printf('<span style="white-space: nowrap;">%s %s...',_('Deleting'),$dn);
if ($server->delete($dn)) {
printf(' <span style="color:green">%s</span></span><br />',_('Success'));
return true;
} else {
system_message(array(
'title'=>_('Could not delete the entry.').sprintf(' (%s)',pretty_print_dn($dn)),
'body'=>ldap_error_msg($server->getErrorMessage(null),$server->getErrorNum(null)),
'type'=>'error'));
}
2009-06-30 09:29:51 +00:00
}
2009-06-30 08:05:37 +00:00
}
2009-06-30 09:29:51 +00:00
?>