<?
include_once '../sys/inc/start.php';
include_once '../sys/inc/compress.php';
include_once '../sys/inc/sess.php';
include_once '../sys/inc/home.php';
include_once '../sys/inc/settings.php';
include_once 'vsys/inc/db_connect.php';
include_once '../sys/inc/ipua.php';
include_once '../sys/inc/fnc.php';
include_once '../sys/inc/user.php';
if (isset($_GET['id']))$user['id']=intval($_GET['id']);
else {header("Location: ../index.php?".SID);exit;}


if (mysql_result(mysql_query("SELECT COUNT(*) FROM `user` WHERE `id` = '$user[id]' LIMIT 1"),0)==0){header("Location: /index.php?".SID);exit;}
$user=mysql_fetch_array(mysql_query("SELECT * FROM `user` WHERE `id` = $user[id] LIMIT 1"));

$set['title']='Удаление пользователя "'.$user['nick'].'"';
include_once '../sys/inc/thead.php';
title();


if (isset($_POST['delete']))
{
$mass[0]=$user['id'];
$collisions=user_collision($mass,1);
mysql_query("DELETE FROM `user` WHERE `id` = '$user[id]'");
mysql_query("DELETE FROM `chat_post` WHERE `id_user` = '$user[id]'");
mysql_query("DELETE FROM `forum_t` WHERE `id_user` = '$user[id]'");

$q5=mysql_query("SELECT * FROM `forum_t` WHERE `id_user` = '$user[id]'");
while ($post5 = mysql_fetch_array($q5))
{
mysql_query("DELETE FROM `forum_p` WHERE `id_them` = '$post5[id]'");
}



mysql_query("DELETE FROM `forum_p` WHERE `id_user` = '$user[id]'");
mysql_query("DELETE FROM `forum_zakl` WHERE `id_user` = '$user[id]'");
mysql_query("DELETE FROM `guest` WHERE `id_user` = '$user[id]'");
mysql_query("DELETE FROM `loads_komm` WHERE `id_user` = '$user[id]'");
mysql_query("DELETE FROM `news_komm` WHERE `id_user` = '$user[id]'");


$opdirbase=@opendir(H.'sys/add/delete_user_act');
while ($filebase=@readdir($opdirbase))
if (eregi('\.php$',$filebase))
include_once(H.'sys/add/delete_user_act/'.$filebase);

$q5=mysql_query("SELECT * FROM `obmennik_files` WHERE `id_user` = '$user[id]'");
while ($post5 = mysql_fetch_array($q5))
{
unlink(H.'sys/obmen/files/'.$post5['id'].'.dat');
}


mysql_query("DELETE FROM `obmennik_files` WHERE `id_user` = '$user[id]'");

mysql_query("DELETE FROM `konts` WHERE `id_user` = '$ank[id]' OR `id_kont` = '$user[id]'");
mysql_query("DELETE FROM `frends` WHERE `id_user` = '$ank[id]' OR `id_frends` = '$user[id]'");
mysql_query("DELETE FROM `mail` WHERE `id_user` = '$ank[id]' OR `id_kont` = '$user[id]'");
mysql_query("DELETE FROM `user_voice` WHERE `id_user` = '$ank[id]' OR `id_kont` = '$user[id]'");
mysql_query("DELETE FROM `user_collision` WHERE `id_user` = '$ank[id]' OR `id_user2` = '$user[id]'");
mysql_query("DELETE FROM `votes_user` WHERE `u_id` = '$user[id]'");


if (count($collisions)>1 && isset($_GET['all']))
{
for ($i=1;$i<count($collisions);$i++)
{
mysql_query("DELETE FROM `user` WHERE `id` = '$collisions[$i]'");
mysql_query("DELETE FROM `chat_post` WHERE `id_user` = '$collisions[$i]'");


mysql_query("DELETE FROM `forum_t` WHERE `id_user` = '$collisions[$i]'");


$q5=mysql_query("SELECT * FROM `forum_t` WHERE `id_user` = '$collisions[$i]'");
while ($post5 = mysql_fetch_array($q5))
{
mysql_query("DELETE FROM `forum_p` WHERE `id_them` = '$post5[id]'");
}

mysql_query("DELETE FROM `forum_p` WHERE `id_user` = '$collisions[$i]'");
mysql_query("DELETE FROM `forum_zakl` WHERE `id_user` = '$collisions[$i]'");
mysql_query("DELETE FROM `guest` WHERE `id_user` = '$collisions[$i]'");
mysql_query("DELETE FROM `loads_komm` WHERE `id_user` = '$collisions[$i]'");
mysql_query("DELETE FROM `news_komm` WHERE `id_user` = '$collisions[$i]'");


$q5=mysql_query("SELECT * FROM `obmennik_files` WHERE `id_user` = '$collisions[$i]'");
while ($post5 = mysql_fetch_array($q5))
{
unlink(H.'sys/obmen/files/'.$post5['id'].'.dat');
}
mysql_query("DELETE FROM `obmennik_files` WHERE `id_user` = '$collisions[$i]'");

mysql_query("DELETE FROM `konts` WHERE `id_user` = '$collisions[$i]' OR `id_kont` = '$collisions[$i]'");
mysql_query("DELETE FROM `frends` WHERE `id_user` = '$collisions[$i]' OR `id_frends` = '$collisions[$i]'");
mysql_query("DELETE FROM `mail` WHERE `id_user` = '$collisions[$i]' OR `id_kont` = '$collisions[$i]'");
mysql_query("DELETE FROM `user_voice` WHERE `id_user` = '$collisions[$i]' OR `id_kont` = '$collisions[$i]'");
mysql_query("DELETE FROM `user_collision` WHERE `id_user` = '$collisions[$i]' OR `id_user2` = '$collisions[$i]'");
mysql_query("DELETE FROM `votes_user` WHERE `u_id` = '$collisions[$i]'");
}
header("Location: /index.php?".SID);exit;
}
else 
header("Location: /index.php?".SID);exit;


$tab=mysql_list_tables($set['mysql_db_name']);
for($i=0;$i<mysql_num_rows($tab);$i++)
{
mysql_query("OPTIMIZE TABLE `".mysql_tablename($tab,$i)."`");
}

echo "<div class='foot'>\n";
echo "&laquo;<a href='/users.php'>Пользователи</a><br />\n";
echo "</div>\n";
include_once '../sys/inc/tfoot.php';
}

echo "Вы уверены, что хотите полностью удалить свой аккаунт?<br />Удаленные данные невозможно будет восстановить!<br />\n";

echo "<form method=\"post\" action=\"\">\n";
echo "<input value=\"Удалить\" type=\"submit\" name='delete' />\n";
echo "</form>\n";

echo "<a href='../settings.php'><b>Назад</b></a> \n";

include_once '../sys/inc/tfoot.php';
?>