<?php
/*********************************************************      
 程序说明：         
    功能说明：设置七号信令中的 Local node
              
    调用关系：调用: 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';
$paramTable		='OBJ_223.param_99';
$maxNum = 30;

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

$nGetComm	= 0;
$nSetComm	= 3;

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

if($DEBUG) echo "<br>setObjIdStr = $setObjIdStr";
if($DEBUG) echo "<br>setInstanceNo = $setInstanceNo";

//==========================================================
//数据处理
//==========================================================
$localNodeObjId='2.1';
$localNodeArr=array(
	array('2.1.4',	'OMC'),
	array('2.1.6',	'HLR'), 
   	array('2.1.7',	'VLR'), 
   	array('2.1.8',	'MSC'), 
   	array('2.1.9',	'EIR'), 
   	array('2.1.10',	'AUC'), 
   	array('2.1.11',	'SMSC'),
   	array('2.1.19',	'SMPP-PPS'), 
   	array('2.1.20',	'SMPP-SMSC'), 
   	array('2.1.21',	'SMPP-OMC'), 
   	
   	array('2.1.22', 'SRF0'),
   	array('2.1.23', 'SRF1'),
   	array('2.1.24', 'SRF2'),
   	array('2.1.25', 'SRF3'),
   	
   	array('2.1.32',	'MNP'), 
   	array('2.1.33',	'OPPS'), 
   	array('2.1.146','SSF'), 
   	array('2.1.147','SCF-CAP'),
   	array('2.1.153','SCF-MAP'), 
   	array('2.1.254','AIF')
);

$localNodeConfArr=array(
	array('NetID',		'00.0-00.7'),
	array('MSISDN',		'01.0-10.7'),
	array('IP0',		'11.0-14.7'),
	array('IP1',		'15.0-18.7')
);

$NetIdConfArr=array(
	array('0','international'),
	array('1','international spare'),
	array('2','national'),
	array('3','national spare')
);

if(isset($setSys) || isset($getSys)){
	echo "<br><br><br><br><br>";
	if($DEBUG) echo "<br>sysId=$sysId";
	$objIdStr=$localNodeObjId;
	if($DEBUG) echo "<br>objIdStr=$objIdStr";
	if(isset($setSys)){
		$moveSql = "UPDATE $paramTable SET readValue = initValue   
					WHERE level_1='2' AND level_2='1'
					";
	    if($DEBUG) echo "<BR>moveSql=$moveSql";
	    mysqli_query($pubConn,$moveSql);
	    echo mysqli_error($pubConn);
		$commIdStr	= sysCommSend($sysId,$nSetComm,$objIdStr);
		
		if($DEBUG) echo "<br>nSetComm";
		$showType="Set";
	}else{
		$commIdStr	= sysCommSend($sysId,$nGetComm,$objIdStr);
		$showType="Get";
	}
	$i = 0;
	while(1)
	{
		//echo "<br>i=$i";
		if($i == 0)
			echo "<br>$showType Local node";
		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 = "223_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++;
	}
	$needCopyReadBuf=1;
	$moveSql = "UPDATE $paramTable SET initValue = readValue   
			WHERE level_1='2' AND level_2='1' 
			";
	if($DEBUG) echo "<BR>moveSql=$moveSql";
	mysqli_query($pubConn,$moveSql);
	echo mysqli_error($pubConn);
}elseif(isset($saveSys)){
	$objIdStr=$localNodeObjId;
	$updSql = " UPDATE $paramTable SET initValue = '02' 
		               WHERE  level_1 = '3' AND level_2 = '2'
					   ";
	$updRes = @mysqli_query($pubConn,$updSql);
	echo mysqli_error($pubConn);
	$commIdStr=sysCommSend($sysId,$nSetComm,'3.2');
	$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 = "223_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)){
	$objIdStr=$localNodeObjId;
	$updSql = " UPDATE $paramTable SET initValue = '00' 
		               WHERE  level_1 = '3' AND level_2 = '2'
					   ";
	$updRes = @mysqli_query($pubConn,$updSql);
	echo mysqli_error($pubConn);
	$commIdStr=sysCommSend($sysId,$nSetComm,'3.2');
	$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 = "223_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($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>";
?>

<script LANGUAGE="JavaScript">  
function openSet(objIdStr,instanceNo){
	URL="./gttLocalConf.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();
}    
</script>

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

	$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);
	}
}
?>


<form name="selectform">
<?php

echo "<table id=\"table_up\" border=\"0\" width=\"100%\">";
echo "<tr>";
echo "<td width=\"50%\">";
echo "$strConfiguration > $strNetwork > SS7 > $strLocalNode";
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("gttLSetFlag") ) {
	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 "&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.1\">";

echo "</td>";
echo "<td>&nbsp;</td>";
echo "</table>";

adjust_title_tail();
adjust_content_head();
/*
echo "<br>";
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("gttLSetFlag") ) {
	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\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
echo "<input type=\"hidden\" name=\"objIdStr\" value=\"2.1\">";
echo "<br>";
echo "<br>";
*/


?>
<br>
<table border="1" width="100%" cellpadding="1" cellspacing="0" bordercolor="#666666" bordercolordark="#FFFFFF">
<?php
echo "<tr bgcolor=\"#E6E6E6\">";
echo "<td>Entity</td>";
echo "<td>MSISDN</td>";
echo "<td>Network indicator</td>";
echo "<td>IP0 (Server 0)</td>";
echo "<td>IP1 (Server 1)</td>";
echo "</tr>";
for($i=0;$i<sizeof($localNodeArr);$i++){
	$objIdStr=$localNodeArr[$i][0];
	$serverName	=$localNodeArr[$i][1];
	$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]}";
	}
	$getSql="SELECT $initValue
			FROM $paramTable 
			WHERE level_1='$level_1' AND level_2='$level_2' AND level_3='$level_3' AND instanceNo='$instanceNo'
		";
	if($DEBUG) echo "<BR>getSql=$getSql";
	$result	=mysqli_query($pubConn,$getSql);
	echo mysqli_error($pubConn);
	$rows	=mysqli_fetch_array($result);
	echo mysqli_error($pubConn);
	$value=$rows[0];
	//$value	=getSysParamValue($sysId,$objIdStr,$instanceNo,$valueName);
	$netId	=getBitValue($value,$localNodeConfArr[0][1]);
	for($j=0;$j<sizeof($NetIdConfArr);$j++){
		if($netId == $NetIdConfArr[$j][0]){
			$netIdName= $NetIdConfArr[$j][1];
			break;
		}
	}

	$msisdn	=getBitValue($value,$localNodeConfArr[1][1]);
	$msisdn =str_replace('F','',$msisdn);
	if($msisdn == ''){
		$msisdn='--';
	}
	
	$ip_0	=getBitValue($value,$localNodeConfArr[2][1]);
	if($ip_0 == 'FFFFFFFF')
		$ipStr_0='--';
	else
		$ipStr_0=byte2ip($ip_0);
	$ip_1	=getBitValue($value,$localNodeConfArr[3][1]);
	if($ip_1 == 'FFFFFFFF')
		$ipStr_1='--';
	else
		$ipStr_1=byte2ip($ip_1);
//	$ipStr_1=byte2ip($ip_1);
	if($DEBUG) echo "<BR>value=$value";	
	if($instanceNo == $setInstanceNo && $objIdStr==$setObjIdStr)
		echo "<tr bgcolor=#CCFFCC>";
	else
		echo "<tr>";
	echo "<td><a href=\"javascript:openSet('$objIdStr','$instanceNo')\">";
	echo "$serverName</a></td>";
	echo "<td>$msisdn</td>";
	echo "<td>$netIdName</td>";
	echo "<td>$ipStr_0</td>";
	echo "<td>$ipStr_1</td>";
	echo "</tr>";
}
?>

</table>
</form>
&nbsp;
<?php
adjust_content_tail();
?>
</body>
</html>
