Subversion Repositories eFlore/Applications.cel

Rev

Rev 416 | Rev 766 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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