<?php
require 'db_config.php';
header('Content-Type: application/json');

$user_id = intval($_POST['user_id'] ?? 0);

if (!$user_id) {
    echo json_encode(['status' => 'error', 'message' => 'Missing user ID']);
    exit;
}

$check = $conn->prepare("SELECT id FROM promotional_materials WHERE user_id = ?");
$check->bind_param("i", $user_id);
$check->execute();
$check->store_result();

if ($check->num_rows > 0) {
    echo json_encode(['status' => 'already_collected']);
} else {
    echo json_encode(['status' => 'ok']);
}
