<?php
include('../../connection.php');
mysqli_set_charset($conn, 'utf8mb4');
header("Content-Type: application/json");

if (isset($_POST['id'])) {
    $id = $_POST['id'];
    $status = isset($_POST['status']) ? $_POST['status'] : 'done';

    $stmt = $conn->prepare("UPDATE marketing SET status=? WHERE id=?");
    $stmt->bind_param("si", $status, $id);

    if ($stmt->execute()) {
        echo json_encode([
            'status' => 'success',
            'message' => 'Status updated to ' . $status
        ]);
    } else {
        echo json_encode([
            'status' => 'error',
            'message' => 'Database error: ' . $stmt->error
        ]);
    }

    $stmt->close();
} else {
    echo json_encode([
        'status' => 'error',
        'message' => 'ID is required'
    ]);
}

$conn->close();
?>
