From a6d2a0c17b0c6960cc6a2663c487768d7bc58a7d Mon Sep 17 00:00:00 2001 From: rodude123 Date: Thu, 15 Dec 2022 23:25:00 +0000 Subject: [PATCH] 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