<meta charset="UTF-8">
<?php
// Martin Taťák diplomová práce 2016

require_once("classes/Mysql.php");
require_once("utils/utils.php"); 

//ini_set('display_errors', '1');
error_reporting(E_ALL);                        
session_start();
                                          
if(isset($_POST['login']) && !empty($_POST['login'])){
$m = new Mysql();
$sql = "SELECT ID FROM uzivatele WHERE user = '".$_POST['userName']."' AND pass = '".$_POST['userPass']."'";
$mysql_result = $m->dotaz($sql) or die('Query failed: ' . mysql_error());

if ($mysql_result == FALSE){
		echo("mysql_result fail");
	} else {
		if ($m->pocetRadku($mysql_result)==1) {
			$user = $m->podejRadek($mysql_result);
			session_start();

			//$_SESSION['expire'] = time()+3600;
			$_SESSION['userID'] = $user->ID;
			$_SESSION['name'] = $_POST['userName'];
			//setcookie('name', $_POST['userName']);
			$_SESSION['userPass'] = $_POST['userPass'];
			//setcookie('pass', $_POST['userPass']);
			

			//redirect();
			//exit();
		} else
        echo ("<script>alert('SPATNE JMENO NEBO HESLO!');</script>");
	}
}else if($_GET['sekce']== "odhlaseni"){
  end_session();
}


include("pages/header.html"); 

if (is_logged()){
  $sekce = "domu";
  if (isset($_GET['sekce'])){
    $sekce = $_GET['sekce'];
  }

  echo GenerateMenu($sekce);

  if (!empty($_GET['sekce'])) { 
    $sekce = $_GET['sekce'];  
    $sekce = basename($sekce);  
    include("pages/$sekce.php");  
  }
  else{
    include("pages/domu.php");
  }
}else{
//  end_session(); 
                              
?>

<img src="pictures/logicon.png" style="display:block;  margin:auto;">
<br>
<div align="center">
<form id="log_form" method="POST" action="index.php">
  <label id="prepazka1" ></label>
	<label id="inputName" class="menu_font" for="userName">JMÉNO </label>
  <input type="text" id="userName" name="userName" required>
	<label id="inputPass" class="menu_font" for="userPass">HESLO </label>
  <input type="password" id="userPass" name="userPass" required>
	<input type="hidden" name="screenWidth" id="screenWidth" value="1024">
	<input type="hidden" name="screenHeight" id="screenHeight" value="720">
	
	<label id="prepazka2" ></label>
	<input type="submit" name="login" id="logSent" value="Přihlásit"">
</form>
</div>
          
<?php
}

include("pages/footer.html");
?>

