Subversion Repositories eFlore/Applications.cel

Rev

Rev 662 | Go to most recent revision | Details | 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]));
26
 
27
		if(isset($uid[4]) && $uid[4] != "*" && $uid[4] != "?") {
28
			$code_pays = urldecode($uid[4]);
29
		} else {
30
			$code_pays = 'FR';
31
		}
32
 
33
		if($lat != '*' && $lng != '*') {
34
 
35
			$commune_json = file_get_contents("http://ws.geonames.org/findNearbyJSON?featureClass=ADM4&lat=".urlencode($lat)."&lng=".urlencode($lng)."&style=full") ;
36
			header("Content-Type: text/html; charset=UTF-8");
37
			$value = $commune_json ;
38
 
39
	    } elseif($commune != '*') {
40
 
41
			$requete = "http://ws.geonames.org/postalCodeSearchJSON?placename_startsWith=".urlencode($commune);
42
 
43
			if($code_postal != '*') {
44
				$requete .= "&postalcode_startsWith=".urlencode($code_postal);
45
	    	}
46
			$requete .= "&country=".urlencode($code_pays)."&maxRows=10" ;
47
 
48
			$coord_json = file_get_contents($requete);
49
 
50
			header("Content-Type: text/html; charset=UTF-8");
51
			$value = $coord_json ;
52
 
53
	    } else {
54
 
55
	      header('HTTP/1.0 400 Bad Request');
56
	      echo "Commune ou Coordonnées non spécifiées " ;
57
	      exit;
58
	    }
59
 
60
		print $value;
61
	}
62
}
63
?>