<?php
//Include the head file
require("../../inc/header.inc");
require("./function.inc");
?>
<script language="JavaScript">
//the function is called when the sel_date_from value changed
function sel_date_from_change()
{	
	var sysTypeNo=document.myform.sysTypeNo.value;
	var show_type=document.myform.show_type.value;
	var page_id=document.myform.page_id.value;
	var down_date_from=document.myform.sel_date_from.value;
	var down_date_to=document.myform.sel_date_to.value;
	
	var keyOne=document.myform.keyOne.value;
	
	var keyTwo=0;
	if(sysTypeNo == 320 && page_id != 0)
	{
		keyTwo=document.myform.keyTwo.value;
	}
	else if(sysTypeNo == 390 && page_id == 0)
	{
		keyTwo=document.myform.keyTwo.value;
	}
	else if(sysTypeNo == 375 && page_id == 0)
	{
		keyTwo=document.myform.keyTwo.value;
	}
	else if(sysTypeNo == 378 && page_id == 1)
	{
		keyTwo=document.myform.keyTwo.value;
	}
	else if(sysTypeNo == 362 && page_id == 0){
		keyTwo=document.myform.keyTwo.value;
	}
	else if(sysTypeNo == 350 && page_id == 0){
		keyTwo=document.myform.keyTwo.value;
	}
	//var scrollY=document.body.scrollTop;
	if(down_date_from<=down_date_to)
		down_date_to=down_date_from;
	{
	var urll='<?php echo"$PHP_SELF";?>?sysTypeNo='+sysTypeNo+'&show_type='+show_type+'&page_id='+page_id+'&sel_date_from='+down_date_from+'&sel_date_to='+down_date_to+'&keyOne='+keyOne+'&keyTwo='+keyTwo;
	window.location.href=urll;
	}
}

function add_trunk_text()
{
	if(document.myform.keyTwo.value == 1)
		document.myform.trunk_text.style.display='';
	else
		document.myform.trunk_text.style.display='none';
}

function openFieldConf(sysTypeNo,pageId,showType)
{
	var urll='./general_csta_index.php?sysTypeNo='+sysTypeNo+'&show_type='+showType+'&page_id='+pageId+'&sel_date_from='+down_date_from+'&sel_date_to='+down_date_to+'&isExport=1';
	console.log("Constructed URL:", urll);  // 打印构造的 URL
	window.location.href=urll;
console.log(sysTypeNo,pageId)
}
</script>

<base target="general_csta_down">
<body leftmargin="15" rightmargin="10" onload="javascript:adjust_frame('up');" onresize="javascript:adjust_frame('up');" style="overflow:hidden;overflow-x:hidden;overflow-y:hidden;">
<form action="general_csta_down.php" method="post" name="myform">

<?php
$generalConf=parse_ini_file("general.conf",true);
if(0)
{
	echo "<pre>";
	print_r($generalConf);
	echo "</pre>";
}

adjust_head_frame("up");
adjust_title_head_frame("up");
$sysTypeNo=$_REQUEST['sysTypeNo'];
$page_id=$_REQUEST['page_id'];
$show_type=$_REQUEST['show_type'];
$sel_date_from=$_REQUEST['sel_date_from'];
$sel_date_to=$_REQUEST['sel_date_to'];
$keyOne=$_REQUEST['keyOne'];
$keyTwo=$_REQUEST['keyTwo'];
$sel_pod_id=$_REQUEST['sel_pod_id'];

	echo "<table id=\"table_up\" border=0 width=\"100%\">";
	echo "<tr>";
	echo "<td width=50% align=\"left\">";
	echo "{$generalConf[PageTitle][$sysTypeNo][$page_id]}";
	echo "</td>";
	echo "<td align=\"right\">";
	if(isset($generalConf[HelpID][$sysTypeNo][$page_id]))
		showHelp($generalConf[HelpID][$sysTypeNo][$page_id]);
	echo "</td>";
	echo "</tr>";
	echo "<tr>";
	echo "<td align=\"left\">";

if($sysTypeNo == MSC_SYSTYPENO)
{
	if($page_id == 1)
	{
		$tmpLabel=array("In&Out","In","Out");
		echo "<select name=\"keyTwo\" onchange=\"javascript:sel_date_from_change();\">";
		for($i=0;$i<sizeof($tmpLabel);$i++)
		{
			if($keyTwo == $i)
				echo "<option selected value=$i>{$tmpLabel[$i]}</option>";
			else
				echo "<option value=$i>{$tmpLabel[$i]}</option>";
		}
		echo "</select>&nbsp";
	}
	else if($page_id == 2 || $page_id == 3)
	{
		$tmpLabel=array("Service","Trunk Group");
		echo "<select name=\"keyTwo\" onchange=\"javascript:add_trunk_text();\">";
		for($i=0;$i<sizeof($tmpLabel);$i++)
		{
			if($keyTwo == $i)
				echo "<option selected value=$i>{$tmpLabel[$i]}</option>";
			else
				echo "<option value=$i>{$tmpLabel[$i]}</option>";
		}
		echo "</select>&nbsp";
	}
}
else if($sysTypeNo == VSS_SYSTYPENO)
{
	if($page_id == 0)
	{
		echo "System ID <select name=\"keyTwo\" onchange=\"javascript:sel_date_from_change();\">";
		for($i=0;$i<10;$i++)
		{
			if($keyTwo == $i)
				echo "<option selected value=$i>{$i}</option>";
			else
				echo "<option value=$i>{$i}</option>";
		}
		echo "</select>&nbsp";
	}
}
else if($sysTypeNo == OPPS_SYSTYPENO)
{
	if($page_id == 0)
	{
		$serviceFlag=array(
			"00"=>"BothClose",
			"01"=>"IMDXOpen",
			"10"=>"OPROpen",
			"11"=>"BothOpen"
		);
		$oppsServiceStatus=getSystemState(375,86,2);
		if($serviceFlag[$oppsServiceStatus] == "OPROpen")
			$tmpLabel=array(0=>"OPR Registration",1=>"OPR Location Update",2=>"OPR Mode Switch");
		else if($serviceFlag[$oppsServiceStatus] == "IMDXOpen")
			$tmpLabel=array(0=>"IMDX MO",1=>"IMDX Location Update");
		else if($serviceFlag[$oppsServiceStatus] == "BothOpen")
			$tmpLabel=array(0=>"OPR Registration",1=>"OPR Location Update",2=>"OPR Mode Switch",3=>"IMDX MO",4=>"IMDX Location Update");
		else
		{
			$tmpLabel=array(0=>"None");
		}
		echo "Type&nbsp;<select name=\"keyTwo\" onchange=\"javascript:sel_date_from_change();\">";
		for($i=0;$i<sizeof($tmpLabel);$i++)
		{
			if($keyTwo == $i)
				echo "<option selected value=$i>{$tmpLabel[$i]}</option>";
			else
				echo "<option value=$i>{$tmpLabel[$i]}</option>";
		}
		echo "</select>&nbsp";
	}
}
else if($sysTypeNo == PALIM_SYSTYPENO)
{
	if($page_id == 1)
	{
		$tmpLabel=array("LU","Call MO","Call MT","SM MO","SM MT");
		echo "<select name=\"keyTwo\" onchange=\"javascript:sel_date_from_change();\">";
		for($i=0;$i<sizeof($tmpLabel);$i++)
		{
			if($keyTwo == $i)
				echo "<option selected value=$i>{$tmpLabel[$i]}</option>";
			else
				echo "<option value=$i>{$tmpLabel[$i]}</option>";
		}
		echo "</select>&nbsp";
	}
}
else if($sysTypeNo == 364)
{
	if($page_id == 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($pubConn,$sql);
		$podCount=mysqli_num_rows($result);

		if($podCount>0)
		{
       			while($rows = @mysqli_fetch_array($result))
        		{
           		     $pod_no=$rows[instanceNo]+0;
          		     $pod_status[$pod_no]=1;
                	     $pod_element_title[$pod_no]=$rows[initValue];
        		}
		}
	        if(1)
        	{
                	echo "<br>POD ID ";
                	echo "<select name=\"keyTwo\" onchange=\"javascript:sel_date_from_change;\">";
                	for($i=1;$i<sizeof($pod_element_title)+1;$i++)
                	{
				if($keyTwo == $i)
                        		echo "<option selected value=$i>{$pod_element_title[$i]}</option>";
				else
					echo "<option value=$i>{$pod_element_title[$i]}</option>";
                	}
                	echo "</select>&nbsp";
       		 }


	}//if page==1
}
else if($sysTypeNo == 362){
	echo "System ID <select name=\"keyTwo\" onchange=\"javascript:sel_date_from_change();\">";
	for($i=0;$i<2;$i++)
	{
		if($keyTwo == $i)
			echo "<option selected value=$i>{$i}</option>";
		else
			echo "<option value=$i>{$i}</option>";
	}
	echo "</select>&nbsp";
}
else if($sysTypeNo == 350){
	echo "SMPP <select name=\"keyTwo\" onchange=\"javascript:sel_date_from_change();\">";
	for($i=0;$i<64;$i++)
	{
		if($keyTwo == $i)
			echo "<option selected value=$i>{$i}</option>";
		else
			echo "<option value=$i>{$i}</option>";
	}
	echo "</select>&nbsp";
}
else
{
	echo "<input type=\"hidden\" name=\"keyTwo\" value=0>";
}

for($i=0;$i<$generalConf[MaxDay];$i++)
{
	$startDay[]=date("Y-m-d",mktime(0,0,0,date("m"),date("d")-$i,date("Y")));
}
//select day from
echo "<select name=\"sel_date_from\" onChange=\"javascript:sel_date_from_change();\">";
for($i=0;$i<$generalConf[MaxDay];$i++)
{
	if($i==$sel_date_from)
		echo "<option selected value=$i>{$startDay[$i]}</option>";			
	else
		echo "<option value=$i>{$startDay[$i]}</option>";
}
echo "</select>&nbsp;to&nbsp;";
//select day to
echo "<select name=\"sel_date_to\" onChange=\"javascript:sel_date_from_change();\">";
for($i=0;$i<=$sel_date_from;$i++)
{
	if($i==$sel_date_to)
		echo "<option selected value=$i>{$startDay[$i]}</option>";			
	else
		echo "<option value=$i>{$startDay[$i]}</option>";
}
echo "</select>&nbsp;";

if($sysTypeNo == MSC_SYSTYPENO)
{
	if($page_id == 2 || $page_id == 3)
	{
		echo "&nbsp;<input title=\"Input trunk group no. for drawing chart\" type=\"text\" name=\"trunk_text\" value=\"1,2\" class=\"text\" size=8 ";
		if($keyTwo == 1)
			echo ">";
		else
			echo "style=\"display:none;\">";
	}
}

//search button
echo "<span onClick=\"javascript:myform.submit()\" style=\"cursor:hand\">";
echo "<IMG align=absBottom border=0 src=\"../../images/search.gif\">$strSearch";
echo "</span>";
echo "</td>";
echo "<td align=\"right\">";
//export
if($sysTypeNo=="320"||$sysTypeNo=="350"){
echo "<a href=\"./downCDR.php?sysTypeNo=$sysTypeNo&show_type=$show_type&page_id=$page_id&sel_date_from=$sel_date_from&sel_date_to=$sel_date_to&isExport=1\">";
echo "<img  border=0 src=\"../../images/list.gif\" width=16 height=16>";
echo "</a>&nbsp;&nbsp;&nbsp;&nbsp;";
}
if($show_type == "hour")
{
	echo "<a target=\"_parent\" href=\"../../performance/generalCsta/general_csta_index.php?sysTypeNo=$sysTypeNo&show_type=day&page_id=$page_id&sel_date_from=$sel_date_from&sel_date_to=$sel_date_to&keyOne=$keyOne&keyTwo=$keyTwo\"><img src=\"../../images/left.gif\" border=0></img>back</a>";
}

?>
<span onClick="window.print();" style="cursor:hand">
	<img  border=0 src="../../images/printer.gif" width="16" height="16">
</span>
<?php
		
	echo "</td>";
	echo "</tr>";
	echo "</table>";
	
	echo "<input type=\"hidden\" name=\"sysTypeNo\" value=\"$sysTypeNo\">";
	echo "<input type=\"hidden\" name=\"show_type\" value=\"$show_type\">";
	echo "<input type=\"hidden\" name=\"page_id\" value=\"$page_id\">";
	echo "<input type=\"hidden\" name=\"keyOne\" value=\"$keyOne\">";
	
	echo "</form>";
adjust_title_tail_frame("up");
adjust_content_head_frame("up");
adjust_content_tail_frame("up");
?>
