<?php
/*********************************************************      
 程序说明：         
    功能说明：设置七号信令中的 Linkset
              
    调用关系：调用: 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';
$db	= "OBJ_222";
$numberPerPage	= 100;		//每页纪录数
$paramTable		='OBJ_222.param_99';

$sysId		='222_99_99';
$initValue	='initValue';
$listPageUrl="./ss7LinksetList.php?setObjIdStr=$objIdStr&setInstanceNo=$instanceNo";
$linksetOid	='2.4.1';
//==========================================================
//输入变量
//==========================================================
if($DEBUG) echo "<BR>instanceNo	=$instanceNo";
if($DEBUG) echo "<BR>objIdStr	=$objIdStr";

//==========================================================
//数据处理
//==========================================================
$linksetConfArr=array(
	array('Linkset DPC',		'0.0-2.7',	'DPC'),
	array('Network indicator',	'3.0-3.1',	'NetID'),
	array('Flag',				'3.2-3.2',	'Flag'),
	array('Loopback Option',	'3.3-3.3',	'LoopFlag')
	);
$NetIdConfArr=array(
	array('00','International'),
	array('01','International Spare'),
	array('10','National'),
	array('11','National Spare')
);

$LoopConfArr=array(
	array('0','Disable'),
	array('1','Enable')
);

$flagConfArr=array(0=>"Disable",1=>"Enable");
//==========================================================
//输出并显示数据
//==========================================================
if($DEBUG) echo "<BR>";
?>
<br>
<body topmargin="0" leftmargin="12">

<?php 
echo "<form method=\"POST\" name=\"setForm\" action=\"$PHP_SELF\">";
$tableHeader  ="<table border=\"1\" width=\"100%\" cellpadding=\"1\" cellspacing=\"0\" ";
$tableHeader .="bordercolor=\"#666666\" bordercolordark=\"#FFFFFF\">";

$levelArr=explode('.',$linksetOid);
for($j=0;$j<sizeof($levelArr);$j++){
	$levelNo=$j+1;
	${"level_$levelNo"}=$levelArr[$j];
	if($DEBUG) 
	echo "<BR>levelArr[$j]={$levelArr[$j]}";
}

$defSql	= "SELECT initValue from paramConf 
			WHERE level_1='$level_1' AND level_2='$level_2' AND level_3='$level_3'
		";
if($DEBUG)	
echo "defSql=$defSql<br>";
$defRes	= mysqli_query($pubConn,$defSql);
$defRow = mysqli_fetch_array($defRes);
$defaultValue	= $defRow[initValue];
if($DEBUG)	
echo "defaultValue=$defaultValue<br>";

switch($objIdStr){
	case '2.4.1':
		if($instanceNo == 'new'){
			$orgValue='0000000000000000000000000000000000000000';
		}else{
			$selSql = "SELECT  initValue    
					 FROM $paramTable 
					 WHERE level_1='2' AND level_2='4'  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];
			echo mysqli_error($pubConn);
			//$orgValue=getSysParamValue($sysId,$objIdStr,$instanceNo,$initValue);
		}
		if($_SERVER['REQUEST_METHOD'] == "POST"){	
			//保存改动
			$newValue=$orgValue;
			//OPC
			if($DEBUG) echo "<br>OPC=$OPC"; 
			$OPC=omc_keep_length($OPC,"0","6","1");
			$newValue=setBitValue($newValue,$linksetConfArr[0][1],$OPC);
			if($DEBUG) echo "<br>newValue=$newValue"; 

			
			//NetID
			if($DEBUG) echo "<br>NetID=$NetID"; 
			$newValue=setBitValue($newValue,$linksetConfArr[1][1],$NetID);
			if($DEBUG) echo "<br>newValue=$newValue"; 

			//Flag
			if($DEBUG) echo "<br>Flag=$Flag"; 
			$newValue=setBitValue($newValue,$linksetConfArr[2][1],$Flag);
			if($DEBUG) echo "<br>newValue=$newValue"; 


			//loopFlag
			if($DEBUG) echo "<br>loopFlag=$loopFlag"; 
			$newValue=setBitValue($newValue,$linksetConfArr[3][1],$loopFlag);
			if($DEBUG) echo "<br>newValue=$newValue"; 
			$updSql = "UPDATE $paramTable SET initValue = '$newValue'   
					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);
			//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{
			//显示
			$OPC		=getBitValue($orgValue,$linksetConfArr[0][1]);
			$NetID		=getBitValue($orgValue,$linksetConfArr[1][1]);
			$Flag		=getBitValue($orgValue,$linksetConfArr[2][1]);
			$loopFlag	=getBitValue($orgValue,$linksetConfArr[3][1]);
			echo "\n $tableHeader";
			echo "\n <tr bgcolor=\"#E6E6E6\">";	
			echo "<td>Name</td>";
			echo "<td>Value</td>";
			echo "</tr>";

			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='$level_1' AND level_2='$level_2' AND level_3='$level_3'AND $initValue = '$defaultValue'";
				$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 "\n <tr>";
			echo "<td>Flag</td>";
			echo "<td>";
			echo "<select name=\"Flag\">";
			for($i=0;$i<sizeof($flagConfArr);$i++)
			{
				if($Flag == $i)
					echo "<option value=$i selected>{$flagConfArr[$i]}</option>";
				else
					echo "<option value=$i>{$flagConfArr[$i]}</option>";
			}
			echo "</select>";
			echo "</td></tr>";

			echo "\n <tr>";
			echo "<td>Linkset DPC(hex)</td>";
			echo "<td><input type=\"text\" name=\"OPC\" maxlength=\"6\" value=\"$OPC\" class=\"text\"></td>";
			echo "</tr>";
			
			
			

			echo "\n <tr>";
			echo "<td>Network Indicator</td>";
			echo "<td>";
			echo "<select name=\"NetID\" size=\"1\">";
			for($i=0;$i<sizeof($NetIdConfArr);$i++){
				if($NetID == $NetIdConfArr[$i][0]){
					echo "<option value=\"{$NetIdConfArr[$i][0]}\" selected>{$NetIdConfArr[$i][1]}</option>";
				}else{
					echo "<option value=\"{$NetIdConfArr[$i][0]}\">{$NetIdConfArr[$i][1]}</option>";
				}
			}
			echo "</select>";
			echo "</td>";
			echo "</tr>";

			echo "<tr>";
			echo "<td>Loopback Option</td>";
			echo "<td>";
			echo "<select name=\"loopFlag\" size=\"1\">";
			for($i=0;$i<sizeof($LoopConfArr);$i++){
				if($loopFlag == $LoopConfArr[$i][0]){
					echo "<option value=\"{$LoopConfArr[$i][0]}\" selected>{$LoopConfArr[$i][1]}</option>";
				}else{
					echo "<option value=\"{$LoopConfArr[$i][0]}\">{$LoopConfArr[$i][1]}</option>";
				}
			}
			echo "</select>";
			echo "</td>";
			echo "</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\">";
			break;
		}
}
/*
Opposite point code: The opposite point code of the linkset<br><br>
Network indicator: The network type of the opposite point code<br><br>
Loop back: Loop back enable or disable, used for MSC loop back link
*/
?>
</form>
<b>Remarks:</b><br><br>
DPC: Specify a Destination Point Code to this linkset.<br><br>
Network indicator: The signaling network type of this signaling point.<br><br>
Loop back: Enable or disable loopback function on this linkset. Used only for dual platform MSS loopback.
</body>
</html>
