<?php
// Location: taka26.site/public_html/update_aviator_link.php
// Open once in browser, then delete this file.

require_once __DIR__ . '/auth_helper.php';

header('Content-Type: text/plain; charset=utf-8');

try {
    if (function_exists('set_setting')) {
        set_setting('aviator_url', 'aviator_launch.php');
    } else {
        pdo()->prepare("
            INSERT INTO settings(setting_key, setting_value, updated_at)
            VALUES('aviator_url', 'aviator_launch.php', ?)
            ON DUPLICATE KEY UPDATE
            setting_value='aviator_launch.php',
            updated_at=VALUES(updated_at)
        ")->execute([date('Y-m-d H:i:s')]);
    }

    try {
        pdo()->prepare("
            UPDATE games 
            SET game_url='aviator_launch.php' 
            WHERE LOWER(title)='aviator'
        ")->execute();
    } catch (Throwable $ignore) {}

    echo "OK: Aviator link updated to aviator_launch.php\n";
    echo "Now delete this file: update_aviator_link.php\n";

} catch (Throwable $e) {
    echo "FAILED: " . $e->getMessage();
}