-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.php
66 lines (57 loc) · 2.21 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
// Start the session.
session_start();
// Create instance of database class and store in session.
require_once "Database/database.php";
$_SESSION["database"] = new Database();
$db = $_SESSION["database"];
// Import all classes.
require_once "Classes/PHP/user.php";
require_once "Classes/PHP/animation.php";
require_once "Classes/PHP/frame.php";
require_once "Classes/PHP/post.php";
require_once "Classes/PHP/comment.php";
require_once "Classes/PHP/group.php";
require_once "Classes/PHP/message.php";
require_once "Classes/PHP/assignment.php";
require_once "Classes/PHP/assignmentWork.php";
// Import useful functions.
require_once "Utils/Functions/arrayMappers.php";
require_once "Utils/Functions/arraySorters.php";
// Check which page the user is looking for.
$page = explode("?", str_replace("/", "", $_SERVER["REQUEST_URI"]), 2)[0];
if (strlen($page) === 0) $page = "home";
// Get the title for the page the user has asked for.
$title = ucfirst($page);
// Check if the user is already logged in.
$loggedIn = isset($_SESSION["auth"]) && $_SESSION["auth"];
// Check if the user is trying to log in or out.
$loggingInOrOut = $page === "login" || $page === "signup" || $page === "logout";
// Render page header.
require_once "Include/header.inc";
echo <<<HTML
<script>
const setCookie = (name, value) => document.cookie = name + "=" + value + ";";
const getCookie = (name) => document.cookie.match(/(firstName=)([^;]*)(;\s)/g)?.[0].split("=")[1].replace("; ", "");
const unsetCookie = (name) => document.cookie = name + "=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
</script>
HTML;
// Render a message telling the user they need to log in.
if (!$loggedIn && !$loggingInOrOut) {
echo <<<HTML
<h1>Microcontroller Animations</h1>
<div class="alert alert-danger" role="alert">
You are <strong>not</strong> logged in.
</div>
HTML;
}
// Redirect user to the requested page, taking into account their access level.
else {
// Get the path for the requested page.
$page = "Pages/$page.php";
if (!file_exists($page)) $page = "Pages/404.php";
// Render the requested page.
require_once $page;
}
// Render page footer.
require_once "Include/footer.inc";