<?php
/*********************************************************      
Signaling point Configuration.
"OBJ_222"
$sysId		='222_99_99';
$oidlinkset = array("2.4.1","2.6","3.2");
$oidE1		 = array("2.5.1","3.1");

*********************************************************/

require("../sub_inc/commfunc.php");
$helpId = "1.1.1";
$DEBUG = 0;
$nSetComm	= 3;
$backurl ="$PHP_SELF?trunkgp=$trunkgp&infoNo=$infoNo&gtt=$gtt&sysNo=$sysNo&linkset=$linkset&gttSSN=$gttSSN&grpNo=$grpNo&appType=$appType";

//==========================================================
//变量定义
//==========================================================
$pubDb			= 'OMC_PUB';
$db	= "OBJ_222";
$paramTable		='OBJ_222.param_99';

$sysId		='222_99_99';
$sysId_AAS = '222_11_99';


//Spname
//取设备名,编号

getElementInfo($infoNo,$elementInfoArr);
$this_sysNo = $TypeNo = $elementInfoArr[sysNo];
$TypeIn = $elementInfoArr[typeValue];
$elementName = $elementInfoArr[eleName];
$devicename = $elementInfoArr[typeName];
$webname = $elementInfoArr[webName];
//填充oid数组
if($TypeIn ==2)
{
	$aasMtp3_sysId = "222_11_".$TypeNo;
	$oidsysarr=array(
		array('oid'=>'2.2',		'sysid'=>'222_99_99',	'selectsysid'=>'-1'),
		array('oid'=>'2.4.1',	'sysid'=>'222_99_99',	'selectsysid'=>'-1'),
		
		array('oid'=>'2.5.1',	'sysid'=>'222_99_99',	'selectsysid'=>'-1'),
		array('oid'=>'2.5.2',	'sysid'=>'222_99_99',	'selectsysid'=>'-1'),
		
		array('oid'=>'2.6.1',	'sysid'=>'222_99_99',	'selectsysid'=>'-1'),
		array('oid'=>'2.6.2',	'sysid'=>'222_99_99',	'selectsysid'=>'-1'),
		array('oid'=>'2.6.3',	'sysid'=>'222_99_99',	'selectsysid'=>'-1'),
		array('oid'=>'2.6.4',	'sysid'=>'222_99_99',	'selectsysid'=>'-1'),
		array('oid'=>'2.2',		'sysid'=>'223_99_99',	'selectsysid'=>'-1')//sccp
	);
	$oidsysarr1=array(	
		array('oid'=>'2.7.2',	'sysid'=>'222_99_99',	'selectsysid'=>'-1'),
		array('oid'=>'2.7.3',	'sysid'=>'222_99_99',	'selectsysid'=>'-1'),
		array('oid'=>'2.7.4',	'sysid'=>'222_99_99',	'selectsysid'=>'-1'),
		array('oid'=>'2.7.5',	'sysid'=>'222_99_99',	'selectsysid'=>'-1'),
		
		array('oid'=>'2.1.4',	'sysid'=>'322_99_99',	'selectsysid'=>'-1'),//TG 保存修改的dpc
		array('oid'=>'2.4',	'sysid'=>'322_99_99',	'selectsysid'=>'-1'),
	);
	$oidAASarr=array(
		array('oid'=>'2.5.1',	'sysid'=> $aasMtp3_sysId,	'selectsysid'=> '-1'),
		array('oid'=>'2.5.2',	'sysid'=> $aasMtp3_sysId,	'selectsysid'=> '-1')
	);
	$SaveArr=array(
		array('oidstr'=>'3.7',	'setvalue'=>'02'	,'sysid'=> $aasMtp3_sysId,'selectsysid'=> '-1'),
		array('oidstr'=>'3.7',	'setvalue'=>'02'	,'sysid'=>'222_99_99','selectsysid'=>'-1'),
		array('oidstr'=>'3.2',	'setvalue'=>'B5'	,'sysid'=>'322_99_99','selectsysid'=>'-1'),
		array('oidstr'=>'3.2',	'setvalue'=>'02'	,'sysid'=>'223_99_99','selectsysid'=>'-1')
	);
}
elseif($TypeIn ==3)//vms
{
	$vmsMtp3_sysId = "222_8_".$TypeNo;
	$oidsysarr=array(
		array('oid'=>'2.2',		'sysid'=>'222_99_99',	'selectsysid'=>'-1'),
		array('oid'=>'2.4.1',	'sysid'=>'222_99_99',	'selectsysid'=>'-1'),
		
		array('oid'=>'2.5.1',	'sysid'=>'222_99_99',	'selectsysid'=>'-1'),
		array('oid'=>'2.5.2',	'sysid'=>'222_99_99',	'selectsysid'=>'-1'),
		
		array('oid'=>'2.6.1',	'sysid'=>'222_99_99',	'selectsysid'=>'-1'),
		array('oid'=>'2.6.2',	'sysid'=>'222_99_99',	'selectsysid'=>'-1'),
		array('oid'=>'2.6.3',	'sysid'=>'222_99_99',	'selectsysid'=>'-1'),
		array('oid'=>'2.6.4',	'sysid'=>'222_99_99',	'selectsysid'=>'-1'),
		array('oid'=>'2.2',		'sysid'=>'223_99_99',	'selectsysid'=>'-1')//sccp
	);
	$oidsysarr1=array(	
		array('oid'=>'2.7.2',	'sysid'=>'222_99_99',	'selectsysid'=>'-1'),
		array('oid'=>'2.7.3',	'sysid'=>'222_99_99',	'selectsysid'=>'-1'),
		array('oid'=>'2.7.4',	'sysid'=>'222_99_99',	'selectsysid'=>'-1'),
		array('oid'=>'2.7.5',	'sysid'=>'222_99_99',	'selectsysid'=>'-1'),
		
		array('oid'=>'2.1.4',	'sysid'=>'322_99_99',	'selectsysid'=>'-1'),//TG 保存修改的dpc
		array('oid'=>'2.4',		'sysid'=>'322_99_99',	'selectsysid'=>'-1'),
	);
	$oidVSSarr=array(
		array('oid'=>'2.5.1',	'sysid'=> $vmsMtp3_sysId,	'selectsysid'=>'-1' ),
		array('oid'=>'2.5.2',	'sysid'=> $vmsMtp3_sysId,	'selectsysid'=>'-1' )
	);
	$SaveArr=array(
		array('oidstr'=>'3.2',	'setvalue'=>'B5'	,'sysid'=>'322_99_99','selectsysid'=>'-1'),
		array('oidstr'=>'3.7',	'setvalue'=>'02'	,'sysid'=>'222_99_99','selectsysid'=>'-1'),
		array('oidstr'=>'3.7',	'setvalue'=>'02'	,'sysid'=> $vmsMtp3_sysId,'selectsysid'=>'-1' ),
		array('oidstr'=>'3.2',	'setvalue'=>'02'	,'sysid'=>'223_99_99','selectsysid'=>'-1')
	);
}
elseif($devicename==$strGttObjects)
{
	$oidsysarr=array(
		array('oid'=>'2.4.1',	'sysid'=>'222_99_99',	'selectsysid'=>'-1'),
		
		array('oid'=>'2.5.1',	'sysid'=>'222_99_99',	'selectsysid'=>'-1'),
		array('oid'=>'2.5.2',	'sysid'=>'222_99_99',	'selectsysid'=>'-1'),
		
		array('oid'=>'2.6.1',	'sysid'=>'222_99_99',	'selectsysid'=>'-1'),
		array('oid'=>'2.6.2',	'sysid'=>'222_99_99',	'selectsysid'=>'-1'),
		array('oid'=>'2.6.3',	'sysid'=>'222_99_99',	'selectsysid'=>'-1'),
		array('oid'=>'2.6.4',	'sysid'=>'222_99_99',	'selectsysid'=>'-1'),
	);
	$oidsysarr1=array(	
		array('oid'=>'2.7.2',	'sysid'=>'222_99_99',	'selectsysid'=>'-1'),
		array('oid'=>'2.7.3',	'sysid'=>'222_99_99',	'selectsysid'=>'-1'),
		array('oid'=>'2.7.4',	'sysid'=>'222_99_99',	'selectsysid'=>'-1'),
		array('oid'=>'2.7.5',	'sysid'=>'222_99_99',	'selectsysid'=>'-1'),
			
		array('oid'=>'2.2',		'sysid'=>'223_99_99',	'selectsysid'=>'-1')//sccp
	);
	$SaveArr=array(
		array('oidstr'=>'3.7',	'setvalue'=>'02'	,'sysid'=>'222_99_99','selectsysid'=>'-1'),
		array('oidstr'=>'3.2',	'setvalue'=>'02'	,'sysid'=>'223_99_99','selectsysid'=>'-1')
	);		
}
else
{
	$oidsysarr=array(
		array('oid'=>'2.4.1',	'sysid'=>'222_99_99',	'selectsysid'=>'-1'),
		
		array('oid'=>'2.5.1',	'sysid'=>'222_99_99',	'selectsysid'=>'-1'),
		array('oid'=>'2.5.2',	'sysid'=>'222_99_99',	'selectsysid'=>'-1'),
		
		array('oid'=>'2.6.1',	'sysid'=>'222_99_99',	'selectsysid'=>'-1'),
		array('oid'=>'2.6.2',	'sysid'=>'222_99_99',	'selectsysid'=>'-1'),
		array('oid'=>'2.6.3',	'sysid'=>'222_99_99',	'selectsysid'=>'-1'),
		array('oid'=>'2.6.4',	'sysid'=>'222_99_99',	'selectsysid'=>'-1'),
		array('oid'=>'2.2',		'sysid'=>'223_99_99',	'selectsysid'=>'-1')//sccp
	);
	$oidsysarr1=array(
		array('oid'=>'2.7.2',	'sysid'=>'222_99_99',	'selectsysid'=>'-1'),
		array('oid'=>'2.7.3',	'sysid'=>'222_99_99',	'selectsysid'=>'-1'),
		array('oid'=>'2.7.4',	'sysid'=>'222_99_99',	'selectsysid'=>'-1'),
		array('oid'=>'2.7.5',	'sysid'=>'222_99_99',	'selectsysid'=>'-1'),
		
		array('oid'=>'2.4',	'sysid'=>'322_99_99',	'selectsysid'=>'-1'),
		
		array('oid'=>'2.1.4',	'sysid'=>'322_99_99',	'selectsysid'=>'-1')//TG 保存修改的dpc
	);
	$SaveArr=array(
		array('oidstr'=>'3.2',	'setvalue'=>'B5'	,'sysid'=>'322_99_99','selectsysid'=>'-1'),
		array('oidstr'=>'3.7',	'setvalue'=>'02'	,'sysid'=>'222_99_99','selectsysid'=>'-1'),
		array('oidstr'=>'3.2',	'setvalue'=>'02'	,'sysid'=>'223_99_99','selectsysid'=>'-1')
	);	
}
//==========================================================
//数据处理
//==========================================================

if($_SERVER['REQUEST_METHOD'] == "POST")
{	
	if(isset($setSys) || isset($getSys))
	{
		if(isset($setSys))
		{
			echo "<br>Setting parameters<br>";	
			if($TypeIn ==2)
			{ 
				SetParam($oidAASarr);				
			}
			if($TypeIn ==3)
			{ 
				SetParam($oidVSSarr);				
			}
					
			update_e1($linkset,'222_99_99');
			
			if($TypeIn ==2)
			{
				update_e1(0,'222_11_99',$aasMtp3_sysId);
			}
			
			SetParam($oidsysarr);
			SetParam($oidsysarr1);

			SaveParam($SaveArr);
		}
		else
		{
			echo "<br>Getting parameters<br>";
			
			if($TypeIn ==2)
			{
				GetParam($oidAASarr);
			}
			if($TypeIn ==3)
			{
				GetParam($oidVSSarr);
			}
			GetParam($oidsysarr);
			GetParam($oidsysarr1);
			if($devicename!=$strGttObjects) get_e1channel($trunkgp);
		}
	}
}

if(1==$E1del)
{
	$IdArr	= explode('_',$delValue);
	$delValue = $IdArr[0];
	$AAS_E1ID = $IdArr[1];

	$sysId = '222_99_99';
	
	$sysIdArr	= explode('_',$sysId);
	$sysTypeNo	= $sysIdArr[0];
	$sysNo		= $sysIdArr[1];
	$subSysNo	= $sysIdArr[2];
	
	$oidstr = '2.5.1';
	$objWhereStr= '';	
	$objWhereStr =getLevelWhere($oidstr);	
	
	$objDb		= 'OBJ_'.$sysTypeNo;
	$paramTable = 'param_'.$sysNo;

	$defSql = " SELECT initValue FROM paramConf WHERE $objWhereStr";
	$defRes = @mysqli_query($pubConn,$defSql);
	$row = @mysqli_fetch_array($defRes);
	
	if($TypeIn == 3)//added by arwean 2006-03-30
	{
		$selSql = "select initValue from $paramTable where $objWhereStr and instanceNo='$delValue' ";
		$result = @mysqli_query($pubConn,$selSql);
		$rowFind = @mysqli_fetch_array($result);
		//MTP3_8_pub
		$VSS_MTP3Table	 = 'param_8';
		$selSql = "select initValue,instanceNo from $VSS_MTP3Table where $objWhereStr and initValue!='$row[initValue]'";
		$result = @mysqli_query($pubConn,$selSql);
		if(0)
	    {
	    	echo "<br>selSql: $selSql";
	    	echo mysqli_num_rows($result);
	    	exit;
	    }
		while($Row_1=@mysqli_fetch_array($result))
		{
			if($Row_1[initValue]==$rowFind[initValue])
			{
				$delSql = "UPDATE $VSS_MTP3Table SET initValue = '$row[initValue]' 
			            WHERE $objWhereStr AND instanceNo='$Row_1[instanceNo]'";
			    if(0)
			    {
			    	echo "<br>delSql: $delSql";
			    	exit;
			    }
				$delRes = @mysqli_query($pubConn,$delSql);
				echo mysqli_error($pubConn);	
				break;
			}
		}		
	}//end if
	
	$delSql = "UPDATE $paramTable SET initValue = '$row[initValue]' 
            WHERE subSysNo = '$subSysNo' AND $objWhereStr AND instanceNo='$delValue'";
	if($DEBUG)	echo "<br>delSql=$delSql";
	$delRes = @mysqli_query($pubConn,$delSql);
	echo mysqli_error($pubConn);
	if($DEBUG) echo "$TypeIn<br>";
	if($TypeIn == 2)
	{
		//MTP3_11_pub
		$AAS_MTP3Table	 = 'param_11';
		$delSql = "UPDATE $AAS_MTP3Table SET initValue = '$row[initValue]' 
	            WHERE $objWhereStr AND instanceNo='$AAS_E1ID'";
		if($DEBUG)	echo "<br>delSql=$delSql";
		$delRes = @mysqli_query($pubConn,$delSql);
		echo mysqli_error($pubConn);
	}				
	
	echo "<script LANGUAGE=\"JavaScript\">";
	echo "\n window.location.href=\"$backurl\";";
	echo "\n </script>";
	exit();				
}
if(1==$E1lock)
{
		$IdArr	= explode('_',$delValue);
		$delValue = $IdArr[0];
		$AAS_E1ID = $IdArr[1];
	
		$sysId = '222_99_99';
		
		$sysIdArr	= explode('_',$sysId);
		$sysTypeNo	= $sysIdArr[0];
		$sysNo		= $sysIdArr[1];
		$subSysNo	= $sysIdArr[2];
		
		$oidstr = '2.5.1';
		$objWhereStr= '';	
		$objWhereStr =getLevelWhere($oidstr);
		
		
		$objDb		= 'OBJ_'.$sysTypeNo;
		$paramTable = 'param_'.$sysNo;

		$defSql = " SELECT initValue FROM $paramTable WHERE $objWhereStr AND instanceNo='$delValue'";
		$defRes = @mysqli_query($pubConn,$defSql);
		$row = @mysqli_fetch_array($defRes);
		$flagoffset = "06.0-06.0";
		$row[initValue] = setBitValue($row[initValue],$flagoffset,0);

		$delSql = "UPDATE $paramTable SET initValue = '$row[initValue]' 
	            WHERE subSysNo = '$subSysNo' AND $objWhereStr AND instanceNo='$delValue'";
		if($DEBUG)	echo "<br>delSql=$delSql";
		$delRes = @mysqli_query($pubConn,$delSql);
		echo mysqli_error($pubConn);
		
		$commIdStr	=oidSysCommSend($sysId,$nSetComm,$oidstr);
		if($commIdStr=='-1')
		{
			DelComm($commArr);
			echo "<br><br><b>Error while getting/setting parameters. Please check the device state!<br>";
			echo "oidSysCommSend($tmpSysId,$nSetComm,$tmpObjIdStr)<br>";
			echo "<p align=\"left\"><a href=\"JavaScript:history.go(-1)\"><img align=absBottom border=0 src=\"../../images/left.gif\" width=\"14\" height=\"14\">Back</a>";			
			exit();
		}
		
		if($DEBUG) echo "$TypeIn<br>";
		if($TypeIn == 2){
			//MTP3_11_pub
			$AAS_MTP3Table	 = 'param_11';
			$delSql = "UPDATE $AAS_MTP3Table SET initValue = '$row[initValue]' 
		            WHERE $objWhereStr AND instanceNo='$AAS_E1ID'";
			if($DEBUG)	echo "<br>delSql=$delSql";
			$delRes = @mysqli_query($pubConn,$delSql);
			echo mysqli_error($pubConn);
		}				
		
			echo "<script LANGUAGE=\"JavaScript\">";
			echo "\n window.location.href=\"$backurl\";";
			echo "\n </script>";
			exit();				
}
if(1==$E1unlock)
{
		$IdArr	= explode('_',$delValue);
		$delValue = $IdArr[0];
		$AAS_E1ID = $IdArr[1];
	
		$sysId = '222_99_99';
		
		$sysIdArr	= explode('_',$sysId);
		$sysTypeNo	= $sysIdArr[0];
		$sysNo		= $sysIdArr[1];
		$subSysNo	= $sysIdArr[2];
		
		$oidstr = '2.5.1';
		$objWhereStr= '';	
		$objWhereStr =getLevelWhere($oidstr);
		
		
		$objDb		= 'OBJ_'.$sysTypeNo;
		$paramTable = 'param_'.$sysNo;

		$defSql = " SELECT initValue FROM $paramTable WHERE $objWhereStr AND instanceNo='$delValue'";
		$defRes = @mysqli_query($pubConn,$defSql);
		$row = @mysqli_fetch_array($defRes);
		$flagoffset = "06.0-06.0";
		$row[initValue] = setBitValue($row[initValue],$flagoffset,1);

		$delSql = "UPDATE $paramTable SET initValue = '$row[initValue]' 
	            WHERE subSysNo = '$subSysNo' AND $objWhereStr AND instanceNo='$delValue'";
		if($DEBUG)	echo "<br>delSql=$delSql";
		$delRes = @mysqli_query($pubConn,$delSql);
		echo mysqli_error($pubConn);
		
		$commIdStr	=oidSysCommSend($sysId,$nSetComm,$oidstr);
		if($commIdStr=='-1')
		{
			DelComm($commArr);
			echo "<br><br><b>Error while getting/setting parameters. Please check the device state!<br>";
			echo "oidSysCommSend($tmpSysId,$nSetComm,$tmpObjIdStr)<br>";
			echo "<p align=\"left\"><a href=\"JavaScript:history.go(-1)\"><img align=absBottom border=0 src=\"../../images/left.gif\" width=\"14\" height=\"14\">Back</a>";			
			exit();
		}
		
		if($DEBUG) echo "$TypeIn<br>";
		if($TypeIn == 2){
			//MTP3_11_pub
			$AAS_MTP3Table	 = 'param_11';
			$delSql = "UPDATE $AAS_MTP3Table SET initValue = '$row[initValue]' 
		            WHERE $objWhereStr AND instanceNo='$AAS_E1ID'";
			if($DEBUG)	echo "<br>delSql=$delSql";
			$delRes = @mysqli_query($pubConn,$delSql);
			echo mysqli_error($pubConn);
		}				
		
			echo "<script LANGUAGE=\"JavaScript\">";
			echo "\n window.location.href=\"$backurl\";";
			echo "\n </script>";
			exit();				
}

if($setSys)
{
	echo "<script LANGUAGE=\"JavaScript\">";
	echo " location='./wxc2_sp.php?infoNo=$infoNo&trunkgp=$trunkgp&gtt=$gtt&sysNo=$sysNo&linkset=$linkset&gttSSN=$gttSSN&grpNo=$grpNo&appType=$appType';";
	echo "</script>";
}

if($setSys || $getSys  || $undoSet)
{
	echo "<br><br><h4><font color=\"#0000ff\">Finished!</font></h4>";
	if($DEBUG) exit();
	//sleep(1);
	echo "<script LANGUAGE=\"JavaScript\">";
	echo " location='$backurl';";
	echo "</script>";
	exit();
}


//==========================================================
//输出并显示数据
//==========================================================
?>

<body topmargin="0" leftmargin="12">
<?php
if(!isset($linkset))
{
	if(!isset($linkset))
		echo "<font><b>ERROR!!:linkset == NULL</b></font><br>";	
	exit(0);
}
echo "<form method=\"POST\" name=\"setForm\" action=\"$PHP_SELF?trunkgp=$trunkgp&infoNo=$infoNo&linkset=$linkset\">";
{//show help and back
	echo "<table border=\"0\" width=\"100%\">";
	echo "<tr>";
	echo "<td width=\"50%\">";
	echo "Configuration > <a href=\"../overview/overview.php\">Network</a> > ";
	echo "<a href=\"./wxc2_sp.php?trunkgp=$trunkgp&infoNo=$infoNo&gtt=$gtt&sysNo=$sysNo&linkset=$linkset&gttSSN=$gttSSN&grpNo=$grpNo&appType=$appType\">$devicename</a> > ";
	echo "<a href=\"#\">$elementName</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%\">";
				/*
				echo "<b>MSC SP $devicename:</b>&nbsp;&nbsp;";
				*/
				echo "$Spname&nbsp;&nbsp;";
			echo "</td>";
			echo "<td width=\"20%\" align=\"right\">";
					echo "<input type=\"submit\" title=\"$strTitleGet\" name=\"getSys\" value=\"$strGet\" class=\"button\" style=\"cursor:pointer; left: 1; top: 2; width: 60; height: 25; position: relative\">";
					echo "&nbsp;&nbsp;&nbsp;";
					echo "<input type=\"submit\" title=\"$strTitleSet\" name=\"setSys\" value=\"$strSet\" class=\"button\" style=\"cursor:pointer; left: 1; top: 2; width: 60; height: 25; position: relative\">";
				echo "</td>";
			echo "<td width=\"10%\">";
				echo "<p align=\"right\"><a href=\"./wxc2_sp.php?trunkgp=$trunkgp&gtt=$gtt&sysNo=$sysNo&infoNo=$infoNo&linkset=$linkset&gttSSN=$gttSSN&grpNo=$grpNo&appType=$appType\"><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=\"trunkgp\" value=\"$trunkgp\">";
		echo "<input type=\"hidden\" name=\"gtt\" value=\"$gtt\">";
		echo "<input type=\"hidden\" name=\"sysNo\" value=\"$sysNo\">";
		echo "<input type=\"hidden\" name=\"gttSSN\" value=\"$gttSSN\">";
		echo "<input type=\"hidden\" name=\"grpNo\" value=\"$grpNo\">";
		echo "<input type=\"hidden\" name=\"appType\" value=\"$appType\">";
		echo "<input type=\"hidden\" name=\"infoNo\" value=\"$infoNo\">";
		echo "</table>";
		echo "<br>";
	}
}
?>

<?php

echo "<table rules=rows border=\"1\" width=\"100%\" cellpadding=\"1\" cellspacing=\"0\" bordercolor=\"#666666\" bordercolordark=\"#FFFFFF\">";
if($linkset!=-1)
{//Linkset start
	echo "<tr bgcolor=\"#E6E6E6\">";
	echo "<td width=\"15%\" rowspan=\"1\" style=\"border-right:1px solid\"><b>&nbsp;Linkset</b></td>";
	echo "<td width=\"15%\">No.</td>";
	echo "<td width=\"15%\">NI</td>";
	echo "<td width=\"15%\">DPC</td>";
	echo "<td width=\"15%\">ACN</td>";
	echo "<td width=\"25%\" colspan=\"2\">Status</td>";
	echo "</tr>";
	
	{//查询LinkSet参数表
		$out_time=date("Y-m-d H:i:s",mktime(date("H"),date("i"),date("s")-30,date("m"),date("d"),date("Y")));
		$HbparamSql = " SELECT detailStat FROM OMC_PUB.sysStat  
				WHERE sysTypeNo='200' AND sysNo='9' AND (subSysNo='0' or subSysNo='1') AND updateTime>'$out_time'
				";
		$Hbresult = mysqli_query($pubConn,$HbparamSql);				
		while($Hbvalue_mpt3Arr[] = mysqli_fetch_array($Hbresult));//取mtp3 的heartbeat		
		if(sizeof($Hbvalue_mpt3Arr)==3)
			$isDualServ=1;
		if(0)echo "<br>$HbparamSql<br>Hbvalue_mpt3: {$Hbvalue_mpt3Arr[0][detailStat]}";
		
		$linksetConfArr=array(
			array('Linkset DPC',		'0.0-2.7',	'DPC'),
			array('Network indicator',	'3.0-3.1',	'NetID'),
			array('Linkset loopback',	'3.3-3.3',	'LoopFlag')
			);
		
		$NetIdConfArr=array('International','International-S','National','National-S');
		
		$LoopConfArr=array('Disable','Enable');
		
		$sysId = '222_99_99';
		
		$sysIdArr	= explode('_',$sysId);
		$sysTypeNo	= $sysIdArr[0];
		$sysNo		= $sysIdArr[1];
		$subSysNo	= $sysIdArr[2];
		
		$oidstr = '2.4.1';
		
		$objWhereStr= '';
		$objWhereStr =getLevelWhere($oidstr);
		
		$objDb		= 'OBJ_'.$sysTypeNo;
		$paramTable = 'param_'.$sysNo;
		
		
		$paramSql = " SELECT initValue,readValue,instanceNo FROM $paramTable  
					WHERE subSysNo = '$subSysNo' AND  $objWhereStr AND instanceNo ='$linkset' 
					";
		
		$Result = mysqli_query($pubConn,$paramSql);				
		$Row	= mysqli_fetch_array($Result);
		//------------读LinkSet参数表---------------------
		$DPC	= getBitValue($Row[initValue],$linksetConfArr[0][1]);
		$DPC 	= hexdec($DPC);
		$NetID	= BinDec(getBitValue($Row[initValue],$linksetConfArr[1][1]));
		$loopFlag = getBitValue($Row[initValue],$linksetConfArr[2][1]);
	}
	
	{//Alternative linkset
		$AlternativeArr=array(
			array('Linkset DPC',		'0.0-2.7',	'DPC'),
			array('Normal linkset',		'3.0-3.7',	'linkset'),
			array('Alternative linkset','4.0-4.7',	'Alternative')
			);
		$temp = $NetID+1;
		$oidstr = '2.6.'.$temp;
	
		$objWhereStr= '';
		$objWhereStr =getLevelWhere($oidstr);
	
		$paramSql = " SELECT initValue,readValue,instanceNo FROM $paramTable  
					WHERE subSysNo = '$subSysNo' AND  $objWhereStr
					";
	
		$Result_2 = mysqli_query($pubConn,$paramSql);
		$num =0;
		while($Row_2 = mysqli_fetch_array($Result_2))
		{
			$t_DPC = hexdec(getBitValue($Row_2[initValue],$AlternativeArr[0][1]));			
			$t_LINKSET = hexdec(getBitValue($Row_2[initValue],$AlternativeArr[1][1]));
			
			if($t_DPC == $DPC && $t_LINKSET == $linkset)
			{
				$Alternative = hexdec(getBitValue($Row_2[initValue],$AlternativeArr[2][1]));
				$ACNinstNo = $Row_2[instanceNo];
				$num++;
				break;
			}
		}
		
		if($num == 0 )
		{
			$paramSql = " SELECT initValue,readValue,instanceNo FROM $paramTable  
						WHERE initValue = '0000008080' AND  $objWhereStr
						";
			$Result_2 = mysqli_query($pubConn,$paramSql);
			$Row_2 = mysqli_fetch_array($Result_2);
			
			$DPC_new = dechex($DPC);
			$DPC_new = omc_keep_length($DPC_new,0,6);
			$Row_2[initValue] = setBitValue($Row_2[initValue],$AlternativeArr[0][1],$DPC_new);
	
			$hex_linkset = dechex($linkset);
			$hex_linkset = omc_keep_length($hex_linkset,0,2);
			$Row_2[initValue] = setBitValue($Row_2[initValue],$AlternativeArr[1][1],$hex_linkset);
			$Alternative = 128;
			$ACNinstNo = $Row_2[instanceNo];
			
			$updSql = "UPDATE $paramTable SET initValue = '$Row_2[initValue]'   
				WHERE $objWhereStr AND instanceNo = '$Row_2[instanceNo]'
				";
			mysqli_query($pubConn,$updSql);
			
			if($devicename==$strGttObjects)
			{
				//ACNinstNo
				$temp = $NetID+2;
				$tmpACN = '2.7.'.$temp;
				$tmpWhereStr =getLevelWhere($tmpACN);
				
				$tmpParamConfTable='OBJ_222.paramConf';
				$getSql="SELECT initValue FROM $tmpParamConfTable 
							WHERE $tmpWhereStr
						";
				$result	=mysqli_query($pubConn,$getSql);
				$rows=mysqli_fetch_array($result);
				$tmpDefaultValue=$rows[initValue];				
						
				$updSql = "UPDATE $paramTable SET initValue = '$tmpDefaultValue'   
					WHERE $tmpWhereStr AND instanceNo = '$Row_2[instanceNo]'
					";
				mysqli_query($pubConn,$updSql);								
			}
		}			
	}
	
	{//status
	
		$StatArr=array('Unavailable','Available','Inhibited','Reserved');				
	
		//从heartbeat读statue
		$Hboffset=39+64+Floor($linkset/4);
		//echo "<hr>$linkset<hr>";
		$tmpValue=substr($Hbvalue_mpt3Arr[0][detailStat],$Hboffset*2,2);
		$bitoff	=$linkset%4;
		$bitoff1=$bitoff*2;
		$bitoff2=$bitoff1+1;
		$bitoff='0.'.$bitoff1.'-0.'.$bitoff2;
		$tmp=bindec(getBitValue($tmpValue,$bitoff));		
		if(0) echo "<br>offset:$Hboffset<br>tmpValue:$tmpValue<br>bitoffset: $bitoff<br>tmp: $tmp";
		if($tmp>1)
			$tmp=0;			
	
		$Status = $StatArr[$tmp];
		//echo "<hr>$Status<hr>";
	}
	
	
	{//显示Linkset参数表
		$setobjIdstr = "2.4.1-2.4.1-2.6.";
		$temp = $NetID+1;
		$setobjIdstr = $setobjIdstr.$temp;
		echo "<tr>";
		echo "<td bgcolor=\"#E6E6E6\" style=\"border-right:1px solid\">&nbsp;</td>";
		if($TypeIn == 16)
			echo "<td ><a href=\"javascript:openSet('$setobjIdstr','$linkset-$ACNinstNo-$elementName','Linkset','$sysId','$trunkgp','$linkset','Switch','$backurl','$infoNo')\">$linkset&nbsp</a></td>";
		else
			echo "<td ><a href=\"javascript:openSet('$setobjIdstr','$linkset-$ACNinstNo-$elementName','Linkset','$sysId','$trunkgp','$linkset','Other','$backurl','$infoNo')\">$linkset&nbsp</a></td>";
		echo "<td >$NetIdConfArr[$NetID]&nbsp;</td>";
		echo "<input type=\"hidden\" name=\"newNetId\" value=\"$NetId\">";
		echo "<td >$DPC&nbsp;</td>";	
		echo "<input type=\"hidden\" name=\"DPC\" value=\"$DPC\">";
		
		$temp = $NetID+2;
		$oidACN = '2.7.'.$temp;
		echo "<input type=\"hidden\" name=\"oidACN\" value=\"$oidACN\">";
		if($devicename==$strGttObjects)
			echo "<td ><a href=\"javascript:openSet('$oidACN','$ACNinstNo','ACN','$sysId','$trunkgp','$linkset','$webname','$backurl','$infoNo')\">Edit&nbsp;</a></td>";
		else
			echo "<td>--</td>";
		echo "<td colspan=\"2\">$Status&nbsp;</td>";
	}
	echo "</tr>";
}//Linkset end

{//E1 strat
//------------查询E1参数表---------------------

$E1ConfArr=array(
	array('Flag',		'06.5-06.5',	'Flag'),
	array('Linkset',	'00.0-00.7',	'Linkset'),
	array('SLC',		'01.0-01.7',	'SLC'),
	array('MTP3IP',		'02.0-05.7',	'MTP3IP'),
	array('Link type',	'06.1-06.3',	'Link type')
	);
	
$LinkTypeArr=array('Non-sigtran','Sigtran','SCCP Lite');

$sysId = '222_99_99';

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

$oidstr = '2.5.1';

$objWhereStr= '';
$objWhereStr =getLevelWhere($oidstr);

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

$paramSql = " SELECT initValue,readValue,instanceNo FROM $paramTable  
			WHERE subSysNo = '$subSysNo' AND  $objWhereStr
			ORDER BY instanceNo
			";
//echo "<br>$paramSql";
$Result = mysqli_query($pubConn,$paramSql);				


//------------读E1参数表---------------------
$n = 0;
$addflag=0;
$E1listarr="";
while($Row = mysqli_fetch_array($Result))
{
	$flag		= getBitValue($Row[initValue],$E1ConfArr[0][1]);
	$E1linkset	= hexdec(getBitValue($Row[initValue],$E1ConfArr[1][1]));

	if($flag && $E1linkset == $linkset)
	{
		//echo "<br>$n:".$Row[instanceNo];
		$instNo[$n]	= $Row[instanceNo];
		$SLC[$n]    = hexdec(getBitValue($Row[initValue],$E1ConfArr[2][1]));
		$MTP3IP[$n] = getBitValue($Row[initValue],$E1ConfArr[3][1]);
		$tmptype 	= bindec(getBitValue($Row[initValue],$E1ConfArr[4][1]));
		$Linktype[$n] =	$LinkTypeArr[$tmptype];
		$Lockflag[$n] = getBitValue($Row[initValue],"06.0-06.0");
		{//status

		$StatArr=array('Unavailable','Available','Reserved');				

		//从heartbeat读statue
		$Hboffset=39+Floor($Row[instanceNo]/4);
		$tmpValue=substr($Hbvalue_mpt3Arr[0][detailStat],$Hboffset*2,2);
		if($isDualServ && $Row[instanceNo]>=128)
			$tmpValue=substr($Hbvalue_mpt3Arr[1][detailStat],$Hboffset*2,2);
		$bitoff	=$Row[instanceNo]%4;
		$bitoff1=$bitoff*2;
		$bitoff2=$bitoff1+1;
		$bitoff='0.'.$bitoff1.'-0.'.$bitoff2;

		$tmp=bindec(getBitValue($tmpValue,$bitoff));		
		if(0) echo "<br>offset:$Hboffset<br>tmpValue:$tmpValue<br>bitoffset: $bitoff<br>tmp: $tmp";
		if($tmp>1)
			$tmp=0;			
		$Linkstate[$n] = $StatArr[$tmp];
		
		}
		//$addflag,用来决定在哪一个平面添加下一个E1 link	
		if($instNo[$n]>127){
			$addflag++;
		}else{
			$addflag--;
		}
		if($n==0){
			$E1listarr = 	$instNo[$n];
		}else{
			$E1listarr = $E1listarr."_".$instNo[$n];		
		}
		$n++;
	}

}
echo "<input type=\"hidden\" name=\"E1listarr\" value=\"$E1listarr\">";

//------------显示E1参数表---------------------	
$rowspan = $n +1;
if($n == 0)
{
	$SLC[0] = 256;
	$rowspan=2;
}
$setobjIdstr = "2.5.1-2.5.1-2.5.2";
echo "<tr bgcolor=\"#E6E6E6\">";
echo "<td  width=\"15%\" style=\"border-right:1px solid\">";
	echo "<table width=\"100%\" cellpadding=\"1\" cellspacing=\"1\" border=\"0\"><tr>";
	echo "<td align=\"left\"><b>Link</b></td>";
	$tmpBackUrl="./wxc2_sp_signaling.php?trunkgp=$trunkgp&gtt=$gtt&sysNo=$sysNo&infoNo=$infoNo&linkset=$linkset&gttSSN=$gttSSN&grpNo=$grpNo&appType=$appType";
	if($TypeIn ==2 && $n > 1)
	{
		echo "<td align=\"right\"><a href=\"javascript:newError('E1')\"><font size=4>+</font></a></td>";		
	}
	elseif($n > 15)
	{
		echo "<td align=\"right\"><a href=\"javascript:newError('E1')\"><font size=4>+</font></a></td>";		
	}
	else
	{
		echo "<td align=\"right\"><a href=\"javascript:openSet('$SLC[0]','new','E1_link','$addflag>$n','$trunkgp','$linkset','$webname','$tmpBackUrl','$infoNo')\"><font size=4>+</font></a></td>";
	}
	echo "</tr></table>";
echo "</td>";
echo "<td  width=\"15%\" >No.</td>"; 
echo "<td  width=\"15%\" colspan=\"2\" >SLC</td>";
//echo "<td >Link type</td>";
//echo "<td >SG no.</td>";
echo "<td width=\"15%\" >Admin State</td>";
echo "<td width=\"15%\" >Status</td>";
echo "<td width=\"10%\" align=\"right\">Delete</td>";
echo "</tr>";

if($n == 0)
{
	echo "<tr><td bgcolor=\"#E6E6E6\"  style=\"border-right:1px solid\"></td><td colspan=\"6\">--</td></tr>";
}
else
{
	echo "<td bgcolor=\"#E6E6E6\" rowspan=\"$rowspan\" style=\"border-right:1px solid\">&nbsp;</td>";
}
for($i=0;$i < $n;$i++)
{
	$tempnum = $instNo[$i]/8;
	$cardno = Floor($tempnum);
	$cardE1no = $instNo[$i] - $cardno*8;
	$cscNo = Floor($cardno/16);
	$subCardNo = $cardno%16;
	$cardname = "CSC$cscNo"."&nbsp;"."Card-$subCardNo-$cardE1no";
		
	echo "<tr>";	
	echo "<td ><a href=\"javascript:openSet('$SLC[$i]','$instNo[$i]','E1_link','$sysId','$trunkgp','$linkset','$webname','$backurl','$infoNo')\">$cardname</a></td>";
	echo "<td  colspan=\"2\">$SLC[$i]</td>";
//	echo "<td >$Linktype[$i]&nbsp;</td>";	
//	echo "<td >$SGno[$i]&nbsp;</td>";		
	
	if($SLC[$i] == 0)
	{
		$delE1ID = 0;
	}
	else
	{
		$delE1ID = 1;
	}	
	$delID = $instNo[$i]."_".$delE1ID;
	if($DEBUG) echo "$delID<br>";
	
//	if($Lockflag[$i])
//		echo "<td><input type=\"reset\" name=\"dolock\" value=\"Lock\" class=\"button\" style=\"cursor:pointer; left: 0; top: 0; width: 45; height: 20; position: relative\" onClick=\"javascript:delFirm('$delID','E1lock','$trunkgp','$linkset','$gtt',this)\">";
//	else
//		echo "<td><input type=\"reset\" name=\"dounlock\" value=\"Unlock\" class=\"button\" style=\"cursor:pointer; left: 0; top: 0; width: 45; height: 20; position: relative\" onClick=\"javascript:delFirm('$delID','E1unlock','$trunkgp','$linkset','$gtt',this)\">";

	if($Lockflag[$i])
		echo "<td><a href=\"javascript:delFirm('$delID','E1lock','$trunkgp','$linkset','$gtt',this)\" title=\"to lock this Link\">Unlocked</a>";
	else
		echo "<td><a href=\"javascript:delFirm('$delID','E1unlock','$trunkgp','$linkset','$gtt',this)\" title=\"to unlock this Link\">Locked</a>";

	echo "</td>";	
	
	echo "<td>$Linkstate[$i]&nbsp;</td>";

	echo "<td align=\"right\"><input type=\"checkbox\" name=\"C$instanceNo\" value=\"ON\" onClick=\"javascript:delFirm('$delID','E1','$trunkgp','$linkset','$gtt',this)\" ></td>";
	echo "</tr>";	
}
}//E1 end
?>
</form>
</body>
</html>

<script LANGUAGE="JavaScript"> 
function delFirm(No,deltype,trunkgp,linkset,gtt,delcheckbox)
{
	var delValue,x,y;
	var baseHref;
	x = document.body.scrollLeft;
	y = document.body.scrollTop;
    baseHref = '<?php echo $PHP_SELF."?infoNo=".$infoNo."&grpNo=".$grpNo."&appType=".$appType;?>';
	if(deltype == 'E1')
	{
		if(confirm('Do you want to delete the selected?')!=true)
			delcheckbox.checked=false;
		else
			window.location.href=baseHref+"&E1del=1&delValue="+No+"&linkset="+linkset+"&trunkgp="+trunkgp+"&gtt="+gtt;
	}
	
	if(deltype == 'E1lock')
	{
		if(confirm('Do you want to Lock the Link?')!=true)
			delcheckbox.checked=false;
		else			
			window.location.href=baseHref+"&E1lock=1&delValue="+No+"&linkset="+linkset+"&trunkgp="+trunkgp+"&gtt="+gtt;
	}
	if(deltype == 'E1unlock')
	{
		if(confirm('Do you want to Unlock the Link?')!=true)
			delcheckbox.checked=false;
		else			
			window.location.href=baseHref+"&E1unlock=1&delValue="+No+"&linkset="+linkset+"&trunkgp="+trunkgp+"&gtt="+gtt;		
	}
		
}

function openSet(objIdStr,instanceNo,setname,sysId,tg,linkset,webname,backurl,infoNo)
{
	backurl=escape(backurl);
	devicename = "<?php echo $devicename; ?>";
	spname = "<?php echo $Spname; ?>";
	//alert(devicename);
	if(setname == 'ACN')
		URL="./ACNconf.php?infoNo="+infoNo+"&instanceNo="+instanceNo+"&objIdStr="+objIdStr+"&sysId="+sysId+"&webname="+webname+"&devicename="+devicename+"&trunkgp="+tg+"&linkset="+linkset+"&backurl="+backurl;
	else if(setname == 'E1_link')
		URL="./E1linkconf.php?infoNo="+infoNo+"&instanceNo="+instanceNo+"&slc="+objIdStr+"&addflag="+sysId+"&spname="+spname+"&devicename="+devicename+"&trunkgp="+tg+"&linkset="+linkset+"&backurl="+backurl;
	else
		URL="./paramconf.php?infoNo="+infoNo+"&instanceNo="+instanceNo+"&objIdStr="+objIdStr+"&sysId="+sysId+"&setname="+setname+"&trunkgp="+tg+"&linkset="+linkset+"&webname="+webname+"&devicename="+devicename+"&backurl="+backurl;
	window.location.href=URL;
}
</script>
