<?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: capcha.php
*
*/


include(PATH.'/lib/connect.php');
include(PATH.'/lib/CofigFarm.php');
include(PATH.'/lib/func.php');

if(isset($_GET['ref']))
{
	$RefName = clean($_GET['ref']);
	setcookie("ref", $RefName, time() + 8640000, "/");
	$r = $mysql->prepare("UPDATE db_users SET CountClick = CountClick + ? WHERE Login = ?");
	$r->execute(array('1', $RefName));
	Header("Location: /");
	exit;
}


$ttt = time();
$b = $mysql->query("SELECT * FROM db_users WHERE ChatBan = 1 AND DateBanChat < '$ttt'");
if($b->rowCount() > 0){
	while($bb = $b->fetch())
	{
		$bbb = $mysql->prepare("UPDATE db_users SET ChatBan = ?, DateBanChat = ? WHERE Uid = ?");
		$bbb->execute(array(0, 0, $bb['Uid']));
	}
}

if(isset($_SESSION['id']) and $_SESSION['id'] > 0)
{
	$e = $mysql->prepare("SELECT * FROM db_users WHERE Uid = ?");
	$e->execute(array($_SESSION['id']));
	$User = $e->fetch();
	$cv = $mysql->prepare("SELECT * FROM db_chat_online WHERE UserId = ?");
$cv->execute(array($_SESSION['id']));
if(isset($_GET['page']) and $_GET['page'] == 'chat')
{
	
	if($cv->rowCount() == 0)
	{
		$gg = $mysql->prepare("INSERT INTO db_chat_online SET UserId = ?, Login = ?");
		$gg->execute(array($_SESSION['id'], $_SESSION['login']));
	}
}
else
{
	if($cv->rowCount() > 0)
	{
		$gg = $mysql->prepare("DELETE FROM db_chat_online WHERE UserId = ?");
		$gg->execute(array($_SESSION['id']));
	}
}
}


include(PATH.'/theme/head.php');

if(isset($_GET['page']))
{
	$page = clean($_GET['page']);
	switch($page)
	{
		case 'index': include(PATH.'/page/index.php'); break;
		case 'register': include(PATH.'/page/register.php'); break;
		case 'account': include(PATH.'/page/account.php'); break;
		case 'deposits': include(PATH.'/page/deposits.php'); break;
		case 'shop': include(PATH.'/page/shop.php'); break;
		case 'chat': include(PATH.'/page/chat.php'); break;
		case 'bonus': include(PATH.'/page/bonus.php'); break;
		case 'log': include(PATH.'/page/log.php'); break;
		case 'news': include(PATH.'/page/news.php'); break;
		case 'about': include(PATH.'/page/about.php'); break;
		case 'stats': include(PATH.'/page/stats.php'); break;
		case 'rules': include(PATH.'/page/rules.php'); break;
		case 'support': include(PATH.'/page/support.php'); break;
		case 'levels': include(PATH.'/page/levels.php'); break;
		case 'enter': include(PATH.'/page/enter.php'); break;
		case 'finances': include(PATH.'/page/finances.php'); break;
		case 'referals': include(PATH.'/page/referals.php'); break;
		case 'contests': include(PATH.'/page/contests.php'); break;
		case 'logout': include(PATH.'/page/logout.php'); break;
		case 'konkurs': include(PATH.'/page/konkurs.php'); break;
		case 'lost': include(PATH.'/page/lost.php'); break;
		case 'exchanger': include(PATH.'/page/exchanger.php'); break;
		default: include(PATH.'/page/404.php'); break;
	}
}
else
{
	include(PATH.'/page/index.php');
}
include(PATH.'/theme/foot.php');

?>