Just as a reference, this is the code which drives my Mode-S page:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<?php
// initialize variables
$BSFILE = 'files/basestation_light.sqb';
$FLAGSFILE = 'files/bsflags-mil_web.txt';
$FLAGSFOLDER = 'flags';
$GROUNDSTATION = "'<your sharer code>'";
$LOGDIR = 'logs';
$LOOKUP = 'http://www.airliners.net/search/photo.search?';
$POSITION = '<your position>';
$RADIUS = '<your reception radius>';
// fill flags array
$FLAGS = array();
foreach(file($FLAGSFILE, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) as $LINE) {
$FLAGS[] = explode(' ', $LINE, 3);
}
// connect to basestation database
$BSDB = new PDO('sqlite:' . $BSFILE);
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Military Mode-S logs - Ground Station '<?php echo $GROUNDSTATION ?>'</title>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<link rel="stylesheet" type="text/css" media="all" href="modeslogs.css">
</head>
<body>
<div class="section" id="header_section">
<form action="?" method="post" id="header_form">
<div id="selectlog">
<label for="date_select">Select log date:</label>
<select name="date_select" onchange="header_form.submit();">
<?php
// fill dropdown box with available dates
foreach(array_reverse(glob($LOGDIR . '/pp_report20??????00.sqb')) as $LOGFILE) {
$DATE = substr($LOGFILE, -14, 8);
echo '<option value="' . $LOGFILE . '"';'>' . date('D d-m-Y', strtotime($DATE));
if (isset($_POST['date_select'])) {
if ($_POST['date_select'] == $LOGFILE) {
echo ' selected="selected"';
$SELECTED = $LOGFILE;
}
}
echo '>' . date(' D d-m-Y ', strtotime($DATE)) . '</option>' . PHP_EOL;
}
?>
</select>
</div><!-- #selectlog -->
<span>Military Mode-S logs</span>
<div class="buttons">
<button type="button" onclick="header_form.submit();">Refresh</button>
</div><!-- .buttons -->
</form>
</div><!-- #header_section -->
<div class="section" id="display_section">
<?php
// for the initial page view, selected is todays log file
if (!isset($SELECTED)) $SELECTED = $LOGDIR . '/pp_report'. date('Ymd') . '00.sqb';
// log date
echo '<div id="logdate">' . date('l d-m-Y', strtotime(substr($SELECTED, -14, 8))) . '</div>';
// connect to log database and fetch all rows
$LOGDB = new PDO('sqlite:' . $SELECTED);
$QUERY = $LOGDB->query("SELECT * FROM PPreport ORDER BY firsttime");
$LOGRESULT = $QUERY->fetchAll(PDO::FETCH_ASSOC);
?>
<table>
<tr>
<th></th>
<th></th>
<th>flight</th>
<th>registration</th>
<th>type</th>
<th>UTC time</th>
<th>ICAO Hex</th>
<th>squawk</th>
<th>altitude</th>
</tr>
<?php
// display all rows
$LOGROWCLASS = '';
foreach($LOGRESULT as $LOGROW) {
// get relevant data from basestation database
$FLIGHTID = explode(';', $LOGROW['flightid']);
$SQLSTR = "SELECT ModeSCountry, Manufacturer, [Type] FROM Aircraft WHERE ModeS = '" . $FLIGHTID[0] . "'";
$QUERY = $BSDB->query($SQLSTR);
$BSRESULT = $QUERY->fetch(PDO::FETCH_ASSOC);
// flag image and text
foreach($FLAGS as $FLAG) {
if ((castHex($FLIGHTID[0]) >= castHex($FLAG[0])) && (castHex($FLIGHTID[0]) <= castHex($FLAG[1]))) break;
}
$COUNTRY = explode('.', $FLAG[2], 2);
$COUNTRY[0] = str_replace(array($FLAGSFOLDER, '_'), array('', ' '), $COUNTRY[0]);
if ((strtolower(substr($BSRESULT['ModeSCountry'], -3))) == 'mil') {
$FLAG[2] = str_replace('.', '_Mil.', $FLAG[2]);
$COUNTRY[0] .= ' (mil)';
}
// display row
$LOGROWCLASS = ($LOGROWCLASS == 'odd') ? 'even' : 'odd';
echo '<tr class="' . $LOGROWCLASS . '">' . PHP_EOL . '<td id="flag">';
echo '<img src="' . $FLAG[2] . '" title=" ' . $COUNTRY[0] . ' "></td>' . PHP_EOL;
echo '<td id="space"> </td>' . PHP_EOL . '<td>' . $FLIGHTID[1] . '</td>' . PHP_EOL;
echo '<td title=" find \'' . regFormat($FLIGHTID[2]) . '\' on airliners.net "><a href="' . $LOOKUP;
echo 'regsearch=' . regFormat($FLIGHTID[2]) . '" target="_blank">' . $FLIGHTID[2] . '</a></td>' . PHP_EOL;
if ($BSRESULT['Type'] != '') {
echo '<td title=" ' . trim($BSRESULT['Manufacturer']) . ' ' . $BSRESULT['Type'] . ' (ICAO: ';
echo $LOGROW['type'] . ') ">' . $BSRESULT['Type'] . '</td>' . PHP_EOL;
} else {
echo '<td>' . $LOGROW['type'] . '</td>' . PHP_EOL;
}
echo '<td title=" GMT+' . (1 + date('I')) . ': ' . date('H:i:s', $LOGROW['firsttime']) . ' → ';
echo date('H:i:s', $LOGROW['lasttime']) . ' ">' . gmdate('H:i:s', $LOGROW['firsttime']) . ' → ';
echo gmdate('H:i:s', $LOGROW['lasttime']) . '</td>' . PHP_EOL . '<td>' . $FLIGHTID[0] . '</td>' . PHP_EOL;
echo '<td>' . $LOGROW['firstsquawk'];
if ($LOGROW['firstsquawk'] != $LOGROW['lastsquawk']) echo ' → ' . $LOGROW['lastsquawk'];
echo '</td>' . PHP_EOL . '<td>' . $LOGROW['firstalt'];
if ($LOGROW['firstalt'] != $LOGROW['lastalt']) echo ' → ' . $LOGROW['lastalt'];
echo '</td>' . PHP_EOL . '</tr>' . PHP_EOL;
}
?>
</table>
</div><!-- #display_section -->
<div class="section" id="footer_section">
<form action="#footer_section" method="post" id="footer_form">
<div id="footer_copyright">© Crouze.com</div>
<?php
if (substr($SELECTED, -14, 8) == gmdate('Ymd')) {
echo '<div class="buttons">';
echo '<button type="button" onclick="footer_form.submit();">Refresh</button></div>' . PHP_EOL;
}
?>
<div id="footer_text">
PlanePlotter Ground Station. Sharer id <?php echo $GROUNDSTATION ?>
approximate position: <?php echo $POSITION ?>
usual log radius: about <?php echo $RADIUS ?> miles
</div><!-- #footer_text -->
</form>
</div><!-- #footer_section -->
</body>
</html>
<?php
// cast hexadecimal
function castHex($STR) {
return '0x' . $STR;
}
// format registrations
function regFormat($STR) {
return str_replace(array('+', 'LXN904'),
array('' , 'LX-N904'),
$STR);
}
?>