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

$slot=$sel_date_from-$sel_date_to+1;
$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")));

$cstaData=GetCstaDataByDay($cstaConf,$startTime,$endTime,"detail");

if(0)
{
	echo "<pre>";
	print_r($cstaData);
	echo "</pre>";
}

//Table-1
{
	unset($lu_data);
	unset($callmo_data);
	unset($callmt_data);
	unset($smmo_data);
	unset($smmt_data);

	for($i=1;$i<=256;$i++)
	{
		$lu_data[Attempt]+=$cstaData[0][1][$i][Attempt]+0;
		$lu_data[Success]+=$cstaData[0][1][$i][Success]+0;
		$lu_data[Duration]+=$cstaData[0][1][$i][Duration]+0;
		$lu_data[Normal]+=$cstaData[0][1][$i][lu_normal]+0;
		$lu_data[NoResource]+=$cstaData[0][1][$i][lu_res_not_ok]+0;
		$lu_data[NoService]+=$cstaData[0][1][$i][lu_ser_not_ok]+0;
		$lu_data[InvalidService]+=$cstaData[0][1][$i][lu_ser_no_imp]+0;
		$lu_data[InvalidMessage]+=$cstaData[0][1][$i][lu_msg_error]+0;
		$lu_data[SignalError]+=$cstaData[0][1][$i][lu_pro_error]+0;
		
		$callmo_data[Attempt]+=$cstaData[0][2][$i][Attempt]+0;
		$callmo_data[Success]+=$cstaData[0][2][$i][Success]+0;
		$callmo_data[Duration]+=$cstaData[0][2][$i][Duration]+0;
		$callmo_data[Normal]+=$cstaData[0][2][$i][cc_normal]+0;
		$callmo_data[CallDeny]+=$cstaData[0][2][$i][cc_call_deny]+0;
		$callmo_data[NetBusy]+=$cstaData[0][2][$i][cc_net_busy]+0;
		$callmo_data[CallerClear]+=$cstaData[0][2][$i][cc_caller_clear]+0;
		$callmo_data[SubBusy]+=$cstaData[0][2][$i][cc_sub_busy]+0;
		$callmo_data[NoAnswer]+=$cstaData[0][2][$i][cc_no_answer]+0;
		$callmo_data[SignalError]+=$cstaData[0][2][$i][cc_sig_error]+0;
		
		$callmt_data[Attempt]+=$cstaData[0][3][$i][Attempt]+0;
		$callmt_data[Success]+=$cstaData[0][3][$i][Success]+0;
		$callmt_data[Duration]+=$cstaData[0][3][$i][Duration]+0;
		$callmt_data[Normal]+=$cstaData[0][3][$i][cc_normal]+0;
		$callmt_data[CallDeny]+=$cstaData[0][3][$i][cc_call_deny]+0;
		$callmt_data[NetBusy]+=$cstaData[0][3][$i][cc_net_busy]+0;
		$callmt_data[CallerClear]+=$cstaData[0][3][$i][cc_caller_clear]+0;
		$callmt_data[SubBusy]+=$cstaData[0][3][$i][cc_sub_busy]+0;
		$callmt_data[NoAnswer]+=$cstaData[0][3][$i][cc_no_answer]+0;
		$callmt_data[SignalError]+=$cstaData[0][3][$i][cc_sig_error]+0;
		
		$smmo_data[Attempt]+=$cstaData[0][4][$i][Attempt]+0;
		$smmo_data[Success]+=$cstaData[0][4][$i][Success]+0;
		$smmo_data[Duration]+=$cstaData[0][4][$i][Duration]+0;
		$smmo_data[Normal]+=$cstaData[0][4][$i][sm_normal]+0;
		$smmo_data[SubError]+=$cstaData[0][4][$i][sm_error_sub]+0;
		$smmo_data[NoService]+=$cstaData[0][4][$i][sm_ser_not_ok]+0;
		$smmo_data[NetBusy]+=$cstaData[0][4][$i][sm_net_busy]+0;
		$smmo_data[MessageError]+=$cstaData[0][4][$i][sm_msg_error]+0;
		$smmo_data[SignalError]+=$cstaData[0][4][$i][sm_pro_error]+0;
		$smmo_data[NoResource]+=$cstaData[0][4][$i][sm_res_not_ok]+0;
       
		$smmt_data[Attempt]+=$cstaData[0][5][$i][Attempt]+0;
		$smmt_data[Success]+=$cstaData[0][5][$i][Success]+0;
		$smmt_data[Duration]+=$cstaData[0][5][$i][Duration]+0;
		$smmt_data[Normal]+=$cstaData[0][5][$i][sm_normal]+0;
		$smmt_data[SubError]+=$cstaData[0][5][$i][sm_error_sub]+0;
		$smmt_data[NoService]+=$cstaData[0][5][$i][sm_ser_not_ok]+0;
		$smmt_data[NetBusy]+=$cstaData[0][5][$i][sm_net_busy]+0;
		$smmt_data[MessageError]+=$cstaData[0][5][$i][sm_msg_error]+0;
		$smmt_data[SignalError]+=$cstaData[0][5][$i][sm_pro_error]+0;
		$smmt_data[NoResource]+=$cstaData[0][5][$i][sm_res_not_ok]+0;
	}

	$table_title="Service 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=\"8%\">Type</td>";
		echo "<td align=\"center\" width=\"8%\">Attempt</td>";
		echo "<td align=\"center\" width=\"8%\">Success</td>";
		echo "<td align=\"center\" width=\"8%\">Normal</td>";
		echo "<td align=\"center\" width=\"8%\">No Resource</td>";
		echo "<td align=\"center\" width=\"8%\">No Service</td>";
		echo "<td align=\"center\" width=\"8%\">Invalid Service</td>";
		echo "<td align=\"center\" width=\"18%\" colspan=\"2\">Invalid Message</td>";
		echo "<td align=\"center\" width=\"10%\">Signal Error</td>";
		echo "<td align=\"center\" width=\"8%\">Duration</td>";
		echo "<td align=\"center\" width=\"15%\">Average Duration</td>";
	echo "</tr>";	
	
	echo "<tr>";
	echo "<td align=\"center\">";
	echo "<a href=# onclick=\"javascript:toHourPage('$sysTypeNo','$show_type','$page_id','$sel_date_from','$sel_date_to','1','-1');\">";
	echo "LU";
	echo "</a>";
	echo "</td>";
	
	$value=$lu_data[Attempt];
	echo "<td align=\"center\">$value</td>";
	
	$value=$lu_data[Success];
	$percent=GetPercent($lu_data[Success],$lu_data[Attempt]);
	echo "<td align=\"center\">";
	echo "$value<br>";
	echo "$percent";
	echo "</td>";
	
	$value=$lu_data[Normal];
	$percent=GetPercent($lu_data[Normal],$lu_data[Attempt]);
	echo "<td align=\"center\">";
	echo "$value<br>";
	echo "$percent";
	echo "</td>";
	
	$value=$lu_data[NoResource];
	$percent=GetPercent($lu_data[NoResource],$lu_data[Attempt]);
	echo "<td align=\"center\">";
	echo "$value<br>";
	echo "$percent";
	echo "</td>";
	
	$value=$lu_data[NoService];
	$percent=GetPercent($lu_data[NoService],$lu_data[Attempt]);
	echo "<td align=\"center\">";
	echo "$value<br>";
	echo "$percent";
	echo "</td>";
	
	$value=$lu_data[InvalidService];
	$percent=GetPercent($lu_data[InvalidService],$lu_data[Attempt]);
	echo "<td align=\"center\">";
	echo "$value<br>";
	echo "$percent";
	echo "</td>";
	
	$value=$lu_data[InvalidMessage];
	$percent=GetPercent($lu_data[InvalidMessage],$lu_data[Attempt]);
	echo "<td align=\"center\" colspan=\"2\">";
	echo "$value<br>";
	echo "$percent";
	echo "</td>";
	
	$value=$lu_data[SignalError];
	$percent=GetPercent($lu_data[SignalError],$lu_data[Attempt]);
	echo "<td align=\"center\">";
	echo "$value<br>";
	echo "$percent";
	echo "</td>";
	
	$value=$lu_data[Duration];
	$timestamp=SecondToTimeStamp($value);
	echo "<td align=\"center\">";
	//echo "$value<br>";
	echo "--<br>";
	echo "$timestamp";
	echo "</td>";
	
	if($lu_data[Success] > 0)
		$value=ceil($lu_data[Duration]/$lu_data[Success]);
	else
		$value=0;
	echo "<td align=\"center\">";
	//echo "$value";
	echo "--<br>";
	echo "</td>";
	echo "</tr>";
	
	echo "<tr bgcolor=\"#E6E6E6\">";
		echo "<td align=\"center\" width=\"8%\">&nbsp;</td>";
		echo "<td align=\"center\" width=\"8%\">Attempt</td>";
		echo "<td align=\"center\" width=\"8%\">Success</td>";
		echo "<td align=\"center\" width=\"8%\">Normal</td>";
		echo "<td align=\"center\" width=\"8%\">Call Deny</td>";
		echo "<td align=\"center\" width=\"8%\">Net Busy</td>";
		echo "<td align=\"center\" width=\"8%\">Caller Clear</td>";
		echo "<td align=\"center\" width=\"8%\">Sub Busy</td>";
		echo "<td align=\"center\" width=\"10%\">No Answer</td>";
		echo "<td align=\"center\" width=\"10%\">Signal Error</td>";
		echo "<td align=\"center\" width=\"8%\">Duration</td>";
		echo "<td align=\"center\" width=\"15%\">Average Duration</td>";
	echo "</tr>";	
	
	unset($tmpLabel);
	unset($tmpdata);
	$tmpLabel=array("Call MO","Call MT");
	$tmpdata[0]=$callmo_data;
	$tmpdata[1]=$callmt_data;
	for($i=0;$i<2;$i++)
	{
		echo "<tr>";
		echo "<td align=\"center\">";
		$tmp=$i+2;
		echo "<a href=# onclick=\"javascript:toHourPage('$sysTypeNo','$show_type','$page_id','$sel_date_from','$sel_date_to','$tmp','-1');\">";
		echo "{$tmpLabel[$i]}";
		echo "</td>";
		$value=$tmpdata[$i][Attempt];
		echo "<td align=\"center\">$value</td>";
	
		$value=$tmpdata[$i][Success];
		$percent=GetPercent($tmpdata[$i][Success],$tmpdata[$i][Attempt]);
		echo "<td align=\"center\">";
		echo "$value<br>";
		echo "$percent";
		echo "</td>";
	
		$value=$tmpdata[$i][Normal];
		$percent=GetPercent($tmpdata[$i][Normal],$tmpdata[$i][Attempt]);
		echo "<td align=\"center\">";
		echo "$value<br>";
		echo "$percent";
		echo "</td>";
	
		$value=$tmpdata[$i][CallDeny];
		$percent=GetPercent($tmpdata[$i][CallDeny],$tmpdata[$i][Attempt]);
		echo "<td align=\"center\">";
		echo "$value<br>";
		echo "$percent";
		echo "</td>";
	
		$value=$tmpdata[$i][NetBusy];
		$percent=GetPercent($tmpdata[$i][NetBusy],$tmpdata[$i][Attempt]);
		echo "<td align=\"center\">";
		echo "$value<br>";
		echo "$percent";
		echo "</td>";
	
		$value=$tmpdata[$i][CallerClear];
		$percent=GetPercent($tmpdata[$i][CallerClear],$tmpdata[$i][Attempt]);
		echo "<td align=\"center\">";
		echo "$value<br>";
		echo "$percent";
		echo "</td>";
	
		$value=$tmpdata[$i][SubBusy];
		$percent=GetPercent($tmpdata[$i][SubBusy],$tmpdata[$i][Attempt]);
		echo "<td align=\"center\">";
		echo "$value<br>";
		echo "$percent";
		echo "</td>";
	
		$value=$tmpdata[$i][NoAnswer];
		$percent=GetPercent($tmpdata[$i][NoAnswer],$tmpdata[$i][Attempt]);
		echo "<td align=\"center\">";
		echo "$value<br>";
		echo "$percent";
		echo "</td>";
	
		$value=$tmpdata[$i][SignalError];
		$percent=GetPercent($tmpdata[$i][SignalError],$tmpdata[$i][Attempt]);
		echo "<td align=\"center\">";
		echo "$value<br>";
		echo "$percent";
		echo "</td>";
	
		$value=$tmpdata[$i][Duration];
		$timestamp=SecondToTimeStamp($value);
		echo "<td align=\"center\">";
		echo "$value<br>";
		echo "$timestamp";
		echo "</td>";
		
		if($tmpdata[$i][Success] > 0)
			$value=ceil($tmpdata[$i][Duration]/$tmpdata[$i][Success]);
		else
			$value=0;
		echo "<td align=\"center\">";
		echo "$value";
		echo "</td>";
		echo "</tr>";
	}
	
	echo "<tr bgcolor=\"#E6E6E6\">";
		echo "<td align=\"center\" width=\"8%\">&nbsp;</td>";
		echo "<td align=\"center\" width=\"8%\">Attempt</td>";
		echo "<td align=\"center\" width=\"8%\">Success</td>";
		echo "<td align=\"center\" width=\"8%\">Normal</td>";
		echo "<td align=\"center\" width=\"8%\">Sub Error</td>";
		echo "<td align=\"center\" width=\"8%\">No Service</td>";
		echo "<td align=\"center\" width=\"8%\">Net Busy</td>";
		echo "<td align=\"center\" width=\"8%\">Message Error</td>";
		echo "<td align=\"center\" width=\"10%\">Signal Error</td>";
		echo "<td align=\"center\" width=\"10%\">No Resource</td>";
		echo "<td align=\"center\" width=\"8%\">Duration</td>";
		echo "<td align=\"center\" width=\"15%\">Average Duration</td>";
	echo "</tr>";	
	
	unset($tmpLabel);
	unset($tmpdata);
	$tmpLabel=array("SM MO","SM MT");
	$tmpdata[0]=$smmo_data;
	$tmpdata[1]=$smmt_data;
	for($i=0;$i<2;$i++)
	{
		echo "<tr>";
		echo "<td align=\"center\">";
		$tmp=$i+4;
		echo "<a href=# onclick=\"javascript:toHourPage('$sysTypeNo','$show_type','$page_id','$sel_date_from','$sel_date_to','$tmp','-1');\">";
		echo "{$tmpLabel[$i]}";
		echo "</a>";
		echo "</td>";
		$value=$tmpdata[$i][Attempt];
		echo "<td align=\"center\">$value</td>";
	
		$value=$tmpdata[$i][Success];
		$percent=GetPercent($tmpdata[$i][Success],$tmpdata[$i][Attempt]);
		echo "<td align=\"center\">";
		echo "$value<br>";
		echo "$percent";
		echo "</td>";
	
		$value=$tmpdata[$i][Normal];
		$percent=GetPercent($tmpdata[$i][Normal],$tmpdata[$i][Attempt]);
		echo "<td align=\"center\">";
		echo "$value<br>";
		echo "$percent";
		echo "</td>";
	
		$value=$tmpdata[$i][SubError];
		$percent=GetPercent($tmpdata[$i][SubError],$tmpdata[$i][Attempt]);
		echo "<td align=\"center\">";
		echo "$value<br>";
		echo "$percent";
		echo "</td>";
	
		$value=$tmpdata[$i][NoService];
		$percent=GetPercent($tmpdata[$i][NoService],$tmpdata[$i][Attempt]);
		echo "<td align=\"center\">";
		echo "$value<br>";
		echo "$percent";
		echo "</td>";
	
		$value=$tmpdata[$i][NetBusy];
		$percent=GetPercent($tmpdata[$i][NetBusy],$tmpdata[$i][Attempt]);
		echo "<td align=\"center\">";
		echo "$value<br>";
		echo "$percent";
		echo "</td>";
	
		$value=$tmpdata[$i][MessageError];
		$percent=GetPercent($tmpdata[$i][MessageError],$tmpdata[$i][Attempt]);
		echo "<td align=\"center\">";
		echo "$value<br>";
		echo "$percent";
		echo "</td>";
	
		$value=$tmpdata[$i][SignalError];
		$percent=GetPercent($tmpdata[$i][SignalError],$tmpdata[$i][Attempt]);
		echo "<td align=\"center\">";
		echo "$value<br>";
		echo "$percent";
		echo "</td>";
	
		$value=$tmpdata[$i][NoResource];
		$percent=GetPercent($tmpdata[$i][NoResource],$tmpdata[$i][Attempt]);
		echo "<td align=\"center\">";
		echo "$value<br>";
		echo "$percent";
		echo "</td>";
	
		$value=$tmpdata[$i][Duration];
		$timestamp=SecondToTimeStamp($value);
		echo "<td align=\"center\">";
		//echo "$value<br>";
		//echo "$timestamp";
		echo "--<br>";
		echo "</td>";
	
		if($tmpdata[$i][Success] > 0)
			$value=ceil($tmpdata[$i][Duration]/$tmpdata[$i][Success]);
		else
			$value=0;
		echo "<td align=\"center\">";
		//echo "$value";
		echo "--<br>";
		echo "</td>";
		echo "</tr>";
	}
	echo "</table>";
}

//Graphics-1
{
	unset($tmpData);
	unset($tmpColor);
	$tmpData[]=$lu_data[Attempt];
	$tmpData[]=$callmo_data[Attempt];
	$tmpData[]=$callmt_data[Attempt];
	$tmpData[]=$smmo_data[Attempt];
	$tmpData[]=$smmt_data[Attempt];
	
	$tmpColor[]=array(0x99,0x00,0x33);
	$tmpColor[]=array(0x99,0x00,0xcc);
	$tmpColor[]=array(0x99,0x99,0x00);
	$tmpColor[]=array(0x99,0xcc,0x99);
	$tmpColor[]=array(0x99,0xff,0x33);
	
	echo "<br><b>Service(Attempt)</b><br>";
	$image=CreateImage(450,320);
	$image=DrawPercentHistogram(
		$image,
		$tmpData,
		$tmpColor,
		array(30,20),
		array(400,250),1,0
	);
	$remarkBlock=array(
		"LU",
		"Call MO",
		"Call MT",
		"SM MO",
		"SM MT"
	);
	$pointArr=array(
		array(77,290),
		array(137,290),
		array(208,290),
		array(285,290),
		array(360,290)
	);
	$image=AddRemarkToImage($image,$pointArr,$remarkBlock,0,0,2);
	DrawImage($image);
}
?>
