<?php
session_start();
if (!isset($_SESSION["user"])) {
    header("Location: login.php");
    exit;
}

$host = "localhost";
$user = "appshett_ibill";
$pass = "appshett_ibill";
$dbname = "appshett_ibill";
$conn = new mysqli($host, $user, $pass, $dbname);

if ($conn->connect_error) {
    die("Database connection failed.");
}

if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $tracking_id = $_POST['tracking_id'] ?? null;
    $status = $_POST['status'] ?? null;

    if ($tracking_id && $status) {
        $stmt = $conn->prepare("UPDATE validation_request SET status = ? WHERE tracking_id = ?");
        $stmt->bind_param("ss", $status, $tracking_id);

        if ($stmt->execute()) {
            $stmt->close();
            $conn->close();
            
            // Redirect back to the validation page after updating
            header("Location: view_validation.php");
            exit;
        } else {
            echo "Error updating transaction.";
        }
    } else {
        echo "Invalid request.";
    }
}
?>
