<?php
/*	Function: Element main page
	Author:	lilong
	Date:	2004-8-10
	Description: 
*/

require("../../inc/header.inc");
$DEBUG = 1;

$seqNo = 0;
$DB = "OMC_PUB";
$initValue	='initValue';

$ss7Info = array(
	'MSC'=>array('paramTable'=>'OBJ_223.param_99', 'objIdStr'=>'2.1.8')
);
$netInfo = array(
	'0'=>'International',
	'1'=>'International spare',
	'2'=>'National',
	'3'=>'National spare'
);
?>

<script LANGUAGE="JavaScript">  
function openSet(seqNo,action){
	URL="./editElement.php?seqNo="+seqNo+"&action="+action;
	var setWindow = open(URL, 'newWin', 'toolbar=no,directories=no,menubar=no,scrollbars=yes,resizable=yes,status=yes,width=400,height=350');
	setWindow.focus();
}   
</script>
<body onload="javascript:adjust();" onresize="javascript:adjust();" leftmargin="15" style="overflow:hidden;overflow-x:hidden;overflow-y:hidden;">

<?php
echo "<form method=\"POST\" name=\"confForm\" action=\"$PHP_SELF\">";

adjust_head();
adjust_title_head();
echo "<table id=\"table_up\" border=\"0\" width=\"100%\">";
echo "<tr>";
echo "<td width=\"50%\">";
echo "Template > Element";
echo "</td>";
echo "<td width=\"50%\" align=\"right\" title=\"Help\">";
echo "</td>";
echo "</tr>";
echo "</table>";

adjust_title_tail();
adjust_content_head();
echo "<br>";

echo "<TABLE  border=\"1\" width=\"100%\" cellpadding=\"2\" cellspacing=\"0\" ";
echo "bordercolor=\"#666666\" bordercolordark=\"#FFFFFF\" bgcolor=\"#FFFFFF\">";

echo "<tr bgcolor=\"#E6E6E6\">";
echo "<td colspan=3>Wxc2-Element";
echo "<td colspan=3>Get</td>";
echo "<td colspan=4>Set</td>";
echo "</tr>";

echo "<tr bgcolor=\"#E6E6E6\">";
echo "<td>No.</td>";
echo "<td>Name</td>";
echo "<td>Element</td>";
echo "<td>Signalling point</td>";
echo "<td>SS7 Network</td>";
echo "<td>Protocol</td>";
echo "<td>Global Title/Trunk group</td>";
echo "<td>State</td>";
echo "<td>Remarks</td>";
echo "<td>Delete</td>";
echo "</tr>";

$selSql = "SELECT * FROM element";
$selRes = @mysqli_query($pubConn,$selSql);
$totalDevice	= @mysqli_num_rows($selRes);
for ($i=0; $i<$totalDevice; $i++){
	$selRow = @mysqli_fetch_array($selRes);
	$name[$i]		= $selRow[name];
	$element[$i]	= $selRow[element];
	$signallingPoint[$i]	= $selRow[signallingPoint];
	$remarks[$i]	= $selRow[remarks];
	if($DEBUG)	echo "element[$i] = $element[$i]<br>";
}

//得到各element的状态和颜色------State 
for ($i=0; $i<$totalDevice; $i++){
	$selTimeSql = "SELECT sysStat.sysTypeNo,sysStat.updateTime AS updateTime FROM sysStat,sysConf
				WHERE sysStat.sysTypeNo=sysConf.sysTypeNo 
				AND sysConf.sysTypeName LIKE \"$element[$i]\"
				AND sysConf.needHeartBeat=1";

	if($DEBUG) echo "selTimeSql = $selTimeSql<br>";
	$selTimeRes	= @mysqli_query($pubConn,$selTimeSql);
	$num = @mysqli_num_rows($selTimeRes);
	if($DEBUG)	echo "num=$num<br>";
	for ($j=0; $j<$num;	$j++){
		$selTimeRow	= @mysqli_fetch_row($selTimeRes);
		if($DEBUG)	echo "$selTimeRow[0],updateTime = $selTimeRow[1]<br>";

		$due_date	= date("Y-m-d H:i:s",mktime(date("H"),date("i"),date("s")-$heatbeat_overtime,date("m"),date("d"),date("Y")));
		$ove_date	= date("Y-m-d H:i:s",mktime(date("H"),date("i"),date("s")+$heatbeat_overtime,date("m"),date("d"),date("Y")));
		if($DEBUG)	echo "$due_date, $ove_date<Br>";

		if ( ($selTimeRow[updateTime] < $due_date) || ($selTimeRow[updateTime] > $ove_date) ){
			$state[$i]	= "OK";
			$stateColor[$i]	= "#0000FF";
		}else{
			$state[$i]	= "Fail";
			$stateColor[$i]	= "#FF0000";
		}
	}
	if($DEBUG)	echo "stateColor[$i] = $stateColor[$i]<br>";
}

//NI and GTT in SCCP-------SS7 network and Global Title/Trunk group
$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')
);
for ($i=0; $i<$totalDevice; $i++){
	$levelArr=explode('.',$ss7Info[$element[$i]][objIdStr]);
	$where	= " WHERE ";
	for($j=0;$j<sizeof($levelArr);$j++){
		$levelNo=$j+1;
		if($DEBUG) echo "level_$levelNo = {$levelArr[$j]},";
		if(0 != $j)	$where = $where." AND ";
		$where = $where." level_$levelNo = $levelArr[$j] ";
	}
	$getSql="SELECT $initValue,instanceNo  FROM {$ss7Info[$element[$i]][paramTable]} $where";
	if($DEBUG)	echo "<br>getSql=$getSql<br>";
	$getRes = @mysqli_query($pubConn,$getSql);
	$getRow	= @mysqli_fetch_row($getRes);
	if($DEBUG)	echo "getRow=$getRow[0]<br>";
	
	$ni = hexdec(getBitValue($getRow[0],$localNodeConfArr[0][1]));
	$ss7Network[$i]	= $netInfo[$ni];
	echo "ss7Network[$i] = {$ss7Network[$i]}<br>";

	$gtt[$i]	= getBitValue($getRow[0],$localNodeConfArr[1][1]);
	$gtt[$i]	= str_replace('F','',$gtt[$i]);
	if($gtt[$i] == ''){
		$gtt[$i] = '--';
	}
	echo "gtt=$gtt[$i]<br>";
}

for ($i=0; $i<$totalDevice; $i++){
	echo "<tr>";
	echo "<td>$seqNo</td>";
	echo "<td>$name[$i]</td>";
	echo "<td>$element[$i]</td>";
	echo "<td>$signallingPoint[$i]</td>";
	echo "<td>$ss7Network[$i]</td>";
	echo "<td>&nbsp;</td>";
	echo "<td>$gtt[$i]</td>";
	echo "<td ><font color=\"$stateColor[$i]\">$state[$i]</font></td>";
	echo "<td>$remarks[$i]</td>";
	echo "<td>&nbsp;</td>";
	echo "</tr>";
}

//Add an element
echo "<tr>";
echo "<td colspan=10><a href=\"javascript:openSet('0','new')\">";
echo "New</a></td>";
echo "</tr>";
adjust_content_tail();
echo "</form>";
echo "</body>";
?>
