<?php
require("../sub_inc/commfunc.php");
$helpId = "2.1.2.1"; 
$DEBUG = 0;
$sysInfoTable = 'OMC_PUB.sysInfo';
?>
<script LANGUAGE="JavaScript">           
function openSet(sNum,pNum){
	var x,y;
	x = document.body.scrollLeft;
	y = document.body.scrollTop;

	URL="./e1Edit.php?sNum="+sNum+"&pNum="+pNum+"&scroll_x="+x+"&scroll_y="+y;
	var msgWindow = open(URL, 'newWin', 'toolbar=no,directories=no,menubar=no,scrollbars=yes,resizable=yes,status=yes,width=400,height=420');
	msgWindow.focus();
}
</script>
<?php
function getTitleByTg($tg)
{
	$pubDb = "OMC_PUB";
	if($tg==253 || $tg==254){
		$title = 'LoopBack'.$tg;
		return $title;
	}
	$selSql = "SELECT initValue FROM OBJ_322.param_99 WHERE subSysNo = '99' and level_1='2' AND level_2='1' AND level_3='4' and instanceNo='$tg'";
	$result = mysqli_query($pubConn,$selSql);
	$Rows = mysqli_fetch_array($result);
	$dpc = hexdec(substr($Rows[initValue],2,6));
	$hexDpc = strtoupper(omc_keep_length(dechex($dpc),0,6));
	
	$tmpSql="SELECT initValue,instanceNo FROM OBJ_222.param_99 
					WHERE level_1='2' AND level_2='4' AND level_3='1' AND initValue LIKE '$hexDpc%'
				";
	if($DEBUG)echo "<BR>tmpSql=$tmpSql";
	$tmpResult	=mysqli_query($pubConn,$tmpSql);
	echo mysqli_error($pubConn);
	if(mysqli_num_rows($tmpResult)>0)
	{
		$tmpRows	=mysqli_fetch_array($tmpResult);
		$title = toAscii(getBitValue($tmpRows[0],"7.0-16.7"));
	}
	else
		$title = "--";
	
	return $title;
}//end getTitleByTg

$sysTypeNo_0 = "111";
if($thisOmcType==10){
	$sysTypeNo_1 = "251";
}else{
	$sysTypeNo_1 = "322";
}

$db_0 = "OBJ_".$sysTypeNo_0;
$db_1 = "OBJ_".$sysTypeNo_1;

$tb_0 = "param_0";
$tb_1 = "param_1";
$tb_2 = "param_99";

$maxNum = 30;

$nPubFlag = 99;
$nSubSysParam		= 0;
$nGlobalSubSysParam = 1;
$nGlobalSysParam	= 2;

$nGetComm = 0;
$nSetComm = 3;

$nInteger = 2;
$nOctStr = 4;

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

//E1 flag
$oidFlag = "2.1"; 
$pE1 = explode(".",$oidFlag);
$i = 0;
$wFlag = '';
while(isset($pE1[$i]))
{
	$lNum = $i+1;
	if($DEBUG) echo "<br>pE1[$i]=$pE1[$i]";
	$wFlag = $wFlag." AND level_$lNum = $pE1[$i] ";
	$i++;
}


//2.6 CRC4 flag
$oidCrc = "2.6"; 
$pE1 = explode(".",$oidCrc);
$i = 0;
$wCrc = '';
while(isset($pE1[$i])) {
	$lNum = $i+1;
	if($DEBUG)echo "<br>pE1[$i]=$pE1[$i]";
	$wCrc = $wCrc." AND level_$lNum = $pE1[$i] ";
	$i++;
}

//2.2 E1 MTP2 alarm flag
$oidDlink = "2.2"; 
$pE1 = explode(".",$oidDlink);
$i = 0;
$wDlink = '';
while(isset($pE1[$i]))
{
	$lNum = $i+1;
	if($DEBUG)echo "<br>pE1[$i]=$pE1[$i]";
	$wDlink = $wDlink." AND level_$lNum = $pE1[$i] ";
	$i++;
}

//2.4.1 2.4.2 2.4.3 MSC
$uwMsc = " WHERE subSysNo = '99' AND level_1 = '2' AND level_2 = '4'  AND (level_3 = '1' OR level_3 = '2' OR level_3 = '3') ";


$wMsc = " WHERE subSysNo = '99' AND level_1 = '2' AND level_2 = '4'  AND (level_3 = '1' OR level_3 = '2' OR level_3 = '3') ORDER BY level_3 ";

$wMsc_1 = " WHERE subSysNo = '99' AND level_1 = '2' AND level_2 = '4'  AND level_3 = '1' AND instanceNo  = '$pNum' ";

$wMsc_2 = " WHERE subSysNo = '99' AND level_1 = '2' AND level_2 = '4'  AND level_3 = '2' AND instanceNo  = '$pNum' ";

$wMsc_3 = " WHERE subSysNo = '99' AND level_1 = '2' AND level_2 = '4'  AND level_3 = '3' AND instanceNo  = '$pNum' ";

$eFlagArr=array(
		array('num' => '0',  'remark' => 'N', 'color' => '#FF0000'),
		array('num' => '1',  'remark' => 'Y', 'color' => '#0000FF'),
		array('num' => '2',  'remark' => 'T', 'color' => '#0000FF')

);

$eCrcArr=array(
		array('num' => '0',  'remark' => 'Off', 'color' => '#FF0000'),
		array('num' => '1',  'remark' => 'On', 'color' => '#0000FF')
);

$eDlinkArr=array(
		array('num' => '0',  'remark' => 'N', 'color' => '#FF0000'),
		array('num' => '1',  'remark' => 'Y', 'color' => '#0000FF')
);

$mPtArr=array(
		array('num' => '0',  'remark' => 'TUP', 'color' => '#FF0000'),
		array('num' => '1',  'remark' => 'ISUP', 'color' => '#0000FF'),
		array('num' => '2',  'remark' => 'AIF', 'color' => '#0000FF'),
		array('num' => '3',  'remark' => 'ISDN NT', 'color' => '#0000FF'),
		array('num' => '4',  'remark' => 'ISDN LT', 'color' => '#0000FF'),
		array('num' => '5',  'remark' => 'CIC CNF', 'color' => '#0000FF'),
		array('num' => '6',  'remark' => 'CIC INT', 'color' => '#0000FF')
);



/**************select used E1 card*******************/
$getSql = " SELECT sysNo,subSysNo,baseStat,updateTime
			FROM $sysInfoTable
			WHERE sysTypeNo='$sysTypeNo_0' AND updateTime > '0'
			ORDER BY sysNo,subSysNo
		  ";
//echo "<br>getSql=$getSql";
$getRes = @mysqli_query($pubConn,$getSql);
$getRow = @mysqli_fetch_array($getRes);
echo mysqli_error($pubConn);
do
{
	$sysNo = $getRow[sysNo];
	$subSysNo = $getRow[subSysNo];
	$isUpdate[$sysNo][$subSysNo] = $getRow[updateTime] > 0 ? 1:0;
}while($getRow = @mysqli_fetch_array($getRes));

$isUpdate[0][0]="1";


/************select value to see************/
//E1 flag
for($i=0;$i<2;$i++)
{
	$temTb = ${tb_.$i};
	$flagSql = " SELECT instanceNo,initValue,readValue FROM $temTb WHERE subSysNo >= 0 ".$wFlag." ORDER BY instanceNo "; 
	if($DEBUG) echo "<br>flagSql=$flagSql";
	$flagRes = @mysqli_query($pubConn,$flagSql);
	$flagRow = @mysqli_fetch_array($flagRes);
	echo mysqli_error($pubConn);
	do
	{
		$instanceNo = $flagRow[instanceNo];
		$initValue = HexDec($flagRow[initValue]);
		$initValue = DecBin($initValue);
		$initValue = omc_keep_length($initValue,0,8);
		if($DEBUG) echo "<br>initValue=$initValue";
		for($j=0;$j<8;$j++)
		{
			$fNum = $instanceNo*8+7-$j;
			$flagArr[$i][$fNum] = substr($initValue,$j,1);
			if($DEBUG) echo "<br>flagArr[$i][$fNum]={$flagArr[$i][$fNum]}";
		}
	}while($flagRow = @mysqli_fetch_array($flagRes));
}

//2.6 CRC4 flag
for($i=0;$i<2;$i++)
{
	$temTb = ${tb_.$i};
	$crcSql = " SELECT instanceNo,initValue,readValue FROM $temTb WHERE subSysNo >= 0 ".$wCrc." ORDER BY instanceNo "; 
	if($DEBUG)echo "<br>crcSql=$crcSql";
	$crcRes = @mysqli_query($pubConn,$crcSql);
	$crcRow = @mysqli_fetch_array($crcRes);
	if($DEBUG)echo mysqli_error($pubConn);
	do
	{
		$instanceNo = $crcRow[instanceNo];
		$initValue = HexDec($crcRow[initValue]);
		$initValue = DecBin($initValue);
		$initValue = omc_keep_length($initValue,0,8);
		if($DEBUG)echo "<br>initValue=$initValue";
		for($j=0;$j<8;$j++)
		{
			$fNum = $instanceNo*8+7-$j;
			$crcArr[$i][$fNum] = substr($initValue,$j,1);
			if($DEBUG)echo "<br>crcArr[$i][$fNum]={$crcArr[$i][$fNum]}";
		}
	}while($crcRow = @mysqli_fetch_array($crcRes));
}

//2.2 E1 MTP2 alarm flag
for($i=0;$i<2;$i++)
{
	$temTb = ${tb_.$i};
	$dlinkSql = " SELECT instanceNo,initValue,readValue FROM $temTb WHERE subSysNo >= 0 ".$wDlink." ORDER BY instanceNo "; 
	if($DEBUG)echo "<br>dlinkSql=$dlinkSql";
	$dlinkRes = @mysqli_query($pubConn,$dlinkSql);
	$dlinkRow = @mysqli_fetch_array($dlinkRes);
	echo mysqli_error($pubConn);
	do{
		$instanceNo = $dlinkRow[instanceNo];
		$initValue = HexDec($dlinkRow[initValue]);
		$initValue = DecBin($initValue);
		$initValue = omc_keep_length($initValue,0,8);
		if($DEBUG)echo "<br>initValue=$initValue";
		for($j=0;$j<8;$j++)
		{
			$fNum = $instanceNo*8+7-$j;
			$dlinkArr[$i][$fNum] = substr($initValue,$j,1);
			if($DEBUG)echo "<br>dlinkArr[$i][$fNum]={$dlinkArr[$i][$fNum]}";
		}
	}while($dlinkRow = @mysqli_fetch_array($dlinkRes));
}


//2.4.1 2.4.2 2.4.3 MSC
$mscSql = " SELECT level_3,instanceNo,initValue,readValue FROM $tb_2 ".$wMsc; 
if($DEBUG) 
	echo "<br>mscSql=$mscSql<br>db_1=$db_1";
$mscRes = @mysqli_query($pubConn,$mscSql);
$mscRow = @mysqli_fetch_array($mscRes);
echo mysqli_error($pubConn);

do {
	$level_3 = $mscRow[level_3];
	$instanceNo = $mscRow[instanceNo];
	$initValue = HexDec($mscRow[initValue]);
	$mscArr[$level_3][$instanceNo] = $initValue;
	if($DEBUG) echo "<br>mscArr[$level_3][$instanceNo]={$mscArr[$level_3][$instanceNo]}";	
}while($mscRow = @mysqli_fetch_array($mscRes));


if($comSys || $comDisk) {
	for($i=0;$i<128;$i++) {
		if($flagArr[0][$i] != $flagArr[1][$i])
			$flagCol[$i]="#FF0000";
				
		if($mscArr[3][$i] != $mscArr[3][$i+128])
			$mscCol[3][$i]="#FF0000";
		
		if($mscArr[2][$i] != $mscArr[2][$i+128])
			$mscCol[2][$i]="#FF0000";
		
		if($mscArr[1][$i] != $mscArr[1][$i+128])
			$mscCol[1][$i]="#FF0000";

		if($crcArr[0][$i] != $crcArr[1][$i])
			$crcCol[$i]="#FF0000";
		
		if($dlinkArr[0][$i] != $dlinkArr[1][$i])
			$dlinkCol[$i]="#FF0000";
	}
}//end of $comDisk
$scroll_x = isset($scroll_x)?$scroll_x:'0';
$scroll_y = isset($scroll_y)?$scroll_y:'0';
echo "<body onLoad='self.scrollBy($scroll_x,$scroll_y)'>";
echo "<form method=\"POST\" name=\"confForm\" 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=\"#\">E1 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>";
?>

<TABLE rules=rows border="1" width="100%" cellpadding="2" cellspacing="0" bordercolor="#666666" bordercolordark="#FFFFFF" bgcolor="#FFFFFF">     
<tr bgcolor="#E6E6E6">
<td>&nbsp;</td>     
<td width=50% colspan="8" align="center" style="border-right:1px solid">MSC-0</td>     
<td width=50% colspan="8" align="center">MSC-1</td>   
<!-- <td>&nbsp;</td> -->     
</tr>
<tr bgcolor="#E6E6E6">
<td>Slot</td>     
<td>Title</td>     
<td>Port</td>     
<td>Flag</td>     
<td>CIC</td> 
<td>TG</td>     
<td>Protocol</td>     
<td>CRC4</td>
<td style="border-right:1px solid"><nobr>Alarm</nobr></td>
<td>Title</td> 
<td>Port</td>     
<td>Flag</td>     
<td>CIC</td> 
<td>TG</td>     
<td>Protocol</td>     
<td>CRC4</td>
<td><nobr>Alarm</nobr></td>
</tr>
<?php
for($i=0;$i<128;$i++)
{
	$sNum = floor($i/8);
	$pNum = floor($i%8);

	if(!$isUpdate[0][$sNum])
		continue;

	if($pNum == 0 && $i > 0)
		echo "<tr bgcolor=\"#E6E6E6\">";
	else
		echo "<tr>";

	echo "<td>$sNum</font></td>";
	if($flagArr[0][$i]){
		$title = getTitleByTg($mscArr[2][$i]);
		echo "<td>$title</td>";
	}
	else
		echo "<td>--</td>";
	echo "<td>$pNum</td>";
	echo "<td><font color=\"{$flagCol[$i]}\">{$eFlagArr[$flagArr[0][$i]][remark]}</font></td>";
	if($flagArr[0][$i]){
		
		echo "<td><font color=\"{$mscCol[3][$i]}\">{$mscArr[3][$i]}</font></td>";
		echo "<td><font color=\"{$mscArr[2][$i]}\">{$mscArr[2][$i]}</font></td>";
		echo "<td><font color=\"{$mscArr[1][$i]}\">{$mPtArr[$mscArr[1][$i]][remark]}&nbsp;</font></td>";
		echo "<td><font color=\"{$crcCol[$i]}\">{$eCrcArr[$crcArr[0][$i]][remark]}</font></td>";
		echo "<td style=\"border-right:1px solid\"><font color=\"{$dlinkCol[$i]}\">{$eDlinkArr[$dlinkArr[0][$i]][remark]}</font></td>";
	}else{
		echo "<td>--</td>";
		echo "<td>--</td>";
		echo "<td>--</td>";
		echo "<td>--</td>";
		echo "<td style=\"border-right:1px solid\">--</td>";
	}
	if($flagArr[1][$i]){
		$title = getTitleByTg($mscArr[2][$i+128]);
		echo "<td>$title</td>";
	}
	else
		echo "<td>--</td>";
	echo "<td>$pNum</td>";
	echo "<td><font color=\"{$flagCol[$i]}\">{$eFlagArr[$flagArr[1][$i]][remark]}</font></td>";
	if($flagArr[1][$i]){
		echo "<td><font color=\"{$mscCol[3][$i]}\">{$mscArr[3][$i+128]}</font></td>";
		echo "<td><font color=\"{$mscCol[2][$i]}\">{$mscArr[2][$i+128]}</font></td>";
		echo "<td><font color=\"{$mscCol[1][$i]}\">{$mPtArr[$mscArr[1][$i+128]][remark]}&nbsp;</font></td>";
		echo "<td><font color=\"{$crcCol[$i]}\">{$eCrcArr[$crcArr[1][$i]][remark]}</font></td>";
		echo "<td><font color=\"{$dlinkCol[$i]}\">{$eDlinkArr[$dlinkArr[1][$i]][remark]}</font></td>";
	}else{
		echo "<td>--</td>";
		echo "<td>--</td>";
		echo "<td>--</td>";
		echo "<td>--</td>";
		echo "<td>--</td>";
	}
	//echo "<td><input type=\"checkbox\" name=\"C$i\" value=\"ON\"></td>";
	echo "</tr>";
}
echo "</table>";
echo "<input type=\"hidden\" name=\"wDef\" value=\"$wDef\">";
echo "</form>";
?>
</body>
</html>
