<?
if(isset($_GET['active'])){
$post=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_key` WHERE `id` = '".intval($_GET[active])."' AND `id_user`='$ku[id]'"));
if(empty($post[time])){$err=1;}
if(empty($err)){
if($ku[keytime]<=$time){$vrem=$time+$post[time];}else{$vrem=$ku[keytime]+$post[time];}
mysql_query("UPDATE `kolhoz_user` SET `keytime` = '$vrem' WHERE `id` = '$ku[id]' LIMIT 1");
mysql_query("DELETE FROM kolhoz_key WHERE id=".intval($_GET[active])."");
header("Location:?nk&msg");
}else{header("Location:?nk&err");}
}
if(isset($_GET['msg'])){
echo "<div class='feedback'><img width='16' height='16' src='images/icons/pkey.png' alt='o'>Ключ успешно активирован</div>";
}
if(isset($_GET['err'])){
echo "<div class='feedback'>Произошла ошибка</div>";
}
echo "<div class='event'><h1>Погреб</h1></div>";
echo "<div class='content'>";
echo "<div class='block'>";
$coun = mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_key` WHERE `id_user` = '$ku[id]'"),0);
$ku['pkey']=$coun;
if($ku['pkey']>=1){
if($ku['pkey']==1){$tex="Ключ";}
if($ku['pkey']>=2 and $ku['pkey']<=4){$tex="Ключа";}
if($ku['pkey']>=5 and $ku['pkey']<=20){$tex="Ключей";}
$rest = substr("$ku[pkey]", -1);
if($ku['pkey']>=21 and $rest==1){$tex="Ключ";}
if($ku['pkey']>=21 and $rest>=2  and $rest<=4){$tex="Ключа";}
if($ku['pkey']>=21 and $rest>=5){$tex="Ключей";}
if($rest==0){$tex="Ключей";}

echo"У вас <img width='16' height='16' src='images/icons/pkey.png' alt='o'> $ku[pkey] $tex<br/>";
$q=mysql_query("SELECT * FROM `kolhoz_key` WHERE `id_user` = '$ku[id]'");
$i=1;
while($post=mysql_fetch_array($q))
{
echo "Ключ $post[id] (Срок: ".time_left($post['time']).") <a href='?nk&active=$post[id]'>[Активировать]</a><br/>";
$i++;
}
}else{
echo "<span>У Вас отсутствует ключ<br/>";}
echo"<br/> <img width='16' height='16' src='images/icons/immob.png' alt='o'> <a href='http://immob.ru'>Купить ключ на immob.ru</a><br/>";
echo "</ul></div>";
include_once 'inc/foot.php';
?>