<?
require_once 'system/common.php';
require_once 'system/functions.php';
require_once 'system/user.php';
$title = 'Бонус';
require_once 'system/h.php';
$gift = mysql_fetch_assoc(mysql_query("SELECT * FROM `user_podarok` WHERE `user_id` = '".$user['id']."' order by `last_auth` desc limit 1"));
$nagrada = rand(1,20);
$time = $gift['last_auth'] + 86400;
$now = time();
echo "<table class='post'>";

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

echo "<br /><div class=' '><center><b>Вы получили </b>$nagrada <img src='images/icon/gold.png'> золота</b> </div></center></br>";
		mysql_query("UPDATE `users` SET `g` = `g` + '$nagrada' WHERE `id` = '".$user['id']."'");






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

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


if ($time < $now) {
echo "<div class='title'>Бонус</div> <center><div class='content'><b>Каждый <span class='red'>день</span>, получай бонус в размере до 100 <img src='images/icon/gold.png' alt='o'> золота<span class='green'></span><span class='red'></span>.<br /> Приятной игры.</b>
<br><a class='submit' href='bonus.php?take'><span class='button'><span class='submit'>Забрать бонус</span></span></a></center></div>";
} else {
$hour_t = ceil(($time - $now) / 86400);
$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 "<center><b>Вы уже получали подарок.</br>Приходите через: <b><span class='green'>$min </span></b>мин.</b></centet><br>";
}
echo "</table></div>";
include_once 'system/f.php';
?>