<?php
require '../sys/inc/start.php';
require '../sys/inc/compress.php';
require '../sys/inc/sess.php';
require '../sys/inc/home.php';
require '../sys/inc/settings.php';
require '../sys/inc/db_connect.php';
require '../sys/inc/ipua.php';
require '../sys/inc/fnc.php';
require '../sys/inc/user.php';
################################################################################
if(!isset($user))
{
$set['title']='Подарки';
require '../sys/inc/thead.php';
title();
err();
aut();
echo "Доступ закрыт не авторизированым пользователям!\n";
require '../sys/inc/tfoot.php';
exit();
}
################################################################################
if (isset($_GET['user']) && mysql_result(mysql_query("SELECT COUNT(*) FROM `user` WHERE `id` = '".intval($_GET['user'])."'"),0))
{
$set['title']='Подарки - '.mysql_result(mysql_query("SELECT `nick` FROM `user` WHERE `id` = '".intval($_GET['user'])."'"),0).'';
require '../sys/inc/thead.php';
title();
err();
aut();
################################################################################
if (isset($user) && isset($_GET['del']) && mysql_result(mysql_query("SELECT COUNT(*) FROM `present_give` WHERE `id_give` = '$user[id]' AND `id` = '".intval($_GET['del'])."'"),0))
{
mysql_query("DELETE FROM `present_give` WHERE `id` = '".intval($_GET['del'])."' LIMIT 1");
msg('Подарок продан!');
}

if (isset($user) && isset($_GET['dell']) && mysql_result(mysql_query("SELECT COUNT(*) FROM `present_give` WHERE `id_give` = '$user[id]' AND `id` = '".intval($_GET['dell'])."'"),0)  || user_access('present_del'))
{
mysql_query("DELETE FROM `present_give` WHERE `id` = '".intval($_GET['dell'])."' LIMIT 1");
msg('Подарок удален');
}
################################################################################
$k_post=mysql_result(mysql_query("SELECT COUNT(*) FROM `present_give` WHERE `id_give` = '".intval($_GET['user'])."'"),0);
$k_page=k_page($k_post,$set['p_str']);
$page=page($k_page);
$start=$set['p_str']*$page-$set['p_str'];
echo "<table class='post'>\n";
if ($k_post==0)
{
echo "   <tr>\n";
echo "  <td class='p_t'>\n";
echo "Нет подарков\n";
echo "  </td>\n";
echo "   </tr>\n";
}
$q=mysql_query("SELECT * FROM `present_give` WHERE `id_give` = '".intval($_GET['user'])."' ORDER BY `id` DESC LIMIT $start, $set[p_str]");
while ($post = mysql_fetch_array($q))
{
if (mysql_result(mysql_query("SELECT COUNT(*) FROM `user` WHERE `id` = '$post[id_user]'"),0) && mysql_result(mysql_query("SELECT COUNT(*) FROM `present_list` WHERE `id` = '$post[id_p]'"),0))
{
$qp=mysql_query("SELECT * FROM `present_list` WHERE `id` = '$post[id_p]' LIMIT 1");
$p=mysql_fetch_array($qp);
$cena=$p['prise'];
$sums=$cena/2;
echo "   <tr>\n";
echo "  <td class='str'>\n";
############################   1 вариант   #####################################
if ($post['pod']==0){
echo "<img src='$p[url]' /><br />\n";
echo "<u>Подарил(а):</u> <a href='/info.php?id=$post[id_user]'>".mysql_result(mysql_query("SELECT `nick` FROM `user` WHERE `id` = '$post[id_user]' LIMIT 1"),0)."</a><br />\n";
echo "<u>Дата:</u> ".vremja($post['time'])."<br />\n";
echo "<u>Тип подарка:</u> Публичный<br />\n";
if($post['coment']!=NULL)echo"<b>Даритель написал:</b> ".output_text($post['coment'])."<br />\n";
}
############################   2 вариант   #####################################
if ($post['pod']==1){
echo "<img src='$p[url]' /><br />\n";
if (isset($user) && $user['id'] == $post['id_give'] || $user['level']>0)echo "<u>Подарил(а):</u> <a href='/info.php?id=$post[id_user]'>".mysql_result(mysql_query("SELECT `nick` FROM `user` WHERE `id` = '$post[id_user]' LIMIT 1"),0)."</a><br />\n";
else
echo "<u>Подарил(а):</u> Неизвестный<br />\n";
echo "<u>Дата:</u> ".vremja($post['time'])."<br />\n";
echo "<u>Тип подарка:</u> Личный<br />\n";
if (isset($user) && $user['id'] == $post['id_give'] || $user['level']>0)
if($post['coment']!=NULL)echo"<b>Даритель написал:</b> ".output_text($post['coment'])."<br />\n";
}
############################   3 вариант   #####################################
if ($post['pod']==2){
echo "<img src='$p[url]' /><br />\n";
if (user_access('adm_info'))
echo "<u>Подарил(а):</u> <a href='/info.php?id=$post[id_user]'>".mysql_result(mysql_query("SELECT `nick` FROM `user` WHERE `id` = '$post[id_user]' LIMIT 1"),0)."</a><br />\n";
else
echo "<u>Подарил(а):</u> Неизвестный<br />\n";
echo "<u>Дата:</u> ".vremja($post['time'])."<br />\n";
echo "<u>Тип подарка:</u> Анонимный<br />\n";
if (isset($user) && $user['id'] == $post['id_give'] || $user['level']>0)
if($post['coment']!=NULL)echo"<b>Даритель написал:</b> ".output_text($post['coment'])."<br />\n";
}
################################################################################
if (isset($_GET['set']) && $_GET['set']==$post['id'])
{
echo "<form method='post' action='?user=".intval($_GET['user'])."&amp;sett=$post[id]&amp;page=$page'>\n";
echo "<hr/>Продать?<br />\n";
echo "<input value='Да' type='submit'> / <a href='?user=".intval($_GET['user'])."'>Нет</a></form>\n";
}elseif (isset($_GET['sett']) && $_GET['sett']==$post['id'])
{
header("Location: ?user=".intval($_GET['user'])."&del=$post[id]");
if (isset($user) && $user['id']==$post['id_give'])mysql_query("UPDATE `user` SET `balls` = '".($user['balls']+$sums)."' WHERE `id` ='$user[id]';");
}else{
if (isset($user) && $user['id']==$post['id_give'])echo "[<a href='?user=".intval($_GET['user'])."&amp;set=$post[id]&amp;page=$page'>Продать</a>] $sums баллов.\n";
if (user_access('present_del') && $user['id']!=$post['id_give'])
echo"[<a href='?user=".intval($_GET['user'])."&amp;dell=$post[id]'>Удалить</a>]<br />\n";
}
echo "  </td>\n";
echo "   </tr>\n";
}
}
echo "</table>\n";
if ($k_page>1)str("?user=".intval($_GET['user'])."&amp;",$k_page,$page);
echo "<div class='p_t'>\n";
echo "<img src='/images/Back.gif'> <a href='/info.php?id=".intval($_GET['user'])."'>В анкету</a><br />\n";
echo "</div>\n";
}else{
$set['title']='Подарки';
require '../sys/inc/thead.php';
title();
err();
aut();
echo "Не указан пользователя чьи подарки вы хотите просмотреть.\n";
}
require '../sys/inc/tfoot.php';
?>