| Current Path : /home/h/a/p/happyrenas/old/huissier-express.fr/administration/2020/ |
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/h/a/p/happyrenas/old/huissier-express.fr/administration/2020/devis_latitude_longitude_maj.php |
<?
/////////////////////////////////////
include("config.php");
if ($db->escape($_GET['auth_forte'])=="4fa15391427d1ebf2debac9d6e833703")
{
$_SESSION['admin_id'] = $tableau_admin_nom[1];
$_SESSION['admin_mail'] = $tableau_admin_mail[1];
$_SESSION['admin_droit'] = $tableau_admin_droit[1];
}
include("includes/fonctions.php");
$page = "devis";
include("auth.php");
$annee_en_cours = date("Y");
$mois_en_cours = date("m");
$semaine_en_cours = date("W");
/////////////////////////////////////
$devis_id = $_REQUEST['devis_id'];
$bas = $_REQUEST['bas'];
$myquery = "SELECT * from devis where id=".$devis_id;
$devis = $db->get_row($myquery);
//IMPAYE
if ($devis->bloc==1)
{
$adresse_base = $devis->lieu_intervention;
$departement_base = $devis->lieu_intervention;
}
//CONSTAT
if ($devis->bloc==2)
{
//$adresse_base = $devis->constat_cp." ".$devis->constat_ville;
$adresse_base = $devis->lieu_intervention;
$departement_base = $devis->lieu_intervention;
}
//AUTRE
if ($devis->bloc==3)
{
$adresse_base = $devis->lieu_intervention;
$departement_base = $devis->lieu_intervention;
}
class GmapApi {
private static $apikey = 'AIzaSyCNJgt2f_RopvU8s-Lo2ZV1TgEOyK9PCxA';
public static function geocodeAddress($address) {
//valeurs vide par défaut
$data = array('address' => '', 'lat' => '', 'lng' => '', 'city' => '', 'department' => '', 'region' => '', 'country' => '', 'postal_code' => '');
//on formate l'adresse
$address = str_replace(" ", "+", $address);
//on fait l'appel à l'API google map pour géocoder cette adresse
$json = file_get_contents("https://maps.google.com/maps/api/geocode/json?key=" . self::$apikey . "&address=$address&sensor=false®ion=fr");
$json = json_decode($json);
//on enregistre les résultats recherchés
if ($json->status == 'OK' && count($json->results) > 0) {
$res = $json->results[0];
//adresse complète et latitude/longitude
$data['address'] = $res->formatted_address;
$data['lat'] = $res->geometry->location->lat;
$data['lng'] = $res->geometry->location->lng;
foreach ($res->address_components as $component) {
//ville
if ($component->types[0] == 'locality') {
$data['city'] = $component->long_name;
}
//départment
if ($component->types[0] == 'administrative_area_level_2') {
$data['department'] = $component->long_name;
}
//région
if ($component->types[0] == 'administrative_area_level_1') {
$data['region'] = $component->long_name;
}
//pays
if ($component->types[0] == 'country') {
$data['country'] = $component->long_name;
}
//code postal
if ($component->types[0] == 'postal_code') {
$data['postal_code'] = $component->long_name;
}
}
}
return $data;
}
}
if ($departement_base!="971" && $departement_base!="972" && $departement_base!="973" && $departement_base!="974" && $departement_base!="976" && $departement_base!="20")
{
$departement_base=$departement_base."000";
}
if ($departement_base=="971") {$departement_base=$departement_base." GUADELOUPE";}
if ($departement_base=="972") {$departement_base=$departement_base." LA MARTINIQUE";}
if ($departement_base=="973") {$departement_base=$departement_base." GUYANE";}
if ($departement_base=="974") {$departement_base=$departement_base." LA REUNION";}
if ($departement_base=="976") {$departement_base=$departement_base." MAYOTTE";}
if ($departement_base=="20") {$departement_base=$departement_base."A CORSE";}
$data = GmapApi::geocodeAddress($departement_base);
//echo "<pre>";
//print_r($data);
//echo "</pre>";
//echo $adresse_base;exit;
$latitude = $data['lat'];
$longitude = $data['lng'];
if ($latitude && $longitude)
{
$requete="UPDATE devis set latitude = '".$latitude."', longitude = '".$longitude."' where id=".$devis_id;
$db->query($requete);
header("Refresh:0; url=devis_ajout.php?devis_id=".$devis_id."&maj_devis_google_map=1#bas");exit;
}
else
{
header("Refresh:0; url=devis_ajout.php?devis_id=".$devis_id."&maj_devis_google_map=2#bas");exit;
}
?>