<?php
// api/my_submissions.php - 查詢使用者自己提交的截圖審核狀態
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");
require_once 'db.php';

$user_id = $_GET['user_id'] ?? 0;

try {
    $sql = "SELECT s.id as submission_id, s.status, s.created_at, t.title, t.reward 
            FROM task_submissions s
            JOIN tasks t ON s.task_id = t.id
            WHERE s.user_id = ?
            ORDER BY s.id DESC LIMIT 30";
    $stmt = $pdo->prepare($sql);
    $stmt->execute([$user_id]);
    $data = $stmt->fetchAll(PDO::FETCH_ASSOC);

    echo json_encode(["status" => "success", "data" => $data]);
} catch (Exception $e) {
    echo json_encode(["status" => "error", "message" => "DB Error: " . $e->getMessage()]);
}
?>