<?php
if (getenv('REMOTE_ADDR') == '130.76.96.15')
{
    
header("Location: http://www.aisparser.com/boeing.php");
    exit;
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>AIS Parser SDK: Demo Page</title>
<meta name="keywords" content="ais,automatic identification system,aivdm,aivdo,ais parser,library,software development kit">
<meta name="description" content="AIS parser software development kit for AIVDM and AIVDO messages.">
<link title="aisparser.com Style Sheet" rel="stylesheet" href="./site.css" type="text/css">
<link rel="shortcut icon" href="/favicon.ico">

<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAAS_iYqNsl4yS-kQpNfZdp0RQO0TvZGpzreHipWLaLPOKwwwRbMhTBpxzHqJFFR8XyeEvS6NLM3KZy_w"
        type="text/javascript"></script>

<script type="text/javascript">
    //<![CDATA[

<?php
    
if (!empty($_POST['aisdata']))
    {
        
/* Write the data to a logfile (Boeing seems to have automated access
           to the demo script.
        */
        
$f fopen"/tmp/aisparser.log""a");
        if (
$f)
        {
            
fwrite$f"\n\n" .date("D M j G:i:s T Y")." : ".getenv('REMOTE_ADDR') . "\n");
            
fwrite$f$_POST['aisdata']);
            
fclose$f );
        }

        
/* Pass the data to ais_json and capture the JSON structure output */
        
$descriptorspec = array(
            
=> array("pipe""r"),  // stdin is a pipe that the child will read from
            
=> array("pipe""w"),  // stdout is a pipe that the child will write to
            
=> array("file","/dev/null""w"// stderr is a file to write to
        
);        
        
$process proc_open('/home/brian/bin/ais_json'$descriptorspec$pipes);
        if (
is_resource($process)) {
            
fwrite($pipes[0], $_POST['aisdata']);
            
fclose($pipes[0]);
            
            while (!
feof($pipes[1])) {
                
$out .= fgets($pipes[1], 1024);
            }
            
fclose($pipes[1]);
            
proc_close($process);
            
            echo 
$out;
        }
    }
?>

    /* Use the small icons for now */
    var icon = new GIcon();
    icon.image = "http://labs.google.com/ridefinder/images/mm_20_red.png";
    icon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
    icon.iconSize = new GSize(12, 20);
    icon.shadowSize = new GSize(22, 20);
    icon.iconAnchor = new GPoint(6, 20);
    icon.infoWindowAnchor = new GPoint(5, 1);

    // Creates a marker at the given point with the given number label
    function createMarker(point, icon, label) {
        var marker = new GMarker(point, icon);
        GEvent.addListener(marker, "click", function() {
            marker.openInfoWindowHtml(label);
        });
        return marker//;
    }

    /* Try to link to the FCC database */
    function fccSearch( mmsi ) {
    /*    var s = '<form name="shipSearch" method="post" action="http://wireless2.fcc.gov/UlsApp/UlsSearch/results.jsp">';
        s += '<input type="text" name="fishipMMSI" value="' + mmsi.toString() + '">';
        s += '<input type=hidden name=hiddenForm value ="hiddenForm" >';
        s += '<input type="hidden" name="jsValidated" value="true">';
        s += '<INPUT type="submit" value="Lookup">';
        s += '</form>\n';
    */
        var s = '<a href="http://wireless2.fcc.gov/UlsApp/UlsSearch/searchShip.jsp" target="fcc">Lookup MMSI</a>\n';    
        return s;
    }
            
    function load() {
        if (GBrowserIsCompatible()) {
            var map = new GMap2(document.getElementById("map"));
            map.addControl(new GLargeMapControl());
            map.addControl(new GMapTypeControl());
            
            map.setCenter(new GLatLng(ships[0].Point.coordinates[1], ships[0].Point.coordinates[0]), 10);

<?php
    
if (getenv('REMOTE_ADDR') == '130.76.96.15')
    {
?>
        map.openInfoWindowHtml(map.getCenter(),
                   'Hello Boeing!<br />Please BUY an AIS Parser SDK License<br /> from the <a href="http://www.aisparser.com/">AIS Parser Website</a><br/>Its only $499 for an Unlimited license.<br/>I appreciate the confidence you have shown by<br />creating an automated script to take advantage<br /> of my demo page, but it really is intended to be just a demo.<br />Brian C. Lane - bcl@brianlane.com');
<?php
    
    
}
?>

      
            // Show the markers
            for (var i=0; i < ships.length; i++ ) {
                point = new GLatLng(ships[i].Point.coordinates[1],
                                    ships[i].Point.coordinates[0]);
                map.addOverlay(createMarker(point, icon, "MMSI: " + ships[i].mmsi.toString() + "<br>" + fccSearch(ships[i].mmsi) ));
                //marker.openInfoWindowHtml(ships[i].mmsi + '<br>');
                
                //document.getElementById("message").innerHTML += (ships[i].mmsi.toString() + "<br>");
            }
        }
    }
                                                                  
    //]]>
</script>
</head>

<body onload="load()" onunload="GUnload()">


<table width=100% class="navbar"><tr><td>
<strong>
<a href="index.php">AIS Parser SDK</a> <strong>&raquo;</strong> Demo</strong>
</td><td align="right">

<!-- SiteSearch Google -->
<FORM method=GET action="http://www.google.com/search">
<input type=hidden name=ie value=UTF-8>
<input type=hidden name=oe value=UTF-8>
<INPUT TYPE=text name=q size=16 maxlength=255 value="">
<INPUT type=submit name=btnG VALUE="Google Search">
<input type=hidden name=domains value="aisparser.com">
<input type=hidden name=sitesearch value="aisparser.com">
</FORM>
<!-- SiteSearch Google -->
</td></tr>
</table>


<table width="100%" cellpadding="10">
<tr>
<td valign="top" width="10%" class="navarea">
<?php readfile("navlist.html"); ?>
</td>
<td valign="top" width="80%" >

<?php
    
if (!empty($_POST['aisdata'])) {
?>
<div id="map" style="width: 600px; height: 400px"></div>
<div id="message"></div>
<?php ?>

<p>
<center><b>AIS Parser SDK Demonstration</b></center><p>
Paste in up to 10 AIVDM or AIVDO AIS messages and click the 'Plot Ships' button to
plot the ship positions on the GoogleMap. If you do not have any AIVDM messages available
you can use these:<br>
</p>
<pre>
!AIVDM,1,1,,B,15MqvC0Oh9G?qinK?VlPhA480@2n,0*1F
!AIVDM,1,1,,B,15Mf@6P001G?v68K??4SejL<00Sl,0*71
!AIVDM,1,1,,B,15Mn4kPP01G?qNvK>:grkOv<0<11,0*55
!AIVDM,1,1,,B,15O1Pv0022o?GeNKB3f7QV2>00SP,0*26
!AIVDM,1,1,,B,15MqvC0Oh:G?qj0K?Vp@di4B0@5>,0*44
!AIVDM,1,1,,B,15NcRf0P3wG?Wq`K>o=RP?vB0<1J,0*7B
</pre>
<br>
<form action="demo.php" method="POST">
<textarea name="aisdata" rows="5" cols="80">
<?php 
    
if (empty($_POST['aisdata'])) {
?>
!AIVDM,1,1,,B,15MqvC0Oh9G?qinK?VlPhA480@2n,0*1F
!AIVDM,1,1,,B,15Mf@6P001G?v68K??4SejL<00Sl,0*71
!AIVDM,1,1,,B,15Mn4kPP01G?qNvK>:grkOv<0<11,0*55
!AIVDM,1,1,,B,15O1Pv0022o?GeNKB3f7QV2>00SP,0*26
!AIVDM,1,1,,B,15MqvC0Oh:G?qj0K?Vp@di4B0@5>,0*44
!AIVDM,1,1,,B,15NcRf0P3wG?Wq`K>o=RP?vB0<1J,0*7B
<?php ?>
</textarea>
<input type="submit" value="Plot Ships">
</form>

<p>
<em>What is this?</em><br>
This page demonstrates the <a href="http://www.aisparser.com">AIS Parser SDK</a> 
from <a href="http://www.brianlane.com">Brian C. Lane</a>. 
<a href="http://www.navcen.uscg.gov/enav/ais/default.htm">AIS is a system</a> 
for tracking ships using VHF transponders. You can receive these transmissions
using receivers available from <a href="http://www.milltechmarine.com">Milltech Marine</a> 
to listen to the ship reports.<br> This page demonstrates plotting the ships using 
the <a href="http://www.google.com/apis/maps/documentation/">Google Map API</a> 
and the ais_json program available with the <a href="index.php">AIS Parser SDK</a>.
</p>
<p>
<em>How does it work?</em><br>
When you paste in your AIVDM messages and click the 'Plot Ships' button
the server passes the data to a program names ais_json that parses the AIVDM
messages into a javascript data structure. This structure is then used by the
Google Maps API to plot the positions of the ships on the map.
</p>
<p>
The code for this page is availble <a href="demo_howto.php">here</a>. The basic 
structure of the page is taken from the 
<a href="http://www.google.com/apis/maps/documentation/">Google Map API</a> example 
page. I then added my own template to it, and some php code to pass the AIVDM 
strings to the ais_json application.
</p>
<p>
After the javascript section is started we insert a little bit of PHP code to 
check to see if any AIVDM sentences have been passed to the script. If the 
'aisdata' field (from a POST to the demo.php page) has data in it, it is passed 
to the AIS Parser SDK's JSON demo application. It parses the AIVDM sentences 
and outputs a javascript variable named ships.
</p>
The first javascript code sets up the icon to use for the ship positions. We 
could even make a custom icon that looked like a ship. This is done by 
setting the icon size and graphics of the GIcon() object that we create.
</p>
<p>
The first function, createMarker() is a helper function to create a marker at 
a position using the point (position), icon and text label passed to the function. 
Each marker also has a click event associated with it that will open the information 
window. You could easily add the Lat/Lon of the ship, its name, destination, etc.
</p>
<p>
fccSearch() is an incomplete function that attempts to pass the MMSI to the FCC
search form. It is currently commented out because it doesn't work. So instead it 
just shows a link to the FCC search form where you can paste the MMSI in manually. 
This function is called when building the text label to send to the createMarker() 
function.
</p>
<p>
The load() function is where all the fun happens. load() is called when the page 
is loaded (because it has been set in the onload field of the body section of 
the page. It first creates a map, adds the basic controls to the map and 
sets the center of the map to the first ship in the list. It then steps through 
the list of ships and places markers at each position using the createMarker() 
function.
</p>
<p>
The rest of the page contains the form, pre-populated with AIVDM messages if
nothing has been entered before, and this text. Not much to it, is there? 
</p>
</td>
</table>

<center>
<p class="copyright">
Copyright &copy; 2007-2008 by <a href="http://www.brianlane.com/">Brian C. Lane</a><br>All Rights Reserved
</p>
</center>

<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-550103-1";
urchinTracker();
</script>

</body>
</html>