phpldapadmin/htdocs/mass_delete.php

154 lines
4.3 KiB
PHP
Raw Normal View History

2009-06-30 08:09:20 +00:00
<?php
2009-06-30 09:40:37 +00:00
// $Header: /cvsroot/phpldapadmin/phpldapadmin/htdocs/mass_delete.php,v 1.13.2.1 2005/10/09 09:07:21 wurley Exp $
2009-06-30 09:22:30 +00:00
2009-06-30 09:29:51 +00:00
/**
2009-06-30 08:09:20 +00:00
* Enables user to mass delete multiple entries using checkboxes.
*
2009-06-30 09:29:51 +00:00
* Variables that come in via common.php
* - server_id
2009-06-30 08:09:20 +00:00
* 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.
2009-06-30 09:29:51 +00:00
*
* @package phpLDAPadmin
*/
/**
2009-06-30 08:09:20 +00:00
*/
2009-06-30 09:29:51 +00:00
require './common.php';
2009-06-30 08:09:20 +00:00
2009-06-30 09:29:51 +00:00
if( $ldapserver->isReadOnly() )
pla_error( $lang['no_deletes_in_read_only_mode'] );
if( ! $ldapserver->haveAuthInfo())
pla_error( $lang['not_enough_login_info'] );
2009-06-30 08:09:20 +00:00
$confirmed = isset( $_POST['confirmed'] ) ? true : false;
2009-06-30 09:29:51 +00:00
isset( $_POST['mass_delete'] ) or
2009-06-30 09:22:30 +00:00
pla_error( $lang['error_calling_mass_delete'] );
2009-06-30 08:09:20 +00:00
$mass_delete = $_POST['mass_delete'];
2009-06-30 09:29:51 +00:00
is_array( $mass_delete ) or
pla_error( $lang['mass_delete_not_array'] );
2009-06-30 08:09:20 +00:00
2009-06-30 09:29:51 +00:00
$ldapserver->isMassDeleteEnabled() or
pla_error( $lang['mass_delete_not_enabled'] );
2009-06-30 08:09:20 +00:00
2009-06-30 09:29:51 +00:00
require './header.php';
2009-06-30 08:09:20 +00:00
echo "<body>\n";
2009-06-30 09:22:30 +00:00
echo "<h3 class=\"title\">" . $lang['mass_deleting'] . "</h3>\n";
2009-06-30 08:09:20 +00:00
if( $confirmed == true ) {
2009-06-30 09:29:51 +00:00
echo "<h3 class=\"subtitle\">" . sprintf( $lang['mass_delete_progress'], $ldapserver->name ) . "</h3>\n";
echo "<blockquote>";
echo "<small>\n";
2009-06-30 08:09:20 +00:00
2009-06-30 09:29:51 +00:00
$successfully_delete_dns = array();
$failed_dns = array();
if( ! is_array( $mass_delete ) )
pla_error( $lang['malformed_mass_delete_array'] );
if( count( $mass_delete ) == 0 ) {
echo "<br />";
echo "<center>" . $lang['no_entries_to_delete'] . "</center>";
die();
}
foreach( $mass_delete as $dn => $junk ) {
echo sprintf( $lang['deleting_dn'], htmlspecialchars($dn) );
flush();
if( true === run_hook ( 'pre_entry_delete', array ( 'server_id' => $ldapserver->server_id, 'dn' => $dn ) ) ) {
$success = @ldap_delete( $ldapserver->connect(), $dn );
2009-06-30 08:09:20 +00:00
2009-06-30 09:29:51 +00:00
if( $success ) {
run_hook ( 'post_entry_delete', array ( 'server_id' => $ldapserver->server_id, 'dn' => $dn ) );
echo " <span style=\"color:green\">" . $lang['success'] . "</span>.<br />\n";
$successfully_delete_dns[] = $dn;
} else {
echo " <span style=\"color:red\">" . $lang['failed'] . "</span>.\n";
2009-06-30 09:40:37 +00:00
echo "(" . $ldapserver->error() . ")<br />\n";
2009-06-30 09:29:51 +00:00
$failed_dns[] = $dn;
}
2009-06-30 08:09:20 +00:00
}
2009-06-30 09:29:51 +00:00
flush();
}
echo "<blockquote>";
echo "</small>\n";
$failed_count = count( $failed_dns );
$total_count = count( $mass_delete );
if( $failed_count > 0 ) {
echo "<span style=\"color: red; font-weight: bold;\">\n";
echo sprintf( $lang['total_entries_failed'], $failed_count, $total_count ) . "</span>\n";
} else {
echo "<span style=\"color: green; font-weight: bold;\">\n";
echo $lang['all_entries_successful'] . "</span>\n";
}
2009-06-30 08:09:20 +00:00
// kill the deleted DNs from the tree browser session variable and
// refresh the tree viewer frame (left_frame)
2009-06-30 09:29:51 +00:00
if( array_key_exists( 'tree', $_SESSION ) ) {
2009-06-30 08:09:20 +00:00
$tree = $_SESSION['tree'];
2009-06-30 09:29:51 +00:00
2009-06-30 08:09:20 +00:00
foreach( $successfully_delete_dns as $dn ) {
2009-06-30 09:29:51 +00:00
// does it have children? (it shouldn't, but hey, you never know)
if( isset( $tree[$ldapserver->server_id][$dn] ) )
unset( $tree[$ldapserver->server_id][$dn] );
// search and destroy
foreach( $tree[$ldapserver->server_id] as $tree_dn => $subtree )
foreach( $subtree as $key => $sub_tree_dn )
if( 0 == strcasecmp( $sub_tree_dn, $dn ) )
unset( $tree[$ldapserver->server_id][$tree_dn][$key] );
2009-06-30 08:09:20 +00:00
}
2009-06-30 09:29:51 +00:00
2009-06-30 08:09:20 +00:00
$_SESSION['tree'] = $tree;
2009-06-30 09:29:51 +00:00
session_write_close(); ?>
2009-06-30 08:09:20 +00:00
<script language="javascript">
parent.left_frame.location.reload();
</script>
2009-06-30 09:29:51 +00:00
<?php }
2009-06-30 08:09:20 +00:00
} else {
$n = count( $mass_delete );
2009-06-30 09:29:51 +00:00
echo "<h3 class=\"subtitle\">" . sprintf( $lang['confirm_mass_delete'], $n, $ldapserver->name ) . "</h3>\n"; ?>
2009-06-30 08:09:20 +00:00
<center>
2009-06-30 09:29:51 +00:00
Do you really want to delete
2009-06-30 08:09:20 +00:00
<?php echo ($n==1?'this':'these') . ' ' . $n . ' ' . ($n==1?'entry':'entries'); ?>?
<form action="mass_delete.php" method="post">
<input type="hidden" name="confirmed" value="true" />
2009-06-30 09:29:51 +00:00
<input type="hidden" name="server_id" value="<?php echo $ldapserver->server_id; ?>" />
2009-06-30 08:09:20 +00:00
<table><tr><td>
<ol>
<?php foreach( $mass_delete as $dn => $foo ) {
echo "<input type=\"hidden\" name=\"mass_delete[" . htmlspecialchars($dn) . "]\" value=\"on\" />\n";
echo "<li>" . htmlspecialchars( $dn ) . "</li>\n";
} ?>
</ol>
</td></tr></table>
2009-06-30 09:22:30 +00:00
<input class="scary" type="submit" value=" <?php echo $lang['yes_delete']; ?> " /></center>
2009-06-30 08:09:20 +00:00
</form>
2009-06-30 09:29:51 +00:00
<?php }
2009-06-30 08:09:20 +00:00
?>