<?php
require("../../inc/lib.inc");
require("../serverStatusImprove/function.inc")
?>

<?php
$global_id=0;
global $pubConn;

function AssignID()
{
	global $global_id;
	
	$id="ID_{$global_id}";
	$global_id++;
	return $id;
}
?>
<?php

$config=parse_ini_file("config.ini",true);
$config_count=sizeof($config);

$total_response="";
$show_num=0;

foreach($config as $key => $val)
{
	if(strcmp($key,"PlatSysTypeNo")==0)
	{
		continue;
	}
	for($sysNo=0;$sysNo<$config[$key]['PlatformNo'];$sysNo++)
	{
		$sql="select * from OMC_PUB.sysInfo where sysTypeNo={$config['PlatSysTypeNo']} and sysNo={$config[$key]['PlatformID']} and subSysNo={$sysNo} ";
		$res=mysqli_query($pubConn,$sql);
		$num=mysqli_num_rows($res);
		
		if($num == 0)
		{
			$id=AssignID();
			$total_response.="$id,none,none,none;";
			$id=AssignID();
			$id=AssignID();
			$id=AssignID();
			$id=AssignID();
			continue;
		}
		else
		{
			$row=@mysqli_fetch_array($res);
			$id=AssignID();
			$total_response.="$id,block,none,none;";
			
			//Status
			$id=AssignID();
			$value=$row['baseStat']+0;
			$refresh_time=$row['updateTime'];
			$due_date=date("Y-m-d H:i:s",mktime(date("H"),date("i"),date("s")-60,date("m"),date("d"),date("Y")));
			$ove_date=date("Y-m-d H:i:s",mktime(date("H"),date("i"),date("s")+60,date("m"),date("d"),date("Y")));
			if($refresh_time < $due_date || $refresh_time > $ove_date)
			{
				$valid_time=0;
			}
			else
			{
				$valid_time=1;
			}
			if($valid_time == 0 || $value == 0)
				$total_response.="$id,block,N,#ff0000;";
			else
				$total_response.="$id,block,Y,#0000ff;";
				
			//Start Time
			$id=AssignID();
			$tmpConf['PlatNo']=$config[$key]['PlatformID'];
			$plat=GetPlatInfo($tmpConf,$sysNo);
			if(trim($plat['StartTime']['Value']) == "")
				$total_response.="$id,block,--,#0000ff;";
			else
				$total_response.="$id,block,{$plat['StartTime']['Value']},#0000ff;";
			
			//Refresh Time
			$id=AssignID();
			if($valid_time)
				$total_response.="$id,block,$refresh_time,#0000ff;";
			else
				$total_response.="$id,block,$refresh_time,#ff0000;";
				
			//IP Address
			$id=AssignID();
			$value=$row['ip'];
			$total_response.="$id,block,$value,#0000ff;";
			
			$show_num++;
		}
	}
}
if($show_num)
	$total_response.="blank_line,none,none,none;";

echo $total_response;
?>
