<?php
require_once '../config.php';
require_once '../stock_engine.php';

// 權限檢查 (僅限世界政府)
if (!isset($_SESSION['super_admin_logged_in']) || $_SESSION['super_admin_logged_in'] !== true) {
    header("Location: login.php");
    exit;
}

try {
    // 1. 把所有股票的「最後更新日期」強制作弊退回昨天 (5/31)
    $yesterday = date('Y-m-d', strtotime('-1 day'));
    $mysql_db->exec("UPDATE global_stocks SET last_update_date = '{$yesterday}' WHERE is_active = 1");

    // 2. 呼叫大盤引擎！引擎會以為今天還沒更新過，立刻產生今日的隨機漲跌幅！
    StockEngine::updateDailyPrices($mysql_db);

    $msg = "⚡ 大盤電擊成功！系統已遭欺騙並強制產生了 6/1 的最新漲跌幅！";
} catch (Exception $e) {
    $msg = "電擊失敗：" . $e->getMessage();
}
?>

<!DOCTYPE html>
<html lang="zh-TW">
<head>
    <meta charset="UTF-8">
    <title>大盤強制電擊器</title>
    <style>
        body { font-family: 'Segoe UI', sans-serif; background-color: #1a1a2e; color: #fff; text-align: center; padding: 100px 20px; }
        .card { background: #16213e; padding: 40px; border-radius: 12px; border: 1px solid #e94560; display: inline-block; box-shadow: 0 0 20px rgba(233, 69, 96, 0.4); }
        .btn { display: inline-block; margin-top: 20px; padding: 10px 20px; background: #4facfe; color: #fff; text-decoration: none; border-radius: 6px; font-weight: bold; }
    </style>
</head>
<body>
    <div class="card">
        <h1 style="margin-top:0;">⚡ 系統電擊完畢</h1>
        <p style="font-size: 1.2rem;"><?php echo $msg; ?></p>
        <a href="stocks-super.php" class="btn">返回證券交易所大盤</a>
    </div>
</body>
</html>