| Current Path : /home/happyrenas/find.myreco.online/OLD/ |
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/find.myreco.online/OLD/test.php |
<?php
session_start();
include("configuration.php");
include("includes/fonctions.php");
//include("includes/fonctions_hebergements.php"); // adapte le chemin si besoin
$ville_pays = trim($_GET['ville_pays'] ?? 'Revel, FR');
$rayon_km = (int)($_GET['rayon_km'] ?? 50);
if ($rayon_km <= 0) {
$rayon_km = 50;
}
function hh($value)
{
return htmlspecialchars((string)$value, ENT_QUOTES, 'UTF-8');
}
$parts = explode(',', $ville_pays);
$ville = trim($parts[0] ?? '');
$pays = strtoupper(trim($parts[1] ?? ''));
$erreur = '';
$debug_rows = [];
$ville_ref = null;
$lat_ref = null;
$lon_ref = null;
$delta_lat = null;
$delta_lon = null;
if ($ville === '' || $pays === '') {
$erreur = "Format attendu : Ville, FR";
} else {
// Point de référence actuel : 1 hébergement trouvé dans la ville
$ville_ref = $db->get_row("
SELECT id, name, city, country_code, latitude, longitude
FROM heb
WHERE city = '" . $db->escape($ville) . "'
AND country_code = '" . $db->escape($pays) . "'
AND name != 'lite'
AND latitude IS NOT NULL
AND longitude IS NOT NULL
LIMIT 1
");
if (!$ville_ref) {
$erreur = "Aucun point de référence trouvé pour {$ville}, {$pays}.";
} else {
$lat_ref = (float) str_replace(",", ".", $ville_ref->latitude);
$lon_ref = (float) str_replace(",", ".", $ville_ref->longitude);
// Version corrigée pour debug
$delta_lat = $rayon_km / 111;
$delta_lon = $rayon_km / (111 * cos(deg2rad($lat_ref)));
// 1) Hébergements dans la ville
$hebs_ville = $db->get_results("
SELECT *
FROM heb
WHERE city = '" . $db->escape($ville) . "'
AND country_code = '" . $db->escape($pays) . "'
AND name != 'lite'
AND latitude IS NOT NULL
AND longitude IS NOT NULL
");
$hebergements = [];
$ids_deja = [];
if ($hebs_ville) {
foreach ($hebs_ville as $h) {
$h->origine_debug = 'ville';
$hebergements[] = $h;
$ids_deja[] = (int)$h->id;
}
}
// 2) Hébergements dans le rectangle élargi
$exclusion = $ids_deja
? "AND id NOT IN (" . implode(',', array_map('intval', $ids_deja)) . ")"
: '';
$hebs_rect = $db->get_results("
SELECT *
FROM heb
WHERE CAST(REPLACE(latitude, ',', '.') AS DECIMAL(10,6)) BETWEEN " . ($lat_ref - $delta_lat) . " AND " . ($lat_ref + $delta_lat) . "
AND CAST(REPLACE(longitude, ',', '.') AS DECIMAL(10,6)) BETWEEN " . ($lon_ref - $delta_lon) . " AND " . ($lon_ref + $delta_lon) . "
AND country_code = '" . $db->escape($pays) . "'
AND name != 'lite'
$exclusion
");
if ($hebs_rect) {
foreach ($hebs_rect as $h) {
$h->origine_debug = 'rectangle';
$hebergements[] = $h;
}
}
foreach ($hebergements as $heb) {
$lat = (float) str_replace(",", ".", $heb->latitude);
$lon = (float) str_replace(",", ".", $heb->longitude);
$distance = round(calculerlaDistance($lat_ref, $lon_ref, $lat, $lon), 1);
$dans_rayon = ($distance <= $rayon_km);
$debug_rows[] = [
'id' => (int)$heb->id,
'name' => $heb->name,
'city' => $heb->city,
'postal_code' => $heb->postal_code,
'latitude' => $lat,
'longitude' => $lon,
'origine' => $heb->origine_debug,
'distance' => $distance,
'dans_rayon' => $dans_rayon ? 'OUI' : 'NON',
'token' => $heb->token ?? '',
'photo_locale' => $heb->photo_locale ?? '',
];
}
usort($debug_rows, function ($a, $b) {
return $a['distance'] <=> $b['distance'];
});
}
}
?>
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<title>Debug hébergements</title>
<style>
body {
font-family: Arial, sans-serif;
font-size: 14px;
margin: 20px;
color: #222;
}
h1, h2 {
margin-bottom: 10px;
}
form {
margin-bottom: 20px;
padding: 15px;
background: #f7f7f7;
border: 1px solid #ddd;
}
input[type="text"],
input[type="number"] {
padding: 8px;
width: 240px;
margin-right: 10px;
}
button {
padding: 8px 14px;
cursor: pointer;
}
.box {
border: 1px solid #ddd;
background: #fafafa;
padding: 15px;
margin-bottom: 20px;
}
.ok {
color: #0a7a2f;
font-weight: bold;
}
.ko {
color: #c62828;
font-weight: bold;
}
table {
width: 100%;
border-collapse: collapse;
margin-top: 12px;
}
th, td {
border: 1px solid #ccc;
padding: 8px;
vertical-align: top;
text-align: left;
}
th {
background: #efefef;
}
tr.in-range {
background: #eefbea;
}
tr.out-range {
background: #fff1f1;
}
.small {
color: #666;
font-size: 12px;
}
code {
background: #f1f1f1;
padding: 2px 5px;
}
</style>
</head>
<body>
<h1>Debug recherche hébergements</h1>
<form method="get">
<label>
Ville, pays :
<input type="text" name="ville_pays" value="<?= h($ville_pays) ?>" placeholder="Revel, FR">
</label>
<label>
Rayon km :
<input type="number" name="rayon_km" value="<?= h($rayon_km) ?>" min="1" step="1">
</label>
<button type="submit">Tester</button>
</form>
<?php if ($erreur !== '') : ?>
<div class="box ko"><?= h($erreur) ?></div>
<?php else : ?>
<div class="box">
<h2>Point de référence</h2>
<p><strong>ID :</strong> <?= h($ville_ref->id) ?></p>
<p><strong>Nom :</strong> <?= h($ville_ref->name) ?></p>
<p><strong>Ville :</strong> <?= h($ville_ref->city) ?>, <?= h($ville_ref->country_code) ?></p>
<p><strong>Latitude :</strong> <?= h($lat_ref) ?></p>
<p><strong>Longitude :</strong> <?= h($lon_ref) ?></p>
<hr>
<p><strong>Rayon demandé :</strong> <?= h($rayon_km) ?> km</p>
<p><strong>Delta latitude :</strong> <?= h(round($delta_lat, 6)) ?></p>
<p><strong>Delta longitude :</strong> <?= h(round($delta_lon, 6)) ?></p>
<p class="small">
Rectangle utilisé :
<br>
lat entre <code><?= h(round($lat_ref - $delta_lat, 6)) ?></code> et <code><?= h(round($lat_ref + $delta_lat, 6)) ?></code>
<br>
lon entre <code><?= h(round($lon_ref - $delta_lon, 6)) ?></code> et <code><?= h(round($lon_ref + $delta_lon, 6)) ?></code>
</p>
</div>
<div class="box">
<h2>Résultats debug</h2>
<p>
<strong>Total trouvé avant filtre final :</strong> <?= count($debug_rows) ?>
</p>
<table>
<thead>
<tr>
<th>ID</th>
<th>Nom</th>
<th>Ville</th>
<th>Origine</th>
<th>Lat</th>
<th>Lon</th>
<th>Distance (km)</th>
<th>Dans rayon</th>
<th>Token</th>
</tr>
</thead>
<tbody>
<?php foreach ($debug_rows as $row) : ?>
<tr class="<?= ($row['dans_rayon'] === 'OUI') ? 'in-range' : 'out-range' ?>">
<td><?= h($row['id']) ?></td>
<td><?= h($row['name']) ?></td>
<td><?= h($row['city']) ?> <?= h($row['postal_code']) ?></td>
<td><?= h($row['origine']) ?></td>
<td><?= h($row['latitude']) ?></td>
<td><?= h($row['longitude']) ?></td>
<td><?= h($row['distance']) ?></td>
<td class="<?= ($row['dans_rayon'] === 'OUI') ? 'ok' : 'ko' ?>">
<?= h($row['dans_rayon']) ?>
</td>
<td><?= h($row['token']) ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<div class="box">
<h2>Légende</h2>
<p>
Les lignes en vert sont dans le rayon réel de <?= h($rayon_km) ?> km.
Les lignes en rouge sont bien remontées par la recherche rectangle, mais hors rayon après calcul réel.
</p>
</div>
<?php endif; ?>
</body>
</html>