add-admin #5
@ -0,0 +1,53 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Add Fines</title>
|
||||
<link rel="stylesheet" href="css/nav.css">
|
||||
</head>
|
||||
<body>
|
||||
<nav>
|
||||
<ul>
|
||||
<li><a href="search.html" class="btn">Search</a></li>
|
||||
<li><a href="addVehicle.html" class="btn">Add new vehicle</a></li>
|
||||
<li><a href="newReport.html" class="btn">Create new report</a></li>
|
||||
<li class="admin"><a href="newUser.html" class="btn">Create new user</a></li>
|
||||
<li class="admin"><a href="addFine.html" class="btn active">Add Fines</a></li>
|
||||
<li class="admin"><a href="viewLog.html" class="btn">View log</a></li>
|
||||
<li><a href="changePassword.html" class="btn">Change password</a></li>
|
||||
<li><a id="logout" class="btn">Logout</a></li>
|
||||
</ul>
|
||||
</nav>
|
||||
|
||||
<main>
|
||||
<header id="title">
|
||||
<h1></h1>
|
||||
</header>
|
||||
|
||||
<form method="POST" id="addFineForm">
|
||||
<div class="formControl">
|
||||
<label for="amount">Amount in £</label>
|
||||
<input type="number" name="amount" id="amount" required>
|
||||
</div>
|
||||
|
||||
<div class="formControl">
|
||||
<label for="points">Points</label>
|
||||
<input type="number" name="points" id="points" required>
|
||||
</div>
|
||||
|
||||
<div class="formControl"><label for="incident">Incident</label>
|
||||
<div class="selectDiv">
|
||||
<select id="incident" name="incident" required>
|
||||
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<input type="submit" value="Add Fines" class="btn btnPrimary" style="margin-top: 1em;">
|
||||
</form>
|
||||
</main>
|
||||
|
||||
<script src="js/checkUser.js"></script>
|
||||
<script src="js/addFine.js"></script>
|
||||
</body>
|
||||
</html>
|
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
session_start();
|
||||
require_once 'config.php';
|
||||
header('Content-Type: application/json');
|
||||
|
||||
if (isset($_SESSION["username"]) && isset($_SESSION["admin"]))
|
||||
{
|
||||
$conn = dbConn();
|
||||
$amount = $_POST["amount"];
|
||||
$points = $_POST["points"];
|
||||
$incident = $_POST["incident"];
|
||||
|
||||
$stmt = $conn->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 "));
|
||||
}
|
||||
{
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Title</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
</body>
|
||||
</html>
|
@ -12,7 +12,7 @@
|
||||
<li><a href="addVehicle.html" class="btn active">Add new vehicle</a></li>
|
||||
<li><a href="newReport.html" class="btn">Create new report</a></li>
|
||||
<li class="admin"><a href="newUser.html" class="btn">Create new user</a></li>
|
||||
<li class="admin"><a href="addFines.html" class="btn">Add Fines</a></li>
|
||||
<li class="admin"><a href="addFine.html" class="btn">Add Fines</a></li>
|
||||
<li class="admin"><a href="viewLog.html" class="btn">View log</a></li>
|
||||
<li><a href="changePassword.html" class="btn">Change password</a></li>
|
||||
<li><a id="logout" class="btn">Logout</a></li>
|
||||
|
@ -12,7 +12,7 @@
|
||||
<li><a href="addVehicle.html" class="btn">Add new vehicle</a></li>
|
||||
<li><a href="newReport.html" class="btn">Create new report</a></li>
|
||||
<li class="admin"><a href="newUser.html" class="btn">Create new user</a></li>
|
||||
<li class="admin"><a href="addFines.html" class="btn">Add Fines</a></li>
|
||||
<li class="admin"><a href="addFine.html" class="btn">Add Fines</a></li>
|
||||
<li class="admin"><a href="viewLog.html" class="btn">View log</a></li>
|
||||
<li><a href="changePassword.html" class="btn active">Change password</a></li>
|
||||
<li><a id="logout" class="btn">Logout</a></li>
|
||||
|
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
session_start();
|
||||
require_once 'config.php';
|
||||
header('Content-Type: application/json');
|
||||
|
||||
if (isset($_SESSION["username"]) && isset($_SESSION["admin"]))
|
||||
{
|
||||
$conn = dbConn();
|
||||
$stmt = $conn->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 "));
|
||||
}
|
@ -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 += `<option value="${incident.Incident_ID}">${incident.Incident_Report} — ${incident.Incident_Date}</option>`;
|
||||
}
|
||||
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");
|
||||
}
|
||||
|
||||
}));
|
||||
});
|
@ -12,7 +12,7 @@
|
||||
<li><a href="addVehicle.html" class="btn">Add new vehicle</a></li>
|
||||
<li><a href="newReport.html" class="btn">Create new report</a></li>
|
||||
<li class="admin"><a href="newUser.html" class="btn active">Create new user</a></li>
|
||||
<li class="admin"><a href="addFines.html" class="btn">Add Fines</a></li>
|
||||
<li class="admin"><a href="addFine.html" class="btn">Add Fines</a></li>
|
||||
<li class="admin"><a href="viewLog.html" class="btn">View log</a></li>
|
||||
<li><a href="changePassword.html" class="btn">Change password</a></li>
|
||||
<li><a id="logout" class="btn">Logout</a></li>
|
||||
|
@ -13,7 +13,7 @@
|
||||
<li><a href="addVehicle.html" class="btn">Add new vehicle</a></li>
|
||||
<li><a href="newReport.html" class="btn">Create new report</a></li>
|
||||
<li class="admin"><a href="newUser.html" class="btn">Create new user</a></li>
|
||||
<li class="admin"><a href="addFines.html" class="btn">Add Fines</a></li>
|
||||
<li class="admin"><a href="addFine.html" class="btn">Add Fines</a></li>
|
||||
<li class="admin"><a href="viewLog.html" class="btn">View log</a></li>
|
||||
<li><a href="changePassword.html" class="btn">Change password</a></li>
|
||||
<li><a id="logout" class="btn">Logout</a></li>
|
||||
@ -34,7 +34,7 @@
|
||||
</div>
|
||||
|
||||
<div class="searchBtnContainer">
|
||||
<input type="text" id="searchField" name="searchField" placeholder="Find owner">
|
||||
<input type="text" id="searchField" name="searchField" placeholder="Find owner" required>
|
||||
<button type="submit"><i class="fa-solid fa-magnifying-glass"></i></button>
|
||||
</div>
|
||||
</form>
|
||||
|
Loading…
Reference in New Issue
Block a user