bjack/controllers/content.php
2012-03-13 11:36:26 +01:00

133 lines
2.4 KiB
PHP

<?php include(SITE_ROOT . "/include/" . "config.inc.php"); ?>
<div id="wrapper">
<?php
/*
* Let's check our database connection
*/
require_once(SITE_ROOT . "/models/" . "database.php");
$database = new Database();
$db = $database->connect();
if (!$db == 0) {
echo "BJack is not fully installed, please run install.php!";
} else {
$page = $_SERVER["QUERY_STRING"];
if (!$page || $page == "menu") {
/*
* Here comes the front page
*/
include(SITE_ROOT . "/templates/" . "menu.tpl.php");
} else if ($page == "login") {
/*
* User, password, ...
*/
session_start();
if(isset($_SESSION["user"])) {
include(SITE_ROOT . "/templates/" . "game.tpl.php");
} else {
include(SITE_ROOT . "/templates/" . "login.tpl.php");
}
} else if ($page == "logout") {
/*
* Destroy session
*/
require_once(SITE_ROOT . "/models/" . "bjack.php");
$bjack = new BJack();
$bjack->destroySession();
include(SITE_ROOT . "/templates/" . "logout.tpl.php");
} else if ($page == "game") {
/*
* Game
*/
/* Validate data */
$user = $_POST["user"];
$pass = $_POST["pass"];
if ($user == "name" || $user == "" || $pass == "password" || $pass == "") {
include(SITE_ROOT . "/templates/" . "invalid.tpl.php");
} else {
/*
* Data is valid
* - check database for existing user
* - create new user
*/
require_once(SITE_ROOT . "/models/" . "database.php");
$database = new Database();
$checkuser = $database->checkUser($user, $pass);
if ($checkuser == 2 || $checkuser == 0) {
/* Create shuffled deck and store everything into session */
session_start();
if (!isset($_SESSION["num"])) {
require_once(SITE_ROOT . "/models/" . "bjack.php");
$bjack = new BJack();
$deck = $bjack->generateShuffledDeck();
$_SESSION["deck"] = $deck;
$_SESSION["num"] = 0;
$_SESSION["score"] = 0;
}
$_SESSION["user"] = $user;
include(SITE_ROOT . "/templates/" . "game.tpl.php");
} else {
include(SITE_ROOT . "/templates/" . "invalid.tpl.php");
}
}
} else if ($page == "impressum") {
/*
* Impressum
*/
include(SITE_ROOT . "/templates/" . "impressum.tpl.php");
} else if ($page == "highscores") {
/*
* Highscores
*/
include(SITE_ROOT . "/templates/" . "highscores.tpl.php");
} else {
/*
* 404
*/
include(SITE_ROOT . "/templates/" . "404.tpl.php");
}
}
?>
</div>