<?
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($_GET['act']) && $_GET['act']=='admin' && $user['level']>=4)include_once 'admin.php';
if(isset($_GET['act']) && $_GET['act']=='medal' && isset($user) && ($user['group_access']>1 || $user['status_vip']))include_once 'medal.php';
$id=$user['id'];
if(isset($_GET['id']))$id=intval($_GET['id']);
$ank=mysql_query("SELECT * FROM `user` WHERE `id` = '$id' LIMIT 1");
if(mysql_num_rows($ank)==0){header("Location: index.php?".SID);exit;}
$ank=mysql_fetch_array($ank);
$set['title']="Награды $ank[nick]";
include_once '../sys/inc/thead.php';
title();

echo "<div class='foot1'>\n";
echo "<table>";
if(isset($_GET['del']) && intval($_GET['del'])!=NULL && mysql_result(mysql_query("SELECT COUNT(*) FROM `rank` WHERE `id` = '".intval($_GET['del'])."' AND `id_user` = '$ank[id]'"),0)!=0 && $user['level']>=4)
{
$del=mysql_fetch_array(mysql_query("SELECT * FROM `rank` WHERE `id` = '".intval($_GET['del'])."'"));
if(isset($_GET['ok']))
{
mysql_query("DELETE FROM `rank` WHERE `id` = '$del[id]'");
header("Location:?id=$ank[id]");
}
echo "<center>Вы уверены, что хотите удалить эту награду?<br />
<small>[<a style='color:red' href='?id=$ank[id]&del=$del[id]&ok'>Да</a>]</small> [<a style='color:blue'  href='?id=$ank[id]'>Нет</a>]</center><br />\n";
echo "<div class='menu_razd'><img src='img/back.png' /> <a href='?id=$ank[id]'>Назад</a></div>";
include_once '../sys/inc/tfoot.php';
exit;
}
$k_post = mysql_result(mysql_query("SELECT COUNT(*) FROM `rank` WHERE `id_user` = '$ank[id]'"), 0);
if ($k_post==0)
{
echo "<div class='rekl_main'>\n";
echo "<img src='/img/star_fav.gif' alt='' class='icon'/> У обитателя $ank[nick] нет наград";
echo "</div>";
}
$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 `rank` WHERE `id_user` = '$ank[id]' ORDER BY `time` DESC LIMIT $start, $set[p_str]");
while($post=mysql_fetch_array($q))
{
$ank2=mysql_fetch_array(mysql_query("SELECT * FROM `user` WHERE `id` = '$post[ot_id]' LIMIT 1"));
$rank=mysql_fetch_array(mysql_query("SELECT * FROM `rank_list` WHERE `id` = '$post[id_rank]' LIMIT 1"));
echo "<tr>";
if(isset($num) && $num==1)
{
echo "<td style='border-top: 1px #CCC solid;background-color: #edeff4;padding: 1px;margin: 1px;width: 10%' rowspan='1'>";
}
else
{
echo "<td style='border-top: 1px #CCC solid;background-color: #edeff4;padding: 1px;margin: 1px;width: 10%' rowspan='1'>";
}
echo "<img src='/rank/img_rank/$rank[id].png' alt='*' class='icon'/>";
echo "</td>";
if(isset($num) && $num==1)
{
echo "<td style='border-top: 1px #ccc solid;background-color: #edeff4;padding: 1px;margin: 1px;width: 91%' rowspan='1'>";
$num=0;
}
else
{
echo "<td style='border-top: 1px #CCC solid;background-color: #FFF;padding: 1px;margin: 1px;width: 91%' rowspan='1'>";
$num=1;
}
echo "<div class='rekl_main'>\n";
if($user['level']>=4)echo "<span style='float: right; font-size: small; color: grey'><a class='icolink' href='?id=$ank[id]&del=$post[id]'><img src='img/del.png'/></a></span>\n";
echo "<b>".output_text($rank['msg'])."</b> (<a href='/info.php?id=$ank2[id]'>$ank2[nick]</a>)<br/>";
echo "<img src='img/time.png'> Время награждения: ".vremja($post['time'])."<br/>";
echo "<img src='img/time.png'> Действует до: ".vremja($post['time_to'])."<br/>";
echo "<img src='img/msg.png'> Сообщение наградителя: ".output_text($post['msg'])."";
echo "</td></tr>";
}
echo "</div>";
if ($k_page>1)str("?id=$ank[id]&",$k_page,$page); // Вывод страниц

echo "</table>";
if(isset($user) && $user['id']!=$ank['id'] && ($user['group_access']>1 || $user['status_vip']))echo "<div class='menu_razd'><img src='img/add.png' /> <a href='?act=medal&id=$ank[id]'>Наградить пользователя</a></div>";
echo "</div>";
echo "<div class='p_t'><img src='img/back.png' /> <a href='/info.php?id=$ank[id]'>Дом $ank[nick]</a>".(isset($user) && $user['id']!=$ank['id']?" | <a href='?id=$user[id]'>Мои награды</a>":null)."</div>";
include_once '../sys/inc/tfoot.php';
?>