<?
$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['money']>=$gift['cena'] AND $ku['rubies']>=$gift['rubies'])
{
$msg=$_POST['msg'];
if($ku['level']<=30 AND $ank['id']!==1)$_POST['msg']=antispam($_POST['msg']);
if(strlen2($msg)>512)
{
$err=1;
echo "Сообщение длиннее 512-ти символов";
}
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_friends` WHERE `id_user` = '$ank[id]' AND `id_ank`='$ku[id]'"),0)==0 AND mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_setting` WHERE `id_user` = '$ank[id]' AND `privat_gift`='1'"),0)==1)
{
$err=1;
err_game("Этот игрок закрыл передачу подарков.");
}
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_blacklist` WHERE `id_user` = '$ank[id]' AND `id_ank` = '$ku[id]'"),0)!=0)
{
$err=1;
err_game("Этот пользователь внес Вас в чёрный список, Вы не можете отправлять ему подарки.");
}
if(isset($molchi) && $molchi==1)
{
$err=1;
err_game("Отправлять подарки запрещено.");
}
if($ku['level']<=15)
{
$err=1;
err_game("Отправлять подарки можно с 15 ур.");
}


if(!isset($err))
{
$_SESSION['msg']='Подарок успешно отправлен!';
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]'");
$moni=$ku['money']-$gift['cena'];
$ku['money']=minus_money($gift['cena']);
$ku['rubies']=minus_rubies($gift['rubies']);
header("Location:/user/$ank[id]");
}
}
else
{
if($ku['money']<$gift['cena'])$_SESSION['no_money']=$gift['cena']-$ku['money'];
if($ku['rubies']<$gift['rubies'])$_SESSION['no_rubies']=$gift['rubies']-$ku['rubies'];
header("Location:?presents=$ank[id]&do&cat=$cat[id]&gift=$gift[id]");
}
}
echo "<div class='event'><h1>Подарок для $anku[nick]</h1></div>";
echo '<div class="content"><div class="block">';
echo "<img src='/images/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]/cat-$cat[id]/gift-$gift[id]/do/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><a href='/presents-$ank[id]/do'>Виды подарков</a> / Подарок для $anku[nick]</h1></div>";
echo '<div class="content"><div class="block">';
echo "<ul>";
$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 "<li class='pb'><img src='/images/gifts/$post[id].png' alt='*' width='96' height='96'><br><span class='title'>".hsc($post['name'])."</span><br><span class='small minor'>Цена <span>".(!empty($post['cena'])?"<img width='16' height='16' src='/images/icons/money.png' alt='*'> <span class='title'>$post[cena]</span>":"")."".(!empty($post['rubies'])?" <img width='16' height='16' src='images/icons/ruby.png' alt=''> <span class='title'>$post[rubies]</span>":"")."</span></span><br><a href='/presents-$ank[id]/cat-$cat[id]/gift-$post[id]/do'>Подарить</a></li>";
}
if ($k_page>1)new_str("do/presents-$ank[id]/cat-$cat[id]/",$k_page,$page); // Вывод страниц
echo "</ul>";
}
}
else
{
echo "<div class='event'><h1>Подарок для $anku[nick]</h1></div>";
echo '<div class="content"><div class="block">';
echo "<ul>";
$q=mysql_query("SELECT * FROM `kolhoz_gift_cat` ORDER by `id` DESC");
while($post=mysql_fetch_array($q))
{
echo "<li><img src='/images/icons/gift.png' alt='*' width='16' height='16'> <a href='/presents-$ank[id]/cat-$post[id]/do'><span>".hsc($post['name'])."</span></a></li>";
}
}
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='images/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><div><span class='small title'><p>".output_text($post['msg'], $ank2['id'])."</p></span></div>";
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>";
echo "<li></li><div><img width='16' height='16' src='images/icons/gift_plus.png' alt='o'> <a href='?presents=$ank[id]&do'>Подарить</a></div>";
}
include_once 'inc/foot.php';
?>