From afa89167b4f5e15eb350f9e9463fa020427b2ded Mon Sep 17 00:00:00 2001 From: Flatlogic Bot Date: Sat, 4 Oct 2025 17:32:15 +0000 Subject: [PATCH] v01.4 --- api/update_status.php | 36 +++++++++++++++++++++++++++ dashboard.php | 57 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 api/update_status.php diff --git a/api/update_status.php b/api/update_status.php new file mode 100644 index 0000000..2795e4c --- /dev/null +++ b/api/update_status.php @@ -0,0 +1,36 @@ + false, 'message' => 'Invalid request.']); + exit; +} + +$id = $_POST['id']; +$status = $_POST['status']; +$allowed_statuses = ['Approved', 'Rejected']; + +if (!in_array($status, $allowed_statuses)) { + echo json_encode(['success' => false, 'message' => 'Invalid status.']); + exit; +} + +try { + $pdo = db(); + $stmt = $pdo->prepare("UPDATE expense_reports SET status = ? WHERE id = ?"); + $success = $stmt->execute([$status, $id]); + + if ($success) { + echo json_encode(['success' => true, 'message' => 'Status updated successfully.']); + } else { + echo json_encode(['success' => false, 'message' => 'Failed to update status.']); + } + +} catch (PDOException $e) { + // In a real app, log this error. + echo json_encode(['success' => false, 'message' => 'Database error: ' . $e->getMessage()]); +} +?> \ No newline at end of file diff --git a/dashboard.php b/dashboard.php index 57e0a53..5461f21 100644 --- a/dashboard.php +++ b/dashboard.php @@ -124,7 +124,10 @@ function getStatusBadgeClass($status) { - View +
+ + +
@@ -141,5 +144,57 @@ function getStatusBadgeClass($status) { + \ No newline at end of file