<?
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 News</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>");
	echo ("<font face=Arial size=2>");

				$ID = array();
				$PersistenceLevel = array();
				$UrgencyLevel = array();
				$Category = array();
				$IdiomSize = array();
				$Idiom = array();
				$NewsTime = array();
				$TimeDetail = array();
				$Color = array();

				$idiomtext = "";
				$idiomtextcorr = "";
				$testchar = "";
				$test=0;

				$caturgcolor = array();
				$caturgcolor[0][0] = "#B6B7FE";
				$caturgcolor[0][1] = "#A9A9F1";
				$caturgcolor[0][2] = "#9594E0";
				$caturgcolor[0][3] = "#8282CE";
				$caturgcolor[0][4] = "#6C6CBA";
				$caturgcolor[0][5] = "#5B5CAA";
				$caturgcolor[1][0] = "#EB873D";
				$caturgcolor[1][1] = "#DE7032";
				$caturgcolor[1][2] = "#CE5524";
				$caturgcolor[1][3] = "#BE3B18";
				$caturgcolor[1][4] = "#AF210B";
				$caturgcolor[1][5] = "#A20C01";
				$caturgcolor[2][0] = "#00EB72";
				$caturgcolor[2][1] = "#00D668";
				$caturgcolor[2][2] = "#00BC5B";
				$caturgcolor[2][3] = "#00A44F";
				$caturgcolor[2][4] = "#008A42";
				$caturgcolor[2][5] = "#007639";


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

    				$query = "SELECT UrgencyLevel,Category,Idiom FROM newsstory ORDER BY NewsTime";
    				$result = mysql_query($query);
				$a=0;
				while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {

				$UrgencyLevel[$a] = $line['UrgencyLevel'];
				$Category[$a] = $line['Category'];
				$Idiom[$a] = $line['Idiom'];

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

				echo ("<br>");
				for ($i=$a;$i--;) {
					
					for ($j=0; $j<strlen($Idiom[$i])/2; $j++) {
						$idiomtext.=chr(base_convert(substr($Idiom[$i],$j*2,2),16,10));
					}

					$test=0;					
					for ($k=0; $k<strlen($idiomtext)-1; $k++) {
						$testchar = substr($idiomtext, $k, 1);
						if($testchar == ".") {
							$idiomtextcorr = substr($idiomtext, $k+2);
							$test=1;
						}
						if($testchar == "!") {
							$idiomtextcorr = substr($idiomtext, $k+2);
							$test=1;
						}
					
					}
					if($test == 0) {
						$idiomtextcorr = substr($idiomtext, 1);
					}

					echo ("<b>");					
					echo ("<font color=");
					echo $caturgcolor[$Category[$i]][$UrgencyLevel[$i]];
					echo (">");

					echo $idiomtextcorr;
					
					echo ("</font>");
					echo ("</b><br><br>");

					$idiomtext = "";					
					$idiomtextcorr = ""; 
				}			
	echo ("</font>");			
	echo ("</td>");
	echo ("</tr>");
echo ("</table>");
echo ("<br>");
echo ("</body>");
echo ("</html>");
?>