<?php
/*********************************************************      
 程序说明：         
    功能说明：E1参数配置

    调用关系：调用: header.inc     
              被调用:   
 
    变量说明：

     返回值：无

 作者：    
      
修改注释：      
NO.1      
姓名：            
时间：      
修改说明：      
*********************************************************/  
require("../../inc/header.inc");
$DEBUG = 0;
?>
<script LANGUAGE="JavaScript">           
function openSet(){
	URL="./e1Edit.php";
	var msgWindow = open(URL, 'newWin', 'toolbar=no,directories=no,menubar=no,scrollbars=yes,resizable=yes,status=yes,width=400,height=700');
	msgWindow.focus();
}
</script>
<?
$sysTypeNo_0 = "111";
if($thisOmcType==10){
	$sysTypeNo_1 = "251";
}else{
	$sysTypeNo_1 = "322";
}

$db_0 = "OBJ_".$sysTypeNo_0;
$db_1 = "OBJ_".$sysTypeNo_1;

$tb_0 = "param_0";
$tb_1 = "param_1";
$tb_2 = "param_99";
if($DEBUG)echo "<br>pNum=$pNum";
$temTb = ${tb_.$sNum};
$instanceNo = floor($pNum/8);
$mNum = $sNum*128+$pNum;
if($DEBUG)echo "<br>mNum=$mNum";
if($DEBUG)echo "<br>instanceNo=$instanceNo";
$portNo = $pNum%8;
if($DEBUG)echo "<br>portNo=$portNo";

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

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

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

$mPtArr=array(
		array('num' => '0',  'remark' => 'TUP', 'color' => '#FF0000'),
		array('num' => '1',  'remark' => 'ISUP', 'color' => '#0000FF'),
		array('num' => '2',  'remark' => 'AIF', 'color' => '#0000FF'),
		array('num' => '3',  'remark' => 'ISDN NT', 'color' => '#0000FF'),
		array('num' => '4',  'remark' => 'ISDN LT', 'color' => '#0000FF'),
		array('num' => '5',  'remark' => 'CI CNF', 'color' => '#0000FF'),
		array('num' => '6',  'remark' => 'CI loopback', 'color' => '#0000FF')
);

//E1 flag
$oidFlag = "2.1"; 
$pE1 = explode(".",$oidFlag);
$i = 0;
$wFlag = '';
while(isset($pE1[$i]))
{
	$lNum = $i+1;
	if($DEBUG) echo "<br>pE1[$i]=$pE1[$i]";
	$wFlag = $wFlag." AND level_$lNum = $pE1[$i] ";
	$i++;
}


//2.6 CRC4 flag
$oidCrc = "2.6"; 
$pE1 = explode(".",$oidCrc);
$i = 0;
$wCrc = '';
while(isset($pE1[$i]))
{
	$lNum = $i+1;
	if($DEBUG)echo "<br>pE1[$i]=$pE1[$i]";
	$wCrc = $wCrc." AND level_$lNum = $pE1[$i] ";
	$i++;
}

//2.2 E1 MTP2 alarm flag
$oidDlink = "2.2"; 
$pE1 = explode(".",$oidDlink);
$i = 0;
$wDlink = '';
while(isset($pE1[$i]))
{
	$lNum = $i+1;
	if($DEBUG)echo "<br>pE1[$i]=$pE1[$i]";
	$wDlink = $wDlink." AND level_$lNum = $pE1[$i] ";
	$i++;
}

//2.4.1 2.4.2 2.4.3 MSC

$wMsc = " WHERE subSysNo = '99' AND level_1 = '2' AND level_2 = '4'  AND (level_3 = '1' OR level_3 = '2' OR level_3 = '3') AND instanceNo  = '$mNum' ORDER BY level_3 ";

$wMsc_1 = " WHERE subSysNo = '99' AND level_1 = '2' AND level_2 = '4'  AND level_3 = '1' AND instanceNo  = '$mNum' ";

$wMsc_2 = " WHERE subSysNo = '99' AND level_1 = '2' AND level_2 = '4'  AND level_3 = '2' AND instanceNo  = '$mNum' ";

$wMsc_3 = " WHERE subSysNo = '99' AND level_1 = '2' AND level_2 = '4'  AND level_3 = '3' AND instanceNo  = '$mNum' ";

if($set)
{
	//E1 flag
	$flagSql = " SELECT instanceNo,initValue,editValue,readValue FROM $temTb WHERE instanceNo = '$instanceNo' ".$wFlag; 
	if($DEBUG)echo "<br>flagSql=$flagSql";
	$flagRes = @mysqli_query($pubConn,$flagSql);
	$flagRow = @mysqli_fetch_array($flagRes);
	$initValue = HexDec($flagRow[initValue]);
	$initValue = DecBin($initValue);
	$initValue = omc_keep_length($initValue,0,8);
	if($DEBUG) echo "<br>initValue=$initValue";
	for($i=0;$i<8;$i++)
	{
		$flagArr[7-$i] = substr($initValue,$i,1);
		if($DEBUG)echo "<br>flagArr[7-$i]={$flagArr[7-$i]}";

	}
	
	if($DEBUG)echo "<br>flag=$flag";
	$flagArr[$portNo]=$flag;
	$initValue = '';
	for($i=7;$i>-1;$i--)
	{
		$initValue = $initValue.$flagArr[$i];
		if($DEBUG)echo "<br>initValue=$initValue";
	}
	
	$initValue = BinDec($initValue);
	$initValue = strtoupper(omc_keep_length(DecHex($initValue),0,2));
	$uFlagSql = " UPDATE $temTb set initValue = '$initValue' WHERE instanceNo = '$instanceNo' ".$wFlag;
	if($DEBUG)echo "<br>uFlagSql=$uFlagSql";
	$uFlagRes = @mysqli_query($pubConn,$uFlagSql);
	

	//CRC4 flag
	$crcSql = " SELECT instanceNo,initValue,editValue,readValue FROM $temTb WHERE instanceNo = '$instanceNo' ".$wCrc; 
	if($DEBUG)echo "<br>crcSql=$crcSql";
	$crcRes = @mysqli_query($pubConn,$crcSql);
	$crcRow = @mysqli_fetch_array($crcRes);
	$initValue = HexDec($crcRow[initValue]);
	$initValue = DecBin($initValue);
	$initValue = omc_keep_length($initValue,0,8);
	if($DEBUG) echo "<br>initValue=$initValue";
	for($i=0;$i<8;$i++)
	{
		$crcArr[7-$i] = substr($initValue,$i,1);
		if($DEBUG)echo "<br>crcArr[7-$i]={$crcArr[7-$i]}";

	}
	
	if($DEBUG)echo "<br>crc=$crc";
	$crcArr[$portNo]=$crc;
	$initValue = '';
	for($i=7;$i>-1;$i--)
	{
		$initValue = $initValue.$crcArr[$i];
		if($DEBUG)echo "<br>initValue=$initValue";
	}
	
	$initValue = BinDec($initValue);
	$initValue = strtoupper(omc_keep_length(DecHex($initValue),0,2));
	$uCrcSql = " UPDATE $temTb set initValue = '$initValue' WHERE instanceNo = '$instanceNo' ".$wCrc;
	if($DEBUG)echo "<br>uCrcSql=$uCrcSql";
	$uCrcRes = @mysqli_query($pubConn,$uCrcSql);


	//2.2 E1 MTP2 alarm flag
	$dlinkSql = " SELECT instanceNo,initValue,editValue,readValue FROM $temTb WHERE instanceNo = '$instanceNo' ".$wDlink; 
	if($DEBUG)echo "<br>dlinkSql=$dlinkSql";
	$dlinkRes = @mysqli_query($pubConn,$dlinkSql);
	$dlinkRow = @mysqli_fetch_array($dlinkRes);
	$initValue = HexDec($dlinkRow[initValue]);
	$initValue = DecBin($initValue);
	$initValue = omc_keep_length($initValue,0,8);
	if($DEBUG) echo "<br>initValue=$initValue";
	for($i=0;$i<8;$i++)
	{
		$dlinkArr[7-$i] = substr($initValue,$i,1);
		if($DEBUG)echo "<br>dlinkArr[7-$i]={$dlinkArr[7-$i]}";

	}
	
	
	$dlinkArr[$portNo]=$dlink;
	$initValue = '';
	for($i=7;$i>-1;$i--)
	{
		$initValue = $initValue.$dlinkArr[$i];
		if($DEBUG)echo "<br>initValue=$initValue";
	}
	
	$initValue = BinDec($initValue);
	$initValue = strtoupper(omc_keep_length(DecHex($initValue),0,2));
	$uDlinkSql = " UPDATE $temTb set initValue = '$initValue' WHERE instanceNo = '$instanceNo' ".$wDlink;
	if($DEBUG)echo "<br>uDlinkSql=$uDlinkSql";
	$uDlinkRes = @mysqli_query($pubConn,$uDlinkSql);
	
	//PT
	$pt = omc_keep_length(DecHex($pt),0,2);
	if($DEBUG)echo "<br>pt=$pt";
	$uPtSql = " UPDATE $tb_2 set initValue = '$pt' ".$wMsc_1;
	if($DEBUG)echo "<br>uPtSql=$uPtSql";
	$uPtRes = @mysqli_query($pubConn,$uPtSql);

	$tg = omc_keep_length(DecHex($tg),0,2);
	if($DEBUG)echo "<br>tg=$tg";
	//TG
	$uTgSql = " UPDATE $tb_2 set initValue = '$tg' ".$wMsc_2;
	if($DEBUG)echo "<br>uTgSql=$uTgSql";
	$uTgRes = @mysqli_query($pubConn,$uTgSql);
	
	$cic = omc_keep_length(DecHex($cic),0,2);
	if($DEBUG)echo "<br>cic=$cic";
	//CIC
	$uCicSql = " UPDATE $tb_2 set initValue = '$cic' ".$wMsc_3;
	if($DEBUG)echo "<br>uCicSql=$uCicSql";
	$uCicRes = @mysqli_query($pubConn,$uCicSql);

	echo "<script LANGUAGE=\"JavaScript\">";
	echo "window.opener.location.href='./e1Conf.php?scroll_x=$scroll_x&scroll_y=$scroll_y';";		
	echo "\n window.close();";
	echo "\n </script>";
}

//E1 flag
$flagSql = " SELECT instanceNo,initValue,editValue,readValue FROM $temTb WHERE instanceNo = '$instanceNo' ".$wFlag; 
if($DEBUG)echo "<br>flagSql=$flagSql";
$flagRes = @mysqli_query($pubConn,$flagSql);
$flagRow = @mysqli_fetch_array($flagRes);
$initValue = HexDec($flagRow[initValue]);
$initValue = DecBin($initValue);
$initValue = omc_keep_length($initValue,0,8);
if($DEBUG) echo "<br>initValue=$initValue";
for($i=0;$i<8;$i++)
{
	$flagArr[7-$i] = substr($initValue,$i,1);
	if(7-$i == $portNo){
		$flag = $flagArr[7-$i];
		if($DEBUG)echo "<br>flag=$flag";
	}
	if($DEBUG)echo "<br>flagArr[7-$i]={$flagArr[7-$i]}";

}


//2.6 CRC4 flag
$crcSql = " SELECT instanceNo,initValue,editValue,readValue FROM $temTb WHERE instanceNo = '$instanceNo' ".$wCrc." ORDER BY instanceNo "; 
if($DEBUG)echo "<br>crcSql=$crcSql";
$crcRes = @mysqli_query($pubConn,$crcSql);
$crcRow = @mysqli_fetch_array($crcRes);
$initValue = HexDec($crcRow[initValue]);
$initValue = DecBin($initValue);
$initValue = omc_keep_length($initValue,0,8);
if($DEBUG) echo "<br>initValue=$initValue";
for($i=0;$i<8;$i++)
{
	$crcArr[7-$i] = substr($initValue,$i,1);
	if(7-$i == $portNo){
		$crc = $crcArr[7-$i];
		if($DEBUG)echo "<br>crc=$crc";
	}
	if($DEBUG)echo "<br>crcArr[7-$i]={$crcArr[7-$i]}";
}



//2.2 E1 MTP2 alarm flag
$dlinkSql = " SELECT instanceNo,initValue,editValue,readValue FROM $temTb WHERE instanceNo = '$instanceNo' ".$wDlink." ORDER BY instanceNo "; 
if($DEBUG)echo "<br>flagSql=$flagSql";
$dlinkRes = @mysqli_query($pubConn,$dlinkSql);
$dlinkRow = @mysqli_fetch_array($dlinkRes);
$initValue = HexDec($dlinkRow[initValue]);
$initValue = DecBin($initValue);
$initValue = omc_keep_length($initValue,0,8);
if($DEBUG) echo "<br>initValue=$initValue";
for($i=0;$i<8;$i++)
{
	$dlinkArr[7-$i] = substr($initValue,$i,1);
	if(7-$i == $portNo){
		$dlink = $dlinkArr[7-$i];
		if($DEBUG)echo "<br>dlink=$dlink";
	}
	if($DEBUG)echo "<br>dlinkArr[7-$i]={$dlinkArr[7-$i]}";
}



//2.4.1 2.4.2 2.4.3 MSC
$mscSql = " SELECT level_3,instanceNo,initValue,editValue,readValue FROM $tb_2 ".$wMsc; 
if($DEBUG)echo "<br>mscSql=$mscSql";
$mscRes = @mysqli_query($pubConn,$mscSql);
$mscRow = @mysqli_fetch_array($mscRes);
if($DEBUG)echo mysqli_error($pubConn);

do
{
	$level_3 = $mscRow[level_3];
	$initValue = HexDec($mscRow[initValue]);
	$mscArr[$level_3] = $initValue;
	if($DEBUG)echo "<br>mscArr[$level_3]={$mscArr[$level_3]}";	
}while($mscRow = @mysqli_fetch_array($mscRes));

$cic = $mscArr[3];
$tg = $mscArr[2];
$pt = $mscArr[1];


echo "<form method=\"POST\" name=\"confForm\" action=\"$PHP_SELF\">";
echo "<table border=\"0\" cellpadding=\"2\" cellspacing=\"2\" width=\"100%\">";
echo "<tr>";
echo "<td colspan=\"4\"><b>Plane $sNum, Slot $instanceNo, Port $portNo</b></td>";
echo "</tr>";
echo "<tr>";
echo "<td  valign=middle title=\"\"><nobr>Flag</nobr></td>";
if($flag){
	echo "<td ><nobr><input type=\"radio\" value=\"1\" name=\"flag\" checked>Yes</nobr></td>";
	echo "<td><nobr><input type=\"radio\" name=\"flag\" value=\"0\">No&nbsp;</nobr></td>";
}else{
	echo "<td ><nobr><input type=\"radio\" value=\"1\" name=\"flag\">Yes</nobr></td>";
	echo "<td><nobr><input type=\"radio\" name=\"flag\" value=\"0\" checked>No&nbsp;</nobr></td>";
}
echo "</tr>";

echo "<tr>";
echo "<td  valign=middle title=\"\"><nobr>CIC</nobr></td>";
echo "<td colspan=\"2\"><input type=\"text\" name=\"cic\" size=\"3\" value=\"$cic\" maxLength=\"3\"></td>";
echo "</tr>";
echo "<tr>";
echo "<td  valign=middle><nobr>TG</nobr></td>";
echo "<td colspan=\"2\"><input type=\"text\" name=\"tg\" size=\"3\" value=\"$tg\" maxLength=\"3\"></td>";
echo "</tr>";

echo "<tr>";
echo "<td  valign=middle title=\"\">Protocol</td>";
echo "<td colspan=\"2\">";
echo "<select style=\"font-family: Verdana; font-size: 8pt\" size=\"1\" name=\"pt\" id=\"pt\">";
for($i=0;$i<7;$i++)
{
	if($pt == $i)
		echo "<option value=\"$i\" selected>{$mPtArr[$i][remark]}</option>";
	else
		echo "<option value=\"$i\">{$mPtArr[$i][remark]}</option>";
}
echo "</select>";
echo "</td>";
echo "</tr>";

echo "<tr>";
echo "<td  valign=middle title=\"\">CRC4</td>";
if($crc){
	echo "<td ><input type=\"radio\" value=\"1\"  name=\"crc\" checked>On</td>";
	echo "<td><input type=\"radio\"  value=\"0\" name=\"crc\">Off&nbsp;</td></tr>"; 
}else{
	echo "<td ><input type=\"radio\" value=\"1\"  name=\"crc\">On</td>";
	echo "<td><input type=\"radio\" value=\"0\" name=\"crc\" checked>Off&nbsp;</td></tr>"; 
}
echo "<tr>";
echo "<td   valign=middle title=\"\">Alarm</td>";

if($dlink){
	echo "<td ><input type=\"radio\" value=\"1\" name=\"dlink\" checked>Yes</td>";
	echo "<td><input type=\"radio\"  value=\"0\" name=\"dlink\">No&nbsp;</td>";
}else{
	echo "<td ><input type=\"radio\" value=\"1\" name=\"dlink\">Yes</td>";
	echo "<td><input type=\"radio\"  value=\"0\" name=\"dlink\" checked>No&nbsp;</td>";
}
echo "</tr>"; 
echo "</table>";
//echo "<br><u><b>Remark:</b></u>";
echo "<br>";
echo "<input type=\"submit\" name=\"set\" value = \"Set\" class=\"button\">";
echo "&nbsp;&nbsp;";
echo "<input type=\"reset\" name=\"Reset\" value =\"Reset\" class=\"button\">";
echo "<input type=\"hidden\" name=\"sNum\" value =\"$sNum\">";
echo "<input type=\"hidden\" name=\"pNum\" value =\"$pNum\">";
echo "<input type=\"hidden\" name=\"mNum\" value =\"$mNum\">";
echo "<input type=\"hidden\" name=\"scroll_x\" value =\"$scroll_x\">";
echo "<input type=\"hidden\" name=\"scroll_y\" value =\"$scroll_y\">";
echo "</form>";


?>
  <b>Remarks:</b><br><br>
Flag: Y=E1 enable, N=E1 disable<br><br>
CIC: Circuit identity code that uniquely identifies each circuit within a trunk group. CIC of both ends of a circuit must be identical. CIC of each circuit of a trunk group must be unique<br><br>
TG: Trunk group to which this E1 port is assigned<br><br>
Protocol: Protocol type of an E1 port<br>
CI CNF: Install a CNF module for call intercept<br>
CI loopback: Indicate this E1 is one of dual loopback E1 ports between MSC-CSC0 and MSC-CSC1 for call intercept<br><br>
CRC4: Cyclic redundancy check, CRC4 flag of both ends of a traffic channel (TCH) must be identical<br>
Alarm: Flag of MTP2 alarm, Yes=MTP2 alarm enable, No=MTP2 alarm disable<br>




</body>
</html>