<?
$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'])
{
$msg=$_POST['msg'];
if(strlen2($msg)>512)
{
$err=1;
echo "Сообщение длиннее 512-ти символов";
}
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 `money` = '".($ku['money']-$gift['cena'])."' WHERE `id` = '$ku[id]'");
header("Location:?user=$ank[id]");
}
}
else
{
$_SESSION['no_money']=$gift['cena']-$ku['money'];
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]&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><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='o' width='96' height='96'><br><span class='title'>".hsc($post['name'])."</span><br><span class='small minor'>Цена <span><img width='16' height='16' src='images/icons/money.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></li>";
}
if ($k_page>1)str("?presents=$ank[id]&do&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`");
while($post=mysql_fetch_array($q))
{
echo "<li><img src='images/icons/gift.png' alt='o' width='16' height='16'> <a href='?presents=$ank[id]&do&cat=$post[id]'><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"><div class="small ptm">';
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';
?>