<?php
/*********************************************************      
 程序说明：         
    功能说明：设置七号信令中的 E1connect
    调用关系：调用: 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;
//*****
//$url_temp=$_SERVER["REQUEST_URI"];
//echo "This page URL:$url_temp<br>";
if($DEBUG) echo "<br>正在调试中！！";
//==========================================================
//变量定义
//==========================================================
$nGetComm	= 0;
$nSetComm	= 3;

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


$objDb		= 'OBJ_'.$sysTypeNo;
$paramTable = 'param_'.$sysNo;

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

$objIdarr = array("2.4.1","2.4.3");

$ProtocolArr=array("TUP","ISUP","AIF","ISDN NT","ISDN LT","CI-CNF","CI-loopback");


//==========================================================
//数据处理
//==========================================================
{//设备类型 与设备编号
	getElementInfo($infoNo,$elementInfoArr);
	$this_sysNo = $TypeNo = $elementInfoArr[sysNo];
	$TypeIn = $elementInfoArr[typeValue];
}

//echo "TypeIn:$TypeIn<hr>";
{//get all 8ke1 cards' heart beat
	$selSql = "select sysNo,subSysNo,detailStat from sysStat where sysTypeNo='111'";
	$Result = mysqli_query($pubConn,$selSql);
	while($Row = mysqli_fetch_array($Result))
	{
		$cardNo = $Row[sysNo] * 16 + $Row[subSysNo];
		$bitValue = substr($Row[detailStat],42,2);
		if($bitValue=='00') $type='E1';
		else if($bitValue=='01') $type='T1';
		$k8e1CardTypeArr[$cardNo] = $type;
		//echo "<br>$Row[sysNo]-$Row[subSysNo]:$bitValue";
	}
}//end get 8ke1's heart beat.

//保存改动
if($_SERVER['REQUEST_METHOD'] == "POST")
{
	
	
	if($instanceNo == 'New' ||$instanceNo == 'new')
	{		
		$instanceNo = $newID;	
	}
	
	
	//============save for mtp2 error correction parameter=====================
		$instance_no_tmp=$instanceNo;
		//=======get the plat no=======================
		$plat_no_tmp=-1;
		if($instance_no_tmp>=0&&$instance_no_tmp<=127)
		{
			$plat_no_tmp=0;
			$ins_no_tmp=floor($instance_no_tmp/8);
			$bit_tmp=$instance_no_tmp%8;
		}
		else if($instance_no_tmp>=128&&$instance_no_tmp<=255)
		{
			$plat_no_tmp=1;
			$instance_no_tmp=$instance_no_tmp-128;
			$ins_no_tmp=floor($instance_no_tmp/8);
			$bit_tmp=$instance_no_tmp%8;
		}
		//=====get the table name in database===========
		$table_name_tmp="param_".$plat_no_tmp;
		$database="OBJ_111";
		$sql="select instanceNo,initValue from $table_name_tmp where level_1=2 and level_2=8 and instanceNo=$ins_no_tmp";
		$result=@mysqli_query($pubConn,$sql);
		$rows=@mysqli_fetch_array($result);
		$old_value=$rows[initValue];
		$tmp="0.".$bit_tmp."-0.".$bit_tmp;
		$new_value= setBitValue($old_value,$tmp,$mtp2_error_correction_select);
		
		$updSql = "UPDATE $table_name_tmp SET initValue = '$new_value'   
					where level_1=2 and level_2=8 and instanceNo=$ins_no_tmp
					";	
		mysqli_query($pubConn,$updSql);
		echo mysqli_error($pubConn);
	//==========================================================================
	
	$sysId = '322_99_99';
	$sysIdArr	= explode('_',$sysId);
	$sysTypeNo	= $sysIdArr[0];
	$sysNo		= $sysIdArr[1];
	$subSysNo	= $sysIdArr[2];

	$objDb		= 'OBJ_'.$sysTypeNo;
	$paramTable = 'param_'.$sysNo;

	
	$objIdStr='2.4.1';
	$objWhereStr =getLevelWhere($objIdStr);
	$totalValue = omc_keep_length(dechex($Protocol),"0","2");
	$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);
	
	//=====to set the interface first===============================
	$commIdStr	= oidSysCommSend("322_99_99",$nSetComm,"2.4.1",-1);
	CheckState($commIdStr);
	sleep(1);
	$commIdStr	= oidSysCommSend("322_99_99",$$nGetComm,"2.4.1",-1);
	CheckState($commIdStr);
	
	
	$database="OBJ_322";
	$sql="select readValue from param_99 where level_1=2 and level_2=4 and level_3=1 and instanceNo=$instanceNo ";
	if($DEBUG)
	 echo "<BR>Sql=$sql";
	$result=@mysqli_query($pubConn,$sql);
	
	$rows=@mysqli_fetch_array($result);
	$readValue=$rows[readValue];
	//=========no E1 license====================
	//echo "setValue----$totalValue<hr>";
	//echo "readValue----$readValue<hr>";
	if($totalValue!=$readValue)
	{
		//========get the default value==================
		$database="OBJ_322";
		$sql="select initValue from paramConf where level_1=2 and level_2=4 and level_3=1 ";
		$result=@mysqli_query($pubConn,$sql);
		$rows=@mysqli_fetch_array($result);
		$default_Value=$rows[initValue];
		//========resume the value======================
		$updSql = "UPDATE param_99 SET initValue = '$default_Value'   
					WHERE level_1=2 and level_2=4 and level_3=1 AND instanceNo='$instanceNo'
					";
		if($DEBUG) echo "<BR>updSql=$updSql";
		mysqli_query($pubConn,$updSql);
		echo mysqli_error($pubConn);
		
		
		echo "<script language=\"JavaScript\">\n";
		echo "alert('No E1/T1 port available.Please check the license!');\n";
		echo "window.history.go(-2);\n";
		echo "</script>";
		exit();
		
	}
	
	
	
	
	if($instanceNo == 'New' ||$instanceNo == 'new')
	{		
		$instanceNo = $newID;		
		//初始化时序参数
		$tempnum = $instanceNo/8;
		$cardno = Floor($tempnum);
		$cardname = "cardno"."_$cardno";
		$tempno = $cardno+1;
		$oidCard = "2.5."."$tempno";
		$objWhereStr =getLevelWhere($oidCard);
		
		$cardE1no = $instanceNo - $cardno*8;
		$timeslotno = $cardE1no*32;			
		for($j=0; $j< 32;$j++)
		{
			$updSql = "UPDATE param_99 SET initValue = '05EEEE'
					 WHERE $objWhereStr AND instanceNo='$timeslotno'
					";
			if($DEBUG) echo "<BR>updSql=$updSql";
			mysqli_query($pubConn',$updSql);
			echo mysqli_error($pubConn);
			$timeslotno++;
		}	
		//open k8e1 enable
		open8ke1Enable($instanceNo,1);
	}
	//echo "crc4flag:$crc4flag";
	if($webname=='PCR')
	{
		open8ke1CRC4Flag($instanceNo,0);
	}
	else
	{
		if($crc4flag==1)
			open8ke1CRC4Flag($instanceNo,1);
		else
			open8ke1CRC4Flag($instanceNo,0);
	}
	if($mtpAlarm==1)
		open8ke1mtpAlarm($instanceNo,1);
	else
		open8ke1mtpAlarm($instanceNo,0);
		
	if($webname=='Switch')
	{
		set8ke1Canceller($instanceNo,$echoCanceller);
	}
	$tempnum = $instanceNo/8;
	$cardno = Floor($tempnum);
	$cscNo = Floor($cardno/16);
	$subCardNo = $cardno%16;
	if($k8e1CardTypeArr[$cardno]=='T1')
	{
//		set8ke1SigSlot($instanceNo,$sigSlot);
		set8kT156K64K($instanceNo,$T1_56K64K);
		set8kCardType($instanceNo,90);
		if(isset($resetCard))
		{
			echo "<br>Reseting CSU$sysNo-Card $subSysNo ...";
			$tmpObjId = '3.1';
			$setValue = '5A';
			$subSysId = '111_' . $cscNo . '_'.$subCardNo;
			echo "subSysId:$subSysId";
			$SaveArr[0]['sysid']	=$subSysId;
			$SaveArr[0]['oidstr']	=$tmpObjId;
			$SaveArr[0]['setvalue']	=$setValue;
		
			SaveParam($SaveArr);
		}
	}
	else
	{
		set8kCardType($instanceNo,0);
	}
	set8kIdleCode($instanceNo,$T1_idleCode);

	if($Protocol==3 || $Protocol==4)
	{
		set8ke1LinkType($instanceNo, 1);
		if($Protocol==3)
			set8ke1NTLT($instanceNo, 1);
		else
			set8ke1NTLT($instanceNo, 0);
	}
	else
	{
		set8ke1LinkType($instanceNo, 0);
		set8ke1NTLT($instanceNo, 0);
	}
	//exit;
	

	$objIdStr='2.4.2';
	$objWhereStr =getLevelWhere($objIdStr);
	$totalValue = omc_keep_length(dechex($trunkgp),"0","2");
	$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);

	$objIdStr='2.4.3';
	$objWhereStr =getLevelWhere($objIdStr);

	$tmp = dechex($CIC);
	$tmp = omc_keep_length($tmp,'0',2);
	$setValue = strtoupper($tmp);	
	$updSql = "UPDATE $paramTable SET initValue = '$setValue'   
					WHERE $objWhereStr AND instanceNo='$instanceNo'
					";
	if($DEBUG) echo "<BR>updSql=$updSql";
	mysqli_query($pubConn,$updSql);
	echo mysqli_error($pubConn);
	
	$objIdStr='2.4.4';
	$objWhereStr =getLevelWhere($objIdStr);
	
	$selSql = "SELECT initValue from $paramTable 
					WHERE $objWhereStr AND instanceNo='$instanceNo'
					";
	$result = mysqli_query($pubConn,$selSql);
	$Rows = mysqli_fetch_array($result);
	$setValue = setBitValue($Rows[initValue],'0.0-0.0','1');//asigned	
	$setValue = setBitValue($setValue,'00.1-001','1');//unlock
	
	$updSql = "UPDATE $paramTable SET initValue = '$setValue'   
					WHERE $objWhereStr AND instanceNo='$instanceNo'
					";
	if($DEBUG) echo "<BR>updSql=$updSql";
	mysqli_query($pubConn,$updSql);
	echo mysqli_error($pubConn);
		
	if($DEBUG)
	{
		exit();
	}
	else
	{
		echo "<script LANGUAGE=\"JavaScript\">";
		echo " location='$backurl';";  
		echo "\n </script>";
		exit();
	}
}


//==========================================================
//输出并显示数据
//==========================================================
if($DEBUG) echo "<BR>";
echo "<script language=\"javascript\" src=\"../sub_inc/expand.js\" ></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%\">";
echo "Configuration > <a href=\"../overview/overview.php\">Network</a> > ";
echo "<a href=\"$backurl\">$webname</a> > ";
echo "<a href=\"#\">E1</a>";
echo "</td>";
echo "<td width=\"50%\" align=\"right\" title=\"Help\">";
//showHelp($helpId);
echo "</td>";
echo "</tr>";
echo "</table>";
echo "<br>";

{
	echo "<table width=\"100%\">";
	echo "<tr>";
		echo "<td width=\"70%\">";
			if($instanceNo == 'new')
			{
				//echo "<b>Add E1 connection:</b>&nbsp;&nbsp;";
				echo "&nbsp;&nbsp;";
			}
			else
			{
				//echo "<b>Edit E1 connection:</b>&nbsp;&nbsp;";
				echo "&nbsp;&nbsp;";
			}
		echo "</td>";
		echo "<td width=\"20%\" align=\"right\">";
				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 "</td>";
	echo "</tr>";
	echo "<input type=\"hidden\" name=\"linkset\" value=\"$linkset\">";
	echo "<input type=\"hidden\" name=\"ctrflag\" value=\"$ctrflag\">";
	echo "<input type=\"hidden\" name=\"trunkgp\" value=\"$trunkgp\">";
	echo "<input type=\"hidden\" name=\"backurl\" value=\"$backurl\">";
	echo "<input type=\"hidden\" name=\"webname\" value=\"$webname\">";
	echo "</table>";
	echo "<br>";
}
echo "<table border=\"1\" width=\"100%\" cellpadding=\"1\" cellspacing=\"0\" bordercolor=\"#666666\" bordercolordark=\"#FFFFFF\">";	

//E1 connection
if($instanceNo == 'New' ||$instanceNo == 'new')
{
	for($i=0;$i< sizeof($objIdarr);$i++)
	{
		$objIdStr=$objIdarr[$i];
		$objWhereStr =getLevelWhere($objIdStr);
		$defSql = " SELECT initValue FROM paramConf WHERE $objWhereStr ";
		$defRes = @mysqli_query($pubConn,$defSql);
		$defRow = @mysqli_fetch_array($defRes);
		$defaultValue = $defRow[initValue];
		$value[$i]	=$defaultValue;	
	}
	if($TypeIn==2)//AAS自动配置参数
	{
		if($cicflag==0)
		{
			$value[1]=20;	
		}
		else
		{
			$value[1]=0;	
		}
	}
	else
	{
		$tmp=0;
		$tmp = omc_keep_length(dechex($ctrflag%32),"0","2");
		$value[1]=$tmp;	
	}
	
}
else
{
	for($i=0;$i< sizeof($objIdarr);$i++)
	{	
		$objIdStr=$objIdarr[$i];
		$objWhereStr =getLevelWhere($objIdStr);
		$getSql="SELECT initValue,instanceNo
				FROM $paramTable 
				WHERE $objWhereStr AND instanceNo='$instanceNo'
				";
		if($DEBUG) echo "<BR>getSql=$getSql";
		$result	=mysqli_query($pubConn,$getSql);
		$rows	=mysqli_fetch_array($result);
		$value[$i]=$rows[initValue];
		if($DEBUG) echo "<BR>value[$i]=$value[$i]";
	}
}

$Protocol 		= hexdec($value[0]);
$CIC			= hexdec($value[1]);

echo "<tr bgcolor=\"#E6E6E6\"><td width=\"50%\"><b>Parameters</b></td><td><b>Value</b></td></tr>";
echo "<tr>";
echo "<td>E1/T1 no.</td>";
if($instanceNo == 'new')
{
	echo "<td>";
	
	$objIdStr='2.4.4';
	$objWhereStr =getLevelWhere($objIdStr);	
	$getInstanceSql="SELECT initValue,instanceNo FROM $paramTable
					WHERE $objWhereStr "; 		
	$result=mysqli_query($pubConn,$getInstanceSql);
	if($webname=='Switch')
		echo "<select name=\"newID\" size=\"1\" style=width:\"$nShowsize\" onchange=\"javascript:selectInstance(this.value);showEchoCanceller(this.value,'echoCanceller');\">";
	else
		echo "<select name=\"newID\" size=\"1\" style=width:\"$nShowsize\" onchange=\"javascript:selectInstance(this.value);\">";
	$i=0;
	while($row=mysqli_fetch_array($result))
	{
		$oflag = getBitValue($row[initValue],'0.0-0.0');
		$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";
		
		$show=0;
		foreach($k8e1CardTypeArr as $card => $value)
		{
			if($cardno==$card)
			{
				$show=1;
				break;
			}
		}

		if($show==1 && $oflag==0)
		{	
			$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 disbale
			{
				if($i==0)
				{
					if(!isset($slctInstNo))
						$slctInstNo = $row[instanceNo];
				}
				echo "<option value=$row[instanceNo] ";
					if($row[instanceNo]==$slctInstNo) echo "selected";
				echo ">$cardname</option>";
				$i++;
			}	
		}			
	}
	echo"</select>";

	echo "</td>";
}
else
{
	echo "<td>$instanceNo</td>";
}
echo "</tr>";

echo "<tr>";
echo "<td>TrunkGroup no.</td>";
echo "<td>$trunkgp</td>";
echo "</tr>";

echo "<tr>";
echo "<td>Protocol</td>";
//if($TypeIn == 2)//aas
if($TypeIn > 1 && $TypeIn < 6) //aas, vms, pcr, cnf
{
	echo "<td><input type=\"hidden\" name=\"Protocol\" value=\"1\">{$ProtocolArr[1]}</td>";	
}
elseif($TypeIn == 1)//bss
{
	echo "<td><input type=\"hidden\" name=\"Protocol\" value=\"2\">{$ProtocolArr[2]}</td>";	
}
elseif($TypeIn == 17)
{
	echo "<td><select name=\"Protocol\" style=width:\"$nShowsize\" onchange=javascript:ChangeOrigInd(this)>";
		for($i=0;$i< sizeof($ProtocolArr);$i++)
		{
			if($i==3||$i==4)//ISDN NT ISDN LT 
			{
				if($i == $Protocol)
				{
					echo "<option value=\"$i\" selected>$ProtocolArr[$i]";
				}
				else
				{
					echo "<option value=\"$i\">$ProtocolArr[$i]";
				}
			}
		}
	echo "</select></td>";
}
else
{
	echo "<td><select name=\"Protocol\" style=width:\"$nShowsize\" onchange=javascript:ChangeOrigInd(this)>";
		for($i=0;$i< sizeof($ProtocolArr);$i++)
		{
			if($i==0||$i==1)// ITU OR ISUP
			{
				if($i == $Protocol)
				{
					echo "<option value=\"$i\" selected>$ProtocolArr[$i]";
				}
				else
				{
					echo "<option value=\"$i\">$ProtocolArr[$i]";
				}
			}
		}
	echo "</select></td>";
}
echo "</tr>";

if($TypeIn!=17){
	echo "<tr>";
	echo "<td>Circuit ID</td>";
	$tmpvalue = $CIC;
	echo "<td>";
	if($TypeIn==2)
	{
		echo "<input type=\"hidden\" name=\"CIC\" value=\"$tmpvalue\">$tmpvalue";	
	}
	else
	{
		echo "<input type=\"text\" style=width:\"$nShowsize\" maxlength=\"10\" value=\"$tmpvalue\" class=\"text\" name=\"CIC\"  onchange = checkInput(this,10,255)>";
	}
	echo "</td></tr>";
}//end if($TypeIn!=17)
//==========IUA CIC============
else
{
	//==================get the trunk instanceNo=============
	$tg_no_tmp=$trunkgp;
	$database="OBJ_322";
	$sql="select initValue from param_99 where level_1=2 and level_2=1 and level_3=4 and instanceNo=$tg_no_tmp";
	$result=@mysqli_query($pubConn,$sql);
	$rows=@mysqli_fetch_array($result);
	$tg_protocal_stack=hexdec(getBitValue($rows[initValue],'12.0-12.7'))+0;
	//====ANSI====
	if($tg_protocal_stack==1)
	{
		echo "<tr>";
		echo "<td>Interface ID</td>";
		$tmpvalue = $CIC;
		echo "<td>";
			
		echo "<input type=\"text\" style=width:\"$nShowsize\" maxlength=\"10\" value=\"$tmpvalue\" class=\"text\" name=\"CIC\"  onchange = checkInput(this,10,255)>";
		
		echo "</td></tr>";
	}
	//====ITU====
	else
	{
		$tmp="";
	}
}
if($instanceNo=='new')
	$insNo = $slctInstNo;
else
	$insNo = $instanceNo;
$tempnum = $insNo/8;
$cardno = Floor($tempnum);
$tmp = $cardno/16;
$k8e1SysNo = floor($tmp);
$k8e1Table = "param_$k8e1SysNo";
$k8e1Db = "OBJ_111";
$setInstNo = $cardno%16;
$cardE1no = $insNo - $cardno*8;

if(!($webname=='PCR' || $webname=='VSS'))
{
	echo "<tr>";
	echo "<td>CRC4 Flag</td>";
	{
		if($instanceNo=='new')
			$checked = 0;
		else
		{
			$selSql = "select initValue from $k8e1Table 
					where level_1='2' and level_2='6' and instanceNo='$setInstNo' ";
			$result = mysqli_query($pubConn,$selSql);
			$row = mysqli_fetch_array($result);
			$setbit = "0.$cardE1no-0.$cardE1no";
			$checked = getBitValue($row[initValue],$setbit);
		}
		$checkeStr = $checked == 1 ? 'checked':'';
		echo "<td>";
			echo "<input type=\"checkbox\" name=\"crc4flag\" value=\"$checked\" onClick=\"javascript:selectCheck(this)\" $checkeStr>On";
		echo "</td>";
	}
	echo "</tr>";
}
echo "<tr>";
echo "<td>MTP Alarm</td>";
{
	if($instanceNo=='new')
		$checked = 1;
	else
	{
		$selSql = "select initValue from $k8e1Table 
				where level_1='2' and level_2='2' and instanceNo='$setInstNo' ";
		$result = mysqli_query($pubConn,$selSql);
		$row = mysqli_fetch_array($result);
		$setbit = "0.$cardE1no-0.$cardE1no";
		$checked = getBitValue($row[initValue],$setbit);
	}
	$checkeStr = $checked == 1 ? 'checked':'';
	echo "<td>";
		echo "<input type=\"checkbox\" name=\"mtpAlarm\" value=\"$checked\" onClick=\"javascript:selectCheck(this)\" $checkeStr>On";
	echo "</td>";
}
echo "</tr>";

if($webname=='Switch')
{
	if($cardE1no % 2 == 0)
	{
		$selSql = "select initValue from $k8e1Table 
				where level_1='2' and level_2='9' and instanceNo='$setInstNo' ";
		$result = mysqli_query($pubConn,$selSql);
		$row = mysqli_fetch_array($result);
		$tmpBit = $cardE1no/2;
		$setbit = "0.$tmpBit-0.$tmpBit";
		$cancellerType = getBitValue($row[initValue],$setbit);//0:A-law, 1: Mu-Law
	}
	if(isset($cancellerType))
		$showStr = '';
	else
		$showStr = 'none';
		
	echo "<tr id=\"echoCanceller\" style=\"DISPLAY: $showStr\">";
	echo "<td>Echo Canceller</td>";
	{
		echo "<td>";
		if($cancellerType==0)
		{
			echo "<input type=\"radio\"  name=\"echoCanceller\" value=\"0\" checked>A-law";
			echo "<input type=\"radio\"  name=\"echoCanceller\" value=\"1\">Mu-Law";
		}
		else
		{
			echo "<input type=\"radio\"  name=\"echoCanceller\" value=\"0\" >A-law";
			echo "<input type=\"radio\"  name=\"echoCanceller\" value=\"1\" checked>Mu-Law";
		}
		echo "</td>";
	}
	echo "</tr>";
}
if($k8e1CardTypeArr[$cardno]=='T1')//show T1 8ke1 card type parameters
{
	{//2.10.6
		$levelWhere = getLevelWhere('2.10.6');
		$selSql = "select initValue from $k8e1Table where $levelWhere and instanceNo='$setInstNo'";
		$result = mysqli_query($pubConn,$selSql);
		$row = mysqli_fetch_array($result);
		$setbit = "0.$cardE1no-0.$cardE1no";
		$T1_56K64K = getBitValue($row[initValue],$setbit);
//		echo "<br>$selSql;<br>$setbit;<br>$T1_56K64K";
		echo "<tr>";
		echo "<td>T1 64K/56K</td>";
		{
			echo "<td>";
			if($T1_56K64K==0)
			{
				echo "<input type=\"radio\"  name=\"T1_56K64K\" value=\"0\" checked onClick=\"hideIt('KB4Child','Reset8ke1','0');\">64K";
				echo "<input type=\"radio\"  name=\"T1_56K64K\" value=\"1\" onClick=\"hideIt('KB4Child','Reset8ke1','1');\">56K";
			}
			else
			{
				echo "<input type=\"radio\"  name=\"T1_56K64K\" value=\"0\" onClick=\"hideIt('KB4Child','Reset8ke1','1');\">64K";
				echo "<input type=\"radio\"  name=\"T1_56K64K\" value=\"1\" checked onClick=\"hideIt('KB4Child','Reset8ke1','0');\">56K";
			}
			echo "&nbsp;&nbsp;&nbsp;<span id=\"KB4Child\" style=\"DISPLAY: none\">";
			echo "<input type=\"Checkbox\" id=\"Reset8ke1\" name=\"resetCard\" onClick=\"hideIt('KB4Child','Reset8ke1','0');\">Reset 8kE1/T1 Card.";
			echo "</span>";
			echo "</td>";
		}
		echo "</tr>";
	}//end 2.10.6
	
}//end show T1 8ke1 card type parameters
{//2.12
	if($k8e1CardTypeArr[$cardno]=='E1') $tmpDefault = 'D5';
	else 	$tmpDefault = 'FE';
	$levelWhere = getLevelWhere('2.12');
	$selSql = "select initValue from $k8e1Table where $levelWhere and instanceNo='$setInstNo'";
	$result = mysqli_query($pubConn,$selSql);
	$row = mysqli_fetch_array($result);
	$setbit = "$cardE1no.0-$cardE1no.7";
	$T1_idleCode = getBitValue($row[initValue],$setbit);
//		echo "<br>$selSql;<br>$setbit;<br>$T1_idleCode";
	echo "<tr>";
	echo "<td>$k8e1CardTypeArr[$cardno] Idle Code</td>";
	echo "<td>";
		echo "<input type=\"text\" size=\"4\" maxlength=\"2\" name=\"T1_idleCode\" value=\"$T1_idleCode\">";
		echo "<font color=\"#808080\">&nbsp;&nbsp;Usual Idle Code = $tmpDefault</font>";
	echo "</td>";
	echo "</tr>";
}//end 2.12

//====================MTP2 error correction=======================
{
$mtp2_error_correction_label=array(0=>"Basic Error Correction",1=>"Preventive Cyclic Retransmission");
echo "<tr>";
	echo "<td>MTP2 Error Correction</td>";
	echo "<td>";
	if($instanceNo=="New"||$instanceNo=="new")
		$mtp2_error_correction_value=0;
	else
	{
		//=====get the specfic port no.,then show the parameter=======
		$instance_no_tmp=$instanceNo;
		//=======get the plat no=======================
		$plat_no_tmp=-1;
		if($instance_no_tmp>=0&&$instance_no_tmp<=127)
		{
			$plat_no_tmp=0;
			$ins_no_tmp=floor($instance_no_tmp/8);
			$bit_tmp=$instance_no_tmp%8;
		}
		else if($instance_no_tmp>=128&&$instance_no_tmp<=255)
		{
			$plat_no_tmp=1;
			$instance_no_tmp=$instance_no_tmp-128;
			$ins_no_tmp=floor($instance_no_tmp/8);
			$bit_tmp=$instance_no_tmp%8;
		}
		//=====get the table name in database===========
		$table_name_tmp="param_".$plat_no_tmp;
		$database="OBJ_111";
		$sql="select instanceNo,initValue from $table_name_tmp where level_1=2 and level_2=8 and instanceNo=$ins_no_tmp";
		$result=@mysqli_query($pubConn,$sql);
		$rows=@mysqli_fetch_array($result);
		$tmp="0.".$bit_tmp."-0.".$bit_tmp;
		$mtp2_error_correction_value=hexdec(getBitValue($rows[initValue],$tmp))+0;
		
	}
	
	echo "<select name=\"mtp2_error_correction_select\">";
		for($i=0;$i<2;$i++)
		{
			if($i==$mtp2_error_correction_value)
				echo "<option value=$i selected>{$mtp2_error_correction_label[$i]}</option>";
			else
				echo "<option value=$i>{$mtp2_error_correction_label[$i]}</option>";				
		}
	echo "</select>";
	echo "</td>";
echo "</tr>";
}



echo "</table>";


echo "<input type=\"hidden\" name=\"sysId\" value=\"$sysId\">";
echo "<input type=\"hidden\" name=\"cicflag\" value=\"$cicflag\">";
echo "<input type=\"hidden\" name=\"instanceNo\" value=\"$instanceNo\">";
echo "<input type=\"hidden\" name=\"card\" value=\"$cardno\">";
echo "<input type=\"hidden\" name=\"infoNo\" value=\"$infoNo\">";

echo "</form>";

?>

<script LANGUAGE="JavaScript"> 
function selectInstance(value)
{
	<?php $backurl=urlencode($backurl);?>
	URL = '<?php echo "$PHP_SELF?infoNo=$infoNo&instanceNo=$instanceNo&cicflag=$cicflag&ctrflag=$ctrflag&webname=$webname&trunkgp=$trunkgp&linkset=$linkset"; ?>';
	URL += '&slctInstNo=' + value;
	URL += '<?php echo "&backurl=$backurl"; ?>';
	window.location.href=URL;
}
function showEchoCanceller(inst, term)
{
	whichEl = document.getElementById(term);
	tempnum = inst/8;
	cardno = Math.floor(tempnum);
	cardE1no = inst - cardno*8;
	if(cardE1no % 2==0)
	{
		whichEl.style.display = "";
	}
	else
	{
		whichEl.style.display = "none";
	}
}
function selectCheck(thisCheckBox)
{
	if(thisCheckBox.checked == true)
		thisCheckBox.value=1;
	else
		thisCheckBox.value=0;
}
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 != 4 )
	{
		initIt();
		expandIt('KB1');

	}
	else
	{
		initIt();
	}
}
function hideIt(term, ckbox, flag)
{
	whichEl = document.getElementById(term);
	ckboxObj = document.getElementById(ckbox);
	if(flag==1)
	{
		whichEl.style.display = "";
		ckboxObj.checked=true;
	}
	if(flag==0)
	{
		whichEl.style.display = "none";
		ckboxObj.checked=false;
	}
}
</script>
