main
<?php
// Includes
require_once "ic_mgr.php";
require_once "simulator.php";
$manager = new ICManager( );
//$simulator = new Simulator( );
// Determine type of display
$useragent = $HTTP_SERVER_VARS["HTTP_USER_AGENT"];
//echo $useragent;
$manager->set_display( $useragent
);
$device_display = $manager->get_display( );
$manager->activate_ic( );
?>
ic_mgr
<?php
// Includes
require_once "desktop_ic.php";
require_once "handheld_ic.php";
require_once "vehicle_ic.php";
// Common values
//$const_dsp_desktop = "desktop";
//$const_dsp_handheld = "handheld";
//$const_dsp_vehicle = "vehicle";
// IC Manager class.
class ICManager
{
var $display_type;
function ICManager( )
{
$this->display_type = "none";
}
function set_display( $dspl_type )
{
$this->display_type = $dspl_type;
//if( preg_match( "/MSIE/i",
"$dspl_type" ) )
//{
// // Set display type to desktop
// $this->display_type = $const_dsp_desktop;
//}
//
//elseif( preg_match( "/MobilePhone/i", "$dspl_type" )
// || preg_match( "/Opera/i", "$dspl_type" ) )
//{
// // Set display type to handheld
// $this->display_type = $const_dsp_handheld;
//}
//
//elseif( preg_match( "/Netscape/i", "$dspl_type" ) )
//{
// // Set display type to vehicle
// $this->display_type = $const_dsp_vehicle;
//}
//
//else
//{
// echo "<br>ERROR: Unable to determine device display type!";
// $this->display_type = "none";
//}
}
function get_display( )
{
// Returns the display value
return( $this->display_type );
}
function activate_ic( )
{
//echo "<br>Activating ic...<br>";
if( $this->display_type == "none" )
{
echo "<br>ERROR: Device display type not set!";
}
elseif( preg_match( "/MSIE/i",
"$this->display_type" ) )
{
// Create a new desktop IC
$desktop_ic = new DesktopIC( );
$desktop_ic->format_display( );
}
elseif( preg_match( "/MobilePhone/i", "$this->display_type"
)
|| preg_match( "/Opera/i", "$this->display_type" ) )
{
// Create a new handheld IC
$handheld_ic = new HandheldIC( );
$handheld_ic->format_display( );
}
elseif( preg_match( "/Netscape/i", "$this->display_type"
) )
{
// Create a new vehicle IC
$vehicle_ic = new VehicleIC( );
$vehicle_ic->format_display( );
}
else
{
echo "<br>ERROR: Unable to determine device type!";
}
}
}
?>
desktop_ic
<?php
// Includes
require_once "track.php";
require_once "simulator.php";
require_once "crossing.php";
class DesktopIC
{
var $simulator;
var $curr_bucket;
var $curr_sec_at_pos;
var $track1;
var $track2;
var $track3;
var $track4;
var $track5;
var $track6;
var $track7;
var $track8;
var $track9;
var $track10;
var $track11;
var $crossing1;
var $crossing2;
var $crossing3;
// Constructor
function DesktopIC( )
{
$this->simulator = new Simulator( );
$this->simulator->simulate( );
$this->curr_bucket = $this->simulator->get_bucket( );
$this->curr_sec_at_pos = $this->simulator->get_seconds( );
$tk_size = "large";
$this->track1 = new Track( 1, $tk_size
);
$this->track2 = new Track( 2, $tk_size );
$this->track3 = new Track( 3, $tk_size );
$this->track4 = new Track( 4, $tk_size );
$this->track5 = new Track( 5, $tk_size );
$this->track6 = new Track( 6, $tk_size );
$this->track7 = new Track( 7, $tk_size );
$this->track8 = new Track( 8, $tk_size );
$this->track9 = new Track( 9, $tk_size );
$this->track10 = new Track( 10, $tk_size );
$this->track11 = new Track( 11, $tk_size );
// For simulation to work, the ID
must match the track position.
$this->crossing1 = new Crossing( 3 );
$this->crossing2 = new Crossing( 6 );
$this->crossing3 = new Crossing( 9 );
}
function format_display( )
{
// Full graphics Desktop IC
echo "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">
<html>
<head>
<title>Full Graphical View</title>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">
<meta http-equiv=\"refresh\" content=\"3 ;url=main.php\">
</head>";
echo "
<body>
<div align=\"center\">
<img src=\"images/train_logo.gif\"><br><br>
<table width=\"90%\" border=\"1\" cellspacing=\"0\"
cellpadding=\"0\">
<tr>
<td><div align=\"center\"><img src=\"images/town_north.jpg\"
width=\"880\" height=\"250\"></div></td>
</tr>
<tr>
<td><table width=\"100%\" border=\"0\" cellspacing=\"0\"
cellpadding=\"0\">
<tr>";
echo "<td><img src=\"";
echo $this->track1->determine_track_color( $this->curr_bucket ); /*images/green_tk.jpg*/
echo "\" width=\"80\" height=\"10\"></td>";
echo "<td><img src=\"";
echo $this->track2->determine_track_color( $this->curr_bucket );
echo "\" width=\"80\" height=\"10\"></td>";
echo "<td><img src=\"";
echo $this->track3->determine_track_color( $this->curr_bucket );
echo "\" width=\"80\" height=\"10\"></td>";
echo "<td><img src=\"";
echo $this->track4->determine_track_color( $this->curr_bucket );
echo "\" width=\"80\" height=\"10\"></td>";
echo "<td><img src=\"";
echo $this->track5->determine_track_color( $this->curr_bucket );
echo "\" width=\"80\" height=\"10\"></td>";
echo "<td><img src=\"";
echo $this->track6->determine_track_color( $this->curr_bucket );
echo "\" width=\"80\" height=\"10\"></td>";
echo "<td><img src=\"";
echo $this->track7->determine_track_color( $this->curr_bucket );
echo "\" width=\"80\" height=\"10\"></td>";
echo "<td><img src=\"";
echo $this->track8->determine_track_color( $this->curr_bucket );
echo "\" width=\"80\" height=\"10\"></td>";
echo "<td><img src=\"";
echo $this->track9->determine_track_color( $this->curr_bucket );
echo "\" width=\"80\" height=\"10\"></td>";
echo "<td><img src=\"";
echo $this->track10->determine_track_color( $this->curr_bucket );
echo "\" width=\"80\" height=\"10\"></td>";
echo "<td><img src=\"";
echo $this->track11->determine_track_color( $this->curr_bucket );
echo "\" width=\"80\" height=\"10\"></td>";
echo "</tr>
</table></td>
</tr>
<tr>
<td><div align=\"center\"><img src=\"images/town_south.jpg\"
width=\"880\" height=\"250\"></div></td>
</tr>
</table>
<br><br>
<table width=\"90%\" border=\"4\" cellpadding=\"2\"
cellspacing=\"0\" bgcolor=\"#FFFFFF\">
<tr>
<td width=\"33%\"><div align=\"center\"><font
face=\"Arial, Helvetica, sans-serif\"><strong>Current
Train Direction:<br>
<img src=\"images/right_arrow_ball.gif\" width=\"60\"
height=\"60\"> </strong></font></div></td>
<td width=\"34%\"><div align=\"center\"><font
color=\"#0000FF\" size=\"6\" face=\"Arial, Helvetica,
sans-serif\"><strong>Crossing
Information</strong></font></div></td>
<td width=\"33%\"><div align=\"center\"><font
face=\"Arial, Helvetica, sans-serif\">
<form action=\"main.php\" method=\"POST\"><input
type=\"submit\" value=\"Refresh\"></form></font></div></td>
</tr>
<tr>
<td><div align=\"center\"><font size=\"5\"
face=\"Arial, Helvetica, sans-serif\"><strong>Crossing
#1</strong></font></div></td>
<td><div align=\"center\"><font size=\"5\"
face=\"Arial, Helvetica, sans-serif\"><strong>Crossing
#2</strong></font></div></td>
<td><div align=\"center\"><font size=\"5\"
face=\"Arial, Helvetica, sans-serif\"><strong>Crossing
#3</strong></font></div></td>
</tr>
<tr>";
echo "<td><font face=\"Arial, Helvetica, sans-serif\"><strong>Estimated
Delay: < ";
echo $this->crossing1->get_crossing_delay( $this->curr_bucket, $this->curr_sec_at_pos
);
echo " min</strong></font></td>";
echo "<td><font face=\"Arial,
Helvetica, sans-serif\"><strong>Estimated Delay: < ";
echo $this->crossing2->get_crossing_delay( $this->curr_bucket, $this->curr_sec_at_pos
);
echo " min</strong></font></td>";
echo "<td><font face=\"Arial,
Helvetica, sans-serif\"><strong>Estimated Delay: < ";
echo $this->crossing3->get_crossing_delay( $this->curr_bucket, $this->curr_sec_at_pos
);
echo " min</strong></font></td>";
echo "</tr>
<tr>";
echo "<td><font face=\"Arial, Helvetica, sans-serif\"><strong>Est.
Time Until Block: < ";
echo $this->crossing1->get_time_to_block( $this->curr_bucket, $this->curr_sec_at_pos
);
echo " min</strong></font></td>";
echo "<td><font face=\"Arial,
Helvetica, sans-serif\"><strong>Est. Time Until Block: < ";
echo $this->crossing2->get_time_to_block( $this->curr_bucket, $this->curr_sec_at_pos
);
echo " min</strong></font></td>";
echo "<td><font face=\"Arial,
Helvetica, sans-serif\"><strong>Est. Time Until Block: < ";
echo $this->crossing3->get_time_to_block( $this->curr_bucket, $this->curr_sec_at_pos
);
echo " min</strong></font></td>";
echo "</tr>
</table>
</div>
</body>
</html>
";
}
}
?>
vehicle_ic
<?php
// Includes
require_once "track.php";
require_once "simulator.php";
require_once "crossing.php";
class VehicleIC
{
var $simulator;
var $curr_bucket;
var $curr_sec_at_pos;
var $track1;
var $track2;
var $track3;
var $track4;
var $track5;
var $track6;
var $track7;
var $track8;
var $track9;
var $track10;
var $track11;
var $crossing1;
var $crossing2;
var $crossing3;
// Constructor
function VehicleIC( )
{
$this->simulator = new Simulator( );
$this->simulator->simulate( );
$this->curr_bucket = $this->simulator->get_bucket( );
$this->curr_sec_at_pos = $this->simulator->get_seconds( );
$this->track1 = new Track( 1, $tk_size
);
$this->track2 = new Track( 2, $tk_size );
$this->track3 = new Track( 3, $tk_size );
$this->track4 = new Track( 4, $tk_size );
$this->track5 = new Track( 5, $tk_size );
$this->track6 = new Track( 6, $tk_size );
$this->track7 = new Track( 7, $tk_size );
$this->track8 = new Track( 8, $tk_size );
$this->track9 = new Track( 9, $tk_size );
$this->track10 = new Track( 10, $tk_size );
$this->track11 = new Track( 11, $tk_size );
// For simulation to work, the ID
must match the track position.
$this->crossing1 = new Crossing( 3 );
$this->crossing2 = new Crossing( 6 );
$this->crossing3 = new Crossing( 9 );
}
function format_display( )
{
// Full graphics Desktop IC
echo "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">
<html>
<head>
<title>Vehicle View</title>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">
<meta http-equiv=\"refresh\" content=\"3 ;url=main.php\">
</head>";
echo "
<body>
<div align=\"center\">
<img src=\"images/sm_train_logo.jpg\"><br><br>
<table width=\"440\" border=\"1\" cellspacing=\"0\"
cellpadding=\"0\">
<tr>
<td><div align=\"center\"><img src=\"images/sm_town_north.jpg\"
width=\"440\" height=\"125\"></div></td>
</tr>
<tr>
<td><table width=\"100%\" border=\"0\" cellspacing=\"0\"
cellpadding=\"0\">
<tr>";
echo "<td><img src=\"";
echo $this->track1->determine_track_color( $this->curr_bucket ); /*images/green_tk.jpg*/
echo "\" width=\"40\" height=\"5\"></td>";
echo "<td><img src=\"";
echo $this->track2->determine_track_color( $this->curr_bucket );
echo "\" width=\"40\" height=\"5\"></td>";
echo "<td><img src=\"";
echo $this->track3->determine_track_color( $this->curr_bucket );
echo "\" width=\"40\" height=\"5\"></td>";
echo "<td><img src=\"";
echo $this->track4->determine_track_color( $this->curr_bucket );
echo "\" width=\"40\" height=\"5\"></td>";
echo "<td><img src=\"";
echo $this->track5->determine_track_color( $this->curr_bucket );
echo "\" width=\"40\" height=\"5\"></td>";
echo "<td><img src=\"";
echo $this->track6->determine_track_color( $this->curr_bucket );
echo "\" width=\"40\" height=\"5\"></td>";
echo "<td><img src=\"";
echo $this->track7->determine_track_color( $this->curr_bucket );
echo "\" width=\"40\" height=\"5\"></td>";
echo "<td><img src=\"";
echo $this->track8->determine_track_color( $this->curr_bucket );
echo "\" width=\"40\" height=\"5\"></td>";
echo "<td><img src=\"";
echo $this->track9->determine_track_color( $this->curr_bucket );
echo "\" width=\"40\" height=\"5\"></td>";
echo "<td><img src=\"";
echo $this->track10->determine_track_color( $this->curr_bucket );
echo "\" width=\"40\" height=\"5\"></td>";
echo "<td><img src=\"";
echo $this->track11->determine_track_color( $this->curr_bucket );
echo "\" width=\"40\" height=\"5\"></td>";
echo "</tr>
</table></td>
</tr>
<tr>
<td><div align=\"center\"><img src=\"images/sm_town_south.jpg\"
width=\"440\" height=\"125\"></div></td>
</tr>
</table>
<br>
<table width=\"440\" border=\"4\" cellpadding=\"2\"
cellspacing=\"0\" bgcolor=\"#FFFFFF\">
<tr>
<td width=\"33%\"><div align=\"center\"><font
face=\"Arial, Helvetica, sans-serif\" size=\"2\"><strong>Current
Train Direction:<br>
<img src=\"images/sm_right_arrow.jpg\" width=\"30\" height=\"30\">
</strong></font></div></td>
<td width=\"34%\"><div align=\"center\"><font
color=\"#0000FF\" size=\"3\" face=\"Arial, Helvetica,
sans-serif\"><strong>Crossing
Information</strong></font></div></td>
<td width=\"33%\"><div align=\"center\"><font
face=\"Arial, Helvetica, sans-serif\">
<form action=\"main.php\" method=\"POST\"><input
type=\"submit\" value=\"Refresh\"></form></font></div></td>
</tr>
<tr>
<td><div align=\"center\"><font size=\"2\"
face=\"Arial, Helvetica, sans-serif\"><strong>Crossing
#1</strong></font></div></td>
<td><div align=\"center\"><font size=\"2\"
face=\"Arial, Helvetica, sans-serif\"><strong>Crossing
#2</strong></font></div></td>
<td><div align=\"center\"><font size=\"2\"
face=\"Arial, Helvetica, sans-serif\"><strong>Crossing
#3</strong></font></div></td>
</tr>
<tr>";
echo "<td><font face=\"Arial, Helvetica, sans-serif\"
size=\"2\">Estimated Delay: <strong><br>< ";
echo $this->crossing1->get_crossing_delay( $this->curr_bucket, $this->curr_sec_at_pos
);
echo " min</strong></font></td>";
echo "<td><font face=\"Arial,
Helvetica, sans-serif\" size=\"2\">Estimated Delay: <strong><br><
";
echo $this->crossing2->get_crossing_delay( $this->curr_bucket, $this->curr_sec_at_pos
);
echo " min</strong></font></td>";
echo "<td><font face=\"Arial,
Helvetica, sans-serif\" size=\"2\">Estimated Delay: <strong><br><
";
echo $this->crossing3->get_crossing_delay( $this->curr_bucket, $this->curr_sec_at_pos
);
echo " min</strong></font></td>";
echo "</tr>
<tr>";
echo "<td><font face=\"Arial, Helvetica, sans-serif\"
size=\"2\">Est. Time Until Block: <strong><br><
";
echo $this->crossing1->get_time_to_block( $this->curr_bucket, $this->curr_sec_at_pos
);
echo " min</strong></font></td>";
echo "<td><font face=\"Arial,
Helvetica, sans-serif\" size=\"2\">Est. Time Until Block:
<strong><br>< ";
echo $this->crossing2->get_time_to_block( $this->curr_bucket, $this->curr_sec_at_pos
);
echo " min</strong></font></td>";
echo "<td><font face=\"Arial,
Helvetica, sans-serif\" size=\"2\">Est. Time Until Block:
<strong><br>< ";
echo $this->crossing3->get_time_to_block( $this->curr_bucket, $this->curr_sec_at_pos
);
echo " min</strong></font></td>";
echo "</tr>
</table>
</div>
</body>
</html>
";
}
}
?>
handheld_ic
<?php
// Includes
require_once "simulator.php";
require_once "crossing.php";
class HandheldIC
{
var $simulator;
var $curr_bucket;
var $curr_sec_at_pos;
var $crossing1;
var $crossing2;
var $crossing3;
// Constructor
function HandheldIC( )
{
$this->simulator = new Simulator( );
$this->simulator->simulate( );
$this->curr_bucket = $this->simulator->get_bucket( );
$this->curr_sec_at_pos = $this->simulator->get_seconds( );
// For simulation to work, the ID
must match the track position.
$this->crossing1 = new Crossing( 3 );
$this->crossing2 = new Crossing( 6 );
$this->crossing3 = new Crossing( 9 );
}
function format_display( )
{
// Text Only Handheld IC (WML)
//echo "<?xml version=\"1.0\"\?\>";
//echo "<!DOCTYPE wml PUBLIC \"-//WAPFORUM//DTD WML 1.1//EN\"
\"http://www.wapforum.org/DTD/wml_1.1.xml\">";
//
//echo "<wml>
//<card>
//<p><b>Rail Traffic Notification System</b></p>
//
//
//<do label=\'Refresh\' type=\'accept\'><go href=\'main.php\'/></do>
//</card>
//</wml>";
// Full graphics Desktop IC
echo "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">
<html>
<head>
<title>Handheld Version</title>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">
</head>";
echo "
<body>
<font face=\"Arial, Helvetica, sans-serif\" color=\"#0000FF\">
<strong>Rail Traffic Notifier System</strong></font><br>
<hr>
<p>
<em><strong>Crossing #1</strong></em><br>
<font face=\"Arial, Helvetica, sans-serif\"><strong>Estimated
Delay:</strong><br>< ";
echo $this->crossing1->get_crossing_delay( $this->curr_bucket, $this->curr_sec_at_pos
);
echo " min</font><br>";
echo "<font face=\"Arial,
Helvetica, sans-serif\"><strong>Est. Time Until Block:</strong>
< ";
echo $this->crossing1->get_time_to_block( $this->curr_bucket, $this->curr_sec_at_pos
);
echo " min</font><br><br>";
echo "
<em><strong>Crossing #2</strong></em><br>
<font face=\"Arial, Helvetica, sans-serif\"><strong>Estimated
Delay:</strong><br>< ";
echo $this->crossing2->get_crossing_delay( $this->curr_bucket, $this->curr_sec_at_pos
);
echo " min</font><br>";
echo "<font face=\"Arial,
Helvetica, sans-serif\"><strong>Est. Time Until Block:</strong>
< ";
echo $this->crossing2->get_time_to_block( $this->curr_bucket, $this->curr_sec_at_pos
);
echo " min</font><br><br>";
echo "
<em><strong>Crossing #3</strong></em><br>
<font face=\"Arial, Helvetica, sans-serif\"><strong>Estimated
Delay:</strong><br>< ";
echo $this->crossing3->get_crossing_delay( $this->curr_bucket, $this->curr_sec_at_pos
);
echo " min</font><br>";
echo "<font face=\"Arial,
Helvetica, sans-serif\"><strong>Est. Time Until Block:</strong>
< ";
echo $this->crossing3->get_time_to_block( $this->curr_bucket, $this->curr_sec_at_pos
);
echo " min</font><br>";
echo "<form action=\"main.php\"
method=\"POST\">";
echo "<input type=\"submit\" value=\"Refresh\"></form>";
echo "
</p>
</body>
</html>";
}
}
?>
simulator
<?php
// Simulator Class
class Simulator
{
var $curr_bucket;
var $sec_in_bucket;
// Constructor
function simulate( )
{
$curr_time = time( );
//echo $curr_time;
$seconds = ( $curr_time%60 );
//echo "<br>The number of seconds is: ";
//echo $seconds;
$this->curr_bucket = ( ( $seconds/4
) - ( fmod( $seconds, 4 ) / 4 ) );
//echo "<br>Bucket Number (Seconds/4): ";
//echo $this->curr_bucket;
$this->sec_in_bucket = ( fmod(
$seconds, 4 ) ); //+ 1 );
//echo "<br>Seconds -1 in this bucket: ";
//echo $this->sec_in_bucket;
}
// Bucket accessor
function get_bucket( )
{
return( $this->curr_bucket );
}
// Seconds in bucket accessor
function get_seconds( )
{
return( $this->sec_in_bucket );
}
}
?>
track
<?php
// Includes
require_once "ic_mgr.php";
class Track
{
var $track_position = 0;
var $track_size = "large";
var $green_tk_path;
var $sm_green_tk_path;
var $yellow_tk_path;
var $sm_yellow_tk_path;
var $red_tk_path;
var $sm_red_tk_path;
// Constructor
function Track( $track_pos, $dsp_size = "large" )
{
$this->track_position = $track_pos;
$this->track_size = $dsp_size;
$this->green_tk_path = "images/green_tk.jpg";
$this->sm_green_tk_path = "images/sm_green_tk.jpg";
$this->yellow_tk_path = "images/yellow_tk.jpg";
$this->sm_yellow_tk_path = "images/sm_yellow_tk.jpg";
$this->red_tk_path = "images/red_tk.jpg";
$this->sm_red_tk_path = "images/sm_red_tk.jpg";
}
function determine_track_color( $bucket
)
{
$return_val;
// Determine type of display
//$user_display = $HTTP_SERVER_VARS["HTTP_USER_AGENT"];
if( $bucket == ( $this->track_position
) )
{
if( $this->track_size == "small" )
{
$return_val = $this->sm_yellow_tk_path;
}
else
{
$return_val = $this->yellow_tk_path;
}
}
elseif( ( $bucket == ( $this->track_position + 1 ) )
|| ( $bucket == ( $this->track_position + 2 ) ) )
{
if( $this->track_size == "small" )
{
$return_val = $this->sm_red_tk_path;
}
else
{
$return_val = $this->red_tk_path;
}
}
else
{
if( $this->track_size == "small" )
{
$return_val = $this->sm_green_tk_path;
}
else
{
$return_val = $this->green_tk_path;
}
}
return( $return_val );
}
}
?>
crossing
<?php
class Crossing
{
var $crossing_id = 0;
// Constructor
function Crossing( $device_id )
{
$this->crossing_id = $device_id;
}
function get_crossing_delay( $bucket,
$sec_at_pos )
{
$return_val = 0;
if( $bucket == $this->crossing_id
+ 1 )
{
// Add 1 to correct for train occupancy.
$return_val = ( 4 + ( 4 - $sec_at_pos ) );
}
elseif( $bucket == ( $this->crossing_id
+ 2 ) )
{
// Add 1 to correct for train occupancy.
$return_val = ( 4 - $sec_at_pos );
}
return( $return_val );
}
function get_time_to_block( $bucket,
$sec_at_pos )
{
$return_val;
$sec_remain_at_pos = ( 4 - $sec_at_pos );
if( $bucket <= $this->crossing_id
)
{
$return_val = ( ( ( $this->crossing_id - $bucket ) * 4 ) + $sec_remain_at_pos
);
}
elseif( $bucket > ( $this->crossing_id
+ 2 ) )
{
$return_val = ( ( ( 14 - $bucket + 1 ) * 4 ) + ( ( $this->crossing_id ) *
4 ) + $sec_remain_at_pos );
}
else
{
$return_val = 0;
}
return( $return_val );
}
}
?>