<?php
require("../../inc/header.inc");
$helpId = "2.1.2.2"; 
$DEBUG = 0;
$sysInfoTable = 'OMC_PUB.sysInfo';
$DEFAULT_SYS = 'MSC'
?>
<?php
$sysTypeNo_1 = "322";

$db_1 = "OBJ_".$sysTypeNo_1;

$tb_0 = "param_0";
$tb_1 = "param_1";
$tb_2 = "param_99";

$maxNum = 20;

$nPubFlag = 99;
$nSubSysParam		= 0;
$nGlobalSubSysParam = 1;
$nGlobalSysParam	= 2;

$nGetComm = 0;
$nSetComm = 3;

$nInteger = 2;
$nOctStr = 4;

$nProcFail = 0;
$nWaitProc = 1;
$nInProc   = 2;	
$nOutProc  = 3;

//Prefix assignment
$oidPas = "2.1.1"; 
$pPas = explode(".",$oidPas);
$i = 0;
$wPas = '';
while(isset($pPas[$i]))
{
	$lNum = $i+1;
	if($DEBUG) echo "<br>pPas[$i]=$pPas[$i]";
	$wPas = $wPas." AND level_$lNum = $pPas[$i] ";
	$i++;
}
//echo "<br>wPas=$wPas";
//Prefix attributes
$oidPat = "2.1.2"; 
$pPat = explode(".",$oidPat);
$i = 0;
$wPat = '';
while(isset($pPat[$i]))
{
	$lNum = $i+1;
	if($DEBUG) echo "<br>pPat[$i]=$pPat[$i]";
	$wPat = $wPat." AND level_$lNum = $pPat[$i] ";
	$i++;
}
//echo "<br>wPat=$wPat";

//Assign TG to prefix
$oidTg = "2.1.3"; 
$pTg = explode(".",$oidTg);
$i = 0;
$wTg = '';
while(isset($pTg[$i]))
{
	$lNum = $i+1;
	if($DEBUG) echo "<br>pTg[$i]=$pTg[$i]";
	$wTg = $wTg." AND level_$lNum = $pTg[$i] ";
	$i++;
}
//echo "<br>wTg=$wTg";

$wAnd = " AND level_1 = 2 AND level_2 = 1 AND (level_3 = 1 OR level_3 = 2 OR level_3 = 3) "; 

/************get default value**************/
$defSql = " SELECT initValue,level_3 FROM paramConf WHERE keyId > 0 ".$wAnd." ORDER BY level_3 ";
$defRes = @mysqli_query($pubConn,$defSql);
$defRow = @mysqli_fetch_array($defRes);
do
{
	$leve_3 = $defRow[level_3];
	$defaultValue[$leve_3] = $defRow[initValue];
	//echo "<br>defaultValue[$leve_3]=$defaultValue[$leve_3]";
}while($defRow = @mysqli_fetch_array($defRes));

	$prefixFlagArr=array(
			array('num' => '0',  'remark' => 'N', 'color' => '#FF0000'),
			array('num' => '1',  'remark' => 'Y', 'color' => '#0000FF')
	);
	$inTonArr=array(
			array('num' => '0',  'remark' => 'Spare',		'color' => '#FF0000'),
			array('num' => '1',  'remark' => 'SUB',		'color' => '#0000FF'),
			array('num' => '2',  'remark' => 'UNK',			'color' => '#0000FF'),
			array('num' => '3',  'remark' => 'NDD',			'color' => '#0000FF'),
			array('num' => '4',  'remark' => 'IDD',			'color' => '#0000FF'),
			array('num' => '5',  'remark' => 'Spare',		'color' => '#0000FF')
	);

	$outTonArr=array(
			array('num' => '0',  'remark' => 'Spare',		'color' => '#FF0000'),
			array('num' => '1',  'remark' => 'SUB',		'color' => '#0000FF'),
			array('num' => '2',  'remark' => 'UNK',			'color' => '#0000FF'),
			array('num' => '3',  'remark' => 'NDD',			'color' => '#0000FF'),
			array('num' => '4',  'remark' => 'IDD',			'color' => '#0000FF'),
			array('num' => '5',  'remark' => 'Spare',		'color' => '#0000FF')
	);
	
	$cdrFlagArr=array(
			array('num' => '0',  'remark' => 'Off', 'color' => '#FF0000'),
			array('num' => '1',  'remark' => 'On', 'color' => '#0000FF')
	);

if($DEFAULT_SYS == 'MSC'){
	$proTypeArr=array(
			array('num' => '0',  'remark' => 'Trunk',		'color' => '#FF0000'),
			array('num' => '1',  'remark' => 'MSISDN',		'color' => '#0000FF'),
			array('num' => '2',  'remark' => 'MSRN',		'color' => '#0000FF'),
			array('num' => '3',  'remark' => 'MSC',			'color' => '#0000FF')
	);
	$callTypeArr=array(
			array('num' => '0',  'remark' => 'Normal Call',		'color' => '#FF0000'),
			array('num' => '1',  'remark' => 'Emergency',			'color' => '#0000FF'),
			array('num' => '2',  'remark' => 'MCT',			'color' => '#FF0000'),
			array('num' => '3',  'remark' => 'IP',			'color' => '#0000FF'),
			array('num' => '4',  'remark' => 'IN',			'color' => '#0000FF'),
			array('num' => '5',  'remark' => 'FC',			'color' => '#0000FF'),
			array('num' => '4',  'remark' => 'Free Call',			'color' => '#0000FF'),

	);	
}else{
	$proTypeArr=array(
			array('num' => '0',  'remark' => 'Trunk',		'color' => '#FF0000'),
			array('num' => '1',  'remark' => 'PBX',		'color' => '#0000FF'),
			array('num' => '2',  'remark' => 'SUB',		'color' => '#0000FF'),
			array('num' => '3',  'remark' => '--',			'color' => '#0000FF')
	);
	$callTypeArr=array(
			array('num' => '0',  'remark' => 'Normal',		'color' => '#FF0000'),
			array('num' => '1',  'remark' => 'EM',			'color' => '#0000FF'),
			array('num' => '2',  'remark' => 'MCT',			'color' => '#FF0000'),
			array('num' => '3',  'remark' => 'VMS',			'color' => '#0000FF'),
			array('num' => '4',  'remark' => 'IN',			'color' => '#0000FF')

	);	
}


	$tgTypeArr=array(
			array('num' => '0',  'remark' => 'PSTN',		'color' => '#FF0000'),
			array('num' => '1',  'remark' => 'HPLMN',	'color' => '#0000FF'),
			array('num' => '2',  'remark' => 'VPLMN',	'color' => '#0000FF'),
			array('num' => '3',  'remark' => 'subscriber',	'color' => '#0000FF'),
			array('num' => '4',  'remark' => '--',			'color' => '#0000FF')
	);

	$camelFlagArr=array(
			array('num' => '0',  'remark' => 'N', 'color' => '#FF0000'),
			array('num' => '1',  'remark' => 'Y', 'color' => '#0000FF')
	);

	$cliTypeArr = array(
		array('num' => '0', 'remark' => 'Sub', 'color' => '#0000FF'),
		array('num' => '1', 'remark' => 'NDD', 'color' => '#0000FF'),
		array('num' => '2', 'remark' => 'IDD', 'color' => '#0000FF'),
		array('num' => '3', 'remark' => 'UNK(local)', 'color' => '#0000FF'),
		array('num' => '4', 'remark' => 'UNK(NDD)', 'color' => '#0000FF'),
		array('num' => '5', 'remark' => 'UNK(IDD)', 'color' => '#0000FF')
	);


/************select value to see************/
//Attributes of TG

$andSql = " SELECT level_3,instanceNo,initValue,readValue FROM $tb_2 WHERE subSysNo = '99' ".$wAnd." ORDER BY instanceNo "; 
if($DEBUG) echo "<br>andSql=$andSql";
$andRes = @mysqli_query($pubConn,$andSql);
$andRow = @mysqli_fetch_array($andRes);
echo mysqli_error($pubConn);

do
{
	$level_3 = $andRow[level_3];
	$instanceNo = $andRow[instanceNo];
	$initValue = $andRow[initValue];
	//echo "<br>initValue=$initValue";
	
	if($initValue == $defaultValue[$level_3]){
		$andShow[$level_3][$instanceNo] = 0;
	}else{
		$andShow[$level_3][$instanceNo] = 1;
	}
	//echo "<br>andShow[$level_3][$instanceNo]={$andShow[$level_3][$instanceNo]}";
	
	if($level_3 == 1){
		$prefixNum = $initValue;
		$pNum = explode("E",$prefixNum);
		$prefixNum=$prefixArr[$instanceNo][1] = $pNum[0];
		//echo "<br>prefixArr[$instanceNo][1]={$prefixArr[$instanceNo][1]}";
	}elseif($level_3 == 2){
		$DEBUG = 0;
		$hex_0 = substr($initValue,0,2);
		if($DEBUG)echo "<br>hex_0=$hex_0";
		$bin_0 = omc_keep_length(DecBin(HexDec($hex_0)),0,8);
		if($DEBUG)echo "<br>bin_0=$bin_0";
		
		$inTon = $prefixArr[$instanceNo][2] = BinDec(substr($bin_0,4,4));
		//echo "<br>inTon=$inTon";
		
		$outTon = $prefixArr[$instanceNo][3] = BinDec(substr($bin_0,0,4));
		//echo "<br>outTon=$outTon";
		
		$hex_1 = substr($initValue,2,2);
		if($DEBUG)echo "<br>hex_1=$hex_1";
		$bin_1 = omc_keep_length(DecBin(HexDec($hex_1)),0,8);
		if($DEBUG)echo "<br>bin_1=$bin_1";
		
		$trkDelC = $prefixArr[$instanceNo][4] = BinDec(substr($bin_1,4,4));
		if($DEBUG)echo "<br>trkDelC=$trkDelC";
		
		$trkInsC = $prefixArr[$instanceNo][5] = BinDec(substr($bin_1,0,4));
		if($DEBUG)echo "<br>trkInsC=$trkInsC";
		
		$trkInsD  = substr($initValue,4,16);
		$pTrk = explode("E",$trkInsD);
		$trkInsD = $prefixArr[$instanceNo][6] = $pTrk[0];
		if($DEBUG)echo "<br>trkInsD=$trkInsD";

		$hex_6 = substr($initValue,20,2);
		if($DEBUG)echo "<br>hex_6=$hex_6";
		$bin_6 = omc_keep_length(DecBin(HexDec($hex_6)),0,8);
		if($DEBUG)	echo "<br>bin_6=$bin_6";
		
		$cdrFlag = $prefixArr[$instanceNo][7] = BinDec(substr($bin_6,7,1));
		if($DEBUG)echo "<br>cdrFlag=$cdrFlag";
		
		$proType = $prefixArr[$instanceNo][8] = BinDec(substr($bin_6,4,2));
		if($DEBUG)echo "<br>proType=$proType";

		$callType = $prefixArr[$instanceNo][9] = BinDec(substr($bin_6,1,3));
		if($DEBUG)echo "<br>callType=$callType";

		$prefixFlag = $prefixArr[$instanceNo][0] = BinDec(substr($bin_6,0,1));
		if($DEBUG)echo "<br>prefixFlag=$prefixFlag";

		$dLen = $prefixArr[$instanceNo][10] = HexDec(substr($initValue,22,2));
		if($DEBUG)echo "<br>dLen=$dLen";

		$hex_8 = substr($initValue,24,2);
		if($DEBUG)echo "<br>hex_8=$hex_8";
		$bin_8 = omc_keep_length(DecBin(HexDec($hex_8)),0,8);
		if($DEBUG)echo "<br>bin_8=$bin_8";
		
		$eDelC = $prefixArr[$instanceNo][11] = BinDec(substr($bin_8,4,4));
		if($DEBUG)echo "<br>eDelC=$eDelC";
		
		$eInsC = $prefixArr[$instanceNo][12] = BinDec(substr($bin_8,0,4));
		if($DEBUG)echo "<br>eInsC=$eInsC";

		$eInsD  = substr($initValue,26,8);
		$pTrk = explode("E",$eInsD);
		$eInsD = $prefixArr[$instanceNo][13] = $pTrk[0];
		if($DEBUG)echo "<br>eInsD=$eInsD";

		$cliType	= $prefixArr[$instanceNo][15]	= hexdec(substr($initValue,34,2));
		if($DEBUG) echo "cliType = $cliType<br>";
	}else{
		$tgNum = $prefixArr[$instanceNo][14] = HexDec($initValue);
		//echo "<br>prefixArr[$instanceNo][14]={$prefixArr[$instanceNo][14]}";
	}
}while($andRow = @mysqli_fetch_array($andRes));

$wDef = " AND (";

//for($i=0;$i<256;$i++)
for($i=0;$i<1024;$i++)
{
	if($andShow[1][$i] > 0 || $andShow[2][$i] > 0 || $andShow[3][$i] > 0){
		$realShow[$i] = 1;
		//echo "<br>realShow[$i]=$realShow[$i]";
		$wDef = $wDef." instanceNo = $i OR ";
	}
}
$wDef = substr($wDef,0,-3);
$wDef = $wDef.")";
if(strlen($wDef) < 10){
	$wDef = ' AND instanceNo < 0 ';
}
//echo "<br>wDef=$wDef";
//$realShow[0] = "1";

$scroll_x = isset($scroll_x)?$scroll_x:'0';
$scroll_y = isset($scroll_y)?$scroll_y:'0';
echo "<body onLoad='self.scrollBy($scroll_x,$scroll_y)'>";
echo "<form method=\"POST\" name=\"confForm\" action=\"$PHP_SELF\">";
?>
<?php
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=\"#\">Prefix 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>";
?>
<table border="0" cellpadding="0" cellspacing="0" width="100%">           
    <tr>    
	<?php
		//echo "<input type=\"submit\" class=\"button\" value=$strGet name=\"readSys\" style=\"left: 1; top: 2; width: 60; height: 25; position: relative\">";
	?>
	 </tr>   
</table>         
</form>

       
<TABLE  rules=rows border="1" width="100%" cellpadding="2" cellspacing="0" bordercolor="#666666" bordercolordark="#FFFFFF" bgcolor="#FFFFFF">     
<tr bgcolor="#E6E6E6">
<td>No.</td>     
<td><nobr>Prefix</nobr></td>     
<td><nobr>In-TON</nobr></td> 
<td><nobr>Out-TON</nobr></td>     
<td title="Out trunk deletion count"><nobr>T-D-C</nobr></td>
<td title="Out trunk insertion count"><nobr>T-I-C</nobr></td>     
<td title="Out trunk inserted digits"><nobr>T-I-D</nobr></td>
<td><nobr>CDR</nobr</td>
<td><nobr>Properties</nobr</td>     
<td><nobr>Call type</nobr</td>  
<td><nobr>Digit-L</nobr</td>  
<td title="MAP deletion count "><nobr>M-D-C</nobr</td>   
<td title="MAP insertion count "><nobr>M-I-C</nobr</td>   
<td title="MAP inserted digits "><nobr>M-I-D</nobr</td>   
<td><nobr>TG</nobr</td>
<td><nobr>CLI</nobr</td>   
</tr>
<?php
//for($i=0;$i<256;$i++)
for($i=0;$i<1024;$i++)
{
	if($prefixFlagArr[$prefixArr[$i][0]][remark] == 'N') continue;
	
	$sNum = floor($i/8);
	$pNum = floor($i%8);
	
	
	if($realShow[$i]){
		
			echo "<tr onMouseOver=\"this.bgColor='#D2F0FF'\" onMouseOut=\"this.bgColor='#ffffff'\">";


		echo "<td>$i</td>";
		echo "<td><nobr>{$prefixArr[$i][1]}&nbsp;</nobr></td>";		
		echo "<td><nobr>{$inTonArr[$prefixArr[$i][2]][remark]}&nbsp;</nobr></td>";
		echo "<td><nobr>{$outTonArr[$prefixArr[$i][3]][remark]}&nbsp;</nobr></td>";
		echo "<td><nobr>{$prefixArr[$i][4]}&nbsp;</nobr></td>";
		echo "<td><nobr>{$prefixArr[$i][5]}&nbsp;</nobr></td>";
		echo "<td><nobr>{$prefixArr[$i][6]}&nbsp;</nobr></td>";
		echo "<td><nobr>{$cdrFlagArr[$prefixArr[$i][7]][remark]}&nbsp;</nobr></td>";
		echo "<td><nobr>{$proTypeArr[$prefixArr[$i][8]][remark]}&nbsp;</nobr></td>";
		echo "<td><nobr>{$callTypeArr[$prefixArr[$i][9]][remark]}&nbsp;</nobr></td>";
		echo "<td><nobr>{$prefixArr[$i][10]}&nbsp;</nobr></td>";		
		echo "<td><nobr>{$prefixArr[$i][11]}&nbsp;</nobr></td>";
		echo "<td><nobr>{$prefixArr[$i][12]}&nbsp;</nobr></td>";
		echo "<td><nobr>{$prefixArr[$i][13]}&nbsp;</nobr></td>";
		echo "<td><nobr>{$prefixArr[$i][14]}&nbsp;</nobr></td>";
		echo "<td><nobr>{$cliTypeArr[$prefixArr[$i][15]][remark]}&nbsp;</nobr></td>";
		echo "</tr>";

	}
}
echo "</table>";
echo "<input type=\"hidden\" name=\"wDef\" value=\"$wDef\">";
echo "</form>";
?>
</body>
</html>
