<?
$ank=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_user` WHERE `id` = '".intval($_GET['presents'])."'"));
$anku=$ank;


if(isset($_GET['do']))
{
if(isset($_GET['cat']) && intval($_GET['cat'])!=NULL && mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_gift_cat` WHERE `id` = '".intval($_GET['cat'])."'"),0)!=0)
{
$cat=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_gift_cat` WHERE `id` = '".intval($_GET['cat'])."'"));
if(isset($_GET['gift']) && intval($_GET['gift'])!=NULL && mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_gift` WHERE `id` = '".intval($_GET['gift'])."' AND `id_cat` = '$cat[id]'"),0)!=0)
{
$gift=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_gift` WHERE `id` = '".intval($_GET['gift'])."' AND `id_cat` = '$cat[id]'"));
if(isset($_GET['ok']))
{
if($ku['rubies']>=$gift['cena'])
{
$msg=$_POST['msg'];
if(strlen2($msg)>512)
{
$err=1;
echo "Сообщение длиннее 512-ти символов";
}
if($ku['level']<=15)
{
$err=1;
err_game("Дарить подарки можно после того как достигните 15-го уровня!");
}
if($ku['time']<=3600*2)
{
$err=1;
err_game("Дарить подарки можно после того как проведете в игре <b>2 часа</b>");
}


if(!isset($err))
{
mysql_query("INSERT INTO `kolhoz_gifts` SET `id_user` = '$ank[id]', `id_kont` = '$ku[id]', `msg` = '".my_esc($msg)."', `time` = '$time', `id_gift` = '$gift[id]'");
mysql_query("UPDATE `kolhoz_user` SET `rubies` = '".($ku['rubies']-$gift['cena'])."' WHERE `id` = '$ku[id]'");
$ku[rubies] = $ku['rubies']-$gift['cena'];     
header("Location:?user=$ank[id]");
}
}
else
{
$_SESSION['no_rubies']=$gift['cena']-$ku['rubies'];
header("Location:?presents=$ank[id]&do&cat=$cat[id]&gift=$gift[id]");
}
}
//====================
echo "<div class='event'><h1>Список подарков</h1></div>";
echo "<div class='block'>";
echo "<b><img src='img/icons/ruby.png' alt='o'>За рубины</b> | <img src='img/icons/money.png' alt='o'><a href='?presentsm=$anku[id]&do'>За монеты</a> | <img src='img/icons/baks.png' alt='o'><a href='?presentsb=$anku[id]&do'>За баксы</a><br/>";
echo "<font color='violet'>Подарок для:</font> <font color='tomato'><b>$anku[nick]</b></font>";
echo "</div>";
//====================
echo '<div class="content"><div class="block">';
echo "<img src='img/gifts/$gift[id].png' alt='o' width='96' height='96'><br><span class='title'>".hsc($gift['name'])."</span><br><div class='small minor'>Сообщение к подарку (необязательно):</div><form action='?presents=$ank[id]&do&cat=$cat[id]&gift=$gift[id]&ok' method='post'><label><textarea class='wide' rows='5' name='msg'></textarea><br></label><input type='submit' value='Отправить' name='ok'></form>";
}
else
{
//====================
echo "<div class='event'><h1>Список подарков</h1></div>";
echo "<div class='block'>";
echo "<b><img src='img/icons/ruby.png' alt='o'>За рубины</b> | <img src='img/icons/money.png' alt='o'><a href='?presentsm=$anku[id]&do'>За монеты</a> | <img src='img/icons/baks.png' alt='o'><a href='?presentsb=$anku[id]&do'>За баксы</a><br/>";
echo "<font color='violet'>Подарок для:</font> <font color='tomato'><b>$anku[nick]</b></font>";
echo "</div>";
//====================
echo '<div class="content"><div class="block">';
echo "<div class='block'><img src='img/icons/left.png' alt='o' width='16' height='16'> <a href='?presents=$ank[id]&do'>К категориям</a></div>";
$k_post = mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_gift` WHERE `id_cat` = '$cat[id]'"),0);
if ($k_post==0)
{
echo "Список пуст...";
}
$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 `kolhoz_gift` WHERE `id_cat` = '$cat[id]' ORDER BY `id` DESC LIMIT $start, $set[p_str]");
while($post=mysql_fetch_array($q))
{
echo "<div class='block'><img src='img/gifts/$post[id].png' alt='o' width='96' height='96'><br><span class='title'>".hsc($post['name'])."</span> <span class='small minor'>(<span><img width='16' height='16' src='img/icons/ruby.png' alt='o'> <span class='title'>$post[cena]</span></span>)</span><br><a href='?presents=$ank[id]&do&cat=$cat[id]&gift=$post[id]'>Подарить</a></div>";
}
if ($k_page>1)str("?presents=$ank[id]&do&cat=$cat[id]&",$k_page,$page); // Вывод страниц
echo "</ul>";
}
}
else
{
//====================
echo "<div class='event'><h1>Список подарков</h1></div>";
echo "<div class='block'>";
echo "<b><img src='img/icons/ruby.png' alt='o'>За рубины</b> | <img src='img/icons/money.png' alt='o'><a href='?presentsm=$anku[id]&do'>За монеты</a> | <img src='img/icons/baks.png' alt='o'><a href='?presentsb=$anku[id]&do'>За баксы</a><br/>";
echo "<font color='violet'>Подарок для:</font> <font color='tomato'><b>$anku[nick]</b></font>";
echo "</div>";
//====================
echo '<div class="content"><div class="block">';
echo "<ul>";
$q=mysql_query("SELECT * FROM `kolhoz_gift_cat`");
while($post=mysql_fetch_array($q))
{
echo "<div class='block'><img src='img/icons/right.png' alt='o' width='16' height='16'> <a href='?presents=$ank[id]&do&cat=$post[id]'><span>".hsc($post['name'])."</span></a></div>";
}
}
echo "</ul><div></div></div>";
}
elseif(isset($_GET['del']) && intval($_GET['del'])!=NULL && mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_gifts` WHERE `id` = '".intval($_GET['del'])."'"),0)!=0)
{
mysql_query("DELETE FROM `kolhoz_gifts` WHERE `id` = '".intval($_GET['del'])."'");
header("Location:?presents=$ank[id]");
}
else
{
echo "<div class='event'><h1>".($ank['id']==$ku['id']?"Мои подарки":"<a href='?user=$ank[id]'>$anku[nick]</a> / Подарки")."</h1></div>";
echo '<div class="content"><div class="block">';
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_gifts` WHERE `id_user` = '$ku[id]' AND `read` = '0'"),0)!=0 && $ank['id']==$ku['id'])
{
mysql_query("UPDATE `kolhoz_gifts` SET `read` = '1' WHERE `id_user` = '$ku[id]' AND `read` = '0'");
header("Location:?presents=$ku[id]");
}
echo "<ul>";
$k_post = mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_gifts` WHERE `id_user` = '$ank[id]'"),0);
if ($k_post==0)
{
echo "Список пуст...";
}
$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 `kolhoz_gifts` 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 `kolhoz_user` WHERE `id` = '$post[id_kont]'"));
$anku2=$ank2;
$gift=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_gift` WHERE `id` = '$post[id_gift]'"));
echo "<li class='pb'><div><img src='img/gifts/$gift[id].png' alt='o' width='96' height='96'></div><div><span class='title'>".hsc($gift['name'])."</span></div><div><div><span>Подарил".($anku2['pol']==0?"a":null)."</span> <span>";
echo on_k($ank2['id']);
echo " <a class='' href='?user=$ank2[id]'>".nc($ank2['id'])."</a></span> <div class='minor'> (<span>".vremja($post['time'])."</span>)</div></div>";



$ban = mysql_fetch_array(mysql_querll("SELECT * FROM `kolhoz_ban` WHERE `id_user` = '$ank2[id]' AND (`time` > '$time' OR `izg` = '1') ORDER BY `id` DESC LIMIT 1"));
$us_ban = mysql_fetch_array(mysql_querll("SELECT * FROM `kolhoz_user` WHERE `id` = '$ban[id_who]'"));

if($ban['id']){
//echo " <a class='' href='?user=$ank[id]'><span>".nc($ank['id'])."</span></a></span>";
echo "".($ban['izg']==1?'<font color="tomato">Сообщение заблокировано</font>':"<font color='tomato'>Сообщение заблокировано до:</font> <b>".vremja($ban['time']))."</b><br/>";
if($ku['status']>0){echo "(<font color='#A52A2A'>".(!empty($post['otvet'])?"".($ku['id']==$ot['id']?"<span class='rare'>":null)."$ot[nick]".($ku['id']==$ot['id']?"</span>":null).", ":null)."".output_text($post['msg'], $ank['id'])."</font>)<br/><b><font color='#FFD700'>Видно только должностным лицам</font></b>";}

}
else
if($ank2['id']){


echo "<div><span class='small title'><p>".output_text($post['msg'], $ank2['id'])."</p></span></div>";

}//blok

if($ku['id']==$ank['id'])echo "<div><a class='small minor' href='?presents=$ank[id]&del=$post[id]'>[удалить]</a></div>";
echo "</div></li>";
}
if ($k_page>1)str("?presents=$ank[id]&",$k_page,$page); // Вывод страниц
echo "</ul>";
echo "</div>";
}
include_once 'inc/foot.php';
?>