<?php
$title ='Драконоборцы ';
include_once 'protected/sys.php';

if (!isset($user)){

	if (isset($_POST['name']) && isset($_POST['password']))
	{
		$nameAuth = trim(htmlspecialchars($_POST['name']));
		$passwordAuth = trim(htmlspecialchars($_POST['password']));

		if ($nameAuth == 'Боец')
		{
			header("Location:/");
			exit;
		}


       	$sqlAuth = "SELECT * FROM `users` WHERE `login`=? and `password`=?";
       	$plAuth = array($nameAuth,$passwordAuth);

		$rowsAuth = $db->rows($sqlAuth,$plAuth);	

		if ($rowsAuth == 1)
		{
			$AuthClient = $db->fetch($sqlAuth,$plAuth);

			$_SESSION['id'] =  $AuthClient['id'];
			$_SESSION['password'] =  $passwordAuth;

			header("Location:/");
		}
		else
		{
			?>
		<center>
			<font color ='red'/>
			Не верный логин или пароль
			</font>
		</center>
			<?
		}
	} 


	?>

<img style="top: 0" width="100%" src="http://mdrag.ru/style/css/img/logo.jpg" alt="" />
<div style="margin-top: -2px" class="wrapper center">
    <span class="rarity _5">Драконоборцы</span> <span class="high"> - погрузись в мир объятый пламенем легендарных драконов!</span>
</div>
<div class="wrapper-btn">
    <a class="btn _green" href="/start">Начать игру</a>
</div>
<div class="wrapper center _form">
        <form action="" method="post">
        Логин:<br />
        <input type="text" name="name" maxlength="20" value="" /><br />
        Пароль:<br />
        <input type="text" name="password" maxlength="20" value="" /><br />
        <input class="btn _blue" type="submit" value="Войти" /><br />
        <a href="/password_recovery.php"><span class="unline"><small>Забыли пароль?</small></span></a>
    </form>
</div>    </div>
    <div class="footer">
        <small>
	<?
}
elseif(isset($user))
{
	$tt = $user['fights_reset'] - $config['time'];
	$h = $tt/3600%60;
	$m = $tt/60%60;
	$s = $tt%60;

	$tur = $db->rows("SELECT `status`,`end` FROM `arena_turnir` WHERE `status`='active' and `end`>?",
							array(time()));


		if($user['read_news'] == 1){
		?>

		<a class="menu" href ="/news"/><img src='/imgData/static/news.png'/> 
		<span class = 'q5'>
			Новости [+]
		</span> </a>
		<? } 


?>
		  <a style="margin-top: 1px" class="wrapper _shop" href="/boss.php">
        <div class="t">
            <span class="item _dungeon">
                <i></i>
            </span>
            <p>
                <span class="high">Подземелье</span>                <br >
                
            </p>
        </div>
    </a>
<?
if ($user['fights'] == 0 && $user['fights_reset'] > $config['time'])
{
	$tt = $user['ohota_time'] - time();
	$h = $tt/3600%60;
	$m = $tt/60%60;
	$s = $tt%60;
?>

		<a style="margin-top: 1px" class="wrapper _shop" href="/arena.php">
    <div class="t">
        <span class="item _hunting">
            
        </span>
        <p>
            <span class="high">Арена</span> </br>    До боя: <?=$h;?>ч <?=$m;?>м <?=$s;?>с.             
            
        </p>
    </div>
</a>
<?
}else{

?>

		<a style="margin-top: 1px" class="wrapper _shop" href="/arena.php">
    <div class="t">
        <span class="item _hunting">
           
        </span>
        <p>
            <span class="high">Арена</span>  </br>    в бой      
            
        </p>
    </div>
</a>
<?
}
?>
    <a style="margin-top: 1px" class="wrapper" href="/dragon">
        <div class="t">
            <span class="item _drag">
                <i></i>
            </span>
            <p>
                <small>
                    Логово дракона<br />
                    <span class="high">Костяной дракон</span><br />
                                            Остались бои: <?=$user['artem_aluka']?>                                    </small>
            </p>
        </div>
    </a>

<?

if ($user['ohota'] == 0 && $user['ohota_time'] > $config['time'])
{
	$tt = $user['ohota_time'] - time();
	$h = $tt/3600%60;
	$m = $tt/60%60;
	$s = $tt%60;


	?>
<a style="margin-top: 1px" class="wrapper _shop" href="/ohota.php">
    <div class="t">
        <span class="item _hunting">
            <i></i>
        </span>
        <p>
            <span class="high">Охота</span>            <br >
            <small>
                До боя: <?=$h;?>ч <?=$m;?>м <?=$s;?>с.            </small>
        </p>
    </div>
</a>
<?
}else{
?>
<a style="margin-top: 1px" class="wrapper _shop" href="/ohota.php">
    <div class="t">
        <span class="item _hunting">
            <i></i>
        </span>
        <p>
            <span class="high">Охота</span>            <br >
            <small>
                В бой       </small>
        </p>
    </div>
</a>
<?
}
?>

 <a class="menu _icon _travel" href="/campaign.php">Поход</a>

<a class="menu _icon _travel" href="/travel.php">Путешествие</a>

	<div class="menuList">
		 <a class="menu _icon _shop" href="/shop">Магазин</a>
		<a class="menu" href ="/arena_turnir"/> <img src='/imgData/static/best.png'/> Турнир Арены <?=($tur == 1 ? '<span class=\'win\'/>[+]</span>':null);?></a></li>

<a class="menu _icon _training" href="/train.php">Тренировка</a>
      <a class="menu _icon _company" href="/company.php">Кампания</a>
 
		<a class="menu" href ="/rating"/><img src='/imgData/static/best.png'/> Рейтинг </a></li>
<a class="menu" href ="/clan_reit"/><img src='/imgData/static/best.png'/> Список кланов</a></li>
		<a class="menu" href ="/forum"/><img src='/imgData/static/shop.png'/> Форум </a></li>
		<a class="menu" href ="/pay/buy.php"/><img src='/imgData/static/gold.png'/> Купить золото </a></li>
	</div>
	<?

}



include_once 'protected/footermain.php';