<?

//--------------------------гости-----------------------//
if(isset($user) && $user['id']!=$ank['id'])
{
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `my_guests` WHERE `id_ank` = '$ank[id]' AND `id_user`='$user[id]' LIMIT 1"),0)==0)
{
mysql_query("INSERT INTO `my_guests` (`id_ank`, `id_user`, `time`) VALUES ('$ank[id]', '$user[id]', '$time')");
}
else
{
$guest=mysql_fetch_array(mysql_query("SELECT * FROM `my_guests` WHERE `id_ank` = '$ank[id]' AND `id_user`='$user[id]' LIMIT 1"));
mysql_query("UPDATE `my_guests` SET `count` = '".($guest['count']+1)."', `time`='$time' WHERE `id` = '$guest[id]' LIMIT 1");
}
}
//------------------------------------------------------//




//-------------------------стена------------------------//
if (isset($_GET['wall']) && $_GET['wall']==1){
mysql_query("UPDATE `user` SET `wall` = '1' WHERE `id` = '$user[id]'");
header("Location: /info.php?id=$ank[id]");
}
elseif (isset($_GET['wall']) && $_GET['wall']==0){
mysql_query("UPDATE `user` SET `wall` = '0' WHERE `id` = '$user[id]'");
header("Location: /info.php?id=$ank[id]");
}


if (isset($_POST['msg']) && isset($user))
{
$msg=$_POST['msg'];
if (isset($_POST['translit']) && $_POST['translit']==1)$msg=translit($msg);
$mat=antimat($msg);
if ($mat)$err[]='В тексте сообщения обнаружен мат: '.$mat;
if (strlen2($msg)>1024){$err[]='Сообщение слишком длинное';}
elseif (strlen2($msg)<2){$err[]='Короткое сообщение';}
elseif (mysql_result(mysql_query("SELECT COUNT(*) FROM `stena` WHERE `id_user` = '$user[id]' AND  `id_stena` = '$ank[id]' AND `msg` = '".my_esc($msg)."' LIMIT 1"),0)!=0)
{$err='Ваше сообщение повторяет предыдущее';}
elseif(!isset($err)){

//-------------------уведомления---------------------//
if ($respons==TRUE){
if ($ank_otv['id']==$ank['id'])
$msgenta="$user[nick], ответил вам на [url=/info.php?id=$ank[id]&wall=0]вашей стене[/url]";
else
if ($ank_otv['id']==$user['id'])
$msgenta="$user[nick], ответил вам на [url=/info.php?id=$ank[id]&wall=0]своей стене[/url]";
else
$msgenta="$user[nick], ответил вам на [url=/info.php?id=$ank[id]&wall=0]стене $ank[nick][/url]";
mysql_query("INSERT INTO `mail` (`id_user`, `id_kont`, `msg`, `time`) values('0', '$ank_otv[id]', '$msgenta', '$time')"); 
}

if (isset($user) && $ank['id']!=$user['id'] && $respons==false){
$msgenta="$user[nick], оставил комментарий на [url=/info.php?id=$ank[id]&wall=0]вашей стене[/url]";
mysql_query("INSERT INTO `mail` (`id_user`, `id_kont`, `msg`, `time`) values('0', '$ank[id]', '$msgenta', '$time')"); 
}
//-------------------alex-borisi---------------------//
mysql_query("INSERT INTO `stena` (id_user, time, msg, id_stena) values('$user[id]', '$time', '".my_esc($msg)."', '$ank[id]')");
mysql_query("UPDATE `user` SET `balls` = '".($user['balls']+1)."' WHERE `id` = '$user[id]' LIMIT 1");
msg('Сообщение успешно добавлено');
}
}

//-----------------------------------------------------//

if ((!isset($_SESSION['refer']) || $_SESSION['refer']==NULL)
&& isset($_SERVER['HTTP_REFERER']) && $_SERVER['HTTP_REFERER']!=NULL &&
!preg_match('#info\.php#',$_SERVER['HTTP_REFERER']))
$_SESSION['refer']=str_replace('&','&amp;',preg_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('Ваше мнение о пользователе успешно изменено');
}


//-------------статус запись-----------//
if (isset($_POST['status']) && isset($user))
{
$msg=$_POST['status'];
if (isset($_POST['translit']) && $_POST['translit']==1)$msg=translit($msg);
$mat=antimat($msg);
if ($mat)$err[]='В тексте статуса обнаружен мат: '.$mat;
if (strlen2($msg)>512){$err='Слишком длинный статус';}
elseif (strlen2($msg)<2){$err='Короткий статус';}
elseif (mysql_result(mysql_query("SELECT COUNT(*) FROM `status` WHERE `id_user` = '$user[id]' AND `msg` = '".my_esc($msg)."' LIMIT 1"),0)!=0){$err='Ваш статус повторяет предыдущий';}
elseif(!isset($err)){
if (mysql_result(mysql_query("SELECT COUNT(*) FROM `status` WHERE `id_user` = '$user[id]' LIMIT 1"),0)==0)
mysql_query("INSERT INTO `status` (`id_user`, `msg`) values('$user[id]', '".my_esc($msg)."')");
else
mysql_query("UPDATE `status` SET `msg` = '".my_esc($msg)."' WHERE `id_user` = '$user[id]'");
$status=mysql_fetch_assoc(mysql_query("SELECT * FROM `status` WHERE `id_user` = '$ank[id]' LIMIT 1"));
mysql_query("DELETE FROM `status_like` WHERE `id_status` = '$status[id]'");

$q = mysql_query("SELECT * FROM `frends` WHERE `user` = '$user[id]' AND `i` = '1'");
while ($f = mysql_fetch_array($q))
{
$a = mysql_fetch_array(mysql_query("SELECT * FROM `user` WHERE `id` = '$f[frend]' LIMIT 1"));
mysql_query("INSERT INTO `tape` (`id_user`, `avtor`, `type`, `time`, `id_sim`) values ('$a[id]', '$user[id]', 'status', '$time', '$status[id]')");
}

msg('Статус успешно изменен');
} 
}
//-------------------------------------//
$status=mysql_fetch_assoc(mysql_query("SELECT * FROM `status` WHERE `id_user` = '$ank[id]' LIMIT 1"));

//-------------------статус like------------------------//
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `status_like` WHERE `id_user` = '$user[id]' AND `id_status`='$status[id]' LIMIT 1"),0)==0 && isset($_GET['like']) && $user['id']!=$ank['id'])
{
mysql_query("INSERT INTO `status_like` (`id_user`, `id_status`, `like`) VALUES ('$user[id]', '$status[id]', '".intval($_GET['like'])."')");
mysql_query("UPDATE `user` SET `balls` = '".($ank['balls']+5)."' WHERE `id` = '$ank[id]' LIMIT 1");
}
//------------------------------------------------------//



//----------------------в друзья---------------------//
$frend_new=mysql_result(mysql_query("SELECT COUNT(*) FROM `frends_new` WHERE (`user` = '$user[id]' AND `to` = '$ank[id]') OR (`user` = '$ank[id]' AND `to` = '$user[id]') LIMIT 1"),0);
$frend=mysql_result(mysql_query("SELECT COUNT(*) FROM `frends` WHERE (`user` = '$user[id]' AND `frend` = '$ank[id]') OR (`user` = '$ank[id]' AND `frend` = '$user[id]') LIMIT 1"),0);
$not_user=mysql_result(mysql_query("SELECT COUNT(*) FROM `user` WHERE `id` = '$ank[id]' LIMIT 1"),0)==0;

if ($user['id']!=$ank['id']){
if (isset($_GET['fok'])){
echo '<center>';
echo "<div class='foot'><form action='/info.php?id=".$ank['id']."' method=\"post\">";
echo "<input class=\"submit\" type=\"submit\" value=\"Закрыть\" />\n";
echo "</form></div>";
echo '</center>';
}
}
if (isset($_GET['frends'])  && $frend_new==0 && $frend==0 ){
if ($user['id']!=$ank['id']){
echo '<center>';
echo "<div class='err'>Пользователь должен будет подтвердить, что вы друзья.</div><div class='foot'><form action='/user/frends/create.php?add=".$ank['id']."' method=\"post\">";
echo "<input class=\"submit\" type=\"submit\" value=\"Пригласить\" />\n";
echo " <a href='/info.php?id=$ank[id]'>Отмена</a><br />\n";
echo "</form></div>";
echo '</center>';
}
}
//-------------------------------------------------------------//


//-------------статус форма------------//
if (isset($_GET['status'])){
if (isset($user) && $user['id']==$ank['id']){
echo '<div class="status">Статус [512 символов]<br />';
echo "<form action='/info.php?id=".$ank['id']."' method=\"post\">";
echo "<textarea type=\"text\" style='' name=\"status\" value=\"\"/>$status[msg]</textarea> \n";
echo "<input class=\"submit\" style='' type=\"submit\" value=\"Сохранить\" />\n";
echo "</form>";
echo "</div>";
echo '<div class="foot"><a href="info.php">Назад</a></div>';
include_once 'sys/inc/tfoot.php';
}
}
//-------------------------------------//



if ($ank['group_access']>1)echo "<div class='err'>$ank[group_name]</div>\n";
echo "<div class='main2'>";
echo " ".group($ank['id'])." $ank[nick]";
echo " ".medal($ank['id'])." ".online($ank['id'])."<br />";
echo "</div>";


echo "<div class='main'>";
avatar_ank($ank['id']);
echo "<br />";


if (isset($_GET['like']) && $user['id']!=$ank['id'] && mysql_result(mysql_query("SELECT COUNT(*) FROM `status_like` WHERE `id_status` = '$status[id]' AND `id_user` = '$user[id]' LIMIT 1"),0)==0){
mysql_query("INSERT INTO `status_like` (`id_user`, `id_status`) values('$user[id]', '$status[id]')");
}
if ($status['msg'])
{
echo "".output_text($status['msg'])."";
if ($ank['id']==$user['id'])echo " [<a href='?id=$ank[id]&status'><img src='/style/icons/edit.gif' alt='*'> ред</a>]";
}
else if ($ank['id']==$user['id'])
{
echo "Ваш статус [<a href='?id=$ank[id]&status'><img src='/style/icons/edit.gif' alt='*'> ред</a>]";
}
if (isset($status['msg']) && $user['id']!=$ank['id'] && mysql_result(mysql_query("SELECT COUNT(*) FROM `status_like` WHERE `id_user` = '$user[id]' AND `id_status`='$status[id]' LIMIT 1"),0)==0)
echo "<br />[<img src='/style/icons/like.gif' alt='*' /> <a href='/info.php?id=$ank[id]&amp;like=1'> Мне нравится</a>] [<img src='/style/icons/dlike.gif' alt='*' /> <a href='/info.php?id=$ank[id]&amp;like=0'></a>] ";
else if (isset($status['msg']))
echo "<br />[<img src='/style/icons/like.gif' alt='*' /> ".mysql_result(mysql_query("SELECT COUNT(*) FROM `status_like` WHERE `id_status`='$status[id]' AND `like` = '1'"),0)."] [<img src='/style/icons/dlike.gif' alt='*' /> ".mysql_result(mysql_query("SELECT COUNT(*) FROM `status_like` WHERE `id_status`='$status[id]' AND `like` = '0'"),0)."] ";

echo "</div>";


//-----------------анкета---------------------//
echo "<div class='main2'>";
echo "<img src='/style/icons/anketa.gif' alt='*' /> <a href='/user/info/anketa.php?id=$ank[id]'>Анкета</a> ";
if (isset($user) && $user['id']==$ank['id']){
echo "[<img src='/style/icons/edit.gif' alt='*' /> <a href='/user/info/edit.php'>ред</a>]";
}
echo "</div>";
//-------------------------------------------//

//--------------------------гости-----------------------------//
if (isset($user) && $user['id']==$ank['id']){
echo "<div class='main'>";
$new_g=mysql_result(mysql_query("SELECT COUNT(*) FROM `my_guests` WHERE `id_ank` = '$user[id]' AND `read`='1'"),0);
echo "<img src='/style/icons/guests.gif' alt='*' /> ";
if($new_g!=0)
{
$color = "<font color='red'>";
$color2 = "</font>";
}
else
{
$color = null;
$color2 = null;
}
echo "<a href='/user/myguest/index.php'>".$color."Гости".$color2."</a> \n";
if($new_g!=0)echo "<font color=\"red\">+$new_g</font>\n";
echo "</div>";
echo "<div class='main'>";
/*-----------------лента-----------------*/
if ($user['id']==$ank['id'])
{
$k_l=mysql_result(mysql_query("SELECT COUNT(*) FROM `tape` WHERE `id_user` = '$user[id]'  AND  `read` = '0'"),0);
if($k_l!=0)
{
$color = "<font color='red'>";
$color2 = "</font>";
}
else
{
$color = null;$color2 = null;
}
echo "<img src='/style/icons/lenta.gif' alt='*' /> <a href='/user/tape/'>".$color."Лента".$color2."</a> \n";
if($k_l!=0)echo "<font color=\"red\">+$k_l</font>\n";
echo "<br />";
}
/*---------------------------------------*/
echo "</div>";
}
//-----------------------------------------------------------//



//-----------------------------друзья-------------------------------//
$k_f = mysql_result(mysql_query("SELECT COUNT(id) FROM `frends_new` WHERE `to` = '$ank[id]' LIMIT 1"), 0);
$k_fr = mysql_result(mysql_query("SELECT COUNT(*) FROM `frends` WHERE `user` = '$ank[id]' AND `i` = '1'"), 0);
$res = mysql_query("select `frend` from `frends` WHERE `user` = '$ank[id]' AND `i` = '1'");
echo "<div class='main'>";
echo "<img src='/style/icons/druzya.png' alt='*' /> ";
echo '<a href="/user/frends/?id='.$ank['id'].'">Друзья</a> ('.$k_fr.'</b>/';$i =0;
while ($k_fr = mysql_fetch_array($res)){
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `user` WHERE `id` = '$k_fr[frend]' && `date_last` > '".(time()-600)."'"),0) != 0) $i++;
}
echo "<span style='color:green'><a href='/user/frends/online.php?id=".$ank['id']."'>$i</a></span>)";
if ($k_f>0 && $ank['id']==$user['id'])echo " <a href='/user/frends/new.php'><font color='red'>+$k_f</font></a>";
echo "</div>";
//------------------------------------------------------------------//






//--------------------------фотоальбомы-----------------------------//
echo "<div class='main2'>";
echo "<img src='/style/icons/foto.png' alt='*' /> ";
echo "<a href='/foto/$ank[id]/'>Фотографии</a> ";
echo "(" . mysql_result(mysql_query("SELECT COUNT(*) FROM `gallery_foto` WHERE `id_user` = '$ank[id]'"),0) . ")";
echo "</div>";
//------------------------------------------------------------------//



//----------------------------заметки-------------------------------//
echo "<div class='main'>";
$kol_dnev=mysql_result(mysql_query("SELECT COUNT(*) FROM `blog_list` WHERE `id_user` = '".$ank['id']."'"),0);
echo "<img src='/style/icons/zametki.gif' alt='*' /> ";
echo "<a href='/user/notes/user.php?id=$ank[id]'>Заметки</a> ($kol_dnev)\n";
echo "</div>";
//------------------------------------------------------------------//



//-------------------------------в друзья---------------------------//
if ($user['id']!=$ank['id']){
echo "<div class='main'>";
if ($frend_new==0 && $frend==0){
echo "<img src='/style/icons/druzya.png' alt='*'/> <a href='/info.php?id=$ank[id]&amp;frends'>Добавить в друзья</a><br />\n";
}elseif ($frend_new==1){
echo "<img src='/style/icons/druzya.png' alt='*'/> <a href='/user/frends/create.php?otm=$ank[id]'>Отклонить заявку</a><br />\n";
}elseif ($frend==2){
echo "<img src='/style/icons/druzya.png' alt='*'/> <a href='/user/frends/create.php?del=$ank[id]'>Удалить из друзей</a><br />\n";
}
echo "</div>";
}
//-----------------------------------------------------------------//
echo "<div class='main'>";
echo "<img src='/style/my_menu/who_rating.png' alt='*' /> <a href='/user/info/who_rating.php?id=$ank[id]'><b>Отзывы</b></a> (".mysql_result(mysql_query("SELECT COUNT(*) FROM `user_voice2` WHERE `id_kont` = '".$ank['id']."'"),0).")<br />\n";echo "</div>";

//-------------------------------настройки----------------------//

if ($ank['id']==$user['id']){
echo "<div class='main2'>";
echo "<img src='/style/icons/settings.png' alt='*' /> <a href=\"/settings.php\">Мои настройки</a> | <a href=\"/umenu.php\">Меню</a>\n";
echo "</div>";
}
//---------------------------------------------------------//

//-----------------------------стена--------------------------------//
echo "<div class='foot'>";
echo "<img src='/style/icons/stena.gif' alt='*' /> ";
if ($user['wall']==0)
echo "<a href='/info.php?id=$ank[id]&amp;wall=1'>Стена</a>\n";
else
echo "<a href='/info.php?id=$ank[id]&amp;wall=0'>Стена</a>\n";
echo "</div>";
if ($user['wall']==0){
include_once 'user/stena/index.php';
}
//------------------------------------------------------------------//

?>