diff --git a/action.php b/action.php index e69f03e..b333503 100644 --- a/action.php +++ b/action.php @@ -84,6 +84,7 @@ function opCancel() { $sql = "UPDATE submitted SET status = 'CANCELED' where id = " . $_GET['id']; $result = $conn->query($sql); logJournal($conn, $_GET['id'], "Marked Canceled"); + $conn->close(); } function opLanded() { @@ -91,6 +92,15 @@ function opLanded() { $sql = "UPDATE submitted SET status = 'LANDED', landed_dt = NOW() where id = " . $_GET['id']; $result = $conn->query($sql); logJournal($conn, $_GET['id'], "Marked Landed"); + $conn->close(); +} + +function opDelete() { + $conn = connectDb(); + $sql = "UPDATE submitted SET status = 'DELETED' where id = " . $_GET['id']; + $result = $conn->query($sql); + logJournal($conn, $_GET['id'], "Marked Deleted"); + $conn->close(); } function opDetail() { @@ -128,6 +138,7 @@ function opDetail() { echo "No details found for the given ID."; } + $conn->close(); } switch($_GET['op']) { @@ -137,6 +148,9 @@ switch($_GET['op']) { case "landed": opLanded(); break; + case "delete": + opDelete(); + break; case "detail": opDetail(); break; diff --git a/admin.php b/admin.php new file mode 100644 index 0000000..c641724 --- /dev/null +++ b/admin.php @@ -0,0 +1,246 @@ + + + + + + + + + + Swansea Daily PPR + + + + + +

Swansea Inbound PPR ADMIN

+ +
+

Select a Month

+ + + +

+
+ + + +connect_error) { + die("Connection failed: " . $conn->connect_error); +} + +$sql = "SELECT * FROM submitted WHERE status != 'DELETED' ORDER BY eta ASC;"; // Replace with your table name +$result = $conn->query($sql); + +// Check if there are results +if ($result->num_rows > 0) { + // Start HTML table + echo ' + + '; + + // Output table headers (assuming column names are known) + $fields = $result->fetch_fields(); + foreach ($fields as $field) { + if ($field->name != 'id') { + echo ''; + } + + } + // echo ''; + + echo ' + + '; + + // Output table rows + while ($row = $result->fetch_assoc()) { + echo ''; + foreach ($row as $key => $value) { + if ($key != 'id') { + echo ''; + } + } + // echo ''; + echo ''; + } + + echo '
' . htmlspecialchars($field->name ?? '') . 'actions
' . htmlspecialchars($value ?? '') . '
'; +} else { + echo "No results found."; +} + +// Close the database connection +$conn->close(); + +?> + +
+ + \ No newline at end of file diff --git a/functions.php b/functions.php index 128c525..9c68543 100644 --- a/functions.php +++ b/functions.php @@ -6,6 +6,16 @@ $username = 'ppruser'; // Replace with your database username $password = 'iJ8kN*5[g6P3jaqN'; // Replace with your database password $database = 'pprdevdb'; // Replace with your database name +function getUserIP() { + if (!empty($_SERVER['HTTP_CLIENT_IP'])) { + return $_SERVER['HTTP_CLIENT_IP']; + } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { + return $_SERVER['HTTP_X_FORWARDED_FOR']; + } else { + return $_SERVER['REMOTE_ADDR']; + } +} + function connectDb() { // Create connection @@ -22,8 +32,8 @@ function connectDb() { function logJournal($conn, $id, $message) { - $stmt = $conn->prepare("INSERT INTO journal (ppr_id, entry, user) VALUES (?, ?, ?)"); - $stmt->bind_param("iss", $id, $message, $_SERVER['PHP_AUTH_USER']); + $stmt = $conn->prepare("INSERT INTO journal (ppr_id, entry, user, ip) VALUES (?, ?, ?, ?)"); + $stmt->bind_param("isss", $id, $message, $_SERVER['PHP_AUTH_USER'], getUserIP()); $stmt->execute(); $stmt->close();