<?php
	
	include_once __DIR__ . '/include/common.php';
	include_once __DIR__ . '/include/general_functions.php';
	include_once __DIR__ . '/include/utils.php';	
	include_once __DIR__ . '/include/user.php';

	if ( ! @$user)
	{
		redirect('/');
	}
	
	$params	=	[];
	$params['title']	=	'Усиления героя';
	$params['list_errors']	=	[];
	
	ob_start();
	
	include_once __DIR__ . '/include/header.php';
	
	?>
	<div class='container cntr c_blue'>Мощные усиления героя - сила, опыт, награда!</div>
	<div class='min-line'></div>
	<?php
	
		$eff=	isset($_GET['eff'])?max(10, min(12, intval($_GET['eff']))):0;
	if ($eff!= 0 && isset($_GET['z']))
	{
		
		if ($_GET['z'] != $_SESSION['z'])
			$params['list_errors'][]	=	'Ошибка сессии';
		
		$_SESSION['z']	=	md5(mt_rand());
		
		if ($user['gold']<25)
			$params['list_errors'][]	=	sprintf(
				'Нехаватает <img src="/images/icon/gold.png" alt="" /> %d',
				25-$user['gold']
			);
		
		if (sizeof($params['list_errors'])==0)
		{
		
			@mysql_query(sprintf(
				'UPDATE
						`users`
					SET
						`gold`	=	`gold`	-	25
					WHERE
						`id`	=	%d',
				$user['id']
			));
			
			if (eff_exists($user['id'], $eff))
			{
				
				@mysql_query(sprintf(
					'UPDATE
							`user_eff`
						SET
							`time`	=	`time`	+	%d
						WHERE
							`user_id`
									=	%d
								AND
							`eff`	=	%d',
					((60*60)*24),
					$user['id'], $eff
				));
					
			}
			else
			{
				
				if ($eff==11)
				{
					
					@mysql_query(sprintf(
						'UPDATE
								`users`
							SET
								`str`	=	`str`	+	100,
								`dex`	=	`dex`	+	100,
								`protection`
										=	`protection`
													+	100,
								`life`	=	`life`	+	100
							WHERE
								`id`	=	%d',
						$user['id']
					));
					
				}
				
				@mysql_query(sprintf(
					'INSERT INTO
							`user_eff`
							(
								`user_id`,
								`eff`,
								`time`
							)
							VALUES
							(
								%d,
								%d,
								%d
							)',
					$user['id'], $eff, time()+((60*60)*24)
				));
				
			}
			
		}
		
	}
	?>
	<ul class='menu'>
		<li>
			<table>
			<tr>
			<td style='vertical-align:	top;'><img src='/images/effects/10.png' alt='' /></td>
			<td style='vertical-align:	top;'>
				<b>Основной эффект</b><br />
				<span class='small'><span class='c_l-green'>+50%</span> к опыту</span><br />
			</td>
			</tr>
			</table>
			<div class='cntr'>
	<?php
	if (eff_exists($user['id'], 10))
	{
		$timeleft	=	get_eff_timeleft($user['id'], 10);
	?>
				<span class='c_blue'>Осталось:</span> <?=timeleft($timeleft)?>
				<div class='spr-line'></div>
	<?php
	}
	?>
				<a href='/effshop?eff=10&z=<?=$_SESSION['z']?>' class='btn'>Купить за <img src='/images/icon/gold.png' alt='' /> 25</a>
			</div>
		</li>
		<li>
			<table>
			<tr>
			<td style='vertical-align:	top;'><img src='/images/effects/11.png' alt='' /></td>
			<td style='vertical-align:	top;'>
				<b>Боевой эффект</b><br />
				<span class='small'><span class='c_l-green'>+100</span> ко всем параметрам</span><br />
				<span class='small'><span class='c_l-green'>+25%</span> к опыту</span>
			</td>
			</tr>
			</table>
			<div class='cntr'>
	<?php
	if (eff_exists($user['id'], 11))
	{
		$timeleft	=	get_eff_timeleft($user['id'], 11);
	?>
				<span class='c_blue'>Осталось:</span> <?=timeleft($timeleft)?>
				<div class='spr-line'></div>
	<?php
	}
	?>
				<a href='/effshop?eff=11&z=<?=$_SESSION['z']?>' class='btn'>Купить за <img src='/images/icon/gold.png' alt='' /> 25</a>
			</div>
		</li>
		<li>
			<table>
			<tr>
			<td style='vertical-align:	top;'><img src='/images/effects/12.png' alt='' /></td>
			<td style='vertical-align:	top;'>
				<b>Добывающий эффект</b><br />
				<span class='small'><span class='c_l-green'>-25%</span> времени поиска и добычи ресурсов</span><br />
				<span class='small'><span class='c_l-green'>+25%</span> к опыту</span>
			</td>
			</tr>
			</table>
			<div class='cntr'>
	<?php
	if (eff_exists($user['id'], 12))
	{
		$timeleft	=	get_eff_timeleft($user['id'], 12);
	?>
				<span class='c_blue'>Осталось:</span> <?=timeleft($timeleft)?>
				<div class='spr-line'></div>
	<?php
	}
	?>
				<a href='/effshop?eff=12&z=<?=$_SESSION['z']?>' class='btn'>Купить за <img src='/images/icon/gold.png' alt='' /> 25</a>
			</div>
		</li>
	</ul>
	<?php
	
	include_once __DIR__ . '/include/footer.php';
	
	setContentType('text/html; charset=UTF-8');
	render(
		__DIR__ . '/include/template.php',
		ob_get_clean(),
		$params
	);
	
	?>
