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

    作者：
      
修改注释：      
NO.1      
姓名： Cui Ticun         
时间：2004-4-21
修改说明：Support OMC7.0,从advanced移到configuration中，修改和添
		 加了上方的操作按钮
*********************************************************/
require("../../inc/header.inc");
$helpId = "2.1.0"; 
$DEBUG = 0;
?>
<body leftmargin="15" rightmargin="10" onload="javascript:adjust();" onresize="javascript:adjust();" style="overflow:hidden;overflow-x:hidden;overflow-y:hidden;">

<?php
adjust_head();
adjust_title_head();
if($DEBUG) echo "<br>正在调试中！！";
//==========================================================
//变量定义
//==========================================================
$pubDb		= 'OMC_PUB';
$db			= "OBJ_222";
$paramTable	='OBJ_222.param_99';
$maxNum = 30;

$sysId		='222_99_99';
$instanceNo	='0';
$editValue	='editValue';
$initValue  ='initValue';
$readValue  ='readValue';

$nGetComm	= 0;
$nSetComm	= 3;

$nProcFail = 0;//failure
$nWaitProc = 1;//wait
$nInProc   = 2;
$nOutProc  = 3;

$NetOPLenArr=array(
	//array('oid','offset', 'name'),
	array('2.2','0.0','International network'),
	array('2.2','0.1','International network spare'),
	array('2.2','0.2','National network'),
	array('2.2','0.3','National network spare')
);

$NetOPTypeArr=array(
	//array('oid','offset', 'name'),
	array('International network type','0.4'),
	array('International network spare type','0.5'),
	array('National network type','0.6'),
	array('National network spare type','0.7')
);

$NetOPCArr=array(
   //array('oid', 'name'),
   array('2.3.1', '14bit international network'),
   array('2.3.2', '14bit international network -s'), 
   array('2.3.3', '14bit national network'), 
   array('2.3.4', '14bit national network -s'), 
   array('2.3.5', '24bit international network'), 
   array('2.3.6', '24bit internation network -s'), 
   array('2.3.7', '24bit national network'), 
   array('2.3.8', '24bit national network -s')
);

$RoutingArr=array(
   array('2.6.1', 'International network'), 
   array('2.6.2', 'International network spare'), 
   array('2.6.3', 'National network'), 
   array('2.6.4', 'National network spare')
);

$ACNArr=array( 
   array('2.7.1', 'Local ACN'), 
   array('2.7.2', 'International network'), 
   array('2.7.3', 'International network spare'),
   array('2.7.4', 'National network'), 
   array('2.7.5', 'National network spare') 
);

//==========================================================
//输入变量
//==========================================================
if($DEBUG) echo "<br>setInstanceNo=$setInstanceNo";
if($DEBUG) echo "<BR>setObjIdStr  =$setObjIdStr";
//==========================================================
//数据处理
//==========================================================
//处理get/set命令
if($_SERVER['REQUEST_METHOD'] == "POST"){	
	echo "<br><br><br><br><br>";
	if(isset($setSys)){
		//为set做准备
		$moveSql = "UPDATE $paramTable SET readValue = initValue   
				WHERE level_1='2' AND level_2='2'
				";
		if($DEBUG) echo "<BR>moveSql=$moveSql";
	    mysqli_query($pubConn,$moveSql);
	    echo mysqli_error($pubConn);
		$moveSql = "UPDATE $paramTable SET readValue = initValue   
			WHERE level_1='2' AND level_2='3'
					";
	    if($DEBUG) echo "<BR>moveSql=$moveSql";
	    mysqli_query($pubConn,$moveSql);
	    echo mysqli_error($pubConn);
		$moveSql = "UPDATE $paramTable SET readValue = initValue   
			WHERE level_1='2' AND level_2='6'
					";
	    if($DEBUG) echo "<BR>moveSql=$moveSql";
	    mysqli_query($pubConn,$moveSql);
	    echo mysqli_error($pubConn);
		$moveSql = "UPDATE $paramTable SET readValue = initValue   
				WHERE level_1='2' AND level_2='7'
				";
	    if($DEBUG) echo "<BR>moveSql=$moveSql";
	    mysqli_query($pubConn,$moveSql);

		$commIdStr	= sysCommSend($sysId,$nSetComm,"2.3");
	        
		$i = 0;
		while(1)
		{
			//echo "<br>i=$i";
			if($i == 0)
				echo "<br>Set OPC";
			if($i > $maxNum){
				echo "<br><font size=\"2\" color=\"#FF0000\">Timeout</font>";
				break;
			}
			echo "<img border=\"0\" src=\"../../images/arrow.gif\" width=\"10\" height=\"10\">";
			flush();	
			$sysId = "222_99_99";
			$chkType = "0";
			$chRes=ChComm($sysId,$chkType);
			//echo "<br>chRes=$chRes";
			if($chRes == $nOutProc || $chRes == $nProcFail){
				if($chRes == $nProcFail)
					echo "<br><font size=\"2\" color=\"#FF0000\">$remark</font><br>";
				elseif($remark == 'response timeout')
					echo "<br><font size=\"2\" color=\"#FF0000\">$remark</font><br>";
				else
					echo "<br><font size=\"2\" color=\"#0000FF\">$remark</font><br>";
				break;
			}
	
			sleep(1);
			$i++;
		}


		$commIdStr	= sysCommSend($sysId,$nSetComm,"2.2");
						        
		$i = 0;
		while(1)
		{
			//echo "<br>i=$i";
			if($i == 0)
				echo "<br>Set PC length";
			if($i > $maxNum){
				echo "<br><font size=\"2\" color=\"#FF0000\">Timeout</font>";
				break;
			}
			echo "<img border=\"0\" src=\"../../images/arrow.gif\" width=\"10\" height=\"10\">";
			flush();	
			$sysId = "222_99_99";
			$chkType = "0";
			$chRes=ChComm($sysId,$chkType);
			//echo "<br>chRes=$chRes";
			if($chRes == $nOutProc || $chRes == $nProcFail){
				if($chRes == $nProcFail)
					echo "<br><font size=\"2\" color=\"#FF0000\">$remark</font><br>";
				elseif($remark == 'response timeout')
					echo "<br><font size=\"2\" color=\"#FF0000\">$remark</font><br>";
				else
					echo "<br><font size=\"2\" color=\"#0000FF\">$remark</font><br>";
				break;
			}
	
			sleep(1);
			$i++;
		}

		$commIdStr	= sysCommSend($sysId,$nSetComm,"2.6");
	        
		$i = 0;
		while(1)
		{
			//echo "<br>i=$i";
			if($i == 0)
				echo "<br>Set DPC,Normal linkset,Alternative linkset";
			if($i > $maxNum){
				echo "<br><font size=\"2\" color=\"#FF0000\">Timeout</font>";
				break;
			}
			
			echo "<img border=\"0\" src=\"../../images/arrow.gif\" width=\"10\" height=\"10\">";
			flush();	
			$sysId = "222_99_99";
			$chkType = "0";
			$chRes=ChComm($sysId,$chkType);
			
			//echo "<br>chRes=$chRes";
			if($chRes == $nOutProc || $chRes == $nProcFail){
				if($chRes == $nProcFail)
					echo "<br><font size=\"2\" color=\"#FF0000\">$remark</font><br>";
				elseif($remark == 'response timeout')
					echo "<br><font size=\"2\" color=\"#FF0000\">$remark</font><br>";
				else
					echo "<br><font size=\"2\" color=\"#0000FF\">$remark</font><br>";
				break;
			}
	
			sleep(1);
			$i++;
		}
	
		$commIdStr	= sysCommSend($sysId,$nSetComm,"2.7");
					
		
			
		$i = 0;
		while(1)
		{
			//echo "<br>i=$i";
			if($i == 0)
				echo "<br>Set ACN";
			if($i > $maxNum){
				echo "<br><font size=\"2\" color=\"#FF0000\">Timeout</font>";
				break;
			}
			echo "<img border=\"0\" src=\"../../images/arrow.gif\" width=\"10\" height=\"10\">";
			flush();	
			$sysId = "222_99_99";
			$chkType = "0";
			$chRes=ChComm($sysId,$chkType);
			//echo "<br>chRes=$chRes";
			if($chRes == $nOutProc || $chRes == $nProcFail){
				if($chRes == $nProcFail)
					echo "<br><font size=\"2\" color=\"#FF0000\">$remark</font><br>";
				elseif($remark == 'response timeout')
					echo "<br><font size=\"2\" color=\"#FF0000\">$remark</font><br>";
				else
					echo "<br><font size=\"2\" color=\"#0000FF\">$remark</font><br>";
				break;
			}
	
			sleep(1);
			$i++;
		}
		
				
	}elseif(isset($getSys)){
		$commIdStr	= sysCommSend($sysId,$nGetComm,"2.3");
		
		$i = 0;
		while(1)
		{
			//echo "<br>i=$i";
			if($i == 0)
				echo "<br>Get OPC";
			if($i > $maxNum){
				echo "<br><font size=\"2\" color=\"#FF0000\">Timeout</font>";
				break;
			}
			echo "<img border=\"0\" src=\"../../images/arrow.gif\" width=\"10\" height=\"10\">";
			flush();	
			$sysId = "222_99_99";
			$chkType = "0";
			$chRes=ChComm($sysId,$chkType);
			//echo "<br>chRes=$chRes";
			if($chRes == $nOutProc || $chRes == $nProcFail){
				if($chRes == $nProcFail)
					echo "<br><font size=\"2\" color=\"#FF0000\">$remark</font><br>";
				elseif($remark == 'response timeout')
					echo "<br><font size=\"2\" color=\"#FF0000\">$remark</font><br>";
				else
					echo "<br><font size=\"2\" color=\"#0000FF\">$remark</font><br>";
				break;
			}
	
			sleep(1);
			$i++;
		}
		
		$commIdStr	= sysCommSend($sysId,$nGetComm,"2.2");
		
		$i = 0;
		while(1)
		{
			//echo "<br>i=$i";
			if($i == 0)
				echo "<br>Get PC length";
			if($i > $maxNum){
				echo "<br><font size=\"2\" color=\"#FF0000\">Timeout</font>";
				break;
			}
			echo "<img border=\"0\" src=\"../../images/arrow.gif\" width=\"10\" height=\"10\">";
			flush();	
			$sysId = "222_99_99";
			$chkType = "0";
			$chRes=ChComm($sysId,$chkType);
			//echo "<br>chRes=$chRes";
			if($chRes == $nOutProc || $chRes == $nProcFail){
				if($chRes == $nProcFail)
					echo "<br><font size=\"2\" color=\"#FF0000\">$remark</font><br>";
				elseif($remark == 'response timeout')
					echo "<br><font size=\"2\" color=\"#FF0000\">$remark</font><br>";
				else
					echo "<br><font size=\"2\" color=\"#0000FF\">$remark</font><br>";
				break;
			}
	
			sleep(1);
			$i++;
		}
		
		$commIdStr	= sysCommSend($sysId,$nGetComm,"2.6");
		
		$i = 0;
		while(1)
		{
			//echo "<br>i=$i";
			if($i == 0)
				echo "<br>Get DPC,Normal linkset,Alternative linkset";
			if($i > $maxNum){
				echo "<br><font size=\"2\" color=\"#FF0000\">Timeout</font>";
				break;
			}
			echo "<img border=\"0\" src=\"../../images/arrow.gif\" width=\"10\" height=\"10\">";
			flush();	
			$sysId = "222_99_99";
			$chkType = "0";
			$chRes=ChComm($sysId,$chkType);
			//echo "<br>chRes=$chRes";
			if($chRes == $nOutProc || $chRes == $nProcFail){
				if($chRes == $nProcFail)
					echo "<br><font size=\"2\" color=\"#FF0000\">$remark</font><br>";
				elseif($remark == 'response timeout')
					echo "<br><font size=\"2\" color=\"#FF0000\">$remark</font><br>";
				else
					echo "<br><font size=\"2\" color=\"#0000FF\">$remark</font><br>";
				break;
			}
		
			sleep(1);
			$i++;
		}
		
		$commIdStr	= sysCommSend($sysId,$nGetComm,"2.7");
		$i = 0;
		while(1)
		{
			//echo "<br>i=$i";
			if($i == 0)
				echo "<br>Get ACN";
			if($i > $maxNum){
				echo "<br><font size=\"2\" color=\"#FF0000\">Timeout</font>";
				break;
			}
			echo "<img border=\"0\" src=\"../../images/arrow.gif\" width=\"10\" height=\"10\">";
			flush();	
			$sysId = "222_99_99";
			$chkType = "0";
			$chRes=ChComm($sysId,$chkType);
			//echo "<br>chRes=$chRes";
			if($chRes == $nOutProc || $chRes == $nProcFail){
				if($chRes == $nProcFail)
					echo "<br><font size=\"2\" color=\"#FF0000\">$remark</font><br>";
				elseif($remark == 'response timeout')
					echo "<br><font size=\"2\" color=\"#FF0000\">$remark</font><br>";
				else
					echo "<br><font size=\"2\" color=\"#0000FF\">$remark</font><br>";
				break;
			}
	
			sleep(1);
			$i++;
		}
		
		$moveSql = "UPDATE $paramTable SET initValue = readValue   
				WHERE level_1='2' AND level_2='2'
				";
		if($DEBUG) echo "<BR>moveSql=$moveSql";
		mysqli_query($pubConn,$moveSql);
		echo mysqli_error($pubConn);
		$moveSql = "UPDATE $paramTable SET initValue = readValue   
				WHERE level_1='2' AND level_2='3'
				";
		if($DEBUG) echo "<BR>moveSql=$moveSql";
		mysqli_query($pubConn,$moveSql);
		echo mysqli_error($pubConn);
		$moveSql = "UPDATE $paramTable SET initValue = readValue   
				WHERE level_1='2' AND level_2='6'
				";
		if($DEBUG) echo "<BR>moveSql=$moveSql";
		mysqli_query($pubConn,$moveSql);
		echo mysqli_error($pubConn);
		$moveSql = "UPDATE $paramTable SET initValue = readValue   
				WHERE level_1='2' AND level_2='7'
				";
		if($DEBUG) echo "<BR>moveSql=$moveSql";
		mysqli_query($pubConn,$moveSql);
		echo mysqli_error($pubConn);
	}elseif(isset($saveSys)){
		$updSql = " UPDATE $paramTable SET initValue = '02' 
		               WHERE  level_1 = '3' AND level_2 = '7'
					   ";
		$updRes = @mysqli_query($pubConn,$updSql);
		echo mysqli_error($pubConn);
		$objIdStr = "3.7";
		$commIdStr=sysCommSend($sysId,$nSetComm,$objIdStr);
		$i = 0;
		while(1)
		{
			//echo "<br>i=$i";
			if($i == 0)
				echo "<br>Save parameter to system";
			if($i > $maxNum){
				echo "<br><font size=\"2\" color=\"#FF0000\">Timeout</font>";
				break;
			}
			echo "<img border=\"0\" src=\"../../images/arrow.gif\" width=\"10\" height=\"10\">";
			flush();	
			$sysId = "222_99_99";
			$chkType = "0";
			$chRes=ChComm($sysId,$chkType);
			//echo "<br>chRes=$chRes";
			if($chRes == $nOutProc || $chRes == $nProcFail){
				if($chRes == $nProcFail)
					echo "<br><font size=\"2\" color=\"#FF0000\">$remark</font><br>";
				elseif($remark == 'response timeout')
					echo "<br><font size=\"2\" color=\"#FF0000\">$remark</font><br>";
				else
					echo "<br><font size=\"2\" color=\"#0000FF\">$remark</font><br>";
				break;
			}
	
			sleep(1);
			$i++;
		}		
	}elseif(isset($resetSys)){
		$updSql = " UPDATE $paramTable SET initValue = '01' 
		               WHERE  level_1 = '3' AND level_2 = '7'
					   ";
		$updRes = @mysqli_query($pubConn,$updSql);
		echo mysqli_error($pubConn);
		$objIdStr = "3.7";
		$commIdStr=sysCommSend($sysId,$nSetComm,$objIdStr);
		$i = 0;
		while(1)
		{
			//echo "<br>i=$i";
			if($i == 0)
				echo "<br>Reset system";
			if($i > $maxNum){
				echo "<br><font size=\"2\" color=\"#FF0000\">Timeout</font>";
				break;
			}
			echo "<img border=\"0\" src=\"../../images/arrow.gif\" width=\"10\" height=\"10\">";
			flush();	
			$sysId = "222_99_99";
			$chkType = "0";
			$chRes=ChComm($sysId,$chkType);
			//echo "<br>chRes=$chRes";
			if($chRes == $nOutProc || $chRes == $nProcFail){
				if($chRes == $nProcFail)
					echo "<br><font size=\"2\" color=\"#FF0000\">$remark</font><br>";
				elseif($remark == 'response timeout')
					echo "<br><font size=\"2\" color=\"#FF0000\">$remark</font><br>";
				else
					echo "<br><font size=\"2\" color=\"#0000FF\">$remark</font><br>";
				break;
			}
	
			sleep(1);
			$i++;
		}
	}
}
if(1==$delete){
	$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]}";
			}

	$delSql = "UPDATE $paramTable SET initValue = '000000808000000000' 
	            WHERE level_1='$level_1' AND level_2='$level_2' AND level_3='$level_3' AND instanceNo='$delValue'";
	//echo "<br>delSql=$delSql";
	$delRes = @mysqli_query($pubConn,$delSql);
	echo mysqli_error($pubConn);
}


if($setSys || $getSys || $saveSys || $undoSet||$resetSys){
	echo "<br>";
	echo "<p align=\"left\"><a href=\"$PHP_SELF?setFlag=$setFlag\" target=\"contents\"><img align=absBottom border=0 src=\"../../images/left.gif\" width=\"14\" height=\"14\">$strBack</a>";
	exit();
}

if($DEBUG) echo "<BR>=======NetID==========";
$NetIDArr=array(
	//array('name',					'len value','OPC'),
	array('International Network',		'',	''),
	array('International Network Spare','',	''),
	array('National Network',			'',	''),
	array('National Network Spare',		'',	'')
);

$NetTypeArr=array(
	array('International Network',		'',	''),
	array('International Network Spare','',	''),
	array('National Network',			'',	''),
	array('National Network Spare',		'',	'')
);

$objIdStr	=$NetOPLenArr[0][0];
$NetIDvalue=getSysParamValue($sysId,$objIdStr,$instanceNo,$initValue);
if($DEBUG) echo "<BR>NetIDvalue=$NetIDvalue";
for($i=0;$i<sizeof($NetIDArr);$i++){
	$tmpValue=getBitValue($NetIDvalue,$NetOPLenArr[$i][1]);
	if($tmpValue > '0'){
		$NetIDArr[$i][1]='24bit';
		$objIdStr=$NetOPCArr[$i+4][0];
		$OPCvalue=getSysParamValue($sysId,$objIdStr,$instanceNo,$initValue);
		$NetIDArr[$i][2]=$OPCvalue;
		$m=$i+5;
	}else{
		$NetIDArr[$i][1]='14bit';
		$objIdStr=$NetOPCArr[$i][0];
		$OPCvalue=getSysParamValue($sysId,$objIdStr,$instanceNo,$initValue);
		$NetIDArr[$i][2]=$OPCvalue;
		$m=$i+1;
	}
	$tmpValue=getBitValue($NetIDvalue,$NetOPTypeArr[$i][1]);
	
	if($tmpValue > '0'){
		$NetTypeArr[$i][1]='ANSI';
	}else{
		$NetTypeArr[$i][1]='ITU';
	};
	$opcIdArr[$i]="2."."3.".$m;
	if($DEBUG) echo "<BR>{$NetIDArr[$i][0]}:<t>Len={$NetIDArr[$i][1]} ,<t>OPC={$NetIDArr[$i][2]}";
}

//==========================================================
//输出并显示数据
//==========================================================
if($DEBUG) echo "<BR>";
?>

<script LANGUAGE="JavaScript">  
function openSet(objIdStr,instanceNo){
	URL="./ss7spcRoutineConf.php?instanceNo="+instanceNo+"&objIdStr="+objIdStr;
	var setWindow = open(URL, 'newWin', 'toolbar=no,directories=no,menubar=no,scrollbars=yes,resizable=yes,status=yes,width=400,height=350');
	setWindow.focus();
} 

function delFirm(objIdStr,instanceNo)
{
	var delValue,x,y;
	x = document.body.scrollLeft;
	y = document.body.scrollTop;
    
	if(confirm('Do you want to delete the selected?')!=true){
		window.location.href='<?php echo $PHP_SELF;?>'+"?scroll_x="+x+"&scroll_y="+y;
	}else{
		window.location.href='<?php echo $PHP_SELF;?>?&delete=1&delValue='+instanceNo+"&objIdStr="+objIdStr+"&scroll_x="+x+"&scroll_y="+y;
	}
}
</script>

<?php
function ChComm($sysId,$chkType)
{     
	global $omc_db;
	global $remark,$nProcFail,$nWaitProc,$nInProc,$nOutProc;
	//$DEBUG = 1;

	$commTable = "parameterComm";
	
	$sysIdArr = explode('_',$sysId);
	$sysTypeNo	= $sysIdArr[0];
	$sysNo		= $sysIdArr[1];
	$subSysNo	= $sysIdArr[2];
	
	if($chkType==0)
		$selComm = " SELECT commState,remark FROM $commTable WHERE sysTypeNo = '$sysTypeNo' ";
	else
		$selComm = " SELECT commState,remark FROM $commTable WHERE sysTypeNo = '$sysTypeNo' AND sysNo = '$sysNo' ";
	
	$selRes  = @mysqli_query($pubConn,$selComm);
	$selRow  = @mysqli_fetch_array($selRes);
	echo mysqli_error($pubConn);
	$outProcCount=0;
	do
	{
		$temCommState = $selRow[commState];
		if(isset($selRow[remark])){
			$remark = $selRow[remark];
			if($DEBUG)echo "<br>remark=$remark";
		}
		if($DEBUG)echo "<br>temCommState=$temCommState";
		if($temCommState == $nWaitProc){
			return($nWaitProc);
		}elseif($temCommState == $nInProc){
			return($nInProc);
		}elseif($temCommState == $nOutProc){
			$commState = $nOutProc;
			$outProcCount++;
		}else{
			$commState = $nProcFail;
		}
	}while($selRow  = @mysqli_fetch_array($selRes));
	if($outProcCount > 0){
		return($nOutProc);
	}else{
		return($nProcFail);
	}
}
?>

<body leftmargin="15" rightmargin="10" onload="javascript:adjust();" onresize="javascript:adjust();" style="overflow:hidden;overflow-x:hidden;overflow-y:hidden;">


<?php
echo "<form method=\"POST\" name=\"setForm\" action=\"$PHP_SELF\">";
echo "<table id=\"table_up\" border=\"0\" width=\"100%\">";
echo "<tr>";
echo "<td width=\"50%\">";
echo "$strConfiguration > $strNetwork > SS7 > SPC Routing";
echo "</td>";
echo "<td width=\"50%\" align=\"right\" title=\"Help\">";
showHelp($helpId);
echo "</td>";
echo "</tr>";
echo "<tr>";
echo "<td align=\"left\">";

echo "<b>System:</b>&nbsp;&nbsp;";
echo "<input type=\"submit\" name=\"getSys\" value=\"$strGet\" class=\"button\">";
echo "<input type=\"submit\" name=\"setSys\" value=\"$strSet\" class=\"button\">";
/*
if ( TRUE == session_is_registered("routineSetFlag") ) {
	echo "<input type=\"submit\" name=\"undoSet\" value=\"$strUndo\" class=\"button\"  style=\"left: 1; top: 2; width: 60; height: 25; position: relative\">&nbsp;&nbsp;&nbsp;&nbsp;";
}else{
	echo "<input type=\"submit\" name=\"undoSet\" value=\"$strUndo\" DISABLED class=\"button\"  style=\"left: 1; top: 2; width: 60; height: 25; position: relative\">&nbsp;&nbsp;&nbsp;&nbsp;";
}
*/
echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
echo "<b>Command:</b>&nbsp;&nbsp;";
echo "<input type=\"submit\" name=\"saveSys\" value=\"$strSave\" class=\"button\">";
echo "<input type=\"submit\" name=\"resetSys\" value=\"$strReset\" class=\"button\">";
echo "<input type=\"hidden\" name=\"objIdStr\" value=\"2\">";
echo "</form>";

echo "</td>";
echo "<td>&nbsp;</td>";
echo "</tr>";
echo "</table>";
adjust_title_tail();
adjust_content_head();
/*
echo "<b>System:</b>&nbsp;&nbsp;";
echo "<input type=\"submit\" name=\"getSys\" value=\"$strGet\" class=\"button\" style=\"left: 1; top: 2; width: 60; height: 25; position: relative\">";
echo "<input type=\"submit\" name=\"setSys\" value=\"$strSet\" class=\"button\" style=\"left: 1; top: 2; width: 60; height: 25; position: relative\">";
echo "<input type=\"submit\" name=\"saveSys\" value=\"$strSave\" class=\"button\" style=\"left: 1; top: 2; width: 60; height: 25; position: relative\">";
if ( TRUE == session_is_registered("routineSetFlag") ) {
	echo "<input type=\"submit\" name=\"undoSet\" value=\"$strUndo\" class=\"button\"  style=\"left: 1; top: 2; width: 60; height: 25; position: relative\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
}else{
	echo "<input type=\"submit\" name=\"undoSet\" value=\"$strUndo\" DISABLED class=\"button\"  style=\"left: 1; top: 2; width: 60; height: 25; position: relative\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
}
echo "<b>OMC:</b>&nbsp;&nbsp;";
echo "<input type=\"submit\" name=\"getOmc\" value=\"$strGet\" class=\"button\" style=\"left: 1; top: 2; width: 60; height: 25; position: relative\">";
echo "<input type=\"submit\" name=\"saveOmc\" value=\"$strSave\" class=\"button\" style=\"left: 1; top: 2; width: 60; height: 25; position: relative\">";
echo "<input type=\"hidden\" name=\"objIdStr\" value=\"2\">";
echo "</form>";
*/


echo "<br>";
$tableHead="<table border=\"1\" width=\"100%\" cellpadding=\"1\" cellspacing=\"0\" bordercolor=\"#666666\" bordercolordark=\"#FFFFFF\">";
for($i=0;$i<sizeof($NetIDArr);$i++){
	//echo "opcIdArr[$i]=$opcIdArr[$i]";
	echo "$tableHead";
	$RTobjIdStr	=$RoutingArr[$i][0];
	$ACNobjIdStr=$ACNArr[$i+1][0];
	$opcIdStr   =$opcIdArr[$i];
	echo "<tr bgcolor=\"#E6E6E6\">";
	echo "<td colspan=\"7\"><b>{$NetIDArr[$i][0]}</b></td>";
	echo "</tr>";
	
	$NetworkId="2.2.".$i;
	echo "<tr bgcolor=\"#E6E6E6\">";
	echo "<td colspan=\"7\"><a href=\"javascript:openSet('$NetworkId','0')\">PC length:{$NetIDArr[$i][1]}&nbsp;|&nbsp;PC type:{$NetTypeArr[$i][1]}</a></td>";
	echo "</tr>";
	echo "<tr bgcolor=\"#E6E6E6\">";
	echo "<td colspan=\"5\"><a href=\"javascript:openSet('$opcIdStr','$instanceNo')\">OPC (hex):{$NetIDArr[$i][2]}</a></td>";
	echo "<td colspan=\"2\"><a href=\"javascript:openSet('{$ACNArr[0][0]}','0')\">";
	echo "ACN</a></td>";
	echo "</tr>";

	echo "<tr>";
	echo "<td width=\"5%\">No.</td>";
	echo "<td width=\"20%\">DPC (hex)</td>";
	echo "<td width=\"20%\">Normal linkset (dec)</td>";
	echo "<td width=\"22%\">Alternative linkset (dec)</td>";
	echo "<td>M3UA Routing Context (dec)</td>";
	echo "<td width=\"5%\">ACN</td>";
	echo "<td width=\"5%\">Delete</td>";
	echo "</tr>";

	$levelArr=explode('.',$RoutingArr[$i][0]);
	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>";

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

	while($rows	=mysqli_fetch_array($result)){
		if($DEBUG)	
		echo "$rows[0], <1>";
		if(strcasecmp($rows[0],$defaultValue)==0){
			continue;
		}
		$DPC=substr($rows[0],0,6);
		$NormalLinkset=substr($rows[0],6,2);
		$NormalLinkset=hexdec($NormalLinkset);
		$M3UA_routing_context=hexdec(substr($rows[0],10,8));
		if($NormalLinkset>127)
			$NormalLinkset="--";
		
		$AlternativeLinkset=substr($rows[0],8,2);
		$AlternativeLinkset=hexdec($AlternativeLinkset);
		if($AlternativeLinkset > 127){
			$AlternativeLinkset="--";
		}

		$instanceNo=$rows[instanceNo];
		if(($RTobjIdStr == $setObjIdStr || $ACNobjIdStr== $setObjIdStr) && $instanceNo == $setInstanceNo){
			echo "<tr bgcolor=\"#CCFFCC\">";
		}else{
			echo "<tr>";
		}
		
		echo "<td><a href=\"javascript:openSet('$RTobjIdStr','$instanceNo')\">";
		echo "$instanceNo</a></td>";
		echo "<td>$DPC</td>";
		echo "<td>$NormalLinkset</td>";
		echo "<td>$AlternativeLinkset</td>";
		echo "<td>$M3UA_routing_context</td>";
		echo "<td><a href=\"javascript:openSet('$ACNobjIdStr','$instanceNo')\">";
		echo "ACN</a></td>";
		echo "<td><input type=\"checkbox\" name=\"C$instanceNo\" value=\"ON\" onClick=\"javascript:delFirm('$RTobjIdStr','$instanceNo')\" ></td>";
		echo "</tr>";
	}
	echo "<tr>";
	echo "<td><a href=\"javascript:openSet('$RTobjIdStr','new')\">";
	echo "New</a></td>";
	echo "<td>--</td>";
	echo "<td>--</td>";
	echo "<td>--</td>";
	echo "<td>--</td>";
	echo "<td>--</td>";
	echo "<td>--</td>";
	echo "</tr>";
	echo "</table><br>";
}
?>
</form>
<br><b>Remarks:</b><br>This SPC routing page provides a straightforward interface to set the MTP3 signaling addressing (point code) and ACN (application context name) control. The MSC supports four networks (international, international spare, national and national spare) and both 14-bit and 24-bit signaling point codes. To add or modify a point code, firstly select the type of the network, and then click on the correspondent number of the point code to open the point code set window.
<?php
adjust_content_tail();
?>
</body>
</html>
