<?php
define('PROTECTOR', 1);

include('files/db.php');
include('files/auth.php');
include('files/func.php');
$textl='Ежедневные подарки';
include('files/core.php');
include('files/head.php');
include('files/zag.php');


$gift = mysql_fetch_assoc(mysql_query("SELECT * FROM `user_podarok` WHERE `id` = '$udata[id]' order by `last_auth` desc limit 1"));

$time = $gift['last_auth'] + 3600*24;
$now = time();
echo "<table class='post'>";

if(isset($_GET['take'])){
if ($time < $now) {

echo "<div class='main'><br /><center><b>Вы получили <img width='16' height='16' src='image/icon/almaz.png' alt='o'> 200!</b></center></div></br>";
		mysql_query("UPDATE `users` SET `almaz` = `almaz` + '200' WHERE `id` = '$udata[id]'");





if(mysql_result(mysql_query("SELECT count(id) from `user_podarok` where `id` = '".$udata['id']."'"),0) == 0){
mysql_query("INSERT INTO `user_podarok` SET `last_auth` = '$now', `stage` = '1', `id` = '$udata[id]'");
}else{
        mysql_query("UPDATE `user_podarok` SET `last_auth` = '$now', `stage` = `stage` + '1' WHERE `id` = '$udata[id]'");
}

} else {
echo "</br></br>";
}
}


if ($time < $now) {
echo "<div class='main'><br><center><b>Раз в день вы можете получать <img width='16' height='16' src='image/icon/almaz.png' alt='o'> 200
<form action='bon.php?take' method='post'><br/>
<span class='btn'><span class='end'><input class='label' type='submit' value='Забрать бонус'></span></span></form></div>
</form></center>";
} else {
$hour_t = ceil(($time - $now) / 3600);
$min = ceil(($time - $now) / 60);
if ($hour_t == 1 or $hour_t == 21) {
$hour = 'час';
} elseif ($hour_t >= 2 and $hour_t <= 4 or $hour_t >= 22 and $hour_t <= 24) {
$hour = 'часа';
} elseif ($hour_t >= 5 and $hour_t <= 20) {
$hour = 'часов';
}
echo "<div class='main'><center><b>Следующий подарок через: <b><span class='green'>$hour_t </span></b>часа.</b></centet></div>";
}

if($time < 1){
echo'<div class="main"><div class="block_zero center"><img src="/image/!.png" alt=""/> Вы уже получали бонус</div></div>';
include($path.'files/down.php');exit;
}
echo "</table>";


include($path.'files/down.php');
?>