<?php
include 'dbconnect.php';

if ($_SERVER["REQUEST_METHOD"] === "POST" && isset($_POST['user_id'], $_POST['lead_flag'])) {
    $user_id = $_POST['user_id'];
    $lead_flag = $_POST['lead_flag'] === 'On' ? 1 : 0;
    $euser = "ADMIN"; // or use session user
    $edate = date("Y-m-d H:i:s");

    $sql = "UPDATE tbl_invite_user 
            SET lead_flag = '$lead_flag', edate = '$edate', euser = '$euser'
            WHERE id = '$user_id'";

    if (mysqli_query($conn, $sql)) {
        echo "success";
    } else {
        http_response_code(500);
        echo "Database error.";
    }

    exit;
}
?>
