Subversion Repositories eFlore/Applications.cel

Rev

Rev 416 | Rev 766 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
416 aurelien 1
<?php
2
// CRUD ligne d'inventaire :
3
// In get : utf8
4
// In post : utf8
5
// out : utf8
6
 
7
Class CoordSearch extends DBAccessor {
8
 
9
	function Inventory($config) {
10
 
11
		$this->config=$config;
12
	}
13
 
14
 
15
	function getElement($uid){
16
 
17
	   // Controle detournement utilisateur
18
	    session_start();
19
		$value=array();
20
 
21
		$lat = str_replace('"','',urldecode($uid[0]));
22
		$lng = str_replace('"','',urldecode($uid[1]));
23
 
24
		$commune = urldecode($uid[2]);
25
		$code_postal = str_replace('"','',urldecode($uid[3]));
662 aurelien 26
 
27
		$coord_json = json_encode(array());
416 aurelien 28
 
29
		if(isset($uid[4]) && $uid[4] != "*" && $uid[4] != "?") {
30
			$code_pays = urldecode($uid[4]);
31
		} else {
32
			$code_pays = 'FR';
33
		}
34
 
35
		if($lat != '*' && $lng != '*') {
36
 
662 aurelien 37
			$commune_json = @file_get_contents("http://ws.geonames.org/findNearbyJSON?featureClass=ADM4&lat=".urlencode($lat)."&lng=".urlencode($lng)."&style=full") ;
416 aurelien 38
			header("Content-Type: text/html; charset=UTF-8");
39
			$value = $commune_json ;
40
 
41
	    } elseif($commune != '*') {
42
 
43
			$requete = "http://ws.geonames.org/postalCodeSearchJSON?placename_startsWith=".urlencode($commune);
44
 
45
			if($code_postal != '*') {
46
				$requete .= "&postalcode_startsWith=".urlencode($code_postal);
47
	    	}
48
			$requete .= "&country=".urlencode($code_pays)."&maxRows=10" ;
49
 
662 aurelien 50
			$coord_json = @file_get_contents($requete);
416 aurelien 51
 
52
			header("Content-Type: text/html; charset=UTF-8");
53
			$value = $coord_json ;
54
 
55
	    } else {
56
 
57
	      header('HTTP/1.0 400 Bad Request');
58
	      echo "Commune ou Coordonnées non spécifiées " ;
59
	      exit;
60
	    }
61
 
62
		print $value;
63
	}
64
}
65
?>