From 996fee5ad2c5c6884d87dc8b94b405aa110375ee Mon Sep 17 00:00:00 2001 From: rodude123 Date: Fri, 9 Dec 2022 04:51:56 +0000 Subject: [PATCH] Added in ability to add new vehicle with new owner or existing owner Signed-off-by: rodude123 --- .../addVehicle.php | 41 ++++++++++ .../changePassword.html | 59 ++++++++------ .../css/nav.css | 2 +- .../css/newVehicle.css | 64 +++++++++++++++ .../css/search.css | 67 --------------- .../css/template.css | 71 +++++++++++++++- .../getOwners.php | 13 +++ .../index.html | 3 + .../js/checkUser.js | 15 ++++ .../js/newVehicle.js | 67 +++++++++++++++ .../js/search.js | 11 +-- .../newVehicle.html | 71 +++++++++++++++- .../newVehicle2Forms.html | 81 +++++++++++++++++++ .../search.html | 58 +++++++------ 14 files changed, 491 insertions(+), 132 deletions(-) create mode 100644 DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/addVehicle.php create mode 100644 DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/css/newVehicle.css create mode 100644 DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/getOwners.php create mode 100644 DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/js/checkUser.js create mode 100644 DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/js/newVehicle.js create mode 100644 DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/newVehicle2Forms.html diff --git a/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/addVehicle.php b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/addVehicle.php new file mode 100644 index 0000000..3114169 --- /dev/null +++ b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/addVehicle.php @@ -0,0 +1,41 @@ +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(); + echo json_encode(array("message" => "Vehicle and new owner added successfully")); + } + else + { + $stmt = $conn->prepare("INSERT INTO Ownership (Vehicle_ID, People_ID) VALUES (:vehicleID, :peopleID)"); + $stmt->bindParam(":vehicleID", $vehicleID); + $stmt->bindParam(":peopleID", $_POST["peopleID"]); + $stmt->execute(); + echo json_encode(array("message" => "Vehicle added successfully and assigned to existing owner")); + } +} +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/changePassword.html b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/changePassword.html index 6bf547d..c7d2fa2 100644 --- a/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/changePassword.html +++ b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/changePassword.html @@ -6,33 +6,40 @@ - + -
-
-
- - -
-
- - -
- -
-
+
+
+

+
- +
+
+ + +
+ +
+ + +
+ + +
+
+ + + \ No newline at end of file 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 8e15178..6636076 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 @@ -24,7 +24,7 @@ nav ul li a { } nav ul li a.active, nav ul li a:hover { - padding: 1.4em 1.75em; + padding: 1.5em 1.75em; -webkit-border-radius: 0; -moz-border-radius: 0; border-radius: 0; 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 new file mode 100644 index 0000000..08fa41a --- /dev/null +++ b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/css/newVehicle.css @@ -0,0 +1,64 @@ +@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; + flex-direction: row; + justify-content: flex-start; + align-items: flex-start; + flex-wrap: wrap; + gap: 2em; +} + +main form { + width: 100%; + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; + gap: 1em; + 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 { + 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{ + 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; +} \ No newline at end of file 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 4368ac1..e31ae3a 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 @@ -58,73 +58,6 @@ main#search div.searchBtnContainer:hover button { background-color: var(--hover); } -.selectDiv { - position: relative; - min-width: 300px; - cursor: pointer; -} - -.selectDiv:before { - content: ''; - -webkit-transform: rotate(90deg); - -moz-transform: rotate(90deg); - -ms-transform: rotate(90deg); - transform: rotate(90deg); - right: -5px; - top: 13px; - padding: 0 0 2px; - position: absolute; - width: 46px; - background-color: var(--primary); - height: 30px; - border-top-right-radius: 0.5em; - border-top-left-radius: 0.5em; -} - -.selectDiv:after { - content: '<>'; - font: 18px "Consolas", monospace; - color: #FFFFFF; - -webkit-transform: rotate(90deg); - -moz-transform: rotate(90deg); - -ms-transform: rotate(90deg); - transform: rotate(90deg); - right: 6px; - top: 18px; - padding: 0 0 2px; - position: absolute; -} - -.selectDiv select { - -webkit-appearance: none; - -moz-appearance: none; - appearance: none; - cursor: pointer; - display: block; - outline: none; - width: 100%; - max-width: 30em; - height: 3em; - float: right; - margin: 6px 0; - padding: 0 24px; - background-color: #ffffff; - background-image: none; - border: 4px solid var(--primary); - -webkit-border-radius: 0.5em; - -moz-border-radius: 0.5em; - border-radius: 0.5em; - word-break: normal; -} - -.selectDiv:hover select, .selectDiv select:hover { - border: 4px solid var(--hover); -} - -.selectDiv:hover:before { - background-color: var(--hover); -} - .content { margin-top: 3em; } \ No newline at end of file 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 cb20796..4e3b594 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 @@ -74,6 +74,71 @@ input:not([type="submit"]):hover, form .formControl textarea:hover { border: 4px solid var(--hover); } +.selectDiv { + position: relative; + min-width: 300px; + cursor: pointer; +} + +.selectDiv:before { + content: ''; + -webkit-transform: rotate(90deg); + -moz-transform: rotate(90deg); + -ms-transform: rotate(90deg); + transform: rotate(90deg); + right: -5px; + top: 13px; + padding: 0 0 2px; + position: absolute; + width: 46px; + background-color: var(--primary); + height: 30px; + border-top-right-radius: 0.5em; + border-top-left-radius: 0.5em; +} + +.selectDiv:after { + content: '<>'; + font: 18px "Consolas", monospace; + color: #FFFFFF; + -webkit-transform: rotate(90deg); + -moz-transform: rotate(90deg); + -ms-transform: rotate(90deg); + transform: rotate(90deg); + right: 6px; + top: 18px; + padding: 0 0 2px; + position: absolute; +} + +.selectDiv select { + -webkit-appearance: none; + -moz-appearance: none; + appearance: none; + cursor: pointer; + display: block; + outline: none; + width: 100%; + height: 3em; + margin: 6px 0; + padding: 0 24px; + background-color: #ffffff; + background-image: none; + border: 4px solid var(--primary); + -webkit-border-radius: 0.5em; + -moz-border-radius: 0.5em; + border-radius: 0.5em; + word-break: normal; +} + +.selectDiv:hover select, .selectDiv select:hover { + border: 4px solid var(--hover); +} + +.selectDiv:hover:before { + background-color: var(--hover); +} + table { border-collapse: collapse; } @@ -97,4 +162,8 @@ table th { text-align: left; background-color: var(--primary); color: #FFFFFF; -} \ No newline at end of file +} + +main #title { + align-self: flex-start; +} diff --git a/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/getOwners.php b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/getOwners.php new file mode 100644 index 0000000..da032dc --- /dev/null +++ b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/getOwners.php @@ -0,0 +1,13 @@ +prepare("SELECT People_ID, People_name FROM People"); + $stmt->execute(); + $result = $stmt->fetchAll(PDO::FETCH_ASSOC); + echo json_encode(array("message" => "ok", "owners" => $result)); +} \ No newline at end of file diff --git a/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/index.html b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/index.html index 614f1ae..7ed83c7 100644 --- a/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/index.html +++ b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/index.html @@ -12,15 +12,18 @@
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 new file mode 100644 index 0000000..3e7cc3b --- /dev/null +++ b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/js/checkUser.js @@ -0,0 +1,15 @@ +// 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; +// } +// })); +// }); + 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 new file mode 100644 index 0000000..8d96b1e --- /dev/null +++ b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/js/newVehicle.js @@ -0,0 +1,67 @@ + +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; + } + })); + +}); + +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("#vehicleForm").addEventListener("submit", e => +{ + e.preventDefault(); + let formData = new FormData(); + formData.append("type", document.querySelector("#type").value); + formData.append("colour", document.querySelector("#colour").value); + formData.append("plateNum", document.querySelector("#plateNum").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); + } + + fetch("addVehicle.php", { + method: "POST", + body: formData + }).then(res => res.json().then(json => + { + alert(json.message); + })); + +}); \ No newline at end of file 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 fe0f9d5..81f4419 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 @@ -1,13 +1,4 @@ -// document.addEventListener("DOMContentLoaded", () => -// { -// fetch("isLoggedIn.php").then(res => res.json().then(json => -// { -// if (json.message !== "ok") -// { -// window.location.href = "index.html"; -// } -// })); -// }); +//Search stuff document.querySelector("#searchType").addEventListener("change", e => { diff --git a/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/newVehicle.html b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/newVehicle.html index 566549b..90fd74b 100644 --- a/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/newVehicle.html +++ b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/newVehicle.html @@ -2,9 +2,78 @@ - Title + Add New Vehicle + + +
+
+

+
+ +
+
+
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ +
+ +
+
+ + +
+ +
+
+ + +
+
+ + +
+
+ + +
+
+ +
+
+
+ + \ 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 new file mode 100644 index 0000000..06c715f --- /dev/null +++ b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/newVehicle2Forms.html @@ -0,0 +1,81 @@ + + + + + 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 7e608d9..4a43e52 100644 --- a/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/search.html +++ b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/search.html @@ -19,34 +19,40 @@
  • Logout
  • -
    -
    -
    -
    - -
    -
    - - -
    -
    -
    +
    +
    +

    +
    -
    - - - +
    +
    +
    + +
    -
    - - -
    -
    -
    +
    + + +
    + + - +
    + + + + + + + +
    +
    +
    + + + -- 2.43.0