diff --git a/htdocs/mass_delete.php b/htdocs/mass_delete.php index 36a4bcf..cc87010 100644 --- a/htdocs/mass_delete.php +++ b/htdocs/mass_delete.php @@ -2,109 +2,142 @@ // $Header$ /** - * Enables user to mass delete multiple entries using checkboxes. - * - * Variables that come in as GET vars: - * - mass_delete - an array of DNs to delete in this form: - * Array ( - * [o=myorg,dc=example,dc=com] => on - * [cn=bob,dc=example,dc=com] => on - * ) - * etc. + * Displays a last chance confirmation form to delete a DN. * * @package phpLDAPadmin + * @subpackage Page */ + /** */ require './common.php'; -if ($ldapserver->isReadOnly()) - error(_('You cannot perform updates while server is in read-only mode'),'error','index.php'); +# The DN we are working with +$request = array(); +$request['dn'] = get_request('dn','REQUEST'); -if (! $_SESSION[APPCONFIG]->isCommandAvailable('entry_delete','mass_delete')) - error(sprintf('%s%s %s',_('This operation is not permitted by the configuration'),_(':'),_('delete mass entries')),'error','index.php'); +if (! is_array($request['dn'])) + $request['dn'] = array($request['dn']); -$confirmed = isset($_POST['confirmed']) ? true : false; -isset($_POST['mass_delete']) or - error(_('Error calling mass_delete.php. Missing mass_delete in POST vars.'),'error','index.php'); +$request['children'] = array(); +$request['parent'] = array(); +foreach ($request['dn'] as $dn) { + # Check if the entry exists. + if (! $dn || ! $app['server']->dnExists($dn)) + system_message(array( + 'title'=>_('Entry does not exist'), + 'body'=>sprintf('%s (%s/%s)',_('The entry does not exist and will be ignored'),$dn), + 'type'=>'error')); -$mass_delete = $_POST['mass_delete']; - -is_array($mass_delete) or - error(_('mass_delete POST var is not an array.'),'error','index.php'); - -$ldapserver->isMassDeleteEnabled() or - error(_('Mass deletion is not enabled. Please enable it in config.php before proceeding.'),'error','index.php'); - -printf('
'; - echo ''; - - $successfully_delete_dns = array(); - $failed_dns = array(); - - if (! is_array($mass_delete)) - error(_('Malformed mass_delete array.'),'error','index.php'); - - if (count($mass_delete) == 0) { - echo '
'; - printf('%s ',_('You did not select any entries to delete.')); - return; + # We search all children, not only the visible children in the tree + if (! in_array_ignore_case($dn,$request['children'])) { + $request['children'] = array_merge($request['children'],$app['server']->getContainerContents($dn,null,0,'(objectClass=*)',LDAP_DEREF_NEVER)); + array_push($request['parent'],$dn); } - - // @todo: Should sort these entries, so that they are deleted in order, if a user selects children. - foreach ($mass_delete as $dn => $junk) { - printf(_('Deleting %s'),htmlspecialchars($dn)); - - if(run_hook('pre_entry_delete',array('server_id'=>$ldapserver->server_id,'dn'=>$dn))) { - $success = $ldapserver->delete($dn); - - if ($success) { - run_hook('post_entry_delete',array('server_id'=>$ldapserver->server_id,'dn'=>$dn)); - - printf(' %s.
',_('Success')); - $successfully_delete_dns[] = $dn; - - } else { - printf(' %s.
(%s)
',_('Failed'),$ldapserver->error()); - $failed_dns[] = $dn; - } - } - } - - echo ''; - echo ''; - - $failed_count = count($failed_dns); - $total_count = count($mass_delete); - - if ($failed_count > 0) - printf(''._('%s of %s entries failed to be deleted.').'',$failed_count,$total_count); - else - printf('%s',_('All entries deleted successfully.')); - -} else { - $n = count($mass_delete); - printf(''._('Confirm mass delete of %s entries on server %s').'
',$n,$ldapserver->name); - - echo''; - printf(_('Do you really want to delete %s %s %s'), - ($n == 1? _('this') : _('these')),$n,($n == 1 ? _('entry') : _('entries'))); - - echo ' ',_('Yes, delete!')); - echo ''; } + +printf('%s
',_('Mass Delete')); +printf('%s: %s
',_('Server'),$app['server']->getName()); +echo "\n"; + +echo ''; +echo ' '; + +echo ''; + +if (count($request['parent']) == 1) + printf('
'; +echo '',_('Are you sure you want to permanently delete this object?')); +else + printf(' %s ',_('Are you sure you want to permanently delete these objects?')); + +echo ' %s '; +printf(' ',_('Server'),$app['server']->getName()); + +foreach ($request['parent'] as $dn) + printf(' %s: %s ', + _('Distinguished Name'),_('DN'),$dn); + +echo ' %s %s '; + +$request['delete'] = $request['parent']; + +if (count($request['children'])) { + printf(' ',_('Permanently delete all children also?')); + echo ' %s '; + + # We need to see if the children have children + $query = array(); + $query['scope'] = 'sub'; + $query['attrs'] = array('dn'); + $query['size_limit'] = 0; + $query['deref'] = LDAP_DEREF_NEVER; + + $request['search'] = array(); + foreach ($request['children'] as $dn) { + $query['base'] = $dn; + $request['search'] = array_merge($request['search'],$app['server']->query($query,null)); + } + + foreach ($request['search'] as $value) + array_push($request['delete'],$value['dn']); + + echo ' '; + echo ' '; + + printf(''; + printf(_('This request also includes %s children entries.'),count($request['children'])); + echo ' ', + sprintf(_('phpLDAPadmin can also recursively delete all %s of the child entries. See below for a list of all the entries that this action will delete. Do you want to do this?'),count($request['children']))); + + echo ' %s '; + + printf(' ', + _('Note: this is potentially very dangerous and you do this at your own risk. This operation cannot be undone. Take into consideration aliases, referrals, and other things that may cause problems.')); + echo "\n"; + + echo ' %s '; + + echo "\n"; + + printf(' ',_('List of entries to be deleted:')); + echo ' %s '; + + $i = 0; + echo ' '; + echo "\n"; + + echo ' '; + printf(''; + echo ' '; +} + +echo ' '; +echo ' '; +echo "\n"; + +echo ''; + +echo ' '; +echo ''; +echo ' '; +echo ' '; + +echo ''; + +echo '
'; ?> diff --git a/htdocs/rdelete.php b/htdocs/rdelete.php index cfa335a..09ccb74 100644 --- a/htdocs/rdelete.php +++ b/htdocs/rdelete.php @@ -19,28 +19,40 @@ if (! $_SESSION[APPCONFIG]->isCommandAvailable('entry_delete','simple_delete')) $request = array(); $request['dn'] = get_request('dn','REQUEST',true); -if (! $app['server']->dnExists($request['dn'])) - error(sprintf('%s (%s)',_('No such entry.'),$request['dn']),'error','index.php'); +if (! is_array($request['dn'])) + $request['dn'] = array($request['dn']); -printf('%s %s
',_('Deleting'),get_rdn($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('%s
',_('Delete LDAP entries')); printf('%s
',_('Recursive delete progress')); # Prevent script from bailing early on a long delete @set_time_limit(0); -echo '
'; -echo ''; -$result = pla_rdelete($app['server'],$request['dn']); -echo '
'; +foreach ($request['parent'] as $dn) { + echo '
'; + echo ''; + $result = pla_rdelete($app['server'],$dn); + echo '
'; -if ($result) { - printf(_('Entry %s and sub-tree deleted successfully.'),''.$request['dn'].''); + if ($result) { + printf(_('Entry %s and sub-tree deleted successfully.'),''.$dn.''); -} 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')); + } 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')); + } } function pla_rdelete($server,$dn) { diff --git a/lib/QueryRender.php b/lib/QueryRender.php index f2ab86f..7394af3 100644 --- a/lib/QueryRender.php +++ b/lib/QueryRender.php @@ -99,7 +99,6 @@ class QueryRender extends PageRender { echo ''; } - echo ''; printf(' %s ',_('The format to show the query results'),_('Display Format')); echo ''; echo '