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

if($ku['dostup']==1){
if(isset($_GET['do']))
{
if(isset($_GET['cat']) && intval($_GET['cat'])!=NULL && mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_nag_cat` WHERE `id` = '".intval($_GET['cat'])."'"),0)!=0)
{
$cat=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_nag_cat` WHERE `id` = '".intval($_GET['cat'])."'"));
if(isset($_GET['nag']) && intval($_GET['nag'])!=NULL && mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_nag` WHERE `id` = '".intval($_GET['nag'])."' AND `id_cat` = '$cat[id]'"),0)!=0)
{
$nag=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_nag` WHERE `id` = '".intval($_GET['nag'])."' AND `id_cat` = '$cat[id]'"));
if(isset($_GET['ok']))
{

$msg=$_POST['msg'];
if(strlen2($msg)>512)
{
$err=1;
echo "Сообщение длиннее 512-ти символов";
}


if(!isset($err))
{
mysql_query("INSERT INTO `kolhoz_nagrada` SET `id_user` = '$ank[id]', `id_kont` = '$ku[id]', `msg` = '".my_esc($msg)."', `time` = '$time', `id_nag` = '$nag[id]'");
mysql_query("UPDATE `kolhoz_user` SET `zkl` = '".($ank['zkl']+$nag['cena'])."' WHERE `id` = '$ank[id]'");//ключи
mysql_query("UPDATE `kolhoz_user` SET `money` = '".($ank['money']+$nag['cenam'])."' WHERE `id` = '$ank[id]'");//Монеты
mysql_query("UPDATE `kolhoz_user` SET `euro` = '".($ank['euro']+$nag['cenae'])."' WHERE `id` = '$ank[id]'");//Евро
mysql_query("UPDATE `kolhoz_user` SET `akmaz` = '".($ank['almaz']+$nag['cenab'])."' WHERE `id` = '$ank[id]'");//баксы


header("Location:?user=$ank[id]");
}
}

//====================

echo "<div class='event'><h1>Список наград</h1></div>";
echo "<div class='block'>";
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/nag/$nag[id].png' alt='o'> <span class='title'>".hsc($nag['name'])."</span><br/><div class='small minor'>За что награждаем (Обязательно):</div><form action='?nagrada=$ank[id]&do&cat=$cat[id]&nag=$nag[id]&ok' method='post'><label><textarea class='wide' rows='5' name='msg'></textarea><br></label><input type='submit' value='Наградить' name='ok'></form>";
include_once 'inc/foot.php';
}
else
{
//====================
echo "<div class='event'><h1>Список наград</h1></div>";
echo "<div class='block'>";
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='?nagrada=$ank[id]&do'>Сменить заслугу</a></div>";
$k_post = mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_nag` 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_nag` 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/nag/$post[id].png' alt='o'> <span class='title'>".hsc($post['name'])."</span><br/><span class='small minor'>За эту награду игрок получит: 
<b><font color='#808000'>$post[cena]</font></b><img width='16' height='16' src='img/icons/zkl.png' alt='o'>,
<b><font color='#808000'>$post[cenam]</font></b><img width='16' height='16' src='img/icons/money.png' alt='o'>,
<b><font color='#808000'>$post[cenae]</font></b><img width='16' height='16' src='img/euro.png' alt='o'> и 
<b><font color='#808000'>$post[cenab]</font></b><img width='16' height='16' src='img/icons/baks.png' alt='o'></span></span><br><a href='?nagrada=$ank[id]&do&cat=$cat[id]&nag=$post[id]'>Наградить игрока</a></div>";
}
if ($k_page>1)str("?nagrada=$ank[id]&do&cat=$cat[id]&",$k_page,$page); // Вывод страниц
echo "</ul>";
include_once 'inc/foot.php';
}
}
else
{
//====================
echo "<div class='event'><h1>Список наград</h1></div>";
echo "<div class='block'>";
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_nag_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='?nagrada=$ank[id]&do&cat=$post[id]'><span>".hsc($post['name'])."</span></a></div>";
}
}
echo "</ul><div></div></div>";
include_once 'inc/foot.php';
}
elseif(isset($_GET['del']) && intval($_GET['del'])!=NULL && mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_nagrada` WHERE `id` = '".intval($_GET['del'])."'"),0)!=0)
{

mysql_query("DELETE FROM `kolhoz_nagrada` WHERE `id` = '".intval($_GET['del'])."'");

header("Location:?nagrada=$ank[id]");
}
//include_once 'inc/foot.php';
}
/*else
{
header("Location:?user=$ku[id]");
}*/
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_nagrada` WHERE `id_user` = '$ku[id]' AND `read` = '0'"),0)!=0 && $ank['id']==$ku['id'])
{
mysql_query("UPDATE `kolhoz_nagrada` SET `read` = '1' WHERE `id_user` = '$ku[id]' AND `read` = '0'");
header("Location:?nagrada=$ku[id]");
}
echo "<ul>";
$k_post = mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_nagrada` 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_nagrada` 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;
$nag=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_nag` WHERE `id` = '$post[id_nag]'"));
echo "<div class='block'><img src='img/nag/$nag[id].png' alt='o'> <span class='title'>".hsc($nag['name'])."</span>";
if($ku['dostup']==1)echo " <a href='?nagrada=$ank[id]&del=$post[id]'><img width='16' height='16' src='img/icons/cross.png' alt='o'></a>";

echo "<br/><span>Наградил".($anku2['pol']==0?"a":null)."</span> ";
echo on_k($ank2['id']);
echo " <a class='' href='?user=$ank2[id]'>".nc($ank2['id'])."</a></span>";

$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/>";
}
else
if($ank2['id']){

//<font color='violet'>Награда за:</font><br/>
echo "<br/>".output_text($post['msg'], $ank2['id'])."";
echo " <span class='small minor'>(".vremja($post['time']).")</span>";
echo "<br/><font color='violet'>Эта награда принесла игроку:</font><br/><b><font color='#808000'>$nag[cena]</font></b><img width='16' height='16' src='img/icons/zkl.png' alt='o'>,
<b><font color='#808000'>$nag[cenam]</font></b><img width='16' height='16' src='img/icons/money.png' alt='o'>,
<b><font color='#808000'>$nag[cenae]</font></b><img width='16' height='16' src='img/euro.png' alt='o'> и 
<b><font color='#808000'>$nag[cenab]</font></b><img width='16' height='16' src='img/icons/baks.png' alt='o'>";
}//blok

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