<?php
require("../../inc/header.inc");
?>
<body leftmargin="15" rightmargin="10" onload="javascript:adjust_frame('down');" onresize="javascript:adjust_frame('down');" style="overflow:hidden;overflow-x:hidden;overflow-y:hidden;">

<?php
adjust_head_frame("down");
adjust_title_head_frame("down");
adjust_title_tail_frame("down");

adjust_content_head_frame("down");	
echo "<br>";

	//global variables
	$serviceFlag=array("00"=>"BothClose",
										 "01"=>"IMDXOpen",
										 "10"=>"OPROpen",
										 "11"=>"BothOpen");
	

	$oppsServiceStatus=getSystemState(375,94,2);
	if($DEBUG)echo "oppsServiceStatus=+$oppsServiceStatus+<br>";
	if($oppsServiceStatus=="")
	{
		exit("<p>Can't receive the heartbeat of OPPS!<br>");
	}
	
	if($serviceFlag[$oppsServiceStatus] == "OPROpen")
		$type_label=array(0=>"OPR Registration",1=>"OPR Location Update",2=>"OPR Mode Switch");
	else if($serviceFlag[$oppsServiceStatus] == "IMDXOpen")
		$type_label=array(0=>"IMDX MO",1=>"IMDX Location Update");
	else if($serviceFlag[$oppsServiceStatus] == "BothOpen")
		$type_label=array(0=>"OPR Registration",1=>"OPR Location Update",2=>"OPR Mode Switch",3=>"IMDX MO",4=>"IMDX Location Update");
	else
	{
		echo "<p>OPPS function disabled<br>";
		adjust_content_tail("down");
		exit(" ");
	}
	
	
	//============================================================================
	//global variables
	$DEBUG=0;
	if(!isset($sel_date))
		$sel_date=0;
	if(!isset($sel_type))
		$sel_type=0;
	if($DEBUG)
	{
		echo "sel_type=$sel_type<br>";
		echo "sel_date=$sel_date<br>";
	}
	//============================================================================
	
	//============================================================================
	//configurable variables
	$serviceFlag=array("00"=>"BothClose",
										 "01"=>"IMDXOpen",
										 "10"=>"OPROpen",
										 "11"=>"BothOpen");
	$oprTableTitle="OPR Statistic Date: ";
	$oprTableRowHead=array("Manual Register",
												 "Auto Register",
												 "OPR LU",
												 "Recycle Account",
												 "Switch to Roam",
												 "Switch to OPR");
	$oprTableColHead=array("Success","Fail");
	$imdxTableTitle="IMDX Statistic Date: ";
	$imdxTableRowHeadA=array("Private to Private",
													 "Hybrid to Private",
													 "Hybrid to Public",
													 "Premium to Public",
													 "Ordinary to Public",
													 "Public to Private");	
	$imdxTableRowHeadB=array("Private Success",
													 "Private Excluded",
													 "Hybrid Success",
													 "Hybrid Excluded",
													 "Public Success",
													 "Public Excluded");
	$imdxTableColHead=array("MO Services","LU");
	$oprTableFieldCount=14;
	$imdxTableFieldCount=15;
	$oppsFieldNameInDB=array(0=>"man_reg_suc",
													 1=>"man_reg_fail",										 
													 2=>"auto_reg_suc",
													 3=>"auto_reg_fail",										 
													 4=>"opr_lu_suc",
													 5=>"opr_lu_fail",
													 6=>"oth_lu_suc",
													 7=>"oth_lu_fail",
													 8=>"recy_sub_suc",
													 9=>"recy_sub_fail",
													 10=>"swi_roam_mode_suc",
													 11=>"swi_roam_mode_fail",
													 12=>"swi_opr_mode_suc", 
													 13=>"swi_opr_mode_fail",
													 
													 14=>"pri_to_pri",
													 15=>"hyb_to_pri",
													 16=>"hyb_to_pub",
													 17=>"pub_to_pub",										 
													 18=>"ord_to_pub",
													 19=>"pub_to_pri",
													 20=>"ord_lu_suc",
													 21=>"hyb_lu_suc",										 							 
													 22=>"pub_lu_suc",
													 23=>"ord_lu_exc",
													 24=>"hyb_lu_exc",
													 25=>"pub_lu_exc",
													 26=>"pre_lu_suc",
													 27=>"pre_lu_exc",
													 28=>"pre_to_pub");
													 


	
	//============================================================================
	//get service status
	$oppsServiceStatus=getSystemState(375,94,2);
	if($DEBUG)echo "oppsServiceStatus=+$oppsServiceStatus+<br>";
	if($oppsServiceStatus=="")
	{
		exit("");
	}
	
	if($serviceFlag[$oppsServiceStatus] == "OPROpen")
		$type_label=array(0=>"OPR Registration",1=>"OPR Location Update",2=>"OPR Mode Switch");
	else if($serviceFlag[$oppsServiceStatus] == "IMDXOpen")
		$type_label=array(0=>"IMDX MO",1=>"IMDX Location Update");
	else if($serviceFlag[$oppsServiceStatus] == "BothOpen")
		$type_label=array(0=>"OPR Registration",1=>"OPR Location Update",2=>"OPR Mode Switch",3=>"IMDX MO",4=>"IMDX Location Update");
	else
		exit();
		
	//get whole day data from database
	$db="CSTA_DB";
	$table_name="oppsDetail";
	$temp=date("d",mktime(0,0,0,date("m"),date("d")-$sel_date,date("Y")));
	$table_name=$table_name."_".$temp;
	if($DEBUG)echo "table_name:$table_name<br>";	
	
	$from_time=date("Y-m-d H:i:s",mktime(0,0,0,date("m"),date("d")-$sel_date,date("Y")));
	$to_time=date("Y-m-d H:i:s",mktime(0,0,0,date("m"),date("d")-$sel_date+1,date("Y")));
	if($DEBUG)echo "from:$from_time--to:$to_time<br>";
	
	$select="select key_type,";
	for($i=0;$i<sizeof($oppsFieldNameInDB);$i++)
	{
		$select.="sum({$oppsFieldNameInDB[$i]}) as {$oppsFieldNameInDB[$i]}";
		if($i != (sizeof($oppsFieldNameInDB)-1))
			$select.=",";
		else	
			$select.=" ";
	}

	$from="from $table_name ";
	$where="where csta_datetime >='$from_time' and csta_datetime <'$to_time' ";
	$group="group by key_type ";
	$sql=$select.$from.$where.$group;
	if($DEBUG)echo "$sql<br>";
	$result=@mysqli_query($pubConn,$sql);
	$rows=@mysqli_fetch_array($result);
	
	for($i=0;$i<sizeof($oppsFieldNameInDB);$i++)
	{
		$$oppsFieldNameInDB[$i]=0;
	}

	if($rows)
	{
		do{
				$key_type=$rows[key_type]+0;
				if($key_type == 1)
				{
					for($i=0;$i<$oprTableFieldCount;$i++)
						$$oppsFieldNameInDB[$i]=$rows[$oppsFieldNameInDB[$i]]+0;
				}
				else if($key_type == 2)
				{
					for($i=$oprTableFieldCount;$i<($oprTableFieldCount+$imdxTableFieldCount);$i++)
						$$oppsFieldNameInDB[$i]=$rows[$oppsFieldNameInDB[$i]]+0;
				}
		}while($rows=mysqli_fetch_array($result));	
	}
	
	//get hourly data from database
	$select="select key_type,csta_datetime,";
	for($i=0;$i<sizeof($oppsFieldNameInDB);$i++)
	{
		$select.="{$oppsFieldNameInDB[$i]}";
		if($i != (sizeof($oppsFieldNameInDB)-1))
			$select.=",";
		else	
			$select.=" ";
	}
	$where="where csta_datetime >='$from_time' and csta_datetime <'$to_time' ";
	$sql=$select.$from.$where;
	if($DEBUG)echo "$sql<br>";
	$result=@mysqli_query($pubConn,$sql);
	$rows=@mysqli_fetch_array($result);
	
	for($i=0;$i<sizeof($oppsFieldNameInDB);$i++)
	{
		for($j=0;$j<24;$j++)
			$dataHourly[$i][$j]=0;
	}
	

	if($rows)
	{
		do{
				$key_type=$rows[key_type]+0;
				$hourstr=$rows[csta_datetime];
				$hour=substr($hourstr,11,2)+0;;
				for($i=0;$i<($oprTableFieldCount+$imdxTableFieldCount);$i++)
				{
					//20+26,23+27
					if($i == 26)
						$index=20;
					else if($i == 27)
						$index=23;
					else
						$index=$i;
					$dataHourly[$index][$hour]+=$rows[$oppsFieldNameInDB[$i]]+0;
				}
		}while($rows=mysqli_fetch_array($result));	
	}
	
	//print_r($dataHourly);
	

	//table title
	if($serviceFlag[$oppsServiceStatus] == "OPROpen" || $serviceFlag[$oppsServiceStatus] == "BothOpen")
	{
		echo "<center><b>";
		$sel_date_title=date("Y-m-d",mktime(0,0,0,date("m"),date("d")-$sel_date,date("Y")));
		echo "$oprTableTitle$sel_date_title<br>";
		echo "</b></center>";
	
		//opr table
		echo "<table border=\"1\" width=\"100%\" bordercolordark=\"#FFFFFF\" bordercolor=\"#808080\" cellspacing=\"0\">";
		echo "<tr>";
		echo "<td bgcolor=\"#E6E6E6\" width=10%>&nbsp;</td>";
			for($i=0;$i<sizeof($oprTableRowHead);$i++)
				echo "<td bgcolor=\"#E6E6E6\" width=15%>{$oprTableRowHead[$i]}</td>";
		echo "</tr>";
		//row-1
		echo "<tr>";
		echo "<td bgcolor=\"#E6E6E6\">{$oprTableColHead[0]}</td>";
		echo "<td>{$$oppsFieldNameInDB[0]}</td>";
		echo "<td>{$$oppsFieldNameInDB[2]}</td>";
		echo "<td>{$$oppsFieldNameInDB[4]}</td>";
		echo "<td>{$$oppsFieldNameInDB[8]}</td>";
		echo "<td>{$$oppsFieldNameInDB[10]}</td>";
		echo "<td>{$$oppsFieldNameInDB[12]}</td>";
		echo "</tr>";
		//row-2
		echo "<tr>";
		echo "<td bgcolor=\"#E6E6E6\">{$oprTableColHead[1]}</td>";
		echo "<td>{$$oppsFieldNameInDB[1]}</td>";
		echo "<td>{$$oppsFieldNameInDB[3]}</td>";
		echo "<td>{$$oppsFieldNameInDB[5]}</td>";
		echo "<td>{$$oppsFieldNameInDB[9]}</td>";
		echo "<td>{$$oppsFieldNameInDB[11]}</td>";
		echo "<td>{$$oppsFieldNameInDB[13]}</td>";
		echo "</tr>";
		echo "</table><p>";
	}
	
	if($serviceFlag[$oppsServiceStatus] == "IMDXOpen" || $serviceFlag[$oppsServiceStatus] == "BothOpen")
	{
		//imdx table
		echo "<p><center><b>";
	        echo "$imdxTableTitle$sel_date_title<br>";
	        echo "</b></center>";
		echo "<table border=\"1\" width=\"100%\" bordercolordark=\"#FFFFFF\" bordercolor=\"#808080\" cellspacing=\"0\">";
		echo "<tr>";
		//row-1
		echo "<td bgcolor=\"#E6E6E6\" rowspan=2 width=10%>{$imdxTableColHead[0]}</td>";
			for($i=0;$i<sizeof($imdxTableRowHeadA);$i++)
	    	echo "<td bgcolor=\"#E6E6E6\" width=15%>{$imdxTableRowHeadA[$i]}</td>";
		echo "</tr>";
		echo "<td>{$$oppsFieldNameInDB[14]}</td>";
		echo "<td>{$$oppsFieldNameInDB[15]}</td>";
		echo "<td>{$$oppsFieldNameInDB[16]}</td>";
		echo "<td>{$$oppsFieldNameInDB[28]}</td>";
		echo "<td>{$$oppsFieldNameInDB[18]}</td>";
		echo "<td>{$$oppsFieldNameInDB[19]}</td>";
		
		
		//row-2
		echo "<tr>";
		echo "<td bgcolor=\"#E6E6E6\" rowspan=2 width=10%>{$imdxTableColHead[1]}</td>";
		for($i=0;$i<sizeof($imdxTableRowHeadB);$i++)
	    	echo "<td bgcolor=\"#E6E6E6\" width=15%>{$imdxTableRowHeadB[$i]}</td>";
	  echo "</tr>";
	  $tmpdata=$$oppsFieldNameInDB[20]+$$oppsFieldNameInDB[26];
		echo "<td>$tmpdata</td>";
		$tmpdata=$$oppsFieldNameInDB[23]+$$oppsFieldNameInDB[27];
		echo "<td>$tmpdata</td>";
		echo "<td>{$$oppsFieldNameInDB[21]}</td>";
		echo "<td>{$$oppsFieldNameInDB[24]}</td>";
		echo "<td>{$$oppsFieldNameInDB[22]}</td>";
		echo "<td>{$$oppsFieldNameInDB[25]}</td>";
		echo "</tr>";
		echo "</table><p>";
	}
	//graphics
	echo "<p><b>{$type_label[$sel_type]} Chart</b><br>";
	
	$sizex=820;
	$sizey=300;
	$bgcolor=F8F8F8;
	$fgcolor=000000;
	
	$im = ImageCreate ($sizex, $sizey);
	
	$background_color = ImageColorAllocate ($im, 
				hexdec(substr($bgcolor, 0, 2)), 
				hexdec(substr($bgcolor, 2, 2)),
				hexdec(substr($bgcolor, 4, 2)));
	
	$text_color = ImageColorAllocate ($im, 
				hexdec(substr($fgcolor, 0, 2)), 
				hexdec(substr($fgcolor, 2, 2)),
				hexdec(substr($fgcolor, 4, 2)));
				
	//======get the block legend color======
	$black_color=ImageColorAllocate($im,06,0,0);
	$white_color=ImageColorAllocate($im,0xff,0xff,0xff);
	$color[0]=ImageColorAllocate($im,0x66,0xff,0x33);
	$color[1]=ImageColorAllocate($im,0x66,0xff,0xff);
	$color[2]=ImageColorAllocate($im,0,0x66,0x66);
	$color[3]=ImageColorAllocate($im,0x66,0,0xcc);
	$color[4]=ImageColorAllocate($im,0x66,0x33,0);
	$color[5]=ImageColorAllocate($im,0xcc,0,0x66);
	//======background========
	ImageFilledRectangle($im,0,0,$sizex,$sizey,ImageColorAllocate ($im, 198, 198, 198));
	ImageFilledRectangle($im,2,2,$sizex,$sizey,ImageColorAllocate ($im, 130, 130, 130));
	$pointArr=array(0,$sizey-1,3,$sizey-4,4,$sizey-1);
	Imagefilledpolygon($im, $pointArr, 3, ImageColorAllocate ($im, 130, 130, 130));
	$pointArr=array($sizex-1,0,$sizex-4,3,$sizex,4);
	Imagefilledpolygon($im, $pointArr, 3, ImageColorAllocate ($im, 130, 130, 130));
	ImageFilledRectangle($im,2,2,$sizex-3,$sizey-3,$background_color);
	//=======border========
	$xBgn=60;
	$yBgn=25;
	$xEnd=780;
	$yEnd=255;
	ImageLine($im, $xBgn, $yBgn, $xBgn, $yEnd, $text_color);
	ImageLine($im, $xBgn, $yBgn, $xEnd, $yBgn, $text_color);
	ImageLine($im, $xBgn, $yEnd, $xEnd, $yEnd, $text_color);
	ImageLine($im, $xEnd, $yBgn, $xEnd, $yEnd, $text_color);
	//=======get the biggest Y-scale value==============
	$maxYNum=4;
	for($i=0;$i<($oprTableFieldCount+$imdxTableFieldCount);$i++)
	{
		for($j=0;$j<24;$j++)
		{
			if(!isset($dataHourly[$i][$j]))
				$dataHourly[$i][$j]=0;
			
			if($maxYNum<$dataHourly[$i][$j])
				$maxYNum=$dataHourly[$i][$j];
				
			//echo "g-$i-h-$j:{$dataHourly[$i][$j]}<br>";	
		}
	}

	//======draw the vertical dash line======
	$tempi=0;
	for($i=0;$i<24;$i++){		
		ImageDashedLine($im, $xBgn + $i*30, $yBgn, $xBgn + $i*30, $yEnd, $text_color);
		if(($i*$slot)%24==0&&$i!=0)
			$tempi++;
		$xstr=$i."H";
		Imagestring($im, 2, $xBgn + $i*30 - 4, $yEnd+5, $xstr,  $text_color);
	}
	//=======draw the horizonal dash line======
	$style = array($black_color,$black_color,$black_color,$black_color,$black_color,$white_color,$white_color,$white_color,$white_color,$white_color);
	imagesetstyle($im, $style);
	$unitY=($yEnd-$yBgn)/10;
	$unitV=$maxYNum/10;
	for($i=0;$i<10;$i++){
		if($i!=0)
			imageline($im, $xBgn, $yBgn + $i*$unitY, $xEnd, $yBgn + $i*$unitY, IMG_COLOR_STYLED);
		$tempstr=round((10-$i)*$unitV);
		Imagestring($im, 2, $xBgn - 50, $yBgn + $i*$unitY - 5, $tempstr,  $text_color);	
	}
	//=======draw the block legend========
	if($serviceFlag[$oppsServiceStatus] == "OPROpen")
	{
		if($sel_type == 0)
		{
			$posX=60;
			$posY=280;
			imagefilledrectangle($im,$posX,$posY,$posX+10,$posY+10,$color[0]);
			imagestring($im,2,$posX+15,$posY,"Manual-Registration Success",$text_color);
			
			$posX=250;
			$posY=280;
			imagefilledrectangle($im,$posX,$posY,$posX+10,$posY+10,$color[1]);
			imagestring($im,2,$posX+15,$posY,"Manual-Registration Fail",$text_color);
			
			$posX=440;
			$posY=280;
			imagefilledrectangle($im,$posX,$posY,$posX+10,$posY+10,$color[2]);
			imagestring($im,2,$posX+15,$posY,"Auto-Registration Success",$text_color);
			
			$posX=630;
			$posY=280;
			imagefilledrectangle($im,$posX,$posY,$posX+10,$posY+10,$color[3]);
			imagestring($im,2,$posX+15,$posY,"Auto-Registration Fail",$text_color);
			$lineIndexArr=array(0=>"0",1=>"1",2=>"2",3=>"3");
		}
		else if($sel_type == 1)
		{
			$posX=60;
			$posY=280;
			imagefilledrectangle($im,$posX,$posY,$posX+10,$posY+10,$color[0]);
			imagestring($im,2,$posX+15,$posY,"OPR LU Success",$text_color);
			
			$posX=250;
			$posY=280;
			imagefilledrectangle($im,$posX,$posY,$posX+10,$posY+10,$color[1]);
			imagestring($im,2,$posX+15,$posY,"OPR LU Fail",$text_color);
			
			$posX=440;
			$posY=280;
			imagefilledrectangle($im,$posX,$posY,$posX+10,$posY+10,$color[2]);
			imagestring($im,2,$posX+15,$posY,"Non-OPR LU Success",$text_color);
			
			$posX=630;
			$posY=280;
			imagefilledrectangle($im,$posX,$posY,$posX+10,$posY+10,$color[3]);
			imagestring($im,2,$posX+15,$posY,"Non-OPR LU Fail",$text_color);
			
			$lineIndexArr=array(0=>"4",1=>"5",2=>"6",3=>"7");
		}
		else if($sel_type == 2)
		{
			$posX=60;
			$posY=280;
			imagefilledrectangle($im,$posX,$posY,$posX+10,$posY+10,$color[0]);
			imagestring($im,2,$posX+15,$posY,"OPR to Roam Success",$text_color);
			
			$posX=250;
			$posY=280;
			imagefilledrectangle($im,$posX,$posY,$posX+10,$posY+10,$color[1]);
			imagestring($im,2,$posX+15,$posY,"OPR to Roam Fail",$text_color);
			
			$posX=440;
			$posY=280;
			imagefilledrectangle($im,$posX,$posY,$posX+10,$posY+10,$color[2]);
			imagestring($im,2,$posX+15,$posY,"Roam to OPR Success",$text_color);
			
			$posX=630;
			$posY=280;
			imagefilledrectangle($im,$posX,$posY,$posX+10,$posY+10,$color[3]);
			imagestring($im,2,$posX+15,$posY,"Roam to OPR Fail",$text_color);
			
			$lineIndexArr=array(0=>"10",1=>"11",2=>"12",3=>"13");
		}
	}
	else if($serviceFlag[$oppsServiceStatus] == "IMDXOpen")
	{
		if($sel_type == 0)
		{
			$posX=60;
			$posY=280;
			imagefilledrectangle($im,$posX,$posY,$posX+10,$posY+10,$color[0]);
			imagestring($im,2,$posX+15,$posY,$imdxTableRowHeadA[0],$text_color);
			
			$posX=190;
			$posY=280;
			imagefilledrectangle($im,$posX,$posY,$posX+10,$posY+10,$color[1]);
			imagestring($im,2,$posX+15,$posY,$imdxTableRowHeadA[1],$text_color);
			
			$posX=320;
			$posY=280;
			imagefilledrectangle($im,$posX,$posY,$posX+10,$posY+10,$color[2]);
			imagestring($im,2,$posX+15,$posY,$imdxTableRowHeadA[2],$text_color);
			
			$posX=450;
			$posY=280;
			imagefilledrectangle($im,$posX,$posY,$posX+10,$posY+10,$color[3]);
			imagestring($im,2,$posX+15,$posY,$imdxTableRowHeadA[3],$text_color);
			
			$posX=580;
			$posY=280;
			imagefilledrectangle($im,$posX,$posY,$posX+10,$posY+10,$color[4]);
			imagestring($im,2,$posX+15,$posY,$imdxTableRowHeadA[4],$text_color);
			
			$posX=710;
			$posY=280;
			imagefilledrectangle($im,$posX,$posY,$posX+10,$posY+10,$color[5]);
			imagestring($im,2,$posX+15,$posY,$imdxTableRowHeadA[5],$text_color);
		
			$lineIndexArr=array(0=>"14",1=>"15",2=>"16",3=>"28",4=>"18",5=>"19");
		}
		else if($sel_type == 1)
		{
			$posX=60;
			$posY=280;
			imagefilledrectangle($im,$posX,$posY,$posX+10,$posY+10,$color[0]);
			imagestring($im,2,$posX+15,$posY,$imdxTableRowHeadB[0],$text_color);
			
			$posX=190;
			$posY=280;
			imagefilledrectangle($im,$posX,$posY,$posX+10,$posY+10,$color[1]);
			imagestring($im,2,$posX+15,$posY,$imdxTableRowHeadB[1],$text_color);
			
			$posX=320;
			$posY=280;
			imagefilledrectangle($im,$posX,$posY,$posX+10,$posY+10,$color[2]);
			imagestring($im,2,$posX+15,$posY,$imdxTableRowHeadB[2],$text_color);
			
			$posX=450;
			$posY=280;
			imagefilledrectangle($im,$posX,$posY,$posX+10,$posY+10,$color[3]);
			imagestring($im,2,$posX+15,$posY,$imdxTableRowHeadB[3],$text_color);
			
			$posX=580;
			$posY=280;
			imagefilledrectangle($im,$posX,$posY,$posX+10,$posY+10,$color[4]);
			imagestring($im,2,$posX+15,$posY,$imdxTableRowHeadB[4],$text_color);
			
			$posX=710;
			$posY=280;
			imagefilledrectangle($im,$posX,$posY,$posX+10,$posY+10,$color[5]);
			imagestring($im,2,$posX+15,$posY,$imdxTableRowHeadB[5],$text_color);
		
			$lineIndexArr=array(0=>"20",1=>"23",2=>"21",3=>"24",4=>"22",5=>"25");
		}
	}
	else if($serviceFlag[$oppsServiceStatus] == "BothOpen")
	{
		if($sel_type == 0)
		{
			$posX=60;
			$posY=280;
			imagefilledrectangle($im,$posX,$posY,$posX+10,$posY+10,$color[0]);
			imagestring($im,2,$posX+15,$posY,"Manual-Registration Success",$text_color);
			
			$posX=250;
			$posY=280;
			imagefilledrectangle($im,$posX,$posY,$posX+10,$posY+10,$color[1]);
			imagestring($im,2,$posX+15,$posY,"Manual-Registration Fail",$text_color);
			
			$posX=440;
			$posY=280;
			imagefilledrectangle($im,$posX,$posY,$posX+10,$posY+10,$color[2]);
			imagestring($im,2,$posX+15,$posY,"Auto-Registration Success",$text_color);
			
			$posX=630;
			$posY=280;
			imagefilledrectangle($im,$posX,$posY,$posX+10,$posY+10,$color[3]);
			imagestring($im,2,$posX+15,$posY,"Auto-Registration Fail",$text_color);
			
			$lineIndexArr=array(0=>"0",1=>"1",2=>"2",3=>"3");
		}
		else if($sel_type == 1)
		{
			$posX=60;
			$posY=280;
			imagefilledrectangle($im,$posX,$posY,$posX+10,$posY+10,$color[0]);
			imagestring($im,2,$posX+15,$posY,"OPR LU Success",$text_color);
			
			$posX=250;
			$posY=280;
			imagefilledrectangle($im,$posX,$posY,$posX+10,$posY+10,$color[1]);
			imagestring($im,2,$posX+15,$posY,"OPR LU Fail",$text_color);
			
			$posX=440;
			$posY=280;
			imagefilledrectangle($im,$posX,$posY,$posX+10,$posY+10,$color[2]);
			imagestring($im,2,$posX+15,$posY,"Non-OPR LU Success",$text_color);
			
			$posX=630;
			$posY=280;
			imagefilledrectangle($im,$posX,$posY,$posX+10,$posY+10,$color[3]);
			imagestring($im,2,$posX+15,$posY,"Non-OPR LU Fail",$text_color);
			
			$lineIndexArr=array(0=>"4",1=>"5",2=>"6",3=>"7");
		}
		else if($sel_type == 2)
		{
			$posX=60;
			$posY=280;
			imagefilledrectangle($im,$posX,$posY,$posX+10,$posY+10,$color[0]);
			imagestring($im,2,$posX+15,$posY,"OPR to Roam Success",$text_color);
			
			$posX=250;
			$posY=280;
			imagefilledrectangle($im,$posX,$posY,$posX+10,$posY+10,$color[1]);
			imagestring($im,2,$posX+15,$posY,"OPR to Roam Fail",$text_color);
			
			$posX=440;
			$posY=280;
			imagefilledrectangle($im,$posX,$posY,$posX+10,$posY+10,$color[2]);
			imagestring($im,2,$posX+15,$posY,"Roam to OPR Success",$text_color);
			
			$posX=630;
			$posY=280;
			imagefilledrectangle($im,$posX,$posY,$posX+10,$posY+10,$color[3]);
			imagestring($im,2,$posX+15,$posY,"Roam to OPR Fail",$text_color);
			
			$lineIndexArr=array(0=>"10",1=>"11",2=>"12",3=>"13");
		}
		else if($sel_type == 3)
		{
			$posX=60;
			$posY=280;
			imagefilledrectangle($im,$posX,$posY,$posX+10,$posY+10,$color[0]);
			imagestring($im,2,$posX+15,$posY,$imdxTableRowHeadA[0],$text_color);
			
			$posX=190;
			$posY=280;
			imagefilledrectangle($im,$posX,$posY,$posX+10,$posY+10,$color[1]);
			imagestring($im,2,$posX+15,$posY,$imdxTableRowHeadA[1],$text_color);
			
			$posX=320;
			$posY=280;
			imagefilledrectangle($im,$posX,$posY,$posX+10,$posY+10,$color[2]);
			imagestring($im,2,$posX+15,$posY,$imdxTableRowHeadA[2],$text_color);
			
			$posX=450;
			$posY=280;
			imagefilledrectangle($im,$posX,$posY,$posX+10,$posY+10,$color[3]);
			imagestring($im,2,$posX+15,$posY,$imdxTableRowHeadA[3],$text_color);
			
			$posX=580;
			$posY=280;
			imagefilledrectangle($im,$posX,$posY,$posX+10,$posY+10,$color[4]);
			imagestring($im,2,$posX+15,$posY,$imdxTableRowHeadA[4],$text_color);
			
			$posX=710;
			$posY=280;
			imagefilledrectangle($im,$posX,$posY,$posX+10,$posY+10,$color[5]);
			imagestring($im,2,$posX+15,$posY,$imdxTableRowHeadA[5],$text_color);
			
			$lineIndexArr=array(0=>"14",1=>"15",2=>"16",3=>"28",4=>"18",5=>"19");
		}
		else if($sel_type == 4)
		{
			$posX=60;
			$posY=280;
			imagefilledrectangle($im,$posX,$posY,$posX+10,$posY+10,$color[0]);
			imagestring($im,2,$posX+15,$posY,$imdxTableRowHeadB[0],$text_color);
			
			$posX=190;
			$posY=280;
			imagefilledrectangle($im,$posX,$posY,$posX+10,$posY+10,$color[1]);
			imagestring($im,2,$posX+15,$posY,$imdxTableRowHeadB[1],$text_color);
			
			$posX=320;
			$posY=280;
			imagefilledrectangle($im,$posX,$posY,$posX+10,$posY+10,$color[2]);
			imagestring($im,2,$posX+15,$posY,$imdxTableRowHeadB[2],$text_color);
			
			$posX=450;
			$posY=280;
			imagefilledrectangle($im,$posX,$posY,$posX+10,$posY+10,$color[3]);
			imagestring($im,2,$posX+15,$posY,$imdxTableRowHeadB[3],$text_color);
			
			$posX=580;
			$posY=280;
			imagefilledrectangle($im,$posX,$posY,$posX+10,$posY+10,$color[4]);
			imagestring($im,2,$posX+15,$posY,$imdxTableRowHeadB[4],$text_color);
			
			$posX=710;
			$posY=280;
			imagefilledrectangle($im,$posX,$posY,$posX+10,$posY+10,$color[5]);
			imagestring($im,2,$posX+15,$posY,$imdxTableRowHeadB[5],$text_color);
			
			$lineIndexArr=array(0=>"20",1=>"23",2=>"21",3=>"24",4=>"22",5=>"25");
		}
	}
	else
		exit();
		
	//draw the line
	//imageline
	$unitHori=($xEnd-$xBgn)/24;
	$imgHeight=$yEnd-$yBgn;
	for($i=0;$i<sizeof($lineIndexArr);$i++)
	{
		for($j=0;$j<24-1;$j++)
		{
			$pX1=$xBgn+$j*$unitHori;
			$pX2=$xBgn+($j+1)*$unitHori;
			$pY1=$yBgn+(1-$dataHourly[$lineIndexArr[$i]][$j]/$maxYNum)*$imgHeight;
			$pY2=$yBgn+(1-$dataHourly[$lineIndexArr[$i]][$j+1]/$maxYNum)*$imgHeight;
			imageline($im,$pX1,$pY1,$pX2,$pY2,$color[$i]);
		}
	}
	
	//======draw the graphics========
	//-----输出图形文件，请勿修改
	//delete *.png
	$handle=opendir('.');
	while($file=readdir($handle)){
		$retval="";
		$pt=strrpos($file,".");
		if($pt) $retval=substr($file,$pt+1,strlen($file)-$pt);
		if($retval=='png') unlink($file);
	}
	$tt=time()-5500;
	$filename="opps_".$tt.".png";
	if(1){
		ImagePng ($im,"$filename");  
		ImageDestroy($im);	
	}
	//-----显示图片
	echo "<img src=\"$filename\"></img>";

adjust_content_tail("down");
?>	
