<?

require "include/bittorrent.php";

dbconn ();

validcan ( false, 'can_admin' );
global $CURGROUP, $ALLGROUPS;
location ( "usersforbanned.php", 5 );
$userid = ( int ) $_POST ["id"];
$res = @mysql_fetch_array ( sql_query ( "SELECT avatar, `group` FROM users WHERE id=" . $userid ) );
if (! $res)
	$userid = 0;
$sum1 = summgroup ( $ALLGROUPS [$res ['group']] );
$sum2 = summgroup ( $CURGROUP );
global $ALLGROUPS, $avatar_dir, $DEFAULTBASEURL;
if (! $ALLGROUPS [$res ['group'] ['can_bedeleted']] || $sum2 <= $sum1)
	die ( 'Don`t delete this user!' );
if ($userid) {
	if (strpos ( " " . $res ["avatar"], $DEFAULTBASEURL . "/$avatar_dir/" ) && ! strpos ( " " . $row ["avatar"], "../" ))
		@unlink ( $arr ["avatar"] );
	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__ );
	stdhead ( "Выполнено!" );
	stdmsg ( "Успешно", "Вы успешно удалили пользователя", 'success' );
} else {
	stdhead ( "Ошибка!" );
	stdmsg ( "Ошибка", "Неправильный id пользователя", 'error' );
}
stdfoot ();

?>