<?php
global $objDbConn;

if(0)
{
	echo "sel_date_from=$sel_date_from,sel_date_to=$sel_date_to<br>";
	echo "keyOne=$keyOne,keyTwo=$keyTwo<br>";
}
if(!isset($keyTwo) || trim($keyTwo)=="" || $keyTwo==0)
	$keyTwo=1;

if(1)
{
	$dualTableLevelWhere="T1.level_1=T2.level_1 AND
                                       T1.level_2=T2.level_2 AND
                                          T1.level_3=T2.level_3 AND
                                          T1.level_4=T2.level_4 AND
                                          T1.level_5=T2.level_5 AND
                                          T1.level_6=T2.level_6 AND
                                          T1.level_7=T2.level_7 AND
                                          T1.level_8=T2.level_8 AND
                                          T1.level_9=T2.level_9 AND
                                          T1.level_10=T2.level_10";


                //===get the title of pod=====
                $database="OBJ_364";
                $sql="SELECT T1.* FROM param_99 AS T1,paramConf AS T2 WHERE $dualTableLevelWhere AND T2.name_2='podIdentity' ";

                if(0)
                echo "sql= $sql";

                $result=@mysqli_query($objDbConn,$sql);
                $podCount=mysqli_num_rows($result);

                if($podCount>0)
                {
                        while($rows = @mysqli_fetch_array($result))
                        {
                             $index =$rows[instanceNo]+0;
                             $pod_element_title[$index]=$rows[initValue];
                        }
                }
                
		$database="OBJ_364";
                $sql="SELECT T1.* FROM param_99 AS T1,paramConf AS T2 WHERE $dualTableLevelWhere AND T2.name_2='podPodId' ";

                if(0)
                echo "sql= $sql";

                $result=@mysqli_query($objDbConn,$sql);
                $podCount=mysqli_num_rows($result);

                if($podCount>0)
                {
			$i=1;
                        while($rows = @mysqli_fetch_array($result))
                        {
                             $pod_no[$i]=$rows[initValue];
			     $i = $i + 1;
                        }
                }

} 

$cstaConf=GetCstaConf($sysTypeNo);
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")));
if(0)
echo "startTime=$startTime,endTime=$endTime<br>";
$pod_index=$pod_no[$keyTwo];
$cstaDataTmp=GetCstaDataByDay($cstaConf,$startTime,$endTime,"detail",$pod_index);
$cstaData=$cstaDataTmp[0];
if(0)
{
	echo "<pre>";
	print_r($cstaData);
	echo "</pre>";
}

//Table-1
{
	$table_title="POD <$pod_element_title[$keyTwo]> 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 =$cstaData[$keyTwo][numLuAttempt]+0;
	echo "<td>$value</td>";
	
	$value=$cstaData[$keyTwo][numMoAttempt]+0;
	echo "<td>$value</td>";
	
	$value=$cstaData[$keyTwo][numMtAttempt]+0;
	echo "<td>$value</td>";
	
	$value=$cstaData[$keyTwo][numLsCall]+0;
	echo "<td>$value</td>";
	
	
	$value=$cstaData[$keyTwo][numSmoAttempt]+0;
	echo "<td>$value</td>";
	
	$value=$cstaData[$keyTwo][numSmtAttempt]+0;
	echo "<td>$value</td>";

	$value=$cstaData[$keyTwo][numGprsAttachAttempt]+0;
	echo "<td>$value</td>";
	
	
	$value=$cstaData[$keyTwo][numPdpActAttempt]+0;
	echo "<td>$value</td>";
	
	$value=$cstaData[$keyTwo][numPdpDeact]+0;
	echo "<td>$value</td>";
	echo "</tr>";
	
	//Success
	echo "<tr>";
	echo "<td align=\"left\">Success</td>";
	$value=$cstaData[$keyTwo][numLuSuccess]+0;
	echo "<td>$value</td>";
	
	$value=$cstaData[$keyTwo][numMoSuccess]+0;
	echo "<td>$value</td>";
	
	$value=$cstaData[$keyTwo][numMtSuccess]+0;
	echo "<td>$value</td>";
	
	$value=$cstaData[$keyTwo][numLsCall]+0;
	echo "<td>$value</td>";
	
	$value=$cstaData[$keyTwo][numSmoSuccess]+0;
	echo "<td>$value</td>";
	
	$value=$cstaData[$keyTwo][numSmtSuccess]+0;
	echo "<td>$value</td>";
	
	$value=$cstaData[$keyTwo][numGprsAttachSuccess]+0;
	echo "<td>$value</td>";
	
	$value=$cstaData[$keyTwo][numPdpActSuccess]+0;
	echo "<td>$value</td>";
	
	$value=$cstaData[$keyTwo][numPdpDeact]+0;
	echo "<td>$value</td>";
	echo "</tr>";
	
	
	//Success Percentage
	echo "<tr>";
	echo "<td align=\"left\">Success %</td>";
	$value=GetPercent($cstaData[$keyTwo][numLuSuccess],$cstaData[$keyTwo][numLuAttempt]);
	echo "<td>$value</td>";
	
	$value=GetPercent($cstaData[$keyTwo][numMoSuccess],$cstaData[$keyTwo][numMoAttempt]);
	echo "<td>$value</td>";
	
	$value=GetPercent($cstaData[$keyTwo][numMtSuccess],$cstaData[$keyTwo][numMtAttempt]);
	echo "<td>$value</td>";
	
	$value=GetPercent($cstaData[$keyTwo][numLsCall],$cstaData[$keyTwo][numLsCall]);
	echo "<td>$value</td>";
	
	$value=GetPercent($cstaData[$keyTwo][numSmoSuccess],$cstaData[$keyTwo][numSmoAttempt]);
	echo "<td>$value</td>";
	
	$value=GetPercent($cstaData[$keyTwo][numSmtSuccess],$cstaData[$keyTwo][numSmtAttempt]);
	echo "<td>$value</td>";

	$value=GetPercent($cstaData[$keyTwo][numGprsAttachSuccess],$cstaData[$keyTwo][numGprsAttachAttempt]);
	echo "<td>$value</td>";
	
	$value=GetPercent($cstaData[$keyTwo][numPdpActSuccess],$cstaData[$keyTwo][numPdpActAttempt]);
	echo "<td>$value</td>";
	
	$value=GetPercent($cstaData[$keyTwo][numPdpDeact],$cstaData[$keyTwo][numPdpDeact]);
	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=$cstaData[$keyTwo][numGtpPRecvUplink]+0;
	echo "<td>$value</td>";
	$value=number_format(($cstaData[$keyTwo][numGtpKBRecvUplink]+0)/1024,3);
	echo "<td>$value</td>";
	
	$value="--";
	echo "<td>$value</td>";
	$value="--";
	echo "<td>$value</td>";

	echo "<tr>";
	
	//Attempt
	echo "<td align=\"left\">Uplink Tx</td>";
	$value=$cstaData[$keyTwo][numGtpPSentUplink]+0;
	echo "<td>$value</td>";
	$value=number_format(($cstaData[$keyTwo][numGtpKBSentUplink]+0)/1024,3);
	echo "<td>$value</td>";
	
	$value="--";
	echo "<td>$value</td>";
	$value="--";
	echo "<td>$value</td>";
	
	$value=GetPercent($cstaData[$keyTwo][numGtpPSentUplink]-$cstaData[$keyTwo][numGtpPRecvUplink],$cstaData[$keyTwo][numGtpPSentUplink]);
	echo "<td>$value</td>";
	$value=GetPercent($cstaData[$keyTwo][numGtpKBSentUplink]-$cstaData[$keyTwo][numGtpKBRecvUplink],$cstaData[$keyTwo][numGtpKBSentUplink]);
	echo "<td>$value</td>";
	
	echo "<tr>";
	echo "<td align=\"left\">Downlink Rx</td>";
	$value=$cstaData[$keyTwo][numGtpPRecvDnlink]+0;
	echo "<td>$value</td>";
	$value=number_format(($cstaData[$keyTwo][numGtpKBRecvDnlink]+0)/1024,3);
	echo "<td>$value</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=$cstaData[$keyTwo][numGtpPSentDnlink]+0;
	echo "<td>$value</td>";
	$value=number_format(($cstaData[$keyTwo][numGtpKBSentDnlink]+0)/1024,3);
	echo "<td>$value</td>";

	$value=GetPercent($cstaData[$keyTwo][numGtpPRecvDnlink]-$cstaData[$keyTwo][numGtpPSentDnlink],$cstaData[$keyTwo][numGtpPRecvDnlink]);
	echo "<td>$value</td>";
	$value=GetPercent($cstaData[$keyTwo][numGtpKBRecvDnlink]-$cstaData[$keyTwo][numGtpKBSentDnlink],$cstaData[$keyTwo][numGtpKBRecvDnlink]);
	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]=$cstaHourData[$keyTwo][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]=$cstaHourData[$keyTwo][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]=$cstaHourData[$keyTwo][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]=$cstaHourData[$keyTwo][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]=$cstaHourData[$keyTwo][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]=number_format(($cstaHourData[$keyTwo][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]=number_format(($cstaHourData[$keyTwo][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]=number_format(($cstaHourData[$keyTwo][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]=number_format(($cstaHourData[$keyTwo][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>";

?>
