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 @@ - - -
- -