<?php
session_start();
// načtení souboru header.php
require_once "includes/header.php";
// připojení k databázi MySQL
include "includes/db_init.php";

?>

<?php
// 
// COPYRIGHT BY THE AUTHORS OF WEBWHITELISTER 
// ALL RIGHTS RESERVED.
//

// CONFIG: PLEASE INSERT YOUR MYSQL INFORMATION
	$sql_host = "srv.mojecs.eu";
	$sql_username = "H4X0R";
	$sql_password = "852852";
	$sql_database = "H4X0R";
	$server_name = "mancraft.eu";
	$enable_mc_premium_check = false;
	
// DONT EDIT ANYTHING BELOW HERE; UNLESS YOU KNOW WHAT YOU ARE DOING
	session_start();
	require_once("./script/captcha/simple-php-captcha.php");
	
	if($_SERVER['REQUEST_METHOD'] == "POST" && isset($_SESSION['captcha']['code']) && isset($_POST['captcha'])) {
//Check if captcah is correct
		if($_SESSION['captcha']['code'] != $_POST['captcha'])
			die("<META HTTP-EQUIV='Refresh' CONTENT='3'; URL='http://mancraft.eu/cpanel'> Captcha is not correct!");			
		
//Check if username is set
		if($_POST['name'] == "")
			die("<META HTTP-EQUIV='Refresh' CONTENT='3'; URL='http://mancraft.eu/cpanel'> Please insert a username!");	
			
//Check if the inserted MC username exists
		if($enable_mc_premium_check and !check_user($_POST['name']))
			die("<META HTTP-EQUIV='Refresh' CONTENT='3'; URL='http://mancraft.eu/cpanel'> The inserted username is not a Minecraft premium account.");
			
//Whitelist the player
		mysql_connect($sql_host, $sql_username, $sql_password) or die("ERROR: ".mysql_error());
		mysql_select_db($sql_database) or die("ERROR: ".mysql_error());

		mysql_query("INSERT INTO `WEBWHITELISTER` (`USERNAME`, `WHITELISTED`) VALUES ('" . 			mysql_real_escape_string($_POST['name']) . "', false) ;") or die("ERROR: ".mysql_error());
		die("Uživatel pridaný na whitelist <META HTTP-EQUIV='Refresh' CONTENT='3'; URL='http://mancraft.eu/cpanel'> automaticky budete presmerovaný do Cpanelu");
	} else {
		$_SESSION['captcha'] = captcha();
	}
	
	function check_user($mcUser) {
		$check_mcUser = file_get_contents('http://www.minecraft.net/haspaid.jsp?user='.$mcUser.'');
		if ($check_mcUser == "true")
			return true;
		else
			return false;
	}
?>

<?php

if ($login->is_logged==1){
// zde bude kód stránek provedený při přihlášeném uľivateli

?>

 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN">
<html>
  <head> 
  <link rel="stylesheet" href="style.css" type="text/css" media="screen">
  <meta http-equiv="content-type" content="text/html; charset=windows-1250">
  <meta name="generator" content="PSPad editor, www.pspad.com">
  <title>WhiteList Cpanel v1.0</title>
  </head>
  <body>
  
<center><img src='http://minecraft.mancraft.eu/wp-content/uploads/2012/09/head.png' /></center>
  <div id="bady" align="center">
  <p>
  <!DOCTYPE html>
<html>
<head>
 <center>
<!DOCTYPE html>
<html>
<head>
<LINK href="./css/whitelist.css" rel="stylesheet" type="text/css">
<meta charset="windows-1250">
<title>Whitelist formulár pre <?php echo $server_name; ?></title>
</head>
<body>

<div id="stylized" class="myform">
<form id="form" name="form" method="post" action="">
<h1>Pridať do WL na servery <?php echo $server_name; ?></h1>
<p>Ak chcete pridať hráča na WhiteList vyplňte formulár.</br><b><font color='red'>Rozlišujte veľkosť písmen</font></b></p>
<hr />

<label>Nick
<span class="small">Minecraft Nick</span>
</label>
<input type="text" name="name" id="name" />

<label>AntiSpam
<span class="small"></span>
</label>
<img src="<?php echo $_SESSION['captcha']['image_src']; ?>" alt="CAPTCHA" />

<label>Ľudské overenie
<span class="small">Kód z AntiSpam</span>
</label>
<input type="text" name="captcha" id="captcha" />

<button type="submit">Pridať na WhiteList!</button>
<div class="spacer"></div>
</form>
<br>
<br>
<br>
<br>
<br><br><br>


</div>
    <?php
if ($login->is_logged==1){
	echo "<center>Prihlásený: <strong>".$login->login_name."  &nbsp <br> ".$login->firma."</strong> <br> <a href='?logout=1'><img src='images/log_off.png'></a></center>&nbsp;";
}
?>
  </center>
  </body>
</html> </p>
  </div>
  
  </body>
</html>


<?php

} else {
// zde bude kód stránek provedený při nepřihlášeném uživateli

?>
<?php
	// zobrazení přihlašovacího formuláře
	$login->show_login_form();
}
?>