<?php
require("../sub_inc/commfunc.php");
$helpId = "2.1.1.1"; 
$DEBUG = 0;

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

$sysId		='222_99_99';
$instanceNo	='0';
$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')
);//roger

$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($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',		'',	'')
);
//roger....................................
$NetTypeArr=array(
	array('International Network',		'',	''),
	array('International Network Spare','',	''),
	array('National Network',			'',	''),
	array('National Network Spare',		'',	'')
);
//roger....................................
$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]);
	$tmpValue_type=getBitValue($NetIDvalue,$NetOPTypeArr[$i][1]);//roger
	if($tmpValue > '0'){
		$NetIDArr[$i][1]='24bit';
		$objIdStr=$NetOPCArr[$i+4][0];
		$OPCvalue=getSysParamValue($sysId,$objIdStr,$instanceNo,$initValue);
		$OPCvalue = hexdec($OPCvalue);//roger
		$NetIDArr[$i][2]=$OPCvalue;
		$m=$i+5;
	}else{
		$NetIDArr[$i][1]='14bit';
		$objIdStr=$NetOPCArr[$i][0];
		$OPCvalue=getSysParamValue($sysId,$objIdStr,$instanceNo,$initValue);
		$OPCvalue = hexdec($OPCvalue);//roger
		$NetIDArr[$i][2]=$OPCvalue;
		$m=$i+1;
	};
	if($tmpValue_type > '0'){
		$NettypeArr[$i][1]='ANSI';
	}else{
		$NettypeArr[$i][1]='ITU';
	};//roger
	$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>";
?>

<body topmargin="0" leftmargin="12">

<?php
echo "<form method=\"POST\" name=\"setForm\" action=\"$PHP_SELF\">";
echo "<table border=\"0\" width=\"100%\">";
echo "<tr>";
echo "<td width=\"50%\">";
echo "Configuration > <a href=\"../overview/overview.php?scroll_y=1000\">Network</a> > <a href=\"#\">SPC overview</a>";
echo "</td>";
echo "<td width=\"50%\" align=\"right\" title=\"Help\">";
//showHelp($helpId);
echo "</td>";
echo "<td>";
echo "<p align=\"right\"><a href=\"../../element/overview/overview.php?scroll_y=1000\"><img align=absBottom border=0 src=\"../../images/left.gif\" width=\"14\" height=\"14\">$strBack</a>";
echo "</td></tr>";

echo "</table>";
echo "<br>";

echo "<table width=\"100%\">";
echo "<tr><td>";

//echo "<input type=\"submit\" name=\"getSys\" value=\"$strGet\" class=\"button\" style=\"left: 1; top: 2; width: 60; height: 25; position: relative\">";

echo "<input type=\"hidden\" name=\"objIdStr\" value=\"2\">";
echo "</table>";
echo "</form>";

//echo "<b>SPC overview:</b><br>";

$tableHead="<table rules=rows 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=\"4\"><b>{$NetIDArr[$i][0]}</b></td>";
	echo "</tr>";
	
	$NetworkId="2.2.".$i;
	echo "<tr bgcolor=\"#E6E6E6\">";
	echo "<td colspan=\"4\">PC length:{$NetIDArr[$i][1]}&nbsp;|&nbsp;PC type:{$NettypeArr[$i][1]}</td>";//roger
	echo "</tr>";
	echo "<tr bgcolor=\"#E6E6E6\">";
	echo "<td colspan=\"4\">OPC:{$NetIDArr[$i][2]}</td>";
	echo "</tr>";

	echo "<tr>";
	echo "<td width=\"5%\">No.</td>";
	echo "<td width=\"25%\">DPC</td>";
	echo "<td width=\"30%\">Normal linkset</td>";
	echo "<td width=\"30%\">Alternative linkset</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($rows[0] == $defaultValue){
			continue;
		}
		$DPC=substr($rows[0],0,6);
		$DPC = hexdec($DPC);

		$NormalLinkset=substr($rows[0],6,2);
		$NormalLinkset=hexdec($NormalLinkset);

		if($NormalLinkset>127){
			$NormalLinkset="--";
			$NormalLinksetTitle='--';
		}else{
			$tmpSql="SELECT $initValue FROM $paramTable 
						WHERE level_1='2' AND level_2='4' AND level_3='1' AND instanceNo='$NormalLinkset'
					";
			if($DEBUG) echo "<BR>tmpSql=$tmpSql";
			$tmpResult	=mysqli_query($pubConn,$tmpSql);
			echo mysqli_error($pubConn);

			$tmpRows	=mysqli_fetch_array($tmpResult);

			$NormalLinksetTitle	=toAscii(getBitValue($tmpRows[0],"7.0-16.7"));
		}

		
		$AlternativeLinkset=substr($rows[0],8,2);
		$AlternativeLinkset=hexdec($AlternativeLinkset);
		
		if($AlternativeLinkset > 127){
			$AlternativeLinkset="--";
			$AlternativeLinksetTitle="--";
		}else{
			$tmpSql="SELECT $initValue FROM $paramTable 
						WHERE level_1='2' AND level_2='4' AND level_3='1' AND instanceNo='$AlternativeLinkset'
					";
			if($DEBUG) echo "<BR>tmpSql=$tmpSql";
			$tmpResult	=mysqli_query($pubConn,$tmpSql);
			echo mysqli_error($pubConn);

			$tmpRows	=mysqli_fetch_array($tmpResult);

			$AlternativeLinksetTitle	=toAscii(getBitValue($tmpRows[0],"7.0-16.7"));
		}

		$instanceNo=$rows[instanceNo];
		if(($RTobjIdStr == $setObjIdStr || $ACNobjIdStr== $setObjIdStr) && $instanceNo == $setInstanceNo){
			echo "<tr bgcolor=\"#CCFFCC\">";
		}else{
			echo "<tr>";
		}
		
		echo "<td>$instanceNo</td>";
		echo "<td>$DPC</td>";
		echo "<td>No.$NormalLinkset($NormalLinksetTitle)</td>";
		echo "<td>No.$AlternativeLinkset($AlternativeLinksetTitle)</td>";
		echo "</tr>";
	}
	echo "</table><br>";
}


?>
</form>
</body>
</html>
