From 108cf7586dfd055f996e3b48d4271e7709a3c050 Mon Sep 17 00:00:00 2001 From: rodude123 Date: Fri, 16 Dec 2022 13:21:10 +0000 Subject: [PATCH] Added in the ability to create new reports Signed-off-by: rodude123 --- .../css/newVehicle.css | 2 +- .../css/reports.css | 52 +++++++ .../getOffences.php | 17 +++ .../getVehicles.php | 17 +++ .../js/reports.js | 136 ++++++++++++++++++ .../newReport.html | 10 -- .../newReport.php | 57 ++++++++ .../reports.html | 112 +++++++++++++++ 8 files changed, 392 insertions(+), 11 deletions(-) create mode 100644 DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/css/reports.css create mode 100644 DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/getOffences.php create mode 100644 DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/getVehicles.php create mode 100644 DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/js/reports.js delete mode 100644 DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/newReport.html create mode 100644 DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/newReport.php create mode 100644 DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/reports.html 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 6382973..bc6c09c 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 @@ -41,7 +41,7 @@ main form .formControl .selectDiv { transition: visibility 0s linear 300ms, opacity 300ms; } -#addOwner.shown{ +#addOwner.shown { visibility: visible; opacity: 1; -webkit-transition: visibility 0s linear 0s, opacity 300ms; diff --git a/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/css/reports.css b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/css/reports.css new file mode 100644 index 0000000..b449bf2 --- /dev/null +++ b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/css/reports.css @@ -0,0 +1,52 @@ +@import "nav.css"; + +main .formGroup { + width: 40%; + display: flex; + flex-direction: row; + justify-content: flex-start; + align-items: flex-start; + flex-wrap: wrap; + gap: 2em; +} + +main form { + width: 100%; + align-items: center; + flex: 1; +} + +main form .formControl .selectDiv { + width: 100%; +} + +.formSpace { + width: 100%; + display: flex; + flex-direction: column; + justify-content: flex-start; + align-items: flex-start; + gap: 1em; + flex: 1; +} + + +#addOwner, #addVehicle { + visibility: hidden; + opacity: 0; + -webkit-transition: visibility 0s linear 300ms, opacity 300ms; + -moz-transition: visibility 0s linear 300ms, opacity 300ms; + -ms-transition: visibility 0s linear 300ms, opacity 300ms; + -o-transition: visibility 0s linear 300ms, opacity 300ms; + transition: visibility 0s linear 300ms, opacity 300ms; +} + +#addOwner.shown, #addVehicle.shown { + visibility: visible; + opacity: 1; + -webkit-transition: visibility 0s linear 0s, opacity 300ms; + -moz-transition: visibility 0s linear 0s, opacity 300ms; + -ms-transition: visibility 0s linear 0s, opacity 300ms; + -o-transition: visibility 0s linear 0s, opacity 300ms; + transition: visibility 0s linear 0s, opacity 300ms; +} diff --git a/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/getOffences.php b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/getOffences.php new file mode 100644 index 0000000..dfa121b --- /dev/null +++ b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/getOffences.php @@ -0,0 +1,17 @@ +prepare("SELECT Offence_ID, Offence_description, Offence_maxFine FROM Offence"); + $stmt->execute(); + $result = $stmt->fetchAll(PDO::FETCH_ASSOC); + echo json_encode(array("message" => "ok", "offences" => $result)); +} +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/getVehicles.php b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/getVehicles.php new file mode 100644 index 0000000..fcbf448 --- /dev/null +++ b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/getVehicles.php @@ -0,0 +1,17 @@ +prepare("SELECT Vehicle_ID, Vehicle_type, Vehicle_licence FROM Vehicle"); + $stmt->execute(); + $result = $stmt->fetchAll(PDO::FETCH_ASSOC); + echo json_encode(array("message" => "ok", "vehicles" => $result)); +} +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/reports.js b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/js/reports.js new file mode 100644 index 0000000..fc51636 --- /dev/null +++ b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/js/reports.js @@ -0,0 +1,136 @@ + +document.addEventListener("DOMContentLoaded", () => +{ + fetch("getOwners.php").then(res => res.json().then(json => + { + if(json.message === "ok") + { + let body = ""; + for (const owner of json.owners) + { + body += ``; + } + body += ``; + document.querySelector("#owner").innerHTML = body; + } + })); + + fetch("getVehicles.php").then(res => res.json().then(json => + { + if (json.message === "ok") + { + let body = ""; + for (const owner of json.vehicles) + { + body += ``; + } + body += ``; + document.querySelector("#vehicle").innerHTML = body; + } + })); + + + fetch("getOffences.php").then(res => res.json().then(json => + { + if (json.message === "ok") + { + let body = ""; + for (const owner of json.offences) + { + body += ``; + } + body += ``; + document.querySelector("#offence").innerHTML = body; + } + })); + +}); + +document.querySelector("#owner").addEventListener("change", e => +{ + let inputs = document.querySelectorAll("#addOwner input"); + if (e.target.value === "new") + { + document.querySelector("#addOwner").classList.add("shown"); + for (const input of inputs) + { + input.setAttribute("required", ""); + } + } + else + { + document.querySelector("#addOwner").classList.remove("shown"); + for (const input of inputs) + { + input.removeAttribute("required"); + } + } +}); + +document.querySelector("#vehicle").addEventListener("change", e => +{ + let inputs = document.querySelectorAll("#addVehicle input"); + if (e.target.value === "new") + { + document.querySelector("#addVehicle").classList.add("shown"); + for (const input of inputs) + { + input.setAttribute("required", ""); + } + } + else + { + document.querySelector("#addVehicle").classList.remove("shown"); + for (const input of inputs) + { + input.removeAttribute("required"); + } + } +}); + +document.querySelector("#reports").addEventListener("click", e => +{ + e.preventDefault(); + let formData = new FormData(); + formData.append("incidentReport", document.querySelector("#incidentReport").value); + formData.append("incidentDate", document.querySelector("#incidentDate").value); + if (document.querySelector("#owner").value === "new") + { + formData.append("name", document.querySelector("#name").value); + formData.append("address", document.querySelector("#address").value); + formData.append("licence", document.querySelector("#licence").value); + } + else + { + formData.append("peopleID", document.querySelector("#owner").value); + } + + if (document.querySelector("#vehicle").value === "new") + { + formData.append("type", document.querySelector("#type").value); + formData.append("colour", document.querySelector("#colour").value); + formData.append("plateNumber", document.querySelector("#plateNum").value); + } + else + { + formData.append("vehicleID", document.querySelector("#vehicle").value); + } + formData.append("offenceID", document.querySelector("#offence").value); + + fetch("newReport.php",{ + method: "POST", + body: formData + }).then(res => res.json().then(json => + { + if (json.message === "ok") + { + alert("Report added"); + } + else + { + alert("Error adding report"); + } + })); + + +}); \ No newline at end of file diff --git a/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/newReport.html b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/newReport.html deleted file mode 100644 index 566549b..0000000 --- a/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/newReport.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/newReport.php b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/newReport.php new file mode 100644 index 0000000..d67376a --- /dev/null +++ b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/newReport.php @@ -0,0 +1,57 @@ +prepare("INSERT INTO Vehicle (Vehicle_type, Vehicle_colour, Vehicle_licence) VALUES (:type, :colour, :plateNum)"); + $stmt->bindParam(":type", $_POST["type"]); + $stmt->bindParam(":colour", $_POST["colour"]); + $stmt->bindParam(":plateNum", $_POST["plateNum"]); + $stmt->execute(); + $vehicleID = $conn->lastInsertId(); + } + + if (isset($_POST["name"]) && isset($_POST["address"]) && isset($_POST["licence"])) + { + $stmtPeople = $conn->prepare("INSERT INTO People (People_name, People_address, People_licence) VALUES (:name, :address, :licence)"); + $stmtPeople->bindParam(":name", $_POST["name"]); + $stmtPeople->bindParam(":address", $_POST["address"]); + $stmtPeople->bindParam(":licence", $_POST["licence"]); + $stmtPeople->execute(); + $peopleID = $conn->lastInsertId(); + } + + $stmtOwner = $conn->prepare("INSERT INTO Ownership (Vehicle_ID, People_ID) VALUES (:vehicleID, :peopleID)"); + $stmtOwner->bindParam(":vehicleID", $vehicleID); + $stmtOwner->bindParam(":peopleID", $peopleID); + $stmtOwner->execute(); + + $stmt = $conn->prepare("INSERT INTO Incident (Incident_report, Incident_date, People_ID, Vehicle_ID, Offence_ID) VALUES (:incidentReport, :incidentDate, :peopleID, :vehicleID, :offenceID)"); + $stmt->bindParam(":incidentReport", $incidentReport); + $stmt->bindParam(":incidentDate", $incidentDate); + $stmt->bindParam(":peopleID", $peopleID); + $stmt->bindParam(":vehicleID", $vehicleID); + $stmt->bindParam(":offenceID", $offenceID); + $stmt->execute(); + + $logSQL = "INSERT INTO Logs (Logs_type, Users_username, Logs_date) VALUES ('Add Report', :username, NOW())"; + $logStmt = $conn->prepare($logSQL); + $logStmt->bindParam(":username", $_SESSION["username"]); + $logStmt->execute(); + + echo json_encode(array("message" => "ok")); +} +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/reports.html b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/reports.html new file mode 100644 index 0000000..ddfa3db --- /dev/null +++ b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/reports.html @@ -0,0 +1,112 @@ + + + + + Reports + + + + + +
+
+

+
+ +
+
+
+ +
+ + +
+ +
+ + +
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ + +
+ +
+
+ + +
+
+ + +
+
+ + +
+
+ +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ +
+
+
+ + + + + \ No newline at end of file