<?
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 'sys/inc/db_connect.php';
include_once 'sys/inc/ipua.php';
include_once 'sys/inc/fnc.php';
include_once 'sys/inc/user.php';


if (isset($user))$ank['id']=$user['id'];
if (isset($_GET['id']))$ank['id']=intval($_GET['id']);


if ($ank['id']==0)
{
$ank=get_user($ank['id']);
$set['title']=$ank['nick'].' - анкета '; // заголовок страницы
include_once 'sys/inc/thead.php';
title();
aut();
echo "<span class=\"status\">$ank[group_name]</span><br />\n";

if ($ank['ank_o_sebe']!=NULL)echo "<span class=\"ank_n\">О себе:</span> <span class=\"ank_d\">$ank[ank_o_sebe]</span><br />\n";




if(isset($_SESSION['refer']) && $_SESSION['refer']!=NULL && otkuda($_SESSION['refer']))
echo "<div class='foot'>&laquo;<a href='$_SESSION[refer]'>".otkuda($_SESSION['refer'])."</a><br />\n</div>\n";

include_once 'sys/inc/tfoot.php';
exit;
}

$ank=get_user($ank['id']);
if(!$ank){header("Location: /index.php?".SID);exit;}








$ank['rating']=intval(@mysql_result(mysql_query("SELECT SUM(`rating`) FROM `user_voice2` WHERE `id_kont` = '$ank[id]'"),0));
$set['title']=$ank['nick'].' - анкета '; // заголовок страницы
include_once 'sys/inc/thead.php';
title();


if ((!isset($_SESSION['refer']) || $_SESSION['refer']==NULL)
&& isset($_SERVER['HTTP_REFERER']) && $_SERVER['HTTP_REFERER']!=NULL &&
!ereg('info\.php',$_SERVER['HTTP_REFERER']))
$_SESSION['refer']=str_replace('&','&amp;',ereg_replace('^http://[^/]*/','/', $_SERVER['HTTP_REFERER']));


if (isset($_POST['rating']) && isset($user)  && $user['id']!=$ank['id'] && $user['balls']>=50 && mysql_result(mysql_query("SELECT SUM(`rating`) FROM `user_voice2` WHERE `id_kont` = '$user[id]'"),0)>=0)
{
$new_r=min(max(@intval($_POST['rating']),-2),2);
mysql_query("DELETE FROM `user_voice2` WHERE `id_user` = '$user[id]' AND `id_kont` = '$ank[id]' LIMIT 1");

if ($new_r)
mysql_query("INSERT INTO `user_voice2` (`rating`, `id_user`, `id_kont`) VALUES ('$new_r','$user[id]','$ank[id]')");
$ank['rating']=intval(mysql_result(mysql_query("SELECT SUM(`rating`) FROM `user_voice2` WHERE `id_kont` = '$ank[id]'"),0));
mysql_query("UPDATE `user` SET `rating` = '$ank[rating]' WHERE `id` = '$ank[id]' LIMIT 1");

if ($new_r>0)
mysql_query("INSERT INTO `mail` (`id_user`, `id_kont`, `msg`, `time`) values('0', '$ank[id]', '$user[nick] оставил положительный отзыв в [url=/who_rating.php]Вашей анкете[/url]', '$time')");
if ($new_r<0)
mysql_query("INSERT INTO `mail` (`id_user`, `id_kont`, `msg`, `time`) values('0', '$ank[id]', '$user[nick] оставил негативный отзыв в [url=/who_rating.php]Вашей анкете[/url]', '$time')");
if ($new_r==0)
mysql_query("INSERT INTO `mail` (`id_user`, `id_kont`, `msg`, `time`) values('0', '$ank[id]', '$user[nick] оставил нейтральный отзыв в [url=/who_rating.php]Вашей анкете[/url]', '$time')");



msg('Ваше мнение о пользователе успешно изменено');
}
aut();



echo "<div class='rowup'>";
if ($ank['group_access']>1)echo "<span class='status'>$ank[group_name]</span><br />\n";


avatar($ank['id']);

echo "<br><span class='ank_n'>ID:</span> <span class='ank_d'>$ank[id]</span><br />\n";

if (mysql_result(mysql_query("SELECT COUNT(*) FROM `ban` WHERE `id_user` = '$ank[id]' AND `time` > '$time'"), 0)!=0)
{
$q=mysql_query("SELECT * FROM `ban` WHERE `id_user` = '$ank[id]' AND `time` > '$time' ORDER BY `time` DESC LIMIT 5");
while ($post = mysql_fetch_assoc($q))
{
echo "<span class='ank_n'>Забанен до ".vremja($post['time']).":</span>\n";
echo "<span class='ank_d'>".output_text($post['prich'])."</span><br />\n";
}
}
else
{
$narush=mysql_result(mysql_query("SELECT COUNT(*) FROM `ban` WHERE `id_user` = '$ank[id]'"), 0);
echo "<span class='ank_n'>Нарушений:</span>".(($narush==0)?" <span class='ank_d'>нет</span><br />\n":" <span class=\"ank_d\">$narush</span><br />\n");
}






$chat_post=mysql_result(mysql_query("SELECT COUNT(*) FROM `chat_post` WHERE `id_user` = '$ank[id]'"),0);
echo "<span class=\"ank_n\">Сообщений в чате:</span> <span class=\"ank_d\">$chat_post</span><br />\n";

$k_them=mysql_result(mysql_query("SELECT COUNT(*) FROM `forum_t` WHERE `id_user` = '$ank[id]'"),0);
echo "<span class=\"ank_n\">Тем в форуме:</span> <span class=\"ank_d\">$k_them</span><br />\n";

$k_p_forum=mysql_result(mysql_query("SELECT COUNT(*) FROM `forum_p` WHERE `id_user` = '$ank[id]'"),0);
echo "<span class=\"ank_n\">Сообщений в форуме:</span> <span class=\"ank_d\">$k_p_forum</span><br />\n";



if (user_access('user_show_add_info') && $user['level']>$ank['level']){
$zakl3=mysql_result(mysql_query("SELECT COUNT(*) FROM `forum_zakl` WHERE `id_user` = '$ank[id]'"),0);
if (isset($user) && ($user['level']>$ank['level'] || $user['level']==4))
echo "<span class=\"ank_n\">Закладки:</span> <span class=\"ank_d\">$zakl3</span><br />\n";

$guest3=mysql_result(mysql_query("SELECT COUNT(*) FROM `guest` WHERE `id_user` = '$ank[id]'"),0);
echo "<span class=\"ank_n\">Гостевая:</span> <span class=\"ank_d\">$guest3</span><br />\n";


$mail3=mysql_result(mysql_query("SELECT COUNT(*) FROM `mail` WHERE `id_user` = '$ank[id]' OR `id_kont` = '$ank[id]'"),0);
if (isset($user) && ($user['level']>$ank['level'] || $user['level']==4))
echo "<span class=\"ank_n\">Приватные сообщения:</span> <span class=\"ank_d\">$mail3</span><br />\n";
}
$komm_loads=mysql_result(mysql_query("SELECT COUNT(*) FROM `loads_komm` WHERE `id_user` = '$ank[id]'"),0);
echo "<span class=\"ank_n\">Комментарии в загрузках:</span> <span class=\"ank_d\">$komm_loads</span><br />\n";

$news_komm=mysql_result(mysql_query("SELECT COUNT(*) FROM `news_komm` WHERE `id_user` = '$ank[id]'"),0);
echo "<span class=\"ank_n\">Комментарии новостей:</span> <span class=\"ank_d\">$news_komm</span><br />\n";


if (isset($access['show_all_info'])){
$user_voice=mysql_result(mysql_query("SELECT COUNT(*) FROM `user_voice2` WHERE `id_user` = '$ank[id]' OR `id_kont` = '$ank[id]'"),0);
if (isset($user) && ($user['level']>$ank['level'] || $user['level']==4))
echo "<span class=\"ank_n\">Рейтинги:</span> <span class=\"ank_d\">$user_voice</span><br />\n";

$votes_user=mysql_result(mysql_query("SELECT COUNT(*) FROM `votes_user` WHERE `u_id` = '$ank[id]'"),0);
if (isset($user) && ($user['level']>$ank['level'] || $user['level']==4))
echo "<span class=\"ank_n\">Голосования:</span> <span class=\"ank_d\">$votes_user</span><br />\n";

$obmennik3=mysql_result(mysql_query("SELECT COUNT(*) FROM `obmennik_files` WHERE `id_user` = '$ank[id]'"),0);
if (isset($user) && ($user['level']>$ank['level'] || $user['level']==4))
echo "<span class=\"ank_n\">Файлы в обменнике:</span> <span class=\"ank_d\">$obmennik3</span><br />\n";
}

echo "<span class=\"ank_n\">Баллы:</span> <span class=\"ank_d\">$ank[balls]</span><br />\n";

echo "<span class=\"ank_n\">Рейтинг:</span> <span class=\"ank_d\">$ank[rating]</span>".($ank['id']==$user['id']?" <a href='/who_rating.php'>[?]</a>":null)."<br />\n";
echo "Вернуться к <a href='/info.php?id=$ank[id]'>$ank[nick]</a>\n";


echo "</div>\n";
include_once 'sys/inc/tfoot.php';
?>