<?
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();

$set['title'] = 'Мои друзья';
include_once '../../sys/inc/thead.php';
title();
aut();
	$num=0;
	$anks['id'] = $user['id'];
if (isset($_GET['id']))$anks['id'] = intval($_GET['id']);
	$q = mysql_query("SELECT * FROM `user` WHERE `id` = $anks[id] LIMIT 1");
if (mysql_num_rows($q)==0){header("Location: index.php?".SID);exit;}

	$anks = mysql_fetch_array($q);

	$k_post = mysql_result(mysql_query("SELECT COUNT(*) FROM `frends` WHERE `user` = '$anks[id]' AND `i` = '1'"), 0);
if (isset($_GET['add']))msg('Предложение дружбы отправлено');
if ($anks['id']==$user['id'])
{
	$k_p = mysql_result(mysql_query("SELECT COUNT(*) FROM `frends` INNER JOIN `user` ON `frends`.`frend`=`user`.`id` WHERE `frends`.`user` = '$anks[id]' AND `frends`.`i` = '1' AND `user`.`date_last`>'".(time()-600)."'"), 0);
	$k_f = mysql_result(mysql_query("SELECT COUNT(id) FROM `frends_new` WHERE `to` = '$anks[id]' LIMIT 1"), 0);
	echo '<div class="foot">Друзья ('.$k_post.') | <a href="/user/frends/fredon.php">Онлайн</a> ('.$k_p.') | <a href="/user/frends/frend_new.php">Приглашения дружить</a> ('.$k_f.')</div>';
}
else echo "<div class='p_t'>$anks[nick]</div>";


echo '<table class="post">'."\n";
if (mysql_result(mysql_query("SELECT COUNT(*) FROM `frends` WHERE `user` = '$anks[id]' AND `i` = '1'"), 0)==0)
{
	echo "   <tr>\n";
	echo "  <td class='p_t'>\n";
	echo "У тебя пока нет друзей\n";
	echo "  </td>\n";
	echo "   </tr>\n";
}
$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` = '$anks[id]' AND `i` = '1' ORDER BY time DESC LIMIT $start, $set[p_str]");
while ($post = mysql_fetch_assoc($q))
{
//$ank=mysql_fetch_assoc(mysql_query("SELECT * FROM `user` WHERE `id` = $post[id_user] LIMIT 1"));
$ank=get_user($post['frend']);
echo '<table class="post">'."\n";
echo "   <tr>\n";

if ($set['set_show_icon']==2){
echo "  <td class='icon48'>\n";
avatar($ank['id']);
echo "  </td>\n";
}
elseif ($set['set_show_icon']==1)
{
echo "  <td class='icon14'>\n";
echo "".status($ank['id'])."";
echo "  </td>\n";
}
echo "  <td class='p_t'>\n";
echo " ".group($ank['id'])." <a href='/info.php?id=$ank[id]'>$ank[nick]</a> ".medal($ank['id'])." ".online($ank['id'])." (".(($ank['pol']==1)?'М':'Ж').")";

if ($anks['id']==$user['id'])echo ' <a href="frend_new.php?del='.$ank['id'].'"><img src="/style/icons/delete.gif" alt="*" /></a>';

echo "  </td>\n";
echo "   </tr>\n";
echo '</table>';

echo '<table class="post">'."\n";
echo "   <tr>\n";
echo "  <td class='p_m'>\n";
echo " <a href=\"/mail.php?id=$ank[id]\"><img src='/style/icons/pochta.gif' alt='*' /> Написать сообщение</a> \n";
echo'('.vremja($post['time']).')';
echo "  </td>\n";
echo "   </tr>\n";
echo '</table>';
}

echo '</table>';

if ($k_page>1)str("?id=$anks[id]&",$k_page,$page); // Вывод страниц

echo "</div>";

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