<?php

/*
* @package BANANA WARS
* @copyright: (c) 2017 G.P. aka Mvcshka (mvcshka@yandex.ru)
* @license: GNU General Public License version 2; see LICENSE.txt
* @files: /page/bonus.php
*
*/

if(!isset($_SESSION['id']))
{
	Header("Location: /");
	exit;
}

?>

<?php

$q = $mysql->prepare("SELECT * FROM db_bonus WHERE UserId = ? ORDER BY Uid DESC LIMIT 1");
$q->execute(array($_SESSION['id']));
$qq = $q->fetch();
//$level = GetUser('Level', $_SESSION['id'];

?>
 <!-- OPEN CENTER -->
 <tr>
	<td align="left" valign="top">
		<table width="100%" border="0" cellspacing="0" cellpadding="0">
			<tbody>
				<tr>
					<td width="284" align="left" valign="top">
						<?php require('theme/users_block.php');?>
					</td><!-- MENU USER -->
					<td align="left" valign="top">
						<?php require('theme/menu.php'); ?>
						<div style="height:15px"></div>
						<div style="background:url('/images/title.jpg') no-repeat center;text-align:center"><span style="background-color:#F0E8D5;padding-right:15px;padding-left:15px;font-size:18px">Раздача бустеров </span></div>						
						<br />
						<table cellspacing="0" cellpadding="0" width="100%" align="center" border="0">
						<tbody>
							<tr>
								<td valign="top" class="rules" width="100%" style="padding-right: 10px;">
									<div align="center" style="vertical-align:middle;font-size:14px;font-weight: bold; width: 100%; background-color: rgb(232, 220, 196);">Бустеры: <img align="absmiddle" src="/images/index-icons/buster_dark.jpg"><?=intval($User['MoneyIn']); ?>&nbsp;&nbsp;Деньги: <img align="absmiddle" src="/images/index-icons/money_dark.jpg"><?=intval($User['MoneyOut']); ?></div>
									<br>
									
									<?php if($qq['LastDate'] < time()) { ?>
									<div id="exc_select">
									<table cellpadding="0" cellspacing="0" border="0" width="100%">
										<tbody>
											<tr>
												<td align="center">
												<span style="text-decoration:none" onclick="process('','/process/bonus.php?action=take','bonusResult','bonusResult','bonus')">
													<div class="exchange1" onmouseover="this.className='exchange1_on';" onmouseout="this.className='exchange1';">
														<table width="224" border="0" cellpadding="0" cellspacing="0" style="font-weight:bold">
															<tbody>
															<tr>
																<td colspan="3" style="height:56px">&nbsp;</td>
															</tr>
															<tr>
																<td width="100" style="padding-left:7px;padding-top:12px;text-align:center;font-size:16px;color:#e24319">1</td>
																<td width="34">&nbsp;</td>
																<td width="100" style="text-align:center;padding-right:0px;padding-top:13px;"><font style="font-size:12px;color:#7e8600"><?=$BonusSum[GetUser('Level', $_SESSION['id'])]; ?></font></td>
															</tr>
															</tbody>
														</table>
													</div>
												</span>
												</td>
												<td rowspan="2" width="200"><img src="/images/buy_buster.jpg"></td>
												<td align="center">
												<a href="javascript:void(0)" style="text-decoration:none" onclick="trade('10')">
													<div class="exchange2" onmouseover="this.className='exchange2_on';" onmouseout="this.className='exchange2';">
														<table width="224" border="0" cellpadding="0" cellspacing="0" style="font-weight:bold">
															<tbody>
															<tr>
																<td colspan="3" style="height:56px">&nbsp;</td>
															</tr>
															<tr>
																<td width="100" style="padding-left:7px;padding-top:12px;text-align:center;font-size:16px;color:#e24319">10</td>
																<td width="34">&nbsp;</td>
																<td width="100" style="text-align:center;padding-right:0px;padding-top:13px;"><font style="font-size:12px;color:#7e8600">$5.000</font>
																	<font style="font-size:11px;color:#e24319">+500</font>
																</td>
															</tr>
															</tbody>
														</table>
													</div>
												</a>
												</td>
											</tr>
											<tr>
												<td align="center">
						
												</td>
												<td align="center">

												</td>
											</tr>
										</tbody>
									</table>
									</div>

									<?php } else { ?>
									
									<table border="0" width="100%" bgcolor="#aab9b4" cellpadding="0" cellspacing="1">
									<tbody>
										<tr>
											<td bgcolor="#f6f1e4" style="padding:4">
												<table border="0" cellpadding="4" cellspacing="0" width="100%">
												<tbody>
													<tr>
														<td valign="middle" width="31px"><img src="/images/icons/green.gif" width="31px" height="31px" align="left" style="margin-right:5"></td>
														<td>До следующей выдачи бустеров осталось : <span id="timer" style="color:#E24319; font-size:15px;">--:--:--</span></td>
													</tr>
												</tbody>
												</table>
											</td>
										</tr>
									</tbody>
									</table>

									<?php
													
									$time = $qq['LastDate'] - time();
									$timeU = $time; 
									//минуты часы и дни  в секундах: 
									$min = 60; 
									$hour = 60 * 60; 
									$day = 60 * 60 * 24; 
									$r_days = floor ($timeU / $day); 
									$r_hours = floor (($timeU - ($r_days * $day))/$hour); 
									$r_min = floor (($timeU - ($r_days * $day) - ($r_hours * $hour))/$min); 
									$r_sec = (($timeU - ($r_days * $day) - ($r_hours * $hour) - ($r_min * $min)));

									?>
									<script type="text/javascript">
										var hour = <?=(int)$r_hours; ?>;
										var minute = <?=(int)$r_min; ?>;
										var second = <?=(int)$r_sec; ?>;
											
										function timer() {	
											$("#timer").html((hour < 10 ? "0"+hour : hour)+":"+(minute < 10 ? "0"+minute : minute)+":"+(second < 10 ? "0"+second : second));
											--second;
											if(second < 0) {
												--minute;
												if(minute < 0) {
													--hour;
													if(hour < 0) {
														clearInterval(timer_id);
													}
													minute = 59;
												}
												second = 59;
											}
										}
										timer();
										timer_id = setInterval('timer()',1000);
									</script>


									<?php } ?>
									<br /><br/ >
									<table border="0" cellspacing="0" cellpadding="0" bgcolor="#E8DCC4" width="100%">
										<tbody>
											<tr>
												<td height="8px" width="8px"><img width="9" height="9" src="/images/form-up-left.gif"></td>
												<td></td>
												<td align="right"><img width="9" height="9" src="/images/form-up-right.gif"></td>
											</tr>
											<tr>
												<td style="padding:11px 20px" colspan="3">
													<table id="lastResult" class="maintable" border="0" width="100%" cellspacing="0" cellpadding="4">
														<tbody>		
																<script type="text/javascript">process('','/process/bonus.php?action=last','lastResult','lastResult','last')</script>	
														</tbody>
													</table>						
												</td>
											</tr>
										</tbody>
									</table>
									<p>
									<table border="0" width="100%" bgcolor="#aab9b4" cellpadding="0" cellspacing="1">
									<tbody>
										<tr>
											<td bgcolor="#f6f1e4" style="padding:4">
												<table border="0" cellpadding="4" cellspacing="0" width="100%">
													<tbody>
														<tr>
															<td valign="middle" width="31px"><img src="/images/icons/help.gif" width="31px" height="31px" align="left" style="margin-right:5"></td>
															<td> Выдача бустеров, осуществляеться только один раз в сутки! </td>
														</tr>
													</tbody>
												</table>
											</td>
										</tr>
									</tbody>
									</table>
									</p>
								</td>
							</tr>
						</tbody>
						</table>						
					</td><!-- CONTENT USER -->
				</tr>
			</tbody>
		</table>
	</td>
</tr>
<!-- CLOSE CENTER -->