DIDS-Coursework/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/addFine.php
rodude123 95b11f3496 Created the log functionality
Signed-off-by: rodude123 <rodude123@gmail.com>
2022-12-16 12:19:38 +00:00

35 lines
1.0 KiB
PHP

<?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();
$logSQL = "INSERT INTO Logs (Logs_type, Users_username, Logs_date) VALUES ('Added a fine', :username, NOW())";
$logStmt = $conn->prepare($logSQL);
$logStmt->bindParam(":username", $_SESSION["username"]);
$logStmt->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 "));
}
{
}