<?php
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';

only_reg();

$ank['id'] = $user['id'];

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

$q = mysql_query("SELECT * FROM `user` WHERE `id` = '".$ank['id']."' LIMIT 1");

if(mysql_num_rows($q)==0){
	header("Location: index.php");
	exit;
	}

$ank = mysql_fetch_array($q);

$set['title'] = 'Список друзей '.$ank['nick'].' &amp; '.$_SERVER['HTTP_HOST'];
include_once 'sys/inc/thead.php';

title();
aut();

if ($ank['ank_enter'] == '2' && !isset($user))
{
echo' <div class="gend"> - Пользователь запретил просмотр своих друзей</div>';
include_once 'sys/inc/tfoot.php';
exit();
}

if ($ank['ank_enter'] == '2' && $ank['id'] != $user['id'] && mysql_result(mysql_query("SELECT COUNT(*) FROM `frends` WHERE `user` = '$ank[id]' && `frend` = '$user[id]'"),0) == '0')
{
echo' <div class="gend"> - Пользователь запретил просмотр своих друзей</div>';

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

echo '<div class="rowup">';

echo '<table class="post">';

if(isset($_GET['add'])){
	msg('Заявка отправлена');
	}

if($ank['id']==$user['id']){
	echo "<div class='menu'>";
echo '<img src="/img/tabor/add_frends.gif" alt=""/> <a href="frend_new.php">Предложение дружбы</a></div>';
echo "</div>";
	}

$k_post = mysql_result(mysql_query("SELECT COUNT(*) FROM `frends` WHERE `user` = '".$ank['id']."' AND `i` = '1'"),0);

if($k_post==0){
	echo 'У обитателя <span style="color:'.$ank['ncolor'].'">'.$ank['nick'].'</span> нет друзей';
	}

$k_page = k_page($k_post,$set['p_str']);
$page = page($k_page);
$start = $set['p_str']*$page-$set['p_str'];

$q = mysql_query("SELECT * FROM `frends` WHERE `user` = '".$ank['id']."' AND `i` = '1' ORDER BY time DESC LIMIT $start, $set[p_str]");
while ($f = mysql_fetch_array($q)){
	$a = mysql_fetch_array(mysql_query("SELECT * FROM `user` WHERE `id` = '".$f['frend']."' LIMIT 1"));

echo '<tr><td class="icon48" rowspan="2">';
echo avatar2($a['id']);
echo '</td><td class="p_t">&nbsp;'.online($a['id']).'&nbsp;<a href="/info.php?id='.$a['id'].'"><span style="color:'.$a['ncolor'].'">'.$a['nick'].'</span></a>&nbsp;'.adm($a['id']).'&nbsp;<span class="ank_n">('.vremja($f['time']).')</span></td></tr><tr>';

if($ank['id']==$user['id']){
	echo '<td class="p_m"><a href="/frend_new.php?del='.$a['id'].'">Удалить из друзей</a></td></tr>';
	}
echo '</td></tr>';
	}

echo '</table>';
echo '</div>';
if($k_page>1){
	str("?id=".$ank['id']."&amp;",$k_page,$page);
	}

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