From fc92b809384345217635441e9c9d7fdcbfa14656 Mon Sep 17 00:00:00 2001 From: Job Vonk Date: Mon, 9 Mar 2020 18:09:41 +0000 Subject: [PATCH] Finished first draft of the system. --- html/index.php | 12 ++++++++++-- php/auth.php | 2 +- php/dashboard.php | 8 ++++++++ php/logout.php | 7 +++++++ php/update.php | 15 +++++++++++++++ templates/dashboard.html.php | 19 ++++++++++++++++++- templates/layout.html.php | 6 +++++- templates/login.html.php | 1 - 8 files changed, 64 insertions(+), 6 deletions(-) create mode 100755 php/logout.php create mode 100755 php/update.php 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