<?php
require("../sub_inc/commfunc.php");
?>
<?php
echo "<body>";
echo "<form method=\"POST\" name=\"confForm\" action=\"$PHP_SELF\">";
echo "<table border=\"0\" width=\"100%\">";
echo "<tr>";
echo "<td width=\"50%\">";
echo "Configuration > <a href=\"../overview/overview.php?scroll_y=1000\">Network</a> > <a href=\"#\">Element overview</a>";
echo "</td>";
echo "<td width=\"50%\" align=\"right\" title=\"Help\">";
//showHelp($helpId);
echo "</td>";
echo "<td>";
echo "<p align=\"right\"><a href=\"../../element/overview/overview.php?scroll_y=1000\"><img align=absBottom border=0 src=\"../../images/left.gif\" width=\"14\" height=\"14\">$strBack</a>";
echo "</td></tr>";
echo "</table>";

echo "<br>";
//echo "<b>Element overview:</b><br>";



//===============================get the default value of XAPP element info==============================
	$database="OBJ_225";
	$sql="select initValue from paramConf where level_1=2 and level_2=11 ";
	$result=@mysqli_query($pubConn,$sql);
	$rows=@mysqli_fetch_array($result);
	$default_initValue=$rows[initValue];
	//echo "default_initValue:$default_initValue<br>";
//===============================init====================================================	
	for($i=0;$i<128;$i++)
	{
		$xapp_show[$i]=0;
		
	}
	
	//===============================get the data from OBJ_225 param_99===========================
	$database="OBJ_225";
	$sql="select instanceNo,initValue from param_99 where level_1=2 and level_2=11 ";
	$result=@mysqli_query($pubConn,$sql);
	$rows=@mysqli_fetch_array($result);
	do
	{
		//====instance No
		$instanceNo=$rows[instanceNo];
		$initValue=$rows[initValue];
		//====show or no
		if($initValue!=$default_initValue)
			$xapp_show[$instanceNo]=1;
		//====device type
		$xapp_deviceType[$instanceNo]=hexdec(getBitValue($rows[initValue],'1.0-1.7'))+0;
		//=====sysNo
		$xapp_sysNo[$instanceNo]=hexdec(getBitValue($rows[initValue],'2.0-2.3'))+0;
		//======subSysNo
		$xapp_subSysNo[$instanceNo]=hexdec(getBitValue($rows[initValue],'2.4-2.7'))+0;
		//======assign tg
		$xapp_assign_tg[$instanceNo]=hexdec(getBitValue($rows[initValue],'3.0-3.7'))+0;
		//======assign linkset
		$xapp_assign_linkset[$instanceNo]=hexdec(getBitValue($rows[initValue],'4.0-4.7'))+0;
		//======application type
		$xapp_application_type[$instanceNo]=hexdec(getBitValue($rows[initValue],'5.0-5.7'))+0;
		//=======grp no
		$xapp_grp_no[$instanceNo]=hexdec(getBitValue($rows[initValue],'6.0-6.7'))+0;
		//=======title
		$xapp_title[$instanceNo]=getBitValue($rows[initValue],'14.0-23.7');
		//echo "{$xapp_title[$instanceNo]}<br>";
	}while($rows=mysqli_fetch_array($result));
	
	//========================format the data================================================
	$device_type_label=array(1=>"BSC",2=>"AAS",3=>"VSS",4=>"PCR",5=>"CNF",16=>"Switch(SS7)",17=>"switch(ISDN)",18=>"Application");
	$application_type_label=array(0=>"MSC",1=>"HLR",2=>"VLR",3=>"SMSC",4=>"SGSN",5=>"NewElement");
	for($i=0;$i<256;$i++)
	{
		
		//=======device type
		$xapp_deviceType[$i]=$device_type_label[$xapp_deviceType[$i]];
		//=======application type
		$xapp_application_type[$i]=$application_type_label[$xapp_application_type[$i]];
		//=======element title	
		$temp="";
		for($num=0;$num<10;$num++)
		{
			$str=substr($xapp_title[$i],$num*2,2);
			$str=hexdec($str);
			$str=chr($str);
			$temp.=$str;
		}
		$xapp_title[$i]=$temp;
		
	}
	
	
	//====================================test==============================================
	/*
	for($i=0;$i<256;$i++)
	{
		echo "<hr>";
		echo "instanceNo---$i<br>";
		echo "device type---{$xapp_deviceType[$i]}<br>";
		echo "sysNo---{$xapp_sysNo[$i]}<br>";
		echo "subSysNo---{$xapp_subSysNo[$i]}<br>";
		echo "assign tg---{$xapp_assign_tg[$i]}<br>";
		echo "assign linkset---{$xapp_assign_linkset[$i]}<br>";
		echo "application type---{$xapp_application_type[$i]}<br>";
		echo "grp no---{$xapp_application_type[$i]}<br>";
		echo "title---{$xapp_title[$i]}<br>";
		echo "<hr>";
	}
	*/
	
	//====================================show the table====================================
	//0 by instanceNo 
	//1 by device type
	//2 by application type
	if(!isset($sort_type))
		$sort_type=0;
		
		
	echo "<table border=\"1\" width=\"100%\" cellpadding=\"1\" cellspacing=\"0\" bordercolor=\"#666666\" bordercolordark=\"#FFFFFF\">";
		echo "<tr bgcolor=\"#E6E6E6\">";
			echo "<td><a href=\"../../element/mss/xapp_overview.php?sort_type=0\">No.</a></td>";
			echo "<td><a href=\"../../element/mss/xapp_overview.php?sort_type=1\">Device Type</a></td>";
			echo "<td>System No.</td><td>Subsystem No.</td><td>Assign TG</td><td>Assign Linkset</td>";
			echo "<td><a href=\"../../element/mss/xapp_overview.php?sort_type=2\">Application Type</a></d>";
			echo "<td>Grp No.</td><td>Element Title</td>";
		echo "</tr>";
	

		
	if($sort_type==0)
	{
		for($i=0;$i<256;$i++)
		{
			if($xapp_show[$i]==0)
				echo "<tr style=\"display:none\">";
			else	
				echo "<tr>";
				
				echo "<td>$i</td>";
				
				if(trim($xapp_deviceType[$i])=="")
					echo "<td>--</td>";
				else	
					echo "<td>$xapp_deviceType[$i]</td>";
					
				if(trim($xapp_sysNo[$i])=="")
					echo "<td>--</td>";
				else	
					echo "<td>$xapp_sysNo[$i]</td>";
					
				if(trim($xapp_subSysNo[$i])=="")
					echo "<td>--</td>";
				else	
					echo "<td>$xapp_subSysNo[$i]</td>";
				
				if(trim($xapp_assign_tg[$i])=="")
					echo "<td>--</td>";
				else	
					echo "<td>$xapp_assign_tg[$i]</td>";	
						
				if(trim($xapp_assign_linkset[$i])=="")
					echo "<td>--</td>";
				else	
					echo "<td>$xapp_assign_linkset[$i]</td>";	
				
				if(trim($xapp_application_type[$i])=="")
					echo "<td>--</td>";
				else	
					echo "<td>$xapp_application_type[$i]</td>";	
				
				if(trim($xapp_grp_no[$i])=="")
					echo "<td>--</td>";
				else	
					echo "<td>$xapp_grp_no[$i]</td>";	
				
				if(trim($xapp_title[$i])=="")
					echo "<td>--</td>";
				else	
					echo "<td>$xapp_title[$i]</td>";
				
				
			echo "</tr>";
		}
		echo "</table>";
	}
	else if($sort_type==1)
	{
		arsort($xapp_deviceType,SORT_STRING);
		
		foreach($xapp_deviceType as $key => $value)
		{
			if($xapp_show[$key]==0)
				echo "<tr style=\"display:none\">";
			else	
				echo "<tr>";
				
				echo "<td>$key</td>";
				echo "<td>&nbsp$xapp_deviceType[$key]</td>";
				echo "<td>&nbsp$xapp_sysNo[$key]</td>";
				echo "<td>&nbsp$xapp_subSysNo[$key]</td>";		
				echo "<td>&nbsp$xapp_assign_tg[$key]</td>";
				echo "<td>&nbsp$xapp_assign_linkset[$key]</td>";
				echo "<td>&nbsp$xapp_application_type[$key]</td>";
				echo "<td>&nbsp$xapp_grp_no[$key]</td>";
				echo "<td>&nbsp$xapp_title[$key]</td>";
			echo "</tr>";
			
		}
	}
	else if($sort_type==2)	
	{
		arsort($xapp_application_type,SORT_STRING);
		
		foreach($xapp_application_type as $key => $value)
		{
			if($xapp_show[$key]==0)
				echo "<tr style=\"display:none\">";
			else	
				echo "<tr>";
				
				echo "<td>$key</td>";
				echo "<td>&nbsp$xapp_deviceType[$key]</td>";
				echo "<td>&nbsp$xapp_sysNo[$key]</td>";
				echo "<td>&nbsp$xapp_subSysNo[$key]</td>";		
				echo "<td>&nbsp$xapp_assign_tg[$key]</td>";
				echo "<td>&nbsp$xapp_assign_linkset[$key]</td>";
				echo "<td>&nbsp$xapp_application_type[$key]</td>";
				echo "<td>&nbsp$xapp_grp_no[$key]</td>";
				echo "<td>&nbsp$xapp_title[$key]</td>";
			echo "</tr>";
			
		}
	}
		
		
?>
