<?php
require("../../inc/header.inc");
require("../serverStatusImprove/function.inc");
?>
<script language="JavaScript">
function clearAll()
{
	window.location.href="./plat_status.php?clearAll=1";
}
</script>
<body onload="javascript:adjust();" onresize="javascript:adjust();" leftmargin="15" style="overflow:hidden;overflow-x:hidden;overflow-y:hidden;">
<?php
$global_id=0;
function AssignID()
{
	global $global_id;
	
	$id="ID_{$global_id}";
	$global_id++;
	return $id;
}
?>

<?php
adjust_head();

adjust_title_head();
echo "<FORM NAME=\"downForm\" action=\"./server_status.php\" method=\"post\">";
echo "<table id=\"table_up\" border=\"0\" width=\"100%\">";
	echo "<tr>";
		echo "<td width=\"50%\">";
		echo "$strSysStatus > NSS > Platform";
		echo "</td>";
		echo "<td width=\"50%\" align=\"right\" title=\"Help\">";
		//showHelp($helpId);
		echo "</td>";
	echo "</tr>";
	echo "<tr>";
		echo "<td width=\"50%\">";
		echo "&nbsp;";
		echo "</td>";
		echo "<td width=\"50%\" align=\"right\" title=\"Clear\">";
		echo "<a href=# onClick=\"javascript:clearAll();\"><img align=absBottom border=0 src=\"../../images/delete.gif\" width=\"14\" height=\"14\">$strClear</a>";
		echo "</td>";
	echo "</tr>";
echo "</table>";
adjust_title_tail();
adjust_content_head();


$config=parse_ini_file("config.ini",true);
$config_count=sizeof($config);
if(0)
{
	echo "config_count=$config_count<br>";
	echo "<pre>";
	print_r($config);
	echo "</pre>";
}

if($clearAll == 1)
{
	$sql="delete from OMC_PUB.sysInfo where sysTypeNo={$config[PlatSysTypeNo]} ";
	@mysqli_query($pubConn,$sql);
	echo mysqli_error($pubConn);
}

echo "<br><center><font color=\"blue\">Platform summary information</font></center>";
echo "<table border=\"1\" width=\"100%\" cellpadding=\"1\" cellspacing=\"0\" bordercolor=\"#666666\" bordercolordark=\"#FFFFFF\" bgcolor=\"#ffffff\">";
echo "<tr bgcolor=\"#E6E6E6\">";
echo "<td>Item</td>";
echo "<td>Status</td>";
echo "<td>Start Time</td>";
echo "<td>Refresh Time</td>";
echo "<td>IP Address</td>";
echo "</tr>";
echo "<tr id=\"blank_line\">";
echo "<td>--</td><td>--</td><td>--</td><td>--</td><td>--</td>";
echo "</tr>";


foreach($config as $key => $val)
{
	if(strcmp($key,"PlatSysTypeNo")==0)
	{
		continue;
	}



	for($j=0;$j<$config[$key][PlatformNo];$j++)
	{
		//Rowline
		$id=AssignID();
		echo "<tr id=\"$id\" style=\"display:none;\">";
		//Item Name
		
		echo "<td>{$config[$key][PlatformName]}_{$j}</td>";
		//Status
		$id=AssignID();
		echo "<td>";
		echo "<a href=\"./plat_status_detail.php?subSysNo=$j&platID={$config[$key][PlatformID]}\">";
		echo "<span id=\"{$id}\" style=\"color:#000000;\">$id</span>";
		echo "</a>";
		echo "</td>";
		
		//Start Time
		$id=AssignID();
		echo "<td>";
		echo "<span id=\"{$id}\" style=\"color:#000000;\">$id</span>";
		echo "</td>";
		
		//Refresh Time
		$id=AssignID();
		echo "<td>";
		echo "<span id=\"{$id}\" style=\"color:#000000;\">$id</span>";
		echo "</td>";
		
		//IP Address
		$id=AssignID();
		echo "<td>";
		echo "<span id=\"{$id}\" style=\"color:#000000;\">$id</span>";
		echo "</td>";
		
		echo "</tr>";
	}
}

echo "<table>";


echo "<table border=\"0\" width=\"100%\">";
	echo "<tr>";
		echo "<td width=\"50%\" align=\"left\">";
		echo "Remarks:  <font color=\"blue\">Y</font> = Normal,    <font color=\"red\">N</font> = Abnormal,   -- = None.";
		echo "</td>";
		echo "<td width=\"50%\" align=\"right\" title=\"Clear\">";
		echo "<a href=# onClick=\"javascript:clearAll();\"><img align=absBottom border=0 src=\"../../images/delete.gif\" width=\"14\" height=\"14\">$strClear</a>";
		echo "</td>";
	echo "</tr>";
echo "</table>";
if($clearAll)
{
	echo "<script language=\"JavaScript\">\n";
	echo "document.getElementById('blank_line').style.display='';\n";
	echo "</script>\n";
}

echo "</form>";
adjust_content_tail();
?>

<script language="JavaScript">
function updateStatus()
{
	var fixurl="./plat_status_update.php";
	var browserr = navigator.appName;
	if(browserr == "Microsoft Internet Explorer")
	{
		request_oo = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else
	{
		request_oo = new XMLHttpRequest();
	}
	request_oo.open("GET",fixurl,"false");

	request_oo.onreadystatechange=function()
	{ 
		checUpdateState(); 
	}
	request_oo.send(null);
	setTimeout("updateStatus()", 10000);
}

function checUpdateState()
{
	//not
	if(request_oo.readyState == 3)
	{
		//alert("not finish");
	}
	if(request_oo.readyState == 4)
	{
		var response = request_oo.responseText;
		//alert(response);
		
		var module=response.split(';');
		//alert("module.length="+module.length);
		for(i=0;i<module.length;i++)
		{
			var items=module[i].split(',');
			//alert(items.length);
			if(items.length != 4)
				continue;
			var item_id=items[0].replace(/(^\s*)|(\s*$)/g, "");
			var item_state=items[1].replace(/(^\s*)|(\s*$)/g, "");
			var item_value=items[2].replace(/(^\s*)|(\s*$)/g, "");
			var item_color=items[3].replace(/(^\s*)|(\s*$)/g, "");
			//alert("item_id="+item_id+",item_state="+item_state+",item_value="+item_value+",item_color="+item_color);
			if(item_state == 'block')
			{
				document.getElementById(item_id).style.display='';
			}
			else
			{
				document.getElementById(item_id).style.display='none';
			}
			
			if(item_value != 'none')
			{
				document.getElementById(item_id).innerHTML=item_value;
			}
			if(item_color != 'none')
			{
				document.getElementById(item_id).style.color=item_color;
			}			
		}
	}
}

updateStatus();
</script>
