57 lines
2.3 KiB
PHP
57 lines
2.3 KiB
PHP
<?php
|
|
session_start();
|
|
require_once 'config.php';
|
|
header('Content-Type: application/json');
|
|
if (isset($_SESSION["username"]))
|
|
{
|
|
$conn = dbConn();
|
|
$incidentReport = $_POST["incidentReport"];
|
|
$incidentDate = $_POST["incidentDate"];
|
|
$peopleID = $_POST["peopleID"];
|
|
$vehicleID = $_POST["vehicleID"];
|
|
$offenceID = $_POST["offenceID"];
|
|
|
|
if (isset($_POST["type"]) && isset($_POST["colour"]) && isset($_POST["plateNum"]))
|
|
{
|
|
$stmt = $conn->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"));
|
|
} |