<?php
// Désactiver les erreurs visibles et activer les logs
ini_set('display_errors', 0);
ini_set('display_startup_errors', 0);
ini_set('log_errors', 1);
ini_set('error_log', '/home/lantheu/logs/php_errors.log');
error_reporting(E_ALL);
// Configuration de la base de données
define('DB_HOST', 'lantheurecettes.mysql.db');
define('DB_NAME', 'lantheurecettes');
define('DB_USER', 'lantheurecettes');
define('DB_PASS', 'Recettes203040');
define('DB_CHARSET', 'utf8mb4');

// Configuration du site
define('SITE_NOM', 'Recettes de Famille');
define('SITE_URL', 'https://lantheaume.fr');

// Configuration email (pour reset mot de passe)
define('EMAIL_FROM', 'noreply@lantheaume.fr');
define('EMAIL_NOM', 'Recettes de Famille');

// Durée d'inactivité avant déconnexion automatique (en secondes)
define('SESSION_EXPIRATION', 3600); // 1 heure

// Démarrage de la session
if (session_status() === PHP_SESSION_NONE) {
    session_start();
}

// Vérifier l'expiration de la session
if (isset($_SESSION['derniere_activite'])) {
    if (time() - $_SESSION['derniere_activite'] > SESSION_EXPIRATION) {
        // Session expirée — déconnecter
        $_SESSION = [];
        session_destroy();
        session_start();
    } else {
        // Mettre à jour l'heure de dernière activité
        $_SESSION['derniere_activite'] = time();
    }
}

// Connexion à la base de données
try {
    $pdo = new PDO(
        'mysql:host=' . DB_HOST . ';dbname=' . DB_NAME . ';charset=' . DB_CHARSET,
        DB_USER,
        DB_PASS,
        [
            PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
            PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
            PDO::ATTR_EMULATE_PREPARES => false,
        ]
    );
} catch (PDOException $e) {
    die('Erreur de connexion à la base de données.');
}

// Google Drive — Backup
define('GDRIVE_FOLDER_ID', '1FM9UnawOiGoEdVxnk77NMnsAxPig_xCz');
define('GDRIVE_CREDENTIALS', [
    "type"           => "service_account",
    "project_id"     => "recettes-famille-492212",
    "private_key_id" => "cf3c9979a13fb42ee85c81ff625009d71422d245",
    "private_key"    => "-----BEGIN PRIVATE KEY-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CM7I9h5EZk5v0Y3TEvD53hKfN+Ov3bwVrYOG+1Sx\nXd6kyaYxIwKBgQC3PxCwKT8Bd/g7cPzkbWH0G68H3TZzeXDwIkpDabtBUZcKcEfm\nruffgSk0o1mVTMQVpBvQpdrZ3GfUu2snxtf6nQZCVI8KeB31Q3F/grjdLRp051fk\nsZ9mrj86xaPOQYloJ4biFQwkNA1YnRs0Xc4bujCChmRr4SQwmON54DTAXwKBgBi2\n701HroucVBu1qGJSEiaI4qQ7kA9CBoGRxL8TZK3jOeO1VFxzuhbJ2pf/tSG1nPug\nCCLXm4i6ZKCZuOFlnxfAxdxv+sSo96+lT1s1KZS5zDNEHpu2imWysyRvBQnSxhz4\nwolQMj5TxulE1YznA+9C0I80huvfcNQs3b0nFvgfAoGAaLGxvfbd+OK2YKtkeC70\niY4ln4H84gedwOBo3w0eE2s6Y1efoCP4uiHJx8OZX4GAsQB4OOFV7LmX2jFgWn7m\nmhi862JN0a9OWEsOB04HhVtXTuDtJxbbGZZUVXHH1yDFcZGetijdukxG2N2vI/TU\nv/Xp1RW+U/W3bDwhLCbucKo=\n-----END PRIVATE KEY-----\n",
    "client_email"   => "backup-recettes@recettes-famille-492212.iam.gserviceaccount.com",
    "client_id"      => "113202121612818427031",
    "token_uri"      => "https://oauth2.googleapis.com/token",
    "sub"            => "jean-charles@lantheaume.fr"
]);
