| Current Path : /home/happyrenas/myreco.online/ |
Linux webd005.cluster105.gra.hosting.ovh.net 5.15.206-ovh-vps-grsec-zfs-classid #1 SMP Fri May 15 02:41:25 UTC 2026 x86_64 |
| Current File : /home/happyrenas/myreco.online/hebergement_resultat.php |
<?
include("configuration.php");
include("includes/fonctions.php");
$country_code="FR";
$trad = chargerTraductions($country_code);
?>
<html class="no-js" lang="<?echo $country_code;?>">
<head>
<?include("includes/google_head.php");?>
<meta charset="utf-8">
<title>MyReco.Online</title>
<meta name="description" content="">
<meta name="robots" content="noindex, nofollow">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="shortcut icon" href="https://www.myreco.online/img/icone.png" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<link rel="stylesheet" href="https://www.myreco.online/css/custom1.css">
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/flatpickr/dist/flatpickr.min.css">
<script src="https://cdn.jsdelivr.net/npm/flatpickr"></script>
<script src="https://cdn.jsdelivr.net/npm/flatpickr/dist/l10n/fr.js"></script>
<style>
.awesomplete ul {
background-color: #fff;
border: 1px solid #6B757D;
border-radius: 4px;
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}
.awesomplete li {
padding: 8px 12px;
color: #6B757D;
font-weight: 500;
}
.awesomplete li[aria-selected="true"] {
background: #e1dbd5;
}
</style>
</head>
<body>
<div id="halt_loader_overlay"></div><div id="halt_loader" class=""><i class="fa fa-spinner fa-spin"></i> <?echo $trad['Chargement des informations, merci de patienter'] ?? '⚠️';?></div>
<?
// ➤ Extraction de la ville et du code pays
$parts = explode(',', ($_GET["ville_pays"]));
$ville_clean = trim($parts[0]);
$pays_clean = strtoupper(trim($parts[1] ?? ''));
// ➤ Vérifier si cache déjà existant :
$requete_cache="
SELECT resultat_json, compteur
FROM ville_recherche_cache
WHERE ville = '" . $db->escape($ville_clean) . "'
AND pays = '" . $db->escape($pays_clean) . "'
";
$cache = $db->get_row($requete_cache);
$cache="";
if ($cache) {
$miseencache=1;
// Mise à jour du compteur
$db->query("
UPDATE ville_recherche_cache
SET compteur = compteur + 1, last_search = NOW()
WHERE ville = '" . $db->escape($ville_clean) . "'
AND pays = '" . $db->escape($pays_clean) . "'
");
$tableau_liste = json_decode($cache->resultat_json, true);
} else {
$miseencache=0;
// ➤ Sinon
$tableau_liste = rechercherHebergementsProches($_GET['ville_pays'], $db);
//echo "<pre>";
//print_r($tableau_liste);
//echo "</pre>";
//exit;
// Enregistrement dans le cache
$db->query("
INSERT INTO ville_recherche_cache (ville, pays, resultat_json)
VALUES (
'" . $db->escape($ville_clean) . "',
'" . $db->escape($pays_clean) . "',
'" . $db->escape(json_encode($tableau_liste, JSON_UNESCAPED_UNICODE)) . "'
)
ON DUPLICATE KEY UPDATE
resultat_json = VALUES(resultat_json),
compteur = compteur + 1,
last_search = NOW()
");
}
// ➤ Gestion de la langue
if (isset($_GET['langue']) && in_array(strtoupper($_GET['langue']), $langues)) {
$_SESSION['langue'] = strtoupper($_GET['langue']);
}
if (isset($_SESSION['langue']) && in_array($_SESSION['langue'], $langues)) {
$langue = $_SESSION['langue'];
} else {
$country_code = strtoupper($pays_clean ?? 'FR');
$langue = in_array($country_code, $langues) ? $country_code : 'FR';
$_SESSION['langue'] = $langue; // On l'enregistre aussi
}
$trad = chargerTraductions($langue);
include("includes/google_body.php");
include("includes/hebergements_head.php");
?>
<div class="container" style="max-width: 1900px; margin-top: 160px; min-height: 120px; border: 1px solid #6B757D; border-radius: 8px;">
<?
//$hebs_ville = array_filter($tableau_liste, fn($h) => $h['origine'] === 'ville');
//$hebs_autour = array_filter($tableau_liste, fn($h) => $h['origine'] === 'rectangle');
?>
<div class="row">
<div class="col-sm-6 py-2 mb-2">
<h3 class='mb-4'><?echo $trad['Hébergements à'] ?? '⚠️';?> <strong><?echo $_GET['ville_pays'];?></strong><small><?echo $miseencache;?></h3>
<?php foreach ($tableau_liste as $lieu): ?>
<div class="card mb-3">
<div class="row no-gutters" style="min-height: 250px; height: 100%;">
<!-- Badge en haut à droite -->
<?php if (!empty($lieu['type_hebergement'])): ?>
<div style="position: absolute; top: 10px; right: 10px; z-index: 10;">
<span class="badge badge-success" style="font-size: 0.85em;"><?= $lieu['type_hebergement'] ?></span>
</div>
<?php endif;?>
<div style="position: absolute; top: 0px; left: 0px; z-index: 10;">
<span class="badge badge-success" style="font-size: 1.85em;"><?= $lieu['distance'] ?> <?= $lieu['origine'] ?></span>
</div>
<!-- Colonne image -->
<div class="col-md-4">
<div class="h-100" style="max-height:250px;">
<img src="<?= $lieu['photo']['url'] ?>" class="card-img h-100" style="object-fit: cover;" title="<?= $lieu['photo']['url'] ?>">
</div>
</div>
<!-- Colonne texte -->
<div class="col-md-8">
<div class="card-body d-flex flex-column h-100">
<?echo "<pre>";print_r($lieu);echo"</pre>";?>
<div class="flex-grow-1">
<h5 class="card-title mb-1"><?= htmlspecialchars($lieu['name']) ?></h5>
<small class="text-muted">
<? echo $lieu['postal_code'];?> <? echo $lieu['country_code'];?>
</small>
<? echo $lieu['distance'];?>
<p class="mb-1 text-muted"><?= htmlspecialchars($lieu['ville']) ?> <?= htmlspecialchars($lieu['category']) ?></p>
<?php if (!empty($lieu['donnees']['etoiles'])): ?>
<p class="mb-1 text-warning">
<?php
$nb = (int) $lieu['donnees']['etoiles'];
for ($i = 0; $i < $nb; $i++) {
echo '<i class="fas fa-star"></i> ';
}
?>
</p>
<?php endif; ?>
<?php if (!empty($lieu['donnees']['nb_chambres']) || !empty($lieu['donnees']['nb_sdb'])): ?>
<div class="d-flex mb-1" style="gap: 20px;">
<?php if (!empty($lieu['donnees']['nb_chambres'])): ?>
<div class="d-flex align-items-center">
<i class="fas fa-bed text-muted mr-1" style="font-size: 0.8em;"></i>
<small class="text-muted">
<?= (int)$lieu['donnees']['nb_chambres'] ?> <?echo $trad['chambres'] ?? '⚠️';?>
</small>
</div>
<?php endif; ?>
<?php if (!empty($lieu['donnees']['nb_sdb'])): ?>
<div class="d-flex align-items-center">
<i class="fas fa-bath text-muted mr-1" style="font-size: 0.8em;"></i>
<small class="text-muted">
<?= (int)$lieu['donnees']['nb_sdb'] ?> <?echo $trad['salle de bain'] ?? '⚠️';?>
</small>
</div>
<?php endif; ?>
</div>
<?php endif; ?>
<?php
$date_arrivee = $_GET['date_arrivee'] ?? null;
$date_depart = $_GET['date_depart'] ?? null;
$tarif_nuit = (float)$lieu['tarif_nuit'];
$nb_nuits = 1;
$cout_total = 0;
if ($date_arrivee && $date_depart) {
$d1 = DateTime::createFromFormat('d-m-Y', $date_arrivee);
$d2 = DateTime::createFromFormat('d-m-Y', $date_depart);
if ($d1 && $d2 && $d1 < $d2) {
$nb_nuits = $d1->diff($d2)->days;
}
}
$cout_total = $nb_nuits * $tarif_nuit;?>
<?php if ($tarif_nuit > 0): ?>
<p class="mt-2 mb-1">
<b><?= number_format($tarif_nuit, 2, ',', ' ') ?> € / <?echo $trad['nuit'] ?? '⚠️';?></b>
<?php if ($nb_nuits > 1): ?>
<small class="text-muted">(<?echo $trad['Total séjour'] ?? '⚠️';?> : <?= number_format($cout_total, 2, ',', ' ') ?> € <?echo $trad['pour'] ?? '⚠️';?> <?= $nb_nuits ?> <?echo $trad['nuit'] ?? '⚠️';?>)</small>
<?php endif; ?>
</p>
<?php endif; ?>
<?php if (!empty($lieu['equipements'])): ?>
<p class="mb-1"><small class="text-muted"><?= implode(' · ', $lieu['equipements']) ?></small></p>
<?php endif; ?>
<?php if (!empty($lieu['activites'])): ?>
<p class="mb-1"><small class="text-muted"><?= implode(' · ', $lieu['activites']) ?></small></p>
<?php endif; ?>
<?php if (!empty($lieu['parking'])): ?>
<p class="mb-1"><small class="text-muted"><?= $lieu['parking'] ?></small></p>
<?php endif; ?>
<p class="mt-2 mb-2">
<?//= $lieu['token'] ?>
</p>
</div>
<div>
<a href="contacter.php?heb_id=<?= $lieu['id'] ?>" class="btn btn-secondary btn-block text-white mt-2"><?echo $trad['Contacter l hote'] ?? '⚠️';?></a>
</div>
</div>
</div>
</div>
</div>
<?php endforeach; ?>
</div>
<div class="col-sm-6 py-2 mb-2">
<div id="map" style="height: 500px; margin-bottom: 30px;"></div>
</div>
</div>
</div>
<link rel="stylesheet" href="https://code.jquery.com/ui/1.13.2/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/ui/1.13.2/jquery-ui.min.js"></script>
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" />
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script>
<!-- CSS Awesomplete -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/awesomplete/1.1.5/awesomplete.css" />
<!-- JS Awesomplete -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/awesomplete/1.1.5/awesomplete.min.js"></script>
<?php
$points = [];
foreach ($tableau_liste as $lieu) {
//$fiche = $db->get_row("SELECT * FROM heb WHERE id = " . intval($lieu['id']));
$points[] = [
'nom' => $lieu['name'],
'ville' => $lieu['ville'],
'tarif' => $lieu['tarif_nuit'],
'lat' => floatval($lieu['latitude']),
'lon' => floatval($lieu['longitude']),
'id' => $lieu['id']
];
}
?>
<script>
const hebPoints = <?= json_encode($points); ?>;
</script>
<script>
document.addEventListener("DOMContentLoaded45", function () {
if (!hebPoints.length) return;
const map = L.map('map').setView([hebPoints[0].lat, hebPoints[0].lon], 8);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© OpenStreetMap',
maxZoom: 18,
}).addTo(map);
hebPoints.forEach(p => {
const marker = L.marker([p.lat, p.lon]).addTo(map);
marker.bindPopup(`
<strong>${p.nom}</strong><br>
${p.ville}<br>
${p.tarif}€/nuit<br>
<a href='contacter.php?heb_id=${p.id}' class='btn btn-sm btn-link'>Contacter</a>
`);
});
});
</script>
<script type="text/javascript" src="js/notify.js"></script>
<script>
$(document).ready( function(){
function showLoader() {
$('#halt_loader_overlay').show();
$('#halt_loader').show();
$('#message_erreur').text("").removeClass('alert-danger').attr("title", '').show();
}
function hideLoader(error = null) {
$('#halt_loader_overlay').hide();
$('#halt_loader').hide();
if (error) {
$('#message_erreur')
.text("Une erreur est survenue")
.addClass('alert-danger')
.attr("title", error) // Affiche l'erreur au survol
.show();
}
}
$("#btn_rechercher").on("click", function() {
showLoader();
});
// Initialisation des deux champs
const dateArrivee = flatpickr("#date_arrivee", {
dateFormat: "d-m-Y",
locale: "fr",
onChange: function(selectedDates, dateStr, instance) {
// Met à jour la date min du champ départ
dateDepart.set("minDate", dateStr);
}
});
const dateDepart = flatpickr("#date_depart", {
dateFormat: "d-m-Y",
locale: "fr"
});
const input = document.getElementById("ville_pays");
const clearBtn = document.getElementById("clear_ville");
let lastPrefix = "";
let lastList = [];
let awesomplete = new Awesomplete(input, {
minChars: 3,
maxItems: 20,
autoFirst: true
});
// Si le champ est prérempli (ex : via GET), afficher la croix et précharger les suggestions
const initialVal = input.value.trim();
if (initialVal.length >= 2) {
clearBtn.style.display = "inline";
const prefix = initialVal.substring(0, 2).toLowerCase();
fetch("includes/data/villes_prefix/villes_" + prefix + ".json")
.then(res => res.ok ? res.json() : [])
.then(data => {
lastPrefix = prefix;
lastList = data;
// Prépare les suggestions en filtrant le JSON local
awesomplete.list = filterSuggestions(data, initialVal);
})
.catch(() => {
awesomplete.list = [];
});
}
input.addEventListener("input", function () {
const term = input.value.trim();
clearBtn.style.display = term.length ? "inline" : "none";
if (term.length >= 2) {
const prefix = term.substring(0, 2).toLowerCase();
if (prefix !== lastPrefix) {
// Nouveau préfixe → charger nouveau fichier JSON
fetch("includes/data/villes_prefix/villes_" + prefix + ".json")
.then(res => {
if (!res.ok) throw new Error("Fichier non trouvé");
return res.json();
})
.then(data => {
lastPrefix = prefix;
lastList = data;
awesomplete.list = filterSuggestions(data, term);
})
.catch(() => {
awesomplete.list = [];
});
} else {
// Même préfixe → filtrer localement
awesomplete.list = filterSuggestions(lastList, term);
}
} else {
awesomplete.list = [];
}
});
// Filtrage des suggestions
function filterSuggestions(list, term) {
const lc = term.toLowerCase();
return list.filter(item => item.toLowerCase().includes(lc)).slice(0, 40);
}
// Affiche suggestions précédentes au focus
input.addEventListener("focus", function () {
if (lastList.length && input.value.trim().length >= 2) {
awesomplete.list = filterSuggestions(lastList, input.value.trim());
}
});
// Action lors de la sélection
input.addEventListener("awesomplete-selectcomplete", function () {
console.log("Ville sélectionnée :", input.value);
setTimeout(() => dateArrivee.open(), 100);
});
// Bouton de reset
clearBtn.addEventListener("click", function () {
input.value = "";
input.focus();
clearBtn.style.display = "none";
awesomplete.list = [];
});
});
</script>
</body>
</html>