phpldapadmin/htdocs/rdelete.php

86 lines
2.8 KiB
PHP
Raw Normal View History

2009-06-30 09:22:30 +00:00
<?php
2009-06-30 11:46:44 +00:00
// $Header: /cvsroot/phpldapadmin/phpldapadmin/htdocs/rdelete.php,v 1.28.2.1 2007/12/26 09:26:32 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 10:26:08 +00:00
pla_error(_('You cannot perform updates while server is in read-only mode'));
2009-06-30 08:05:37 +00:00
2009-06-30 11:46:44 +00:00
if (! $_SESSION[APPCONFIG]->isCommandAvailable('entry_delete', 'simple_delete'))
2009-06-30 10:46:00 +00:00
pla_error(sprintf('%s%s %s',_('This operation is not permitted by the configuration'),_(':'),_('delete entry')));
2009-06-30 08:07:14 +00:00
2009-06-30 10:46:00 +00:00
$entry['dn'] = $_POST['dn'];
if (! $entry['dn'])
pla_error(_('You must specify a DN'));
2009-06-30 08:05:37 +00:00
2009-06-30 10:46:00 +00:00
if (! $ldapserver->dnExists($entry['dn']))
pla_error(sprintf(_('No such entry: %s'),htmlspecialchars($entry['dn'])));
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 10:46:00 +00:00
pla_error(sprintf(_('Could not delete the entry: %s'),htmlspecialchars($entry['dn'])),
$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: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 10:46:00 +00:00
pla_error(sprintf(_('Failed to delete entry %s'),htmlspecialchars($dn)),
$ldapserver->error(),$ldapserver->errno());
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 10:46:00 +00:00
pla_error(sprintf(_('Failed to delete entry %s'),htmlspecialchars($dn)),
$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
?>