Subversion Repositories eFlore/Applications.cel

Rev

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

<?php
// CRUD ligne d'inventaire :
// In get : utf8
// In post : utf8
// out : utf8

Class CoordSearch extends DBAccessor {

        function Inventory($config) {

                $this->config=$config;
        }


        function getElement($uid){

           // Controle detournement utilisateur
            session_start();
                $value=array();

                $lat = str_replace('"','',urldecode($uid[0]));
                $lng = str_replace('"','',urldecode($uid[1]));

                $commune = urldecode($uid[2]);
                $code_postal = str_replace('"','',urldecode($uid[3]));
                
                $coord_json = json_encode(array());

                if(isset($uid[4]) && $uid[4] != "*" && $uid[4] != "?") {
                        $code_pays = urldecode($uid[4]);
                } else {
                        $code_pays = 'FR';
                }

                if($lat != '*' && $lng != '*') {

                        $commune_json = @file_get_contents("http://ws.geonames.org/findNearbyJSON?featureClass=ADM4&lat=".urlencode($lat)."&lng=".urlencode($lng)."&style=full") ;
                        header("Content-Type: text/html; charset=UTF-8");
                        $value = $commune_json ;

            } elseif($commune != '*') {

                        $requete = "http://ws.geonames.org/postalCodeSearchJSON?placename_startsWith=".urlencode($commune);

                        if($code_postal != '*') {
                                $requete .= "&postalcode_startsWith=".urlencode($code_postal);
                }
                        $requete .= "&country=".urlencode($code_pays)."&maxRows=10" ;

                        $coord_json = @file_get_contents($requete);

                        header("Content-Type: text/html; charset=UTF-8");
                        $value = $coord_json ;

            } else {

              header('HTTP/1.0 400 Bad Request');
              echo "Commune ou Coordonnées non spécifiées " ;
              exit;
            }

                print $value;
        }
}
?>