1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
| <h1 id="codePostal">RENSEIGNEZ VOTRE CODE POSTAL POUR TROUVER LES REVENDEURS PROCHES DE CHEZ VOUS</h1>
<form action="" method="post" id="distrib">
<table>
<tr>
<td><label>Votre code postal</label></td>
<td><label>Votre ville</label></td>
<td rowspan="2"><img src="img/fleche.png" alt="Flèche" title="" width="30" height="24" /></td>
<td rowspan="2"><input type="submit" name="submit" value="Envoyer" /></td>
</tr>
<tr>
<td><input type="text" name="code" id="code" /></td>
<td><input type="text" name="ville" id="ville" /></td>
</tr>
</table>
</form>
<?php
if($_POST['submit'])
{
if(($_POST['code'] == "") || ($_POST['ville'] == ""))
{
echo '<h3 id="attention">Vous devez indiquer votre code postal ainsi que votre ville !</h3>';
}else
{
function getDistance($adresse1,$adresse2){
$adresse1 = str_replace(" ", "+", $adresse1);
$adresse2 = str_replace(" ", "+", $adresse2);
$url='http://maps.google.com/maps/api/directions/xml?language=fr&origin='.$adresse1.'&destination='.$adresse2.'&sensor=false';
$xml=file_get_contents($url);
$root = simplexml_load_string($xml);
$distance=$root->route->leg->distance->text;
if ($root->status == "OK")
{
return $distance;
}else
{
return "0";
}
}
function getDuree($adresse1,$adresse2){
$adresse1 = str_replace(" ", "+", $adresse1);
$adresse2 = str_replace(" ", "+", $adresse2);
$url='http://maps.google.com/maps/api/directions/xml?language=fr&origin='.$adresse1.'&destination='.$adresse2.'&sensor=false';
$xml=file_get_contents($url);
$root = simplexml_load_string($xml);
$duree=$root->route->leg->duration->text;
if ($root->status == "OK")
{
return $duree;
}else
{
return "0";
}
}
echo '<h3 id="titleListe">Liste des distributeurs dans votre département :</h3>';
include('connect-db.php');
$departement = substr($_POST['code'], 0, 2);
$rdistrib = "SELECT * FROM `distributeurs` WHERE `distributeurs`.`departement` = '".$departement."';";
$resdistrib = mysql_query($rdistrib, $base) or die(mysql_error());
$distrib = mysql_fetch_assoc($resdistrib);
echo '<ul id="listeDistributeurs">';
while($distrib)
{
echo '
<li>
<strong>'.$distrib['raison_sociale'].' '.$distrib['enseigne'].'</strong><br />
'.$distrib['adresse'].'<br />
'.$distrib['code_postal'].' '.$distrib['ville'].'<br />
'.$distrib['telephone'].'<br />';
echo '<span class="distance">'.
getDistance("".$_POST['ville'].", ".$_POST['code']."", "".$distrib['ville'].", ".$distrib['code_postal']."")
.'</span>';
echo '<span class="duree">'.
getDuree("".$_POST['ville'].", ".$_POST['code']."", "".$distrib['ville'].", ".$distrib['code_postal']."")
.'</span><br />
<a href="https://www.google.com/maps?saddr='.$_POST['code'].'+'.$_POST['ville'].'&daddr='.$distrib['code_postal'].'+'.$distrib['ville'].'&hl=fr" target="_blank" class="linkItin">Voir l\'itinéraire</a>';
echo '</li>';
$distrib = mysql_fetch_assoc($resdistrib);
}
echo '</ul>';
}
}
?> |
Partager