<?php
include_once ('core/base.php');
include_once ('core/head.php');

if(!isset($u)){
$_REQUEST['success'] = fl($_REQUEST['success']);

if($_REQUEST['success']){
	$name = fl($_POST['login']);
	$pass = fl($_POST['password']);
	$sql = $base -> query("SELECT `login`,`password` FROM `users` WHERE `login` = '".$name."' and `password`='".md5($pass)."' LIMIT 1")  -> fetch_assoc();
	if(empty($name)) error('Введите логин.');
	elseif(empty($pass)) error('Введите пароль.');
	elseif($sql == 0) error('Такой пользователь не найден.');
	else {
		setcookie('login', $name, time()+86400*365, '/');
		setcookie('password', md5($pass), time()+86400*365, '/');
		header('location: /');
	}
}

	echo '<div class="b">';
	echo '<center><img src="/images/main_logo.png" style="width: 100%; max-width: 360px;"></center>';
	echo '<div class="line"></div>';
	echo '<center>Добро Пожаловать в Авалор!<br/>';
	echo 'Каждому новичку <img src="/images/icons/vip.png"><font color="gold">VIP</font> на сутки, в подарок!</center>';
	echo '<div class="line"></div>';
	echo '<center><a href="/start/"><img style="max-width: 100%" src="/images/go.png"></a></center>';
	echo '<div class="line"></div>';
	//echo '<a class="btn" href="/auth/"><img src="/images/icons/key.png"> Авторизация </a>';
	echo '<form action="" method="post">';
		echo '<center>';
		echo 'Логин:<br/>';
		echo '<input type="text" name="login" placeholder="Введите свой логин..."></br>';
		echo 'Пароль: <br/>';
		echo '<input type="password" name="password" placeholder="Введите свой пароль..."></br>';
		echo '<center><input class="green" type="submit" name="success" value="Войти"></center>';
		echo '</center>';
	echo '</form>';
	echo '</div>';

}else{
	echo '<div class="b">';
	echo '<center><img src="/images/avalor.png"></center>';
	//Ивенты
	if($event){
		echo '<div class="title"><img src="/images/icons/'.$event['image'].'_token.png"> '.$event['name'].' <img src="/images/icons/'.$event['image'].'_token.png"></div>';
		if($event['step'] == 1){
			$event_end_time = $event['end_time'] - time();
			echo '<div class="event"><center>
			<font color="#B1B1B1">До конца события:</font> <b>'.tl($event_end_time).'</b><br/>
			<div class="only_line"></div>
			<a class="btn_small" href="/event/">Подробнее</a>
			</center></div>';
		}elseif($event['step'] == 2){
			echo '<div class="event"><center>
			<font color="#B1B1B1">Событие</font> <b>'.$event['name'].'</b> <font color="#B1B1B1">окончено!</font><br/>
			<div class="only_line"></div>
			<a class="btn_small" href="/event/">Подробнее</a>
			</center></div>';
		}
	}
echo '<center>';
echo '<div class="title">Меню</div>';
echo '<table style="width: 100%; max-width: 350px;"><tr>';
			$topics_nr = $base -> query('SELECT * FROM `forum_topics`') -> num_rows;
			echo '<td valign="top" width="33%">
			<center><a href="/forum/"><div class="big_btn"><img src="/images/icons/forum.png"><br/>Форум ('.n_f($topics_nr).')</td>';
			$chat_nr = $base -> query('SELECT * FROM `chat`') -> num_rows;
			$tradechat_nr = $base -> query('SELECT * FROM `tradechat`') -> num_rows;
			echo '<td valign="top" width="33%">
			<center><a href="/chat/"><div class="big_btn"><img src="/images/icons/fearrow.png"><br/>Чат ('.n_f($chat_nr).'/'.n_f($tradechat_nr).')</td>';
			echo '<td valign="top" width="33%">
			<center><a href="/help/"><div class="big_btn"><img src="/images/icons/info.png"><br/>Помощь</td>';
			echo '</tr><tr>';
			echo '<td valign="top" width="33%">
			<center><a href="/rating/"><div class="big_btn"><img src="/images/icons/statue.png"><br/>Рейтинг</td>';
			$on = $base -> query("SELECT * FROM `users` WHERE `date_online` > '".(time()-600)."'") -> num_rows;
			echo '<td valign="top" width="33%">
			<center><a href="/online/"><div class="big_btn"><img src="/images/icons/online.png"><br/>Онлайн ('.$on.')</td>';
			echo '<td valign="top" width="33%">
			<center><a href="/gold/"><div class="big_btn"><img src="/images/icons/gold_24.png"><br/><font color="gold"><b>Золото</b></font></td>';
	echo '</tr></table></center>';
	if($u['admin'] > 1) echo '<a class="btn" href="/panel/"><img src="/images/icons/admin.png"> Панель управления</a>';
	if($u['partner_utm'] != '') echo '<a class="btn" href="/partner/"><img src="/images/icons/admin.png"> Партнерка</a>';
	echo '</div>';
}

include_once ('core/foot.php');
?>