<?php
/*********************************************************      
 程序说明：         
    功能说明：设置七号信令中的 Link
              
    调用关系：调用: header.inc    
              被调用:        
 
    变量说明：

    作者：    
      
修改注释：      
NO.1      
姓名： Cui Ticun         
时间：2004-4-21
修改说明：Support OMC7.0,从advanced移到configuration中，修改
		 和添加了上方的操作按钮
*********************************************************/
require("../../inc/header.inc");
$DEBUG =0;

if($DEBUG) echo "<br>正在调试中！！";
//==========================================================
//变量定义
//==========================================================
$pubDb			= 'OMC_PUB';
$numberPerPage	= 100;		//每页纪录数
$paramTable		= 'OBJ_222.param_99';

$sysId		='222_99_99';
$initValue	='initValue';
$listPageUrl="./ss7LinkList.php?setObjIdStr=$objIdStr&setInstanceNo=$instanceNo";

$objIdStr='2.5.1';

$linkAttConfArr=array(
	array('Flag','06.0-06.0'),
	array('Linkset ID',	'00.0-00.7'),
	array('SLC No.',		'01.0-01.7'),
	array('Host IP',		'02.0-05.7'),
	array('Signaling Type',		'06.1-06.3'),
	array('MTP3-Lite Application Mode','06.4-06.4'),
	array('MTP3-Lite Remote IP','09.0-12.7'),
	array('MTP3-Lite Inactivity Timeout','13.0-13.7'),
	array('MTP3-Lite Allowed Timeout Times','14.0-14.7'),
	array('SG ID',			'07.0-07.7'),
	array('M2UA Interface ID','08.0-08.7'),
	array('Alternative Host IP','15.0-18.7')
);

$linkTypeArr=array(
	0=>'8ECP',
	1=>'M2UA',
	2=>'MTP3-Lite',
	3=>'IUA',
	4=>'M3UA'
);

//==========================================================
//输入变量
//==========================================================
if($DEBUG) echo "<BR>sysId		=$sysId";
if($DEBUG) echo "<BR>instanceNo	=$instanceNo";
if($DEBUG) echo "<BR>objIdStr	=$objIdStr";

//==========================================================
//数据处理
//==========================================================



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


$levelWhere = getLevelWhere($objIdStr);
if($DEBUG) echo "<BR>levelWhere=$levelWhere";

$getSql="SELECT $initValue,instanceNo  FROM $paramTable 
			WHERE $levelWhere
		";
if($DEBUG) echo "<BR>getSql=$getSql";
$result	=mysqli_query($pubConn,$getSql);
echo mysqli_error($pubConn);

$defSql = "select initValue from OBJ_222.paramConf where $levelWhere and paramType='2'";//paramType=2,local
$defResult = mysqli_query($pubConn,$defSql);
$defRow = mysqli_fetch_array($defResult);
$defValue = $defRow[initValue];
if($DEBUG)echo "<br>defValue=$defValue";
if($DEBUG) echo "<BR>";
?>
<br>
<body topmargin="0" leftmargin="12">
<?php 
echo "<form method=\"POST\" name=\"setForm\" action=\"$PHP_SELF\">";
if($instanceNo == 'new')
	{
	$orgValue = $defValue;
	}
else
	{
	$selSql = "SELECT  initValue    
					 FROM $paramTable 
					 WHERE level_1='2' AND level_2='5'  AND level_3='1' AND instanceNo='$instanceNo'
					";
	if($DEBUG) echo "<BR>selSql=$selSql";
	$result=mysqli_query($pubConn,$selSql);
	echo mysqli_error($pubConn);
	$rows  =mysqli_fetch_array($result);
	$orgValue=$rows[0];
	if($DEBUG) echo "<br>orgvalue=$orgValue";
	echo mysqli_error($pubConn);
	//$orgValue = getSysParamValue($sysId,$objIdStr,$instanceNo,$initValue);
	}
if($_SERVER['REQUEST_METHOD'] == "POST"){	
	//保存改动
	$newValue=$orgValue;

	$flag=dechex($flag);
	$newValue=setBitValue($newValue,$linkAttConfArr[0][1],$flag);
	
	$linksetNo	=dechex($linksetNo);
	$linksetNo= strlen($linksetNo) < 2?'0'.$linksetNo:$linksetNo;
	if($DEBUG) echo "<BR>linksetNo=$linksetNo";
	$newValue=setBitValue($newValue,$linkAttConfArr[1][1],$linksetNo);
	if($DEBUG) echo "<BR>newValue=$newValue";

	$slcNo	=dechex($slcNo);
	$slcNo= strlen($slcNo) < 2?'0'.$slcNo:$slcNo;
	if($DEBUG) echo "<BR>slcNo=$slcNo";
	$newValue=setBitValue($newValue,$linkAttConfArr[2][1],$slcNo);
	if($DEBUG) echo "<BR>newValue=$newValue";

	
	if($cpcIp=='')
		$cpcIp="FFFFFFFF";
	else
		$cpcIp=ip2byte($cpcIp);
	if($DEBUG) echo "<BR>cpcIp=$cpcIp";
	$newValue=setBitValue($newValue,$linkAttConfArr[3][1],$cpcIp);
	if($DEBUG) echo "<BR>newValue=$newValue";
	
	
	if($DEBUG) echo "<BR>linkType=$linkType";
	$linkType=decbin($linkType);
	
	//get the bit length of link type modfiy JianHuiZheng 2007-11-30
	$pos=explode("-",$linkAttConfArr[4][1]);
	$len=$pos[0]*10-$pos[1]*10;
	$len=abs($len)+1;
	$linkType=omc_keep_length($linkType,"0",$len);
	
	$newValue=setBitValue($newValue,$linkAttConfArr[4][1],$linkType);
	if($DEBUG) echo "<BR>newValue=$newValue";
	
	
	//MTP3-Lite Application Mode
	$mtp3_lite_app_mode=dechex($mtp3_lite_app_mode);
	$newValue=setBitValue($newValue,$linkAttConfArr[5][1],$mtp3_lite_app_mode);
	
	//MTP3-Lite Remote IP
	if($mtp3_lite_remote_ip == '')
		$mtp3_lite_remote_ip="FFFFFFFF";
	else
		$mtp3_lite_remote_ip=ip2byte($mtp3_lite_remote_ip);
	$newValue=setBitValue($newValue,$linkAttConfArr[6][1],$mtp3_lite_remote_ip);
	
	//MTP3-Lite Inactivity Timeout
	$mtp3_lite_inact_timeout=dechex($mtp3_lite_inact_timeout);
	$newValue=setBitValue($newValue,$linkAttConfArr[7][1],$mtp3_lite_inact_timeout);
	
	//MTP3-Lite Allowed Timeout times
	$mtp3_lite_allow_timeout_time=dechex($mtp3_lite_allow_timeout_time);
	$newValue=setBitValue($newValue,$linkAttConfArr[8][1],$mtp3_lite_allow_timeout_time);
	
	
	$sgNo	=dechex($sgNo);
	$sgNo	= strlen($sgNo) < 2?'0'.$sgNo:$sgNo;
	if($DEBUG) echo "<BR>sgNo=$sgNo";
	$newValue=setBitValue($newValue,$linkAttConfArr[9][1],$sgNo);
	if($DEBUG) echo "<BR>newValue=$newValue";

	$m2uaInterfaceID	=dechex($m2uaInterfaceID);
	$m2uaInterfaceID= strlen($m2uaInterfaceID) < 2?'0'.$m2uaInterfaceID:$m2uaInterfaceID;
	if($DEBUG) echo "<BR>m2uaInterfaceID=$m2uaInterfaceID";
	$newValue=setBitValue($newValue,$linkAttConfArr[10][1],$m2uaInterfaceID);
	if($DEBUG) echo "<BR>newValue=$newValue";

	
	if($alternativeMTP3=='')
		$alternativeMTP3="FFFFFFFF";
	else
		$alternativeMTP3=ip2byte($alternativeMTP3);
	if($DEBUG) echo "<BR>alternativeMTP3=$alternativeMTP3";
	$newValue=setBitValue($newValue,$linkAttConfArr[11][1],$alternativeMTP3);
	if($DEBUG) echo "<BR>newValue=$newValue";


	$updSql = "UPDATE $paramTable SET initValue = '$newValue'   
					WHERE level_1='2' AND level_2='5'  AND level_3='1' AND instanceNo='$instanceNo'
					";
	if($DEBUG) echo "<BR>updSql=$updSql";
	mysqli_query($pubConn,$updSql);
	echo mysqli_error($pubConn);
	//setSysParamValue($sysId,$objIdStr,$instanceNo,$newValue);
	echo "<script LANGUAGE=\"JavaScript\">";
	echo "\n window.opener.location.href=\"$listPageUrl\";";
	echo "\n window.opener.document.setForm.focus();";
	if(!$DEBUG){
		echo "\n window.close();";
	} 
	echo "\n </script>";
	exit();
}else{
	//显示
	$tableHeader  ="<table border=\"1\" width=\"100%\" cellpadding=\"1\" cellspacing=\"0\" ";
	$tableHeader .="bordercolor=\"#666666\" bordercolordark=\"#FFFFFF\">";
	
	//echo "<br>orgValue=$orgValue";
	echo "$tableHeader";
	echo "<tr bgcolor=\"#E6E6E6\"><td>Name</td><td>Value</td></tr>";
	$flag				=getBitValue($orgValue,$linkAttConfArr[0][1]);
	$flag				=hexdec($flag);
	$linksetNo	=getBitValue($orgValue,$linkAttConfArr[1][1]);
	$linksetNo	=hexdec($linksetNo);
	$slcNo		=getBitValue($orgValue,$linkAttConfArr[2][1]);
	$slcNo		=hexdec($slcNo);
	$cpcIp		=getBitValue($orgValue,$linkAttConfArr[3][1]);
	$cpcIp		=byte2ip($cpcIp);
	$linkType	=getBitValue($orgValue,$linkAttConfArr[4][1]);
	$linkType	=bindec($linkType);
	
	$mtp3_lite_app_mode=getBitValue($orgValue,$linkAttConfArr[5][1]);
	$mtp3_lite_app_mode=hexdec($mtp3_lite_app_mode);
	
	$mtp3_lite_remote_ip=getBitValue($orgValue,$linkAttConfArr[6][1]);
	$mtp3_lite_remote_ip=byte2ip($mtp3_lite_remote_ip);
	
	$mtp3_lite_inact_timeout=getBitValue($orgValue,$linkAttConfArr[7][1]);
	$mtp3_lite_inact_timeout=hexdec($mtp3_lite_inact_timeout);
	
	$mtp3_lite_allow_timeout_time=getBitValue($orgValue,$linkAttConfArr[8][1]);
	$mtp3_lite_allow_timeout_time=hexdec($mtp3_lite_allow_timeout_time);
	
	
	
	$sgNo		=getBitValue($orgValue,$linkAttConfArr[9][1]);
	$sgNo		=hexdec($sgNo);
	$m2uaInterfaceID=getBitValue($orgValue,$linkAttConfArr[10][1]);
	$m2uaInterfaceID=hexdec($m2uaInterfaceID);
	$alternativeMTP3=getBitValue($orgValue,$linkAttConfArr[11][1]);
	$alternativeMTP3=byte2ip($alternativeMTP3);
	
	if($instanceNo == 'new'){
		$levelArr=explode('.',$objIdStr);
		for($j=0;$j<sizeof($levelArr);$j++){
			$levelNo=$j+1;
			${"level_$levelNo"}=$levelArr[$j];
			if($DEBUG) echo "<BR>levelArr[$j]={$levelArr[$j]}";
		}
		$getInstanceSql="SELECT instanceNo FROM $paramTable
								WHERE  level_1='2' AND level_2='5' AND level_3='1'AND   initValue = '$defValue'";
		$result=mysqli_query($pubConn,$getInstanceSql);
		echo mysqli_error($pubConn);
		echo "<tr><td>No.</td><td>";
		if($DEBUG) echo "<br>$getInstanceSql";
		echo "<select name=\"instanceNo\" size=\"1\">";
		while($row=mysqli_fetch_array($result)){
			echo "<option value=$row[instanceNo]>$row[instanceNo]</option>";
		}
		echo"</select>";
		echo"</td></tr>";
	}
	echo "<tr><td>Flag</td><td>";
	$flagArr=array(0=>'Disable',1=>'Enable');
	echo "<select name=\"flag\">";
	for($i=0;$i<sizeof($flagArr);$i++)
	{
		echo "<option value=\"$i\" ";
		if($i == $flag)
			echo "selected";
		echo ">$flagArr[$i]</option>";	
	}
	echo "</td></tr>";

	echo "<tr><td>Linkset ID</td> <td>";
	echo "<input type=\"text\" size=\"3\" maxlength=\"3\" name=\"linksetNo\" value=\"$linksetNo\" class=\"text\">";
	echo "</td></tr>";
	echo "<tr><td>SLC</td>		<td>"; 
	echo "<input type=\"text\" size=\"3\" maxlength=\"3\" name=\"slcNo\" value=\"$slcNo\" class=\"text\">";
	echo "</td></tr>";
	echo "<tr><td>Host IP</td>			<td>";
	echo "<input type=\"text\" size=\"15\" maxlength=\"15\" name=\"cpcIp\" value=\"$cpcIp\" class=\"text\">";
	echo "</td></tr>";
	echo "<tr><td>Signaling Type</td>			<td>";
	
	echo "<select  name=\"linkType\">"; 
	for ($i=0;$i<sizeof($linkTypeArr);$i++)
	{
		echo "<option value=\"$i\" ";
	  if ($i == $linkType)
		{
			echo "selected";
		}
	    echo ">$linkTypeArr[$i]</option>";
	}
	echo "</select>"; 
	echo "</td></tr>";
	
	//MTP3-Lite Application Mode
	$appModeArr=array(0=>"Server",1=>"Client");
	echo "<tr><td>MTP3-Lite Application Mode</td>";
	echo "<td>";
	echo "<select name=\"mtp3_lite_app_mode\">";
	for($i=0;$i<sizeof($appModeArr);$i++)
	{
		echo "<option value=\"$i\" ";
		if($i == $mtp3_lite_app_mode)
			echo "selected";
		echo ">{$appModeArr[$i]}</option>";	
	}
	echo "</select>";
	echo "</td></tr>";
	
	//MTP3-Lite Remote IP
	echo "<tr><td>MTP3-Lite Remote IP</td><td>";
	echo "<input type=\"text\" name=\"mtp3_lite_remote_ip\" value=\"$mtp3_lite_remote_ip\" class=\"text\">";
	echo "</td></tr>";
	
	//MTP3-Lite Inactivity Timeout
	echo "<tr><td>MTP3-Lite Inactivity Timeout</td><td>";
	echo "<input type=\"text\" name=\"mtp3_lite_inact_timeout\" value=\"$mtp3_lite_inact_timeout\" class=\"text\">";
	echo "</td></tr>";
	
	//MTP3-Lite Allowed Timeout times
	echo "<tr><td>MTP3-Lite Allowed Timeout times</td><td>";
	echo "<input type=\"text\" name=\"mtp3_lite_allow_timeout_time\" value=\"$mtp3_lite_allow_timeout_time\" class=\"text\">";
	echo "</td></tr>";
	
	echo "<tr><td>SG ID</td><td>"; 
	echo "<input type=\"text\" size=\"3\" maxlength=\"3\" name=\"sgNo\" value=\"$sgNo\" class=\"text\">";
	echo "</td></tr>";
	echo "<tr><td>M2UA Interface ID</td><td>"; 
	echo "<input type=\"text\" size=\"3\" maxlength=\"3\" name=\"m2uaInterfaceID\" value=\"$m2uaInterfaceID\" class=\"text\">";
	echo "</td></tr>";
	echo "<tr><td>Alternative Host IP</td>	<td>";
	echo "<input type=\"text\" size=\"15\" maxlength=\"15\" name=\"alternativeMTP3\" value=\"$alternativeMTP3\" class=\"text\">";
	echo "</td></tr>";
	
	echo "</table>";

	echo "\n <input type=\"hidden\" name=\"objIdStr\" value=\"$objIdStr\">";
	if($instanceNo != 'new'){
		echo "\n <input type=\"hidden\" name=\"instanceNo\" value=\"$instanceNo\">";
	}
	echo "\n <input type=\"submit\" name=\"set\" value=\"Set\">&nbsp;&nbsp;";
	echo "\n <input type=\"reset\" name=\"reset\" value=\"Reset\">";
}

?>
</table>
</form>
<b>Remarks:</b><br><br>
Linkset: The number of the linkset assigned to this link, range from 0 to 127<br><br>
SLC: Signaling link code, rang from 0 to 15, identify the E1 links within a same linkset<br><br>
IP: For the link 0 to 127, input 98. For the link 128 to 255, input 99
&nbsp;
</body>
</html>
