Location: PHPKode > projects > ACollab > admin/user_delete.php
<?php
/****************************************************************************************/
/* ACollab                                                                              */
/****************************************************************************************/
/* Copyright (c) 2002-2004  Adaptive Technology Resource Centre / University of Toronto */
/*                                                                                      */
/* http://atutor.ca/acollab                                                             */
/*                                                                                      */
/* This program is free software. You may redistribute it and/or                        */
/* modify it under the terms of the GNU General Public License                          */
/* as published by the Free Software Foundation; either version 2 of the License,       */
/* or (at your option) any later version.                                               */
/*                                                                                      */
/* This program is distributed in the hope that it will be useful, but                  */
/* WITHOUT ANY WARRANTY; without even the implied warranty of                           */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                                 */
/* See the GNU General Public License for more details.                                 */
/*                                                                                      */
/* You may access the GNU General Public License at:                                    */
/* http://www.opensource.org/licenses/gpl-license.php                                   */
/*                                                                                      */
/* You may contact the Adaptive Technology Resource Centre at                           */
/* Robarts Library, University of Toronto                                               */
/* 130 St. George Street, Toronto, Ontario, Canada M5S 1A5                              */
/* Further contact information is available at http://www.utoronto.ca/atrc/             */
/****************************************************************************************/
/* Programmer:                                                                          */
/* Joel Kronenberg - ATRC                                                               */
/****************************************************************************************/
// $Id: user_delete.php 381 2005-02-09 21:31:28Z shozubq $

define('AC_INCLUDE_PATH', '../include/');

require(AC_INCLUDE_PATH.'vitals.inc.php');
authenticate(USER_ADMIN);

$_SECTION[0][0] = _AC('administration');
$_SECTION[0][1] = 'admin/';
$_SECTION[1][0] = _AC('user_management');
$_SECTION[1][1] = 'admin/users.php?'.urldecode($_GET['group']);
$_SECTION[2][0] = _AC('delete_member_account');
$_SECTION[2][1] = 'admin/user_delete.php';

$id = intval($_REQUEST['id']);
$reassign_id = intval($_REQUEST['reassign_id']);

if ($_POST['cancel']) {
	header('Location: users.php?'.$_REQUEST['group']);
	exit;
}

if (isset($_POST['submit'])) {
	/* contact_list		(delete all)*/
	/* events + events_files (reassign to the member_id doing the deleting ?) */
	$sql	= "SELECT event_id FROM ".TABLE_PREFIX."events WHERE member_id=$id";
	$result = mysql_query($sql, $db);
	while ($row = mysql_fetch_assoc($result)) {
		$sql = "DELETE FROM ".TABLE_PREFIX."events_files WHERE event_id=$row[event_id]";
		mysql_query($sql, $db);
	}
	$sql	= "DELETE FROM ".TABLE_PREFIX."events WHERE member_id=$id";
	$result	= mysql_query($sql, $db);

	/* files			(reassign..) */
	if ($reassign_id != 0) {
		$sql	= "SELECT file_id FROM ".TABLE_PREFIX."files WHERE member_id=$id AND folder_id<>0";
		$result	= mysql_query($sql, $db);
		while ($row = mysql_fetch_assoc($result)) {
			$sql = "UPDATE ".TABLE_PREFIX."files SET member_id=$reassign_id WHERE file_id=$row[file_id]";
			mysql_query($sql, $db);

			$sql = "UPDATE ".TABLE_PREFIX."files_revisions SET member_id=$reassign_id WHERE file_id=$row[file_id]";
			mysql_query($sql, $db);
		}

		$sql	= "UPDATE ".TABLE_PREFIX."folders SET member_id=$reassign_id WHERE member_id=$id";
		$result	= mysql_query($sql, $db);

		$sql = "DELETE FROM ".TABLE_PREFIX."revisions_comments WHERE member_id=$id";
		mysql_query($sql, $db);
	}
	
	/*only deletes personal files or all files belonging to user if user deleted was the last user*/
	/* delete personal files */
	$sql	= "SELECT R.revision_id FROM ".TABLE_PREFIX."files_revisions R, ".TABLE_PREFIX."files F WHERE F.file_id=R.file_id AND F.member_id=$id ORDER BY F.file_id";
	$result = mysql_query($sql, $db);
	while ($row = mysql_fetch_assoc($result)) {
		$char = substr($row['revision_id'], 0, 1).'/';
		@unlink(UPLOAD_DIR.$char.$row['revision_id']);

		$sql = "DELETE FROM ".TABLE_PREFIX."revisions_comments WHERE revision_id=$row[revision_id]";
		mysql_query($sql, $db);
	}

	/*Also Remove files and file revision from database !!*/
	$sql = "DELETE ".TABLE_PREFIX."files_revisions, ".TABLE_PREFIX."files
			FROM ".TABLE_PREFIX."files_revisions R, ".TABLE_PREFIX."files F
			WHERE F.file_id=R.file_id AND F.member_id=$id";
	mysql_query($sql, $db);


	/* groups_members	(delete all) */
	$sql	= "DELETE FROM ".TABLE_PREFIX."groups_members WHERE member_id=$id";
	$result	= mysql_query($sql, $db);

	/* members			(delete the one) */
	$sql	= "DELETE FROM ".TABLE_PREFIX."members WHERE member_id=$id";
	$result	= mysql_query($sql, $db);

	/* messages		(delete all to/from) */
	$sql	= "DELETE FROM ".TABLE_PREFIX."messages WHERE from_member_id=$id OR to_member_id=$id";
	$result	= mysql_query($sql, $db);

	/* these aren't changed:
	forums_threads
	forums */


	header('Location: users.php?f='.F_USER_DELETE);
	exit;
}

require(AC_INCLUDE_PATH.'admin/header.inc.php');


$sql	= "SELECT * FROM ".TABLE_PREFIX."members WHERE member_id=$id";
$result	= mysql_query($sql, $db);
if (!$row = mysql_fetch_assoc($result)) {
	$error = E_USER_NOT_FOUND;
	print_errors($error);
	require(AC_INCLUDE_PATH.'admin/footer.inc.php');	
	exit;
}

?>

<br />
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
	<input type="hidden" name="id" value="<?php echo $id; ?>" />
	<table border="0" cellspacing="0" cellpadding="2" align="center" class="box2">
	<tr>
		<th colspan="3" class="box"><h3><?php echo _AC('delete_member_account'); ?></h3></th>
	</tr>
	<tr bgcolor="white">
		<td>&nbsp;</td>
		<td><b><?php echo _AC('username'); ?>:</b> <?php echo $row['login']; ?></td>
		<td>&nbsp;</td>
	</tr>
	<tr>
		<td class="row1">&nbsp;</td>
		<td class="row1"><img src="images/clr.gif" alt="" height="1" width="1" /><br /><?php echo _AC('confirm_delete_member'); ?><br /></td>
		<td class="row1">&nbsp;</td>
	</tr>
	<tr>
		<td class="row1">&nbsp;</td>
		<td class="row1"><?php

			echo _AC('reassign_to');
			echo '<select name="reassign_id">';

			$sql	= "SELECT M.* FROM ".TABLE_PREFIX."members M WHERE M.member_id<>$id ORDER BY M.login";
			$result	= mysql_query($sql, $db);
			while ($row = mysql_fetch_assoc($result)) {
				echo '<option value="'.$row['member_id'].'"';
				if ($row['member_id'] == $_SESSION['member_id']) {
					echo ' selected="selected"';
				}
				echo '>'.$row['login'].'</option>';
			}
			echo '</select>';

		?><br /></td>
		<td class="row1">&nbsp;</td>
	</tr>

	<tr bgcolor="white">
		<td class="row1">&nbsp;</td>
		<td class="row1" align="right"><br /><input type="submit" name="submit" value="<?php echo _AC('delete'); ?>" class="submitY" onfocus="this.className='submitY highlight'" onblur="this.className='submitY'" /> &nbsp; <input type="submit" name="cancel" value="<?php echo _AC('cancel'); ?>" class="submitN" onfocus="this.className='submitN highlight'" onblur="this.className='submitN'" /><br /><br /></td>
		<td class="row1">&nbsp;</td>
	</tr>
	</table>
</form>

<?php
	require(AC_INCLUDE_PATH.'admin/footer.inc.php');
?>
Return current item: ACollab