<?php
/*********************************************************      
 程序说明：         
    功能说明：设置七号信令中的 E1link
    调用关系：调用: header.inc    
              被调用:        
    变量说明：
    作者：hewd   2003-04-10      
修改注释：      
NO.1      
姓名： Cui Ticun         
时间：2004-4-21
修改说明：Support OMC7.0,从advanced移到configuration中，修改
		 和添加了上方的操作按钮
*********************************************************/
require("../sub_inc/commfunc.php");
$DEBUG = 0;
$pass_backurl = urlencode($backurl);

if($DEBUG) echo "<br>正在调试中！！";
//==========================================================
//变量定义
//==========================================================
$pubDb	 = 'OMC_PUB';

$sysId ='222_99_99';
$sysIdArr	= explode('_',$sysId);
$sysTypeNo	= $sysIdArr[0];
$sysNo		= $sysIdArr[1];
$subSysNo	= $sysIdArr[2];

$objDb		= 'OBJ_'.$sysTypeNo;
$paramTable = 'param_'.$sysNo;
$AAS_MTP3Table = 'param_11';
$VSS_MTP3Table = 'param_8';

//==========================================================
//输入变量
//==========================================================
$nShowsize ='45%';	

$E1linkConfArr=array(
	array('showname'=>'SLC',		'inputname'=>'Linkconf0',		'offset'=>'01.0-01.7','value'=>''),
	array('showname'=>'Host IP', 	'inputname'=>'Linkconf1',		'offset'=>'02.0-05.7','value'=>''),
	array('showname'=>'Link type',	'inputname'=>'Linkconf2',		'offset'=>'06.1-06.3','value'=>''),
	array('showname'=>'LinkNo',		'inputname'=>'Linkconf3',		'offset'=>'00.0-00.7','value'=>''),
	array('showname'=>'Flag',		'inputname'=>'Linkconf4',		'offset'=>'06.5-06.5','value'=>''),
	array('showname'=>'Lock',		'inputname'=>'Linkconf5',		'offset'=>'06.0-06.0','value'=>'1')
);

{//MSC IP	
	$getSysIdSql = "SELECT sysNo,subSysNo,ip FROM sysInfo
				WHERE sysTypeNo='320' AND sysNo='0'
			";
	$getSysIdResult= mysqli_query($pubConn,$getSysIdSql);
	if(@mysqli_num_rows($getSysIdResult)){
		$getSysIdRow=mysqli_fetch_array($getSysIdResult);
		$MSCIP0	=$getSysIdRow[ip];
	}else{
		$MSCIP0	='255.255.255.255';
	}
	$getSysIdSql = "SELECT sysNo,subSysNo,ip FROM sysInfo
				WHERE sysTypeNo='320' AND sysNo='1'
			";
	$getSysIdResult= mysqli_query($pubConn,$getSysIdSql);
	if(@mysqli_num_rows($getSysIdResult)){
		$getSysIdRow=mysqli_fetch_array($getSysIdResult);
		$MSCIP1	=$getSysIdRow[ip];
	}else{
		$MSCIP1	='255.255.255.255';
	}	
}
//==========================================================
//数据处理
//==========================================================
{
	getElementInfo($infoNo,$elementInfoArr);
	$this_sysNo = $TypeNo = $elementInfoArr[sysNo];
	$TypeIn = $elementInfoArr[typeValue];
	
	$otherWhereStr = "and subSysNo=$TypeNo";
}


//保存改动
if($_SERVER['REQUEST_METHOD'] == "POST")
{	
	if($instanceNo == 'new')
	{		
		$instanceNo = $newID;
	}
	
	$E1linkConfArr[0][value] = omc_keep_length(dechex($Linkconf0),"0","2");
	$subIpArr = explode('.',$mtp3_IP);
	$IP1 = omc_keep_length(dechex($subIpArr[0]),"0","2");
	$IP2 = omc_keep_length(dechex($subIpArr[1]),"0","2");
	$IP3 = omc_keep_length(dechex($subIpArr[2]),"0","2");
	$IP4 = omc_keep_length(dechex($subIpArr[3]),"0","2");
	$E1linkConfArr[1][value] = $IP1.$IP2.$IP3.$IP4;
	
	$E1linkConfArr[2][value] = omc_keep_length(decbin($Linkconf2),'0',2);
	$E1linkConfArr[3][value] = omc_keep_length(dechex($Linkconf3),"0","2");
	$E1linkConfArr[4][value] = $Linkconf4;
	for($i=0;$i< sizeof($E1linkConfArr);$i++)
	{
		 $totalValue=setBitValue($totalValue,$E1linkConfArr[$i][offset],$E1linkConfArr[$i][value]);
	}
	
	{//MTP3_99_pub E1 link
		$sysId = '222_99_99';
		$sysIdArr	= explode('_',$sysId);
		$sysTypeNo	= $sysIdArr[0];
		$sysNo		= $sysIdArr[1];
		$subSysNo	= $sysIdArr[2];
		
		
		$objDb		= 'OBJ_'.$sysTypeNo;
		$paramTable = 'param_'.$sysNo;
			
		$objIdStr='2.5.1';
		$objWhereStr =getLevelWhere($objIdStr);
	
		$totalValue = strtoupper($totalValue);
		$updSql = "UPDATE $paramTable SET initValue = '$totalValue'   
						WHERE $objWhereStr AND instanceNo='$instanceNo'
						";
		if($DEBUG) echo "<BR>updSql=$updSql";
		mysqli_query($pubConn,$updSql);
		echo mysqli_error($pubConn);
	}

	if($TypeIn == 2)//MTP3_11_pub(AAS) E1 link
	{
		{//AAS IP
			$AAS_sysId = "311_".$this_sysNo."_0";
			$sysIdArr	= explode('_',$AAS_sysId);
			$sysTypeNo	= $sysIdArr[0];
			$sysNo		= $sysIdArr[1];
			$subSysNo	= $sysIdArr[2];	
		
			
			$getSysIdSql = "SELECT sysNo,subSysNo,ip FROM sysInfo
						WHERE sysTypeNo='$sysTypeNo' AND sysNo='$sysNo' AND subSysNo='$subSysNo'
					";
			$getSysIdResult= mysqli_query($pubConn,$getSysIdSql);
			$getSysIdRow=mysqli_fetch_array($getSysIdResult);
			$IP	= explode('.',$getSysIdRow[ip]);	
			$IP[0] = omc_keep_length(dechex($IP[0]),"0","2");
			$IP[1] = omc_keep_length(dechex($IP[1]),"0","2");
			$IP[2] = omc_keep_length(dechex($IP[2]),"0","2");
			$IP[3] = omc_keep_length(dechex($IP[3]),"0","2");
			$tmp = $IP[0].$IP[1].$IP[2].$IP[3];
			$totalValue=setBitValue($totalValue,$E1linkConfArr[1][offset],$tmp);
			$totalValue=setBitValue($totalValue,'00.0-00.7','00');//LINKSET =0	
			$totalValue = strtoupper($totalValue);
		}	
		//$instanceNo =0 or =1		
		$updSql = "UPDATE $AAS_MTP3Table SET initValue = '$totalValue'   
						WHERE $objWhereStr $otherWhereStr AND instanceNo='$Linkconf0'
						";
		if($DEBUG) echo "<BR>updSql=$updSql";
		mysqli_query($pubConn,$updSql);
		echo mysqli_error($pubConn);
	}
	
	if($TypeIn == 3)//MTP3_9_pub(VSS) E1 link
	{
		{//vms IP
			$VSS_sysId = "390_".$this_sysNo."_0";
			$sysIdArr	= explode('_',$VSS_sysId);
			$sysTypeNo	= $sysIdArr[0];
			$sysNo		= $sysIdArr[1];
			$subSysNo	= $sysIdArr[2];	
		
			
			$getSysIdSql = "SELECT sysNo,subSysNo,ip FROM sysInfo
						WHERE sysTypeNo='$sysTypeNo' AND sysNo='$sysNo' AND subSysNo='$subSysNo'
					";
			$getSysIdResult= mysqli_query($pubConn,$getSysIdSql);
			$getSysIdRow=mysqli_fetch_array($getSysIdResult);
			$IP	= explode('.',$getSysIdRow[ip]);	
			$IP[0] = omc_keep_length(dechex($IP[0]),"0","2");
			$IP[1] = omc_keep_length(dechex($IP[1]),"0","2");
			$IP[2] = omc_keep_length(dechex($IP[2]),"0","2");
			$IP[3] = omc_keep_length(dechex($IP[3]),"0","2");
			$tmp = $IP[0].$IP[1].$IP[2].$IP[3];
			$totalValue=setBitValue($totalValue,$E1linkConfArr[1][offset],$tmp);
			$totalValue=setBitValue($totalValue,'00.0-00.7','00');//LINKSET =0	
			$totalValue = strtoupper($totalValue);
		}	
		$updSql = "UPDATE $VSS_MTP3Table SET initValue = '$totalValue'   
						WHERE $objWhereStr $otherWhereStr AND instanceNo='$Linkconf0'
						";
		if($DEBUG) echo "<BR>updSql=$updSql";
		mysqli_query($pubConn,$updSql);
		echo mysqli_error($pubConn);
	}

	{//link command
		$objIdStr='2.5.2';
		$objWhereStr =getLevelWhere($objIdStr);
	
		$updSql = "UPDATE $paramTable SET initValue = '$Link_cmd'   
						WHERE $objWhereStr AND instanceNo='$instanceNo'
						";
		if($DEBUG) echo "<BR>updSql=$updSql";
		mysqli_query($pubConn,$updSql);
		echo mysqli_error($pubConn);
		
		//MTP3_11_pub(AAS) E1 command
		if($TypeIn == 2)
		{		
			$updSql = "UPDATE $AAS_MTP3Table SET initValue = '$Link_cmd'   
							WHERE $objWhereStr $otherWhereStr AND instanceNo='$Linkconf0'
							";
			if($DEBUG) echo "<BR>updSql=$updSql";
			mysqli_query($pubConn,$updSql);
			echo mysqli_error($pubConn);
		}
		//MTP3_8_pub(VSS) E1 command
		if($TypeIn == 3)
		{		
			$updSql = "UPDATE $VSS_MTP3Table SET initValue = '$Link_cmd'   
							WHERE $objWhereStr $otherWhereStr AND instanceNo='$Linkconf0'
							";
			if($DEBUG) echo "<BR>updSql=$updSql";
			mysqli_query($pubConn,$updSql);
			echo mysqli_error($pubConn);
		}
	}
	if($devicename!='BSC')
		set8ke1Mtp2ErrCrct($instanceNo,$mtp2ErrCrct);
	
	if($tmpTg==-1)
	{
		open8ke1Enable($instanceNo,1);
		open8ke1mtpAlarm($instanceNo,0);
	}
	if($DEBUG)
	{
	}
	else
	{
		echo "<script LANGUAGE=\"JavaScript\">";
		echo " location='$backurl';";  
		echo "\n </script>";
		exit();
	}
}

//==========================================================
//输出并显示数据
//==========================================================
if($DEBUG) echo "<BR>";
//**********************************编辑参数时所用javascript*****************************************
echo "<script language=\"javascript\" src=\"../sub_inc/expand.js\" ></script>";  
?>
<script LANGUAGE="JavaScript"> 
function checkInput(term,flag,maxValue)
{
	term.value = term.value.toUpperCase();
    
    if (flag == 16)
    {
    	var checkOK = "0123456789ABCDEF";
    	var showmsg ="Parameter must be a hexadecimal value";
    }
    else 
    {
    	var checkOK = "0123456789";
    	var showmsg ="Parameter must be a decimal value";
    }

    var checkStr = term.value;
    var allValid = true;
    for (i = 0;  i < checkStr.length;  i++){
		ch = checkStr.charAt(i);
		for (j = 0;  j < checkOK.length;  j++){
			if (ch == checkOK.charAt(j))
				break;
		}
		if (j == checkOK.length){
			allValid = false;
			break;
		}
	}
	
	if (!allValid){  
		alert(showmsg+"!");
		term.focus();
		term.value = 0;
		return (false);
	}
	if (maxValue != 0)
	{
		if (checkStr > maxValue)
		{
			showmsg = "Parameter must less then "+ maxValue;
			alert(showmsg+"!");
			term.value = 0;
			term.focus();
			return (false);
		}
	}
}
function ChangeOrigInd(thisSelect)
{
	var val = thisSelect.value;	
	
	if(val == 01 )
	{
		initIt();
		expandIt('KB1');

	}
	else if(val == 10)
	{
		initIt();	
		expandIt('KB2');
	}
}
function linkSelect(item,spanid,value0,value1)
{
	var val = item.value;
	whichEl = document.getElementById(spanid);
	whichEl2 = document.getElementById("inputMTP3IP");
	if(val > 127)
	{
		whichEl.innerHTML = value1;
		whichEl2.value = value1;
	}
	else
	{
		whichEl.innerHTML = value0;
		whichEl2.value = value0;
	}
	//alert(val + whichEl.innerHTML);
}
</script>
<body topmargin="0" leftmargin="12">
<form method="POST" name="selectform" action="<?php echo "$PHP_SELF?"; ?>">

<?php 
{
	echo "<table border=\"0\" width=\"100%\">";
	echo "<tr>";
	echo "<td width=\"50%\">";
	
	$backurl1 = str_replace("wxc2_sp_signaling","wxc2_sp",$backurl);
	echo "Configuration > <a href=\"../overview/overview.php\">Network</a> > ";
	echo "<a href=\"$backurl1\">$devicename</a> > ";
	echo "<a href=\"$backurl\">$elementInfoArr[eleName]</a> > ";
	echo "<a href=\"#\">Link</a>";
	echo "</td>";
	echo "<td width=\"50%\" align=\"right\" title=\"Help\">";
	showHelp($helpId);
	echo "</td>";
	echo "</tr>";
	echo "</table>";
	
	echo "<table width=\"100%\">";
	echo "<tr><td width=\"70%\">";
	if($instanceNo == 'new')
	{
		//echo "<b>Add a link:</b>&nbsp;&nbsp;";
		echo "&nbsp;&nbsp;";
	}
	else
	{
		//echo "<b>Edit link:</b>&nbsp;&nbsp;";
		echo "&nbsp;&nbsp;";
	}
	echo "</td>";
	echo "<td width=\"20%\">";
	echo "<input type=\"submit\" name=\"set\" value=\"Save\" class=\"button\" style=\"left: 1; top: 2; width: 60; height: 25; position: relative\">";
	echo "&nbsp;&nbsp;&nbsp;";
	echo "<input type=\"reset\" name=\"Reset\" value=\"Reset\" class=\"button\" style=\"left: 1; top: 2; width: 60; height: 25; position: relative\">";
	echo "</td>";
	echo "<td width=\"10%\" align=\"right\">";
	
	echo "<a href=\"$backurl\"><img align=absBottom border=0 src=\"../../images/left.gif\" width=\"14\" height=\"14\">$strBack</a>";
	
	echo "<input type=\"hidden\" name=\"linkset\" value=\"$linkset\">";
	echo "<input type=\"hidden\" name=\"trunkgp\" value=\"$trunkgp\">";
	echo "<input type=\"hidden\" name=\"backurl\" value=\"$backurl\">";
	echo "<input type=\"hidden\" name=\"spname\" value=\"$spname\">";
	echo "<input type=\"hidden\" name=\"addflag\" value=\"$addflag\">";
	echo "<input type=\"hidden\" name=\"slc\" value=\"$slc\">";
	echo "<input type=\"hidden\" name=\"instanceNo\" value=\"$instanceNo\">";
	echo "<input type=\"hidden\" name=\"infoNo\" value=\"$infoNo\">";
	
	echo "</td></tr>";
	echo "</table>";
}
echo "<table border=\"1\" width=\"100%\" cellpadding=\"1\" cellspacing=\"0\" bordercolor=\"#666666\" bordercolordark=\"#FFFFFF\">";	

//E1link show
$ctrflag	= explode('>',$addflag);
$objIdStr='2.5.1';
$objWhereStr =getLevelWhere($objIdStr);

if($instanceNo == 'new')
{			
	$defSql = " SELECT initValue FROM paramConf WHERE $objWhereStr ";
	$defRes = @mysqli_query($pubConn,$defSql);
	$defRow = @mysqli_fetch_array($defRes);
	$defaultValue = $defRow[initValue];
	$value	=$defaultValue;	
	
	if($TypeIn==2)//AAS自动配置参数
	{
		if($slc==0)
		{
			$value=setBitValue($value,$E1linkConfArr[0][offset],'01');
		}
		else
		{
			$value=setBitValue($value,$E1linkConfArr[0][offset],'00');
		}			
	}
	else
	{
		$tmp=0;
		$tmp = omc_keep_length(dechex($ctrflag[1]%16),"0","2");
		$value=setBitValue($value,$E1linkConfArr[0][offset],$tmp);
	}
}
else
{
	$getSql="SELECT initValue,instanceNo
			FROM $paramTable 
			WHERE $objWhereStr AND instanceNo='$instanceNo'
			";
	if($DEBUG) echo "<BR>getSql=$getSql";
	$result	=mysqli_query($pubConn,$getSql);
	echo mysqli_error($pubConn);
	$rows	=mysqli_fetch_array($result);
	echo mysqli_error($pubConn);
	$value=$rows[initValue];
}
echo "<input type=\"hidden\" name=\"totalValue\" value=\"$value\">";
	
for($i=0;$i< sizeof($E1linkConfArr);$i++)
{
	 $E1linkConfArr[$i][value] = getBitValue($value,$E1linkConfArr[$i][offset]);
}
echo "<tr bgcolor=\"#E6E6E6\"><td width=\"50%\"><b>Parameters</b></td><td><b>Value</b></td></tr>";
echo "<tr>";
echo "<td>E1 link no.</td>";
$tmpTg = ($trunkgp==255 ? -1 : $trunkgp);

if($instanceNo == 'new')
{
	if($ctrflag[0]<0)
	{
		$selinstID="instanceNo >127 ";
	}
	else
	{
		$selinstID="instanceNo >=0 ";
	}

	$ins_no = 0;
	if($tmpTg==-1)
	{	
		echo "<td>";	
		$objIdStr='2.4.2';
		$objWhereStr =getLevelWhere($objIdStr);	
		$getInstanceSql="SELECT initValue,instanceNo FROM $paramTable
						WHERE $objWhereStr AND initValue = 'EE'
						"; 		
	//	$getInstanceSql="SELECT initValue,instanceNo FROM $paramTable WHERE $objWhereStr "; 				
		$result=mysqli_query($pubConn',$getInstanceSql);
		$spanId = "divMTP3IP";
		echo "<select name=\"newID\" size=\"1\" onChange=\"linkSelect(this,'$spanId','$MSCIP0','$MSCIP1');\" style=width:\"$nShowsize\">";
		$i=0;
		while($row=mysqli_fetch_array($result))
		{	
			$getInstanceSql="SELECT initValue,instanceNo FROM $paramTable
							WHERE instanceNo='$row[instanceNo]' and level_1 = '2' and level_2 = '5' and level_3 = '1'
							";
			$result_1=mysqli_query($pubConn,$getInstanceSql);
			$LinkRow=mysqli_fetch_array($result_1);
			$tempFlag = getBitValue($LinkRow[initValue],'06.5-06.5');					
			if($tempFlag==0)//E1 link not assigned
			{
				$tempnum = $row[instanceNo]/8;
				$cardno = Floor($tempnum);
				$cardE1no = $row[instanceNo] - $cardno*8;
				$cscNo = Floor($cardno/16);
				$subCardNo = $cardno%16;
				$cardname = "CSC$cscNo"."&nbsp;"."Card-$subCardNo-$cardE1no";
				if($i==0)
					$instanceNo=$row[instanceNo];
				echo "<option value=$row[instanceNo]>$cardname</option>";
				$i++;
			}				
		}
		echo"</select>";	
		echo "</td>";	
	}
	else
	{			
		$HEXtrunkgp	= omc_keep_length(dechex($trunkgp),"0","2");
		$HEXtrunkgp = strtoupper($HEXtrunkgp);
		$paramSql = " SELECT initValue,instanceNo FROM OBJ_322.param_99
					WHERE level_1 = '2' and level_2 = '4' and level_3 = '2' AND initValue = '$HEXtrunkgp' 
					ORDER BY instanceNo";
		if($DEBUG) echo "<br>$paramSql";
		$Result = mysqli_query($pubConn',$paramSql);					
	
		$tmpWhere='(0';
		$E1connarr="";
		while($Row = mysqli_fetch_array($Result))
		{		
			if($tmpWhere=='(0')
				$tmpWhere="(instanceNo='$Row[instanceNo]'";
			else
				$tmpWhere=$tmpWhere." OR instanceNo='$Row[instanceNo]'";					
		}
		$tmpWhere=$tmpWhere.")";	
	{//show as select
		$LinkparamSql = " SELECT initValue,instanceNo FROM OBJ_222.param_99
					WHERE level_1 = '2' and level_2 = '5' and level_3 = '1' AND $tmpWhere
					ORDER BY instanceNo";
		if($DEBUG) echo "<br>$LinkparamSql";
		$LinkResult = mysqli_query($pubConn,$LinkparamSql);	
		
		
		echo "<td>";
		echo "<select name=\"newID\" onChange=\"linkSelect(this,'$spanId','$MSCIP0','$MSCIP1');\" size=\"1\" style=width:\"$nShowsize\">";	
		while($LinkRow = mysqli_fetch_array($LinkResult))
		{
			$Linkflag = hexdec(getBitValue($LinkRow[initValue],'06.5-06.5'));
			if($Linkflag==0)
			{
				if(!isset($firstShowInst))
					$firstShowInst = $LinkRow[instanceNo];
					
				$tempnum = $LinkRow[instanceNo]/8;
				$cardno = Floor($tempnum);
				$cardE1no = $LinkRow[instanceNo] - $cardno*8;
				$cscNo = Floor($cardno/16);
				$subCardNo = $cardno%16;
				$cardname = "CSC$cscNo"."&nbsp;"."Card-$subCardNo-$cardE1no";
				echo "<option value=$LinkRow[instanceNo]>$cardname</option>";
				$ins_no++;
			}
		}
	}//end show as select (modify at 2006-8-20 10:41)
/*{	
		$LinkparamSql = " SELECT initValue,instanceNo FROM OBJ_222.param_99
					WHERE level_1 = '2' and level_2 = '5' and level_3 = '1' AND $tmpWhere AND $selinstID
					ORDER BY instanceNo";
		if($DEBUG) echo "<br>$LinkparamSql";
		$LinkResult = mysqli_query($pubConn,$LinkparamSql);	
	
	//	echo "<td>";
	//	echo "<select name=\"newID\" size=\"1\" style=width:\"$nShowsize\">";	
		while($LinkRow = mysqli_fetch_array($LinkResult))
		{
			$Linkflag = hexdec(getBitValue($LinkRow[initValue],'06.5-06.5'));
			if($Linkflag==0)
			{
				//echo "<option value=$LinkRow[instanceNo]>$LinkRow[instanceNo]</option>";
				$ins_no++;
				break;
			}
		}
		if($ins_no == 0&&$ctrflag[0]<0)//当1平面没有可用E1 link则从0平面选择
		{
			$LinkparamSql = " SELECT initValue,instanceNo FROM OBJ_222.param_99
						WHERE level_1 = '2' and level_2 = '5' and level_3 = '1' AND $tmpWhere
						ORDER BY instanceNo";
			if($DEBUG) echo "$paramSql";
			$LinkResult = mysqli_query($pubConn,$LinkparamSql);							
		
			while($LinkRow = mysqli_fetch_array($LinkResult))
			{		
				$Linkflag = hexdec(getBitValue($LinkRow[initValue],'06.5-06.5'));
				if($Linkflag==0)
				{
					$ins_no++;
					break;
				}
			}		
		}
}*/		
		if($ins_no == 0)
		{
			echo "<script language='javascript'>";  
			echo "window.alert(\"The link is corresponding to E1, please add E1 connection first.\");";	
			echo "location='$backurl';";  
			echo "</script>";
			exit();
		}
/*		
		echo "<td>";
		echo "<input type=\"hidden\" name=\"newID\" value=\"$LinkRow[instanceNo]\">$LinkRow[instanceNo]";		
		$instanceNo = $LinkRow[instanceNo];
		echo "</td>";
*/
	}
}
else
{
	echo "<td>$instanceNo</td>";
}
echo "</tr>";

echo "<tr>";
echo "<td>Linkset no.</td>";
echo "<td>$linkset</td>";
echo "</tr>";

echo "<tr>";
echo "<td>{$E1linkConfArr[0][showname]}</td>";
$tmpvalue = hexdec($E1linkConfArr[0][value]);
echo "<td>";
if($TypeIn == 2)
{
	echo "<input type=\"hidden\" name=\"{$E1linkConfArr[0][inputname]}\" value=\"$tmpvalue\">$tmpvalue";		
}
else
{
	echo "<input type=\"text\" style=width:\"$nShowsize\" maxlength=\"3\" value=\"$tmpvalue\" class=\"text\" name=\"{$E1linkConfArr[0][inputname]}\"  onchange = checkInput(this,10,255)>";
}
echo "</td>";
echo "</tr>";

//自动设置ip地址
if($instanceNo == 'new')
{
	if($firstShowInst<128)
		$MTP3IP = $MSCIP0;
	else
		$MTP3IP	= $MSCIP1;
}
else
{
	if($instanceNo<128)
		$MTP3IP = $MSCIP0;
	else
		$MTP3IP	= $MSCIP1;
}
echo "<tr>";
echo "<td>{$E1linkConfArr[1][showname]}</td>";
echo "<td><span id=\"divMTP3IP\" >$MTP3IP</span>";

echo "<input type=\"hidden\" id=\"inputMTP3IP\" name=\"mtp3_IP\" value=\"$MTP3IP\" >&nbsp;&nbsp;";
echo "</td>";	
echo "</tr>";

echo "<tr>";
//echo "<td>{$E1linkConfArr[2][showname]}</td>";
//$tmpvalue = bindec($E1linkConfArr[2][value]);
//echo "<td>";
//$linkTypeArr = array(0 => 'Non-sigtran', 1 => 'Sigtran', 2 => 'MTP3-Lite');
//
//echo "<select name=\"{$E1linkConfArr[2][inputname]}\" value=\"$tmpvalue\" style=width:\"$nShowsize\" >";	
//	while (list ($key, $val) = each ($linkTypeArr)) 
//	{
//		echo "<option value=\"$key\" ";
//		if($key == $tmpvalue)
//			echo "selected";
//		echo ">$val</option>";
//	}		
//echo "</select>";
//echo "</td>";
echo "<intput type=\"hidden\" name=\"{$E1linkConfArr[2][inputname]}\" value=\"0\">";
echo "</tr>";

echo "<input type=\"hidden\" name=\"{$E1linkConfArr[3][inputname]}\" value=\"$linkset\">";
echo "<input type=\"hidden\" name=\"{$E1linkConfArr[4][inputname]}\" value=\"1\">";

$objIdStr='2.5.2';
$objWhereStr =getLevelWhere($objIdStr);
if($instanceNo == 'new')
{		
	$value	='01';	
}
else
{
	$getSql="SELECT initValue,instanceNo
		FROM $paramTable 
		WHERE $objWhereStr AND instanceNo='$instanceNo'
		";
		$result	=mysqli_query($pubConn,$getSql);
		echo mysqli_error($pubConn);
		$rows	=mysqli_fetch_array($result);
		echo mysqli_error($pubConn);
		$value=$rows[initValue];
}
echo "<input type=\"hidden\" name=\"Link_cmd\" value=\"$value\">"; 
/*
echo "<tr>";
echo "<td>Link command</td>";
$tmpvalue = hexdec($value);
echo "<td>";
echo "<select name=\"Link_cmd\" style=width:\"$nShowsize\">";
			if($tmpvalue==0){
				echo "<option value=\"00\" selected>Disable";
				echo "<option value=\"01\">Enable";
				echo "<option value=\"02\">Inhibit";
				echo "<option value=\"03\">Uninhibit";				
			}elseif($tmpvalue==1){
				echo "<option value=\"00\">Disable";
				echo "<option value=\"01\" selected>Enable";
				echo "<option value=\"02\">Inhibit";
				echo "<option value=\"03\">Uninhibit";				
			}elseif($tmpvalue==2){
				echo "<option value=\"00\">Disable";
				echo "<option value=\"01\">Enable";
				echo "<option value=\"02\" selected>Inhibit";
				echo "<option value=\"03\">Uninhibit";				
			}elseif($tmpvalue==3){
				echo "<option value=\"00\">Disable";
				echo "<option value=\"01\">Enable";
				echo "<option value=\"02\">Inhibit";
				echo "<option value=\"03\" selected>Uninhibit";				
			}else{
				echo "<option value=\"00\" selected>Disable";
				echo "<option value=\"01\">Enable";
				echo "<option value=\"02\">Inhibit";
				echo "<option value=\"03\">Uninhibit";				
			}	
echo "</select>";
echo "</td>";
echo "</tr>";
*/
if($devicename=='Switch')
{
echo "<tr>";
	$tempnum = $instanceNo/8;
	$cardno = Floor($tempnum);
	$tmp = $cardno/16;
	$k8e1SysNo = floor($tmp);
	$k8e1Table = "param_$k8e1SysNo";
	$k8e1Db = "OBJ_111";
	$setInstNo = $cardno%16;
	$cardE1no = $instanceNo - $cardno*8;
	$selSql = "select initValue from $k8e1Table 
			where level_1='2' and level_2='8' and instanceNo='$setInstNo' ";
	$result = mysqli_query($pubConn,$selSql);
	$row = mysqli_fetch_array($result);
	$setbit = "0.$cardE1no-0.$cardE1no";
	$mtp2ErrCrct = getBitValue($row[initValue],$setbit);//0:Basic error correction, 1: Preventive cyclic retransmission
	
	echo "<td>MTP2 error correction</td>";
	{
		echo "<td>";
		if($mtp2ErrCrct==0)
		{
			echo "<input type=\"radio\"  name=\"mtp2ErrCrct\" value=\"0\" checked>Basic error correction";
			echo "<input type=\"radio\"  name=\"mtp2ErrCrct\" value=\"1\">Preventive cyclic retransmission";
		}
		else
		{
			echo "<input type=\"radio\"  name=\"mtp2ErrCrct\" value=\"0\" >Basic error correction";
			echo "<input type=\"radio\"  name=\"mtp2ErrCrct\" value=\"1\" checked>Preventive cyclic retransmission";
		}
		echo "</td>";
	}
echo "</tr>";
}
echo "</table>";

?>

