forked from Lake-Tuggeranong-College/CyberCity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate.php
161 lines (144 loc) · 5.88 KB
/
template.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
<?php require_once 'config.php'; ?>
<html>
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="css/bootstrap.min.css">
</head>
<body>
<!-- Navigation Bar -->
<nav class="navbar navbar-expand-sm navbar-light bg-light">
<div class="container-fluid">
<a class="navbar-brand" href="index.php">
<img src="images/Logo2.jpg" alt="" width="100" height="100">
</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav"
aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav">
<li class="nav-item"><a class="nav-link" href="index.php">Home</a></li>
<!--<li class="nav-item"><a class="nav-link" href="leaderboard.php">Leaderboard</a></li>-->
<?php
$accessLevel = 2;
if (isset($_SESSION["username"])) {
echo '
<!--<li class="nav-item"><a class="nav-link" href="flagClaimer.php">Flag Claimer</a></li>-->
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button"
data-bs-toggle="dropdown" aria-expanded="false">
CTF
</a>
<ul class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="leaderboard.php">Leaderboard</a>
<a class="dropdown-item" href="challengesList.php">Challenges</a>
<a class="dropdown-item" href="tutorialList.php">Tutorials</a>
</ul>
</li>
';
if ($_SESSION["access_level"] == $accessLevel) {
?>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button"
data-bs-toggle="dropdown" aria-expanded="false">
Administrator Functions
</a>
<ul class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="userList.php">User list</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="moduleRegister.php">Add New Module & Challenge</a>
<a class="dropdown-item" href="resetGame.php">Reset Game</a>
<a class="dropdown-item" href="contactpage.php">view contact requests</a>
<?php
}
?>
</ul>
</li>
<li class="nav-item"><a class="nav-link" href="contact.php">Contact Us</a></li>
<?php
} else {
echo '
<li class="nav-item"><a class="nav-link" href="register.php">Register</a></li>
';
echo '
<li class="nav-item"><a class="nav-link" href="login.php">Login</a></li>
';
}
?>
</ul>
</div>
<?php
if (isset($_SESSION["username"])) {
$userToLoad = $_SESSION["user_id"];
$sql = $conn->query("SELECT Score FROM Users WHERE ID= " . $userToLoad);
$userInformation = $sql->fetch();
$userScore = $userInformation["Score"];
echo "<div class='alert alert-success d-flex'><span>Welcome, " . $_SESSION["username"] . "<br> Score: ".$userScore."<br><a href='logout.php'>Logout</a></span> </div>";
}
?>
</div>
</nav>
<?php
if (isset($_SESSION['flash_message'])) {
$message = $_SESSION['flash_message'];
unset($_SESSION['flash_message']);
// echo $message;
?>
<div class="position-absolute bottom-0 end-0">
<?= $message ?>
</div>
<?php
}
?>
<script src="js/bootstrap.bundle.js"></script>
<?php
function sanitise_data($data)
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
function outputFooter()
{
date_default_timezone_set('Australia/Canberra');
$filename = basename($_SERVER["SCRIPT_FILENAME"]);
$footer = "This page was last modified: " . date("F d Y H:i:s.", filemtime($filename));
return $footer;
}
/*
* This function confirms if the user is authorised to access individual pages or not.
* @params
* @return true if user is authorised to access page.
* false if user is not authorised to access page.
*/
function authorisedAccess($unauthorisedUsers, $users, $admin)
{
// Unauthenticated User
if (!isset($_SESSION["username"])) { // user not logged in
if ($unauthorisedUsers == false) {
$_SESSION['flash_message'] = "<div class='bg-danger'>Access Denied</div>";
return false;
}
} else {
// Regular User
if ($_SESSION["access_level"] == 1) {
if ($users == false) {
$_SESSION['flash_message'] = "<div class='bg-danger'>Access Denied</div>";
return false;
}
}
// Administrators
if ($_SESSION["access_level"] == 2) {
if ($admin == false) {
return false;
}
}
}
// otherwise, let them through
return true;
}
?>