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

$global_id=0;
function AssignID()
{
	global $global_id;
	
	$id="ID_{$global_id}";
	$global_id++;
	return $id;
}
if(0)
{
	echo "platID=$platID,subSysNo=$subSysNo";
}

$config=parse_ini_file("config.ini",true);
$config_count=sizeof($config);
foreach($config as $key => $val)
{
	if($config[$key][PlatformID] == $platID)
	{
		$thisconfig=$config[$key];
		break;
	}
}

$sql="select * from OMC_PUB.sysStat where sysTypeNo=200 and sysNo={$platID} and subSysNo=$subSysNo ";
//echo "$sql<br>";
$res=mysqli_query($pubConn,$sql);
$num=mysqli_num_rows($res);
if($num == 0)
	exit();

$tmpconf[PlatNo]=$platID;
$plat=GetPlatInfo($tmpconf,$subSysNo);



//platform Status
$id=AssignID();
$sql="select * from OMC_PUB.sysInfo where sysTypeNo=200 and sysNo={$platID} and subSysNo=$subSysNo ";
//echo "$sql<br>";
$res=mysqli_query($pubConn,$sql);
$num=mysqli_num_rows($res);
if($num != 1)
{
	$baseStat=0;
}
else
{
	$row=@mysqli_fetch_array($res);
	$baseStat=$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 || $baseStat == 0)
	$total_response.="$id,block,N,#ff0000;";
else
	$total_response.="$id,block,Y,#0000ff;";
	
//Refresh Time
$id=AssignID();
if($valid_time)
	$total_response.="$id,block,$refresh_time,#0000ff;";
else
	$total_response.="$id,block,$refresh_time,#ff0000;";
	
//Start Time
$id=AssignID();
if(trim($plat[StartTime][Value]) == "")
	$total_response.="$id,block,--,#000000;";
else
	$total_response.="$id,block,{$plat[StartTime][Value]},#0000ff;";


//CPU Usage PN
$id=AssignID();
$message="{$id},{$plat[CPURatePN][Display]},{$plat[CPURatePN][Value]},{$plat[CPURatePN][Color]};";
$total_response.=$message;

//CPU Usage
$id=AssignID();
$message="{$id},{$plat[CPURate][Display]},{$plat[CPURate][Value]},{$plat[CPURate][Color]};";
$total_response.=$message;

//Physical Memory
$id=AssignID();
$message="{$id},{$plat[PMTotalRatePN][Display]},{$plat[PMTotalRatePN][Value]},{$plat[PMTotalRatePN][Color]};";
$total_response.=$message;

$id=AssignID();
$message="{$id},{$plat[PMTotalRate][Display]},{$plat[PMTotalRate][Value]},{$plat[PMTotalRate][Color]};";
$total_response.=$message;

$id=AssignID();
$message="{$id},{$plat[PMTotalRateV][Display]},{$plat[PMTotalRateV][Value]},{$plat[PMTotalRateV][Color]};";
$total_response.=$message;

$id=AssignID();
$message="{$id},{$plat[PMSwapRatePN][Display]},{$plat[PMSwapRatePN][Value]},{$plat[PMSwapRatePN][Color]};";
$total_response.=$message;

$id=AssignID();
$message="{$id},{$plat[PMSwapRate][Display]},{$plat[PMSwapRate][Value]},{$plat[PMSwapRate][Color]};";
$total_response.=$message;

$id=AssignID();
$message="{$id},{$plat[PMSwapRateV][Display]},{$plat[PMSwapRateV][Value]},{$plat[PMSwapRateV][Color]};";
$total_response.=$message;

$id=AssignID();
$message="{$id},{$plat[PMBuffers][Display]},{$plat[PMBuffers][Value]},{$plat[PMBuffers][Color]};";
$total_response.=$message;

$id=AssignID();
$message="{$id},{$plat[PMCached][Display]},{$plat[PMCached][Value]},{$plat[PMCached][Color]};";
$total_response.=$message;

//Harddisk
for($i=0;$i<16;$i++)
{
	if($i<$plat[HDNum])
	{
		$id=AssignID();
		$message="{$id},layerShow,no,no;";
		$total_response.=$message;
		
		$id=AssignID();
		$message="{$id},{$plat[HD][$i][PN][Display]},{$plat[HD][$i][PN][Value]},{$plat[HD][$i][PN][Color]};";
		$total_response.=$message;
		
		$id=AssignID();
		$message="{$id},{$plat[HD][$i][Rate][Display]},{$plat[HD][$i][Rate][Value]},{$plat[HD][$i][Rate][Color]};";
		$total_response.=$message;
		
		$id=AssignID();
		$message="{$id},{$plat[HD][$i][V][Display]},{$plat[HD][$i][V][Value]},{$plat[HD][$i][V][Color]};";
		$total_response.=$message;
		
		$id=AssignID();
		$message="{$id},{$plat[HD][$i][Path][Display]},{$plat[HD][$i][Path][Value]},{$plat[HD][$i][Path][Color]};";
		$total_response.=$message;
	}
	else
	{
		$id=AssignID();
		$message="{$id},layerHide,no,no;";
		$total_response.=$message;
		
		$id=AssignID();
		$message="{$id},none,{$plat[HD][$i][PN][Value]},{$plat[HD][$i][PN][Color]};";
		//$total_response.=$message;
		
		$id=AssignID();
		$message="{$id},none,{$plat[HD][$i][Rate][Value]},{$plat[HD][$i][Rate][Color]};";
		//$total_response.=$message;
		
		$id=AssignID();
		$message="{$id},none,{$plat[HD][$i][V][Value]},{$plat[HD][$i][V][Color]};";
		//$total_response.=$message;
		
		$id=AssignID();
		$message="{$id},none,{$plat[HD][$i][Path][Value]},{$plat[HD][$i][Path][Color]};";
		//$total_response.=$message;
	}
}

echo "$total_response";
?>
