<?php
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");
error_reporting(0); // 強制關閉警告
require_once 'db.php';

$creator_id = isset($_GET['creator_id']) ? intval($_GET['creator_id']) : 0;
if ($creator_id <= 0) { echo json_encode(["status" => "error", "message" => "參數錯誤"]); exit; }

try {
    $stmt = $pdo->prepare("SELECT * FROM tasks WHERE creator_id = ? ORDER BY id DESC");
    $stmt->execute([$creator_id]);
    $tasks = $stmt->fetchAll(PDO::FETCH_ASSOC);
    echo json_encode(["status" => "success", "data" => $tasks]);
} catch (Exception $e) {
    echo json_encode(["status" => "error", "message" => "資料庫連線失敗"]);
}
?>