<?php
//show all errors
  error_reporting (E_ALL);
  ini_set("display_errors","TRUE");

//standart includes, vars and constants
  $page="";
  if (isset($_GET['page'])) $page=$_GET['page'];
  $BODY    = ""; //the page content
  $ERROR   = ""; //error messages
  $COMMENT = ""; //comments
  if (isset($_GET['to_do'])) define ("TO_DO",$_GET['to_do']);
  else define ("TO_DO","");
  $db = mysqli_connect("localhost","poker","*******", "poker");
  include("globals.php");
  include("functions.php");

//User Login
  if (!session_start()) $ERROR.="Server Session kann nicht eingerichtet werden, kein login m&ouml;glich!<br>";
  if (TO_DO=="login") {
    $login=$_POST['login'];
    $query=mysqli_query($db, "SELECT `password` FROM `player` WHERE `alias` = '$login' AND `password` IS NOT NULL LIMIT 0 , 30");
    $data=mysqli_fetch_array($query);
    if ($data!==NULL && $data!==False && password_verify($_POST['password'], $data['password'])) {
      $_SESSION['login']=$login;
    } else {
        $ERROR.="Login nicht erfolgreich!<br>";
    }
  }
  if ($page=="logout") {
    $_SESSION['login']="";
    $page="";
  }
  if (isset($_SESSION['login'])) define ("LOGIN",$_SESSION['login']);
  else define ("LOGIN","");
  if (LOGIN!="") {
    $BODY.='<table class="list" width="100%"><tr><th style="text-align:left">'.add_icon('user')."&nbsp;&nbsp;".LOGIN."&nbsp;&nbsp;&nbsp;&nbsp;";
    $BODY.='<a class="list" href="index.php?page=edit_game&to_do=new_game">'.add_icon("new_game").'Neues Spiel</a>&nbsp;&nbsp;&nbsp;&nbsp;';
    $BODY.='<a class="list" href="index.php?page=rank&to_do=update_rank">'.add_icon("arrow_out").'Rangliste Aktualisieren</a>&nbsp;&nbsp;&nbsp;&nbsp;';
    $BODY.="</th></tr></table>";
  }
  $BODY.="<br><br>";

//include the requestet page
  if      ($page=="login") include ("login.php");
  elseif ($page=="rank" )  include ("rank.php" );
  elseif ($page=="games" ) include ("games.php" );
  elseif ($page=="edit_game" ) include ("edit_game.php" );
  elseif ($page=="poker_pott") include("poker_pott.php");
  else include ("main.php");

//include the Template
  include ("template.php");

//End of Script
  mysqli_close($db);
?>
