<?php

include("data/geoipcity.inc");
include("data/geoipregionvars.php");
require_once("data/continents.php");
require_once("data/timeZones.php");
require_once("data/localTime.php");

/* check if GeoLiteCity.dat file exist */
$filename = 'data/GeoLiteCity.dat';
if (!file_exists($filename)) {
    header("Location: ../page_not_found.html");
}

$gi = geoip_open($filename,GEOIP_STANDARD);

/*
 * first round for visiting ip address
 */
$ip              = getenv("REMOTE_ADDR");
$record          = geoip_record_by_addr($gi, $ip);

$continentCode   = $record->continent_code;
$continentName   = $IP2C_CONTINENT_NAME[$IP2C_CONTINENT[$record->country_code]];;
$countryCode     = $record->country_code;
$countryCode3    = $record->country_code3;
$countryName     = $record->country_name;
$regionCode      = $record->region;
$regionName      = $GEOIP_REGION_NAME[$record->country_code][$record->region];
$cityName        = $record->city;
$cityPostalCode  = $record->postal_code;
$cityLatitude    = $record->latitude;
$cityLongitude   = $record->longitude;
$cityMetroCode   = $record->metro_code;
$cityAreaCode    = $record->area_code;
/* end of first round */

/*
 * second round for user inputted ip address
 */
$ip_2              = $_GET["ipAddress"];
$record_2          = geoip_record_by_addr($gi, $ip_2);

$continentCode_2   = $record_2->continent_code;
$continentName_2   = $IP2C_CONTINENT_NAME[$IP2C_CONTINENT[$record_2->country_code]];;
$countryCode_2     = $record_2->country_code;
$countryCode3_2    = $record_2->country_code3;
$countryName_2     = $record_2->country_name;
$regionCode_2      = $record_2->region;
$regionName_2      = $GEOIP_REGION_NAME[$record_2->country_code][$record_2->region];
$cityName_2        = $record_2->city;
$cityPostalCode_2  = $record_2->postal_code;
$cityLatitude_2    = $record_2->latitude;
$cityLongitude_2   = $record_2->longitude;
$cityMetroCode_2   = $record_2->metro_code;
$cityAreaCode_2    = $record_2->area_code;
/* end of second round */

geoip_close($gi);

$localTimeZone  = ip2c_getTimeZone($countryCode, $cityLongitude);
//$localTimeEpoch = ip2c_getLocalTime($localTimeZone);

$localTimeZone_2  = ip2c_getTimeZone($countryCode_2, $cityLongitude_2);
//$localTimeEpoch = ip2c_getLocalTime($localTimeZone_2);
?>



<!DOCTYPE HTML> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<meta name="RILEE RGeo" content="Find anyone in the world with an IP address" />
<title>RILEE::RGeo</title> 
 
<link rel="stylesheet" type="text/css" href="styles.css" /> 

<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-24634708-3']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>
</head>

<body> 
<div id="navbar"> 
	<a href="http://richardxlee.com/archive/"><div class="button">home</div></a> 
	<a href="http://richardxlee.com/archive/about"><div class="button">about</div></a> 
	<a href="http://richardxlee.com/archive/products"><div class="button">products</div></a> 
	<a href="http://richardxlee.com/archive/airplane"><div class="button">airplane</div></a> 
	<a href="http://richardxlee.com/archive/design"><div class="button">design</div></a> 
        <a href="http://richardxlee.com/archive/contact"><div class="button">contact</div></a> 
</div> 
<div class="main"> 
	<h1>RGeo-Location</h1>         
	<p>Your location information from your ip address</p> 
        <div class="divider"> </div> 

        <table>
           <tr><td>IP address:</td><td><?php echo $ip; ?></td></tr>
           <tr><td>Continent Code:</td><td><?php echo $continentCode; ?></td></tr>
           <tr><td>Continent Name:</td><td><?php echo $continentName; ?></td></tr>
           <tr><td>Country:</td><td><?php echo $countryName; ?></td></tr>
           <tr><td>Country Code:</td><td><?php echo $countryCode; ?></td></tr>
           <tr><td>Country Code:</td><td><?php echo $countryCode3; ?></td></tr>
           <tr><td>Region Code:</td><td><?php echo $regionCode; ?></td></tr>
           <tr><td>Region Name:</td><td><?php echo $regionName; ?></td></tr>
           <tr><td>City:</td><td><?php echo $cityName; ?></td></tr>
           <tr><td>City Latitude:</td><td><?php echo $cityLatitude; ?></td></tr>
           <tr><td>City Longitude:</td><td><?php echo $cityLongitude; ?></td></tr>
           <tr><td>City Postal Code:</td><td><?php echo $cityPostalCode; ?></td></tr>
           <tr><td>City Metro Code:</td><td><?php echo $cityMetroCode; ?></td></tr>
           <tr><td>City Area Code:</td><td><?php echo $cityAreaCode; ?></td></tr>
           <tr><td>Time Zone:</td><td><?php echo $localTimeZone; ?></td></tr>
           <!--<tr><td>Local Time:</td><td><?php echo $localTimeEpoch; ?></td></tr>-->
        </table>

</div>

<div class="main">
        <h1>RGeo-Location Look Up</h1>         
	<p>Search geo-location information for a particular ip address</p> 
        <div class="divider"> </div>

        <form action="index.php" method="get">
           IP Address: <input type="text" name="ipAddress" size="18" onfocus="if(this.value=='e.g. 12.175.177.0') this.value=''" value="e.g. 12.175.177.0">
           <input type="submit" style="width:100px; height:20px;">
        </form>

<?php
if($ip_2 == "e.g. 12.175.177.0")
{
}
elseif($ip_2 == " ")
{
}
elseif($ip_2 == "")
{
}
else
{
?>
        <p>Geo-location information for <?php echo $ip_2 ?>:</p>
        <table>
           <tr><td>IP address:</td><td><?php echo $ip_2; ?></td></tr>
           <tr><td>Continent Code:</td><td><?php echo $continentCode_2; ?></td></tr>
           <tr><td>Continent Name:</td><td><?php echo $continentName_2; ?></td></tr>
           <tr><td>Country:</td><td><?php echo $countryName_2; ?></td></tr>
           <tr><td>Country Code:</td><td><?php echo $countryCode_2; ?></td></tr>
           <tr><td>Country Code:</td><td><?php echo $countryCode3_2; ?></td></tr>
           <tr><td>Region Code:</td><td><?php echo $regionCode_2; ?></td></tr>
           <tr><td>Region Name:</td><td><?php echo $regionName_2; ?></td></tr>
           <tr><td>City:</td><td><?php echo $cityName_2; ?></td></tr>
           <tr><td>City Latitude:</td><td><?php echo $cityLatitude_2; ?></td></tr>
           <tr><td>City Longitude:</td><td><?php echo $cityLongitude_2; ?></td></tr>
           <tr><td>City Postal Code:</td><td><?php echo $cityPostalCode_2; ?></td></tr>
           <tr><td>City Metro Code:</td><td><?php echo $cityMetroCode_2; ?></td></tr>
           <tr><td>City Area Code:</td><td><?php echo $cityAreaCode_2; ?></td></tr>
           <tr><td>Time Zone:</td><td><?php echo $localTimeZone_2; ?></td></tr>
           <!--<tr><td>Local Time:</td><td><?php echo $localTimeEpoch_2; ?></td></tr>-->
        </table>

<?php } ?>

</div>

</body> 
</html>	