<?
include_once('mapcfg.php');

echo ("<html>");
echo ("<head>");
echo ("<meta http-equiv=Content-Style-Type content=text/css>");
echo ("<link rel=stylesheet href=$cssloc type=text/css>");
echo ("<title>$D2campname Who's Online</title>");
echo ("</head>");
echo ("<body>");
echo ("<br>");
echo ("<table width=60% cellspacing=0 cellpadding=0 border=0 align=center>");
  	echo ("<tr>");
    	echo ("<td width=100% align=center class=windowbg2>");

		$ID = array();
		$CharacterName = array();
		$CharacterPoliticalControl = array();
		$CharacterRank = array();
		$CharacterLocationX = array();
		$CharacterLocationY = array();
		$Flags = array();

		$rankstring = array();
		$rankstring[0] = "Ensign";
		$rankstring[1] = "Lieutenant";
		$rankstring[2] = "LtCommander";
		$rankstring[3] = "Captain";
		$rankstring[4] = "Commodore";
		$rankstring[5] = "RearAdmiral";
		$rankstring[6] = "Admiral";
		$rankstring[7] = "FleetAdmiral";

		$link = mysql_connect($D2dbhostname .":" .$D2dbport, $D2dbuser, $D2dbpass);
   		mysql_select_db($D2db);

    		$query = "SELECT CharacterName,CharacterPoliticalControl,CharacterRank,CharacterLocationX,CharacterLocationY,Flags FROM ServCharacter WHERE WONLOGON <>'' AND (( Flags & 2 ) OR ( Flags & 4 ) OR ( Flags & 8 ) OR ( Flags & 1024 )) ORDER BY CharacterPoliticalControl, CharacterName";
    		$result = mysql_query($query);
		$a=0;
		while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {

		$CharacterName[$a] = $line['CharacterName'];
		$CharacterPoliticalControl[$a] = $line['CharacterPoliticalControl'];
		$CharacterRank[$a] = $line['CharacterRank'];
		$CharacterLocationX[$a] = $line['CharacterLocationX'];
		$CharacterLocationY[$a] = $line['CharacterLocationY'];
		$Flags[$a] = $line['Flags'];

		$a=$a+1;
    		}
    		mysql_free_result($result);
    		mysql_close($link);

		echo ("<br>");
		echo ("<font face=Arial size=2>");

		for ($i=0; $i <= $a-1; $i++) {
			echo $rankstring[$CharacterRank[$i]];
			echo (" ");
			echo ("<b>");
			echo "<font color=";
			echo $empcolor[$CharacterPoliticalControl[$i]];
			echo ">";
			echo $CharacterName[$i];
			echo "</font>";
			echo ("</b>");
			echo (" - ");
			echo ("(");
			echo $CharacterLocationX[$i];
			echo (",");
			echo $CharacterLocationY[$i];
			echo (")");
			if ($Flags[$i] == 66) {
				echo (" in mission");
			}
			echo ("<br>");
		}

		If ($a == 0){
			echo ("Nobody Online...");
		}
		echo ("</font>");
		echo ("<br><br>");	
	
	echo ("</td>");
	echo ("</tr>");
echo ("</table>");
echo ("<br>");
echo ("</body>");
echo ("</html>");

?>
				