<?
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();
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('dost\.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 `jurnal` (`id_user`, `id_kont`, `msg`, `time`) values('0', '$ank[id]', 'Обитатель [red][b]$user[nick][/b][/red] поднял Вам рейтинг!!! | [url=/who_rating.php]История рейтинга[/url]', '$time')");
if ($new_r<0)
mysql_query("INSERT INTO `jurnal` (`id_user`, `id_kont`, `msg`, `time`) values('0', '$ank[id]', 'Обитатель [red][b]$user[nick][/b][/red] ПОНИЗИЛ ВАМ рейтинг!!! | [url=/who_rating.php]История рейтинга[/url]', '$time')");
if ($new_r==0)
mysql_query("INSERT INTO `jurnal` (`id_user`, `id_kont`, `msg`, `time`) values('0', '$ank[id]', 'У Обитателя [red][b]$user[nick][/b][/red] к Вам нейтральное отношение! [url=/who_rating.php]История рейтинга[/url]', '$time')");

msg('Вы успешно проголосовали за Обитателя');
}

echo "<div class='p_t'>";
echo "<img src='/style/back.gif' alt='' class='icon'/>\n";
echo "<a href='prof.php?id=$ank[id]'>Анкета ($ank[nick])</a><br />\n";
echo "</div>\n";
if (isset($user) & $user['balls']<=50)
{
if ($user['pol']==0){echo "Извини <b>красавица,</b> \n";} else {echo "<b>Извини братан,</b> \n";}
echo "Вы не сможете голосовать за обитателей пока не наберете <b>50</b> баллов LM<br/>Набрать баллы можно общаясь в беседке, чате, форуме, комментируя фотографии<br/>У вас <b>$user[balls]</b> баллов LM\n";
}
else
{
echo "<center>";
echo "<img src='/img/add_fav.gif' alt='' class='icon'/>\n";
echo " <a href='/top/rating.php'><font color='#f66782'>Т</font><font color='#67a82d'>оп</font> <font color='#2da1a8'>поп</font>ул<font color='#7e9aeb'>яр</font>но<font color='#cb7eeb'>сти</font></a><br />";
echo "<div class='menu_razd'>";
echo "Голосовать за одного обитателя можно 1 раз!<br/>Вы в любое время сможете изменить свой голос";
echo "</div>\n";
avatar($ank['id']);

//////////////вставка данных автопортрета

echo "<div class='aut'><center>\n";
echo "<img src='/style/icons/stat14.png' alt='' class='icon'/>\n";
echo "Рейтинг $ank[nick] $ank[rating] % ";
if($ank['rating']>=100 && $ank['rating']<=200)echo " <img src='/stars/rank1.gif'></img><br />"; 
if($ank['rating']>=201 && $ank['rating']<=300)echo " <img src='/stars/rank2.gif'></img><br />";
if($ank['rating']>=301 && $ank['rating']<=400)echo " <img src='/stars/rank3.gif'></img><br />";
if($ank['rating']>=401 && $ank['rating']<=500)echo " <img src='/stars/rank4.gif'></img><br />";
if($ank['rating']>=501 && $ank['rating']<=600)echo " <img src='/stars/rank5.gif'></img><br />";
if($ank['rating']>=601 && $ank['rating']<=700)echo " <img src='/stars/rank6.gif'></img><br />";
if($ank['rating']>=701 && $ank['rating']<=800)echo " <img src='/stars/rank7.gif'></img><br />";
if($ank['rating']>=801 && $ank['rating']<=900)echo " <img src='/stars/rank8.gif'></img><br />";
if($ank['rating']>=901 && $ank['rating']<=1000)echo " <img src='/stars/rank9.gif'></img><br />";
if($ank['rating']>=1001 && $ank['rating']<=10000)echo " <img src='/stars/rank10.gif'></img><br />";
echo "</center></div>\n";

if (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)
{

echo "<b>Голосовать за Обитателя:</b><br />\n";
// мое отношение к пользователю
$my_r=intval(@mysql_result(mysql_query("SELECT `rating` FROM `user_voice2` WHERE `id_user` = '$user[id]' AND `id_kont` = '$ank[id]'"),0));

echo "<form method='post' action='?id=$ank[id]&amp;$passgen'>\n";


echo "<select name='rating'>\n";
//echo "<option value='2' ".($my_r==2?'selected="selected"':null).">+ 2</option>\n";
echo "<option value='1' ".($my_r==1?'selected="selected"':null).">+ 1</option>\n";
echo "<option value='0' ".($my_r==0?'selected="selected"':null).">0</option>\n";
echo "<option value='-1' ".($my_r==-1?'selected="selected"':null).">- 1</option>\n";
//echo "<option value='-2' ".($my_r==-2?'selected="selected"':null).">- 2</option>\n";
echo "</select><br/>\n";
echo "<input type='submit' value='Отдать голос' />\n";
echo "</form>\n";
echo "</center>";


}
}
echo "<div class='p_t'>";
echo "<img src='/style/back.gif' alt='' class='icon'/>\n";
echo "<a href='info.php?id=$ank[id]'>Страничка ($ank[nick])</a><br />\n";
echo "</div>\n";
//////////////конец вставки
include_once 'sys/inc/tfoot.php';
?>