diff --git a/html/index.php b/html/index.php index 5687d2e..48c5862 100755 --- a/html/index.php +++ b/html/index.php @@ -7,14 +7,22 @@ ob_start(); $url = $_SERVER['REQUEST_URI']; $url = preg_replace('/\?.+\=.+/m', '', $url); -if ($url === '/') { +if ($url === '/' && !isAuthorized()) { include __DIR__ . '/../templates/index.html.php'; -} elseif ($url === '/login' && $_SERVER['REQUEST_METHOD'] === "GET") { +} elseif ($url === '/' && isAuthorized()) { + header('Location: /dashboard'); +} elseif ($url === '/login' && $_SERVER['REQUEST_METHOD'] === "GET" && !isAuthorized()) { include __DIR__ . '/../templates/login.html.php'; +} elseif ($url === '/login' && $_SERVER['REQUEST_METHOD'] === "GET" && isAuthorized()) { + header('Location: /dashboard'); } elseif ($url === '/login' && $_SERVER['REQUEST_METHOD'] === "POST") { include __DIR__ . '/../php/login.php'; +} elseif ($url === '/update' && $_SERVER['REQUEST_METHOD'] === "POST" && isAuthorized()) { + include __DIR__ . '/../php/update.php'; } elseif ($url === '/dashboard' && isAuthorized()) { include __DIR__ . '/../templates/dashboard.html.php'; +} elseif ($url === '/logout') { + include __DIR__ . '/../php/logout.php'; } $output = ob_get_clean(); diff --git a/php/auth.php b/php/auth.php index 0d17c7c..d55581b 100644 --- a/php/auth.php +++ b/php/auth.php @@ -4,7 +4,7 @@ session_start(); function isAuthorized() { - require 'conn.php'; + require __DIR__ . '/conn.php'; $result = $conn->query("SELECT * FROM docenten WHERE username = '" . $_SESSION["username"] . "' AND password = '" . $_SESSION["password"] . "'"); diff --git a/php/dashboard.php b/php/dashboard.php index 6aa4466..3785d58 100755 --- a/php/dashboard.php +++ b/php/dashboard.php @@ -7,3 +7,11 @@ require 'conn.php'; $result = $conn->query("SELECT * FROM docenten WHERE username = '" . $_SESSION['username'] . "';"); $docent = $result->fetch_assoc(); + +if (isset($_GET['date'])) { + $date = date("Y-m-d", strtotime($_GET['date'])); +} else { + $date = date("Y-m-d"); // Create date in mysql DATE format. +} + +$rooster = $conn->query("SELECT * FROM rooster WHERE docent = " . $docent['id'] . " AND dag = DATE('" . $date . "')")->fetch_assoc(); diff --git a/php/logout.php b/php/logout.php new file mode 100755 index 0000000..66f18b6 --- /dev/null +++ b/php/logout.php @@ -0,0 +1,7 @@ +query("SELECT * FROM rooster WHERE dag = DATE('" . $_GET["date"] . "') AND docent = " . $_GET['docent'] .";"); + + if ($result->num_rows === 0) { + $conn->query("INSERT INTO rooster (dag, docent, opmerking, locatie) VALUES (DATE('" . $_GET['date'] . "'), " . $_GET['docent'] . ", '" . $_POST['opmerking'] . "', " . $_POST['locatie'] . ");"); + } else { + $conn->query("UPDATE rooster SET opmerking = '" . $_POST["opmerking"] . "', locatie = " . $_POST["locatie"] . " WHERE docent = " . $_GET['docent'] . " AND dag = DATE('" . $_GET['date'] . "');"); + } +} + +header('Location: /dashboard'); \ No newline at end of file diff --git a/templates/dashboard.html.php b/templates/dashboard.html.php index 629780b..ef63923 100644 --- a/templates/dashboard.html.php +++ b/templates/dashboard.html.php @@ -1,2 +1,19 @@ -Welkom \ No newline at end of file +Welkom +

Gymrooster voor

+">Dag eerder +">Dag later + +
+
+
+ +
\ No newline at end of file diff --git a/templates/layout.html.php b/templates/layout.html.php index b15d480..3fac7c7 100755 --- a/templates/layout.html.php +++ b/templates/layout.html.php @@ -10,7 +10,11 @@
diff --git a/templates/login.html.php b/templates/login.html.php index fa5ef7d..c073cd8 100755 --- a/templates/login.html.php +++ b/templates/login.html.php @@ -1,4 +1,3 @@ -

Login