<?php
	
	//require_once 'functions.php';
	//require_once 'stats_b.php';
	//require_once 'chats.php';
	//$XMLTEAM = unserialize(file_get_contents('stats_b.php'));
	//$XMLRACE = unserialize(file_get_contents('stats_race.php'));

	$color = array();
	
	$color["JOIN"] = '#008AFF';
	$color["LEAVE"] = '#FFA800';
	$color["SHIFTS"] = '#FF0000';
	$color["MSG"] = '#E9E9E9';
	$color["RACE_START"] = '#00FF00';
	$color["BADCHAT"] = '#FF00DE';
	
	$discardlist = array();
	$discardlist[] = 'made a pit stop';
	$discardlist[] = 'took over from';
	$discardlist[] = 'new guest is connecting';
	$discardlist[] = 'LFSW';
	$discardlist[] = 'Fastest lap';
	$discardlist[] = 'voted to ban';
	$discardlist[] = 'Vote cancelled';
	$discardlist[] = 'PENALTY';
	$discardlist[] = 'penalty';
	$discardlist[] = 'InSim';
	
	
	print "<table width=100% cellspacing=2 cellpadding=2 border=2>";
	
	foreach ($XMLCHAT as $k => $chat)
	{
		$discardline = false;
		foreach ($discardlist as $discard)
		{
			if (strstr($chat['value'], $discard))
			{
				$discardline = true;
				break;
			}
		}
		
		if ($discardline)
			continue;
		
		$c = $color[$chat['type']];
		
		if ($chat['type'] == "MSG")
		{
			if (strstr($chat['value'], " : "))
				$c = $color["BADCHAT"];
		}
		
		print "<tr bgcolor='" . $c . "'>";
			print "<td>" . $k . "</td>";
			print "<td>" . $chat['type'] . "</td>";
			print "<td>&nbsp;" . $chat['lfsworld'] . "</td>";
			print "<td>&nbsp;" . str_replace("^L", "", $chat['value']) . "</td>";
			print "<td>" . normalTime (($chat['logged'] - $XMLRACE['race_start'])*1000, false) . "</td>";
		print "</tr>";
	}
	
	print "</table>";
?>