Location: PHPKode > scripts > GG-Tracker GPS and GSM Tracking > gg-tracker-gps-and-gsm-tracking/index.php
<?php
//**********************************************************************************************
//**********************************************************************************************
//***** GG-Tracker is based on Aspicore GSM Tracker.                                       *****
//*****                                                                                    ***** 
//***** It's in a development phase and no warranties are given for anything. This program *****
//***** may not function the way you expect it and the author is not responsible for       *****
//***** anything. However, I hope you enjoy it and ammend it where possible!               *****
//*****                                                                                    *****
//***** An example of GG-Tracker is live at http://gg-tracker.eppenga.com                     *****
//**********************************************************************************************
//**********************************************************************************************

//**********************************************************************************************
//*****                                      PROGRAM                                      ******
//**********************************************************************************************

header("Expires: 0");
header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0"); 
header("Pragma: no-cache"); 
header("Content-Type: text/html; charset=ISO-8859-1");
header('Content-Disposition: inline; filename="response.html"');
?>

<?php
/* Include settings */
include ("config.php");
include ("config_check.php");
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
            "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<style type="text/css">
			<!--
		  	td { font-family: verdana,arial,helvetica,sans-serif; font-size: 7pt;
			   border: 1px solid black;
			   vertical-align: baseline }
		  	th { font-family: verdana,arial,helvetica,sans-serif; font-size: 8pt; font-weight: bold;
			   border: 1px solid black;
			   border-style: solid; border-width: 1px;
			   vertical-align: baseline }
		  	td.small { font-family: verdana,arial,helvetica,sans-serif; font-size: 6pt }
		  	body         { font-family: verdana,arial,helvetica,sans-serif; font-size: 8pt }
		  	base         { font-family: Courier,MONOSPACE; font-size: 10pt }
		  	table        { border-collapse: collapse; border: solid thin black }
		  	A:link		 { color: black; text-decoration: underline }
			A:visited 	 { color: black; text-decoration: underline }
			A:active 	 { color: black; text-decoration: underline }
			A:hover 	 { color: black; text-decoration: none }
			caption 	 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold }
		  	-->
  		</style>
  		<?php if ($rss) { ?>
      <link rel="alternate" type="application/rss+xml" title="GG-Tracker RSS Feed" href="<?php echo $rssfile; ?>" />  		  
		  <?php } ?>
  		<meta http-equiv="refresh" content="60;URL=." />
  		<title>GG-Tracker (GSM and GPS location combined)</title>
<?php 

/* Open and check connection */ 
$link = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname);
if (!$link) {
   printf("Connect failed: %s\n", mysqli_connect_error());
   exit();
}

/* Calculate history and produce XML files for Google Earth */
if ($ghistory) include ("calc_gearth.php");

/* Get the last known position with full details of the tracked phone */

$query = 'SELECT GPSMSGID, PHONE, STATUS, LATITUDE, LONGITUDE, SPEED_KNOTS, COURSE_DEG, TIME_RECEIVED, EVENT_TYPE, CELL_ID, LAC, MCC, MNC, NWNAME, LABEL, REMOTE_IP '
		. 'FROM GPS ORDER BY GPSMSGID DESC LIMIT 1';
$result = mysqli_query($link, $query);

if (!$result) {
   printf("Query failed: %s\r\n", mysqli_error($link));
   printf("Tried to execute the following SQL query:\r\n");
   printf("%s\r\n", $query );
   mysqli_close($link); 
   exit();}

$row_cnt = mysqli_num_rows($result);
if ($row_cnt == 0) {
	printf("No data, connect Aspicore tracker first.\r\n");
	exit();
	}
else {
	$line = mysqli_fetch_array($result, MYSQLI_ASSOC);
	$id = $line['GPSMSGID'];
	$phone = $line['PHONE'];
	$status = $line['STATUS'];
	$latitude = $line['LATITUDE'];
	$longitude = $line['LONGITUDE'];
	$speed = round($line['SPEED_KNOTS']*1.852,2);
	$course = $line['COURSE_DEG'];
	$rtime = strtotime($line['TIME_RECEIVED']) + $t_offset*3600;
	$rtime = date('Y-m-d H:i:m', $rtime);
	$nwname = $line['NWNAME'];
	$cell = $line['CELL_ID'];
	$lac = $line['LAC'];
	$mcc = $line['MCC'];
	$mnc = $line['MNC'];
	$mode = $line['EVENT_TYPE'];
	$label = $line['LABEL'];
	$ipaddress = $line['REMOTE_IP'];
}

/* Get the last two good positions for a tail */
$query = 'SELECT LATITUDE, LONGITUDE '
	   . 'FROM GPS WHERE STATUS IN (\'A\', \'B\',\'X\',\'C\',\'T\',\'R\') '
	   . 'ORDER BY GPSMSGID DESC LIMIT 1,3';
$result = mysqli_query($link, $query);

$row_cnt = mysqli_num_rows($result);

if ($row_cnt == 3) {
	$line = mysqli_fetch_array($result, MYSQLI_ASSOC);
	$lat_1 = $line['LATITUDE'];
	$lon_1 = $line['LONGITUDE'];
	$line = mysqli_fetch_array($result, MYSQLI_ASSOC);
	$lat_2 = $line['LATITUDE'];
	$lon_2 = $line['LONGITUDE'];
	$line = mysqli_fetch_array($result, MYSQLI_ASSOC);
	$lat_3 = $line['LATITUDE'];
	$lon_3 = $line['LONGITUDE'];
}
else
{
	$lat_1 = $latitude;
	$lat_2 = $latitude;
	$lat_3 = $latitude;	
	$lon_1 = $longitude;
	$lon_2 = $longitude;	
	$lon_3 = $longitude;
}


//Google maps script, only execute if there are positions found
if ($status <> "Z" && $status <> "F") {
	echo "
	    <script src=\"http://maps.google.com/maps?file=api&amp;v=2&amp;key=$gmaps\"
	      type=\"text/javascript\"></script>
	    <script type=\"text/javascript\">
	
	    //<![CDATA[
	    function load() {
	      if (GBrowserIsCompatible()) {
	        var map = new GMap2(document.getElementById(\"map\"));
	        map.setCenter(new GLatLng($latitude, $longitude), 14);
	        map.addControl(new GSmallMapControl());
	        map.addControl(new GMapTypeControl());
	        var marker = new GMarker(new GLatLng($latitude, $longitude));
	        map.addOverlay(marker);
	        GEvent.addListener(marker, \"click\", function() {
	          var html = '<div style=\"width: 250px; height: 50; padding-right: 10px\"><font size=2><b>Hello World!</b><br>This is my my current position. If you enjoy this application, please <br><a href=\"http://www.eppenga.com/gsm-gps-tracking.html\">read my webpage.<\/a><\/font><\/div>';
	          marker.openInfoWindowHtml(html);
	          });
			var polyline = new GPolyline([
	  		  new GLatLng($lat_3, $lon_3),	  		  
			  new GLatLng($lat_2, $lon_2),
	  		  new GLatLng($lat_1, $lon_1),
	  		  new GLatLng($latitude, $longitude)
			], \"#ff0000\", 7);
			map.addOverlay(polyline);
	      }
	    }
	    
	    //]]>
	    </script>
	";
}

//Get some statistical data
include ("calc_stats.php");

//The rest of the internet page
echo "
  </head>

	<body onload=\"load()\" onunload=\"GUnload()\">
  
	<center>
	<table width=600 cellspacing=2 cellpadding=2>
    	<tr align=center>
			<td colspan=3>
				<font size=2 color=red><b>Welcome to GG-Tracker (GPS and GSM Tracking)</b></font>
			</td>
		</tr>
		<tr>
			<td><b>Location label: $label</b></td>
			<td><b>Report date: $rtime</b></td>
			<td><b>Cellphone IP-address: $ipaddress</b></td>
		</tr>
		<tr>
			<td><b>Topspeed today/ever: $maxspeed[1]/$maxspeed[0] km/h</b></td>
			<td><b>Distance to home: $disthome km</b></td>
			<td><b>GSM antenna (useful/total): $gsm_antenna[0]/$gsm_antenna[1]</b></td>
		</tr>	
	</table>";
  
echo "    
	<table width=600 cellspacing=0 cellpadding=0)>
		<tr><td valign=middle width=600 height=400>";
  
if (($status == "Z") || ($status == "F"))
  {
    echo "
		<br><br><br><br><br><br><br><br><br><br><br><br>
		<b>There is no image to display.</b><p>
		The GPS is not connected and the GSM location can not be found in the database.<p>
		Please check back later.";}
else
	{echo "<div id=\"map\" style=\"width: 596px; height: 400px\"></div>";}
   
echo "
	</td></tr>
</table>";
    
echo "
	<table width=600 cellspacing=2 cellpadding=2>
		<tr align=center>
			<td colspan=2><b>GSM Information</b></td>      
			<td colspan=2><b>GPS Information</b></td>
		</tr><tr align=left>
			<td>Network</td><td>$nwname</td>
			<td width=150>Status</td><td width=150>$status</td>
		</tr><tr align=left>      
			<td width=150>Cell ID</td><td width=150>$cell</td>
			<td>Latitude</td><td>$latitude deg</td>
		</tr><tr align=left>
			<td>LAC</td><td>$lac</td>
			<td>Longitude</td><td>$longitude deg</td>
		</tr><tr align=left>
			<td>MCC</td><td>$mcc</td>
			<td>Speed</td><td>$speed km/h</td>
		</tr><tr align=left>
			<td>MNC</td><td>$mnc</td>
			<td>Course</td><td>$course deg</td>
		</tr>";

//Display history line if set in config.php	
if (($ghistory) && ($gnwlink)) {
	echo "<tr align=center>
			<td colspan=2>
				<a href=\"".$gearthfile."\"><b>Show in Google Earth history (".$gearthperiod.")</b></a>
			</td>
			<td colspan=2>
				<a href=\"".$gnwlinkfile."\"><b>Show in Google Earth current position</b></a>
			</td>			
		</tr>";	
}
if (($ghistory) && (!$gnwlink)) {
	echo "<tr align=center>
			<td colspan=4>
				<a href=\"".$gearthfile."\">
					<b>Show in Google Earth the history (".$gearthperiod."), you need Google Earth installed)</b>
				</a>
			</td>
		</tr>";	
}
if ((!$ghistory) && ($gnwlink)) {
	echo "<tr align=center>
			<td colspan=4>
				<a href=\"".$gnwlinkfile."\">
					<b>Show in Google Earth current position (you need Google Earth installed)</b>
				</a>
			</td>
		</tr>";		
}

//Display the rest	
echo "
	</table>

	<br>
		<font size=2><b>
      <a href=\"http://www.eppenga.com/gsm-gps-tracking.html\" target=_top>More information,</a> 
      <a href=\"http://www.eppenga.com/gsm-gps-tracking/equipment.html\" target=_top>setup</a> and 
      <a href=\"http://sourceforge.net/projects/gg-tracker/\" target=_top>download</a> 
      <a href=\"http://www.eppenga.com/gsm-gps-tracking/explanation.html\" target=_top>GG-Tracker application</a>
    </b></font>
	</a>
	<br>	
	<a href=\"http://www.eppenga.com/about/contact.html\">
		<font size=1 color=black><i>GG-Tracker is an open-source development project by Ebo Eppenga</i></font>
	</a>
  
	</center>\r\n\r\n";

/* Include simple counter */
echo "<img src=\"http://teller.eppenga.com/ggtracker/counter.gif&url="
	.$_SERVER['SERVER_NAME']."&path=".$_SERVER['PHP_SELF']."\" border=0 width=1 height=1>";

/* Include footer */
include ("footer.php");
  
echo "	</body>\r\n";
echo "</html>";


/* Close and free everything */

// Free resultset
mysqli_free_result($result);

/* Close connection */    
mysqli_close($link); 

?>
Return current item: GG-Tracker GPS and GSM Tracking