<?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=\"#\">Convert 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>Convert overview:</b><br>";


	//===============================get the default value of Prefix manipulation==============================
	$database="OBJ_225";
	$sql="select initValue from paramConf where level_1=2 and level_2=8 ";
	$result=@mysqli_query($pubConn,$sql);
	$rows=@mysqli_fetch_array($result);
	$default_initValue=$rows[initValue];
	//echo "default_initValue:$default_initValue<br>";
	//================================data init===================================================
	for($i=0;$i<128;$i++)
	{
		$prefix_show[$i]=0;
		$prefix_prefix[$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=8 ";
	$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)
			$prefix_show[$instanceNo]=1;
		//====prefix
		$prefix_prefix[$instanceNo]=getBitValue($rows[initValue],'0.0-15.7');	
		//echo "prefix:{$prefix_prefix[$i]}<br>";
		//=====Deletion Count
		$prefix_deletion_count[$instanceNo]=hexdec(getBitValue($rows[initValue],'16.0-16.7'));	
		//======Insertion Count
		$prefix_insertion_count[$instanceNo]=hexdec(getBitValue($rows[initValue],'17.0-17.7'));	
		//======Inserted Digits
		$prefix_inserted_digits[$instanceNo]=getBitValue($rows[initValue],'18.0-33.7');	
		//=======Number Length
		$prefix_number_length[$instanceNo]=hexdec(getBitValue($rows[initValue],'34.0-34.7'));	
		//======Name
		$prefix_name[$instanceNo]=getBitValue($rows[initValue],'35.0-42.7');	
		
		
		//echo "instanceNo:$instanceNo----initValue:$initValue<br>";
	}while($rows=mysqli_fetch_array($result));


	//==================format the data========================
	
	for($i=0;$i<128;$i++)
	{
		
		//=======prefix
		$temp="";
		for($num=0;$num<16;$num++)
		{
			$str=substr($prefix_prefix[$i],$num*2,2);
			$str=hexdec($str);
			$str=chr($str);
			$temp.=$str;
		}
		$prefix_prefix[$i]=$temp;
		//======Inserted Digits
		$temp="";
		for($num=0;$num<16;$num++)
		{
			$str=substr($prefix_inserted_digits[$i],$num*2,2);
			$str=hexdec($str);
			$str=chr($str);
			$temp.=$str;
		}
		$prefix_inserted_digits[$i]=$temp;
		
		
		//======Name
		$temp="";
		for($num=0;$num<8;$num++)
		{
			$str=substr($prefix_name[$i],$num*2,2);
			$str=hexdec($str);
			$str=chr($str);
			$temp.=$str;
		}
		$prefix_name[$i]=$temp;
		
	}
	
	//====================test======================
	/*
	for($i=0;$i<128;$i++)
	{
		echo "<hr>";
		echo "instanceNo:$i<br>";
		echo "prefix_show:{$prefix_show[$i]}<br>";
		echo "prefix:{$prefix_prefix[$i]}<br>";
		echo "deletion_count:{$prefix_deletion_count[$i]}<br>";
		echo "insertion_count:{$prefix_insertion_count[$i]}<br>";
		echo "inserted_digits:{$prefix_inserted_digits[$i]}<br>";
		echo "number_length:{$prefix_number_length[$i]}<br>";
		echo "name:{$prefix_name[$i]}<br>";	
		echo "<hr>";
	}
	*/
	
	//===============================sort by the name================================
	//echo "sort_flag:$name_sort_flag<br>";
	if($name_sort_flag==1)
	{
		echo "<table border=\"1\" width=\"100%\" cellpadding=\"1\" cellspacing=\"0\" bordercolor=\"#666666\" bordercolordark=\"#FFFFFF\">";
		echo "<tr bgcolor=\"#E6E6E6\">";
			echo "<td><a href=\"../../element/mss/convert_overview.php\">No.</td>";
			echo "<td>Prefix</td><td>Deletion Count</td><td>Insertion Count</td><td>Inserted Digits</td><td>Number Length</td>";
			echo "<td><a href=\"../../element/mss/convert_overview.php?name_sort_flag=1\">Name</d>";
		echo "</tr>";
			
			
		arsort($prefix_name,SORT_STRING);
		
		foreach($prefix_name as $key => $value)
		{
			if($prefix_show[$key]==0)
				echo "<tr style=\"display:none\">";
			else	
				echo "<tr>";
				
				
				$tmp=trim($prefix_prefix[$key]);
				if($tmp=="")
					echo "<td>--</td>";
				else	
					echo "<td>$tmp</td>";
					
				$tmp=trim($prefix_deletion_count[$key]);
				if($tmp=="")
					echo "<td>--</td>";
				else	
					echo "<td>$tmp</td>";	
				
				$tmp=trim($prefix_insertion_count[$key]);
				if($tmp=="")
					echo "<td>--</td>";
				else	
					echo "<td>$tmp</td>";	
					
				$tmp=trim($prefix_inserted_digits[$key]);
				if($tmp=="")
					echo "<td>--</td>";
				else	
					echo "<td>$tmp</td>";	
					
				$tmp=trim($prefix_number_length[$key]);
				if($tmp=="")
					echo "<td>--</td>";
				else	
					echo "<td>$tmp</td>";	
				
				$tmp=trim($prefix_name[$key]);
				if($tmp=="")
					echo "<td>--</td>";
				else	
					echo "<td>$tmp</td>";	
					
				/*
				echo "<td>$key</td>";
				echo "<td>&nbsp$prefix_prefix[$key]</td>";
				echo "<td>&nbsp$prefix_deletion_count[$key]</td>";
				echo "<td>&nbsp$prefix_insertion_count[$key]</td>";		
				echo "<td>&nbsp$prefix_inserted_digits[$key]</td>";
				echo "<td>&nbsp$prefix_number_length[$key]</td>";
				echo "<td>&nbsp$prefix_name[$key]</td>";
				*/
			echo "</tr>";
			
		}
		
		
		
		
	}
	else
	{
		//===========================show the table================================
		echo "<table border=\"1\" width=\"100%\" cellpadding=\"1\" cellspacing=\"0\" bordercolor=\"#666666\" bordercolordark=\"#FFFFFF\">";
		echo "<tr bgcolor=\"#E6E6E6\">";
			echo "<td><a href=\"../../element/mss/convert_overview.php\">No.</td>";
			echo "<td>Prefix</td><td>Deletion Count</td><td>Insertion Count</td><td>Inserted Digits</td><td>Number Length</td>";
			echo "<td><a href=\"../../element/mss/convert_overview.php?name_sort_flag=1\">Name</d>";
		echo "</tr>";
		for($i=0;$i<128;$i++)
		{
			if($prefix_show[$i]==0)
				echo "<tr style=\"display:none\">";
			else	
				echo "<tr>";
				
				echo "<td>$i</td>";
				
				$tmp=trim($prefix_prefix[$i]);
				if($tmp=="")
					echo "<td>--</td>";
				else	
					echo "<td>$tmp</td>";
					
				$tmp=trim($prefix_deletion_count[$i]);
				if($tmp=="")
					echo "<td>--</td>";
				else	
					echo "<td>$tmp</td>";	
				
				$tmp=trim($prefix_insertion_count[$i]);
				if($tmp=="")
					echo "<td>--</td>";
				else	
					echo "<td>$tmp</td>";	
					
				$tmp=trim($prefix_inserted_digits[$i]);
				if($tmp=="")
					echo "<td>--</td>";
				else	
					echo "<td>$tmp</td>";	
					
				$tmp=trim($prefix_number_length[$i]);
				if($tmp=="")
					echo "<td>--</td>";
				else	
					echo "<td>$tmp</td>";	
				
				$tmp=trim($prefix_name[$i]);
				if($tmp=="")
					echo "<td>--</td>";
				else	
					echo "<td>$tmp</td>";	
				
				
				/*
				echo "<td>&nbsp$prefix_prefix[$i]</td>";
				echo "<td>&nbsp$prefix_deletion_count[$i]</td>";
				echo "<td>&nbsp$prefix_insertion_count[$i]</td>";		
				echo "<td>&nbsp$prefix_inserted_digits[$i]</td>";
				echo "<td>&nbsp$prefix_number_length[$i]</td>";
				echo "<td>&nbsp$prefix_name[$i]</td>";
				*/
			echo "</tr>";
		}
		echo "</table>";
	}
	
echo "</form>";
?>
