prepare("SELECT cle, $lang FROM textes_site WHERE section = ?"); $stmt->execute([$section]); $result = []; while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { $result[$row['cle']] = $row[$lang]; } return $result; } // Fonction pour charger les paramètres du site function charger_settings($pdo) { $stmt = $pdo->query("SELECT * FROM site_settings LIMIT 1"); return $stmt->fetch(PDO::FETCH_ASSOC); } // Fonction pour charger les horaires function charger_horaires($pdo, $restaurant_id) { $stmt = $pdo->prepare("SELECT * FROM horaires WHERE restaurant_id = ? ORDER BY jour"); $stmt->execute([$restaurant_id]); return $stmt->fetchAll(PDO::FETCH_ASSOC); } // Récupération des infos du restaurant $restaurant_id = 1; $stmt = $pdo->prepare("SELECT * FROM restaurants WHERE id = ?"); $stmt->execute([$restaurant_id]); $restaurant = $stmt->fetch(PDO::FETCH_ASSOC); // Chargement des paramètres globaux $settings = charger_settings($pdo); // Chargement des textes dynamiques par section $textes_footer = charger_textes_section($pdo, 'footer', $lang); $textes_contact = charger_textes_section($pdo, 'contact', $lang); $textes_index = charger_textes_section($pdo, 'index', $lang); // Chargement des horaires $horaires = charger_horaires($pdo, $restaurant_id); // Calcul de l'horaire du jour $horaire_du_jour = 'Fermé'; $jour_index = date('w'); // 0 = dimanche, 6 = samedi $jour_sql = ($jour_index == 0) ? 6 : $jour_index - 1; $stmt = $pdo->prepare("SELECT * FROM horaires WHERE restaurant_id = ? AND jour = ?"); $stmt->execute([$restaurant_id, $jour_sql]); $horaire = $stmt->fetch(PDO::FETCH_ASSOC); $plages = []; if ($horaire) { if (!empty($horaire['midi_ouvert'])) { $plages[] = substr($horaire['midi_debut'], 0, 5) . '-' . substr($horaire['midi_fin'], 0, 5); } if (!empty($horaire['soir_ouvert'])) { $plages[] = substr($horaire['soir_debut'], 0, 5) . '-' . substr($horaire['soir_fin'], 0, 5); } $horaire_du_jour = count($plages) ? implode(' / ', $plages) : 'Fermé'; } // Chargement du menu dynamique $stmt = $pdo->prepare("SELECT * FROM menu_items WHERE restaurant_id = ? ORDER BY parent_id, position"); $stmt->execute([$restaurant_id]); $items = $stmt->fetchAll(PDO::FETCH_ASSOC); // Organisation des menus parents/enfants $menus = []; foreach ($items as $item) { if ($item['parent_id'] === null) { $menus[$item['id']] = $item; $menus[$item['id']]['children'] = []; } } foreach ($items as $item) { if ($item['parent_id'] !== null && isset($menus[$item['parent_id']])) { $menus[$item['parent_id']]['children'][] = $item; } } // Répartition menu gauche/logo/droite $menu_items = array_values($menus); $nb_total = count($menu_items); $nb_left = floor($nb_total / 2); $left_menus = array_slice($menu_items, 0, $nb_left); $right_menus = array_slice($menu_items, $nb_left); // IDs des catégories à afficher $categories_accueil = [5, 6, 3, 4]; // Génération des placeholders pour la requête préparée $placeholders = implode(',', array_fill(0, count($categories_accueil), '?')); // Préparation et exécution de la requête pour les catégories $sql = "SELECT id, nom, slug, icone_css FROM categories WHERE id IN ($placeholders) ORDER BY ordre ASC"; $stmt = $pdo->prepare($sql); $stmt->execute($categories_accueil); // Récupération des catégories dans un tableau associatif $categories = $stmt->fetchAll(PDO::FETCH_ASSOC); // Pour chaque catégorie, récupérer jusqu'à 4 plats $plats_par_categorie = []; foreach ($categories as $cat) { $sql2 = "SELECT * FROM produits WHERE categorie_id = ? ORDER BY nom_fr ASC LIMIT 4"; $stmt2 = $pdo->prepare($sql2); $stmt2->execute([$cat['id']]); $plats_par_categorie[$cat['slug']] = $stmt2->fetchAll(PDO::FETCH_ASSOC); } // Sélectionner tous les plats de la catégorie 9 suggestions $stmt = $pdo->prepare("SELECT * FROM produits WHERE categorie_id = ? ORDER BY nom_fr ASC"); $stmt->execute([9]); $plats_categorie9 = $stmt->fetchAll(PDO::FETCH_ASSOC); // DEBUG : afficher la langue active echo ''; ?>