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

$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
{
	$table_title="iRLS 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 align=\"center\" width=\"9%\">Type</td>";
	echo "<td align=\"center\" width=\"13%\">Attempt</td>";
	echo "<td align=\"center\" width=\"13%\">Success</td>";
	echo "<td align=\"center\" width=\"13%\">Operation Fail</td>";
	echo "<td align=\"center\" width=\"13%\">Create<br>Channel<br>Fail</td>";
	echo "<td align=\"center\" width=\"13%\">Connect<br>Channel<br>Fail</td>";
	echo "<td align=\"center\" width=\"13%\">Retrieve Fail</td>";
	echo "<td align=\"center\" width=\"13%\">Notification<br>Request<br>Fail</td>";
	echo "</tr>";
	
	echo "<tr>";
	echo "<td align=\"center\">MO</td>";
	$value=$cstaData[0][1][Attempt]+0;
	echo "<td>$value</td>";
	
	$value=$cstaData[0][1][Success]+0;
	echo "<td>$value</td>";
	
	$value=$cstaData[0][1][oper_fail]+0;
	echo "<td>$value</td>";
	
	$value=$cstaData[0][1][cre_vim_fail]+0;
	echo "<td>$value</td>";
	
	$value=$cstaData[0][1][conn_local_fail]+0;
	echo "<td>$value</td>";
	
	//$value=$cstaData[0][1][conn_vim_fail]+0;
	//echo "<td>$value</td>";
	
	$value=$cstaData[0][1][excep_retr_fail]+0;
	echo "<td>$value</td>";
	
	$value=$cstaData[0][1][noti_req_fail]+0;
	echo "<td>--</td>";
  echo "</tr>";
  
  echo "<tr>";
	echo "<td align=\"center\">MT</td>";
	$value=$cstaData[0][2][Attempt]+0;
	echo "<td>$value</td>";
	
	$value=$cstaData[0][2][Success]+0;
	echo "<td>$value</td>";
	
	$value=$cstaData[0][2][oper_fail]+0;
	echo "<td>$value</td>";
	
	$value=$cstaData[0][2][cre_vim_fail]+0;
	echo "<td>$value</td>";
	
	$value=$cstaData[0][2][conn_local_fail]+0;
	echo "<td>$value</td>";
	
	//$value=$cstaData[0][2][conn_vim_fail]+0;
	//echo "<td>$value</td>";
	
	$value=$cstaData[0][2][excep_retr_fail]+0;
	echo "<td>$value</td>";
	
	$value=$cstaData[0][2][noti_req_fail]+0;
	echo "<td>--</td>";
  echo "</tr>";
  
  echo "<tr>";
	echo "<td align=\"center\">VIM</td>";
	$value=$cstaData[0][3][Attempt]+0;
	echo "<td>$value</td>";
	
	$value=$cstaData[0][3][Success]+0;
	echo "<td>$value</td>";
	
	$value=$cstaData[0][3][oper_fail]+0;
	echo "<td>$value</td>";
	
	$value=$cstaData[0][3][cre_vim_fail]+0;
	echo "<td>$value</td>";
	
	$value=$cstaData[0][3][conn_vim_fail]+0;
	echo "<td>$value</td>";
	
	$value=$cstaData[0][3][excep_retr_fail]+0;
	echo "<td>$value</td>";
	
	$value=$cstaData[0][3][noti_req_fail]+0;
	echo "<td>$value</td>";
  echo "</tr>";
  
  echo "</table>";
}

//Graphics-1
{
	echo "<br><b>Statistic Chart</b><br>";
	
	unset($tmpData);
	$type_index=0;
	$column_index=0;
	$block_index=0;
	
	//Attempt
	$tmpData[$type_index][$column_index][$block_index]=$cstaData[0][1][Attempt]+0;
	$block_index++;
	$tmpData[$type_index][$column_index][$block_index]=$cstaData[0][2][Attempt]+0;
	$block_index=0;
	$column_index++;
	$tmpData[$type_index][$column_index][$block_index]=$cstaData[0][3][Attempt]+0;

	
	//Success
	$type_index++;
	$column_index=0;
	$block_index=0;
	$tmpData[$type_index][$column_index][$block_index]=$cstaData[0][1][Success]+0;
	$block_index++;
	$tmpData[$type_index][$column_index][$block_index]=$cstaData[0][2][Success]+0;
	$block_index=0;
	$column_index++;
	$tmpData[$type_index][$column_index][$block_index]=$cstaData[0][3][Success]+0;
	
	
	//Operation Fail
	$type_index++;
	$column_index=0;
	$block_index=0;
	$tmpData[$type_index][$column_index][$block_index]=$cstaData[0][1][oper_fail]+0;
	$block_index++;
	$tmpData[$type_index][$column_index][$block_index]=$cstaData[0][2][oper_fail]+0;
	$block_index=0;
	$column_index++;
	$tmpData[$type_index][$column_index][$block_index]=$cstaData[0][3][oper_fail]+0;

	//Create Vritual/VIM Fail
	$type_index++;
	$column_index=0;
	$block_index=0;
	$tmpData[$type_index][$column_index][$block_index]=$cstaData[0][1][cre_vim_fail]+0;
	$block_index++;
	$tmpData[$type_index][$column_index][$block_index]=$cstaData[0][2][cre_vim_fail]+0;
	$block_index=0;
	$column_index++;
	$tmpData[$type_index][$column_index][$block_index]=$cstaData[0][3][cre_vim_fail]+0;

	//Connect Local/VIM Fail
	$type_index++;
	$column_index=0;
	$block_index=0;
	$tmpData[$type_index][$column_index][$block_index]=$cstaData[0][1][conn_local_fail]+0;
	$block_index++;
	$tmpData[$type_index][$column_index][$block_index]=$cstaData[0][2][conn_local_fail]+0;
	$block_index=0;
	$column_index++;
	$tmpData[$type_index][$column_index][$block_index]=$cstaData[0][3][conn_vim_fail]+0;

	//Retrieve Fail
	$type_index++;
	$column_index=0;
	$block_index=0;
	$tmpData[$type_index][$column_index][$block_index]=$cstaData[0][1][excep_retr_fail]+0;
	$block_index++;
	$tmpData[$type_index][$column_index][$block_index]=$cstaData[0][2][excep_retr_fail]+0;
	$block_index=0;
	$column_index++;
	$tmpData[$type_index][$column_index][$block_index]=$cstaData[0][3][excep_retr_fail]+0;

	//Notification Request Fail
	$type_index++;
	$column_index=0;
	$block_index=0;
	$tmpData[$type_index][$column_index][$block_index]=0;
	$block_index++;
	$tmpData[$type_index][$column_index][$block_index]=0;
	$block_index=0;
	$column_index++;
	$tmpData[$type_index][$column_index][$block_index]=$cstaData[0][3][noti_req_fail]+0;

	if(0)
	{
		echo "<pre>";
		print_r($tmpData);
		echo "</pre>";
	}
  
  $tmpColor[]=array(0xaa,0x44,0x22);
  $tmpColor[]=array(0x22,0xbb,0x22);
  $tmpColor[]=array(0x22,0x22,0xbb);
  
	$image=CreateImage(840,420);
	$image=DrawMuliStackPercentHistogram($image,$tmpData,$tmpColor,$pointInterval,2,array(30,20),array(780,340),1,0);

	
	
	$remarkBlock=array(
		"MO",
		"MT",
		"VIM"
	);
	$pointArr=array(
		array(145,400),
		array(400,400),
		array(680,400)
	);
	$image=AddRemarkToImage($image,$pointArr,$remarkBlock,$tmpColor,0,2);
	
	unset($remarkBlock);
	unset($pointArr);
	$remarkBlock=array(
		"Attempt",
		"Success",
		"Operation","Fail",
		"Create","Channel","Fail",
		"Connect","Channel","Fail",
		"Retrieve","Fail",
		"Notification","Request","Fail"
	);
	$pointArr=array(
		array(90,370),
		array(192,370),
		array(288,365),array(304,375),
		array(405,360),array(402,370),array(411,380),
		array(504,360),array(505,370),array(512,380),
		array(607,365),array(615,375),
		array(700,360),array(712,370),array(720,380)
	);
	$image=AddRemarkToImage($image,$pointArr,$remarkBlock,0,0,2);
	
	DrawImage($image);
}
?>
