<?php
session_start();
require("../sub_inc/commfunc.php");
//
//******
//$url_temp=$_SERVER["REQUEST_URI"];
//echo "This  page URL:$url_temp<br>";
?>
<html>
<script LANGUAGE="JavaScript"> 	
function linkTo(item,stat)
{
	var strSta;
	strSta = document. getElementById(item).innerHTML;
	if(item.substr(0,3)=='loc'/* && strSta != stat*/)
		window.location.href="../../fault/serverStatus/serverStatus.php?backpage=overview";
	if(item.substr(0,3)!='loc'/* && strSta != stat*/)
		window.location.href="../../fault/csuStatus/csuStatus.php?sys_id=all&backpage=overview";
}

function getStat()
{
	var ulr="getOverviewSta.php";
	var browser = navigator.appName;
	if(browser == "Microsoft Internet Explorer")
	{
		request_o = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else
	{
		request_o = new XMLHttpRequest();
	}
	//alert(request_o);
	
	//alert(ulr);
	request_o.open("GET",ulr,"false");

	request_o.onreadystatechange = updateStat; 

	request_o.send(null);
}
function changeStat(idName,stat,cmpStat)
{
	//alert(idName + ", " + stat);
	var color="blue";
	var cursor = 'pointer';
	if(stat != cmpStat)
		color="red";
	document.getElementById(idName).style.cursor=cursor;
	document.getElementById(idName).innerHTML = stat;
	document.getElementById(idName).style.color = color;
	
}
function doChange(flg,strSubResult,cmpStr)
{
	var i,j,len,id_name;
	var arrSubResult = strSubResult.split("###");
	len = eval(arrSubResult.length);
	i=0;
	for(j=1; j<len; j++)
	{	
		id_name = flg + "EleSta_" + i;
		changeStat(id_name,arrSubResult[j],cmpStr);
		i++;	
	} 
}
function updateStat()
{	
	if(request_o.readyState == 4)
	{
		var strResult = request_o.responseText;
		var arrResult = strResult.split("end");
		var cmpStr;		 
		var id_name ='';
		var flg = '';
		//alert(arrResult.length);
		for(var i=0; i<arrResult.length; i++)
		{
			var strSubResult=arrResult[i];	
			//alert(strSubResult);
			cmpStr="Normal";
			if(i==0)//local
			{	
				flg = "local";				
				doChange(flg,strSubResult,cmpStr);
			}
			cmpStr="Available"
			if(i==1)//bsc
			{
				flg = "bss";				
				doChange(flg,strSubResult,cmpStr);
			}
			cmpStr="Available"
			if(i==2)//aas
			{
				flg = "aas";				
				doChange(flg,strSubResult,cmpStr)
			}
			cmpStr="Available"
			if(i==3)//vss
			{
				flg = "vss";				
				doChange(flg,strSubResult,cmpStr);
			}
			cmpStr="Available"
			if(i==4)//pcr
			{
				flg = "pcr";				
				doChange(flg,strSubResult,cmpStr);
			}
			cmpStr="Available"
			if(i==5)//cnf
			{
				flg = "cnf";				
				doChange(flg,strSubResult,cmpStr);
			}
			cmpStr="Available"
			if(i==6)//switch
			{
				flg = "switch";				
				doChange(flg,strSubResult,cmpStr);
			}
			cmpStr="Available"
			if(i==7)//Application msc
			{
				flg = "msc";				
				doChange(flg,strSubResult,cmpStr);
			}
			cmpStr="Available"
			if(i==8)//Application hlr
			{
				flg = "hlr";				
				doChange(flg,strSubResult,cmpStr);
			}
			cmpStr="Available"
			if(i==9)//Application vlr
			{
				flg = "vlr";				
				doChange(flg,strSubResult,cmpStr);
			}
			cmpStr="Available"
			if(i==10)//Application mc
			{
				flg = "mc";				
				doChange(flg,strSubResult,cmpStr);
			}
			cmpStr="Available"
			if(i==11)//Application sgsn
			{
				flg = "sgsn";				
				doChange(flg,strSubResult,cmpStr);
			}
			cmpStr="Available"
			if(i==12)//Application new
			{
				flg = "new";				
				doChange(flg,strSubResult,cmpStr);
			}
		}
	}
}

function onSetTimer()
{
	timer = window.setInterval("getStat()",15000);
}

//=============this function link to sub pages======================
function linkToSubPage(linkURL)
{
	var page_top=document.body.scrollTop;
	linkURL=linkURL+"&page_top="+page_top;
	//alert(linkURL);
	window.location.href=linkURL;
}

//=============show the remark================

</script>

<?php

//================online help=======================
{
	echo "<div style=\"position:absolute;top:-10;left:815;\">";
	$helpId="2";
	showHelp($helpId);
	echo "</div>";
	
}

$SaveArr=array(
		array('oidstr'=>'3.2',	'setvalue'=>'B5'	,'sysid'=>'322_99_99','selectsysid'=>'-1'),
		array('oidstr'=>'3.7',	'setvalue'=>'02'	,'sysid'=>'222_99_99','selectsysid'=>'-1'),
		array('oidstr'=>'3.7',	'setvalue'=>'02'	,'sysid'=>'222_11_99','selectsysid'=> $vmsMtp3_sysId)
	);

//echo "<FORM NAME=\"downForm\">";
$DEBUG = 0;
$pubDb		 = 'OMC_PUB';
$sysInfoTable='OMC_PUB.sysInfo';
$sysStatTable='OMC_PUB.sysStat';


$getSql="SELECT pubVarValue FROM omcPubVarConf  
			WHERE pubVarName='getparam_from'
		";
if($DEBUG) echo "<BR>getSql=$getSql";
$result	=mysqli_query($pubConn,$getSql);
echo mysqli_error($pubConn);
$rows=mysqli_fetch_array($result);
$getflag=$rows[0];

if(isset($changeflag)){
	$getSql="UPDATE omcPubVarConf set pubVarValue = '$changeflag'  
				WHERE pubVarName='getparam_from'
			";
	if($DEBUG) echo "<BR>getSql=$getSql";
	$result	=mysqli_query($pubConn,$getSql);
	echo mysqli_error($pubConn);

	if($DEBUG) echo "<BR>initValue=$rows[initValue]"; 
	$getflag=$changeflag;		
}

{//get all exist elements from elementExistConf
	getExistElements($existElementArr);
	
	if(@array_search('500', $existElementArr)==TRUE)//BSS
		$needBssIp = 1;
}//end get all exisit elements

$localElementArr=array(
	array('sysTypeName'=>'MSC',	'sysTypeNo'=>'320','sysTypeSSN'=>'8','GT'=>'--','existFlag'=>'0','license'=>'--','licenseColor'=>'','users'=>'--','usersColor'=>'','state'=>'1','stateColor'=>'','confLink'=>"../mss/msc.php?load_flag=$getflag"),
	array('sysTypeName'=>'VLR',	'sysTypeNo'=>'325','sysTypeSSN'=>'7','GT'=>'--','existFlag'=>'0','license'=>'--','licenseColor'=>'','users'=>'--','usersColor'=>'','state'=>'1','stateColor'=>'','confLink'=>"../mss/vlr.php?load_flag=$getflag"),
	array('sysTypeName'=>'HLR',	'sysTypeNo'=>'330','sysTypeSSN'=>'6','GT'=>'--','existFlag'=>'0','license'=>'--','licenseColor'=>'','users'=>'--','usersColor'=>'','state'=>'1','stateColor'=>'','confLink'=>"../mss/hlr.php?load_flag=$getflag"),
	array('sysTypeName'=>'AUC',	'sysTypeNo'=>'340','sysTypeSSN'=>'10','GT'=>'--','existFlag'=>'0','license'=>'--','licenseColor'=>'','users'=>'--','usersColor'=>'','state'=>'1','stateColor'=>'','confLink'=>"../mss/auc.php?load_flag=$getflag"),
	array('sysTypeName'=>'SMSC','sysTypeNo'=>'350','sysTypeSSN'=>'11','GT'=>'--','existFlag'=>'0','license'=>'--','licenseColor'=>'','users'=>'--','usersColor'=>'','state'=>'1','stateColor'=>'','confLink'=>"../mss/smsc.php?load_flag=$getflag"),
	array('sysTypeName'=>'PPS',	'sysTypeNo'=>'360','sysTypeSSN'=>'147','GT'=>'--','existFlag'=>'0','license'=>'--','licenseColor'=>'','users'=>'--','usersColor'=>'','state'=>'1','stateColor'=>'','confLink'=>"../mss/loadpps.php?load_flag=$getflag"),
	array('sysTypeName'=>'EIR',	'sysTypeNo'=>'380','sysTypeSSN'=>'9','GT'=>'--','existFlag'=>'0','license'=>'--','licenseColor'=>'','users'=>'--','usersColor'=>'','state'=>'1','stateColor'=>'','confLink'=>"../mss/eir.php?load_flag=$getflag"),
	array('sysTypeName'=>'MNP',	'sysTypeNo'=>'370','sysTypeSSN'=>'32','GT'=>'--','existFlag'=>'0','license'=>'--','licenseColor'=>'','users'=>'--','usersColor'=>'','state'=>'1','stateColor'=>'','confLink'=>"../mss/mnp.php?load_flag=$getflag"));

$NetIdConfArr=array(
	"0"=>"International",
	"1"=>"International spare",
	"2"=>"National",
	"3"=>"National spare"
);

if($DEBUG) echo "<br>正在调试中！！";
//==========================================================
//变量定义
//==========================================================
//<body topmargin="0" onload="onSetTimer();" onunload="clearInterval(timer);" leftmargin="12">
?>
<?php
$scroll_y = isset($scroll_y) ? $scroll_y : 0;
echo "<body topmargin=\"0\" onLoad=\"onSetTimer();self.scrollBy(0,$scroll_y);\" onunload=\"clearInterval(timer);\" leftmargin=\"12\">";


echo "<table border=\"0\" width=\"100%\">";
echo "<tr>";
echo "<td width=\"50%\">";
echo "$strConfiguration > <a href=\"#\">$strNetwork</a>";
echo "</td>";
/*
if($getflag==1){
	echo "<td title=\"MSC\" align=\"right\"><img align=absBottom border=0 src=\"../../images/server.gif\" >";
	echo "<a href=\"$PHP_SELF?changeflag=0\" title=\"Change to OMC.\"><img align=absBottom border=0 src=\"../../images/omc_small.gif\" ></a></td>";
}else{
	echo "<td title=\"OMC\" align=\"right\"><img align=absBottom border=0 src=\"../../images/omc.gif\" >";
	echo "<a href=\"$PHP_SELF?changeflag=1\" title=\"Change to MSC.\"><img align=absBottom border=0 src=\"../../images/server_small.gif\" ></a></td>";
}
echo "<td  align=\"right\" title=\"Help\">";
$helpId = "2"; 
showHelp($helpId);
echo "</td>";
*/echo "</tr>";
echo "</table>";

?>

<?php
//local element
$nGetComm	= 0;
$nSetComm	= 3;

$maxNum = 30;

////////////////
$locEleParTab='OBJ_223.param_99';
for($i=0;$i< sizeof($localElementArr);$i++)
{
	$canAdd = @array_search($localElementArr[$i][sysTypeNo], $existElementArr);
	for($k=0; $k<sizeof($existElementArr);$k++)
	{
		if($localElementArr[$i][sysTypeNo] == $existElementArr[$k])
		{
			$localElementArr[$i][existFlag]=1;
			$tmpOid = "2.1.".$localElementArr[$i][sysTypeSSN];
			$levelWhere = getLevelWhere($tmpOid);
			$getSql="SELECT initValue FROM $locEleParTab WHERE $levelWhere";
			if(0) echo "<BR>getSql=$getSql";
			$result	=mysqli_query($pubConn,$getSql);
			$rows = mysqli_fetch_array($result);
			$tmpHex=substr($rows[0],2,20);
			$tmpHexArr=explode("F",$tmpHex);
			$localElementArr[$i][GT]=$tmpHexArr[0];
			break;
		}
	}
}
if($localElementArr[0][existFlag]==1)
{
	$localElementArr[1][existFlag]=1;
	$tmpOid = "2.1.".$localElementArr[1][sysTypeSSN];
	$levelWhere = getLevelWhere($tmpOid);
	$getSql="SELECT initValue FROM $locEleParTab WHERE $levelWhere";
	$result	=mysqli_query($pubConn,$getSql);
	$rows = mysqli_fetch_array($result);
	$tmpHex=substr($rows[0],2,20);
	$tmpHexArr=explode("F",$tmpHex);
	$localElementArr[1][GT]=$tmpHexArr[0];
}
////////////////

for($i=0;$i<sizeof($localElementArr);$i++)
{
	if($localElementArr[$i][existFlag]==1)
	{
		$getSql="SELECT baseStat,updateTime FROM $sysInfoTable	WHERE sysTypeNo='{$localElementArr[$i][sysTypeNo]}' 
		ORDER BY sysNo,subSysNo";
		if($DEBUG) echo "<BR>getSql=$getSql";
		$result	=mysqli_query($pubConn,$getSql);
		if(mysqli_num_rows($result)==0)
		{
			$localElementArr[$i][state]=0;
			$localElementArr[$i][stateColor]='#FF0000';
		}
		else
		{
			while($rows=mysqli_fetch_array($result))
			{
				$out_time=date("Y-m-d H:i:s",mktime(date("H"),date("i"),date("s")-60,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(1&&$localElementArr[$i][sysTypeNo]==360) echo "<br>" . "{$rows[1]}< $out_time";
				if($rows[0]==0||$rows[1]< $out_time)
				{
					$localElementArr[$i][state]=0;
					$localElementArr[$i][stateColor]='#FF0000';
				}
			}
		}
	}
}

for($i=0;$i<sizeof($localElementArr);$i++)
{
	if($localElementArr[$i][existFlag]==1 && $localElementArr[$i][sysTypeNo]!=325)
	{
		$getSql="SELECT detailStat FROM $sysStatTable WHERE sysTypeNo='{$localElementArr[$i][sysTypeNo]}' 
		ORDER BY sysNo,subSysNo";
		if($DEBUG) echo "<BR>getSql=$getSql";
		$result	=mysqli_query($pubConn,$getSql);
		$serverNum=mysqli_num_rows($result);
		switch($localElementArr[$i][sysTypeNo])
		{
			case 320://msc
			{
				$byteLicStart = 31;
				$lenLic = 4;
				$byteUseStart = 35;
				$lenUse = 4;
				break;
			}
			
			case 330://HLR
			case 340://auc
			case 350://smsc
			case 360://pps
			case 370://mnp
			case 380://eir
			{
				$byteLicStart = 31;
				$lenLic = 4;
				$byteUseStart = 35;
				$lenUse = 4;
				break;
			}
			default:
			{
				$byteLicStart = 31;
				$lenLic = 4;
				$byteUseStart = 35;
				$lenUse = 4;
				break;
			}
			
		}
		
		if($localElementArr[$i][sysTypeNo]==320)
		{
			if($serverNum==0)
			{
				$localElementArr[$i][licenseColor]='#FF0000';
				$localElementArr[$i][usersColor]='#FF0000';
				$localElementArr[1][licenseColor]='#FF0000'; //VLR
				$localElementArr[1][usersColor]='#FF0000';
			}
			else if($serverNum==1)
			{
				$rows=mysqli_fetch_array($result);
										
				$msc_bgn_byt=21;
    		$msc_len_hex=substr($rows[0],$msc_bgn_byt*2,4);//msc length
    		$msc_len_dec=HexDec($msc_len_hex);
    		if($DEBUG)
    			echo "<br>msc_len_dec=$msc_len_dec";
    		$vlr_bgn_byt=$msc_bgn_byt+4+$msc_len_dec;
				$byteVlrLicStart = $vlr_bgn_byt+10;
				$lenVlrLic = 4;
				$byteVlrUseStart = $vlr_bgn_byt+14;
				$lenVlrUse = 4;
				
				$localElementArr[$i][licenseColor]='#FF0000';
				$localElementArr[$i][usersColor]='#FF0000';
				$localElementArr[1][licenseColor]='#FF0000';
				$localElementArr[1][usersColor]='#FF0000';				
				$localElementArr[$i][license]=hexdec(substr($rows[0],$byteLicStart*2,$lenLic*2));
				$localElementArr[$i][users]=hexdec(substr($rows[0],$byteUseStart*2,$lenUse*2));
				$localElementArr[1][license]=hexdec(substr($rows[0],$byteVlrLicStart*2,$lenVlrLic*2));
				$localElementArr[1][users]=hexdec(substr($rows[0],$byteVlrUseStart*2,$lenVlrUse*2));
			}
			else
			{
				$rows=mysqli_fetch_array($result);
				
							
				$msc_bgn_byt=21;
    		$msc_len_hex=substr($rows[0],$msc_bgn_byt*2,4);//msc length
    		$msc_len_dec=HexDec($msc_len_hex);
    		if($DEBUG)
    			echo "<br>msc_len_dec=$msc_len_dec";
    		$vlr_bgn_byt=$msc_bgn_byt+4+$msc_len_dec;
				$byteVlrLicStart = $vlr_bgn_byt+10;
				$lenVlrLic = 4;
				$byteVlrUseStart = $vlr_bgn_byt+14;
				$lenVlrUse = 4;
				$localElementArr[$i][license]=hexdec(substr($rows[0],$byteLicStart*2,$lenLic*2));
				$localElementArr[$i][users]=hexdec(substr($rows[0],$byteUseStart*2,$lenUse*2));
				$localElementArr[1][license]=hexdec(substr($rows[0],$byteVlrLicStart*2,$lenVlrLic*2));
				$localElementArr[1][users]=hexdec(substr($rows[0],$byteVlrUseStart*2,$lenVlrUse*2));
				
				$rows=mysqli_fetch_array($result);
				$tmp_license=hexdec(substr($rows[0],$byteLicStart*2,$lenLic*2));
				$tmp_users=hexdec(substr($rows[0],$byteUseStart*2,$lenUse*2));
				$tmp_license_1=hexdec(substr($rows[0],$byteVlrLicStart*2,$lenVlrLic*2));
				$tmp_users_1=hexdec(substr($rows[0],$byteVlrUseStart*2,$lenVlrUse*2));
				
				if($tmp_license!=$localElementArr[$i][license])
					$localElementArr[$i][licenseColor]='#FF0000';
				if($tmp_users!=$localElementArr[$i][users])
					$localElementArr[$i][usersColor]='#FF0000';
				if($tmp_license_1!=$localElementArr[1][license])
					$localElementArr[1][licenseColor]='#FF0000';
				if($tmp_users_1!=$localElementArr[1][users])
					$localElementArr[1][usersColor]='#FF0000';
			}
		}
		else
		{
			if($serverNum==0)
			{
				$localElementArr[$i][licenseColor]='#FF0000';
				$localElementArr[$i][usersColor]='#FF0000';
			}
			else if($serverNum==1)
			{
				$rows=mysqli_fetch_array($result);
				$localElementArr[$i][licenseColor]='#FF0000';
				$localElementArr[$i][usersColor]='#FF0000';
				$localElementArr[$i][license]=hexdec(substr($rows[0],$byteLicStart*2,$lenLic*2));
				$localElementArr[$i][users]=hexdec(substr($rows[0],$byteUseStart*2,$lenUse*2));
			}
			else
			{
				$rows=mysqli_fetch_array($result);
				$localElementArr[$i][license]=hexdec(substr($rows[0],$byteLicStart*2,$lenLic*2));
				$localElementArr[$i][users]=hexdec(substr($rows[0],$byteUseStart*2,$lenUse*2));
				$rows=mysqli_fetch_array($result);
				$tmp_license=hexdec(substr($rows[0],$byteLicStart*2,$lenLic*2));
				$tmp_users=hexdec(substr($rows[0],$byteUseStart*2,$lenUse*2));
				if($tmp_license!=$localElementArr[$i][license])
					$localElementArr[$i][licenseColor]='#FF0000';
				if($tmp_users!=$localElementArr[$i][users])
					$localElementArr[$i][usersColor]='#FF0000';
			}
		}
	}
}

?>

<?php
$getState=1;
if($getState)
{//start get e1 status
	///////////////////get e1 status
	$e1selSql = "SELECT sysTypeNo,sysNo,subSysNo,detailStat,updateTime 
				FROM sysStat WHERE sysTypeNo='111' order by sysNo,subSysNo";
	$e1Result = @mysqli_query($pubConn,$e1selSql);
	while($e1Row = @mysqli_fetch_array($e1Result))
	{
		$hex_mes = $e1Row[detailStat];
		$sysNo = $e1Row[sysNo];
		$subSysNo = $e1Row[subSysNo];
		
		$bin_mes='';
		for($i=0;$i<strlen($hex_mes);$i++)
		{
			$sig_hex_mes=substr($hex_mes,$i,1);
			$sig_dec_mes=HexDec($sig_hex_mes);
			$sig_bin_mes=DecBin($sig_dec_mes);
			$sig_bin_mes=omc_keep_length($sig_bin_mes,0,4);
			$bin_mes.=$sig_bin_mes;
		}
		
		$e1HeartBeatArr[$sysNo][$subSysNo] = $bin_mes;
	}
	
	$ins_bgn	=	22;	//e1 installed
	$phy_bgn	=	24;	//e1 layer1(physical layer)
	$el2_bgn	=   25; //e1 layer2
	$E1state1=1;//OK
	$E1state2=0;//DOWN	
	for($i=0; $i< 256; $i++)
	{
		$cardno = Floor($i/8); //0 - 32
		$sysNo = $cardno > 15 ? 1 : 0;
		$subSysNo = $cardno % 16;
		$port = $i - $cardno*8;
		//e1 install
		$bin_mes = $e1HeartBeatArr[$sysNo][$subSysNo];
		//if($DEBUG)echo "<br>$i: $bin_mes";
		$bin_ins=substr($bin_mes,$ins_bgn*8+7-$port,1);//0:'--'; 1:'Y'
		$tmp1 = bindec($bin_ins);
		
		//e1 layer1
		$bin_phy=substr($bin_mes,$phy_bgn*8+7-$port,1);//0:'Y'; 1:'N'; 2:'--'
		$tmp2 = bindec($bin_phy);
		$tmp2++;
		$tmp2 = ($tmp2>1) ? 0 : $tmp2;
		
		//e1 layer2 install
		$bin_inl=substr($bin_mes,$el2_bgn*8+7-$port,1);//0:'N'; 1:'Y';
		$tmp3 = bindec($bin_inl);
					
		$E1stateArr1[$i] = $E1state1 & $tmp2 & $tmp3;
		$E1stateArr2[$i] = $E1state2 | $tmp2 | $tmp3;
		//echo "<br>E1stateArr1[$i]:{$E1stateArr1[$i]},E1stateArr2[$i]:{$E1stateArr2[$i]}";
	}//end for
	
	$tmpObjIdStr='2.4.2';
	$levelWhere = getLevelWhere($tmpObjIdStr);
	$tmpTgValue=strtoupper(omc_keep_length($tmpTgValue,0,2));
	$getSql="SELECT initValue,instanceNo FROM OBJ_322.param_99 
				WHERE $levelWhere and initValue!='EE' order by instanceNo";				
	$result	=mysqli_query($pubConn,$getSql);
	while($Rows = mysqli_fetch_array($result))
	{
		$tg = hexdec($Rows[initValue]);
		if(!isset($e1StatAtTgArr1[$tg])) $e1StatAtTgArr1[$tg]=1;
		if(!isset($e1StatAtTgArr2[$tg])) $e1StatAtTgArr2[$tg]=0;
		$e1StatAtTgArr1[$tg] &= $E1stateArr1[$Rows[instanceNo]];
		$e1StatAtTgArr2[$tg] |= $E1stateArr2[$Rows[instanceNo]];
		//echo "<br>$Rows[instanceNo]:{$E1stateArr1[$Rows[instanceNo]]};e1StatAtTgArr1[$tg]:{$e1StatAtTgArr1[$tg]},e1StatAtTgArr2[$tg]:{$e1StatAtTgArr2[$tg]}";
	}
	
	////////////////get lins status
	$out_time=date("Y-m-d H:i:s",mktime(date("H"),date("i"),date("s")-30,date("m"),date("d"),date("Y")));
	//E1 link status		
	$HbparamSql = " SELECT detailStat FROM OMC_PUB.sysStat  
			WHERE sysTypeNo='200' AND sysNo='9' AND (subSysNo='0' or subSysNo='1') AND updateTime>'$out_time'
			";
	$Hbresult = mysqli_query($pubConn,$HbparamSql);				
	while($Hbvalue_mpt3Arr[]  = mysqli_fetch_array($Hbresult));//取mtp3 的heartbeat
	if(sizeof($Hbvalue_mpt3Arr)==3)
		$isDualServ = 1;	
	//E1 link
	$tmpObjIdStr='2.5.1';
	$levelWhere = getLevelWhere($tmpObjIdStr);
	//echo "$levet:$levelWhere<br>";
	$tmpValue=dechex($linkset);
	$tmpValue=strtoupper(omc_keep_length($tmpValue,0,2));
	$getSql="SELECT initValue,instanceNo FROM OBJ_222.param_99 
				WHERE $levelWhere order by instanceNo";				
	$result	=mysqli_query($pubConn,$getSql);			
	while($rows=mysqli_fetch_array($result))
	{	
		$linkflag	= getBitValue($rows[initValue],'06.5-06.5');
		$ls	= hexdec(getBitValue($rows[initValue],'00.0-00.7'));
		if($linkflag)
		{
			if(!isset($e1StatAtLsArr1[$ls])) $e1StatAtLsArr1[$ls]=1;
			if(!isset($e1StatAtLsArr2[$ls])) $e1StatAtLsArr2[$ls]=0;	
	
			$Hboffset=39+Floor($rows[instanceNo]/4);
			$tmpValue=substr($Hbvalue_mpt3Arr[0][detailStat],$Hboffset*2,2);
			if($isDualServ && $rows[instanceNo]>=128)
				$tmpValue=substr($Hbvalue_mpt3Arr[1][detailStat],$Hboffset*2,2);
			$bitoff	=$rows[instanceNo]%4;
			$bitoff1=$bitoff*2;
			$bitoff2=$bitoff1+1;
			$bitoff='0.'.$bitoff1.'-0.'.$bitoff2;
	//echo "<br>$bitoff";
			$tmp=bindec(getBitValue($tmpValue,$bitoff));		
			if($tmp>1)
				$tmp=0;	
			$e1StatAtLsArr1[$ls] &= $tmp;
			$e1StatAtLsArr2[$ls] |= $tmp;
	//		echo "<br>$rows[instanceNo]: e1StatAtLsArr1[$ls]:{$e1StatAtLsArr1[$ls]},e1StatAtLsArr2[$ls]:{$e1StatAtLsArr2[$ls]}";
		}
	}//end while	
}//end get e1 status.


$niTypeArr = getNiType();
//others element
$othersElementObjIdStr='2.4.1';
$levelWhere = getLevelWhere($othersElementObjIdStr);
if($DEBUG) echo "<BR>levelWhere=$levelWhere";
$othersElementParamTable='OBJ_222.param_99';
$getSql="SELECT initValue,instanceNo FROM $othersElementParamTable 
			WHERE $levelWhere ";
if($DEBUG) echo "<BR>getSql=$getSql";
$result	=mysqli_query($pubConn,$getSql);
echo mysqli_error($pubConn);

while($rows=mysqli_fetch_array($result))
{
	if($DEBUG)echo "<BR>initValue=$rows[initValue]";
	$tmpType=getBitValue($rows[initValue],'4.0-4.7');//system type
	if($tmpType==0)
		continue;
	$i = $rows[instanceNo];
	$lsArr[$i][dpc]=hexdec(getBitValue($rows[initValue],'0.0-2.7'));		
	$lsArr[$i][ni]=bindec(getBitValue($rows[initValue],'3.0-3.1'));
	if($DEBUG) echo "<BR>linkset={$elementsArr[$i][linkset]}";
	
}
{//other elements
	$othersElementObjIdStr='2.11';
	$levelWhere = getLevelWhere($othersElementObjIdStr);
	if($DEBUG) echo "<BR>levelWhere=$levelWhere";
	$othersElementParamTable='OBJ_225.param_99';
	$getSql="SELECT initValue,instanceNo FROM $othersElementParamTable 
				WHERE $levelWhere and initValue LIKE '01%'
			";
	if($DEBUG) echo "<BR>getSql=$getSql";
	$result	=mysqli_query($pubConn,$getSql);
	echo mysqli_error($pubConn);
	$typeOffset 	= '1.0-1.7';
	$sysNoOffset 	= '2.0-2.3';
	$subSysNoOffset = '2.4-2.7';
	$tgOffset 		= '3.0-3.7';
	$lsOffset 		= '4.0-4.7';
	$appTypeOffset 	= '5.0-5.7';
	$appGrpOffset 	= '6.0-6.7';
	$nameOffset 	= '14.0-23.7';
	$i=0;
	while($rows=mysqli_fetch_array($result))
	{
		if($DEBUG)echo "<BR>initValue=$rows[initValue]";
		$tmpType=getBitValue($rows[initValue],'1.0-1.7');
		if($tmpType==0)
			continue;
		$elementsArr[$i][infoNo]=$rows[instanceNo];	
		$type = $elementsArr[$i][type]=hexdec($tmpType);
		$elementsArr[$i][sysNo]=bindec(getBitValue($rows[initValue],$sysNoOffset));
		$elementsArr[$i][subSysNo]=bindec(getBitValue($rows[initValue],$subSysNoOffset));
		$ls2tg = $elementsArr[$i][tg]=hexdec(getBitValue($rows[initValue],$tgOffset));
		$ls = $elementsArr[$i][linkset] = $ls = hexdec(getBitValue($rows[initValue],$lsOffset));
		$elementsArr[$i][appType]=hexdec(getBitValue($rows[initValue],$appTypeOffset));
		$elementsArr[$i][appGrp]=hexdec(getBitValue($rows[initValue],$appGrpOffset));
		$elementsArr[$i][name]=getBitValue($rows[initValue],$nameOffset);
		if($elementsArr[$i][name]==0)
			$elementsArr[$i][name]=$elementsArr[$i][tg];
		else
			$elementsArr[$i][name]=trim(toAscii($elementsArr[$i][name]));		
		$elementsArr[$i][ni] = $lsArr[$ls][ni];
		$elementsArr[$i][dpc]= $lsArr[$ls][dpc];
		if($getState)
		{//get state
			if($type==17)//isdn switch
			{
				$e1State1 = $e1StatAtTgArr1[$ls2tg];
				$e1State2 = $e1StatAtTgArr2[$ls2tg];
				if($e1State1==1&&$e1State2==1)
					$E1state='Available';
				elseif($e1State1==0&&$e1State2==1)
					$E1state='Alarm';
				else
					$E1state='Unavailable';
			}
			else if($type==18/* && $ls2tg==255*/)//only link, but no e1
			{
				$e1State1 = $e1StatAtLsArr1[$ls];
				$e1State2 = $e1StatAtLsArr2[$ls];
				if($e1State1==1&&$e1State2==1)
					$E1state='Available';
				elseif($e1State1==0&&$e1State2==1)
					$E1state='Alarm';
				else
					$E1state='Unavailable';
			}
			else
			{
				$e1State1 = $e1StatAtTgArr1[$ls2tg] & $e1StatAtLsArr1[$ls];
				$e1State2 = $e1StatAtTgArr2[$ls2tg] | $e1StatAtLsArr2[$ls];
				if($e1State1==1&&$e1State2==1)
					$E1state='Available';
				elseif($e1State1==0&&$e1State2==1)
					$E1state='Alarm';
				else
					$E1state='Unavailable';
			}
			$elementsArr[$i][state] = $E1state;
		}//end get state.
		$i++;	
	}
}//end otherelments

{//LAC parameters
	$lacObjIdStr='2.2.6'; //find lac
	$levelWhere = getLevelWhere($lacObjIdStr);
	$mscParamTable='OBJ_322.param_99';
	$getSql="SELECT initValue FROM $mscParamTable 
				WHERE $levelWhere ORDER BY instanceNo
				";
	if($DEBUG) 
		echo "<BR>getSql=$getSql";
	$result	=mysqli_query($pubConn,$getSql);
	echo mysqli_error($pubConn);
	
	$i=0;
	while($rows=mysqli_fetch_array($result))
	{
		if(hexdec(getBitValue($rows[initValue],'0.0-0.1'))==1)
		{
			$lacAtt[$i][tg]=hexdec(getBitValue($rows[initValue],'1.0-1.7'));
			$lacAtt[$i][lac]=hexdec(getBitValue($rows[initValue],'2.0-3.7'));
		}
		$i++;
	}
	$lacTotalNum=$i;
}//end lac parameters
//print_r($elementsArr);
if(0)
{//get bss' ip
	$bssTable = "BssOmcDb.OMCR_BSSTABLE";
	$selSql = "select ip,bssid from $bssTable";
	$bssResult = mysqli_query($pubConn,$selSql);
	while($bssRow = mysqli_fetch_array($bssResult))
	{
		$bssIpArr[$bssRow[bssid]] = $bssRow[ip];
	}
}//end get bss' ip
//print_r($bssIpArr);
for($i=0;$i<sizeof($elementsArr);$i++)
{
	if($DEBUG) echo "<br>type={$elementsArr[$i][type]}";
	switch($elementsArr[$i][type])
	{
		case '1'://BSS
		{			
			$bssElementNo=sizeof($bssElementArr);
			if($DEBUG)
				echo"<br>bssElementNo=$bssElementNo";
			$bssElementArr[$bssElementNo][linkset]=$elementsArr[$i][linkset];
			$bssElementArr[$bssElementNo][sysNo] = $tmp_sysNo = $elementsArr[$i][sysNo];
			$bssElementArr[$bssElementNo][name]=$elementsArr[$i][name];
			$bssElementArr[$bssElementNo][dpc]=$elementsArr[$i][dpc];
			$bssElementArr[$bssElementNo][ni]=$elementsArr[$i][ni];
			$bssElementArr[$bssElementNo][tg]=$elementsArr[$i][tg];
			$bssElementArr[$bssElementNo][infoNo]=$elementsArr[$i][infoNo];					
			if($getState) $bssElementArr[$bssElementNo][state]=$elementsArr[$i][state];
			else $bssElementArr[$bssElementNo][state] = "Refreshing";
			//$bssElementArr[$bssElementNo][ip]=$bssIpArr[$tmp_sysNo];
			if($DEBUG) echo "bssElementArr[$bssElementNo][state]$rows[instanceNo],{$elementsArr[$i][linkset]}={$bssElementArr[$bssElementNo][state]}<br>";
		
			for($k=0;$k< $lacTotalNum;$k++)
			{
				if(isset($lacAtt[$k][tg])&&$bssElementArr[$bssElementNo][tg]==$lacAtt[$k][tg])
				{
					$bssElementArr[$bssElementNo][lac]=$lacAtt[$k][lac];
					break;
				}
			}
			if($k==$lacTotalNum)
			{
				$bssElementArr[$bssElementNo][lac]='--';
			}
			break;
		}
		case '2'://AAS 		
		{	
			$aasElementNo=sizeof($aasElementArr);
			$aasElementArr[$aasElementNo][linkset]=$elementsArr[$i][linkset];
			$aasElementArr[$aasElementNo][sysNo]=$elementsArr[$i][sysNo];
			$aasElementArr[$aasElementNo][name]=$elementsArr[$i][name];
			$aasElementArr[$aasElementNo][tg]=$elementsArr[$i][tg];
			$aasElementArr[$aasElementNo][infoNo]=$elementsArr[$i][infoNo];
			if($getState) $aasElementArr[$aasElementNo][state]=$elementsArr[$i][state];
			else $aasElementArr[$aasElementNo][state]='Refreshing';
	
			$tmpObjIdStr='2.1.3';
			$levelWhere = getLevelWhere($tmpObjIdStr);
			$getSql="SELECT initValue,instanceNo FROM OBJ_322.param_99 
						WHERE $levelWhere and instanceNo<252
					";
			if($DEBUG) echo "<BR>getSql=$getSql";
			$result	=mysqli_query($pubConn,$getSql);
			echo mysqli_error($pubConn);
			
			if(isset($tmpInstanceNo))
				unset($tmpInstanceNo);
			while($rows=mysqli_fetch_array($result))
			{
				$tmpValue=hexdec($rows[initValue]);
				//echo "<br>tmpValue=$tmpValue";
				if($tmpValue==$aasElementArr[$aasElementNo][tg])
				{
					//echo "<br>instance=$rows[instanceNo]";
					//echo "<br>initValue=$rows[initValue]";
					//echo "<br>prefixNoStr={$aasElementArr[$aasElementNo][prefixNoStr]}";
					$tmpObjIdStr='2.1.1';
					$levelWhere = getLevelWhere($tmpObjIdStr);
					$getSql="SELECT initValue FROM OBJ_322.param_99 
								WHERE $levelWhere AND instanceNo='$rows[instanceNo]'
							";
					if($DEBUG)echo "<BR>getSql=$getSql";
					$result_2	=mysqli_query($pubConn,$getSql);
					echo mysqli_error($pubConn);
					$rows_2=mysqli_fetch_array($result_2);
					$tmpPrefixArr=explode("E",$rows_2[initValue]);
					if(strlen($tmpPrefixArr[0])==0)
						continue;
					$aasElementArr[$aasElementNo][prefix]=$tmpPrefixArr[0];
					
					if(!isset($tmpInstanceNo))
					{
						$tmpInstanceNo=$rows[instanceNo];
						$aasElementArr[$aasElementNo][prefixNoStr]=$rows[instanceNo];
					}
					else
					{
						$aasElementArr[$aasElementNo][prefixNoStr] .= '.'.$rows[instanceNo];
					}
					//echo "<br>aasElementArr[$aasElementNo][prefixNoStr]: {$aasElementArr[$aasElementNo][prefixNoStr]}";
				}
			}			
			
			//Number of links
			$hexTg = strtoupper(omc_keep_length(dechex($aasElementArr[$aasElementNo][tg]),'0',2));
			$tmpObjIdStr='2.4.2';
			$levelWhere = getLevelWhere($tmpObjIdStr);
			$getSql="SELECT initValue FROM OBJ_322.param_99 
						WHERE $levelWhere AND initValue like '$hexTg'
					";
			if($DEBUG)echo "<BR>getSql=$getSql";
			$result	=mysqli_query($pubConn,$getSql);
			echo mysqli_error($pubConn);
			$aasElementArr[$aasElementNo][linkNum]=mysqli_num_rows($result);
			break;
		}
		case '3'://VSS 	
		{		
			$vssElementNo=sizeof($vssElementArr);
			$vssElementArr[$vssElementNo][linkset]=$elementsArr[$i][linkset];
			$vssElementArr[$vssElementNo][sysNo]=$elementsArr[$i][sysNo];
			$vssElementArr[$vssElementNo][name]=$elementsArr[$i][name];
			$vssElementArr[$vssElementNo][tg]=$elementsArr[$i][tg];
			$vssElementArr[$vssElementNo][infoNo]=$elementsArr[$i][infoNo];	
			if($getState) $vssElementArr[$vssElementNo][state]=$elementsArr[$i][state];
			else		 $vssElementArr[$vssElementNo][state]= 'Refreshing';	
			$tmpObjIdStr='2.1.3';
			$levelWhere = getLevelWhere($tmpObjIdStr);
			$getSql="SELECT initValue,instanceNo FROM OBJ_322.param_99 
						WHERE $levelWhere and instanceNo<252
					";
			if($DEBUG) echo "<BR>getSql=$getSql";
			$result	=mysqli_query($pubConn,$getSql);
			echo mysqli_error($pubConn);
			
			if(isset($tmpInstanceNo))
				unset($tmpInstanceNo);
			while($rows=mysqli_fetch_array($result))
			{
				$tmpValue=hexdec($rows[initValue]);
				//echo "<br>tmpValue=$tmpValue";
				if($tmpValue==$vssElementArr[$vssElementNo][tg])
				{
					//echo "<br>instance=$rows[instanceNo]";
					//echo "<br>initValue=$rows[initValue]";
					//echo "<br>prefixNoStr={$vssElementArr[$vssElementNo][prefixNoStr]}";
					$tmpObjIdStr='2.1.1';
					$levelWhere = getLevelWhere($tmpObjIdStr);
					$getSql="SELECT initValue FROM OBJ_322.param_99 
								WHERE $levelWhere AND instanceNo='$rows[instanceNo]'
							";
					if($DEBUG)echo "<BR>getSql=$getSql";
					$result_2	=mysqli_query($pubConn,$getSql);
					echo mysqli_error($pubConn);
					$rows_2=mysqli_fetch_array($result_2);
					$tmpPrefixArr=explode("E",$rows_2[initValue]);
					if(strlen($tmpPrefixArr[0])==0)
						continue;
					$vssElementArr[$vssElementNo][prefix]=$tmpPrefixArr[0];
					
					if(!isset($tmpInstanceNo))
					{
						$tmpInstanceNo=$rows[instanceNo];
						$vssElementArr[$vssElementNo][prefixNoStr]=$rows[instanceNo];
					}
					else
					{
						$vssElementArr[$vssElementNo][prefixNoStr]=$vssElementArr[$vssElementNo][prefixNoStr].'.'.$rows[instanceNo];
					}
				}
			}			
			
			//Number of links
			$hexTg = strtoupper(omc_keep_length(dechex($vssElementArr[$vssElementNo][tg]),'0',2));
			$tmpObjIdStr='2.4.2';
			$levelWhere = getLevelWhere($tmpObjIdStr);
			$getSql="SELECT initValue FROM OBJ_322.param_99 
						WHERE $levelWhere AND initValue like '$hexTg'
					";
			if($DEBUG)echo "<BR>getSql=$getSql";
			$result	=mysqli_query($pubConn,$getSql);
			echo mysqli_error($pubConn);
			$vssElementArr[$vssElementNo][linkNum]=mysqli_num_rows($result);	
			break;
		}
		case '4'://PCR 	
		{		
			$pcrElementNo=sizeof($pcrElementArr);
			$pcrElementArr[$pcrElementNo][linkset]=$elementsArr[$i][linkset];
			$pcrElementArr[$pcrElementNo][sysNo]=$elementsArr[$i][sysNo];
			$pcrElementArr[$pcrElementNo][name]=$elementsArr[$i][name];
			$pcrElementArr[$pcrElementNo][tg]=$elementsArr[$i][tg];
			$pcrElementArr[$pcrElementNo][infoNo]=$elementsArr[$i][infoNo];	
			if($getState) $pcrElementArr[$pcrElementNo][state]=$elementsArr[$i][state];
			else $pcrElementArr[$pcrElementNo][state] = 'Refreshing';
			//$pcrElementArr[$pcrElementNo][state]=getE1State($pcrElementArr[$pcrElementNo][tg],$elementsArr[$i][linkset]);
			
			$tmpObjIdStr='2.1.3';
			$levelWhere = getLevelWhere($tmpObjIdStr);
			$getSql="SELECT initValue,instanceNo FROM OBJ_322.param_99
						WHERE $levelWhere and instanceNo<252
					";
			if($DEBUG) echo "<BR>getSql=$getSql";
			$result	=mysqli_query($pubConn,$getSql);
			echo mysqli_error($pubConn);
			
			if(isset($tmpInstanceNo))
				unset($tmpInstanceNo);
			while($rows=mysqli_fetch_array($result))
			{
				$tmpValue=hexdec($rows[initValue]);
				//echo "<br>tmpValue=$tmpValue";
				if($tmpValue==$pcrElementArr[$pcrElementNo][tg])
				{
					//echo "<br>instance=$rows[instanceNo]";
					//echo "<br>initValue=$rows[initValue]";
					//echo "<br>prefixNoStr={$pcrElementArr[$pcrElementNo][prefixNoStr]}";
					$tmpObjIdStr='2.1.1';
					$levelWhere = getLevelWhere($tmpObjIdStr);
					$getSql="SELECT initValue FROM OBJ_322.param_99 
								WHERE $levelWhere AND instanceNo='$rows[instanceNo]'
							";
					if($DEBUG)echo "<BR>getSql=$getSql";
					$result_2	=mysqli_query($pubConn,$getSql);
					echo mysqli_error($pubConn);
					$rows_2=mysqli_fetch_array($result_2);
					$tmpPrefixArr=explode("E",$rows_2[initValue]);
					if(strlen($tmpPrefixArr[0])==0 || $tmpPrefixArr[0]!='BB')
						continue;
					$pcrElementArr[$pcrElementNo][prefix]=$tmpPrefixArr[0];
					
					if(!isset($tmpInstanceNo))
					{
						$tmpInstanceNo=$rows[instanceNo];
						$pcrElementArr[$pcrElementNo][prefixNoStr]=$rows[instanceNo];
					}
					else
					{
						$pcrElementArr[$pcrElementNo][prefixNoStr]=$pcrElementArr[$pcrElementNo][prefixNoStr].'.'.$rows[instanceNo];
					}
				}
			}			
			
			//Number of links
			$hexTg = omc_keep_length(dechex($pcrElementArr[$pcrElementNo][tg]),'0',2);
			$tmpObjIdStr='2.4.2';
			$levelWhere = getLevelWhere($tmpObjIdStr);
			$getSql="SELECT initValue FROM OBJ_322.param_99 
						WHERE $levelWhere AND initValue like '$hexTg'
					";
			if($DEBUG)echo "<BR>getSql=$getSql";
			$result	=mysqli_query($pubConn,$getSql);
			echo mysqli_error($pubConn);
			$pcrElementArr[$pcrElementNo][linkNum]=mysqli_num_rows($result);		
			break;
		}
		case '5'://CNF 	多个cnf公用一个linkset，从SubsysNo中区分每个cnf:(sysNo + subSysNo) 0001 0000 -> cnf-0-1; 1000 0000 -> cnf-0-4
		{	
			$cnfElementNo=sizeof($cnfElementArr);	
			$cnfElementArr[$cnfElementNo][infoNo]=$elementsArr[$i][infoNo];
			$cnfElementArr[$cnfElementNo][linkset]=$elementsArr[$i][linkset];
			$cnfElementArr[$cnfElementNo][subSysNo]=$elementsArr[$i][subSysNo];
			$cnfElementArr[$cnfElementNo][sysNo]=$elementsArr[$i][sysNo];
			//$cnfElementArr[$cnfElementNo][name]=$elementsArr[$i][name]."-0-$j";
			$cnfElementArr[$cnfElementNo][name]=$elementsArr[$i][name];
			$cnfElementArr[$cnfElementNo][tg] = $elementsArr[$i][tg];
			if($getState) $cnfElementArr[$cnfElementNo][state] = $elementsArr[$i][state];
			else $cnfElementArr[$cnfElementNo][state] = 'Refreshing';
			$cnfElementArr[$cnfElementNo][prefixNoStr] = $cnfPrefixArr;
			$cnfElementArr[$cnfElementNo][prefix] = $cnfPrefix;
			$cnfElementArr[$cnfElementNo][linkNum] = $cnfLinkNum;
			$cnfElementNo++;
			break;
		}
		case '6'://CNF Center
		{
			$cnfCenterTg = $elementsArr[$i][tg];
			$cnfCenterInfoNo = $elementsArr[$i][infoNo];
			break;
		}
		case '16'://ss7 switch
		{
			$switchElementNo=sizeof($switchElementArr);
			$switchElementArr[$switchElementNo][linkset]=$elementsArr[$i][linkset];
			$switchElementArr[$switchElementNo][ni]=$elementsArr[$i][ni];
			$switchElementArr[$switchElementNo][dpc]=$elementsArr[$i][dpc];
			$switchElementArr[$switchElementNo][sysNo]=$elementsArr[$i][sysNo];
			$switchElementArr[$switchElementNo][name]=$elementsArr[$i][name];
			$switchElementArr[$switchElementNo][tg]=$elementsArr[$i][tg];
			$for_application_tg = $rows[instanceNo];
			$switchElementArr[$switchElementNo][infoNo]=$elementsArr[$i][infoNo];	
			if($getState) $switchElementArr[$switchElementNo][state]=$elementsArr[$i][state];
			else $switchElementArr[$switchElementNo][state]= 'Refreshing';
		
			//$switchElementArr[$switchElementNo][state]=getE1State($switchElementArr[$switchElementNo][tg],$elementsArr[$i][linkset]);
			if($DEBUG) echo "switchElementArr[$switchElementNo][state]$rows[instanceNo],{$elementsArr[$i][linkset]}={$switchElementArr[$switchElementNo][state]}<br>";
		
			$tmpObjIdStr='2.1.3';
			$levelWhere = getLevelWhere($tmpObjIdStr);
			$getSql="SELECT initValue,instanceNo FROM OBJ_322.param_99 
						WHERE $levelWhere and instanceNo<252
					";
			if($DEBUG) 
			echo "<BR>getSql=$getSql";
			$result	=mysqli_query($pubConn,$getSql);
			echo mysqli_error($pubConn);
	
			if(isset($tmpInstanceNo))
				unset($tmpInstanceNo);
			while($rows=mysqli_fetch_array($result))
			{
				//echo "<br>instance=$rows[instanceNo]";
				//echo "<br>initValue=$rows[initValue]";
				$tmpValue=hexdec($rows[initValue]);
				if($tmpValue==$switchElementArr[$switchElementNo][tg])
				{
					$tmpObjIdStr='2.1.1';
					$levelWhere = getLevelWhere($tmpObjIdStr);
					$getSql="SELECT initValue FROM OBJ_322.param_99 
								WHERE $levelWhere AND instanceNo='$rows[instanceNo]'
							";
					if($DEBUG) 
						echo "<BR>getSql=$getSql";
					$result_2	=mysqli_query($pubConn,$getSql);
					echo mysqli_error($pubConn);
					$rows_2=mysqli_fetch_array($result_2);
					$tmpPrefixArr=explode("E",$rows_2[initValue]);
					if(strlen($tmpPrefixArr[0])==0)
						continue;
						
					//$tmpValue=hexdec($tmpValue);
					if(!isset($tmpInstanceNo))
					{
						$tmpInstanceNo=$rows[instanceNo];
						$switchElementArr[$switchElementNo][prefixNoStr]=$rows[instanceNo];
						$switchElementArr[$switchElementNo][prefix]=$tmpPrefixArr[0];
					}
					else
					{
						$switchElementArr[$switchElementNo][prefixNoStr]=$switchElementArr[$switchElementNo][prefixNoStr].'.'.$rows[instanceNo];
					}
				}
			}		
			
			break;
		}
		case '17'://ISDN switch
		{
			$switchElementNo=sizeof($switchElementArr);
			$switchElementArr[$switchElementNo][linkset]=-1;//no linkset
			//$switchElementArr[$switchElementNo][networkIndicator]=-1;
			//$switchElementArr[$switchElementNo][dpc]='-1';
			$switchElementArr[$switchElementNo][sysNo]=$elementsArr[$i][sysNo];
			$switchElementArr[$switchElementNo][name]=$elementsArr[$i][name];
			$switchElementArr[$switchElementNo][tg]=$elementsArr[$i][tg];
			$switchElementArr[$switchElementNo][infoNo]=$elementsArr[$i][infoNo];
			if($getState) $switchElementArr[$switchElementNo][state]=$elementsArr[$i][state];
			else $switchElementArr[$switchElementNo][state]='Refreshing';
			break;
		}
		case '18'://Application
		{
			$tmpEleType = $elementsArr[$i][appType];
			if($tmpEleType==0)//MSC
			{
				$mscEleNo = sizeof($mscElementArr);
				$mscElementArr[$mscEleNo][linkset]=$elementsArr[$i][linkset];
				$mscElementArr[$mscEleNo][name]= $elementsArr[$i][name];
				$mscElementArr[$mscEleNo][tg]=$elementsArr[$i][tg];
				$mscElementArr[$mscEleNo][grpNo]=$elementsArr[$i][appGrp];
				$mscElementArr[$mscEleNo][infoNo]=$elementsArr[$i][infoNo];
				if($getState) $mscElementArr[$mscEleNo][state]=$elementsArr[$i][state];
				else $mscElementArr[$mscEleNo][state]='Refreshing';
			}
			//else if($tmpApplicationType==6)//hlr
			else if($tmpEleType==1)//hlr
			{
				$hlrEleNo = sizeof($hlrElementArr);
				$hlrElementArr[$hlrEleNo][linkset]=$elementsArr[$i][linkset];
				$hlrElementArr[$hlrEleNo][name]= $elementsArr[$i][name];
				$hlrElementArr[$hlrEleNo][tg]=$elementsArr[$i][tg];
				$hlrElementArr[$hlrEleNo][grpNo]=$elementsArr[$i][appGrp];
				$hlrElementArr[$hlrEleNo][infoNo]=$elementsArr[$i][infoNo];
				if($getState) $hlrElementArr[$hlrEleNo][state]=$elementsArr[$i][state];
				else $hlrElementArr[$hlrEleNo][state]='Refreshing';
			}
			else if($tmpEleType==2)//vlr
			{
				$vlrEleNo = sizeof($vlrElementArr);
				$vlrElementArr[$vlrEleNo][linkset]=$elementsArr[$i][linkset];
				$vlrElementArr[$vlrEleNo][name]= $elementsArr[$i][name];
				$vlrElementArr[$vlrEleNo][tg]=$elementsArr[$i][tg];
				$vlrElementArr[$vlrEleNo][grpNo]=$elementsArr[$i][appGrp];
				$vlrElementArr[$vlrEleNo][infoNo]=$elementsArr[$i][infoNo];
				if($getState) $vlrElementArr[$vlrEleNo][state]=$elementsArr[$i][state];
				else $vlrElementArr[$vlrEleNo][state]='Refreshing';
			}
			else if($tmpEleType==3)//mc
			{	
				$mcEleNo = sizeof($mcElementArr);
				$mcElementArr[$mcEleNo][linkset]=$elementsArr[$i][linkset];
				$mcElementArr[$mcEleNo][name]= $elementsArr[$i][name];
				$mcElementArr[$mcEleNo][tg]=$elementsArr[$i][tg];
				$mcElementArr[$mcEleNo][grpNo]=$elementsArr[$i][appGrp];
				$mcElementArr[$mcEleNo][infoNo]=$elementsArr[$i][infoNo];
				if($getState) $mcElementArr[$mcEleNo][state]=$elementsArr[$i][state];
				else $mcElementArr[$mcEleNo][state]='Refreshing';
			}
			else if($tmpEleType==4)//sgsn
			{
				$sgsnEleNo = sizeof($sgsnElementArr);
				$sgsnElementArr[$sgsnEleNo][linkset]=$elementsArr[$i][linkset];
				$sgsnElementArr[$sgsnEleNo][name]= $elementsArr[$i][name];
				$sgsnElementArr[$sgsnEleNo][tg]=$elementsArr[$i][tg];
				$sgsnElementArr[$sgsnEleNo][grpNo]=$elementsArr[$i][appGrp];
				$sgsnElementArr[$sgsnEleNo][infoNo]=$elementsArr[$i][infoNo];
				if($getState) $sgsnElementArr[$sgsnEleNo][state]=$elementsArr[$i][state];
				else $sgsnElementArr[$sgsnEleNo][state]='Refreshing';
			}
			else if($tmpEleType==5)//new element
			{
				$newEleNo = sizeof($newElementArr);
				$newElementArr[$newEleNo][linkset]=$elementsArr[$i][linkset];
				$newElementArr[$newEleNo][name]= $elementsArr[$i][name];
				$newElementArr[$newEleNo][tg]=$elementsArr[$i][tg];
				$newElementArr[$newEleNo][grpNo]=$elementsArr[$i][appGrp];
				$newElementArr[$newEleNo][infoNo]=$elementsArr[$i][infoNo];
				if($getState) $newElementArr[$newEleNo][state]=$elementsArr[$i][state];
				else $newElementArr[$newEleNo][state]= 'Refreshing';
			}
			break;
		}
		default:
			break;
	}

}
?>

<table border="0" height="5%" width="100%" cellpadding="1" cellspacing="0" bordercolor="#666666" bordercolordark="#FFFFFF">
<?php
echo "<tr>";

if(isset($upLoadResult)&&(strlen($upLoadResult)>0)){
		if($upLoadResult=='success')
			echo "<td width=\"80%\"><FONT color=\"#0000FF\">Download Successful</FONT></td>";
		elseif($upLoadResult=='setsuccess')
			echo "<td width=\"80%\"><FONT color=\"#0000FF\">Set All Parameters Successful</FONT></td>";
		elseif($upLoadResult=='getsuccess')
			echo "<td width=\"80%\"><FONT color=\"#0000FF\">Get All Parameters Successful</FONT></td>";			
		else
			echo "<td width=\"80%\"><b><FONT color=\"#FF0000\">Download failed.<br>$upLoadResult</FONT></b></td>";
}else{
	echo "<td width=\"50%\">&nbsp;</td>";
}
echo "<td>&nbsp;</td>";
echo "</tr>";
echo "<tr>";
	echo "<td ><input type=\"button\" id=\"getall\" value=\"Get  All\" class=\"button\" style=\"$buttonStyle\" onClick=\"javascript:BntAction(this)\" >";
	echo "&nbsp;&nbsp;&nbsp;";
	//echo "<input type=\"button\" id=\"setall\" value=\"Set  All\" class=\"button\" style=\"$buttonStyle\" onClick=\"javascript:BntAction(this)\" >";
	echo "</td>";
	echo "<td width=\"50%\" align=\"right\">";
	echo "<a href=\"./addElement.php?setflag=$getflag\" title=\"Add a system.\">Add</a>";
echo "</td>";
echo "</tr>";
?>
</table>

<?php
for($i=0;$i<sizeof($localElementArr);$i++){
	if($DEBUG) 
	echo "<BR>existflag={$localElementArr[$i][existFlag]}";
	if($localElementArr[$i][existFlag]==1)
		break;
}

if($i==sizeof($localElementArr)
	&&sizeof($bssElementArr)==0
	&&sizeof($aasElementArr)==0
	&&sizeof($vssElementArr)==0
	&&sizeof($pcrElementArr)==0
	&&sizeof($cnfElementArr)==0
	&&sizeof($switchElementArr)==0
	&&sizeof($mscElementArr)==0
	&&sizeof($vlrElementArr)==0
	&&sizeof($hlrElementArr)==0
	&&sizeof($mcElementArr)==0
	&&sizeof($sgsnElementArr)==0
	&&sizeof($newElementArr)==0)
{
	echo "<br> No element";
	exit();
}
//rules=rows
?>

<br><table  border="1" width="100%" cellpadding="1" cellspacing="0" bordercolor="#666666" bordercolordark="#FFFFFF">	
<?php

function showStatus($flg,$i,$indexNum)
{
	$eleName = $flg."ElementArr";
	global ${$eleName};
	
	if(${$eleName}[$i][state]=='Refreshing'){
		$color = '#00ff00';
		$cursor="";
	}
	else if(${$eleName}[$i][state]=='Available')
	{
		$color = '#0000ff';
		$cursor="pointer";
	}
	else
	{
		$color = '#ff0000';
		$cursor = 'pointer';
	}
	$id_name = $flg."EleSta_".$indexNum;
	echo "<td><span id=\"$id_name\" style=\"color:$color; cursor:$cursor\" onClick=\"linkTo('$id_name','Available')\" >{${$eleName}[$i][state]}</span></td>";	
}

for($i=0;$i<sizeof($localElementArr);$i++)
{
	if($DEBUG) 
	echo "<BR>existflag={$localElementArr[$i][existFlag]}";
	if($localElementArr[$i][existFlag]==1)
	{

		//MSS
		echo "<tr bgcolor=\"#E6E6E6\">";
		echo "<td width=\"12%\">Local</td>";
		echo "<td width=\"18%\">$strE164Number</td>";		
		echo "<td width=\"22%\">License</td>";
		echo "<td width=\"13%\">Subscriber</td>";
		echo "<td width=\"14%\">Status</td>";
		echo "<td align=\"right\" width=\"10%\">$strDelete</td>";
		echo "</tr>";
		break;
	}
}
unset($needBackupArr);
if(session_is_registered("needBackupArr"))
	session_unregister("needBackupArr");
		
$overBgColor = "#D2F0FF";
$indexNum=0;
for($i=0;$i<sizeof($localElementArr);$i++)
{
	if($DEBUG) 
	echo "<BR>existflag={$localElementArr[$i][existFlag]}";
	if($localElementArr[$i][existFlag]==1)
	{
		$tmpTypNo = $localElementArr[$i][sysTypeNo];
		if($tmpTypNo==320) $tmpTypNo = 322;
		$needBackupArr[] = array('typeNo' => $tmpTypNo,	'name' => $localElementArr[$i][sysTypeName]);
		echo "<tr onMouseOver=\"this.bgColor='$overBgColor'\" onMouseOut=\"this.bgColor='#ffffff'\">";
		//{$localElementArr[$i][confLink]}?license={$localElementArr[$i][license]}&users={$localElementArr[$i][users]}
		echo "<td><a href=\"javascript:linkToSubPage('{$localElementArr[$i][confLink]}?license={$localElementArr[$i][license]}&users={$localElementArr[$i][users]}')\">{$localElementArr[$i][sysTypeName]}</a></td>";
		//echo "<td>{$localElementArr[$i][sysTypeName]}</td>";
		if(strlen($localElementArr[$i][GT])>0)
			echo "<td>{$localElementArr[$i][GT]}</td>";
		else
			echo "<td>--</td>";		
		if($localElementArr[$i][sysTypeNo]==320)
		{
			//============get the E1 license for MSC==============================
			$sel_mes_sql="SELECT detailStat FROM sysStat 
					  WHERE 
					  sysTypeNo='320' 
					 ";
			if($DEBUG)echo "<br>sel_mes_sql=$sel_mes_sql";
			$sel_mes_res=mysqli_query($pubConn,$sel_mes_sql);
			$sel_mes_row=@mysqli_fetch_array($sel_mes_res);
			
			echo mysqli_error($pubConn);
			
			if(!$sel_mes_row)
			{
				$e1_license_msc="--";
			}
			else
			{
				$hex_mes=$sel_mes_row[detailStat];
				$lcn_bgn	=	31; //license user
				//$real_bgn	=	35;	//real user
				$hex_lcn=substr($hex_mes,$lcn_bgn*2,8);
				$lcnNum=HexDec($hex_lcn);
				$e1_license_msc=$lcnNum."(E1)";
			}
			
			
			
			echo "<td>$e1_license_msc</td>";
			echo "<td>--</td>";
		}
		else if($localElementArr[$i][sysTypeNo]==350)
		{
			echo "<td>{$localElementArr[$i][license]}</td>";
			echo "<td>--</td>";
			
		}
		else
		{
			echo "<td>{$localElementArr[$i][license]}</td>";
			echo "<td>{$localElementArr[$i][users]}</td>";
		}
		if($localElementArr[$i][state]>0)
		{
			$value="Normal";
			$color="#0000ff";
			$cursor="pointer";
		}
		else
		{
			$value = "Alarm";
			$color = "#FF0000";
			$cursor='pointer';
		}
		$id_name = "localEleSta_".$indexNum;
		//echo "<td><input type=\"input\" size=\"6\" name=\"$id_name\" value=\"$value\" READONLY style=\"color:$color\" class=\"style9\" onClick=\"linkTo(this,'Normal')\" ></td>";	
		echo "<td><span id=\"$id_name\" style=\"color:$color; cursor:$cursor\" onClick=\"linkTo('$id_name','Normal')\">$value</span></td>";	
		
		echo "<td align=\"right\"><input type=\"checkbox\" name=\"C$indexNum\" value=\"ON\" onClick=\"javascript:delFirm(0,$i,0,0,0,0,this,-1)\" disabled></td>";
		echo "</tr>";
		$indexNum++;
	}
	
}

//To BSS
$indexNum=0;
if(sizeof($bssElementArr)>0)
{
	$bssNeedBackup=1;
	foreach($bssElementArr as $key => $row)
	{
		$name[$key] = $row['name'];
	}
	array_multisort($name, SORT_ASC, $bssElementArr);
	echo "<tr bgcolor=\"#E6E6E6\">";
	if($needBssIp==1){
		echo "<td>MSS-BSS Setting</td>";
		echo "<td>Device Setting</td>";
		echo "<td>NI / DPC</td>";
		echo "<td>BTS Mgr</td>";
	}else{
		echo "<td>BSS Setting</td>";
		echo "<td>NI</td>";
		echo "<td>DPC</td>";
		echo "<td>LAC</td>";
	}
	echo "<td>Status</td>";
	echo "<td align=\"right\">$strDelete</td>";
	echo "</tr>";
}
for($i=0;$i<sizeof($bssElementArr);$i++)
{
	echo "<tr onMouseOver=\"this.bgColor='$overBgColor'\" onMouseOut=\"this.bgColor='#ffffff'\">";
	//echo "<td><a href=\"../toElement/loaddata.php?infoNo={$bssElementArr[$i][infoNo]}&linkset={$bssElementArr[$i][linkset]}&trunkgp={$bssElementArr[$i][tg]}&sysNo={$bssElementArr[$i][sysNo]}&flag=$getflag\">";
	echo "<td><a href=\"javascript:linkToSubPage('../toElement/loaddata.php?infoNo={$bssElementArr[$i][infoNo]}&linkset={$bssElementArr[$i][linkset]}&trunkgp={$bssElementArr[$i][tg]}&sysNo={$bssElementArr[$i][sysNo]}&flag=$getflag')\">";
		
	if(strlen($bssElementArr[$i][name])>0)
		echo "{$bssElementArr[$i][name]}";
	else
		echo "{$bssElementArr[$i][linkset]}";
	echo "</a></td>";
	if($needBssIp==1){
		echo "<td><a href=\"../bssSpecific/bssSpecific.php?bssid={$bssElementArr[$i][sysNo]}&infoNo={$bssElementArr[$i][infoNo]}&linkset={$bssElementArr[$i][linkset]}&trunkgp={$bssElementArr[$i][tg]}&sysNo={$bssElementArr[$i][sysNo]}&flag=$getflag\">BSS</a></td>";
		echo "<td>{$NetIdConfArr[$bssElementArr[$i][ni]]}&nbsp;/&nbsp;{$bssElementArr[$i][dpc]}</td>";
	}else{
		echo "<td>{$NetIdConfArr[$bssElementArr[$i][ni]]}</td>";
		echo "<td>{$bssElementArr[$i][dpc]}</td>";
	}
	if($needBssIp==1)
	{//get numbers of bts.
		$bssDb = "BssOmcDb";
		$tmpBssid = $bssElementArr[$i][sysNo];
		$sqlstring = "select engDisplayName,ObjectId from OMCR_BSSTREE where engDisplayName like 'BTS Manager%' and ObjectId<>'BtsMgr.0' and Presence=1 and bssid=$tmpBssid";
		//echo $sqlstring . "<BR>";
		$result = mysqli_query($pubConn,$sqlstring) or
		          die("Invalid query: $sqlstring\n" . mysqli_error($pubConn));
		while($row = mysqli_fetch_row($result))
		{
			list($bts_display_name[],$bts_object_name[]) =$row;
		}
		$no_of_bts = count($bts_object_name);
		echo "<td>$no_of_bts</td>";
	}//end get bts number.
	else
		echo "<td>{$bssElementArr[$i][lac]}</td>";

	$flg = 'bss';
	showStatus($flg,$i,$indexNum);
	
	if(strlen($bssElementArr[$i][tg])<=0)
		$otherVar_1='-1';
	else
		$otherVar_1=$bssElementArr[$i][tg];
	if(strlen($bssElementArr[$i][btsArr])<=0)
		$otherVar_2='-1';
	else
		$otherVar_2=$bssElementArr[$i][btsArr];
	//echo "<br> otherVar_2=$otherVar_2";	
	echo "<td align=\"right\"><input type=\"checkbox\" name=\"C$indexNum\" value=\"ON\" onClick=\"javascript:delFirm(1,0,{$bssElementArr[$i][sysNo]},{$bssElementArr[$i][linkset]},'$otherVar_1','$otherVar_2',this,{$bssElementArr[$i][infoNo]})\" ></td>";
	$indexNum++;
}

//To Periphreal
{
if(sizeof($aasElementArr)>0
  ||sizeof($vssElementArr)>0
  ||sizeof($pcrElementArr)>0
  ||sizeof($cnfElementArr)>0)
{
	echo "<tr bgcolor=\"#E6E6E6\">";
	echo "<td>Peripheral</td>";
	echo "<td>Device Setting</td>";
	echo "<td>DPC</td>";
	echo "<td>Number of links</td>";
	
	echo "<td>Status</td>";
	echo "<td align=\"right\">$strDelete</td>";
	echo "</tr>";
}
//To AAS
if(sizeof($aasElementArr))
{
	$needBackupArr[] = array('typeNo' => 311,	'name' => 'AAS');
	$indexNum = 0;
	for($i=0;$i<sizeof($aasElementArr);$i++)
	{
		echo "<tr onMouseOver=\"this.bgColor='$overBgColor'\" onMouseOut=\"this.bgColor='#ffffff'\">";
		//../toElement/loaddata.php?infoNo={$aasElementArr[$i][infoNo]}&linkset={$aasElementArr[$i][linkset]}&trunkgp={$aasElementArr[$i][tg]}&sysNo={$aasElementArr[$i][sysNo]}&flag=$getflag
		echo "<td><a href=\"javascript:linkToSubPage('../toElement/loaddata.php?infoNo={$aasElementArr[$i][infoNo]}&linkset={$aasElementArr[$i][linkset]}&trunkgp={$aasElementArr[$i][tg]}&sysNo={$aasElementArr[$i][sysNo]}&flag=$getflag')\">";
		if(strlen($aasElementArr[$i][name])>0)
			echo "{$aasElementArr[$i][name]}";
		else
			echo "{$aasElementArr[$i][linkset]}";
		echo "</a></td>";
		//../toElement/loadaas.php?infoNo={$aasElementArr[$i][infoNo]}&linkset={$aasElementArr[$i][linkset]}&trunkgp={$aasElementArr[$i][tg]}&sysNo={$aasElementArr[$i][sysNo]}&flag=$getflag
		echo "<td><a href=\"javascript:linkToSubPage('../toElement/loadaas.php?infoNo={$aasElementArr[$i][infoNo]}&linkset={$aasElementArr[$i][linkset]}&trunkgp={$aasElementArr[$i][tg]}&sysNo={$aasElementArr[$i][sysNo]}&flag=$getflag')\">AAS</a></td>";	
		
		if(strlen($aasElementArr[$i][prefix])>0)
			echo "<td>{$aasElementArr[$i][prefix]}</td>";
		else
			echo "<td>--</td>";
		
		echo "<td>{$aasElementArr[$i][linkNum]}</td>";
		$flg = 'aas';
		showStatus($flg,$i,$indexNum);
		
		if(strlen($aasElementArr[$i][tg])<=0)
			$otherVar_1='-1';
		else
			$otherVar_1=$aasElementArr[$i][tg];
		if(strlen($aasElementArr[$i][prefixNoStr])<=0)
			$otherVar_2='-1';
		else
			$otherVar_2=$aasElementArr[$i][prefixNoStr];
		echo "<td align=\"right\"><input type=\"checkbox\" name=\"C$indexNum\" value=\"ON\" onClick=\"javascript:delFirm(2,0,{$aasElementArr[$i][sysNo]},{$aasElementArr[$i][linkset]},'$otherVar_1','$otherVar_2',this,{$aasElementArr[$i][infoNo]})\" ></td>";
		$indexNum++;
	}
}
//to VSS
if(sizeof($vssElementArr))
{
	$needBackupArr[] = array('typeNo' => 390,	'name' => 'VSS');
	$indexNum = 0;
	for($i=0;$i<sizeof($vssElementArr);$i++)
	{
		echo "<tr onMouseOver=\"this.bgColor='$overBgColor'\" onMouseOut=\"this.bgColor='#ffffff'\">";
		//../toElement/loaddata.php?infoNo={$vssElementArr[$i][infoNo]}&linkset={$vssElementArr[$i][linkset]}&trunkgp={$vssElementArr[$i][tg]}&sysNo={$vssElementArr[$i][sysNo]}&flag=$getflag
		echo "<td><a href=\"javascript:linkToSubPage('../toElement/loaddata.php?infoNo={$vssElementArr[$i][infoNo]}&linkset={$vssElementArr[$i][linkset]}&trunkgp={$vssElementArr[$i][tg]}&sysNo={$vssElementArr[$i][sysNo]}&flag=$getflag')\">";
		if(strlen($vssElementArr[$i][name])>0)
			echo "{$vssElementArr[$i][name]}";
		else
			echo "{$vssElementArr[$i][linkset]}";
		echo "</a></td>";
		//../toElement/loadvss.php?infoNo={$vssElementArr[$i][infoNo]}&linkset={$vssElementArr[$i][linkset]}&trunkgp={$vssElementArr[$i][tg]}&sysNo={$vssElementArr[$i][sysNo]}&flag=$getflag
		echo "<td><a href=\"javascript:linkToSubPage('../toElement/loadvss.php?infoNo={$vssElementArr[$i][infoNo]}&linkset={$vssElementArr[$i][linkset]}&trunkgp={$vssElementArr[$i][tg]}&sysNo={$vssElementArr[$i][sysNo]}&flag=$getflag')\">VSS</a></td>";	
		
		//======hide the VSS prefix===================
		/*
		if(strlen($vssElementArr[$i][prefix])>0)
			echo "<td>{$vssElementArr[$i][prefix]}</td>";
		else
			echo "<td>--</td>";
		*/
		//===========VSS DPC============
		$tg_tmp=$vssElementArr[$i][tg];
		$database="OBJ_322";
		$sql="select initValue from param_99 where level_1=2 and level_2=1 and level_3=4 and instanceNo=$tg_tmp ";
		$result=@mysqli_query($pubConn,$sql);
		$rows=@mysqli_fetch_array($result);
		$dpc_tmp=hexdec(getBitValue($rows[initValue],'0.0-3.7'))+0;
		echo "<td>$dpc_tmp&nbsp</td>";
		echo "<td>{$vssElementArr[$i][linkNum]}</td>";
		$flg = 'vss';
		showStatus($flg,$i,$indexNum);
		
		if(strlen($vssElementArr[$i][tg])<=0)
			$otherVar_1='-1';
		else
			$otherVar_1=$vssElementArr[$i][tg];
		if(strlen($vssElementArr[$i][prefixNoStr])<=0)
			$otherVar_2='-1';
		else
			$otherVar_2=$vssElementArr[$i][prefixNoStr];
		echo "<td align=\"right\"><input type=\"checkbox\" name=\"C$indexNum\" value=\"ON\" onClick=\"javascript:delFirm(2,1,{$vssElementArr[$i][sysNo]},{$vssElementArr[$i][linkset]},'$otherVar_1','$otherVar_2',this,{$vssElementArr[$i][infoNo]})\" ></td>";
		$indexNum++;
	}
}
//to PCR
if(sizeof($pcrElementArr))
{
	$needBackupArr[] = array('typeNo' => 130,	'name' => 'PCR');
	$indexNum = 0;
	for($i=0;$i<sizeof($pcrElementArr);$i++)
	{
		echo "<tr onMouseOver=\"this.bgColor='$overBgColor'\" onMouseOut=\"this.bgColor='#ffffff'\">";
		//../toElement/loaddata.php?infoNo={$pcrElementArr[$i][infoNo]}&linkset={$pcrElementArr[$i][linkset]}&trunkgp={$pcrElementArr[$i][tg]}&sysNo={$pcrElementArr[$i][sysNo]}&flag=$getflag
		echo "<td><a href=\"javascript:linkToSubPage('../toElement/loaddata.php?infoNo={$pcrElementArr[$i][infoNo]}&linkset={$pcrElementArr[$i][linkset]}&trunkgp={$pcrElementArr[$i][tg]}&sysNo={$pcrElementArr[$i][sysNo]}&flag=$getflag')\">";
		if(strlen($pcrElementArr[$i][name])>0)
			echo "{$pcrElementArr[$i][name]}";
		else
			echo "{$pcrElementArr[$i][linkset]}";
		echo "</a></td>";
		//../toElement/loadpcr.php?infoNo={$pcrElementArr[$i][infoNo]}&linkset={$pcrElementArr[$i][linkset]}&trunkgp={$pcrElementArr[$i][tg]}&sysNo={$pcrElementArr[$i][sysNo]}&flag=$getflag
		echo "<td><a href=\"javascript:linkToSubPage('../toElement/loadpcr.php?infoNo={$pcrElementArr[$i][infoNo]}&linkset={$pcrElementArr[$i][linkset]}&trunkgp={$pcrElementArr[$i][tg]}&sysNo={$pcrElementArr[$i][sysNo]}&flag=$getflag')\">PCR</a></td>";	
		
		
		
		
		//======PCR DPC======
		$tg_tmp=$pcrElementArr[$i][tg];
		$database="OBJ_322";
		$sql="select initValue from param_99 where level_1=2 and level_2=1 and level_3=4 and instanceNo=$tg_tmp ";
		$result=@mysqli_query($pubConn,$sql);
		$rows=@mysqli_fetch_array($result);
		$dpc_tmp=hexdec(getBitValue($rows[initValue],'0.0-3.7'))+0;
		echo "<td>$dpc_tmp&nbsp</td>";
		
		echo "<td>--</td>";
		$flg = 'pcr';
		showStatus($flg,$i,$indexNum);
		
		if(strlen($pcrElementArr[$i][tg])<=0)
			$otherVar_1='-1';
		else
			$otherVar_1=$pcrElementArr[$i][tg];
		if(strlen($pcrElementArr[$i][prefixNoStr])<=0)
			$otherVar_2='-1';
		else
			$otherVar_2=$pcrElementArr[$i][prefixNoStr];
		echo "<td align=\"right\"><input type=\"checkbox\" name=\"C$indexNum\" value=\"ON\" onClick=\"javascript:delFirm(2,2,{$pcrElementArr[$i][sysNo]},{$pcrElementArr[$i][linkset]},'$otherVar_1','$otherVar_2',this,{$pcrElementArr[$i][infoNo]})\" ></td>";
		$indexNum++;
	}
}
//to CNF
if(sizeof($cnfElementArr))
{
	$needBackupArr[] = array('typeNo' => 160,	'name' => 'CNF');
	$indexNum = 0;
	for($i=0;$i<sizeof($cnfElementArr);$i++)
	{
		echo "<tr onMouseOver=\"this.bgColor='$overBgColor'\" onMouseOut=\"this.bgColor='#ffffff'\">";
		//../toElement/loaddata.php?infoNo={$cnfElementArr[$i][infoNo]}&linkset={$cnfElementArr[$i][linkset]}&trunkgp={$cnfElementArr[$i][tg]}&subSysNo={$cnfElementArr[$i][subSysNo]}&flag=$getflag
		echo "<td><a href=\"javascript:linkToSubPage('../toElement/loaddata.php?infoNo={$cnfElementArr[$i][infoNo]}&linkset={$cnfElementArr[$i][linkset]}&trunkgp={$cnfElementArr[$i][tg]}&subSysNo={$cnfElementArr[$i][subSysNo]}&flag=$getflag')\">";
		if(strlen($cnfElementArr[$i][name])>0)
			echo "{$cnfElementArr[$i][name]}";
		else
			echo "{$cnfElementArr[$i][linkset]}";
		echo "</a></td>";
		//../toElement/loadcnf.php?infoNo={$cnfElementArr[$i][infoNo]}&linkset={$cnfElementArr[$i][linkset]}&trunkgp={$cnfElementArr[$i][tg]}&subSysNo={$cnfElementArr[$i][subSysNo]}&flag=$getflag
		echo "<td><a href=\"javascript:linkToSubPage('../toElement/loadcnf.php?infoNo={$cnfElementArr[$i][infoNo]}&linkset={$cnfElementArr[$i][linkset]}&trunkgp={$cnfElementArr[$i][tg]}&subSysNo={$cnfElementArr[$i][subSysNo]}&flag=$getflag')\">CNF</a></td>";	
		
		
		
		//=======CNF DPC============
		$tg_tmp=$cnfElementArr[$i][tg];
		$database="OBJ_322";
		$sql="select initValue from param_99 where level_1=2 and level_2=1 and level_3=4 and instanceNo=$tg_tmp ";
		$result=@mysqli_query($pubConn,$sql);
		$rows=@mysqli_fetch_array($result);
		$dpc_tmp=hexdec(getBitValue($rows[initValue],'0.0-3.7'))+0;
		echo "<td>$dpc_tmp&nbsp</td>";
		
		echo "<td>--</td>";
		$flg = 'cnf';
		showStatus($flg,$i,$indexNum);
	
		if(strlen($cnfElementArr[$i][tg])<=0)
			$otherVar_1='-1';
		else
			$otherVar_1=$cnfElementArr[$i][tg];
		if(strlen($cnfElementArr[$i][prefixNoStr])<=0)
			$otherVar_2='-1';
		else
			$otherVar_2=$cnfElementArr[$i][prefixNoStr];
		if(sizeof($cnfElementArr)==1)//最后一个CNF时，删除相应的TG，以及CNF使用的TG, infoNo。
		{
			$otherVar_1 = $otherVar_1 . '.' . $cnfCenterTg . '.' . $cnfCenterInfoNo;
		}
		else //不是最后一个CNF，$otherVar_1＝－1将不会删除他们使用的TG
			$otherVar_1 = '-1';
		echo "<td align=\"right\"><input type=\"checkbox\" name=\"C$indexNum\" value=\"ON\" onClick=\"javascript:delFirm(2,3,{$cnfElementArr[$i][subSysNo]},{$cnfElementArr[$i][linkset]},'$otherVar_1','$otherVar_2',this,{$cnfElementArr[$i][infoNo]})\" ></td>";
		$indexNum++;
	}
}
}//end Peripheral
//To Switch
if(sizeof($switchElementArr)>0){
	echo "<tr bgcolor=\"#E6E6E6\">";
	echo "<td>Switch</td>";
	echo "<td>Network Indicator</td>";
	echo "<td>DPC</td>";
	echo "<td>Number of E1/T1</td>";
	echo "<td>Status</td>";
	echo "<td align=\"right\">$strDelete</td>";
	echo "</tr>";
}
if(sizeof($switchElementArr)==1)
	$otherTg_Str="-1";
$indexNum=0;
for($i=0;$i<sizeof($switchElementArr);$i++)
{	
	for($j=0; $j<sizeof($switchElementArr); $j++)
	{
		if($j==$i)
			continue;
		$otherTg_Str.="{$switchElementArr[$j][tg]}.";
	}
	$otherTg_Str = rtrim($otherTg_Str,".");

	echo "<tr onMouseOver=\"this.bgColor='$overBgColor'\" onMouseOut=\"this.bgColor='#ffffff'\">";
	//../toElement/loaddata.php?linkset={$switchElementArr[$i][linkset]}&infoNo={$switchElementArr[$i][infoNo]}&trunkgp={$switchElementArr[$i][tg]}&sysNo={$switchElementArr[$i][sysNo]}&flag=$getflag
	echo "<td><a href=\"javascript:linkToSubPage('../toElement/loaddata.php?linkset={$switchElementArr[$i][linkset]}&infoNo={$switchElementArr[$i][infoNo]}&trunkgp={$switchElementArr[$i][tg]}&sysNo={$switchElementArr[$i][sysNo]}&flag=$getflag')\">";
	if(strlen($switchElementArr[$i][name])>0)
		echo "{$switchElementArr[$i][name]}";
	else
		echo "{$switchElementArr[$i][linkset]}";
	echo "</a></td>";
	if($switchElementArr[$i][linkset]==-1)
	{
		for($k=0; $k<2; $k++)
			echo "<td>--</td>";
		//============get the E1 Number of ISDN =================
		$tg_tmp=$switchElementArr[$i][tg]+0;
		$database="OBJ_322";
		$sql="select instanceNo,initValue from param_99 where level_1=2 and level_2=4 and level_3=2 ";
		$result=@mysqli_query($pubConn,$sql);
		$rows=@mysqli_fetch_array($result);
		$e1_count=0;
		
		do{
			$tmp=hexdec(getBitValue($rows[initValue],'0.0-0.7'))+0;
			if($tmp==$tg_tmp)
				$e1_count++;
		}while($rows=mysqli_fetch_array($result));
		echo "<td>$e1_count</td>";
	}
	else
	{
		$tmpni = $switchElementArr[$i][ni];
		
		echo "<td>$NetIdConfArr[$tmpni]</td>";

		$decdpc = ($switchElementArr[$i][dpc]);
		echo "<td>$decdpc</td>";
		//echo "<td>---</td>";
		//======hide the prefix====================
		/*
		if(strlen($switchElementArr[$i][prefix])>0)
			echo "<td>{$switchElementArr[$i][prefix]}</td>";			
		else
			echo "<td>--</td>";
		*/
		//==============show the number of E1================
		
		
		//============get the E1 Number of SS7 =================
		$tg_tmp=$switchElementArr[$i][tg]+0;
		$database="OBJ_322";
		$sql="select instanceNo,initValue from param_99 where level_1=2 and level_2=4 and level_3=2 ";
		$result=@mysqli_query($pubConn,$sql);
		$rows=@mysqli_fetch_array($result);
		$e1_count=0;
		
		do{
			$tmp=hexdec(getBitValue($rows[initValue],'0.0-0.7'))+0;
			if($tmp==$tg_tmp)
				$e1_count++;
		}while($rows=mysqli_fetch_array($result));
		echo "<td>$e1_count</td>";
	}
	$flg = 'switch';
	showStatus($flg,$i,$indexNum);
	
	if(strlen($switchElementArr[$i][tg])<=0)
		$otherVar_1='-1';
	else
		$otherVar_1=$switchElementArr[$i][tg];
	if(strlen($switchElementArr[$i][prefixNoStr])<=0)
		$otherVar_2='-1';
	else
		$otherVar_2=$switchElementArr[$i][prefixNoStr];
	//echo "<br>otherVar_1=$otherVar_1";
	if(strlen($switchElementArr[$i][infoNo])<=0)
		$switchElementArr[$i][infoNo]=-1;
		
	echo "<td align=\"right\"><input type=\"checkbox\" name=\"C$indexNum\" value=\"ON\" onClick=\"javascript:delFirm(3,1,{$switchElementArr[$i][sysNo]},{$switchElementArr[$i][linkset]},'$otherVar_1','$otherTg_Str',this,{$switchElementArr[$i][infoNo]})\" ></td>";
	$indexNum++;
	$otherTg_Str='';
}

//To Application
if(sizeof($mscElementArr)>0||sizeof($hlrElementArr)>0||sizeof($vlrElementArr)>0||sizeof($mcElementArr)>0||sizeof($sgsnElementArr)>0 ||sizeof($newElementArr)>0){
	echo "<tr bgcolor=\"#E6E6E6\">";
	echo "<td>$strGttObjects</td>";
	echo "<td>NI/DPC</td>";
	echo "<td>MSISDN Range</td>";
	echo "<td>IMSI Range</td>";
	echo "<td>Status</td>";
	echo "<td align=\"right\" >$strDelete</td>";
	echo "</tr>";
}
{//Application
	
	
	//=======get the all attribute from gtt table==================
	for($i=0;$i<256;$i++)
	{
		$gtt_number_plan[$i]=-1;
		$gtt_translation_type[$i]=-1;
		$gtt_DPC[$i]="--";
		$gtt_start_gt[$i]=-1;
		$gtt_end_gt[$i]=-1;
		$gtt_title_name[$i]="--";
	}
	$database="OBJ_223";
	$sql="select instanceNo,initValue from param_99 where level_1=2 and level_2=2 ";
	$result=@mysqli_query($pubConn,$sql);
	$rows=@mysqli_fetch_array($result);
	
	do{
			
		
		//==instanceNo
		$tmpInstanceNo=$rows[instanceNo];
		//==number plan
		$gtt_number_plan[$tmpInstanceNo]=hexdec(getBitValue($rows[initValue],'1.0-1.7'))+0;
		//==translation type		
		$gtt_translation_type[$tmpInstanceNo]=hexdec(getBitValue($rows[initValue],'2.0-2.7'))+0;
		//==DPC
		$gtt_DPC[$tmpInstanceNo]=hexdec(getBitValue($rows[initValue],'24.0-26.7'));
		//==start gt
		$temp=getBitValue($rows[initValue],'3.0-12.7');
		$temp=str_replace('F','',$temp);
		if(strlen($temp)==0)
			$gtt_start_gt[$tmpInstanceNo]=-1;
		else	
			$gtt_start_gt[$tmpInstanceNo]=$temp;
		//==end gt
		$temp=getBitValue($rows[initValue],'13.0-22.7');
		$temp=str_replace('F','',$temp);
		if(strlen($temp)==0)
			$gtt_end_gt[$tmpInstanceNo]=-1;
		else	
			$gtt_end_gt[$tmpInstanceNo]=$temp;
		
		
		//if($tmpInstanceNo==15)
		//	alert($gtt_start_gt[$tmpInstanceNo]);
	
	}while($rows=mysqli_fetch_array($result));
	
	
		//================get the GTT title name from GTT application table==================
		$database="OBJ_223";
		$sql="select instanceNo,initValue from param_99 where level_1=2 and level_2=4 ";
		$result=@mysqli_query($pubConn,$sql);
		$rows=@mysqli_fetch_array($result);
		do{
			//==instanceNo
			$tmpInstanceNo=$rows[instanceNo];
			$tmp_title_name=getBitValue($rows[initValue],'3.0-12.7');
			$temp="";
				for($num=0;$num<10;$num++)
				{
					$str=substr($tmp_title_name,$num*2,2);
					$str=hexdec($str);
					$str=chr($str);
					$temp.=$str;
				}
		  $gtt_title_name[$tmpInstanceNo]=trim($temp);
		}while($rows=mysqli_fetch_array($result));
	
	//===================================test==========================================
	/*
	for($i=0;$i<256;$i++)
	{
		echo "<hr>";
		echo "InstanceNo: $i<br>";
		echo "---NP:{$gtt_number_plan[$i]}<br>";
		echo "---TT:{$gtt_translation_type[$i]}<br>";
		echo "---DPC:{$gtt_DPC[$i]}<br>";
		echo "---start_gt:{$gtt_start_gt[$i]}<br>";
		echo "---end_gt:{$gtt_end_gt[$i]}<br>";
		
	}
	*/
	//=================================================================================
	
	
	//======================================msc==========================================
	$indexNum = 0;
	for($i=0; $i<sizeof($mscElementArr); $i++)
	{
		echo "<tr onMouseOver=\"this.bgColor='$overBgColor'\" onMouseOut=\"this.bgColor='#ffffff'\">";
		//../toElement/loaddata.php?infoNo={$mscElementArr[$i][infoNo]}&infoNo={$mscElementArr[$i][infoNo]}&linkset={$mscElementArr[$i][linkset]}&appType=0&gttSSN=8&grpNo={$mscElementArr[$i][grpNo]}&trunkgp={$mscElementArr[$i][tg]}&flag=$getflag
		echo "<td><a href=\"javascript:linkToSubPage('../toElement/loaddata.php?infoNo={$mscElementArr[$i][infoNo]}&infoNo={$mscElementArr[$i][infoNo]}&linkset={$mscElementArr[$i][linkset]}&appType=0&gttSSN=8&grpNo={$mscElementArr[$i][grpNo]}&trunkgp={$mscElementArr[$i][tg]}&flag=$getflag')\">";
		echo $mscElementArr[$i][name];
		echo "</a></td>";
		
	
		//================get the DPC by linkset instanceNo===================
		$linksetInstanceNo=$mscElementArr[$i][linkset];
		$database="OBJ_222";
		$sql="select instanceNo,initValue from param_99 where level_1=2 and level_2=4 and level_3=1 and instanceNo=$linksetInstanceNo";
		$result=@mysqli_query($pubConn,$sql);
		$rows=@mysqli_fetch_array($result);
		//alert($rows[initValue]);
		$DPCtmp=hexdec(getBitValue($rows[initValue],'0.0-2.7'))+0;
		//alert("MSC DPC:".$DPCtmp);
		
		$NItmp=bindec(getBitValue($rows[initValue],'3.0-3.1'))+0;
		//alert("MSC NI:".$NItmp);
		//==========================decide ansi or itu========================================
		switch($NItmp)
		{
			case 0:
				$NIoffset='0.4-0.4';
				break;
			case 1:
				$NIoffset='0.5-0.5';	
				break;
			case 2:
				$NIoffset='0.6-0.6';	
				break;
			case 3:
				$NIoffset='0.7-0.7';	
				break;
		}
		
		//alert("MSC offset:".$NIoffset);
		
	
		$database="OBJ_222";
		$sql="select instanceNo,initValue from param_99 where level_1=2 and level_2=2 ";
		$result=@mysqli_query($pubConn,$sql);
		$rows=@mysqli_fetch_array($result);
		//alert($rows[initValue]);
		$ITU_ANSI=getBitValue($rows[initValue],$NIoffset);
		
		$E164_number="--";
		$MSISDN_Range="--";
		$IMSI_Range="--";	
		
		//==ANSI
		if($ITU_ANSI)
		{
			//===========================E164 number===================================
			for($index=0;$index<256;$index++)
			{
				if($gtt_DPC[$index]==$DPCtmp)
				{
					if($gtt_translation_type[$index]==1)	
					{	
						if($gtt_start_gt[$index]==-1)
							$E164_number="--";
						else	
							$E164_number=$gtt_start_gt[$index];
						break;
					}
				}
			}
			//===========================MSISDN ======================================
			for($index=0;$index<256;$index++)
			{
				if($gtt_DPC[$index]==$DPCtmp)
				{
					
					if($gtt_translation_type[$index]==14)	
					{	
						if($gtt_start_gt[$index]==-1||$gtt_end_gt[$index]==-1)
							$MSISDN_Range="--";
						else	
							$MSISDN_Range=$gtt_start_gt[$index]."-".$gtt_end_gt[$index];
						break;
					}
				}
			}
			//===========================IMSI ======================================
			for($index=0;$index<256;$index++)
			{
				if($gtt_DPC[$index]==$DPCtmp)
				{
					if($gtt_translation_type[$index]==9)	
					{	
						if($gtt_start_gt[$index]==-1||$gtt_end_gt[$index]==-1)
							$IMSI_Range="--";
						else	
							$IMSI_Range=$gtt_start_gt[$index]."-".$gtt_end_gt[$index];
						break;
					}
				}
			}
		}
		//==ITU
		else
		{
			//===========================E164 number===================================
			for($index=0;$index<256;$index++)
			{
				if($gtt_DPC[$index]==$DPCtmp)
				{
					//alert("MSC NP:".$gtt_number_plan[$index]);
					//$gtt_number_plan[$index]=7;
					if($gtt_number_plan[$index]==7)	
					{	
						if($gtt_start_gt[$index]==-1)						
							$E164_number="--";
						else	
							$E164_number=$gtt_start_gt[$index];
						//break;
					}
				}
			}
			//alert("MSC E164 number:".$E164_number);
			//=========================MSISDN=======================================
			for($index=0;$index<256;$index++)
			{
				if($gtt_DPC[$index]==$DPCtmp)
				{
					if($gtt_number_plan[$index]==1)	
					{	
						if($gtt_start_gt[$index]==-1||$gtt_end_gt[$index]==-1)
							$MSISDN_Range="--";
						else	
							$MSISDN_Range=$gtt_start_gt[$index]."-".$gtt_end_gt[$index];
						break;
					}
				}
			}
			//=========================IMSI=======================================
			for($index=0;$index<256;$index++)
			{
				if($gtt_DPC[$index]==$DPCtmp)
				{
					if($gtt_number_plan[$index]==6)	
					{	
						if($gtt_start_gt[$index]==-1||$gtt_end_gt[$index]==-1)
							$IMSI_Range="--";
						else	
							$IMSI_Range=$gtt_start_gt[$index]."-".$gtt_end_gt[$index];
						break;
					}
				}
			}
		}
		
		echo "<td>$E164_number</td>";
		echo "<td>$MSISDN_Range</td>";
		echo "<td>$IMSI_Range</td>";
		
		
		
	//state		
		$flg = 'msc';
		showStatus($flg,$i,$indexNum);
		echo "<td align=\"right\"><input type=\"checkbox\" name=\"C$indexNum\" value=\"ON\" onClick=\"javascript:delFirm(4,0,-1,{$mscElementArr[$i][linkset]},'0',{$mscElementArr[$i][grpNo]},this,{$mscElementArr[$i][infoNo]})\" ></td>";
		$indexNum++;
	}
	//=====================================hlr==========================================
	$indexNum = 0;
	for($i=0;$i<sizeof($hlrElementArr);$i++)
	{
		echo "<tr onMouseOver=\"this.bgColor='$overBgColor'\" onMouseOut=\"this.bgColor='#ffffff'\">";
		//../toElement/loaddata.php?infoNo={$hlrElementArr[$i][infoNo]}&linkset={$hlrElementArr[$i][linkset]}&appType=1&gttSSN=6&grpNo={$hlrElementArr[$i][grpNo]}&trunkgp={$hlrElementArr[$i][tg]}&flag=$getflag
		echo "<td><a href=\"javascript:linkToSubPage('../toElement/loaddata.php?infoNo={$hlrElementArr[$i][infoNo]}&linkset={$hlrElementArr[$i][linkset]}&appType=1&gttSSN=6&grpNo={$hlrElementArr[$i][grpNo]}&trunkgp={$hlrElementArr[$i][tg]}&flag=$getflag')\">";
		echo $hlrElementArr[$i][name];
		echo "</a></td>";
		
	
		//================get the DPC by linkset instanceNo===================
		$linksetInstanceNo=$hlrElementArr[$i][linkset];
		$database="OBJ_222";
		$sql="select instanceNo,initValue from param_99 where level_1=2 and level_2=4 and level_3=1 and instanceNo=$linksetInstanceNo";
		$result=@mysqli_query($pubConn,$sql);
		$rows=@mysqli_fetch_array($result);
		//alert($rows[initValue]);
		$DPCtmp=hexdec(getBitValue($rows[initValue],'0.0-2.7'))+0;
		//alert($DPCtmp);
		$NItmp=bindec(getBitValue($rows[initValue],'3.0-3.1'))+0;
		//alert($NItmp);
		//==========================decide ansi or itu========================================
		switch($NItmp)
		{
			case 0:
				$NIoffset='0.4-0.4';
				break;
			case 1:
				$NIoffset='0.5-0.5';	
				break;
			case 2:
				$NIoffset='0.6-0.6';	
				break;
			case 3:
				$NIoffset='0.7-0.7';	
				break;
		}
		
		//alert($NIoffset);
		
		$database="OBJ_222";
		$sql="select instanceNo,initValue from param_99 where level_1=2 and level_2=2 ";
		$result=@mysqli_query($pubConn,$sql);
		$rows=@mysqli_fetch_array($result);
		//alert($rows[initValue]);
		$ITU_ANSI=getBitValue($rows[initValue],$NIoffset);
		
		$E164_number="--";
		$MSISDN_Range="--";
		$IMSI_Range="--";	
		
		//==ANSI
		if($ITU_ANSI)
		{
			//===========================E164 number===================================
			for($index=0;$index<256;$index++)
			{
				if($gtt_DPC[$index]==$DPCtmp)
				{
					if($gtt_translation_type[$index]==1)	
					{	
						if($gtt_start_gt[$index]==-1)
							$E164_number="--";
						else	
							$E164_number=$gtt_start_gt[$index];
						break;
					}
				}
			}
			//===========================MSISDN ======================================
			for($index=0;$index<256;$index++)
			{
				if($gtt_DPC[$index]==$DPCtmp)
				{
					if($gtt_translation_type[$index]==14)	
					{	
						if($gtt_start_gt[$index]==-1||$gtt_end_gt[$index]==-1)
							$MSISDN_Range="--";
						else	
							$MSISDN_Range=$gtt_start_gt[$index]."-".$gtt_end_gt[$index];
						break;
					}
				}
			}
			//===========================IMSI ======================================
			for($index=0;$index<256;$index++)
			{
				if($gtt_DPC[$index]==$DPCtmp)
				{
					if($gtt_translation_type[$index]==9)	
					{	
						if($gtt_start_gt[$index]==-1||$gtt_end_gt[$index]==-1)
							$IMSI_Range="--";
						else	
							$IMSI_Range=$gtt_start_gt[$index]."-".$gtt_end_gt[$index];
						break;
					}
				}
			}
		}
		//==ITU
		else
		{
			//===========================E164 number===================================
			for($index=0;$index<256;$index++)
			{
				if($gtt_DPC[$index]==$DPCtmp)
				{
					if($gtt_number_plan[$index]==7)	
					{	
						if($gtt_start_gt[$index]==-1)
							$E164_number="--";
						else	
							$E164_number=$gtt_start_gt[$index];
						break;
					}
				}
			}
			//=========================MSISDN=======================================
			for($index=0;$index<256;$index++)
			{
				if($gtt_DPC[$index]==$DPCtmp)
				{
					if($gtt_number_plan[$index]==1)	
					{	
						if($gtt_start_gt[$index]==-1||$gtt_end_gt[$index]==-1)
							$MSISDN_Range="--";
						else	
							$MSISDN_Range=$gtt_start_gt[$index]."-".$gtt_end_gt[$index];
						break;
					}
				}
			}
			//=========================IMSI=======================================
			for($index=0;$index<256;$index++)
			{
				if($gtt_DPC[$index]==$DPCtmp)
				{
					if($gtt_number_plan[$index]==6)	
					{	
						if($gtt_start_gt[$index]==-1||$gtt_end_gt[$index]==-1)
							$IMSI_Range="--";
						else	
							$IMSI_Range=$gtt_start_gt[$index]."-".$gtt_end_gt[$index];
						break;
					}
				}
			}
		}
		
		echo "<td>$E164_number</td>";
		echo "<td>$MSISDN_Range</td>";
		echo "<td>$IMSI_Range</td>";
		
		
		
		
		
	//state		
		$flg = 'hlr';
		showStatus($flg,$i,$indexNum);
		$indexNum++;
		echo "<td align=\"right\"><input type=\"checkbox\" name=\"C$indexNum\" value=\"ON\" onClick=\"javascript:delFirm(4,1,-1,{$hlrElementArr[$i][linkset]},'1',{$hlrElementArr[$i][grpNo]},this,{$hlrElementArr[$i][infoNo]})\" ></td>";
	}
	
	//====================================vlr==========================================
	$indexNum = 0;
	for($i=0;$i<sizeof($vlrElementArr);$i++)
	{
		echo "<tr onMouseOver=\"this.bgColor='$overBgColor'\" onMouseOut=\"this.bgColor='#ffffff'\">";
		//../toElement/loaddata.php?infoNo={$vlrElementArr[$i][infoNo]}&linkset={$vlrElementArr[$i][linkset]}&appType=2&gttSSN=7&grpNo={$vlrElementArr[$i][grpNo]}&trunkgp={$vlrElementArr[$i][tg]}&flag=$getflag
		echo "<td><a href=\"javascript:linkToSubPage('../toElement/loaddata.php?infoNo={$vlrElementArr[$i][infoNo]}&linkset={$vlrElementArr[$i][linkset]}&appType=2&gttSSN=7&grpNo={$vlrElementArr[$i][grpNo]}&trunkgp={$vlrElementArr[$i][tg]}&flag=$getflag')\">";
		echo $vlrElementArr[$i][name];
		echo "</a></td>";
		
		
		//================get the DPC by linkset instanceNo===================
		$linksetInstanceNo=$vlrElementArr[$i][linkset];
		$database="OBJ_222";
		$sql="select instanceNo,initValue from param_99 where level_1=2 and level_2=4 and level_3=1 and instanceNo=$linksetInstanceNo";
		$result=@mysqli_query($pubConn,$sql);
		$rows=@mysqli_fetch_array($result);
		//alert($rows[initValue]);
		$DPCtmp=hexdec(getBitValue($rows[initValue],'0.0-2.7'))+0;
		//alert($DPCtmp);
		$NItmp=bindec(getBitValue($rows[initValue],'3.0-3.1'))+0;
		//alert($NItmp);
		//==========================decide ansi or itu========================================
		switch($NItmp)
		{
			case 0:
				$NIoffset='0.4-0.4';
				break;
			case 1:
				$NIoffset='0.5-0.5';	
				break;
			case 2:
				$NIoffset='0.6-0.6';	
				break;
			case 3:
				$NIoffset='0.7-0.7';	
				break;
		}
		
		//alert($NIoffset);
		
		$database="OBJ_222";
		$sql="select instanceNo,initValue from param_99 where level_1=2 and level_2=2 ";
		$result=@mysqli_query($pubConn,$sql);
		$rows=@mysqli_fetch_array($result);
		//alert($rows[initValue]);
		$ITU_ANSI=getBitValue($rows[initValue],$NIoffset);
		
		$E164_number="--";
		$MSISDN_Range="--";
		$IMSI_Range="--";	
		
		//==ANSI
		if($ITU_ANSI)
		{
			//===========================E164 number===================================
			for($index=0;$index<256;$index++)
			{
				if($gtt_DPC[$index]==$DPCtmp)
				{
					if($gtt_translation_type[$index]==1)	
					{	
						if($gtt_start_gt[$index]==-1)
							$E164_number="--";
						else	
							$E164_number=$gtt_start_gt[$index];
						break;
					}
				}
			}
			//===========================MSISDN ======================================
			for($index=0;$index<256;$index++)
			{
				if($gtt_DPC[$index]==$DPCtmp)
				{
					if($gtt_translation_type[$index]==14)	
					{	
						if($gtt_start_gt[$index]==-1||$gtt_end_gt[$index]==-1)
							$MSISDN_Range="--";
						else	
							$MSISDN_Range=$gtt_start_gt[$index]."-".$gtt_end_gt[$index];
						break;
					}
				}
			}
			//===========================IMSI ======================================
			for($index=0;$index<256;$index++)
			{
				if($gtt_DPC[$index]==$DPCtmp)
				{
					if($gtt_translation_type[$index]==9)	
					{	
						if($gtt_start_gt[$index]==-1||$gtt_end_gt[$index]==-1)
							$IMSI_Range="--";
						else	
							$IMSI_Range=$gtt_start_gt[$index]."-".$gtt_end_gt[$index];
						break;
					}
				}
			}
		}
		//==ITU
		else
		{
			//===========================E164 number===================================
			for($index=0;$index<256;$index++)
			{
				if($gtt_DPC[$index]==$DPCtmp)
				{
					if($gtt_number_plan[$index]==7)	
					{	
						if($gtt_start_gt[$index]==-1)
							$E164_number="--";
						else	
							$E164_number=$gtt_start_gt[$index];
						break;
					}
				}
			}
			//=========================MSISDN=======================================
			for($index=0;$index<256;$index++)
			{
				if($gtt_DPC[$index]==$DPCtmp)
				{
					if($gtt_number_plan[$index]==1)	
					{	
						if($gtt_start_gt[$index]==-1||$gtt_end_gt[$index]==-1)
							$MSISDN_Range="--";
						else	
							$MSISDN_Range=$gtt_start_gt[$index]."-".$gtt_end_gt[$index];
						break;
					}
				}
			}
			//=========================IMSI=======================================
			for($index=0;$index<256;$index++)
			{
				if($gtt_DPC[$index]==$DPCtmp)
				{
					if($gtt_number_plan[$index]==6)	
					{	
						if($gtt_start_gt[$index]==-1||$gtt_end_gt[$index]==-1)
							$IMSI_Range="--";
						else	
							$IMSI_Range=$gtt_start_gt[$index]."-".$gtt_end_gt[$index];
						break;
					}
				}
			}
		}
		
		echo "<td>$E164_number</td>";
		echo "<td>$MSISDN_Range</td>";
		echo "<td>$IMSI_Range</td>";
		
		
		
		
		
	//state		
		$flg = 'vlr';
		showStatus($flg,$i,$indexNum);
		$indexNum++;
		echo "<td align=\"right\"><input type=\"checkbox\" name=\"C$indexNum\" value=\"ON\" onClick=\"javascript:delFirm(4,2,-1,{$vlrElementArr[$i][linkset]},'2',{$vlrElementArr[$i][grpNo]},this,{$vlrElementArr[$i][infoNo]})\" ></td>";
	}
	
	//===================================mc==============================================
	$indexNum = 0;
	for($i=0;$i<sizeof($mcElementArr);$i++)
	{
		echo "<tr onMouseOver=\"this.bgColor='$overBgColor'\" onMouseOut=\"this.bgColor='#ffffff'\">";
		//../toElement/loaddata.php?infoNo={$mcElementArr[$i][infoNo]}&linkset={$mcElementArr[$i][linkset]}&appType=3&gttSSN=11&grpNo={$mcElementArr[$i][grpNo]}&trunkgp={$mcElementArr[$i][tg]}&flag=$getflag
		echo "<td><a href=\"javascript:linkToSubPage('../toElement/loaddata.php?infoNo={$mcElementArr[$i][infoNo]}&linkset={$mcElementArr[$i][linkset]}&appType=3&gttSSN=11&grpNo={$mcElementArr[$i][grpNo]}&trunkgp={$mcElementArr[$i][tg]}&flag=$getflag')\">";
		echo $mcElementArr[$i][name];
		echo "</a></td>";
		
		
		
		//================get the DPC by linkset instanceNo===================
		$linksetInstanceNo=$mcElementArr[$i][linkset];
		$database="OBJ_222";
		$sql="select instanceNo,initValue from param_99 where level_1=2 and level_2=4 and level_3=1 and instanceNo=$linksetInstanceNo";
		$result=@mysqli_query($pubConn,$sql);
		$rows=@mysqli_fetch_array($result);
		//alert($rows[initValue]);
		$DPCtmp=hexdec(getBitValue($rows[initValue],'0.0-2.7'))+0;
		//alert($DPCtmp);
		$NItmp=bindec(getBitValue($rows[initValue],'3.0-3.1'))+0;
		//alert($NItmp);
		//==========================decide ansi or itu========================================
		switch($NItmp)
		{
			case 0:
				$NIoffset='0.4-0.4';
				break;
			case 1:
				$NIoffset='0.5-0.5';	
				break;
			case 2:
				$NIoffset='0.6-0.6';	
				break;
			case 3:
				$NIoffset='0.7-0.7';	
				break;
		}
		
		//alert($NIoffset);
		
		$database="OBJ_222";
		$sql="select instanceNo,initValue from param_99 where level_1=2 and level_2=2 ";
		$result=@mysqli_query($pubConn,$sql);
		$rows=@mysqli_fetch_array($result);
		//alert($rows[initValue]);
		$ITU_ANSI=getBitValue($rows[initValue],$NIoffset);
		
		$E164_number="--";
		$MSISDN_Range="--";
		$IMSI_Range="--";	
		
		//==ANSI
		if($ITU_ANSI)
		{
			//===========================E164 number===================================
			for($index=0;$index<256;$index++)
			{
				if($gtt_DPC[$index]==$DPCtmp)
				{
					if($gtt_translation_type[$index]==1)	
					{	
						if($gtt_start_gt[$index]==-1)
							$E164_number="--";
						else	
							$E164_number=$gtt_start_gt[$index];
						break;
					}
				}
			}
			//===========================MSISDN ======================================
			for($index=0;$index<256;$index++)
			{
				if($gtt_DPC[$index]==$DPCtmp)
				{
					if($gtt_translation_type[$index]==14)	
					{	
						if($gtt_start_gt[$index]==-1||$gtt_end_gt[$index]==-1)
							$MSISDN_Range="--";
						else	
							$MSISDN_Range=$gtt_start_gt[$index]."-".$gtt_end_gt[$index];
						break;
					}
				}
			}
			//===========================IMSI ======================================
			for($index=0;$index<256;$index++)
			{
				if($gtt_DPC[$index]==$DPCtmp)
				{
					if($gtt_translation_type[$index]==9)	
					{	
						if($gtt_start_gt[$index]==-1||$gtt_end_gt[$index]==-1)
							$IMSI_Range="--";
						else	
							$IMSI_Range=$gtt_start_gt[$index]."-".$gtt_end_gt[$index];
						break;
					}
				}
			}
		}
		//==ITU
		else
		{
			//===========================E164 number===================================
			for($index=0;$index<256;$index++)
			{
				if($gtt_DPC[$index]==$DPCtmp)
				{
					if($gtt_number_plan[$index]==7)	
					{	
						if($gtt_start_gt[$index]==-1)
							$E164_number="--";
						else	
							$E164_number=$gtt_start_gt[$index];
						break;
					}
				}
			}
			//=========================MSISDN=======================================
			for($index=0;$index<256;$index++)
			{
				if($gtt_DPC[$index]==$DPCtmp)
				{
					if($gtt_number_plan[$index]==1)	
					{	
						if($gtt_start_gt[$index]==-1||$gtt_end_gt[$index]==-1)
							$MSISDN_Range="--";
						else	
							$MSISDN_Range=$gtt_start_gt[$index]."-".$gtt_end_gt[$index];
						break;
					}
				}
			}
			//=========================IMSI=======================================
			for($index=0;$index<256;$index++)
			{
				if($gtt_DPC[$index]==$DPCtmp)
				{
					if($gtt_number_plan[$index]==6)	
					{	
						if($gtt_start_gt[$index]==-1||$gtt_end_gt[$index]==-1)
							$IMSI_Range="--";
						else	
							$IMSI_Range=$gtt_start_gt[$index]."-".$gtt_end_gt[$index];
						break;
					}
				}
			}
		}
		
		echo "<td>$E164_number</td>";
		echo "<td>$MSISDN_Range</td>";
		echo "<td>$IMSI_Range</td>";
		
		
		
		
	//state		
		$flg = 'mc';
		showStatus($flg,$i,$indexNum);
		$indexNum++;
		echo "<td align=\"right\"><input type=\"checkbox\" name=\"C$indexNum\" value=\"ON\" onClick=\"javascript:delFirm(4,3,-1,{$mcElementArr[$i][linkset]},'3',{$mcElementArr[$i][grpNo]},this,{$mcElementArr[$i][infoNo]})\" ></td>";
	}	
	//===============================sgsn===============================================
	$indexNum = 0;
	for($i=0;$i<sizeof($sgsnElementArr);$i++)
	{
		echo "<tr onMouseOver=\"this.bgColor='$overBgColor'\" onMouseOut=\"this.bgColor='#ffffff'\">";
		//../toElement/loaddata.php?infoNo={$sgsnElementArr[$i][infoNo]}&linkset={$sgsnElementArr[$i][linkset]}&appType=3&gttSSN=11&grpNo={$sgsnElementArr[$i][grpNo]}&trunkgp={$sgsnElementArr[$i][tg]}&flag=$getflag
		echo "<td><a href=\"javascript:linkToSubPage('../toElement/loaddata.php?infoNo={$sgsnElementArr[$i][infoNo]}&linkset={$sgsnElementArr[$i][linkset]}&appType=3&gttSSN=11&grpNo={$sgsnElementArr[$i][grpNo]}&trunkgp={$sgsnElementArr[$i][tg]}&flag=$getflag')\">";
		echo $sgsnElementArr[$i][name];
		echo "</a></td>";
		
	
		//================get the DPC by linkset instanceNo===================
		$linksetInstanceNo=$sgsnElementArr[$i][linkset];
		$database="OBJ_222";
		$sql="select instanceNo,initValue from param_99 where level_1=2 and level_2=4 and level_3=1 and instanceNo=$linksetInstanceNo";
		$result=@mysqli_query($pubConn,$sql);
		$rows=@mysqli_fetch_array($result);
		//alert($rows[initValue]);
		$DPCtmp=hexdec(getBitValue($rows[initValue],'0.0-2.7'))+0;
		//alert($DPCtmp);
		$NItmp=bindec(getBitValue($rows[initValue],'3.0-3.1'))+0;
		//alert($NItmp);
		//==========================decide ansi or itu========================================
		switch($NItmp)
		{
			case 0:
				$NIoffset='0.4-0.4';
				break;
			case 1:
				$NIoffset='0.5-0.5';	
				break;
			case 2:
				$NIoffset='0.6-0.6';	
				break;
			case 3:
				$NIoffset='0.7-0.7';	
				break;
		}
		
		//alert($NIoffset);
		
		$database="OBJ_222";
		$sql="select instanceNo,initValue from param_99 where level_1=2 and level_2=2 ";
		$result=@mysqli_query($pubConn,$sql);
		$rows=@mysqli_fetch_array($result);
		//alert($rows[initValue]);
		$ITU_ANSI=getBitValue($rows[initValue],$NIoffset);
		
		$E164_number="--";
		$MSISDN_Range="--";
		$IMSI_Range="--";	
		
		//==ANSI
		if($ITU_ANSI)
		{
			//===========================E164 number===================================
			for($index=0;$index<256;$index++)
			{
				if($gtt_DPC[$index]==$DPCtmp)
				{
					if($gtt_translation_type[$index]==1)	
					{	
						if($gtt_start_gt[$index]==-1)
							$E164_number="--";
						else	
							$E164_number=$gtt_start_gt[$index];
						break;
					}
				}
			}
			//===========================MSISDN ======================================
			for($index=0;$index<256;$index++)
			{
				if($gtt_DPC[$index]==$DPCtmp)
				{
					if($gtt_translation_type[$index]==14)	
					{	
						if($gtt_start_gt[$index]==-1||$gtt_end_gt[$index]==-1)
							$MSISDN_Range="--";
						else	
							$MSISDN_Range=$gtt_start_gt[$index]."-".$gtt_end_gt[$index];
						break;
					}
				}
			}
			//===========================IMSI ======================================
			for($index=0;$index<256;$index++)
			{
				if($gtt_DPC[$index]==$DPCtmp)
				{
					if($gtt_translation_type[$index]==9)	
					{	
						if($gtt_start_gt[$index]==-1||$gtt_end_gt[$index]==-1)
							$IMSI_Range="--";
						else	
							$IMSI_Range=$gtt_start_gt[$index]."-".$gtt_end_gt[$index];
						break;
					}
				}
			}
		}
		//==ITU
		else
		{
			//===========================E164 number===================================
			for($index=0;$index<256;$index++)
			{
				if($gtt_DPC[$index]==$DPCtmp)
				{
					if($gtt_number_plan[$index]==7)	
					{	
						if($gtt_start_gt[$index]==-1)
							$E164_number="--";
						else	
							$E164_number=$gtt_start_gt[$index];
						break;
					}
				}
			}
			//=========================MSISDN=======================================
			for($index=0;$index<256;$index++)
			{
				if($gtt_DPC[$index]==$DPCtmp)
				{
					if($gtt_number_plan[$index]==1)	
					{	
						if($gtt_start_gt[$index]==-1||$gtt_end_gt[$index]==-1)
							$MSISDN_Range="--";
						else	
							$MSISDN_Range=$gtt_start_gt[$index]."-".$gtt_end_gt[$index];
						break;
					}
				}
			}
			//=========================IMSI=======================================
			for($index=0;$index<256;$index++)
			{
				if($gtt_DPC[$index]==$DPCtmp)
				{
					if($gtt_number_plan[$index]==6)	
					{	
						if($gtt_start_gt[$index]==-1||$gtt_end_gt[$index]==-1)
							$IMSI_Range="--";
						else	
							$IMSI_Range=$gtt_start_gt[$index]."-".$gtt_end_gt[$index];
						break;
					}
				}
			}
		}
		
		echo "<td>$E164_number</td>";
		echo "<td>$MSISDN_Range</td>";
		echo "<td>$IMSI_Range</td>";
		
		
		
		
	//state		
		$flg = 'sgsn';
		showStatus($flg,$i,$indexNum);
		$indexNum++;
		echo "<td align=\"right\"><input type=\"checkbox\" name=\"C$indexNum\" value=\"ON\" onClick=\"javascript:delFirm(4,4,-1,{$sgsnElementArr[$i][linkset]},'4',{$sgsnElementArr[$i][grpNo]},this,{$sgsnElementArr[$i][infoNo]})\" ></td>";
	}	
	//================================new element===========================================
	$indexNum = 0;
	for($i=0;$i<sizeof($newElementArr);$i++)
	{
		echo "<tr onMouseOver=\"this.bgColor='$overBgColor'\" onMouseOut=\"this.bgColor='#ffffff'\">";
		//../toElement/loaddata.php?infoNo={$newElementArr[$i][infoNo]}&linkset={$newElementArr[$i][linkset]}&appType=5&gttSSN=6&grpNo={$newElementArr[$i][grpNo]}&trunkgp={$newElementArr[$i][tg]}&flag=$getflag
		echo "<td><a href=\"javascript:linkToSubPage('../toElement/loaddata.php?infoNo={$newElementArr[$i][infoNo]}&linkset={$newElementArr[$i][linkset]}&appType=5&gttSSN=6&grpNo={$newElementArr[$i][grpNo]}&trunkgp={$newElementArr[$i][tg]}&flag=$getflag')\">";
		echo $newElementArr[$i][name];
		echo "</a></td>";
		
		
		
		
		
		//================get the DPC by linkset instanceNo===================
		$NI_label=array(0=>"International",1=>"International spare",2=>"National",3=>"National spare");
		$linksetInstanceNo=$newElementArr[$i][linkset];
		$database="OBJ_222";
		$sql="select instanceNo,initValue from param_99 where level_1=2 and level_2=4 and level_3=1 and instanceNo=$linksetInstanceNo";
		$result=@mysqli_query($pubConn,$sql);
		$rows=@mysqli_fetch_array($result);
		//alert($rows[initValue]);
		$DPCtmp=hexdec(getBitValue($rows[initValue],'0.0-2.7'))+0;
		//alert($DPCtmp);
		$NItmp=bindec(getBitValue($rows[initValue],'3.0-3.1'))+0;
		//alert($NItmp);
		//==========================decide ansi or itu========================================
		switch($NItmp)
		{
			case 0:
				$NIoffset='0.4-0.4';
				break;
			case 1:
				$NIoffset='0.5-0.5';	
				break;
			case 2:
				$NIoffset='0.6-0.6';	
				break;
			case 3:
				$NIoffset='0.7-0.7';	
				break;
		}
		
		//alert($NIoffset);
		

		$database="OBJ_222";
		$sql="select instanceNo,initValue from param_99 where level_1=2 and level_2=2 ";
		$result=@mysqli_query($pubConn,$sql);
		$rows=@mysqli_fetch_array($result);
		//alert($rows[initValue]);
		$ITU_ANSI=getBitValue($rows[initValue],$NIoffset);
		
		$E164_number="--";
		$MSISDN_Range="--";
		$IMSI_Range="--";	
		
		//==ANSI
		if($ITU_ANSI)
		{
			//===========================E164 number===================================
			for($index=0;$index<256;$index++)
			{
				//if($gtt_DPC[$index]==$DPCtmp)
				if(strcmp($gtt_title_name[$index],$newElementArr[$i][name])==0)
				{
					if($gtt_translation_type[$index]==1)	
					{	
						if($gtt_start_gt[$index]==-1)
							$E164_number="--";
						else	
							$E164_number=$gtt_start_gt[$index];
						break;
					}
				}
			}
			//===========================MSISDN ======================================
			for($index=0;$index<256;$index++)
			{
				//if($gtt_DPC[$index]==$DPCtmp)
				if(strcmp($gtt_title_name[$index],$newElementArr[$i][name])==0)
				{
					if($gtt_translation_type[$index]==14)	
					{	
						if($gtt_start_gt[$index]==-1||$gtt_end_gt[$index]==-1)
							$MSISDN_Range="--";
						else	
							$MSISDN_Range=$gtt_start_gt[$index]."-".$gtt_end_gt[$index];
						break;
					}
				}
			}
			//===========================IMSI ======================================
			for($index=0;$index<256;$index++)
			{
				//if($gtt_DPC[$index]==$DPCtmp)
				if(strcmp($gtt_title_name[$index],$newElementArr[$i][name])==0)
				{
					if($gtt_translation_type[$index]==9)	
					{	
						if($gtt_start_gt[$index]==-1||$gtt_end_gt[$index]==-1)
							$IMSI_Range="--";
						else	
							$IMSI_Range=$gtt_start_gt[$index]."-".$gtt_end_gt[$index];
						break;
					}
				}
			}
		}
		//==ITU
		else
		{
			//===========================E164 number===================================
			for($index=0;$index<256;$index++)
			{
				//if($gtt_DPC[$index]==$DPCtmp)
				if(strcmp($gtt_title_name[$index],$newElementArr[$i][name])==0)
				{
					if($gtt_number_plan[$index]==7)	
					{	
						if($gtt_start_gt[$index]==-1)
							$E164_number="--";
						else	
							$E164_number=$gtt_start_gt[$index];
						break;
					}
				}
			}
			//=========================MSISDN=======================================
			for($index=0;$index<256;$index++)
			{
				//if($gtt_DPC[$index]==$DPCtmp)
				if(strcmp($gtt_title_name[$index],$newElementArr[$i][name])==0)
				{
					if($gtt_number_plan[$index]==1)	
					{	
						if($gtt_start_gt[$index]==-1||$gtt_end_gt[$index]==-1)
							$MSISDN_Range="--";
						else	
							$MSISDN_Range=$gtt_start_gt[$index]."-".$gtt_end_gt[$index];
						break;
					}
				}
			}
			//=========================IMSI=======================================
			for($index=0;$index<256;$index++)
			{
				//if($gtt_DPC[$index]==$DPCtmp)
				if(strcmp($gtt_title_name[$index],$newElementArr[$i][name])==0)
				{
					if($gtt_number_plan[$index]==6)	
					{	
						if($gtt_start_gt[$index]==-1||$gtt_end_gt[$index]==-1)
							$IMSI_Range="--";
						else	
							$IMSI_Range=$gtt_start_gt[$index]."-".$gtt_end_gt[$index];
						break;
					}
				}
			}
		}
		
		echo "<td>{$NI_label[$NItmp]}/$DPCtmp</td>";
		echo "<td>$MSISDN_Range</td>";
		echo "<td>$IMSI_Range</td>";
	//state		
		$flg = 'new';
		showStatus($flg,$i,$indexNum);
		$indexNum++;
		echo "<td align=\"right\"><input type=\"checkbox\" name=\"C$indexNum\" value=\"ON\" onClick=\"javascript:delFirm(4,5,-1,{$newElementArr[$i][linkset]},'5',{$newElementArr[$i][grpNo]},this,{$newElementArr[$i][infoNo]})\" ></td>";
	}
}//end application

session_register("needBackupArr");
?>
</table>

<?php

function alert($msg)
{
	echo "<script language=\"JavaScript\">\n";
	echo "alert('$msg');\n";
	echo "</script>";
}

function getusedCount($oid,$sysId,$otherWhereStr='')
{
	$db = "OMC_PUB";
	$tmpArr = explode('_',$sysId);
	$table = "OBJ_".$tmpArr[0].".param_".$tmpArr[1];
	$confTable = "OBJ_".$tmpArr[0].".paramConf";
	$levelWhere = getLevelWhere($oid);
	$defSql = "select initValue from $confTable where $levelWhere";
	$defResult = mysqli_query($pubConn, $defSql);
	$defRow = mysqli_fetch_array($defResult);
	$defValue = $defRow[initValue];
	//echo "<br>defSql:$defSql";
	$slcSql = "select count(*) as usedNum from $table where $levelWhere and initValue!='$defValue' $otherWhereStr";
	$result = mysqli_query($pubConn,$slcSql);
	$row = mysqli_fetch_array($result);
	//echo "<br>slcSql:$slcSql";
	return $row[0];
}
function outputUsedNum($usedNum)
{
	if($usedNum>0)
		$showStr = "[&nbsp;$usedNum&nbsp;]";
	echo "<td width=\"15%\" align=\"left\"><font color=\"Silver\">$showStr</font></a>";
}
for($i=1; $i<=4; $i++) {
	$oidStr = '2.6.'.$i;
	$spcUsed += getusedCount($oidStr, '222_99_99');
}
$lsUsed = getusedCount('2.4.1','222_99_99');
$lkUsed = getusedCount('2.5.1','222_99_99');
$gttUsed = getusedCount('2.2.0','223_99_99');
$prefixUsed = getusedCount('2.1.2','322_99_99');
$tgUsed = getusedCount('2.1.4','322_99_99');
$e1Used = getusedcount('2.4.4','322_99_99');
$cellUsed = getusedCount('2.2.7','322_99_99','and instanceNo!=1023');
$Prefix_Manipulation_used=getusedCount('2.8','225_99_99');
$xapp_used=getusedCount('2.11','225_99_99');
echo "<br><br>";
echo "<font color=\"gray\"><b>Utilization Summary</b>&nbsp;[Active]</font>";
echo "<table rules=rows border=\"1\" width=\"100%\" cellpadding=\"1\" cellspacing=\"0\" bordercolor=\"#666666\" bordercolordark=\"#FFFFFF\">";	
echo "<tr>";
	echo "<td width=\"10%\"><a href='../../element/mss/spc_overview.php?getFlag=$getflag'>SPC</a></td>";
	outputUsedNum($spcUsed);
	echo "<td width=\"10%\"><a href='../../element/mss/linkset_overview.php?getFlag=$getflag'>Linkset</a></td>";
	outputUsedNum($lsUsed);
	echo "<td width=\"10%\"><a href='../../element/mss/link_overview.php?getFlag=$getflag'>Link</a></td>";
	outputUsedNum($lkUsed);
	echo "<td width=\"10%\"><a href='../../element/mss/gtt_overview.php?getFlag=$getflag'>GTT</a></td>";
	outputUsedNum($gttUsed);
	echo "<td width=\"10%\"><a href='../../element/mss/localNode_overview.php?getFlag=$getflag'><nobr>Local Node</nobr></a></td>";
	echo "<td width=\"15%\">&nbsp;</td>";
echo "</tr>";
echo "<tr>";
	echo "<td width=\"10%\"><a href='../../element/mss/e1_overview.php?getFlag=$getflag'>E1</a></td>";
	outputUsedNum($e1Used);
	echo "<td width=\"10%\"><a href='../../element/mss/prefix_overview.php?getFlag=$getflag''>Prefix</a></td>";
	outputUsedNum($prefixUsed);
	echo "<td width=\"10%\"><a href='../../element/mss/tg_overview.php?getFlag=$getflag'>TG</a></td>";
	outputUsedNum($tgUsed);
	echo "<td width=\"10%\"><a href='../../element/mss/msc_emergency_call.php?getFlag=$getflag'>CELL</a></td>";
	outputUsedNum($cellUsed);
	echo "<td width=\"10%\"><a href='../../element/mss/convert_overview.php'>Convert</a></td>";
	//outputUsedNum($Prefix_Manipulation_used);
	echo "<td width=\"15%\">&nbsp;</td>";
echo "</tr>";


echo "<tr>";
	echo "<td colspan=1 width=\"10%\"><a href='../../element/mss/xapp_overview.php'>Element</a></td>";
	outputUsedNum($xapp_used);
	echo "<td colspan=2 width=\"10%\">&nbsp;</td>";

	echo "<td colspan=2 width=\"10%\">&nbsp;</td>";

	echo "<td colspan=2 width=\"10%\">&nbsp;</td>";

	echo "<td colspan=1 width=\"10%\">&nbsp;</td>";
	

	echo "<td width=\"15%\">&nbsp;</td>";
echo "</tr>";


echo "</table>";
echo "<br><br>";
$btnbackupStyleStr = '';
if($backupShow)
	$btnbackupStyleStr = ";background:yellow";
$btnrestoreStyleStr = '';
if($restoreShow)
	$btnrestoreStyleStr = ";background:yellow";
//title=\"Backup all the system's parameters and subscribers(5000 Items)\"
//title=\"Restore all the system's parameters and subscribers(5000 Items)\"
echo "<span id=\"btnbackup\"  style=\"cursor:pointer $btnbackupStyleStr\" onclick=\"javascript:showId(this);\"><font color=\"gray\" onMouseOver=\"document.all.backup_div.style.display='block';\" onMouseOut=\"document.all.backup_div.style.display='none';\"><b>Backup</b></font></span>&nbsp;&&nbsp;";
echo "<span id=\"btnrestore\"  style=\"cursor:pointer $btnrestoreStyleStr\" onclick=\"javascript:showId(this);\"><font color=\"gray\" onMouseOver=\"document.all.restore_div.style.display='block';\" onMouseOut=\"document.all.restore_div.style.display='none';\"><b>Restore</b></font></span>";
//=============backup and restore remark=====================
$backup_remark="";//Backup lets operator back up System Parameters and Subscriber Data from application servers to a tgz file. Select the check box for the contents that want to back up. Click “Create tgz File” to start the backup operation: EMS downloads data from application servers and compresses it to a tgz package. Click “Download tgz File” to download the latest backed up file to client PC.";
$restore_remark="";//Restore lets operator recover the System Parameters and Subscriber Data to a previous state. It also can be used to configure a new application server in a very quick way. Click the Browse button to locate the folder and previous backed up file. Click the Upload button to start the restore operation. Please be caution that the Restore will erase the System Parameter and Subscriber Data that is currently on the application servers and replace with the restoring data.";

echo "<p>";
echo "<div id=\"backup_div\" style=\"display:none;color:#989898\">$backup_remark</div>";
echo "<div id=\"restore_div\" style=\"display:none;color:#989898\">$restore_remark</div>";
echo "<br><br>";
function getFileList($dir,&$fileListArr)
{
	if ($handle = opendir($dir)) {
	    while (false !== ($file = readdir($handle))) {
	        if ($file != "." && $file != "..") {
	            $fileListArr[] = $file;
	        }
	    }
	    closedir($handle);
	}
}

if($backupShow)
	echo "<div id=\"backup\" style=\"\">";
else
	echo "<div id=\"backup\" style=\"display:none\">";
	echo "<br>";
	$serverip =  getenv("HTTP_HOST"); 
	if( $serverip == "" ){ 
		$serverip = getenv("SERVER_ADDR"); 
	}
	$downLinkStr = '';
	$downFilePath = "/usr/local/apache/htdocs/db_backup/archive/tgzFile/";
	unset($fileListArr);
	if(is_dir($downFilePath))
		getFileList($downFilePath,$fileListArr);
	if (sizeof($fileListArr)>0)
	{
		$fileName=$fileListArr[0];
		$filePathName = $downFilePath.$fileName;
	    $lastModifiedTime = date("Y-m-d  H:i:s", filemtime($filePathName));
	    $downurl = "http://$serverip/db_backup/archive/tgzFile/".$fileName;
		$downLinkStr = "<a href=\"$downurl\"><b>Download tgz File</b></a><font color=\"blue\"> [$lastModifiedTime]</font>";
	}
	echo "<table rules=rows border=\"1\" width=\"60%\" cellpadding=\"1\" cellspacing=\"0\" bordercolor=\"#666666\" bordercolordark=\"#FFFFFF\">";	
	echo "<tr>";
		echo "<td>Select items to backup</td>";
		echo "<td>";
		echo "<input type=\"checkbox\" id=\"chkboxParam\" >Parameters&nbsp;&nbsp;";
	
		
		if($needBssIp==1)
			echo "<input type=\"checkbox\" id=\"chkboxSubs\" >Subscribers&nbsp;&nbsp;";
		
		if($bssNeedBackup==1 && $needBssIp==1) {
			$bssDisplay='';
			$bssShow="BSS";
		} else {
			$bssDisplay='none';
			$bssShow="";
		}
		echo "<input type=\"checkbox\" id=\"chkboxBSS\" style=\"display:$bssDisplay\">$bssShow";
		echo "</td>";
	echo "</tr>";
	echo "<tr>";
	
	if($needBssIp!=1)
	{
		$need_bss_ip=0;
	}
	else
	{
		$need_bss_ip=1;
	}
	
	echo "<td align=\"left\" title=\"update all database and create an new .tag file\" id=\"$id\" style=\"cursor:pointer\" onclick=\"javascript:doDownLoad('$need_bss_ip');\"><font color=\"blue\"><b>Create Tgz File</b></font>";
	echo "<td>$downLinkStr</td>";
	echo "</tr>";
	echo "</table>";
echo "</div>";
if($restoreShow)
	echo "<div id=\"restore\" style=\"\">";
else
	echo "<div id=\"restore\" style=\"display:none\">";
	?>
	<form method ="POST" action="<?php echo"uploadFile.php";?>"  enctype="multipart/form-data">
	
	<b>File</b>(.tgz)<b> to Restore</b>:
	<input type="file" name="inputFile">
	<input type="hidden" name="MAX_FILE_SIZE" value="20971520"><!-- MAX_FILE_SIZE = 20M -->
	<input type="submit" value="Upload">
	</form> 
<?php
echo "</div>";
?>
</body>
</html>
	
<script LANGUAGE="JavaScript">
function delFirm(systemNo,elementNo,sysNo,linkset,otherVar_1,otherVar_2,delcheckbox,infoNo)
{
	//alert(elementNo);
	var x,y;
	x = document.body.scrollLeft;
	y = document.body.scrollTop;

	if(confirm('Do you want to delete the selected?')!=true)
	{
		delcheckbox.checked=false;
	}
	else
	{
		window.location.href='<?php echo "./delElement.php";?>'+"?scroll_x="+x+"&scroll_y="+y+"&systemNo="+systemNo+"&elementNo="+elementNo+"&sysNo="+sysNo+"&linkset="+linkset+"&otherVar_1="+otherVar_1+"&otherVar_2="+otherVar_2+"&infoNo="+infoNo;
	}
}

function BntAction(item){
	var action;
	var pageaction;
	pageaction = item.id;
	action = item.value;
	if(confirm("Do you want to "+action+" Parameters")==true){
		URL="../../element/overview/upLoadingElements.php?pageaction="+pageaction;	
		window.location.href=URL;
	}
}
function doDownLoad(needBssIp)
{
	needGetParam=needGetSubs=needBss=0;
	if(document.getElementById('chkboxParam').checked==true)
		needGetParam=1;
	
	if(needBssIp==1)
	{
				
		if(document.getElementById('chkboxSubs').checked==true)
			needGetSubs=1;
		if(document.getElementById('chkboxBss').checked==true)
			needBss=1;
	}
	if(!(needGetParam||needGetSubs||needBss))
		alert("Select the items need to backup, Please!")
	else
		if(confirm("Are you sure to backup now?"))
			window.location="downloadFile.php?needGetParam="+needGetParam+"&needGetSubs="+needGetSubs+"&needBss="+needBss;
		else
			return;
}
function showId(item)
{
	//alert(thisId);
	var otherbtnId;
	var thisId,otherId;
	if(item.id=='btnbackup'){
		thisId = 'backup';
		otherId = 'restore';
		otherbtnId = 'btnrestore';
	} else {
		thisId = 'restore';
		otherId = 'backup';
		otherbtnId = 'btnbackup';
	}
	document.getElementById(otherbtnId).style.background='';
	if(document.getElementById(thisId).style.display==""){
		document.getElementById(thisId).style.display="none";
		item.style.background='';
	} else {
		item.style.background='yellow';
		document.getElementById(thisId).style.display="";
	}
	document.getElementById(otherId).style.display="none";
	self.scrollBy(0,1000);
}
</script>
