<?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")));
//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="MRFC 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=\"13%\">Type</td>";
	echo "<td align=\"center\" width=\"8%\">Attempt</td>";
	echo "<td align=\"center\" width=\"8%\">Success</td>";
	echo "<td align=\"center\" width=\"8%\">No Resource</td>";
	echo "<td align=\"center\" width=\"8%\">Negotiation Fail</td>";
	echo "<td align=\"center\" width=\"8%\">Media Error</td>";
	echo "<td align=\"center\" width=\"8%\">No Response</td>";
	echo "<td align=\"center\" width=\"8%\">General Error</td>";
	echo "<td align=\"center\" width=\"10%\">Total Call Duration</td>";
	echo "<td align=\"center\" width=\"13%\">Average Call Duration(s)</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 "Conference";
	echo "</a>";
	echo "</td>";
	//Attempt
	$value=$cstaData[0][1][Attempt]+0;
	echo "<td align=\"center\">$value</td>";
	
	//Success
	$value=$cstaData[0][1][Success]+0;
	$percent=GetPercent($cstaData[0][1][Success],$cstaData[0][1][Attempt]);
	echo "<td align=\"center\">";
	echo "$value<br>";
	echo "$percent";
	echo "</td>";
	
	//No Resource
	$value=$cstaData[0][1][Cau1]+0;
	$percent=GetPercent($cstaData[0][1][Cau1],$cstaData[0][1][Attempt]);
	echo "<td align=\"center\">";
	echo "$value<br>";
	echo "$percent";
	echo "</td>";
	
	//Negotiation Fail
	$value=$cstaData[0][1][Cau2]+0;
	$percent=GetPercent($cstaData[0][1][Cau2],$cstaData[0][1][Attempt]);
	echo "<td align=\"center\">";
	echo "$value<br>";
	echo "$percent";
	echo "</td>";
	
	//Media Error
	$value=$cstaData[0][1][Cau3]+0;
	$percent=GetPercent($cstaData[0][1][Cau3],$cstaData[0][1][Attempt]);
	echo "<td align=\"center\">";
	echo "$value<br>";
	echo "$percent";
	echo "</td>";
	
	//No Response
	$value=$cstaData[0][1][Cau4]+0;
	$percent=GetPercent($cstaData[0][1][Cau4],$cstaData[0][1][Attempt]);
	echo "<td align=\"center\">";
	echo "$value<br>";
	echo "$percent";
	echo "</td>";
	
	//General Error
	$value=$cstaData[0][1][Cau5]+0;
	$percent=GetPercent($cstaData[0][1][Cau5],$cstaData[0][1][Attempt]);
	echo "<td align=\"center\">";
	echo "$value<br>";
	echo "$percent";
	echo "</td>";
	
	//Total Call Duration
	$value=$cstaData[0][1][Duration]+0;
	$timestamp=SecondToTimeStamp($value);
	echo "<td align=\"center\">";
	echo "$value<br>";
	echo "$timestamp";
	echo "</td>";
	
	//Average Call Duration
	if($cstaData[0][1][Success] > 0)
		$value=ceil($cstaData[0][1][Duration]/$cstaData[0][1][Success]);
	else
		$value=0;
	echo "<td align=\"center\">";
	echo "$value<br>";
	echo "</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','2','-1');\">";
	echo "Transcoding";
	echo "</a>";
	echo "</td>";
	
	//Attempt
	$value=$cstaData[0][2][Attempt]+0;
	echo "<td align=\"center\">$value</td>";
	
	//Success
	$value=$cstaData[0][2][Success]+0;
	$percent=GetPercent($cstaData[0][2][Success],$cstaData[0][2][Attempt]);
	echo "<td align=\"center\">";
	echo "$value<br>";
	echo "$percent";
	echo "</td>";
	
	//No Resource
	$value=$cstaData[0][2][Cau1]+0;
	$percent=GetPercent($cstaData[0][2][Cau1],$cstaData[0][2][Attempt]);
	echo "<td align=\"center\">";
	echo "$value<br>";
	echo "$percent";
	echo "</td>";
	
	//Negotiation Fail
	$value=$cstaData[0][2][Cau2]+0;
	$percent=GetPercent($cstaData[0][2][Cau2],$cstaData[0][2][Attempt]);
	echo "<td align=\"center\">";
	echo "$value<br>";
	echo "$percent";
	echo "</td>";
	
	//Media Error
	$value=$cstaData[0][2][Cau3]+0;
	$percent=GetPercent($cstaData[0][2][Cau3],$cstaData[0][2][Attempt]);
	echo "<td align=\"center\">";
	echo "$value<br>";
	echo "$percent";
	echo "</td>";
	
	//No Response
	$value=$cstaData[0][2][Cau4]+0;
	$percent=GetPercent($cstaData[0][2][Cau4],$cstaData[0][2][Attempt]);
	echo "<td align=\"center\">";
	echo "$value<br>";
	echo "$percent";
	echo "</td>";
	
	//General Error
	$value=$cstaData[0][2][Cau5]+0;
	$percent=GetPercent($cstaData[0][2][Cau5],$cstaData[0][2][Attempt]);
	echo "<td align=\"center\">";
	echo "$value<br>";
	echo "$percent";
	echo "</td>";
	
	//Total Call Duration
	$value=$cstaData[0][2][Duration]+0;
	$timestamp=SecondToTimeStamp($value);
	echo "<td align=\"center\">";
	echo "$value<br>";
	echo "$timestamp";
	echo "</td>";
	
	//Average Call Duration
	if($cstaData[0][2][Success] > 0)
		$value=ceil($cstaData[0][2][Duration]/$cstaData[0][2][Success]);
	else
		$value=0;
	echo "<td align=\"center\">";
	echo "$value<br>";
	echo "</td>";
	echo "</tr>";
	
	echo "</table>";
}

//Graphics-1
{
	echo "<br><b>Service(Attempt) & Success/Failure</b><br>";
	unset($tmpData);
	unset($tmpColor);
	$tmpData[]=$cstaData[0][1][Attempt]+0;
	$tmpData[]=$cstaData[0][2][Attempt]+0;
	
	$tmpColor[]=array(0x99,0x00,0x33);
	$tmpColor[]=array(0x99,0x00,0xcc);
	
	$image=CreateImage(680,370);
	$image=DrawPercentHistogram($image,
		$tmpData,
		$tmpColor,
		array(30,20),
		array(160,280),1,0
	);
	
	unset($tmpData);
	$data_index=0;
	$tmpData[$data_index][0]=$cstaData[0][1][Success]+0;
	$tmpData[$data_index][1]=$cstaData[0][2][Success]+0;
	$data_index++;
	$tmpData[$data_index][0]=$cstaData[0][1][Cau1]+0;
	$tmpData[$data_index][1]=$cstaData[0][2][Cau1]+0;
	$data_index++;
	$tmpData[$data_index][0]=$cstaData[0][1][Cau2]+0;
	$tmpData[$data_index][1]=$cstaData[0][2][Cau2]+0;
	$data_index++;
	$tmpData[$data_index][0]=$cstaData[0][1][Cau3]+0;
	$tmpData[$data_index][1]=$cstaData[0][2][Cau3]+0;
	$data_index++;
	$tmpData[$data_index][0]=$cstaData[0][1][Cau4]+0;
	$tmpData[$data_index][1]=$cstaData[0][2][Cau4]+0;
	$data_index++;
	$tmpData[$data_index][0]=$cstaData[0][1][Cau5]+0;
	$tmpData[$data_index][1]=$cstaData[0][2][Cau5]+0;
	$data_index++;
	
	$image=DrawStackPercentHistogram($image,
		$tmpData,
		$tmpColor,
		array(220,20),
		array(420,280),0,1
	);
	
	$remarkBlock=array(
		"Attempt",
		"Success",
		"No","Resource",
		"Negotiation","Fail",
		"Media","Error",
		"No","Response",
		"General","Error"
	);
	
	$pointArr=array(
		array(90,320),
		array(245,310),
		array(330,305),array(315,315),
		array(365,305),array(387,315),
		array(448,305),array(447,315),
		array(520,305),array(507,315),
		array(572,305),array(577,315)
	);
	
	$image=AddRemarkToImage($image,$pointArr,$remarkBlock,0,0,2);
	
	unset($remarkBlock);
	unset($pointArr);
	$remarkBlock=array(
		"Conference",
		"Transcoding"
	);
	
	$pointArr=array(
		array(50,340),
		array(340,340),
	);
	
	$image=AddRemarkToImage($image,$pointArr,$remarkBlock,$tmpColor,0,2);
	
	DrawImage($image);
}
?>
