<?php
/******** Get the function state of OPPS ************/
$serviceFlag=array(
			"00"=>"BothClose",
			"01"=>"IMDXOpen",
			"10"=>"OPROpen",
			"11"=>"BothOpen"
);
$oppsServiceStatus=getSystemState(375,86,2);
//echo "oppsServiceStatus=$oppsServiceStatus<br>";
$enableFlag=1;
if($serviceFlag[$oppsServiceStatus] == "OPROpen")
{
	$tmpLabel=array(0=>"OPR Registration",1=>"OPR Location Update",2=>"OPR Mode Switch");
	$sel_type=$tmpLabel[$keyTwo];
}
else if($serviceFlag[$oppsServiceStatus] == "IMDXOpen")
{
	$tmpLabel=array(0=>"IMDX MO",1=>"IMDX Location Update");
	$sel_type=$tmpLabel[$keyTwo];
}
else if($serviceFlag[$oppsServiceStatus] == "BothOpen")
{
	$tmpLabel=array(0=>"OPR Registration",1=>"OPR Location Update",2=>"OPR Mode Switch",3=>"IMDX MO",4=>"IMDX Location Update");
	$sel_type=$tmpLabel[$keyTwo];
}
else
{
	$tmpLabel=array(0=>"None");
	$enableFlag=0;
}

if($enableFlag == 0)
	exit("Can not receive the heartbeat of OPPS or the function is disable");

//*********************************
$cstaConf=GetCstaConf($sysTypeNo);
if(0)
{
	echo "sel_date_from=$sel_date_from,sel_date_to=$sel_date_to<br>";
	echo "keyTwo=$keyTwo,sel_type=$sel_type<br>";
	echo "<pre>";
	print_r($cstaConf);
	echo "</pre>";
}

echo "<input type=\"hidden\" name=\"select_checkbox_id\" value=\"$select_checkbox_id\">";
echo "<input type=\"hidden\" name=\"scroll_y\" value=\"$scroll_y\">";

$slot=$sel_date_from-$sel_date_to+1;
$total_hour_num=$slot*24;
$startTime=date("Y-m-d H:i:s",mktime(0,0,0,date("m"),date("d")-$sel_date_from,date("Y")));
$endTime=date("Y-m-d H:i:s",mktime(23,59,59,date("m"),date("d")-$sel_date_to,date("Y")));
//echo "startTime=$startTime,endTime=$endTime<br>";

$cstaData=GetCstaDataByDay($cstaConf,$startTime,$endTime,"detail");
if(0)
{
	echo "<pre>";
	print_r($cstaData);
	echo "</pre>";
}

//Table-1
if($serviceFlag[$oppsServiceStatus] == "BothOpen" || $serviceFlag[$oppsServiceStatus] == "OPROpen")
{
	$table_title="OPR Statistic&nbsp;&nbsp;Date:";
	if($slot>1)
		$table_title.=date("Y-m-d",mktime(0,0,0,date("m"),date("d")-$sel_date_from,date("Y")))." to ".date("Y-m-d",mktime(0,0,0,date("m"),date("d")-$sel_date_to,date("Y")));
	else
		$table_title.=date("Y-m-d",mktime(0,0,0,date("m"),date("d")-$sel_date_from,date("Y")));
	echo "<br><b><center>$table_title</center></b>";
	echo "<table width=\"100%\" border=\"1\" cellpadding=\"2\" cellspacing=\"0\" bordercolor=\"#666666\" bordercolordark=\"#FFFFFF\" bgcolor=\"#FFFFFF\">";
	echo "<tr bgcolor=\"#E6E6E6\">";
	echo "<td width=\"10%\">&nbsp;</td>";
	echo "<td width=\"15%\">Manual Register</td>";
	echo "<td width=\"15%\">Auto Register</td>";
	echo "<td width=\"15%\">OPR LU</td>";
	echo "<td width=\"15%\">Recycle Account</td>";
	echo "<td width=\"15%\">Switch to Roam</td>";
	echo "<td width=\"15%\">Switch to OPR</td>";
	echo "</tr>";
	
	echo "<tr>";
	echo "<td bgcolor=\"#E6E6E6\">Success</td>";
	$value=$cstaData[0][1][man_reg_suc]+0;
	echo "<td>$value</td>";
	$value=$cstaData[0][1][auto_reg_suc]+0;
	echo "<td>$value</td>";
	$value=$cstaData[0][1][opr_lu_suc]+0;
	echo "<td>$value</td>";
	$value=$cstaData[0][1][recy_sub_suc]+0;
	echo "<td>$value</td>";
	$value=$cstaData[0][1][swi_roam_mode_suc]+0;
	echo "<td>$value</td>";
	$value=$cstaData[0][1][swi_opr_mode_suc]+0;
	echo "<td>$value</td>";
	echo "</tr>";
	
	echo "<tr>";
	echo "<td bgcolor=\"#E6E6E6\">Fail</td>";
	$value=$cstaData[0][1][man_reg_fail]+0;
	echo "<td>$value</td>";
	$value=$cstaData[0][1][auto_reg_fail]+0;
	echo "<td>$value</td>";
	$value=$cstaData[0][1][opr_lu_fail]+0;
	echo "<td>$value</td>";
	$value=$cstaData[0][1][recy_sub_fail]+0;
	echo "<td>$value</td>";
	$value=$cstaData[0][1][swi_roam_mode_fail]+0;
	echo "<td>$value</td>";
	$value=$cstaData[0][1][swi_opr_mode_fail]+0;
	echo "<td>$value</td>";
	echo "</tr>";
	echo "</table>";
}

//Table-2
if($serviceFlag[$oppsServiceStatus] == "BothOpen" || $serviceFlag[$oppsServiceStatus] == "IMDXOpen")
{
	$table_title="IMDX Statistic&nbsp;&nbsp;Date:";
	if($slot>1)
		$table_title.=date("Y-m-d",mktime(0,0,0,date("m"),date("d")-$sel_date_from,date("Y")))." to ".date("Y-m-d",mktime(0,0,0,date("m"),date("d")-$sel_date_to,date("Y")));
	else
		$table_title.=date("Y-m-d",mktime(0,0,0,date("m"),date("d")-$sel_date_from,date("Y")));
	echo "<br><b><center>$table_title</center></b>";
	echo "<table width=\"100%\" border=\"1\" cellpadding=\"2\" cellspacing=\"0\" bordercolor=\"#666666\" bordercolordark=\"#FFFFFF\" bgcolor=\"#FFFFFF\">";

	echo "<tr>";
	echo "<td bgcolor=\"#E6E6E6\" rowspan=3 width=\"10%\">MO Services</td>";
	echo "<tr bgcolor=\"#E6E6E6\">";
	echo "<td width=\"15%\">Private to Private</td>";
	echo "<td width=\"15%\">Hybrid to Private</td>";
	echo "<td width=\"15%\">Hybrid to Public</td>";
	echo "<td width=\"15%\">Premium to Public</td>";
	echo "<td width=\"15%\">Ordinary to Public</td>";
	echo "<td width=\"15%\">Public to Private</td>";
	echo "</tr>";
	echo "<tr>";
	$value=$cstaData[1][2][pri_to_pri]+0;
	echo "<td>$value</td>";
	$value=$cstaData[1][2][hyb_to_pri]+0;
	echo "<td>$value</td>";
	$value=$cstaData[1][2][hyb_to_pub]+0;
	echo "<td>$value</td>";
	$value=$cstaData[1][2][pre_to_pub]+0;
	echo "<td>$value</td>";
	$value=$cstaData[1][2][ord_to_pub]+0;
	echo "<td>$value</td>";
	$value=$cstaData[1][2][pub_to_pri]+0;
	echo "<td>$value</td>";
	echo "</tr>";
	      
	echo "<tr>";
	echo "<td bgcolor=\"#E6E6E6\" rowspan=3>LU</td>";
	echo "<tr bgcolor=\"#E6E6E6\">";
	echo "<td>Private Success</td>";
	echo "<td>Private Excluded</td>";
	echo "<td>Hybrid Success</td>";
	echo "<td>Hybrid Excluded</td>";
	echo "<td>Public Success</td>";
	echo "<td>Public Excluded</td>";
	echo "</tr>";
	echo "<tr>";
	$value=$cstaData[1][2][pre_lu_suc]+$cstaData[1][2][ord_lu_suc];
	echo "<td>$value</td>";
	$value=$cstaData[1][2][pre_lu_exc]+$cstaData[1][2][ord_lu_exc];
	echo "<td>$value</td>";
	$value=$cstaData[1][2][hyb_lu_suc]+0;
	echo "<td>$value</td>";
	$value=$cstaData[1][2][hyb_lu_exc]+0;
	echo "<td>$value</td>";
	$value=$cstaData[1][2][pub_lu_suc]+0;
	echo "<td>$value</td>";
	$value=$cstaData[1][2][pub_lu_exc]+0;
	echo "<td>$value</td>";
	echo "</tr>";
	echo "</table>";
}

//Graphics-1
{
	unset($cstaData);
	unset($tmpData);
	unset($tmpColor);
	$cstaData=GetCstaDataByHour($cstaConf,$startTime,$endTime,"detail");
	if(0)
	{
		echo "<pre>";
		print_r($cstaData);
		echo "</pre>";
		echo "sel_type=$sel_type<br>";
	}
	if(strcmp($sel_type,"OPR Registration")==0)
	{
		if($flag0 == "on")
		{
			$tmpColor[]=array(0x66,0xff,0x33);
			unset($data);
			for($i=0;$i<$total_hour_num;$i++)
				$data[$i]=$cstaData[0][1][man_reg_suc][$i]+0;
			$tmpData[]=$data;
		}
		if($flag1 == "on")
		{
			$tmpColor[]=array(0x66,0xff,0xff);
			unset($data);
			for($i=0;$i<$total_hour_num;$i++)
				$data[$i]=$cstaData[0][1][man_reg_fail][$i]+0;
			$tmpData[]=$data;
		}
		if($flag2 == "on")
		{
			$tmpColor[]=array(0x00,0x66,0x66);
			unset($data);
			for($i=0;$i<$total_hour_num;$i++)
				$data[$i]=$cstaData[0][1][auto_reg_suc][$i]+0;
			$tmpData[]=$data;
		}
		if($flag3 == "on")
		{
			$tmpColor[]=array(0x66,0,0xcc);
			unset($data);
			for($i=0;$i<$total_hour_num;$i++)
				$data[$i]=$cstaData[0][1][auto_reg_fail][$i]+0;
			$tmpData[]=$data;
		}
		
		$remarkBlock=array(
			"Manual-Registration Success",
			"Manual-Registration Fail",
			"Auto-Registration Success",
			"Auto-Registration Fail"
		);
		
		$pointArr=array(
			array(50,367),
			array(240,367),
			array(430,367),
			array(620,367)
		);
		unset($blockColor);
		$blockColor[]=array(0x66,0xff,0x33);
		$blockColor[]=array(0x66,0xff,0xff);
		$blockColor[]=array(0x00,0x66,0x66);
		$blockColor[]=array(0x66,0,0xcc);
	}
	else if(strcmp($sel_type,"OPR Location Update")==0)
	{
		if($flag0 == "on")
		{
			$tmpColor[]=array(0x66,0xff,0x33);
			unset($data);
			for($i=0;$i<$total_hour_num;$i++)
				$data[$i]=$cstaData[0][1][opr_lu_suc][$i]+0;
			$tmpData[]=$data;
		}
		if($flag1 == "on")
		{
			$tmpColor[]=array(0x66,0xff,0xff);
			unset($data);
			for($i=0;$i<$total_hour_num;$i++)
				$data[$i]=$cstaData[0][1][opr_lu_fail][$i]+0;
			$tmpData[]=$data;
		}
		if($flag2 == "on")
		{
			$tmpColor[]=array(0x00,0x66,0x66);
			unset($data);
			for($i=0;$i<$total_hour_num;$i++)
				$data[$i]=$cstaData[0][1][recy_sub_suc][$i]+0;
			$tmpData[]=$data;
		}
		if($flag3 == "on")
		{
			$tmpColor[]=array(0x66,0,0xcc);
			unset($data);
			for($i=0;$i<$total_hour_num;$i++)
				$data[$i]=$cstaData[0][1][recy_sub_fail][$i]+0;
			$tmpData[]=$data;
		}
		
		$remarkBlock=array(
			"OPR LU Success",
			"OPR LU Fail",
			"Non-OPR Success",
			"Non-OPR Fail"
		);
		$pointArr=array(
			array(50,367),
			array(240,367),
			array(430,367),
			array(620,367)
		);
		unset($blockColor);
		$blockColor[]=array(0x66,0xff,0x33);
		$blockColor[]=array(0x66,0xff,0xff);
		$blockColor[]=array(0x00,0x66,0x66);
		$blockColor[]=array(0x66,0,0xcc);
	}
	else if(strcmp($sel_type,"OPR Mode Switch")==0)
	{
		if($flag0 == "on")
		{
			$tmpColor[]=array(0x66,0xff,0x33);
			unset($data);
			for($i=0;$i<$total_hour_num;$i++)
				$data[$i]=$cstaData[0][1][swi_roam_mode_suc][$i]+0;
			$tmpData[]=$data;
		}
		if($flag1 == "on")
		{
			$tmpColor[]=array(0x66,0xff,0xff);
			unset($data);
			for($i=0;$i<$total_hour_num;$i++)
				$data[$i]=$cstaData[0][1][swi_roam_mode_fail][$i]+0;
			$tmpData[]=$data;
		}
		if($flag2 == "on")
		{
			$tmpColor[]=array(0x00,0x66,0x66);
			unset($data);
			for($i=0;$i<$total_hour_num;$i++)
				$data[$i]=$cstaData[0][1][swi_opr_mode_suc][$i]+0;
			$tmpData[]=$data;
		}
		if($flag3 == "on")
		{
			$tmpColor[]=array(0x66,0,0xcc);
			unset($data);
			for($i=0;$i<$total_hour_num;$i++)
				$data[$i]=$cstaData[0][1][swi_opr_mode_fail][$i]+0;
			$tmpData[]=$data;
		}
		
		$remarkBlock=array(
			"OPR to Roam Success",
			"OPR to Roam Fail",
			"Roam to OPR Success",
			"Roam to OPR Fail"
		);
		$pointArr=array(
			array(50,367),
			array(240,367),
			array(430,367),
			array(620,367)
		);
		unset($blockColor);
		$blockColor[]=array(0x66,0xff,0x33);
		$blockColor[]=array(0x66,0xff,0xff);
		$blockColor[]=array(0x00,0x66,0x66);
		$blockColor[]=array(0x66,0,0xcc);
	}
	else if(strcmp($sel_type,"IMDX MO")==0)
	{
		if($flag0 == "on")
		{
			$tmpColor[]=array(0x66,0xff,0x33);
			unset($data);
			for($i=0;$i<$total_hour_num;$i++)
				$data[$i]=$cstaData[1][2][pri_to_pri][$i]+0;
			$tmpData[]=$data;
		}
		if($flag1 == "on")
		{
			$tmpColor[]=array(0x66,0xff,0xff);
			unset($data);
			for($i=0;$i<$total_hour_num;$i++)
				$data[$i]=$cstaData[1][2][hyb_to_pri][$i]+0;
			$tmpData[]=$data;
		}
		if($flag2 == "on")
		{
			$tmpColor[]=array(0x00,0x66,0x66);
			unset($data);
			for($i=0;$i<$total_hour_num;$i++)
				$data[$i]=$cstaData[1][2][hyb_to_pub][$i]+0;
			$tmpData[]=$data;
		}
		if($flag3 == "on")
		{
			$tmpColor[]=array(0x66,0,0xcc);
			unset($data);
			for($i=0;$i<$total_hour_num;$i++)
				$data[$i]=$cstaData[1][2][pre_to_pub][$i]+0;
			$tmpData[]=$data;
		}
		if($flag4 == "on")
		{
			$tmpColor[]=array(0x66,0x33,0);
			unset($data);
			for($i=0;$i<$total_hour_num;$i++)
				$data[$i]=$cstaData[1][2][ord_to_pub][$i]+0;
			$tmpData[]=$data;
		}
		if($flag5 == "on")
		{
			$tmpColor[]=array(0xcc,0,0x66);
			unset($data);
			for($i=0;$i<$total_hour_num;$i++)
				$data[$i]=$cstaData[1][2][pub_to_pri][$i]+0;
			$tmpData[]=$data;
		}
		
		$remarkBlock=array(
			"Private to Private",
			"Hybrid to Private",
			"Hybrid to Public",
			"Premium to Public",
			"Ordinary to Public",
			"Public to Private"
		);
		$pointArr=array(
			array(50,367),
			array(180,367),
			array(310,367),
			array(440,367),
			array(570,367),
			array(700,367)
		);
		unset($blockColor);
		$blockColor[]=array(0x66,0xff,0x33);
		$blockColor[]=array(0x66,0xff,0xff);
		$blockColor[]=array(0x00,0x66,0x66);
		$blockColor[]=array(0x66,0,0xcc);
		$blockColor[]=array(0x66,0x33,0);
		$blockColor[]=array(0xcc,0,0x66);
	}
	else if(strcmp($sel_type,"IMDX Location Update")==0)
	{
		if($flag0 == "on")
		{
			$tmpColor[]=array(0x66,0xff,0x33);
			unset($data);
			for($i=0;$i<$total_hour_num;$i++)
				$data[$i]=$cstaData[1][2][ord_lu_suc][$i]+$cstaData[1][2][pre_lu_suc][$i];
			$tmpData[]=$data;
		}
		if($flag1 == "on")
		{
			$tmpColor[]=array(0x66,0xff,0xff);
			unset($data);
			for($i=0;$i<$total_hour_num;$i++)
				$data[$i]=$cstaData[1][2][ord_lu_exc][$i]+$cstaData[1][2][pre_lu_exc][$i];
			$tmpData[]=$data;
		}
		if($flag2 == "on")
		{
			$tmpColor[]=array(0x00,0x66,0x66);
			unset($data);
			for($i=0;$i<$total_hour_num;$i++)
				$data[$i]=$cstaData[1][2][hyb_lu_suc][$i]+0;
			$tmpData[]=$data;
		}
		if($flag3 == "on")
		{
			$tmpColor[]=array(0x66,0,0xcc);
			unset($data);
			for($i=0;$i<$total_hour_num;$i++)
				$data[$i]=$cstaData[1][2][hyb_lu_exc][$i]+0;
			$tmpData[]=$data;
		}
		if($flag4 == "on")
		{
			$tmpColor[]=array(0x66,0x33,0);
			unset($data);
			for($i=0;$i<$total_hour_num;$i++)
				$data[$i]=$cstaData[1][2][pub_lu_suc][$i]+0;
			$tmpData[]=$data;
		}
		if($flag5 == "on")
		{
			$tmpColor[]=array(0xcc,0,0x66);
			unset($data);
			for($i=0;$i<$total_hour_num;$i++)
				$data[$i]=$cstaData[1][2][pub_lu_exc][$i]+0;
			$tmpData[]=$data;
		}
		
		$remarkBlock=array(
			"Private Success",
			"Private Excluded",
			"Hybrid Success",
			"Hybrid Excluded",
			"Public Success",
			"Public Excluded"
		);
		$pointArr=array(
			array(50,367),
			array(180,367),
			array(310,367),
			array(440,367),
			array(570,367),
			array(700,367)
		);
		unset($blockColor);
		$blockColor[]=array(0x66,0xff,0x33);
		$blockColor[]=array(0x66,0xff,0xff);
		$blockColor[]=array(0x00,0x66,0x66);
		$blockColor[]=array(0x66,0,0xcc);
		$blockColor[]=array(0x66,0x33,0);
		$blockColor[]=array(0xcc,0,0x66);
	}

	echo "<br><b>$sel_type Statistic Chart</b><br>";
	
	if(0)
	{
		echo "flag0=$flag0,flag1=$flag1,flag2=$flag2,flag3=$flag3,flag4=$flag4,flag5=$flag5,flag6=$flag6,flag7=$flag7,flag8=$flag8,flag9=$flag9,flag10=$flag10,flag11=$flag11,flag12=$flag12,flag13=$flag13,flag14=$flag14,flag15=$flag15,flag16=$flag16<br>";
	}
	
	$boldline=$select_checkbox_id;
	for($i=0;$i<$select_checkbox_id;$i++)
	{
		$param="flag$i";
		if($$param != "on")
			$boldline--;
	}

	$image=CreateImage(820,390);
	$image=DrawLineHistogram(
		$image,
		$tmpData,
		$tmpColor,
		750/(24*$slot),
		24,
		array(50,20),
		array(750,280),
		$boldline,1,0,1
	);
	
	$image=AddRemarkToImage($image,$pointArr,$remarkBlock,$blockColor,0,2);
	DrawTimeStamp($image,$sel_date_from,$sel_date_to,array(50,355),750/24);
	
	echo "<table border=0 width=\"820\">";
	echo "<tr>";
	for($i=0;$i<sizeof($remarkBlock);$i++)
	{
		echo "<td>";
		AddCheckbox($remarkBlock[$i]);
		echo "</td>";
	}
	echo "</tr>";
	echo "</table>";
	
	DrawImage($image);
}
?>

