From 1f94dcb709843256a3d64b9efbd0560deaa23363 Mon Sep 17 00:00:00 2001 From: rodude123 Date: Thu, 15 Dec 2022 14:50:58 +0000 Subject: [PATCH 1/2] Created the separation of admin and regular user. Added the ability for a regular user to be added in Signed-off-by: rodude123 --- .../{newVehicle.html => addVehicle.html} | 13 +-- .../changePassword.html | 12 +-- .../css/changePassword.css | 18 ---- .../css/login.css | 1 + .../css/nav.css | 4 + .../css/newVehicle.css | 12 --- .../css/search.css | 11 --- .../css/template.css | 82 ++++++++++++++++++- .../getOwners.php | 2 +- .../isAdmin.php | 11 +++ .../isLoggedIn.php | 2 +- .../js/checkUser.js | 48 +++++++---- .../js/login.js | 11 +++ .../js/newUser.js | 51 ++++++++++++ .../js/newVehicle.js | 2 +- .../js/search.js | 16 ++-- .../login.php | 4 +- .../logout.php | 4 + .../newUser.html | 49 ++++++++++- .../newUser.php | 29 +++++++ .../newVehicle2Forms.html | 81 ------------------ .../search.html | 24 +++--- 22 files changed, 314 insertions(+), 173 deletions(-) rename DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/{newVehicle.html => addVehicle.html} (85%) delete mode 100644 DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/css/changePassword.css create mode 100644 DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/isAdmin.php create mode 100644 DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/js/newUser.js create mode 100644 DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/logout.php create mode 100644 DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/newUser.php delete mode 100644 DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/newVehicle2Forms.html diff --git a/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/newVehicle.html b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/addVehicle.html similarity index 85% rename from DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/newVehicle.html rename to DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/addVehicle.html index 90fd74b..02ecffd 100644 --- a/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/newVehicle.html +++ b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/addVehicle.html @@ -9,13 +9,13 @@ @@ -58,7 +58,7 @@
- +
@@ -74,6 +74,7 @@ + \ No newline at end of file diff --git a/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/changePassword.html b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/changePassword.html index c7d2fa2..4530bd4 100644 --- a/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/changePassword.html +++ b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/changePassword.html @@ -3,19 +3,19 @@ Change Password - + diff --git a/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/css/changePassword.css b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/css/changePassword.css deleted file mode 100644 index 71d7b35..0000000 --- a/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/css/changePassword.css +++ /dev/null @@ -1,18 +0,0 @@ -@import "nav.css"; - -main { - padding-top: 2.5em; - display: flex; - flex-direction: column; - justify-content: center; - align-items: center; -} - -main form { - width: 15%; - display: flex; - flex-direction: column; - justify-content: center; - align-items: flex-start; - gap: 1em; -} diff --git a/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/css/login.css b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/css/login.css index 135323f..8e3c0d8 100644 --- a/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/css/login.css +++ b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/css/login.css @@ -24,6 +24,7 @@ div.login { } form.loginForm { + width: 100%; display: flex; flex-direction: column; justify-content: center; diff --git a/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/css/nav.css b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/css/nav.css index 6636076..0c21df7 100644 --- a/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/css/nav.css +++ b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/css/nav.css @@ -36,4 +36,8 @@ nav ul li a:hover { nav ul li a.active { background-color: var(--hover); +} + +nav ul li.admin { + display: none; } \ No newline at end of file diff --git a/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/css/newVehicle.css b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/css/newVehicle.css index 08fa41a..6382973 100644 --- a/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/css/newVehicle.css +++ b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/css/newVehicle.css @@ -1,13 +1,5 @@ @import "nav.css"; -main { - padding-top: 2.5em; - display: flex; - flex-direction: column; - justify-content: center; - align-items: center; -} - main .formGroup { width: 30%; display: flex; @@ -20,11 +12,7 @@ main .formGroup { main form { width: 100%; - display: flex; - flex-direction: column; - justify-content: center; align-items: center; - gap: 1em; flex: 1; } diff --git a/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/css/search.css b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/css/search.css index e31ae3a..410c472 100644 --- a/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/css/search.css +++ b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/css/search.css @@ -1,13 +1,5 @@ @import "nav.css"; -main { - padding-top: 2.5em; - display: flex; - flex-direction: column; - justify-content: center; - align-items: center; -} - div.searchContainer { display: flex; flex-direction: column; @@ -18,11 +10,8 @@ div.searchContainer { main form { width: 100%; - display: flex; flex-direction: row; - justify-content: center; align-items: center; - gap: 1em; } main#search form input:not([type="submit"]) { diff --git a/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/css/template.css b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/css/template.css index 4e3b594..9aa4d6c 100644 --- a/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/css/template.css +++ b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/css/template.css @@ -7,7 +7,7 @@ --secondary: hsl(210, 100%, 95%, 1); --accent: hsla(15, 99%, 57%, 1); --light: hsla(90, 8%, 85%, 1); - --mutedBlack: hsla(0, 0%, 0%, 0.25) + --mutedBlack: hsla(0, 0%, 0%, 0.25); } * { @@ -74,6 +74,68 @@ input:not([type="submit"]):hover, form .formControl textarea:hover { border: 4px solid var(--hover); } +.checkContainer { + display: block; + position: relative; + margin-bottom: 0.75em; + cursor: pointer; + -webkit-user-select: none; + -moz-user-select: none; + -ms-user-select: none; + user-select: none; +} + +.checkContainer input[type="checkbox"] { + position: absolute; + opacity: 0; + cursor: pointer; + height: 0; + width: 0; +} + +.checkmark { + position: absolute; + top: 1.25em; + left: 0; + height: 1.5em; + width: 1.5em; + background-color: #eee; +} + +.checkContainer:hover input ~ .checkmark { + background-color: #ccc; +} + +.checkContainer input:checked ~ .checkmark { + background-color: var(--primary); +} + +.checkContainer:hover input:checked ~ .checkmark { + background-color: var(--hover); +} + +.checkmark:after { + content: ""; + position: absolute; + display: none; +} + +.checkContainer input:checked ~ .checkmark:after { + display: block; +} + +.checkContainer .checkmark:after { + left: 9px; + top: 5px; + width: 0.35em; + height: 0.6em; + border: solid white; + border-width: 0 3px 3px 0; + -webkit-transform: rotate(45deg); + -ms-transform: rotate(45deg); + transform: rotate(45deg); +} + .selectDiv { position: relative; min-width: 300px; @@ -164,6 +226,24 @@ table th { color: #FFFFFF; } +main { + padding-top: 2.5em; + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; +} + +main form { + width: 15%; + display: flex; + flex-direction: column; + justify-content: center; + align-items: flex-start; + gap: 1em; +} + main #title { align-self: flex-start; + margin-left: 1em; } diff --git a/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/getOwners.php b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/getOwners.php index da032dc..9c2f8f7 100644 --- a/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/getOwners.php +++ b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/getOwners.php @@ -6,7 +6,7 @@ header('Content-Type: application/json'); if (isset($_SESSION["username"])) { $conn = dbConn(); - $stmt = $conn->prepare("SELECT People_ID, People_name FROM People"); + $stmt = $conn->prepare("SELECT People_ID, People_name, People_licence FROM People"); $stmt->execute(); $result = $stmt->fetchAll(PDO::FETCH_ASSOC); echo json_encode(array("message" => "ok", "owners" => $result)); diff --git a/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/isAdmin.php b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/isAdmin.php new file mode 100644 index 0000000..be3add3 --- /dev/null +++ b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/isAdmin.php @@ -0,0 +1,11 @@ + "ok", "admin" => $_SESSION["admin"])); +} +else +{ + echo json_encode(array("message" => "not logged in as admin")); +} diff --git a/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/isLoggedIn.php b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/isLoggedIn.php index 6b73ca8..fd43560 100644 --- a/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/isLoggedIn.php +++ b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/isLoggedIn.php @@ -3,7 +3,7 @@ session_start(); header('Content-Type: application/json'); if (isset($_SESSION["username"])) { - echo json_encode(array("message" => "ok")); + echo json_encode(array("message" => "ok", "username" => $_SESSION["username"], "admin" => $_SESSION["admin"])); } else { diff --git a/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/js/checkUser.js b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/js/checkUser.js index 3e7cc3b..27efa4b 100644 --- a/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/js/checkUser.js +++ b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/js/checkUser.js @@ -1,15 +1,35 @@ -// document.addEventListener("DOMContentLoaded", () => -// { -// fetch("isLoggedIn.php").then(res => res.json().then(json => -// { -// if (json.message !== "ok") -// { -// window.location.href = "index.html"; -// } -// else -// { -// document.querySelector("#title h1").innerText = "Logged in as: " + json.username; -// } -// })); -// }); +document.addEventListener("DOMContentLoaded", () => +{ + fetch("isLoggedIn.php").then(res => res.json().then(json => + { + if (json.message !== "ok") + { + window.location.href = "./"; + } + else + { + document.querySelector("#title h1").innerText = "Logged in as: " + json.username; + let adminLinks = document.querySelectorAll(".admin"); + for (let adminLink of adminLinks) + { + if (json.admin === true) + { + adminLink.style.display = "block"; + } + } + } + })); +}); + +document.querySelector("#logout").addEventListener("click", e => +{ + e.preventDefault(); + fetch("logout.php").then(res => res.json().then(json => + { + if (json.message === "ok") + { + window.location.href = "./"; + } + })); +}); \ No newline at end of file diff --git a/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/js/login.js b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/js/login.js index f672ecf..06c922f 100644 --- a/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/js/login.js +++ b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/js/login.js @@ -1,5 +1,16 @@ // Login stuff +document.addEventListener("DOMContentLoaded", () => +{ + fetch("isLoggedIn.php").then(res => res.json().then(json => + { + if (json.message === "ok") + { + window.location.href = "./search.html"; + } + })); +}); + document.querySelector("#login").addEventListener("submit", e => { e.preventDefault(); diff --git a/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/js/newUser.js b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/js/newUser.js new file mode 100644 index 0000000..8ddb76d --- /dev/null +++ b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/js/newUser.js @@ -0,0 +1,51 @@ +// create new a user stuff + +document.addEventListener("DOMContentLoaded", () => +{ + fetch("isAdmin.php").then(res => res.json().then(json => + { + if (json.message !== "ok") + { + window.location.href = "./search.html"; + } + })); +}); + +document.querySelector("#createUser").addEventListener("submit", e => +{ + e.preventDefault(); + let username = document.querySelector("#username").value; + let password = document.querySelector("#pass").value; + let rePass = document.querySelector("#rePass").value; + let admin = document.querySelector("#isAdmin").checked; + if (password === "" || rePass === "" || username === "") + { + alert("Please fill in all fields"); + } + else if (password !== rePass) + { + alert("Passwords do not match"); + } + else + { + let data = new FormData(); + data.append("username", username); + data.append("password", password); + data.append("admin", admin); + + fetch("newUser.php", { + method: "POST", + body: data + }).then(res => res.json().then(json => + { + if (json.message === "ok") + { + alert("User created"); + } + else + { + alert("Error creating user"); + } + })); + } +}); \ No newline at end of file diff --git a/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/js/newVehicle.js b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/js/newVehicle.js index 8d96b1e..f236bbd 100644 --- a/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/js/newVehicle.js +++ b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/js/newVehicle.js @@ -8,7 +8,7 @@ document.addEventListener("DOMContentLoaded", () => let body = ""; for (const owner of json.owners) { - body += ``; + body += ``; } body += ``; document.querySelector("#owner").innerHTML = body; diff --git a/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/js/search.js b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/js/search.js index 81f4419..e36bee2 100644 --- a/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/js/search.js +++ b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/js/search.js @@ -28,23 +28,25 @@ document.querySelector("#searchForm").addEventListener("submit", e => { document.querySelector("#searchResults thead tr").innerHTML = ""; document.querySelector("#searchResults tbody").innerHTML = ""; - console.log(Object.keys(json.data[0])); - Object.keys(json.data[0]).forEach(key => + + for (const key of Object.keys(json.data[0])) { let header = key.substring(key.indexOf("_") + 1) header = header.charAt(0).toUpperCase() + header.slice(1); document.querySelector("#searchResults thead tr").innerHTML += `${header}`; - }); + } + let body = ""; - json.data.forEach(row => + for (const row of json.data) { body += ""; - Object.keys(row).forEach(key => + for (const key of Object.keys(row)) { body += `${(row[key] === "null" || row[key] === null) ? "N/A" : row[key]}`; - }); + } body += ""; - }); + } + document.querySelector("#searchResults tbody").innerHTML = body; } diff --git a/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/login.php b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/login.php index 02c1cda..bd83fa9 100644 --- a/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/login.php +++ b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/login.php @@ -11,10 +11,12 @@ $stmt = $conn->prepare("SELECT * FROM Users WHERE Users_username = :username AND $stmt->bindParam(":username", $username); $stmt->bindParam(":password", $password); $stmt->execute(); +$result = $stmt->fetchAll(PDO::FETCH_ASSOC); -if (count($stmt->fetchAll(PDO::FETCH_ASSOC)) > 0) +if (count($result) > 0) { $_SESSION["username"] = $username; + $_SESSION["admin"] = $result[0]["Users_admin"] === "1"; echo json_encode(array("message" => "ok")); } else diff --git a/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/logout.php b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/logout.php new file mode 100644 index 0000000..45aae2a --- /dev/null +++ b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/logout.php @@ -0,0 +1,4 @@ + "ok")); \ No newline at end of file diff --git a/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/newUser.html b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/newUser.html index 566549b..5191a1a 100644 --- a/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/newUser.html +++ b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/newUser.html @@ -2,9 +2,56 @@ - Title + Create New User + + +
+
+

+
+ +
+
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ +
+ + +
+
+ + + \ No newline at end of file diff --git a/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/newUser.php b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/newUser.php new file mode 100644 index 0000000..3bff2b8 --- /dev/null +++ b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/newUser.php @@ -0,0 +1,29 @@ +prepare("INSERT INTO Users (Users_username, Users_password, Users_admin) VALUES (:username, :password, :admin)"); + $stmt->bindParam(":username", $username); + $stmt->bindParam(":password", $password); + $isAdmin = $admin ? 1 : 0; + $stmt->bindParam(":admin", $isAdmin); + $stmt->execute(); + + echo json_encode(array("message" => "ok", "admin" => $admin)); +} +else if (isset($_SESSION["username"]) && !isset($_SESSION["admin"])) +{ + echo json_encode(array("message" => "not logged in as admin")); +} +else +{ + echo json_encode(array("message" => "Not logged in ")); +} \ No newline at end of file diff --git a/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/newVehicle2Forms.html b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/newVehicle2Forms.html deleted file mode 100644 index 06c715f..0000000 --- a/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/newVehicle2Forms.html +++ /dev/null @@ -1,81 +0,0 @@ - - - - - Add New Vehicle - - - - - -
-
-

-
- -
-
-
- - -
- -
- - -
- -
- - -
- -
- -
- -
-
- - -
- -
-
-
- - -
-
- - -
-
- - -
-
- -
- -
-
-
-
- - - - \ No newline at end of file diff --git a/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/search.html b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/search.html index 4a43e52..8dec353 100644 --- a/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/search.html +++ b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/search.html @@ -7,18 +7,18 @@ - +

-- 2.43.0 From a6d2a0c17b0c6960cc6a2663c487768d7bc58a7d Mon Sep 17 00:00:00 2001 From: rodude123 Date: Thu, 15 Dec 2022 23:25:00 +0000 Subject: [PATCH 2/2] Created the ability to add fines Signed-off-by: rodude123 --- .../addFine.html | 53 +++++++++++++++++++ .../addFine.php | 30 +++++++++++ .../addFines.html | 10 ---- .../addVehicle.html | 2 +- .../changePassword.html | 2 +- .../getIncidents.php | 21 ++++++++ .../js/addFine.js | 41 ++++++++++++++ .../newUser.html | 2 +- .../search.html | 4 +- .../psxrp11-20450011_cover.txt | 0 10 files changed, 150 insertions(+), 15 deletions(-) create mode 100644 DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/addFine.html create mode 100644 DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/addFine.php delete mode 100644 DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/addFines.html create mode 100644 DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/getIncidents.php create mode 100644 DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/js/addFine.js create mode 100644 DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_cover.txt diff --git a/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/addFine.html b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/addFine.html new file mode 100644 index 0000000..a4a17d8 --- /dev/null +++ b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/addFine.html @@ -0,0 +1,53 @@ + + + + + Add Fines + + + + + +
+
+

+
+ +
+
+ + +
+ +
+ + +
+ +
+
+ +
+
+ + +
+
+ + + + + \ No newline at end of file diff --git a/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/addFine.php b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/addFine.php new file mode 100644 index 0000000..3fc0cc8 --- /dev/null +++ b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/addFine.php @@ -0,0 +1,30 @@ +prepare("INSERT INTO Fines (Fine_amount, Fine_points, Incident_ID) VALUES (:amount, :points, :incident)"); + $stmt->bindParam(":amount", $amount); + $stmt->bindParam(":points", $points); + $stmt->bindParam(":incident", $incident); + $stmt->execute(); + + echo json_encode(array("message" => "ok")); +} +else if (isset($_SESSION["username"]) && !isset($_SESSION["admin"])) +{ + echo json_encode(array("message" => "not logged in as admin")); +} +else +{ + echo json_encode(array("message" => "Not logged in ")); +} +{ +} \ No newline at end of file diff --git a/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/addFines.html b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/addFines.html deleted file mode 100644 index 566549b..0000000 --- a/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/addFines.html +++ /dev/null @@ -1,10 +0,0 @@ - - - - - Title - - - - - \ No newline at end of file diff --git a/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/addVehicle.html b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/addVehicle.html index 02ecffd..2c96e28 100644 --- a/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/addVehicle.html +++ b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/addVehicle.html @@ -12,7 +12,7 @@
  • Add new vehicle
  • Create new report
  • Create new user
  • -
  • Add Fines
  • +
  • Add Fines
  • View log
  • Change password
  • Logout
  • diff --git a/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/changePassword.html b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/changePassword.html index 4530bd4..9007bc3 100644 --- a/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/changePassword.html +++ b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/changePassword.html @@ -12,7 +12,7 @@
  • Add new vehicle
  • Create new report
  • Create new user
  • -
  • Add Fines
  • +
  • Add Fines
  • View log
  • Change password
  • Logout
  • diff --git a/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/getIncidents.php b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/getIncidents.php new file mode 100644 index 0000000..deb8a4c --- /dev/null +++ b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/getIncidents.php @@ -0,0 +1,21 @@ +prepare("SELECT * FROM Incident"); + $stmt->execute(); + $result = $stmt->fetchAll(PDO::FETCH_ASSOC); + echo json_encode(array("message" => "ok", "incidents" => $result)); +} +else if (isset($_SESSION["username"]) && !isset($_SESSION["admin"])) +{ + echo json_encode(array("message" => "not logged in as admin")); +} +else +{ + echo json_encode(array("message" => "Not logged in ")); +} \ No newline at end of file diff --git a/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/js/addFine.js b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/js/addFine.js new file mode 100644 index 0000000..538c5a1 --- /dev/null +++ b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/js/addFine.js @@ -0,0 +1,41 @@ + +document.addEventListener("DOMContentLoaded", () => +{ + fetch("getIncidents.php").then(res => res.json().then(json => + { + if(json.message === "ok") + { + let body = ""; + for (const incident of json.incidents) + { + body += ``; + } + document.querySelector("#incident").innerHTML = body; + } + })); + +}); + +document.querySelector("#addFineForm").addEventListener("submit", e => +{ + e.preventDefault(); + let formData = new FormData(); + formData.append("amount", document.querySelector("#amount").value); + formData.append("points", document.querySelector("#points").value); + formData.append("incident", document.querySelector("#incident").value) + + fetch("addFine.php", { + method: "POST", + body: formData + }).then(res => res.json().then(json => { + if(json.message === "ok") + { + alert("Fine added successfully"); + } + else + { + alert("Error adding fine"); + } + + })); +}); \ No newline at end of file diff --git a/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/newUser.html b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/newUser.html index 5191a1a..c52a6c5 100644 --- a/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/newUser.html +++ b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/newUser.html @@ -12,7 +12,7 @@
  • Add new vehicle
  • Create new report
  • Create new user
  • -
  • Add Fines
  • +
  • Add Fines
  • View log
  • Change password
  • Logout
  • diff --git a/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/search.html b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/search.html index 8dec353..bb19098 100644 --- a/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/search.html +++ b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/search.html @@ -13,7 +13,7 @@
  • Add new vehicle
  • Create new report
  • Create new user
  • -
  • Add Fines
  • +
  • Add Fines
  • View log
  • Change password
  • Logout
  • @@ -34,7 +34,7 @@
    - +
    diff --git a/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_cover.txt b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_cover.txt new file mode 100644 index 0000000..e69de29 -- 2.43.0