<?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>";
}

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>";

$cstaDataTmp=GetCstaDataByDay($cstaConf,$startTime,$endTime,"detail");
$cstaData=$cstaDataTmp[0];

$num_of_pods=count($cstaData);
$num_of_records=count($cstaData,1);
$num_of_col=$num_of_records/$num_of_pods;
if(0)
{
	echo "num=$num_of_col";
	echo "<pre>";
	print_r($cstaData[2]);
	echo "</pre>";
}

//Table-1
{
	$table_title="3G RCS Statistic&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>";
        
	$table_title="Signaling&nbsp;&nbsp;";
        echo "<br><b><center>$table_title</center></b>";

	echo "<table width=\"90%\" border=\"1\" cellpadding=\"2\" cellspacing=\"0\" bordercolor=\"#666666\" bordercolordark=\"#FFFFFF\" bgcolor=\"#FFFFFF\">";
	//Table title
	echo "<tr bgcolor=\"#E6E6E6\">";
	echo "<td rowspan=\"2\" width=\"10%\">&nbsp;</td>";
	echo "<td align=\"center\" colspan=\"6\" width=\"60%\">CS Service&nbsp;</td>";
	echo "<td align=\"center\" colspan=\"3\" width=\"30%\">PS Service&nbsp;</td>";
	echo "</tr>";

	echo "<tr bgcolor=\"#E6E6E6\">";
	echo "<td align=\"center\" width=\"10%\">LU</td>";
	echo "<td align=\"center\" width=\"10%\">MO Call</td>";
	echo "<td align=\"center\" width=\"10%\">MT Call</td>";
	echo "<td align=\"center\" width=\"10%\">LS Call</td>";
	echo "<td align=\"center\" width=\"10%\">MO SMS</td>";
	echo "<td align=\"center\" width=\"10%\">MT SMS</td>";
	echo "<td align=\"center\" width=\"10%\">Attach</td>";
	echo "<td align=\"center\" width=\"10%\">PDP Act</td>";
	echo "<td align=\"center\" width=\"10%\">PDP Deact</td>";
	echo "</tr>";

	echo "<tr>";	
	//Attempt
	echo "<td align=\"left\">Attempt</td>";
	$value=0;
	for($i=1;$i<=$num_of_pods; $i++)
	$value +=$cstaData[$i][numLuAttempt]+0;
	echo "<td>$value</td>";
	
	$value=0;
	for($i=1;$i<=$num_of_pods; $i++)
	$value +=$cstaData[$i][numMoAttempt]+0;
	echo "<td>$value</td>";
	
	$value=0;
	for($i=1;$i<=$num_of_pods; $i++)	
	$value +=$cstaData[$i][numMtAttempt]+0;
	echo "<td>$value</td>";

	$value=0;
	for($i=1;$i<=$num_of_pods; $i++)	
	$value +=$cstaData[$i][numLsCall]+0;
	echo "<td>$value</td>";
	
	$value=0;
	for($i=1;$i<=$num_of_pods; $i++)	
	$value +=$cstaData[$i][numSmoAttempt]+0;
	echo "<td>$value</td>";

	$value=0;
	for($i=1;$i<=$num_of_pods; $i++)	
	$value +=$cstaData[$i][numSmtAttempt]+0;
	echo "<td>$value</td>";

	$value=0;
	for($i=1;$i<=$num_of_pods; $i++)
	$value +=$cstaData[$i][numGprsAttachAttempt]+0;
	echo "<td>$value</td>";
	
	$value=0;
	for($i=1;$i<=$num_of_pods; $i++)	
	$value +=$cstaData[$i][numPdpActAttempt]+0;
	echo "<td>$value</td>";

	$value=0;
	for($i=1;$i<=$num_of_pods; $i++)	
	$value +=$cstaData[$i][numPdpDeact]+0;
	echo "<td>$value</td>";
	echo "</tr>";
	
	//Success
	echo "<tr>";
	echo "<td align=\"left\">Success</td>";
	$value=0;
	for($i=1;$i<=$num_of_pods; $i++)
	$value +=$cstaData[$i][numLuSuccess]+0;
	echo "<td>$value</td>";

	$value=0;
	for($i=1;$i<=$num_of_pods; $i++)	
	$value +=$cstaData[$i][numMoSuccess]+0;
	echo "<td>$value</td>";

	$value=0;
	for($i=1;$i<=$num_of_pods; $i++)	
	$value +=$cstaData[$i][numMtSuccess]+0;
	echo "<td>$value</td>";

	$value=0;
	for($i=1;$i<=$num_of_pods; $i++)	
	$value +=$cstaData[$i][numLsCall]+0;
	echo "<td>$value</td>";
	
	$value=0;
	for($i=1;$i<=$num_of_pods; $i++)	
	$value +=$cstaData[$i][numSmoSuccess]+0;
	echo "<td>$value</td>";
	
	$value=0;
	for($i=1;$i<=$num_of_pods; $i++)	
	$value +=$cstaData[$i][numSmtSuccess]+0;
	echo "<td>$value</td>";
	
	$value=0;
	for($i=1;$i<=$num_of_pods; $i++)	
	$value +=$cstaData[$i][numGprsAttachSuccess]+0;
	echo "<td>$value</td>";

	$value=0;
	for($i=1;$i<=$num_of_pods; $i++)	
	$value +=$cstaData[$i][numPdpActSuccess]+0;
	echo "<td>$value</td>";

	$value=0;
	for($i=1;$i<=$num_of_pods; $i++)	
	$value +=$cstaData[$i][numPdpDeact]+0;
	echo "<td>$value</td>";
	echo "</tr>";
	
	
	//Success Percentage
	echo "<tr>";
	echo "<td align=\"left\">Success %</td>";
	$value1=0;
	$value2=0;

	for($i=1;$i<=$num_of_pods; $i++)	
	{
		$value1 += $cstaData[$i][numLuSuccess];
		$value2 += $cstaData[$i][numLuAttempt];
	}
	$value=GetPercent($value1, $value2);
	echo "<td>$value</td>";

	$value1=0;
	$value2=0;

	for($i=1;$i<=$num_of_pods; $i++)	
	{
		$value1 += $cstaData[$i][numMoSuccess];
		$value2 += $cstaData[$i][numMoAttempt];
	}
	$value=GetPercent($value1, $value2);	
	echo "<td>$value</td>";

	$value1=0;
	$value2=0;

	for($i=1;$i<=$num_of_pods; $i++)	
	{
		$value1 += $cstaData[$i][numMtSuccess];
		$value2 += $cstaData[$i][numMtAttempt];
	}
	$value=GetPercent($value1, $value2);	
	echo "<td>$value</td>";

	$value1=0;
	$value2=0;

	for($i=1;$i<=$num_of_pods; $i++)	
	{
		$value1 += $cstaData[$i][numLsCall];
		$value2 += $cstaData[$i][numMoAttempt];
	}
	$value=GetPercent($value1, $value2);
	echo "<td>$value</td>";

	$value1=0;
	$value2=0;

	for($i=1;$i<=$num_of_pods; $i++)	
	{
		$value1 += $cstaData[$i][numSmoSuccess];
		$value2 += $cstaData[$i][numSmoAttempt];
	}
	$value=GetPercent($value1, $value2);
	echo "<td>$value</td>";

	$value1=0;
	$value2=0;

	for($i=1;$i<=$num_of_pods; $i++)	
	{
		$value1 += $cstaData[$i][numSmtSuccess];
		$value2 += $cstaData[$i][numSmtAttempt];
	}
	$value=GetPercent($value1, $value2);
	echo "<td>$value</td>";

	$value1=0;
	$value2=0;

	for($i=1;$i<=$num_of_pods; $i++)	
	{
		$value1 += $cstaData[$i][numGprsAttachSuccess];
		$value2 += $cstaData[$i][numGprsAttachAttempt];
	}
	$value=GetPercent($value1, $value2);
	echo "<td>$value</td>";

	$value1=0;
	$value2=0;

	for($i=1;$i<=$num_of_pods; $i++)	
	{
		$value1 += $cstaData[$i][numPdpActSuccess];
		$value2 += $cstaData[$i][numPdpActAttempt];
	}
	$value=GetPercent($value1, $value2);
	echo "<td>$value</td>";

	$value1=0;
	$value2=0;

	for($i=1;$i<=$num_of_pods; $i++)	
	{
		$value1 += $cstaData[$i][numPdpDeact];
		$value2 += $cstaData[$i][numPdpDeact];
	}
	$value=GetPercent($value1, $value2);
	echo "<td>$value</td>";
	
	echo "</tr>";
	echo "</table>";

	echo "<br><b></b><br>";
	
}

//Table-2 PS
{
        $table_title="PS Data&nbsp;&nbsp;";
        echo "<br><b><center>$table_title</center></b>";

	echo "<table width=\"90%\" border=\"1\" cellpadding=\"2\" cellspacing=\"0\" bordercolor=\"#666666\" bordercolordark=\"#FFFFFF\" bgcolor=\"#FFFFFF\">";
	//Table title
	echo "<tr bgcolor=\"#E6E6E6\">";
	echo "<td rowspan=\"2\" width=\"10%\">&nbsp;</td>";
	echo "<td align=\"center\" colspan=\"2\" width=\"30%\">IuPS&nbsp;</td>";
	echo "<td align=\"center\" colspan=\"2\" width=\"30%\">Iuh&nbsp;</td>";
	echo "<td align=\"center\" colspan=\"2\" width=\"30%\">Offload&nbsp;</td>";
	echo "</tr>";

	echo "<tr bgcolor=\"#E6E6E6\">";
	echo "<td align=\"center\" width=\"15%\">Packets</td>";
	echo "<td align=\"center\" width=\"15%\">Byte (M)</td>";
	echo "<td align=\"center\" width=\"15%\">Packets</td>";
	echo "<td align=\"center\" width=\"15%\">Byte (M)</td>";
	echo "<td align=\"center\" width=\"15%\">Packets %</td>";
	echo "<td align=\"center\" width=\"15%\">Volume %</td>";
	echo "</tr>";

	echo "<tr>";
	
	//Attempt
	echo "<td align=\"left\">Uplink Rx</td>";
	$value="--";
	echo "<td>$value</td>";	
	$value="--";
	echo "<td>$value</td>";

	$value=0;
	for($i=1;$i<=$num_of_pods; $i++)	
	$value +=$cstaData[$i][numGtpPRecvUplink]+0;
	
	echo "<td>$value</td>";
	$value1=number_format(($value+0)/1024,3);
	echo "<td>$value1</td>";
	
	$value="--";
	echo "<td>$value</td>";
	$value="--";
	echo "<td>$value</td>";

	echo "<tr>";
	
	//Attempt
	echo "<td align=\"left\">Uplink Tx</td>";
	$value=0;
	for($i=1;$i<=$num_of_pods; $i++)	
	$value +=$cstaData[$i][numGtpPSentUplink]+0;
	echo "<td>$value</td>";

	$value1=number_format(($value+0)/1024,3);
	echo "<td>$value1</td>";
	
	$value="--";
	echo "<td>$value</td>";
	$value="--";
	echo "<td>$value</td>";

	$value1=0;
	$value2=0;

	for($i=1;$i<=$num_of_pods; $i++)	
	{
		$value1 += $cstaData[$i][numGtpPSentUplink];
		$value2 += $cstaData[$i][numGtpPRecvUplink];
	}	
	$value=GetPercent($value1-$value2,$value1);
	echo "<td>$value</td>";

	$value1=0;
	$value2=0;

	for($i=1;$i<=$num_of_pods; $i++)	
	{
		$value1 += $cstaData[$i][numGtpKBSentUplink];
		$value2 += $cstaData[$i][numGtpKBRecvUplink];
	}	
	$value=GetPercent($value1-$value2,$value1);
	echo "<td>$value</td>";
	
	echo "<tr>";
	echo "<td align=\"left\">Downlink Rx</td>";
	$value=$cstaData[$i][numGtpPRecvDnlink]+0;
	echo "<td>$value</td>";

	$value=0;
	for($i=1;$i<=$num_of_pods; $i++)	
	$value +=$cstaData[$i][numGtpKBRecvDnlink]+0;

	$value1=number_format(($value+0)/1024,3);
	echo "<td>$value1</td>";
	
	$value="--";
	echo "<td>$value</td>";
	$value="--";
	echo "<td>$value</td>";

	$value="--";
	echo "<td>$value</td>";
	$value="--";
	echo "<td>$value</td>";
	
	echo "<tr>";
	echo "<td align=\"left\">Downlink Tx</td>";
	$value="--";
	echo "<td>$value</td>";	
	$value="--";
	echo "<td>$value</td>";

	$value=0;
	for($i=1;$i<=$num_of_pods; $i++)	
	$value +=$cstaData[$i][numGtpPSentDnlink]+0;
	echo "<td>$value</td>";

	$value1=number_format(($value+0)/1024,3);
	echo "<td>$value1</td>";

	$value1=0;
	$value2=0;
	for($i=1;$i<=$num_of_pods; $i++)	
	{
		$value1 += $cstaData[$i][numGtpPRecvDnlink];
		$value2 += $cstaData[$i][numGtpPSentDnlink];
	}	
	$value=GetPercent($value1-$value2,$value1);
	echo "<td>$value</td>";

	$value1=0;
	$value2=0;
	for($i=1;$i<=$num_of_pods; $i++)	
	{
		$value1 += $cstaData[$i][numGtpKBRecvDnlink];
		$value2 += $cstaData[$i][numGtpKBSentDnlink];
	}	
	$value=GetPercent($value1-$value2,$value1);
	echo "<td>$value</td>";
	
	echo "</tr>";	
	echo "</table>";
}

//Graphics-1
{
	$cstaHourDataTmp=GetCstaDataByHour($cstaConf,$startTime,$endTime,"detail");
	$cstaHourData=$cstaHourDataTmp[0];
	if(0)
	{
		echo "<pre>";
		print_r($cstaHourData);
		echo "</pre>";
	}
	
	unset($tmpData);
	unset($tmpColor);
	if($flag0 == "on")
	{
		$tmpColor[]=array(0x00,0x00,0xff);
		for($i=0;$i<$total_hour_num;$i++)
		{
			$lu_ok[$i] = 0;
			for($j=1;$j<=$num_of_pods; $j++)
			{
				$lu_ok[$i] += $cstaHourData[$j][numLuSuccess][$i]+0;
			}
		}
		$tmpData[]=$lu_ok;
	}
	if($flag1 == "on")
	{
		$tmpColor[]=array(0x00,0xff,0x00);
		for($i=0;$i<$total_hour_num;$i++)
		{
			$mo_call_ok[$i] = 0;
			for($j=1;$j<=$num_of_pods; $j++)
			{
				$mo_call_ok[$i] += $cstaHourData[$j][numMoSuccess][$i]+0;
			}
		}
		$tmpData[]=$mo_call_ok;
	}
	if($flag2 == "on")
	{
		$tmpColor[]=array(0xff,0x00,0x00);
		for($i=0;$i<$total_hour_num;$i++)
		{
			$mt_call_ok[$i] = 0;
			for($j=1;$j<=$num_of_pods; $j++)
			{
				$mt_call_ok[$i] += $cstaHourData[$j][numMtSuccess][$i]+0;
			}
		}
		$tmpData[]=$mt_call_ok;
	}
	if($flag3 == "on")
	{
		$tmpColor[]=array(0x7d,0x00,0x00);
		for($i=0;$i<$total_hour_num;$i++)
		{
			$mo_sms_ok[$i] = 0;
			for($j=1;$j<=$num_of_pods; $j++)
			{
				$mo_sms_ok[$i] += $cstaHourData[$j][numSmoSuccess][$i]+0;
			}
		}
		$tmpData[]=$mo_sms_ok;
	}
	if($flag4 == "on")
	{
		$tmpColor[]=array(0x00,0x7d,0x00);
		for($i=0;$i<$total_hour_num;$i++)
		{
			$mt_sms_ok[$i] = 0;
			for($j=1;$j<=$num_of_pods; $j++)
			{
				$mt_sms_ok[$i] += $cstaHourData[$j][numSmtSuccess][$i]+0;
			}
		}
		$tmpData[]=$mt_sms_ok;
	}
	echo "<br><b>CS Hour Traffic Chart</b><br>";
	
	$boldline=$select_checkbox_id;
	if($select_checkbox_id<5)
	{
	for($i=0;$i<$select_checkbox_id;$i++)
	{
		$param="flag$i";
		if($$param != "on")
			$boldline--;
	}
	}
	//echo "boldline=$boldline,flag0/1/2/3/4/5/6/7/8/9=0$flag0,1$flag1,2$flag2,3$flag3,4$flag4,5$flag5,6$flag6,7$flag7,8$flag8";

	$image=CreateImage(820,390);
	$image=DrawLineHistogram(
		$image,
		$tmpData,
		$tmpColor,
		750/(24*$slot),
		24,
		array(50,20),
		array(750,280),
		$boldline,1,0,1
	);
	
	$remarkBlock=array(
		"LU",
		"MO Call",
		"MT Call",
		"MO SMS",
		"MT SMS",
	);
	$pointArr=array(
		array(30,367),
		array(130,367),
		array(230,367),
		array(330,367),
		array(430,367),
	);
	
	unset($tmpColor);
	$tmpColor[]=array(0x00,0x00,0xff);
	$tmpColor[]=array(0x00,0xff,0x00);
	$tmpColor[]=array(0xff,0x00,0x00);
	$tmpColor[]=array(0x7d,0x00,0x00);
	$tmpColor[]=array(0x00,0x7d,0x00);
	$tmpColor[]=array(0xff,0x00,0xff);
	$tmpColor[]=array(0x66,0x22,0x66);
	$tmpColor[]=array(0x88,0x88,0x88);
	
	$image=AddRemarkToImage($image,$pointArr,$remarkBlock,$tmpColor,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);
	
}
	echo "<br><b></b><br>";

//Graphics-2
{
	$cstaHourDataTmp=GetCstaDataByHour($cstaConf,$startTime,$endTime,"detail");
	$cstaHourData=$cstaHourDataTmp[0];
	if(0)
	{
		echo "<pre>";
		print_r($cstaHourData);
		echo "</pre>";
	}
	
	unset($tmpData);
	unset($tmpColor);
	if($flag5 == "on")
	{
		$tmpColor[]=array(0x00,0x00,0xff);
		
		for($i=0;$i<$total_hour_num;$i++)
		{
			$iu_ps_ul[$i] = 0;
			for($j=1;$j<=$num_of_pods; $j++)
			{
				$iu_ps_ul[$i] += number_format(($cstaHourData[$j][numGtpKBSentUplink][$i]+0)/1024,1);
			}
		}
		$tmpData[]=$iu_ps_ul;
	}
	if($flag6 == "on")
	{
		$tmpColor[]=array(0x00,0xff,0x00);
		for($i=0;$i<$total_hour_num;$i++)
		{
			$iu_ps_dl[$i] = 0;
			for($j=1;$j<=$num_of_pods; $j++)
			{
				$iu_ps_dl[$i] +=number_format(($cstaHourData[$j][numGtpKBRecvDnlink][$i]+0)/1024,1);
			}
		}
		$tmpData[]=$iu_ps_dl;
	}
	if($flag7 == "on")
	{
		$tmpColor[]=array(0xff,0x00,0x00);
		for($i=0;$i<$total_hour_num;$i++)
		{
			$iu_h_ul[$i] = 0;
			for($j=1;$j<=$num_of_pods; $j++)
			{
				$iu_h_ul[$i] +=number_format(($cstaHourData[$j][numGtpKBRecvUplink][$i]+0)/1024,1);
			}
		}
		$tmpData[]=$iu_h_ul;
	}
	if($flag8 == "on")
	{
		$tmpColor[]=array(0x7d,0x00,0x00);
		for($i=0;$i<$total_hour_num;$i++)
		{
			$iu_h_dl[$i] = 0;
			for($j=1;$j<=$num_of_pods; $j++)
			{
				$iu_h_dl[$i] +=number_format(($cstaHourData[$j][numGtpKBSentDnlink][$i]+0)/1024,1);
			}
		}
		$tmpData[]=$iu_h_dl;
	}

	echo "<br><b>PS Hour Traffic Chart</b><br>";
	
	if($select_checkbox_id>=5)
	{
		$boldline=$select_checkbox_id;
		for($i=5;$i<=$select_checkbox_id;$i++)
		{
			$param="flag$i";
			if($$param != "on")
				$boldline--;
		}
	}
	//echo "boldline=$boldline,flag0/1/2/3/4/5/6/7/8/9=0$flag0,1$flag1,2$flag2,3$flag3,4$flag4,5$flag5,6$flag6,7$flag7,8$flag8";

	$image=CreateImage(820,390);
	$image=DrawLineHistogram(
		$image,
		$tmpData,
		$tmpColor,
		750/(24*$slot),
		24,
		array(50,20),
		array(750,280),
		$boldline,1,0,1
	);
	
	$remarkBlock=array(
		"IuPS UL",
		"IuPS DL",
		"IuH UL",
		"IuH DL",
	);
	$pointArr=array(
		array(30,367),
		array(130,367),
		array(230,367),
		array(330,367),
	);
	
	unset($tmpColor);
        
	$tmpColor[]=array(0x00,0x00,0xff);
        $tmpColor[]=array(0x00,0xff,0x00);
        $tmpColor[]=array(0xff,0x00,0x00);
        $tmpColor[]=array(0x7d,0x00,0x00);
        $tmpColor[]=array(0x00,0x7d,0x00);
	$tmpColor[]=array(0xff,0x00,0xff);
	$tmpColor[]=array(0x66,0x22,0x66);
	$tmpColor[]=array(0x88,0x88,0x88);
	$tmpColor[]=array(0x00,0x88,0x88);

	
	$image=AddRemarkToImage($image,$pointArr,$remarkBlock,$tmpColor,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);
	
}
	echo "<br><b></b><br>";

?>
