<?php
/*********************************************************      
 程序说明：         
    功能说明：设置七号信令中的 Linkset
              
    调用关系：调用: 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;

$nGetComm	= 0;
$nSetComm	= 3;

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

$nProcFail = 0;//failure
$nWaitProc = 1;//wait
$nInProc   = 2;
$nOutProc  = 3;
//==========================================================
//输入变量
//==========================================================
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) || isset($getSys)){
		if(isset($setSys)){		
			$moveSql = "UPDATE $paramTable SET readValue = initValue   
					WHERE level_1='2' AND level_2='4' AND level_3='1'
					";
	        if($DEBUG) echo "<BR>moveSql=$moveSql";
	        mysqli_query($pubConn,$moveSql);
	        echo mysqli_error($pubConn);
			$commIdStr	= sysCommSend($sysId,$nSetComm,$objIdStr);
			
			$showType="Set";
		}else{	
			$commIdStr	= sysCommSend($sysId,$nGetComm,$objIdStr);
			$showType="Get";
		}


		$i = 0;
		while(1)
		{
			//echo "<br>i=$i";
			if($i == 0)
				echo "<br>$showType 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++;
		}

		//Get linkset status
		$commIdStr	= sysCommSend($sysId,$nGetComm,"3.2");
		$i = 0;
		while(1)
		{
			//echo "<br>i=$i";
			if($i == 0)
				echo "<br>Get Linkset status";
			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='4' AND level_3='1'
				";
		if($DEBUG) echo "<BR>moveSql=$moveSql";
		mysqli_query($pubConn,$moveSql);
		echo mysqli_error($pubConn);
    	
		$moveSql = "UPDATE $paramTable SET initValue = readValue   
				WHERE level_1='3' AND level_2='2'
				";
		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);
		$commIdStr=sysCommSend($sysId,$nSetComm,'3.7');
		$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);
		$commIdStr=sysCommSend($sysId,$nSetComm,'3.7');
		$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)
{
	$delSql = "UPDATE $paramTable SET initValue = '0000000000000000000000000000000000000000' 
	            WHERE level_1='2' AND level_2='4' AND level_3='1' 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();
}

$linksetOid	='2.4.1';
$objIdStr	='2.4.1';
$linksetConfArr=array(
	array('Flag','3.2-3.2'),
	array('Linkset DPC','0.0-2.7'),
	array('Network indicator','3.0-3.1'),
	array('Loopback Option','3.3-3.3')
	);
$NetIdConfArr=array(
	array('00','International'),
	array('01','International spare'),
	array('10','National'),
	array('11','National spare')
);
$flagConfArr=array(0=>"Disable",1=>"Enable");

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

<script LANGUAGE="JavaScript">  
function openSet(objIdStr,instanceNo){
	URL="./ss7LinksetConf.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(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+"&scroll_x="+x+"&scroll_y="+y;
	}
}
</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);
	}
}
?>

<?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 > $strLinkset";
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("linksetSetFlag") ) {
	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.4.1\">";
echo "</form>";

echo "</td>";
echo "<td>&nbsp;</td>";
echo "</tr>";
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("linksetSetFlag") ) {
	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.4.1\">";
echo "</form>";
*/

?>
<br>
<table border="1" width="100%" cellpadding="1" cellspacing="0" bordercolor="#666666" bordercolordark="#FFFFFF">
<?php 
echo "<tr bgcolor=\"#E6E6E6\">";
echo "<td>No.</td>";
echo "<td>Flag</td>";
echo "<td>Linkset DPC</td>";
echo "<td>Network Indicator</td>";
echo "<td>Loopback Option</td>";
echo "<td>Status</td>";
echo "<td>Delete</td>";
echo "</tr>";


$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>";

$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)){
	$instanceNo=$rows[instanceNo];
	$value=$rows[0];
	if(strcasecmp($rows[initValue],$defaultValue)==0){
		continue;
	}
	
	$flag		=getBitValue($value,$linksetConfArr[0][1]);
	$OPC		=getBitValue($value,$linksetConfArr[1][1]);
	$NetID		=getBitValue($value,$linksetConfArr[2][1]);
	$loopFlag	=getBitValue($value,$linksetConfArr[3][1]);
	if($objIdStr == $setObjIdStr && $instanceNo == $setInstanceNo){
		echo "<tr bgcolor=\"#CCFFCC\">";
	}else{
		echo "<tr>";
	}
	echo "<td><a href=\"javascript:openSet('$objIdStr','$instanceNo')\">";
	echo "$instanceNo</a></td>";
	
	echo "<td>{$flagConfArr[$flag]}</td>";
	
	echo "<td>$OPC</td>";

	echo "<td>";
	if($DEBUG) echo "NetID=$NetID<BR>";
	for($i=0;$i<sizeof($NetIdConfArr);$i++){
		if($NetID == $NetIdConfArr[$i][0]){
			echo "{$NetIdConfArr[$i][1]}";
			break;
		}
	}
	echo "</td><td>";
	if($DEBUG) echo "loopFlag=$loopFlag<BR>";
	if($loopFlag > 0){
		echo "Enable";
	}else{
		echo "Disable";
	}
	{//get linkset Status
		$objStr = '3.2';
		$levelWhere = getLevelWhere($objStr);
		$selSql = "select initValue from $paramTable where $levelWhere and instanceNo='$rows[instanceNo]'";
		$staResult = @mysqli_query($pubConn,$selSql);
		$staRows = @mysqli_fetch_array($staResult);
		$status = hexdec($staRows[initValue]);
	}
	$lsStateArr = array(0=>'Unavailable',1=>'Available',2=>'Reserved');
	echo "</td>";
	echo "<td>";
		echo "{$lsStateArr[$status]}";
	echo "</td>";
	echo "<td><input type=\"checkbox\" name=\"C$instanceNo\" value=\"ON\" onClick=\"javascript:delFirm($instanceNo)\" ></td>";
	echo "</tr>";
}

//New
echo "<tr>";
echo "<td><a href=\"javascript:openSet('$objIdStr','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>";

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