<?php
include('../includes/config.php');
include('../includes/session.php'); 

header('Content-Type: application/json');

if (isset($_POST['order_id']) && isset($_POST['status'])) {
    $order_id = mysqli_real_escape_string($ahk_conn, $_POST['order_id']);
    $new_status = mysqli_real_escape_string($ahk_conn, $_POST['status']);

    // Security check: Sirf logged-in user ka record update hoga
    $mobile = $udata['phone'];

    // UPDATED QUERY: 'order_id' column ke badle 'tracking_id' use kiya hai
    $query = "UPDATE ll_exam_list SET status='$new_status' WHERE tracking_id='$order_id' AND userid='$mobile'";
    
    if (mysqli_query($ahk_conn, $query)) {
        echo json_encode(['status' => true, 'message' => 'Status Updated']);
    } else {
        echo json_encode(['status' => false, 'message' => 'Update Failed: ' . mysqli_error($ahk_conn)]);
    }
} else {
    echo json_encode(['status' => false, 'message' => 'Invalid Data']);
}
?>