<?php
/**
 * init_config.php
 * Exécuter UNE FOIS pour initialiser toutes les clés admin_config
 * Supprimer ce fichier après exécution.
 */
session_start();
require_once 'config.php';
require_once 'functions.php';

requireLogin();
$user = getConnectedUser($pdo);
requireAdmin($user);

$defaults = [
    'pts_chat'              => 1,
    'pts_message'           => 10,
    'pts_vote'              => 5,
    'pts_login'             => 2,
    'pts_bet_view'          => 1,
    'pts_profile'           => 1,
    'wallet_enabled'        => 1,
    'wallet_daily_free'     => 100,
    'wallet_daily_premium'  => 150,
    'wallet_daily_premplus' => 200,
    'wallet_bet_enabled'    => 0,
    'wallet_roll_min'       => 10,
    'wallet_roll_max'       => 500,
    'wallet_shop_enabled'   => 1,
    'limit_circles_free'    => 1,
    'limit_circles_premium' => 5,
    'limit_circles_premplus'=> 20,
    'limit_circles_admin'   => 999,
    'limit_bets_free'       => 10,
    'limit_bets_premium'    => 50,
    'limit_bets_premplus'   => 200,
    'limit_bets_admin'      => 999,
    'limit_friends_free'    => 20,
    'limit_friends_premium' => 100,
    'limit_friends_premplus'=> 500,
    'limit_friends_admin'   => 999,
    'limit_photos_free'     => 2,
    'limit_photos_premium'  => 10,
    'limit_photos_premplus' => 30,
    'limit_photos_admin'    => 999,
    'limit_pm_free'         => 20,
    'limit_pm_premium'      => 200,
    'limit_pm_premplus'     => 999,
    'limit_pm_admin'        => 999,
    'marquee_bg'            => '#0d0d0d',
    'flash_enabled'         => 1,
    'flash_duration'        => 5,
    'flash_delay'           => 2,
    'block_media'           => 0,
];

$inserted = 0; $existing = 0;
foreach ($defaults as $key => $val) {
    $check = $pdo->prepare("SELECT config_value FROM admin_config WHERE config_key=?");
    $check->execute([$key]);
    if ($check->fetch() === false) {
        $pdo->prepare("INSERT INTO admin_config (config_key, config_value) VALUES (?,?)")
            ->execute([$key, $val]);
        $inserted++;
    } else {
        $existing++;
    }
}

echo "<h2>✅ Initialisation terminée</h2>";
echo "<p><strong>$inserted</strong> clés créées</p>";
echo "<p><strong>$existing</strong> clés déjà existantes (non modifiées)</p>";
echo "<hr><h3>État actuel de admin_config :</h3>";
echo "<table border='1' cellpadding='5'><tr><th>Clé</th><th>Valeur</th></tr>";
foreach ($pdo->query("SELECT config_key, config_value FROM admin_config ORDER BY config_key ASC")->fetchAll() as $row) {
    echo "<tr><td>{$row['config_key']}</td><td>{$row['config_value']}</td></tr>";
}
echo "</table>";
echo "<hr><p style='color:red;font-weight:bold;'>⚠️ Supprime ce fichier de ton serveur après utilisation !</p>";
?>
