412 lines
13 KiB
Plaintext
412 lines
13 KiB
Plaintext
<!-- Simple Styling for layout -->
|
|
<style>
|
|
.members {
|
|
position: absolute;
|
|
top: 150px;
|
|
left: 25px;
|
|
width: 230px;
|
|
display: inline-block;
|
|
max-height: 30px
|
|
}
|
|
.buttons-container {
|
|
position: absolute;
|
|
width: 174px;
|
|
height: 500px;
|
|
top: 25px;
|
|
right: 25px;
|
|
border: solid #5b94f0 2px;
|
|
border-style: solid;
|
|
border-radius: 10px;
|
|
background-color: rgba(112, 196, 255, .3);
|
|
}
|
|
.alert {
|
|
max-width: 58%;
|
|
}
|
|
.admin-detail {
|
|
position: absolute;
|
|
left: 25px;
|
|
}
|
|
#div-container {
|
|
position: absolute;
|
|
left: 30%;
|
|
margin-left: 25vm;
|
|
margin-right: 25vm;
|
|
}
|
|
#newTeacher-btn {
|
|
margin-left: 25px;
|
|
margin-top: 10px;
|
|
}
|
|
#bug-btn {
|
|
width: 127px;
|
|
margin-left: 25px;
|
|
margin-top: 10px;
|
|
}
|
|
#logout-btn {
|
|
width: 127px;
|
|
margin-left: 25px;
|
|
margin-top: 10px;
|
|
}
|
|
#user-pro-pic {
|
|
position: absolute;
|
|
top: 0px;
|
|
left: 150px;
|
|
width: 50px;
|
|
height: 50px;
|
|
display: block;
|
|
border-radius: 50px;
|
|
border: 1px solid black;
|
|
margin:5px;
|
|
}
|
|
|
|
h2 {
|
|
font: 350 35px/1.5 Helvetica, Verdana, sans-serif;
|
|
margin: 0;
|
|
padding: 0;
|
|
}
|
|
ul {
|
|
list-style-type: none;
|
|
margin: 0;
|
|
padding: 0;
|
|
}
|
|
li {
|
|
font: 200 20px/1.5 Helvetica, Verdana, sans-serif;
|
|
border-bottom: 1px solid #ccc;
|
|
}
|
|
li:last-child {
|
|
border: none;
|
|
}
|
|
li a {
|
|
text-decoration: none;
|
|
color: #000;
|
|
display: block;
|
|
width: 200px;
|
|
-webkit-transition: font-size 0.3s ease, background-color 0.3s ease;
|
|
-moz-transition: font-size 0.3s ease, background-color 0.3s ease;
|
|
-o-transition: font-size 0.3s ease, background-color 0.3s ease;
|
|
-ms-transition: font-size 0.3s ease, background-color 0.3s ease;
|
|
transition: font-size 0.3s ease, background-color 0.3s ease;
|
|
}
|
|
li a:hover {
|
|
font-size: 30px;
|
|
background: #f6f6f6;
|
|
}
|
|
|
|
@media (max-width: 800px) {
|
|
.alert {
|
|
max-width: 55%;
|
|
}
|
|
#div-container {
|
|
position: absolute;
|
|
left: 25px;
|
|
top: 125px;
|
|
margin-left: 25vm;
|
|
margin-right: 25vm;
|
|
max-height: 125px;
|
|
}
|
|
.members {
|
|
position: absolute;
|
|
left: 24px;
|
|
top: 300px;
|
|
}
|
|
}
|
|
</style>
|
|
|
|
<!-- Header -->
|
|
<div class='head'>
|
|
<div id='teacher-container'>
|
|
<div class='admin-detail'>
|
|
<h1 class="mt-4">Site Admin</h1>
|
|
<p id='welcome' class="lead mb-3">Welcome Admin</p>
|
|
</div>
|
|
<br>
|
|
<div class="buttons-container">
|
|
<!-- Action Buttons -->
|
|
<a id='logout-btn' href="/users/logout" class="btn btn-outline-info btn-sm">Logout</a>
|
|
<!-- Button trigger modal -->
|
|
<button id="newTeacher-btn" onClick='openModal("#exampleModal")' type="button" class="btn btn-outline-info btn-sm">
|
|
Create New Teacher
|
|
</button>
|
|
<a id='bug-btn' href="https://github.com/Braeden57/XP-System/issues" target="_blank" class='btn btn-outline-info btn-sm'>Report Bug</a>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
|
|
function openModal(modalName) {
|
|
$(modalName).modal()
|
|
}
|
|
|
|
// Creates unique ID
|
|
function makeid(length) {
|
|
var result = '';
|
|
var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
var charactersLength = characters.length;
|
|
for ( var i = 0; i < length; i++ ) {
|
|
result += characters.charAt(Math.floor(Math.random() * charactersLength));
|
|
}
|
|
return result;
|
|
}
|
|
|
|
// Create Div
|
|
function createDiv(type, message) {
|
|
let id = makeid(8);
|
|
|
|
if (type == 'error') {
|
|
document.getElementById('div-container').innerHTML += '<div id="new-div-'+id+'" style="display: none; clear: right;" class="alert alert-warning alert-dismissible fade show" role="alert">';
|
|
}
|
|
if (type == 'message') {
|
|
document.getElementById('div-container').innerHTML += '<div id="new-div-'+id+'" style="display: none; clear: right;" class="alert alert-info alert-dismissible fade show" role="alert">';
|
|
}
|
|
document.getElementById('new-div-'+id).innerHTML += '<div id="message'+id+'">'+message+'</div>';
|
|
document.getElementById('new-div-'+id).innerHTML += '<button id="close-btn-'+id+'" class="close" data-dismiss="alert" aria-label="Close"></button>';
|
|
document.getElementById('close-btn-'+id).innerHTML += '<span aria-hidden="true">×</span>';
|
|
document.getElementById('new-div-'+id).style.display = "block";
|
|
}
|
|
|
|
</script>
|
|
|
|
<!-- Catching url Parameters -->
|
|
<script>
|
|
window.onload = function () {
|
|
const queryString = window.location.search;
|
|
const urlParams = new URLSearchParams(queryString);
|
|
const successRate = urlParams.get('successRate')
|
|
if(successRate == 'createdTeacher') {
|
|
createDiv('message', 'Successfully Created Teacher');
|
|
}
|
|
if(successRate == 'deletedUser') {
|
|
createDiv('message', "Successfully Deleted User");
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<!-- Sets Variables for calculating users data -->
|
|
<div>
|
|
<script>
|
|
let xp;
|
|
let currRank;
|
|
let ranks = [
|
|
{"Digital Noob": 0}, // index 0
|
|
{"Digital Novice": 48}, // index 1
|
|
{"Digital Novice II": 100}, // index 2
|
|
{"Digital Amature": 148}, // index 3
|
|
{"Digital Amature II": 200}, // index 4
|
|
{"Digital Apprentice": 248}, // index 5
|
|
{"Digital Apprentice II": 300}, // index 6
|
|
{"Digital Journeyman": 396}, // index 7
|
|
{"Digital Journeyman II": 476}, // index 8
|
|
{"Digital Journeyman III": 532}, // index 9
|
|
{"Digital Crafter": 580}, // index 10
|
|
{"Expert Digital Crafter": 648}, // index 11
|
|
{"Master Digital Crafter": 800} // index 12
|
|
]
|
|
let indexes = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 12]
|
|
|
|
// Students should't be on this page sooooo...
|
|
console.log("Students Also Shouldnt be here");
|
|
</script>
|
|
|
|
<!-- Alert container -->
|
|
<div id='div-container'></div>
|
|
|
|
<!-- Delete User Warning Modal -->
|
|
<div class="modal fade" id="warningModal" tabindex="-1" role="dialog" aria-labelledby="warningModalLabel" aria-hidden="true">
|
|
<div class="modal-dialog" role="document">
|
|
<div class="modal-content">
|
|
<div class="modal-header">
|
|
<h5 class="modal-title" id="warningModalLabel">Are you sure you wish to delete this user?</h5>
|
|
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
|
<span aria-hidden="true">×</span>
|
|
</button>
|
|
</div>
|
|
<div class="modal-body">
|
|
<form action="/users/deleteUser" method="POST" enctype="multipart/form-data">
|
|
<input id='delete_id' type='text' name='delete_id' value='' style='display: none'></input>
|
|
<button type="submit" class="btn btn-primary btn-block">
|
|
Yes, Continue and Delete This User
|
|
</button>
|
|
</form>
|
|
</div>
|
|
<div class="modal-footer">
|
|
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Create Teacher Modal -->
|
|
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
|
|
<div class="modal-dialog" role="document">
|
|
<div class="modal-content">
|
|
<div class="modal-header">
|
|
<h5 class="modal-title" id="exampleModalLabel">Create New Teacher</h5>
|
|
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
|
<span aria-hidden="true">×</span>
|
|
</button>
|
|
</div>
|
|
<div class="modal-body">
|
|
<% include ./partials/messages %>
|
|
<form action="/users/registerTeacher" method="POST" enctype="multipart/form-data">
|
|
<div class="form-group">
|
|
<label for="name">Name</label>
|
|
<input
|
|
type="name"
|
|
id="name"
|
|
name="name"
|
|
class="form-control"
|
|
placeholder="Enter Name"
|
|
value="<%= typeof name != 'undefined' ? name : '' %>"
|
|
/>
|
|
</div>
|
|
<div class="form-group">
|
|
<label for='image'>Upload Profile Picture</label>
|
|
<input class="form-control-file" type="file" id="image" name="image" value="">
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="email">Email</label>
|
|
<input
|
|
type="email"
|
|
id="email"
|
|
name="email"
|
|
class="form-control"
|
|
placeholder="Enter Email"
|
|
value="<%= typeof email != 'undefined' ? email : '' %>"
|
|
/>
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="password">Password</label>
|
|
<input
|
|
type="password"
|
|
id="password"
|
|
name="password"
|
|
class="form-control"
|
|
placeholder="Create Password"
|
|
value="<%= typeof password != 'undefined' ? password : '' %>"
|
|
/>
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="password2">Confirm Password</label>
|
|
<input
|
|
type="password"
|
|
id="password2"
|
|
name="password2"
|
|
class="form-control"
|
|
placeholder="Confirm Password"
|
|
value="<%= typeof password2 != 'undefined' ? password2 : '' %>"
|
|
/>
|
|
</div>
|
|
<button type="submit" class="btn btn-primary btn-block">
|
|
Register Teacher
|
|
</button>
|
|
</form>
|
|
</div>
|
|
<div class="modal-footer">
|
|
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- List of all site students and teachers -->
|
|
<div class='members'>
|
|
<h2>All Site Members</h2>
|
|
<ul>
|
|
<!-- Loops through all members -->
|
|
<% members.forEach(function (member) { %>
|
|
<% if (member.role == "Student") { %>
|
|
<!-- Creates User Button link -->
|
|
<li><button class='btn btn-link mt-2' onclick='openProfile("<%= member.id %>")'><%= member.name %></button></li>
|
|
|
|
<!-- Creates hidden Div with user specific Data -->
|
|
<div style='display: none; position: relative;' data-role='page' id='<%= member._id %>'>
|
|
<img id='user-pro-pic' src='data:image/<%=member.image.contentType%>;base64,<%=member.image.data.toString('base64')%>'>
|
|
<p id='memberName' class='lead mb-3'><%= member.name %></p>
|
|
<p class='lead mb-3'><%= member.email %></p>
|
|
<div>
|
|
<p id='userRank-<%= member.id %>'></p>
|
|
<p>XP: <%= member.xp %></p>
|
|
|
|
<p><%= member.role %></p>
|
|
|
|
<!-- Delete User Option -->
|
|
<button id="delete-btn" onClick='deleteUser("<%= member._id %>")' type="button" class="btn btn-outline-warning btn-sm">
|
|
Delete User
|
|
</button>
|
|
</div>
|
|
<br>
|
|
|
|
<!-- Calculates user specific Rank -->
|
|
<script>
|
|
xp = <%= member.xp %>;
|
|
// Get current rank
|
|
if (xp == 0) {
|
|
currRank = 'Digital Noob';
|
|
} else {
|
|
if (xp < 800 && xp > 0) {
|
|
for(var i = 0; i < ranks.length; i++) {
|
|
for (let rank in ranks[i]) {
|
|
let nextIndex = indexes[i];
|
|
for (let nextRank in ranks[nextIndex]) {
|
|
if (xp >= ranks[i][rank] && xp < ranks[nextIndex][nextRank]) {
|
|
currRank = rank;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
if (xp == 800) {
|
|
currRank = "Master Digital Crafter";
|
|
}
|
|
}
|
|
}
|
|
|
|
// Display Rank
|
|
document.getElementById('userRank-<%= member.id %>').innerHTML = currRank;
|
|
|
|
// Delete User Function
|
|
function deleteUser(id) {
|
|
document.getElementById('delete_id').value = id;
|
|
openModal("#warningModal");
|
|
}
|
|
|
|
</script>
|
|
</div>
|
|
<% } %>
|
|
<% if (member.role == "Teacher") { %>
|
|
<!-- Creates User Button link -->
|
|
<li><button class='btn btn-link mt-2' onclick='openProfile("<%= member.id %>")'><%= member.name %></button></li>
|
|
|
|
<!-- Creates hidden Div with user specific Data -->
|
|
<div style='display: none; position: relative;' data-role='page' id='<%= member._id %>'>
|
|
<img id='user-pro-pic' src='data:image/<%=member.image.contentType%>;base64,<%=member.image.data.toString('base64')%>'>
|
|
<p id='memberName' class='lead mb-3'><%= member.name %></p>
|
|
<p class='lead mb-3'><%= member.email %></p>
|
|
<div>
|
|
<p><%= member.role %></p>
|
|
|
|
<!-- Delete User Option -->
|
|
<button id="delete-btn" onClick='deleteUser("<%= member._id %>")' type="button" class="btn btn-outline-warning btn-sm">
|
|
Delete User
|
|
</button>
|
|
</div>
|
|
<br>
|
|
</div>
|
|
<% } %>
|
|
<% }) %>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Script for show/hide user profile data -->
|
|
<script>
|
|
function openProfile(id) {
|
|
let state = document.getElementById(id).style.display;
|
|
if (state == "block") {
|
|
document.getElementById(id).style.display = 'none';
|
|
} else {
|
|
document.getElementById(id).style.display = 'block';
|
|
}
|
|
}
|
|
</script>
|