<?php

// Yahoo Yql Worldbank Country Search Tutorial - RJM Programming - 2015

$selname = "";
if (isset($_POST['selname'])) $selname = str_replace(" ","%20",$_POST['selname']);
if (isset($_GET['selname'])) $selname = str_replace(" ","%20",$_GET['selname']);
$bcolours = array("white", "pink", "aqua", "lime", "silver", "lightyellow", "cyan", "fuchsia", "orange", "lightblue", "lightgreen", "lightgray");

if ($selname != "") {
 
 $pageContent = file_get_contents("https://query.yahooapis.com/v1/public/yql?q=SELECT%20*%20FROM%20worldbank.countries%20WHERE%20country_id%20%3D%20'" . $selname . "'&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback=");


 $json_output = json_decode($pageContent);  
 
 // Confirm that results were returned before parsing
 if (!is_null($json_output->query->results->country)) {
            //echo "yessir";
			date_default_timezone_set('London/England');
			$date = date('d/m/Y h:i:s a', time());            
            foreach($json_output->query->results as $event) {
			    echo "<!doctype HTML><html><head><link href='//www.rjmprogramming.com.au/PHP/emboss_h1.css' rel='stylesheet' type='text/css'></head><body align='center' style='background-color:yellow;'><h1 align='center'>" . $event->name . " ... Worldbank Countries ... " . $date . " GMT</h1><br><div align='center'>";
                echo "<table><tbody><tr><td style='border:2px solid cyan;'>";
                echo "<iframe style='width:500px;height:500px;' src='http://www.rjmprogramming.com.au/PHP/Map/map.php?title=" . str_replace(" ", "%20", urlencode($event->capitalCity)) . "&label=[%27Lat%27,&value=%27Lon%27,%20%27Name%27]&data=,%20[" . $event->latitude . "," . $event->longitude . ",~" . str_replace(" ", "%20", urlencode($event->name)) . "~]'></iframe>";
                echo "</td><td style='width:60%;border:2px solid pink;'>";
                echo "<iframe style='width:500px;height:500px;' src='http://www.rjmprogramming.com.au/PHP/GeoChart/geo_chart.php?title=" . str_replace(" ", "%20", urlencode($event->name)) . "&width=496&height=347&country=Country&popularity=Dummy&data=,[~" . str_replace(" ", "%20", urlencode($event->name)) . "~,0]'></iframe>";
                echo "</td></tr></tbody></table>";
            }
 			echo "</div></body></html>";
 }

}
?> 

