<?

require "include/bittorrent.php";
dbconn ();
global $DEFAULTBASEURL, $avatar_dir;
if ($_SERVER ["REQUEST_METHOD"] == "POST") {
	$username = trim ( $_POST ["username"] );
	$password = trim ( $_POST ["password"] );
	if (! $username || ! $password)
		stderr ( $tracker_lang ['error'], "Заполните форму корректно." );
	$res = sql_query ( "SELECT * FROM users WHERE username=" . sqlesc ( $username ) . " AND passhash=md5(concat(secret,concat(" . sqlesc ( $password ) . ",secret)))" ) or sqlerr ( __FILE__, __LINE__ );
	if (mysql_num_rows ( $res ) != 1)
		stderr ( $tracker_lang ['error'], "Неверное имя пользователя или пароль. Проверьте введеную информацию." );
	$arr = mysql_fetch_assoc ( $res );
	global $ALLGROUPS;
	if (! $ALLGROUPS [$arr ['group'] ['can_bedeleted']])
		die ( 'Don`t delete this user!' );
	$userid = $arr ['id'];
	if (strpos ( " " . $arr ["avatar"], $DEFAULTBASEURL . "/$avatar_dir/" ) && ! strpos ( " " . $arr ["avatar"], "../" ))
		@unlink ( $arr ["avatar"] );
	$res = sql_query ( "DELETE FROM users WHERE id = $id" ) or sqlerr ( __FILE__, __LINE__ );
	sql_query ( "DELETE FROM users WHERE id = $userid" ) or sqlerr ( __FILE__, __LINE__ );
	sql_query ( "DELETE FROM messages WHERE receiver = $userid" ) or sqlerr ( __FILE__, __LINE__ );
	sql_query ( "DELETE FROM friends WHERE userid = $userid" ) or sqlerr ( __FILE__, __LINE__ );
	sql_query ( "DELETE FROM friends WHERE friendid = $userid" ) or sqlerr ( __FILE__, __LINE__ );
	sql_query ( "DELETE FROM blocks WHERE userid = $userid" ) or sqlerr ( __FILE__, __LINE__ );
	sql_query ( "DELETE FROM blocks WHERE blockid = $userid" ) or sqlerr ( __FILE__, __LINE__ );
	sql_query ( "DELETE FROM bookmarks WHERE userid = $userid" ) or sqlerr ( __FILE__, __LINE__ );
	sql_query ( "DELETE FROM invites WHERE inviter = $userid" ) or sqlerr ( __FILE__, __LINE__ );
	sql_query ( "DELETE FROM peers WHERE userid = $userid" ) or sqlerr ( __FILE__, __LINE__ );
	sql_query ( "DELETE FROM simpaty WHERE fromuserid = $userid" ) or sqlerr ( __FILE__, __LINE__ );
	sql_query ( "DELETE FROM addedrequests WHERE userid = $userid" ) or sqlerr ( __FILE__, __LINE__ );
	sql_query ( "DELETE FROM checkcomm WHERE userid = $userid" ) or sqlerr ( __FILE__, __LINE__ );
	sql_query ( "DELETE FROM offervotes WHERE userid = $userid" ) or sqlerr ( __FILE__, __LINE__ );
	sql_query ( "DELETE FROM sessions WHERE uid = $userid" ) or sqlerr ( __FILE__, __LINE__ );
	if (mysql_affected_rows () != 1)
		stderr ( $tracker_lang ['error'], "Невозможно удалить аккаунт." );
	stderr ( $tracker_lang ['success'], "Аккаунт удален." );
}
stdhead ( "Удалить аккаунт" );
?>
<h1></h1>
<form method="post" action="delacct.php">
<table border="1" cellspacing="0" cellpadding="5">
	<tr>
		<td class="colhead" colspan="2">Удалить аккаунт</td>
	</tr>
	<tr>
		<td class="rowhead">Пользователь</td>
		<td><input size="40" name="username"></td>
	</tr>
	<tr>
		<td class="rowhead">Пароль</td>
		<td><input type="password" size="40" name="password"></td>
	</tr>
	<tr>
		<td colspan="2" align="center"><input type="submit" class="btn"
			value="Удалить"></td>
	</tr>
</table>
</form>
<?
stdfoot ();
?>