<?php
require("../sub_inc/commfunc.php");
$helpId = "2.1.2.4"; 
$DEBUG = 0;
$sysInfoTable = 'OMC_PUB.sysInfo';
?>

<?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;

//Attributes of TG
$oidTg = "2.1.4"; 
$pTg = explode(".",$oidTg);
$i = 0;
$wTg = getLevelWhere($oidTg);
/************get default value**************/
$defSql = " SELECT initValue FROM paramConf WHERE $wTg and keyId > 0 ";
$defRes = @mysqli_query($pubConn,$defSql);
$defRow = @mysqli_fetch_array($defRes);
$defaultValue = $defRow[initValue];
//echo "<br>defaultValue=$defaultValue";

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

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

	$incomingCallTypeArr=array(
			array('num' => '0',  'remark' => 'Normal', 'color' => '#FF0000'),
			array('num' => '1',  'remark' => 'In', 'color' => '#0000FF')
	);

	$cdrFlagArr=array(
			array('num' => '0',  'remark' => 'Off', 'color' => '#FF0000'),
			array('num' => '1',  'remark' => 'On', 'color' => '#0000FF')
	);

	$voFlagArr=array(
			array('num' => '0',  'remark' => 'Off', 'color' => '#FF0000'),
			array('num' => '1',  'remark' => 'On', 'color' => '#0000FF')
	);

if($DEFAULT_SYS == 'MSC'){
	$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' => 'SUB',			'color' => '#0000FF'),
			array('num' => '4',  'remark' => 'IP',			'color' => '#0000FF'),
			array('num' => '5',  'remark' => 'Intercept',	'color' => '#0000FF'),
			array('num' => '6',  'remark' => 'Interconnection',	'color' => '#0000FF'),
	);
}else{
	$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' => 'SUB',			'color' => '#0000FF'),
			array('num' => '4',  'remark' => 'IP',			'color' => '#0000FF'),
			//array('num' => '5',  'remark' => 'GP',			'color' => '#0000FF'),
			array('num' => '5',  'remark' => 'Intercept',	'color' => '#0000FF'),			
			array('num' => '6',  'remark' => 'Interconnection',	'color' => '#0000FF'),
	);
}
	$atFlagArr=array(
			array('num' => '0',  'remark' => 'N', 'color' => '#FF0000'),
			array('num' => '1',  'remark' => 'Y', 'color' => '#0000FF')
	);

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

	$netTypeArr=array(
			array('num' => '0',  'remark' => 'INT',		'color' => '#FF0000'),
			array('num' => '1',  'remark' => 'INT-S',	'color' => '#0000FF'),
			array('num' => '2',  'remark' => 'NAT',			'color' => '#0000FF'),
			array('num' => '3',  'remark' => 'NAT-S',		'color' => '#0000FF'),
			array('num' => '4',  'remark' => '--',					'color' => '#0000FF')
	);

	$cirTypeArr=array(
			array('num' => '0',  'remark' => 'Clockwise',		'color' => '#FF0000'),
			array('num' => '1',  'remark' => 'Anti-C',	'color' => '#0000FF'),
			array('num' => '2',  'remark' => 'Odd',				'color' => '#0000FF'),
			array('num' => '3',  'remark' => 'Even',			'color' => '#0000FF'),
			array('num' => '4',  'remark' => '--',				'color' => '#0000FF')
	);

	$backFlagArr=array(
			array('num' => '0',  'remark' => 'Off', 'color' => '#FF0000'),
			array('num' => '1',  'remark' => 'On', 'color' => '#0000FF')
	);

if($DEFAULT_SYS == 'MSC'){
	$tgLocationArr=array(
			array('num' => '0',  'remark' => 'MSC-0', 'color' => '#FF0000'),
			array('num' => '1',  'remark' => 'MSC-1', 'color' => '#0000FF'),
			array('num' => '2',  'remark' => 'Both',  'color' => '#FF0000'),
			array('num' => '3',  'remark' => 'Spare', 'color' => '#0000FF')
	);
}else{
	$tgLocationArr=array(
			array('num' => '0',  'remark' => 'MSC-0', 'color' => '#FF0000'),
			array('num' => '1',  'remark' => 'MSC-1', 'color' => '#0000FF'),
			array('num' => '2',  'remark' => 'Both',  'color' => '#FF0000'),
			array('num' => '3',  'remark' => 'Spare', 'color' => '#0000FF')
	);
}


/************select value to see************/
//Attributes of TG
$tgSql = " SELECT instanceNo,initValue,readValue FROM $tb_2 
		WHERE subSysNo = '99' and $wTg and initValue!='$defaultValue' ORDER BY instanceNo"; 
if($DEBUG) 
echo "<br>tgSql=$tgSql";
$tgRes = @mysqli_query($pubConn,$tgSql);
echo mysqli_error($pubConn);
$wDef = " AND (";
$defaultValue_1 = "000000000A0382FF00";
$tgNo=0;
while($tgRow = @mysqli_fetch_array($tgRes))
{
	$tgArr[$tgNo][inst] = $tgRow[instanceNo];
	$initValue = $tgRow[initValue];
	$wDef = $wDef." instanceNo = $tgNo OR ";
	
	//echo "<br>tgShow[$tgNo]=$tgShow[$tgNo]";

	if($DEBUG)echo "<br>initValue=$initValue";
	$dpc = $tgArr[$tgNo][2] = hexdec(substr($initValue,2,6));
	if($DEBUG)echo "<br>dpc=$dpc";

	$tgArr[$tgNo][hexDpc]=strtoupper(omc_keep_length(dechex($dpc),0,6));

	$hex_4 = substr($initValue,8,2);
	if($DEBUG)echo "<br>hex_4=$hex_4";
	$bin_4 = omc_keep_length(DecBin(HexDec($hex_4)),0,8);
	if($DEBUG)echo "<br>bin_4=$bin_4";

	$tgFlag = $tgArr[$tgNo][0] = substr($bin_4,7,1);
	if($DEBUG)echo "<br>tgFlag=$tgFlag";

	$cdrFlag = $tgArr[$tgNo][3] = substr($bin_4,6,1);
	if($DEBUG)echo "<br>cdrFlag=$cdrFlag";

	$voFlag = $tgArr[$tgNo][4] = substr($bin_4,5,1);
	if($DEBUG)echo "<br>voFlag=$voFlag";

	$tgType = $tgArr[$tgNo][1] = BinDec(substr($bin_4,2,3));
	if($DEBUG)echo "<br>tgType=$tgType";

	$atFlag = $tgArr[$tgNo][5] = substr($bin_4,1,1);
	if($DEBUG)echo "<br>atFlag=$atFlag";

	$lpFlag = $tgArr[$tgNo][7] = substr($bin_4,0,1);

	$netType = $tgArr[$tgNo][8] = HexDec(substr($initValue,10,2));
	if($DEBUG)echo "<br>netType$netType";

	$hex_6 = substr($initValue,12,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";
	
	$cirType = $tgArr[$tgNo][9] = BinDec(substr($bin_6,6,2));
	if($DEBUG)echo "<br>cirType=$cirType";
	
	$backFlag = $tgArr[$tgNo][10] = substr($bin_6,5,1);
	if($DEBUG)echo "<br>backFlag=$backFlag";

	$tgLct = $tgArr[$tgNo][11] = BinDec(substr($bin_6,0,2));
	if($DEBUG)echo "<br>tgLct=$tgLct";

	$mptyFlag = $tgArr[$tgNo][12] = BinDec(substr($bin_6,2,1));
	if($DEBUG)echo "<br>mptyFlag=$mptyFlag";

	$tgNum = $tgArr[$tgNo][6] = HexDec(substr($initValue,14,2));
	if($DEBUG)echo "<br>tgNum=$tgNum";

	$tandemFlag = $tgArr[$tgNo][13] = HexDec(substr($initValue,16,2));
	if (1 < $tgArr[$tgNo][13]) {
		$tgArr[$tgNo][13] = 1;
	}
	if($DEBUG)	echo "<br>tandemFlag={$tgArr[$tgNo][13]}";

	$incomingCallType = $tgArr[$tgNo][14] = HexDec(substr($initValue,18,2));
	if (1 < $tgArr[$tgNo][14]) {
		$tgArr[$tgNo][14] = 1;
	}
	if($DEBUG)	echo "<br>incomingCallType={$tgArr[$tgNo][14]}";
	
	$tgNo++;
}

if(0)
for($i=0; $i<$tgNo; $i++)
{
	echo "<br>$i: <br>";
	print_r($tgArr[$i]);
}

$tmpSql="SELECT initValue FROM OBJ_225.param_99 
			WHERE level_1='2' AND level_2='11'
			";
if($DEBUG)
	echo "<BR>tmpSql=$tmpSql";
$tmpResult	=mysqli_query($pubConn,$tmpSql);
echo mysqli_error($pubConn);
$i=0;
while($tmpRows = @mysqli_fetch_array($tmpResult)){	
	$tmpArr[$i][tgNum] = hexdec(getBitValue($tmpRows[0],"3.0-3.7"));
	$tmpArr[$i][name]=toAscii(getBitValue($tmpRows[0],"14.0-23.7"));
	$i++;
}

for($i=0; $i< $tgNo; $i++)
{
	if($tgArr[$i][inst]==253 || $tgArr[$i][inst]==254)
	{
		$tgArr[$i][name] = $tgTitleArr[$tgArr[$i][inst]]='LoopBack'.$tgArr[$i][inst];
	}
	else
	{
		for($j=0;$j<256;$j++){
			if($tgArr[$i][inst]==$tmpArr[$j][tgNum]){
				$tgArr[$i][name] = $tgTitleArr[$tgArr[$i][inst]]=$tmpArr[$j][name];
				break;
			}
		}
	}
		
}
/*
if(sizeof($tgArr)>0)
{
	foreach($tgArr as $key => $row)
	{
		$name[$key] = $row['name'];
	}
	array_multisort($name, SORT_ASC, $tgArr);
}
*/
$wDef = substr($wDef,0,-3);
$wDef = $wDef.")";
if(strlen($wDef) < 10){
	$wDef = 'instanceNo < 0';
}
if($DEBUG)echo "<br>wDef=$wDef";
$tgShow[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=\"#\">TG 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
	?>
	 </tr>   
</table>         
</form>

       
<TABLE border="1" width="100%" cellpadding="2" cellspacing="0" bordercolor="#666666" bordercolordark="#FFFFFF" bgcolor="#FFFFFF">     
<tr bgcolor="#E6E6E6">
<td>No.</td>     
<td>Title</td>  
<td>Category</td>     
<td>DPC</td> 
<td>CDR</td>     
<td>Voice</td>
<td>ALT flag</td>     
<td>ALT TG</td>
<td>Loopback</td>
<td>NI</td>     
<td>Circuit</td>     
<td>Back off</td>    
<td>Location</td>    
<td>MPTY</td>    
<td>Tandem</td>  
<td>Incoming call type</td>  
</tr>
<?php
for($i=0;$i< $tgNo;$i++){
	echo "<td>{$tgArr[$i][inst]}</td>";
	echo "<td><nobr>{$tgArr[$i][name]}&nbsp;</nobr></td>";
	echo "<td><nobr>{$tgTypeArr[$tgArr[$i][1]][remark]}</nobr></td>";
	echo "<td><nobr>{$tgArr[$i][2]}&nbsp;</nobr></td>";
	echo "<td><nobr>{$cdrFlagArr[$tgArr[$i][3]][remark]}</nobr></td>";
	echo "<td><nobr>{$voFlagArr[$tgArr[$i][4]][remark]}</nobr></td>";
	echo "<td><nobr>{$atFlagArr[$tgArr[$i][5]][remark]}</nobr></td>";
	echo "<td><nobr>{$tgTitleArr[$tgArr[$i][6]]}&nbsp;</nobr></td>";
	echo "<td><nobr>{$lpFlagArr[$tgArr[$i][7]][remark]}</nobr></td>";
	echo "<td><nobr>{$netTypeArr[$tgArr[$i][8]][remark]}</nobr></td>";
	echo "<td><nobr>{$cirTypeArr[$tgArr[$i][9]][remark]}</nobr></td>";
	echo "<td><nobr>{$backFlagArr[$tgArr[$i][10]][remark]}</nobr></td>";
	echo "<td><nobr>{$tgLocationArr[$tgArr[$i][11]][remark]}</nobr></td>";
	echo "<td><nobr>{$mptyFlagArr[$tgArr[$i][12]][remark]}</nobr></td>";
	echo "<td>{$tandemFlagArr[$tgArr[$i][13]][remark]}</td>";
	echo "<td>{$incomingCallTypeArr[$tgArr[$i][14]][remark]}</td>";
	echo "</tr>";

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


?>
</body>
</html>
