phpldapadmin/htdocs/rdelete.php

93 lines
3.1 KiB
PHP
Raw Normal View History

2009-06-30 09:22:30 +00:00
<?php
2009-06-30 11:52:55 +00:00
// $Header: /cvsroot/phpldapadmin/phpldapadmin/htdocs/rdelete.php,v 1.28.2.3 2008/12/12 12:20:22 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
*
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 11:52:55 +00:00
error(_('You cannot perform updates while server is in read-only mode'),'error','index.php');
2009-06-30 08:05:37 +00:00
2009-06-30 11:52:55 +00:00
if (! $_SESSION[APPCONFIG]->isCommandAvailable('entry_delete','simple_delete'))
error(sprintf('%s%s %s',_('This operation is not permitted by the configuration'),_(':'),_('delete entry')),'error','index.php');
2009-06-30 08:07:14 +00:00
2009-06-30 11:52:55 +00:00
$entry = array();
$entry['dn'] = get_request('dn');
2009-06-30 10:46:00 +00:00
if (! $entry['dn'])
2009-06-30 11:52:55 +00:00
error(_('You must specify a DN'),'error','index.php');
2009-06-30 08:05:37 +00:00
2009-06-30 10:46:00 +00:00
if (! $ldapserver->dnExists($entry['dn']))
2009-06-30 11:52:55 +00:00
error(sprintf('%s (%s)',_('No such entry.'),htmlspecialchars($entry['dn'])),'error','index.php');
2009-06-30 09:29:51 +00:00
2009-06-30 10:46:00 +00:00
printf('<h3 class="title">'._('Deleting %s').'</h3>',htmlspecialchars(get_rdn($entry['dn'])));
2009-06-30 10:26:08 +00:00
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 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-06-30 10:46:00 +00:00
$result = pla_rdelete($ldapserver,$entry['dn']);
2009-06-30 10:26:08 +00:00
echo '</small><br />';
2009-06-30 08:05:37 +00:00
2009-06-30 10:46:00 +00:00
if ($result) {
printf(_('Entry %s and sub-tree deleted successfully.'),'<b>'.htmlspecialchars($entry['dn']).'</b>');
2009-06-30 08:05:37 +00:00
} else {
2009-06-30 11:52:55 +00:00
system_message(array(
'title'=>_('Could not delete the entry.').sprintf(' (%s)',pretty_print_dn($entry['dn'])),
'body'=>ldap_error_msg($ldapserver->error(),$ldapserver->errno()),
'type'=>'error'));
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:46:00 +00:00
# we delete all children, not only the visible children in the tree
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 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)) {
2009-06-30 10:46:00 +00:00
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 11:52:55 +00:00
system_message(array(
'title'=>_('Could not delete the entry.').sprintf(' (%s)',pretty_print_dn($entry['dn'])),
'body'=>ldap_error_msg($ldapserver->error(),$ldapserver->errno()),
'type'=>'error'));
2009-06-30 09:29:51 +00:00
}
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)
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
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)) {
2009-06-30 10:46:00 +00:00
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 11:52:55 +00:00
system_message(array(
'title'=>_('Could not delete the entry.').sprintf(' (%s)',pretty_print_dn($entry['dn'])),
'body'=>ldap_error_msg($ldapserver->error(),$ldapserver->errno()),
'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
?>