<?
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']);




$ank = get_user($ank['id']);

if(!$ank){header("Location: /index.php?".SID);exit;}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;
}

/* Бан пользователя */ 
if ((!isset($user) || $user['group_access'] == 0) && mysql_result(mysql_query("SELECT COUNT(*) FROM `ban` WHERE `razdel` = 'all' AND `id_user` = '$ank[id]' AND (`time` > '$time' OR `navsegda` = '1')"), 0)!=0)
{
	$set['title'] = $ank['nick'].' - страничка '; // заголовок страницы
	include_once 'sys/inc/thead.php';
	title();
	aut();
	
	
	?>
	<div class='gmenu'><img src='/style/icons/zona.gif'><br/>
	<?
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 "<b>Забанен до:</b> ".vremja($post['time'])."\n";
echo "</br><b>Причина:</b> ".output_text($post['prich'])."</span><br />\n";
}
}
	echo '<font color=red> Этот пользователь был заблокирован за нарушение <a href="/rules.php">правил</a> сайта Lafac.Ru</font> ';
	echo '</div>';
	
	include_once 'sys/inc/tfoot.php';
	exit;
}	





/*-------------------------гости----------------------*/
if (isset($user) && $user['id'] != $ank['id'] && !isset($_SESSION['guest_' . $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')");
		mysql_query("UPDATE `user` SET `balls` = '".($ank['balls']+1)."' ,`rating_tmp` = '".($ank['rating_tmp']+1)."' WHERE `id` = '$ank[id]' LIMIT 1");
		$_SESSION['guest_' . $ank['id']] = 1;
	}
	elseif (!isset($_SESSION['guest_' . $ank['id']]))
	{
		$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  `time` = '$time', `read` = '1' WHERE `id` = '$guest[id]' LIMIT 1");
		mysql_query("UPDATE `user` SET `rating_tmp` = '".($ank['rating_tmp']+1)."' WHERE `id` = '$ank[id]' LIMIT 1");
		$_SESSION['guest_' . $ank['id']] = 1;
	}
}

/*---------------------*/

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) && $user['id'] == $ank['id'])
{
$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)){
mysql_query("UPDATE `status` SET `pokaz` = '0' WHERE `id_user` = '$user[id]'");
mysql_query("INSERT INTO `status` (`id_user`, `time`, `msg`, `pokaz`) values('$user[id]', '$time', '".my_esc($msg)."', '1')");$status=mysql_fetch_assoc(mysql_query("SELECT * FROM `status` WHERE `id_user` = '$ank[id]' AND `pokaz` = '1' LIMIT 1"));
######################Лента
$q = mysql_query("SELECT * FROM `frends` WHERE `user` = '".$user['id']."' AND `i` = '1'");
while ($f = mysql_fetch_array($q))
{
$a=get_user($f['frend']);
$lentaSet = mysql_fetch_array(mysql_query("SELECT * FROM `tape_set` WHERE `id_user` = '".$a['id']."' LIMIT 1")); // Общая настройка ленты
if ($f['lenta_status'] == 1 && $lentaSet['lenta_status'] == 1)
mysql_query("INSERT INTO `tape` (`id_user`,`ot_kogo`,  `avtor`, `type`, `time`, `id_file`) values('$a[id]', '$user[id]', '$status[id_user]', 'status', '$time', '$status[id]')"); 
}
#######################Конец

$_SESSION['message'] = 'Статус добавлен';
header("Location: ?id=$ank[id]");
exit;
} 
}
if (isset($_GET['off'])){
if ($ank['id']==$user['id']){
mysql_query("UPDATE `status` SET `pokaz` = '0' WHERE `id_user` = '$user[id]'");
$_SESSION['message'] = 'Статус отключен';
header("Location: ?id=$ank[id]");
exit;
}
}
//-------------------------------------// 

// Статус пользователя
$status=mysql_fetch_assoc(mysql_query("SELECT * FROM `status` WHERE `id_user` = '$ank[id]' AND `pokaz` = '1' LIMIT 1"));

/* Класс к статусу */

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`, `time`, `id_status`) values('$user[id]', '$time', '$status[id]')");######################Лента
$q = mysql_query("SELECT * FROM `frends` WHERE `user` = '".$user['id']."' AND `i` = '1'");
while ($f = mysql_fetch_array($q))
{
$a=get_user($f['frend']);
$lentaSet = mysql_fetch_array(mysql_query("SELECT * FROM `tape_set` WHERE `id_user` = '".$a['id']."' LIMIT 1")); // Общая настройка ленты
if ($a['id'] != $ank['id'] && $f['lenta_status_like']==1 && $lentaSet['lenta_status_like']==1)
mysql_query("INSERT INTO `tape` (`id_user`,`ot_kogo`,  `avtor`, `type`, `time`, `id_file`) values('$a[id]', '$user[id]', '$status[id_user]', 'status_like', '$time', '$status[id]')"); 
}
#######################Конец
header("Location: ?id=$ank[id]");
exit;
}
/*
=================================
добавляем в закладки
=================================
*/
if (isset($_GET['fav']) && isset($user)){	if (mysql_result(mysql_query("SELECT COUNT(*) FROM `mark_people` WHERE `id_user` = '".$user['id']."' AND `id_people` = '".$ank['id']."' LIMIT 1"),0) == 0 && $_GET['fav'] == 1){
		mysql_query("INSERT INTO `mark_people` (`id_people`, `id_user`, `time`) VALUES ('$ank[id]', '$user[id]', '$time')");
		$_SESSION['message'] = $ank['nick'] . ' добавлен в закладки';
	}	if (mysql_result(mysql_query("SELECT COUNT(*) FROM `mark_people` WHERE `id_user` = '".$user['id']."' AND `id_people` = '".$ank['id']."' LIMIT 1"),0) == 1 && $_GET['fav'] == 0){
		mysql_query("DELETE FROM `mark_people` WHERE `id_user` = '$user[id]' AND  `id_people` = '$ank[id]'");
		$_SESSION['message'] = $ank['nick'] . ' удален из закладок';
	}
	
		header("Location: /info.php?id=$ank[id]");
		exit;
}
/*------------------------статус like-----------------------*/
if(isset($user) && isset($_GET['like']) && ($_GET['like']==0 || $_GET['like']==1) && mysql_result(mysql_query("SELECT COUNT(*) FROM `status_like` WHERE `id_user` = '$user[id]' AND `id_status`='$status[id]' LIMIT 1"),0)==0 && $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']+3)."' ,`rating_tmp` = '".($ank['rating_tmp']+3)."' WHERE `id` = '$ank[id]' LIMIT 1");
}
/*----------------------------------------------------------*/



$set['title']=$ank['nick'].' - страничка '; // заголовок страницы
include_once 'sys/inc/thead.php';
title();
aut();

/*
==================================
Приватность станички пользователя
==================================
*/	
include H.'sys/add/user.privace.php';


if ($set['web']==true)
include_once H."user/info/web.php";
else
include_once H."user/info/wap.php";


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