<?php
//---本文件是omc Configuration 用到的一些函数
require("../../inc/header.inc");

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

$nGetComm = 0;
$nSetComm = 3;
	
$maxNum = 100; 

$pubDb		 = 'OMC_PUB';

//****************************************************************
//	update_e1
//函数说明:
//	该函数用于设置E1 link参数前先Disable E1link,然后再Enable E1 link
//	
//	
//参数:
//	需要与E1 link	相关的linset,sys_id,selectsysid
//
//修改注释：      
//NO.1      
//姓名：            
//时间：      
//修改说明：    
//----------------------------------------------------------
function update_e1($linkset,$sys_id,$selectsysid=-1){
	global $pubDb,$nSetComm;
	$DEBUG = 0;
	
	$sysIdArr	= explode('_',$sys_id);
	$sysTypeNo	= $sysIdArr[0];
	$sysNo		= $sysIdArr[1];
	$subSysNo	= $sysIdArr[2];

	$objDb		= 'OBJ_'.$sysTypeNo;
	$paramTable = 'param_'.$sysNo;
		
	$oid = '2.5.1';
	$objWhereStr = getLevelWhere($oid);
	
	$paramSql = " SELECT initValue,instanceNo FROM $paramTable where $objWhereStr and initValue !=readValue ORDER BY instanceNo";
	$Result = mysqli_query($pubConn,$paramSql);
	$count=0;
	while($Row = mysqli_fetch_array($Result)){
		$flag					= getBitValue($Row[initValue],'06.5-06.5');
		$E1linkset		= hexdec(getBitValue($Row[initValue],'00.0-00.7'));
//		if($flag && $E1linkset == $linkset){
		if($flag){
			$setsql_back[$count] = "update $paramTable set initValue = '$Row[initValue]' where $objWhereStr and instanceNo = '$Row[instanceNo]'";
			$count++;
			$initValue = setBitValue($Row[initValue],'06.5-06.5',0);			
			$setsql = "update $paramTable set initValue = '$initValue' where $objWhereStr and instanceNo = '$Row[instanceNo]'";
			mysqli_query($pubConn,$setsql);
			echo mysqli_error($pubConn);
			if($DEBUG) echo "$setsql<br>";						
		}
	}
	if($DEBUG) echo "sysCommSend($sys_id,$nSetComm,$oid,$selectsysid)<br>";
	$commIdStr	= oidSysCommSend($sys_id,$nSetComm,$oid,$selectsysid);
	
	CheckState($commIdStr);

	for($i=0; $i < $count; $i++)
	{		
		mysqli_query($pubConn,$setsql_back[$i]);
		echo mysqli_error($pubConn);
		if($DEBUG) echo "$setsql_back[$i]<br>";
	}	
}

//****************************************************************
//	update_sg
//函数说明:
//	该函数用于设置SG参数前先Disable SG,然后再Enable SG
//	
//参数:
//	需要sys_id,selectsysid
//
//修改注释：      
//NO.1      
//姓名：            
//时间：      
//修改说明：    
//----------------------------------------------------------
function update_sg($sys_id,$selectsysid=-1){
	global $pubDb,$nSetComm;
	$DEBUG = 0;
	$sysIdArr	= explode('_',$sys_id);
	$sysTypeNo	= $sysIdArr[0];
	$sysNo		= $sysIdArr[1];
	$subSysNo	= $sysIdArr[2];

	$objDb		= 'OBJ_'.$sysTypeNo;
	$paramTable = 'param_'.$sysNo;
				
	$oid = '2.9';
	$objWhereStr = getLevelWhere($oid);
	
	$getsql = "SELECT initValue,instanceNo FROM $paramTable where $objWhereStr and initValue LIKE '01%' and initValue !=readValue ";
	$result = @mysqli_query($pubConn,$getsql);
	
	$count=0;
	while($sg_attr = mysqli_fetch_array($result))
	{
		$setsql_back[$count] = "update $paramTable set initValue = '$sg_attr[initValue]' where $objWhereStr and instanceNo = '$sg_attr[instanceNo]'";					
		$count++;		
		$sg_attr[initValue] = setBitValue($sg_attr[initValue],'00.0-00.7','00');
		$setsql = "update $paramTable set initValue = '$sg_attr[initValue]' where $objWhereStr and instanceNo = '$sg_attr[instanceNo]'";					
		mysqli_query($pubConn,$setsql);
		echo mysqli_error($pubConn);
		if($DEBUG) echo "$setsql<br>";
	}
	
	
	if($DEBUG) echo "sysCommSend($sys_id,$nSetComm,$oid,$selectsysid)<br>";
	$commIdStr	= oidSysCommSend($sys_id,$nSetComm,$oid,$selectsysid);
	
	CheckState($commIdStr);	
	
	for($i=0; $i < $count; $i++)
	{		
		mysqli_query($pubConn,$setsql_back[$i]);
		echo mysqli_error($pubConn);
		if($DEBUG) echo "$setsql_back[$i]<br>";
	}	
}

//****************************************************************
//	CheckState
//函数说明:
//	该函数用于监测发送get/set命令后，response的状态
//	
//参数:
//	
//
//修改注释：      
//NO.1      
//姓名：            
//时间：      
//修改说明：    
//----------------------------------------------------------
function CheckState($cmmIdStr,$errRetFlag=0,$outFlag=1){
	global $omc_db;
	global $maxNum,$remark,$nProcFail,$nWaitProc,$nInProc,$nOutProc;
	
	$cmmIdStrArr=explode("-",$cmmIdStr);
	$tmpWhere = '(1';
	for($i=0;$i<sizeof($cmmIdStrArr)-1;$i++){
		if($i==0)
			$tmpWhere="(commId='$cmmIdStrArr[$i]'";
		else
			$tmpWhere=$tmpWhere." OR commId='$cmmIdStrArr[$i]'";
	}
	$tmpWhere=$tmpWhere.")";	
	
				
	$i = 0;
	$commTable = "parameterComm";
	while(1){
		if($i > 180){
			$tmpRemark='Timeout';			
			$delComm = " DELETE FROM $commTable WHERE $tmpWhere ";
			mysqli_query($pubConn,$delComm);						
			outPutChkMsg($tmpsysTypeNo,$tmpsysNo,'0033',$errRetFlag);
			break;
		}
		if($outFlag)
		{
			echo "<img border=\"0\" src=\"../../images/arrow.gif\" width=\"10\" height=\"10\">";
			flush();	
		}
		
		$selComm = "SELECT commState,remark,objId,sysTypeNo,sysNo,subSysNo FROM $commTable WHERE $tmpWhere AND commState='$nProcFail'";
		if($DEBUG) echo "<br>selComm=$selComm";
		
		$selRes  = mysqli_query($pubConn,$selComm);
		
		if(mysqli_num_rows($selRes)>0){
			$selRow  = mysqli_fetch_array($selRes);
			$tmpRemark=$selRow[remark];
			$tmpoidId=$selRow[objId];
			$tmpsysTypeNo=$selRow[sysTypeNo];
			$tmpsysNo=$selRow[sysNo];
			$delComm = " DELETE FROM $commTable WHERE $tmpWhere ";	
			mysqli_query($pubConn,$delComm);
			$tmpRemarkArr=explode(":",$tmpRemark);
			outPutChkMsg($tmpsysTypeNo,$tmpsysNo,$tmpRemarkArr[0],$errRetFlag);							
		}		
		
		$selComm = "SELECT commState,remark FROM $commTable WHERE $tmpWhere AND (commState='$nWaitProc' OR commState='$nInProc')";
	
		if($DEBUG)echo "<br>selComm=$selComm";
		
		$selRes  = mysqli_query($pubConn,$selComm);
		if($DEBUG) $tmpNum=mysqli_num_rows($selRes);
		if($DEBUG) echo "<br>tmpNum=$tmpNum";
		
		if(mysqli_num_rows($selRes)>0){
			sleep(1);
			$i++;
			continue;
		}
		$delComm = " DELETE FROM $commTable WHERE $tmpWhere ";	
		mysqli_query($pubConn,$delComm);	
		break;
	}
}

//****************************************************************
//	ChDbMov
//函数说明:
//	该函数用于把readValue copy到  initValue
//	
//参数:
//	$sysId,$oidstr
//
//修改注释：      
//NO.1      
//姓名：            
//时间：      
//修改说明：    
//----------------------------------------------------------
function ChDbMov($sysId,$oidstr){
	$sysIdArr	= explode('_',$sysId);
	$sysTypeNo	= $sysIdArr[0];
	$sysNo		= $sysIdArr[1];
	$subSysNo	= $sysIdArr[2];
	
	$levelArr=explode('.',$oidstr);
	$objWhereStr= '';
	$objWhereStr =getLevelWhere($oidstr);
	
	$objDb		= 'OBJ_'.$sysTypeNo;
	$paramTable = 'param_'.$sysNo;
	
	$selSql ="SELECT distinct readValue FROM $paramTable 
				WHERE $objWhereStr
				ORDER BY readValue";

	$selRes	= @mysqli_query($pubConn,$selSql);
	$selRow = mysqli_fetch_array($selRes);	
	echo mysqli_error($pubConn);
	
//	if ('' != $selRow[0]){
	if (1){
		$moveSql = "UPDATE $paramTable SET initValue = readValue   
				WHERE $objWhereStr
				";
		if($DEBUG) echo "<BR>moveSql=$moveSql";
		mysqli_query($pubConn,$moveSql);
		echo mysqli_error($pubConn);
	}
}

/****************************************************************
SaveParam
函数说明:
	该函数用于发送save命令
	
参数:
	$SaveArr include $sysId,$oidstr,$Value,$selectedSysId

修改注释：      
NO.1      
姓名：            
时间：      
修改说明：    
****************************************************************/
function SaveParam($SaveArr)
{
	global $nSetComm;
		
	for($j =0;$j< sizeof($SaveArr);$j++)
	{
		$sysId = $SaveArr[$j]['sysid'];
		$oidstr = $SaveArr[$j]['oidstr'];
		$Value = $SaveArr[$j]['setvalue'];
		if(isset($SaveArr[$j]['selectsysid']))//added by oven 2006-9-19 17:39
			$selectedSysId =$SaveArr[$j]['selectsysid'];
		else
			$selectedSysId = '-1';
		
		$sysIdArr	= explode('_',$sysId);
		$sysTypeNo	= $sysIdArr[0];
		$sysNo		= $sysIdArr[1];
		$subSysNo	= $sysIdArr[2];
		
		$objWhereStr= '';
		$objWhereStr =getLevelWhere($oidstr);		
		
		$objDb		= 'OBJ_'.$sysTypeNo;
		$paramTable = 'param_'.$sysNo;

		$defSql = " SELECT initValue FROM $paramTable WHERE $objWhereStr";
		$defRes = @mysqli_query($pubConn,$defSql);
		$row = @mysqli_fetch_array($defRes);
		$saveSql = "UPDATE $paramTable SET initValue = '$Value', readValue = 'FF' WHERE $objWhereStr";
		mysqli_query($pubConn,$saveSql);
		
		$commIdStr	= oidSysCommSend($sysId,$nSetComm,$oidstr,$selectedSysId);
		if($DEBUG) echo "sysCommSend($sysId,$nSetComm,$oidstr,$selectedSysId)";		
		$cmmIdStr = $cmmIdStr.$commIdStr;
	}	
	CheckState($cmmIdStr,2);
}

//****************************************************************
//	GetParam
//函数说明:
//	该函数用于发送get命令
//	
//参数:
//	$oidsysarr,$errRetFlag=0,$checkflag=0
//	$oidsysarr包含需要发送的oid ，sysid，selectsysid
//
//修改注释：      
//NO.1      
//姓名：            
//时间：      
//修改说明：    
//----------------------------------------------------------
function GetParam($oidsysarr,$errRetFlag=0,$checkflag=0,$showflg=1){
	global $nGetComm;
	for($j =0;$j< sizeof($oidsysarr);$j++){
		$sysIdArr	= explode('_',$oidsysarr[$j][sysid]);
		$sysTypeNo	= $sysIdArr[0];
		if($checkflag ==0 || (getHeartbeat($sysTypeNo)>0)){
			if($DEBUG) echo "<br>sysCommSend({$oidsysarr[$j][sysid]},$nGetComm,{$oidsysarr[$j][oid]},{$oidsysarr[$j][selectsysid]})<br>";
			$commIdStr = oidSysCommSend($oidsysarr[$j][sysid],$nGetComm,$oidsysarr[$j][oid],$oidsysarr[$j][selectsysid]);
		}else{
			continue;
		}	
		$cmmIdStr = $cmmIdStr.$commIdStr;
	}
	if($DEBUG) echo "$cmmIdStr<br>";
	CheckState($cmmIdStr,$errRetFlag,$showflg);

	for($j =0;$j< sizeof($oidsysarr);$j++){		
		ChDbMov($oidsysarr[$j][sysid],$oidsysarr[$j][oid]);
	}			
}


//****************************************************************
//	DelComm
//函数说明:
//	该函数用于删除掉parameterComm里面的纪录
//	
//参数:
//	$cmmIdStr为要删除的commId字串
//
//
//修改注释：      
//NO.1      
//姓名：            
//时间：      
//修改说明：    
//----------------------------------------------------------
function DelComm($cmmIdStr){
	if($cmmIdStr==""){
		return;
	}		
	$cmmIdStrArr=explode("-",$cmmIdStr);
	for($i=0;$i<sizeof($cmmIdStrArr)-1;$i++){
		if($i==0)
			$tmpWhere="(commId='$cmmIdStrArr[$i]'";
		else
			$tmpWhere=$tmpWhere." OR commId='$cmmIdStrArr[$i]'";
	}
	$tmpWhere=$tmpWhere.")";						
	$i = 0;
	$commTable = "parameterComm";	
	$delComm = " DELETE FROM $commTable WHERE $tmpWhere ";
	mysqli_query($pubConn,$delComm);						
}

//****************************************************************
//	SetParam
//函数说明:
//	该函数用于发送set命令
//	
//参数:
//	$oidsysarr,$checkflag=0
//	$oidsysarr包含需要发送的oid ，sysid，selectsysid
//
//修改注释：      
//NO.1      
//姓名：            
//时间：      
//修改说明：    
//----------------------------------------------------------
function SetParam($oidsysarr,$checkflag=0){
	global $nSetComm;		

	for($j =0;$j< sizeof($oidsysarr);$j++){
		$sysIdArr	= explode('_',$oidsysarr[$j][sysid]);
		$sysTypeNo	= $sysIdArr[0];
		$sysNo		  = $sysIdArr[1];
		$subSysNo	  = $sysIdArr[2];			
		
		if($checkflag ==0 || (getHeartbeat($sysTypeNo)>0))
		{		
			if($DEBUG) echo "<br>sysCommSend({$oidsysarr[$j][sysid]},$nSetComm,{$oidsysarr[$j][oid]},{$oidsysarr[$j][selectsysid]})<br>";
			$commIdStr = oidSysCommSend($oidsysarr[$j][sysid],$nSetComm,$oidsysarr[$j][oid],$oidsysarr[$j][selectsysid]);				
		}
		else
		{
			continue;
		}
		
		$cmmIdStr	=$cmmIdStr.$commIdStr;
	}
	if($DEBUG)echo "$cmmIdStr<br>";
	CheckState($cmmIdStr);	
}


//****************************************************************
//	Clear_readValud
//函数说明:
//	该函数用于清空readValue
//	
//参数:
//	$oidsysarr
//
//
//修改注释：      
//NO.1      
//姓名：            
//时间：      
//修改说明：    
//----------------------------------------------------------
function Clear_readValud($oidsysarr){
	for($j =0;$j< sizeof($oidsysarr);$j++){
		$sysIdArr	= explode('_',$oidsysarr[$j][sysid]);
		$sysTypeNo	= $sysIdArr[0];
		$sysNo		  = $sysIdArr[1];
		$subSysNo	  = $sysIdArr[2];
		
		$objDb		= 'OBJ_'.$sysTypeNo;
		$paramTable = 'param_'.$sysNo;	
		$updSql = "UPDATE $paramTable SET readValue = ''";
		mysqli_query($pubConn,$updSql);
	}
}


//****************************************************************
//	get_e1channel
//函数说明:
//	该函数用于get相应trunkgroup所属E1的channel参数
//	
//参数:
//	$trunkgp
//
//
//修改注释：      
//NO.1      
//姓名：            
//时间：      
//修改说明：    
//----------------------------------------------------------
function get_e1channel($trunkgp){
	global $nSetComm,$nGetComm,$DEBUG;
	
	$sysId = '322_99_99';
	
	$sysIdArr	= explode('_',$sysId);
	$sysTypeNo	= $sysIdArr[0];
	$sysNo		= $sysIdArr[1];
	$subSysNo	= $sysIdArr[2];
	
	$oidstr = '2.4.2';
	$objWhereStr= '';	
	$objWhereStr =getLevelWhere($oidstr);
	
	
	$objDb		= 'OBJ_'.$sysTypeNo;
	$paramTable = 'param_'.$sysNo;
	
	$HEXtrunkgp		= omc_keep_length(dechex($trunkgp),"0","2");
	$HEXtrunkgp = strtoupper($HEXtrunkgp);
	$paramSql = " SELECT instanceNo FROM $paramTable  
				WHERE $objWhereStr AND initValue = '$HEXtrunkgp' 
				ORDER BY instanceNo
				";

	$Result = mysqli_query($pubConn,$paramSql);
	if(0)echo "<br>paramSql:$paramSql";
	//------------读E1参数表---------------------
	$n = 0;
	while($Row = mysqli_fetch_array($Result)){	
		$tempnum = $Row[instanceNo]/8;
		$cardno = Floor($tempnum);
		$cardname = "cardno"."_$cardno";
		$tempno = $cardno+1;
		$E1Cardno[$tempno]=1;
		$n++;
	}
	$sendflag=0;
	$E1cmmIdStr='';
	for($i=1;$i<33;$i++){
		if($E1Cardno[$i]){
			$oidCard = "2.5."."$i";
			if($DEBUG) echo "<br>oidSysCommSend('322_99_99',$nGetComm,$oidCard)<br>";
			$commIdStr	= oidSysCommSend('322_99_99',$nGetComm,$oidCard);
							
			$E1cmmIdStr	 =$E1cmmIdStr.$commIdStr;
			
			{
				$obj = ($i<17) ? '322_0_0' : '322_1_0';
				if($i < 17)
					$oidCard = "3.5."."$i";
				else
				{
					$ii = $i-16;
					$oidCard = "3.5."."$ii";
				}
				$commIdStr	= oidSysCommSend($obj,$nGetComm,$oidCard);	
				if($DEBUG) echo "<br>oidSysCommSend($obj,$nGetComm,$oidCard)<br>";
						
				$E1cmmIdStr	 =$E1cmmIdStr.$commIdStr;			
			}
			$sendflag=1;
		}
	}
	if($sendflag){
		CheckState($E1cmmIdStr);
	}
	for($i=1;$i<33;$i++){
		if($E1Cardno[$i]){
			$oidCard = "2.5."."$i";			
			ChDbMov('322_99_99',$oidCard);
		}
	}	
	return;

}


//****************************************************************
//	set_e1channel
//函数说明:
//	该函数用于set相应trunkgroup所属E1的channel参数
//	
//参数:
//	$trunkgp
//
//
//修改注释：      
//NO.1      
//姓名：            
//时间：      
//修改说明：    
//----------------------------------------------------------
function set_e1channel($trunkgp){
	global $nSetComm,$nGetComm,$DEBUG;
	
	$sysId = '322_99_99';
	
	$sysIdArr	= explode('_',$sysId);
	$sysTypeNo	= $sysIdArr[0];
	$sysNo		= $sysIdArr[1];
	$subSysNo	= $sysIdArr[2];
	
	$oidstr = '2.4.2';
	$objWhereStr= '';	
	$objWhereStr =getLevelWhere($oidstr);
	
	
	$objDb		= 'OBJ_'.$sysTypeNo;
	$paramTable = 'param_'.$sysNo;
	
	$HEXtrunkgp		= omc_keep_length(dechex($trunkgp),"0","2");
	$HEXtrunkgp = strtoupper($HEXtrunkgp);
	$paramSql = " SELECT instanceNo FROM $paramTable  
				WHERE $objWhereStr AND initValue = '$HEXtrunkgp' 
				ORDER BY instanceNo
				";

	$Result = mysqli_query($pubConn,$paramSql);
	if(0)echo "<br>paramSql:$paramSql";
	//------------读E1参数表---------------------
	$n = 0;
	while($Row = mysqli_fetch_array($Result)){	
		$tempnum = $Row[instanceNo]/8;
		$cardno = Floor($tempnum);
		$cardname = "cardno"."_$cardno";
		$tempno = $cardno+1;
		$E1Cardno[$tempno]=1;
		$n++;
	}
	$E1cmmIdStr='';
	for($i=1;$i<33;$i++){
		if($E1Cardno[$i]){
			$oidCard = "2.5."."$i";
			if($DEBUG) echo "<br>oidSysCommSend('322_99_99',$nSetComm,$oidCard)<br>";
			$commIdStr	= oidSysCommSend('322_99_99',$nSetComm,$oidCard);				
			$E1cmmIdStr	 =$E1cmmIdStr.$commIdStr;
		}
	}
	CheckState($E1cmmIdStr);
	
	return;

}



//****************************************************************
//	changeGTT
//函数说明:
//	该函数用于修改dpc参数是修改相应的GTT纪录
//	
//参数:
//	$DPC,$NetID,$oldDPC,$oldNetID
//
//
//修改注释：      
//NO.1      
//姓名：            
//时间：      
//修改说明：    
//----------------------------------------------------------
function changeGTT($DPC,$NetID,$oldDPC,$oldNetID){
	$tmpDb = 'OBJ_223';
	$tmpTable = 'param_99';
	$tmpoid = '2.2';
	$objWhereStr = getLevelWhere($tmpoid);
	$paramSql = " SELECT initValue,readValue,instanceNo FROM $tmpTable  
				WHERE $objWhereStr
				";
	$Result = mysqli_query($pubConn,$paramSql);
	$num = 0;
	while($Row = mysqli_fetch_array($Result)){
			$GTT_DPC			= hexdec(getBitValue($Row[initValue],'24.0-26.7'));
			$GTT_SSN	  	= hexdec(getBitValue($Row[initValue],'27.0-27.7'));
			$GTT_NetID	  = hexdec(getBitValue($Row[initValue],'23.0-23.7'));
			$flag			  	= hexdec(getBitValue($Row[initValue],'00.0-00.7'));
			if($GTT_DPC == $oldDPC && $flag == 1 && $GTT_NetID == $oldNetID){
				$DPC_GTT				=	dechex($DPC);
				$DPC_GTT    = omc_keep_length($DPC_GTT,0,6);
				$Row[initValue]	= setBitValue($Row[initValue],'24.0-26.7',$DPC_GTT);
				//$SSN_GTT				=	dechex($SSN);
				$SSN_GTT				=	dechex($GTT_SSN);
				$SSN_GTT    = omc_keep_length($SSN_GTT,0,2);
				$Row[initValue]	= setBitValue($Row[initValue],'27.0-27.7',$SSN_GTT);
				$NetID_GTT				=	dechex($NetID);
				$NetID_GTT    = omc_keep_length($NetID_GTT,0,2);
				$Row[initValue]	= setBitValue($Row[initValue],'23.0-23.7',$NetID_GTT);								
				$Row[initValue] = strtoupper($Row[initValue]);
				$updSql = "UPDATE $tmpTable SET initValue = '$Row[initValue]'   
					WHERE $objWhereStr AND instanceNo = '$Row[instanceNo]'
					";
				mysqli_query($pubConn,$updSql);
				$num++;
			}
	}	
}


//****************************************************************
//	toAscii
//函数说明:
//	该函数用于把byte转换成字符串
//	
//参数:
//	$DPC,$NetID,$oldDPC,$oldNetID
//
//
//修改注释：      
//NO.1      
//姓名：            
//时间：      
//修改说明：    
//----------------------------------------------------------
function toAscii($byteValue){	
	$charValue = "";
	$tmpLen=strlen($byteValue);
	for($charCount=0; $charCount < $tmpLen; $charCount++){
		$unitByte = substr($byteValue,$charCount,2);
		$charCount++;
		if($unitByte == 0) break;
		$unitChar = chr(HexDec($unitByte)); // hex -> ascii
		$charValue .= $unitChar;
	}
	return $charValue;	
}

//****************************************************************
//	toHex
//函数说明:
//	该函数用于把字符串转换成byte
//	
//参数:
//	$DPC,$NetID,$oldDPC,$oldNetID
//
//
//修改注释：      
//NO.1      
//姓名：            
//时间：      
//修改说明：    
//----------------------------------------------------------
function toHex($byteValue){	
	$charValue = "";
	$tmpLen=strlen($byteValue);
	for($charCount=0; $charCount < $tmpLen; $charCount++){
		$unitByte = substr($byteValue,$charCount,1);
		$unitChar = dechex(ord($unitByte));
		$charValue .= $unitChar;
	}
	return $charValue;	
}


//****************************************************************
//	getHeartbeat
//函数说明:
//	该函数用于从heartbeat取状态判断设备是否存在
//	
//参数:
//	$sysTypeNo
//
//
//修改注释：      
//NO.1      
//姓名：            
//时间：      
//修改说明：    
//----------------------------------------------------------
function getHeartbeat($sysTypeNo){
		global $pubDb;
		$getSql="SELECT sysTypeNo,sysNo,subSysNo FROM OMC_PUB.sysInfo WHERE sysTypeNo=$sysTypeNo";
		$result	=mysqli_query($pubConn,$getSql);
		//echo "$getSql<br>";
		echo mysqli_error($pubConn);
		$count=0;
		while($rows=mysqli_fetch_array($result)){							
			$count++;				
		}
		return $count;	
}


//****************************************************************
//	InitialAAS
//函数说明:
//	该函数用于初始化aas参数
//	
//参数:
//	$systemNo
//
//
//修改注释：      
//NO.1      
//姓名：            
//时间：      
//修改说明：    
//----------------------------------------------------------
function InitialAAS($systemNo)
{
	global $nSetComm;
					
	$objDB = "OBJ_311";
	$paramTable = 'param_'.$systemNo;
	$sccp_sysId = "223_11_".$systemNo;
	$AasSysId = "311_".$systemNo."_0";

	$oidsysarr=array('2.1.3','2.1.4','2.1.5','2.1.8','2.1.9','2.1.10','2.3.1','2.3.2');

	
	for($i=0;$i<sizeOf($oidsysarr);$i++)
	{
		$oidstr = $oidsysarr[$i];
		$objWhereStr = getLevelWhere($oidstr);
		
		$paramSql = " SELECT initValue FROM OBJ_311.paramConf  
		WHERE $objWhereStr";
		
		$Result_def = mysqli_query($pubConn,$paramSql);					
		$Row_def		= mysqli_fetch_array($Result_def);
		
		$tmpDefValue= $Row_def[initValue];
		
		$updflag = "UPDATE $paramTable SET initValue = '$tmpDefValue'
	        			WHERE $objWhereStr
	        			";								
	  if($debug) echo "$updflag<br>";
		mysqli_query($pubConn,$updflag);
		echo mysqli_error($pubConn);								
		
		//****************************************************************
		$commIdStr	=oidSysCommSend($AasSysId,$nSetComm,$oidstr);
		
		$commArr = $commArr.$commIdStr;
		//****************************************************************		
	}

/*	
	$sccp_objDB = 'OBJ_223';
	$tmpTable = 'param_11';
	$oidstr = '2.1.8';		

	$objWhereStr = getLevelWhere($oidstr);
	
	$paramSql = " SELECT initValue FROM OBJ_223.paramConf  
	WHERE $objWhereStr";
	
	$Result_def = mysql_db_query('OBJ_223',$paramSql);					
	$Row_def		= mysqli_fetch_array($Result_def);		
	$tmpDefValue= $Row_def[initValue];
	
	
	$updflag = "UPDATE $tmpTable SET initValue = '$tmpDefValue' 
        			WHERE $objWhereStr
        			";								
  if($debug) echo "$updflag<br>";
	mysqli_query($pubConn,$updflag);
	echo mysqli_error($pubConn);

	//****************************************************************
	$commIdStr	=oidSysCommSend('223_11_99',$nSetComm,$oidstr,$sccp_sysId);
	if($commIdStr=='-1'){
		DelComm($commArr);
		echo "<br><br><b>Error while getting/setting parameters. Please check the device state!<br>";
		echo "oidSysCommSend('223_11_99',$nSetComm,$oidstr,$sccp_sysId)<br>";
		echo "<p align=\"left\"><a href=\"JavaScript:history.go(-1)\"><img align=absBottom border=0 src=\"../../images/left.gif\" width=\"14\" height=\"14\">Back</a>";			
		exit();
	}
	$commArr = $commArr.$commIdStr;
	//****************************************************************		
*/		
	CheckState($commArr);	
}


//****************************************************************
//	InitialAAS
//函数说明:
//	该函数用于检查dpc有没有重复
//	
//参数:
//	$DPC,$NI
//
//
//修改注释：      
//NO.1      
//姓名：            
//时间：      
//修改说明：    
//----------------------------------------------------------
function chkDPC($DPC,$NI){
		//dpc ni不能设重
		$tmpDb = 'OBJ_222';
		$tmpTable = 'param_99';
		$tmpoid = '2.4.1';
		$objWhereStr = getLevelWhere($tmpoid);
				
		$setDPC = omc_keep_length(dechex($DPC),0,6);
		$setDPC = strtoupper($setDPC);
		$setNetID = $NI;
		$paramSql = " SELECT initValue,readValue,instanceNo FROM $tmpTable  
					WHERE $objWhereStr AND initValue LIKE '$setDPC%'
					";
		$Result = mysqli_query($pubConn,$paramSql);
		while($Row = mysqli_fetch_array($Result)){
			$flag=getBitValue($Row[initValue],'3.2-3.2');
			if($flag&&($setNetID==bindec(getBitValue($Row[initValue],'3.0-3.1')))){
				echo "<script language='javascript'>";  
				echo "window.alert(\"Signaling point is already used!\");";
				echo "history.go(-1)";
				echo "</script>";											 		
				exit();
			}
		}
	
		//不能与 spc 重复
		{
			$oidstr = '2.2';
			$link_Db = 'OBJ_222';	
			$link_Table  = 'param_99';
			
			$subSysNo = 99;
			$objWhereStr= '';
			$objWhereStr =getLevelWhere($oidstr);
			$paramSql = " SELECT initValue,readValue,instanceNo FROM $link_Table  
						WHERE $objWhereStr 
						";
			if($DEBUG) echo "$paramSql<br>";			
			$Result = mysqli_query($pubConn,$paramSql);
			$Row		= mysqli_fetch_array($Result);
										
			$NIbit	= getBitValue($Row[initValue],"0.$setNetID");
			$tmp = $setNetID+1+$NIbit*4;
			$oidstr = '2.3.'.$tmp;
			$objWhereStr= '';
			$objWhereStr =getLevelWhere($oidstr);
			$paramSql = "SELECT initValue FROM $link_Table
									WHERE $objWhereStr AND instanceNo = '0'
									";									
			if($DEBUG)  echo "paramSql=$paramSql<br>";
			$Result   = mysqli_query($pubConn,$paramSql);
			$Row	= mysqli_fetch_array($Result);
			$WXC2DPC = strtoupper($Row[initValue]);
			if(hexdec($setDPC) == hexdec($WXC2DPC)){
				echo "<script language='javascript'>";  
				echo "window.alert(\"Signaling point is already used!\");";
				echo "history.go(-1)";
				echo "</script>";											 		
				exit();				
			}
		}	
	
}
function chkEleName($setName)
{
	global $pubDb;
	$DEBUG = 0;
	$ElementInfoObjId='2.11';
	$levelWhere = getLevelWhere($ElementInfoObjId);
	if($DEBUG) echo "<BR>levelWhere=$levelWhere";
	$ElementInfoParamTable='OBJ_225.param_99';
	$getSql="SELECT initValue,instanceNo FROM $ElementInfoParamTable 
				WHERE $levelWhere and initValue LIKE '01%' ";
	if($DEBUG) echo "<BR>getSql=$getSql";
	$result	=mysqli_query($pubConn,$getSql);
	echo mysqli_error($pubConn);
	$nameOffset 	= '14.0-23.7';
	while($rows=mysqli_fetch_array($result))
	{
		$name = trim(toAscii(getBitValue($rows[initValue],$nameOffset)));
	
		if(strcmp($name,$setName)==0){
			echo "<script language='javascript'>";  
			echo "window.alert(\"This element name is already used!\");";
			echo "history.go(-1)";
			echo "</script>";											 		
			exit();
		}
	}
}

//****************************************************************
//	getE1State
//函数说明:
//	该函数用于检查所属TG，Linkset下E1 ，E1 link的状态
//	
//参数:
//	$TG,$linkset
//
//
//修改注释：      
//NO.1      
//姓名：            
//时间：      
//修改说明：    
//----------------------------------------------------------
function getE1State($TG,$linkset)
{
	global $pubDb;
	if(strlen($TG)<=0)
		$TG =255;
	if(strlen($linkset)<=0)
		$linkset = 255;
			
	
	$tmpObjIdStr='2.4.2';
	$levelWhere = getLevelWhere($tmpObjIdStr);
	$tmpTgValue=dechex($TG);
	$tmpTgValue=strtoupper(omc_keep_length($tmpTgValue,0,2));
	$getSql="SELECT initValue,instanceNo FROM OBJ_322.param_99 
				WHERE $levelWhere AND initValue='$tmpTgValue'
			";				
	$result	=mysqli_query($pubConn,$getSql);	
	
	$flag=0;	
	$E1state1=1;//OK
	$E1state2=0;//DOWN	
	$ins_bgn	=	22;	//e1 installed
	$phy_bgn	=	24;	//e1 layer1(physical layer)
	$el2_bgn	=   25; //e1 layer2
	while($rows = mysqli_fetch_array($result))
	{
		{//e1 enable,L1,L2 status
		$tempnum = $rows[instanceNo]/8;
		$cardno = Floor($tempnum);
		$sysNo = $cardno > 15 ? 1 : 0;
		$slot = $cardno % 16;
		$port = $rows[instanceNo] - $cardno*8;	
		
		$e1selSql = "SELECT sysTypeNo,sysNo,subSysNo,detailStat,updateTime 
						FROM sysStat WHERE sysTypeNo='111' AND sysNo='$sysNo' and subSysNo='$slot' ";

		$e1Result = @mysqli_query($pubConn,$e1selSql);
		if($e1Row = @mysqli_fetch_array($e1Result))
		{
			$hex_mes = $e1Row[detailStat];
			$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;
			}
			//e1 install
			$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);
						
			$E1state1 = $E1state1 & $tmp2 & $tmp3;
			$E1state2 = $E1state2 | $tmp2 | $tmp3;
			$flag = 1;
		}
		}//end e1 L1,L2 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' AND updateTime>'$out_time'
			";
	$Hbresult = mysqli_query($pubConn,$HbparamSql);				
	$Hbvalue_mpt3  = mysqli_fetch_array($Hbresult);//取mtp3 的heartbeat
	
	//E1 link
	$tmpObjIdStr='2.5.1';
	$levelWhere = getLevelWhere($tmpObjIdStr);
	$tmpValue=dechex($linkset);
	$tmpValue=strtoupper(omc_keep_length($tmpValue,0,2));
	$getSql="SELECT initValue,instanceNo FROM OBJ_222.param_99 
				WHERE $levelWhere AND initValue LIKE '$tmpValue%'
			";				
	$result	=mysqli_query($pubConn,$getSql);			
//echo "<br>$getSql";
	$flaglink=0;	
	while($rows=mysqli_fetch_array($result))
	{		
		$linkflag	= getBitValue($rows[initValue],'06.5-06.5');
		if($linkflag)
		{
			$Hboffset=34+Floor($rows[instanceNo]/4);
			$tmpValue=substr($Hbvalue_mpt3[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;	
			$E1state1 = $E1state1 & $tmp;
			$E1state2 = $E1state2 | $tmp;		
			$flaglink=1;			
		}
	}	
	if(0)
	{
		$return = "$tmp; $tmp2 ;$tmp3";
		$return1 = "$sysNo; $slot; $port";
		//return $return1;
		return $return;
	}	
	if($flag&&$flaglink&&$E1state1==1&&$E1state2==1)
		$E1state='Available';
	elseif($flag&&$flaglink&&$E1state1==0&&$E1state2==1)
		$E1state='Alarm';
	else
		$E1state='Unavailable';
	return $E1state;
}

function delete_e1($ins_no)
{
	global $e1_oid,$link_oid,$msc_paramTable,$mtp3_sqltable,$DEBUG,$pubdb;
	$objWhereStr = getLevelWhere($e1_oid[1]);
	$setsql = "update $msc_paramTable set initValue = '00' where $objWhereStr and instanceNo = '$ins_no'";
	mysqli_query($pubConn,$setsql);
	echo mysqli_error($pubConn);
	if($DEBUG) echo "$setsql<br>";
					
	$objWhereStr = getLevelWhere($e1_oid[2]);
	$setsql = "update $msc_paramTable set initValue = 'EE' where $objWhereStr and instanceNo = '$ins_no'";
	mysqli_query($pubConn,$setsql);
	echo mysqli_error($pubConn);
	if($DEBUG) echo "$setsql<br>";
						
	$objWhereStr = getLevelWhere($e1_oid[3]);
	$setsql = "update $msc_paramTable set initValue = '00' where $objWhereStr and instanceNo = '$ins_no'";
	mysqli_query($pubConn,$setsql);
	echo mysqli_error($pubConn);
	if($DEBUG) echo "$setsql<br>";
	
	$objWhereStr = getLevelWhere($e1_oid[4]);
	$setsql = "update $msc_paramTable set initValue = '00' where $objWhereStr and instanceNo = '$ins_no'";
	mysqli_query($pubConn,$setsql);
	echo mysqli_error($pubConn);
	if($DEBUG) echo "$setsql<br>";
	
	$objWhereStr = getLevelWhere($link_oid);
	$setsql = "update $mtp3_sqltable set initValue = '8010FFFFFFFF000000000000000000FFFFFFFF' where $objWhereStr and instanceNo = '$ins_no'";
	mysqli_query($pubConn,$setsql);
	echo mysqli_error($pubConn);
	if($DEBUG) echo "$setsql<br>";	
}

function is8ke1Enable($instanceNo)
{
	$nSetComm = 3;
	$tempnum = $instanceNo/8;
	$cardno = Floor($tempnum);
	$tmp = $cardno/16;
	$k8e1SysNo = floor($tmp);
	$k8e1Table = "param_$k8e1SysNo";
	$k8e1Db = "OBJ_111";
	$setInstNo = $cardno%16;
	$cardE1no = $instanceNo - $cardno*8;
	
	$selSql = "select initValue from $k8e1Table 
			where level_1='2' and level_2='1' and instanceNo='$setInstNo' ";
	$result = mysqli_query($pubConn,$selSql);
	$row = mysqli_fetch_array($result);
	$setbit = "0.$cardE1no-0.$cardE1no";
	$enable = getBitValue($row[initValue],$setbit);
	return $enable;
}

function set8ke1($objIdStr,$instanceNo,$value)
{
	
	$nSetComm = 3;
	$tempnum = $instanceNo/8;
	$cardno = Floor($tempnum);
	$tmp = $cardno/16;
	$k8e1SysNo = floor($tmp);
	$k8e1Table = "param_$k8e1SysNo";
	$k8e1Db = "OBJ_111";
	$setInstNo = $cardno%16;
	$cardE1no = $instanceNo - $cardno*8;
	if(strcmp($objIdStr,'2.9')==0 && $cardE1no % 2 != 0)//set8ke1Canceller, 偶数端口才设置
		return;
	$levelWhere = getLevelWhere($objIdStr);
	
	$selSql = "select initValue from $k8e1Table 
			where $levelWhere and instanceNo='$setInstNo' ";
	$result = mysqli_query($pubConn,$selSql);
	$row = mysqli_fetch_array($result);
	
	$setbit = "0.$cardE1no-0.$cardE1no";
	if(strcmp($objIdStr,'2.12')==0)//set8kIdleCode
		$setbit = "$cardE1no.0-$cardE1no.7";	
	$setValue = strtoupper(setBitValue($row[initValue],$setbit,$value));
	
	if(strcmp($objIdStr,'2.10.2')==0 //set8ke1SigSlot
		|| strcmp($objIdStr,'2.11')==0)//
		$setValue = omc_keep_length(dechex($value),0,2);
		
	$updSql = "update $k8e1Table set initValue='$setValue' 
			where $levelWhere and instanceNo='$setInstNo' ";
	
	mysqli_query($pubConn,$updSql);
	
	$sysId ="111_".$k8e1SysNo."_99";
	//$slcSysId = "111_".$k8e1SysNo."_"."$setInstNo";
	$slcSysId = '-1';
	$commIdStr	=oidSysCommSend($sysId,$nSetComm,$objIdStr,$slcSysId);
	if($commIdStr=='-1')
	{
		//DelComm($commIdStr);
		outPutErrMsg($sysId,$slcSysId);
	}
	CheckState($commIdStr);
}

function open8ke1Enable($instanceNo, $value)
{
	$objIdStr = '2.1';
	set8ke1($objIdStr,$instanceNo,$value);
}

function open8ke1mtpAlarm($instanceNo, $value)
{
	$objIdStr = '2.2';
	set8ke1($objIdStr,$instanceNo,$value);
}

function set8ke1LinkType($instanceNo, $value)
{
	$objIdStr = '2.3';
	set8ke1($objIdStr,$instanceNo,$value);
}

function set8ke1NTLT($instanceNo, $value)
{
	$objIdStr = '2.4';
	set8ke1($objIdStr,$instanceNo,$value);
}

function open8ke1CRC4Flag($instanceNo, $value)
{
	$objIdStr = '2.6';
	set8ke1($objIdStr,$instanceNo,$value);
}

function set8ke1Mtp2ErrCrct($instanceNo, $value)
{
	$objIdStr = '2.8';
	set8ke1($objIdStr,$instanceNo,$value);
}

function set8ke1Canceller($instanceNo, $value)
{
	$objIdStr = '2.9';
	set8ke1($objIdStr,$instanceNo,$value);
}

function set8ke1SigSlot($instanceNo, $value)
{
	$objIdStr = '2.10.2';
	set8ke1($objIdStr,$instanceNo,$value);
}

function set8kT156K64K($instanceNo, $value)
{
	$objIdStr = '2.10.6';
	set8ke1($objIdStr,$instanceNo,$value);
}

function set8kCardType($instanceNo, $value)
{
	$objIdStr = '2.11';
	set8ke1($objIdStr,$instanceNo,$value);
}

function set8kIdleCode($instanceNo, $value)
{
	$objIdStr = '2.12';
	set8ke1($objIdStr,$instanceNo,$value);
}

function getNiType()
{
	global $pubDb;
	$mtp3_sqlTable = 'OBJ_222.param_99';
	$querysql = "select initValue from $mtp3_sqlTable where level_1 = '2' and level_2 = '2'  and level_3 = '0'";
	$indiResult = mysqli_query($pubConn,$querysql);
	$indiRow = mysqli_fetch_array($indiResult);
	echo mysqli_error($pubConn);
	for($i=0; $i<4; $i++)
	{
		$j = $i+4;
		$off_set = "0.$j-0.$j";
		$niTypeArr[$i] = getBitValue($indiRow[initValue],$off_set);//0:ITU; 1:ANSI
		//$niTypeArr[2] = 1;
	}
	return $niTypeArr;
}

function outPutErrMsg($sysId,$slcSysId=-1)
{
	global $PlatTypeDefArr;
	$pubdb = "OMC_PUB";
	$sysIdArr = explode('_',$sysId);
	$sysTypeNo	= $sysIdArr[0];
	$sysNo		= $sysIdArr[1];
	$subSysNo	= $sysIdArr[2];
	if($slcSysId!=-1)
	{
		$slcSysIdArr = explode('_',$slcSysId);
		$slcSysTypeNo	= $slcSysIdArr[0];
		$slcSysNo		= $slcSysIdArr[1];
		$slcSubSysNo	= $slcSysIdArr[2];
	}
	$selSql = "select sysTypeName from sysConf where sysTypeNo='$sysTypeNo'";
	$Result = mysqli_query($pubConn, $selSql);
	$Row = mysqli_fetch_array($Result);
	
	$sysName = $Row[sysTypeName];
	if($sysTypeNo == 111)
	{
		$sysName = "CSU$slcSysNo Card-$slcSubSysNo";
	}
	
	if(isset($slcSysNo)) $sysName .= "-$slcSysNo";
	
	if($sysTypeNo=='222' || $sysTypeNo=='223')
	{
		if($slcSysId != -1)
		{
			$sysName = $PlatTypeDefArr[$slcSysNo][remark];
			$sysName .= "-$slcSubSysNo";
		}
	}
	echo "<br><br><b>$sysName Error, Please check the device state!<br>";
	echo "<p align=\"left\"><a href=\"JavaScript:history.go(-1)\"><img align=absBottom border=0 src=\"../../images/left.gif\" width=\"14\" height=\"14\">Back</a>";			
	exit();
}
function outPutChkMsg($sysTypeNo,$sysNo,$Reason='',$errRetFlag)
{
	global $STR_CONF_COMMAND_ERR_0000;
	global $STR_CONF_PROMPT_001,$STR_CONF_COMMAND_ERR_0011,$STR_CONF_COMMAND_ERR_0012;
	global $STR_CONF_PROMPT_002,$STR_CONF_COMMAND_ERR_0021,$STR_CONF_COMMAND_ERR_0022;
	global $STR_CONF_PROMPT_003,$STR_CONF_COMMAND_ERR_0031,$STR_CONF_COMMAND_ERR_0032,$STR_CONF_COMMAND_ERR_0033;
	global $STR_CONF_PROMPT_004,$STR_CONF_COMMAND_ERR_0041,$STR_CONF_COMMAND_ERR_0042,$STR_CONF_COMMAND_ERR_0043;
	global $STR_CONF_COMMAND_ERR_9999;

	//echo "Reason=$Reason";
	global $PlatTypeDefArr;
	$pubdb = "OMC_PUB";
	$selSql = "select sysTypeName from sysConf where sysTypeNo='$sysTypeNo'";
	$Result = mysqli_query($pubConn, $selSql);
	$Row = mysqli_fetch_array($Result);
	if($sysTypeNo == '222' || $sysTypeNo=='223')
	{
		$sysName = $PlatTypeDefArr[$sysNo][remark] . "-" . $Row[sysTypeName];
	}
	else
	{
		$sysName = $Row[sysTypeName]."-".$sysNo;
	}
	$tmpErrCode="STR_CONF_COMMAND_ERR_".$Reason;
	$tmpPromptCode="STR_CONF_PROMPT_".$Reason[0].$Reason[1].$Reason[2];
	echo "<br><br><b>$sysName Error:${$tmpErrCode} <br>";
	echo "<b>Prompt:${$tmpPromptCode} <br>";
	
	if($errRetFlag == 1){	
		$tmpResult=	"$sysName Error:${$tmpErrCode}.<br>Prompt:${$tmpPromptCode}";
		echo "<script LANGUAGE=\"JavaScript\">";
		echo "\n window.location.href=\"../overview/overview.php?upLoadResult=$tmpResult\";";
		echo "\n </script>";				
	}else{
		echo "<p align=\"left\"><a href=\"JavaScript:history.go(-1)\"><img align=absBottom border=0 src=\"../../images/left.gif\" width=\"14\" height=\"14\">Back</a>";			
	}
	exit();
}

function getElementInfo($infoNo,&$elementInfoArr)
{
	global $sysTypeInLinkSetDef,$strGttObjects;
	$tmpobj		= 'OBJ_225';
	$tmpparam = 'param_99';
	$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';
	
	$objWhereStr =" level_1 = '2' and level_2 = '11'";
	$paramSql = " SELECT initValue,readValue,instanceNo FROM $tmpparam  
					WHERE $objWhereStr AND instanceNo ='$infoNo'";
	$Result  = mysqli_query($pubConn,$paramSql);				
	$rows	 = mysqli_fetch_array($Result);
	$typeValue=hexdec(getBitValue($rows[initValue],$typeOffset));
	$sysNo	= bindec(getBitValue($rows[initValue],$sysNoOffset));
	$subsysNo	= bindec(getBitValue($rows[initValue],$subSysNoOffset));
	$tmpSystemNo= $sysNo;
	$assignedTg = hexdec(getBitValue($rows[initValue],$tgOffset));
	$assignedls = hexdec(getBitValue($rows[initValue],$lsOffset));
	$appType = hexdec(getBitValue($rows[initValue],$appTypeOffset));
	$appGrp = hexdec(getBitValue($rows[initValue],$appGrpOffset));
	$name = trim(toAscii(getBitValue($rows[initValue],$nameOffset)));
	
	$TypeNo	 = getBitValue($Row[initValue],'2.0-2.7');
	$TypeNo  = hexdec($TypeNo);
	
	if($typeValue==0)
	{
		$Spname = "Undefined";		
	}
	elseif($typeValue < 16)
	{
		$tmpno = $typeValue - 1;
		$Spname = $sysTypeInLinkSetDef[$tmpno][name];		
	}
	elseif($typeValue==16)
	{
		$Spname = 'Switch';
	}
	elseif($typeValue==17)
		$Spname = 'IUA';
	elseif( $typeValue==18)
	{
		switch($appType)
		{
			case	'0':
				$Spname = 'MSC';
				break;
			case	'1':
				$Spname = 'HLR';
				break;
			case	'2':
				$Spname = 'VLR';
				break;
			case	'3':
				$Spname = 'SMSC';
				break;
			case	'4':
				$Spname = 'SGSN';
				break;
			case	'5':
			{
				$Spname = $name;
			}
		}
	}
	else
	{
		$Spname = "Undefined";	
	}
	
	$webname = $Spname;
	switch($webname)
	{
		case 'BSC':
			$devicename = 'BSC';
			break;
		case 'AAS':
		case 'VSS':
		case 'PCR':
		case 'CNF':
			$devicename = 'Peripheral';
			break;
		case 'Switch':
		case 'IUA':
			$devicename = 'Switch';				
			break;
		case 'MSC':
		case 'VLR':
		case 'HLR':
		case 'SMSC':
		case 'SGSN':
			$devicename = $strGttObjects;
			break;
		default:
			$devicename = 'Unknow';
			break;
	}	

	if($appType == 5) $devicename = $strGttObjects;

	$elementInfoArr[typeName] = $devicename;
	$elementInfoArr[eleName] = $name;
	$elementInfoArr[webName] = $webname;
	$elementInfoArr[typeValue] = $typeValue;
	$elementInfoArr[sysNo] = $sysNo;
	$elementInfoArr[subSysNo] = $subsysNo;
	$elementInfoArr[tg] = $assignedTg;
}

function checkDevices($sysTypeNo)
{
	global $pubDb;
	$sysIdSql="SELECT DPC,ip,sysTypeName,sysInfo.sysTypeNo,sysNo,subSysNo,sysAlias FROM sysInfo,sysConf WHERE sysInfo.sysTypeNo=sysConf.sysTypeNo AND sysInfo.sysTypeNo = $sysTypeNo ";
	$result = mysqli_query($pubConn,$sysIdSql);
	echo mysqli_error($pubConn);
	$rowsNum=mysqli_num_rows($result);
	$rows=mysqli_fetch_array($result);
	$sysTypeName=$rows[sysTypeName];
	if($rowsNum < 1)
	{
		echo "<font color=\"red\" size=\"large\"><b>Can't find this device!<b></font>";
		echo "<p align=\"left\"><a href=\"../overview/overview.php\"><img align=absBottom border=0 src=\"../../images/left.gif\" width=\"14\" height=\"14\">Back</a>";	
		exit();
	}
}
function alertMsg($msg)
{
	echo "<script LANGUAGE=\"JavaScript\">";
	echo "\n alert('$msg');";
	echo "\n window.history.go(-1);";
	echo "\n </script>";
	exit();
}
function sendBssCommand($bssid,$ip,$sysAlias,$add=1)
{
	$DEBUG = 0;
	$db = "BssOmcDb";
	$remark = $sysAlias;
	if($add==1)
		$nmicmd="newbss $bssid $ip";
	else
		$nmicmd = "dropbss $bssid $ip";
	
	/* Old MySql */
	$sqlstring = "SELECT row_no FROM OMCR_COMMAND WHERE status=0 " .
	             "ORDER BY seqNum ASC LIMIT 10";
	//echo "$sqlstring<BR>";
	$res = mysqli_query($pubConn,$sqlstring) or
	          die("Invalid query:$sqlstring\n" . mysqli_error($pubConn));
	while (list($row_no[]) = mysqli_fetch_row($res));
	$no_of_rows = mysqli_num_rows($res);
	mysql_free_result($res);
	if ( $no_of_rows <= 0 || ($no_of_rows > 10) )
	{
	    //
	    // No available row in OMCR_COMMAND
	    // Send error to MySQL()
	    //
	    $errorInfo = "Command table is full: Wait and send the command again";
		if($DEBUG) echo "<br>errorInfo=$errorInfo";
		alertMsg($errorInfo);
		
	}
	if($add==1)
	{
		//
		// Save "Name and remark" in OMCR_BSSTABLE
		// A non-null IP field in OMCR_BSSTABLE means the entry is valid
		//
		$sqlstring = "UPDATE OMCR_BSSTABLE SET name='$remark', ip='$ip'," .
		             "remark='$remark' WHERE bssid=$bssid";
		if($DEBUG) echo "$sqlstring<BR>";
		$res = mysqli_query($pubConn,$sqlstring) or
		          die("Invalid query:$sqlstring\n" . mysqli_error($pubConn));
	}
	//
	// Insert 1 commands in OMCR_COMMAND out of 10 possible available rows
	//
	$i=0;
	do
	{
	    if ($row_no[$i] != '')
	    {
	        $sqlstring = "REPLACE INTO OMCR_COMMAND VALUES(" .
	                     $row_no[$i] . ",-1,'$nmicmd',null,255,-1,null,null,null)";
	        if($DEBUG) echo "$sqlstring<BR>";
	        $res       = mysqli_query($pubConn,$sqlstring) or
	                     die("Invalid query:$sqlstring\n" . mysqli_error($pubConn));
	    }
	    $i++;
	} while ($i<10 && mysql_affected_rows() != 2); //replace=delete+insert (2 task)
	
	$cmd1_row_no = $row_no[$i-1];
	
	//
	// Wait for response: timeout after 500ms x 20 = 10 secs
	//
	$i=0;
	while ($i<20)
	{
	    usleep(500000);
	    $sqlstring = "SELECT resultcode,result,responsecode,response from OMCR_COMMAND WHERE status=0 AND " .
	                 "row_no=$cmd1_row_no ORDER BY seqNum ASC";
	    if($DEBUG) echo "$sqlstring<BR>";
	    $res       = mysqli_query($pubConn,$sqlstring) or
	                 die("Invalid query:$sqlstring\n" . mysqli_error($pubConn));
	    while ( $mydata = mysqli_fetch_row($res) )
	        list($resultcode,$result,$responsecode,$response) = $mydata;
	        //list($a[],$b[],$c[],$d[],$e[],$f[],$result[],$response[]) = $mydata;
	    $no_of_rows = mysqli_num_rows($res);
	    mysql_free_result($res);
	
	    if ($no_of_rows == 1)
	    {
	    	if($add==1)//add
	    	{
		        if ($result != 'ok')
		        {
		            // Create/Delete failed !!!
					$errorInfo = "$result: $response";
					if($DEBUG) echo "<br>errorInfo=$errorInfo";
					//$errorInfo=rawurlencode($errorInfo);
					alertMsg($errorInfo);
		        }
		    }
		    else//delete
		    {
				if ($resultcode != 0)
				{
					$errorInfo = "dropbss command failed: ".$response;
					if($DEBUG) echo "<br>errorInfo=$errorInfo";
					//$errorInfo=rawurlencode($errorInfo);
					alertMsg($errorInfo);
				}
		    }
	    }
	    echo "<img border=\"0\" src=\"../../images/arrow.gif\" width=\"10\" height=\"10\">";
		flush();	
	    $i++;
	}
}//end sendBssCommand

function getExistElements(&$existElementArr)
{
	global $pubDb;
	$elementConfTb = 'elementExistConf';
	$selSql = " select elementTypeNo from $elementConfTb where existFlag='1' and elementTypeNo!='0' order by elementNo";
	if($DEBUG) echo "<br>selSql=$selSql";
	$res = @mysqli_query($pubConn,$selSql);
	$i=0;
	while($rows = mysqli_fetch_array($res))
	{
		$existElementArr[$i++] = $rows[elementTypeNo];
	}
	return $existElementArr;
}//end getExistElements

function omcStrFill($string,$defLen,$fillWay='high',$fillChar='0'){
	if(strlen($string) <= $defLen){
		$fillLen=$defLen - strlen($string);
		for($i=0;$i<$fillLen;$i++){
			if($fillWay == 'low'){
				$string = $string.$fillChar;
			}else{
				$string = $fillChar.$string;
			}
		}
		return($string);
	}else{
		$errorInfo = "Error in omcStrFill:the defLen < lengh of string!!\\ndefLen=$defLen and string=$string!!";
		echo "<script language='javascript'>";  
		
		echo "window.alert(\"$errorInfo\");";	
		echo "history.go(-1)";
		echo "</script>";						
		exit();
		
		echo "<br>Error in omcStrFill : the defLen < lengh of string!!";
		echo "<br>defLen=$defLen and string=$string!!";
		exit();
	}
}

function omcShowParam($oIdstrarr,$sysTypeNo,$instanceNo,$webname,$no){
	global $language,$paramTable;
	
	$nShowsize = '40%';
	
	$nInteger = 2;
	$nOctStr = 4;
	$sysConfTable = 'OMC_PUB.sysConf';
	$sysTypeNo	= (isset($sysTypeNo)?$sysTypeNo:0);
	
	$pubDb			='OMC_PUB';
	$objDb 			= omcGetObjDb($sysTypeNo);
	$paramConfTable	= omcGetObjTbl($sysTypeNo,paramConf);
	$maxLevelNum	= 10;
	
	if($DEBUG) echo "<br>$paramConfTable<br>";
	if($DEBUG) echo "<br>aliasName=$aliasName<br>";
	//----------------------
	//选择语言版本
	if($language == 'eng'){
		$objNameField=name_2;
		$objSetField=setTemplate_2 ; //语种2
	}else{	
		$objNameField=name_1;
		$objSetField=setTemplate_1 ; //语种1(默认语种)
	}
		
	if($DEBUG) echo "<br>setValue = $setValue ,inputName = $inputName";
	//if($keyId > 0){
	if($oIdstrarr !=NULL){
	
		$levelArr=explode('.',$oIdstrarr);
		$objWhereStr= '';
		
		for($j=0;$j<sizeof($levelArr);$j++)
		{
			$levelNo=$j+1;
			${"level_$levelNo"}=$levelArr[$j];
			$objWhereStr .="level_{$levelNo}"."="."'$levelArr[$j]'"." AND ";
		}
		$objWhereStr = substr($objWhereStr,0,-5);	
		
		$objSql = "SELECT $objNameField,$objSetField,valueType,length,minValue,maxValue FROM $paramConfTable WHERE $objWhereStr";
		$objResult	= mysqli_query($pubConn ,$objSql);
		$objRows	= @mysqli_fetch_array($objResult);
		$totalLen	= $objRows[length]*2;
		$objName	= $objRows[$objNameField];
		$setTemplate = $objRows[$objSetField];
		$valueType	= $objRows[valueType];
		$minValue	= $objRows[minValue];
		$maxValue	= $objRows[maxValue];
		

	{//get $setValue
		if($instanceNo != 'new'){
	
			$paramSql = " SELECT initValue FROM $paramTable  
						WHERE $objWhereStr AND instanceNo = '$instanceNo' 
						";
			
//			echo "$paramSql";
			$v_Result = mysqli_query($pubConn,$paramSql);				
			$v_Row = mysqli_fetch_array($v_Result);
			$setValue = $v_Row[0];
		}else{
			$paramConfTable = 'paramConf';
			$paramSql = " SELECT initValue FROM $paramConfTable  
						WHERE $objWhereStr
						";
			
//			echo "$paramSql";
			$v_Result = mysqli_query($pubConn,$paramSql);				
			$v_Row = mysqli_fetch_array($v_Result);
			$setValue = $v_Row[0];
//				echo "$setValue";
		}				
	}
	
	}else{
		echo "<font><b>ERROR!!:oid == NULL</b></font>";
		exit();
	}
		
	//explode by '[remark]'
	$remarkArr = explode('[remark]',$setTemplate);
	$remark  = $remarkArr[1];
	
	$orderSql = "SELECT paramOBJ ,paramName ,webPageName ,fileOption FROM elementParamConf WHERE paramOBJ ='$oIdstrarr' AND webPageName = '$webname'";
	$orderResult	= mysqli_query($pubConn ,$orderSql);
	$orderRows	= @mysqli_fetch_array($orderResult);
	
	
	$reorder  = $orderRows[fileOption];
	//$reorder  = 'order.2.1-h-100.16.9.5-h-5';
	if($DEBUG) echo "$reorder<br>";
	//explode by '[unit]'
	$unitArr = explode('[unit]',$remarkArr[0]);
	$unitOrderArr = explode('.',$reorder);

  for($i=1;$i<sizeof($unitArr);$i++){
  	 for($j=1;$j<sizeof($unitOrderArr);$j++)
  	 		if($i == $unitOrderArr[$j])
  	 			break;
  	 if($j == sizeof($unitOrderArr))
  	 		$reorder = $reorder.".$i";
  }
  	 		
//  echo 	 		"$reorder";
	$newOrderArr = explode('.',$reorder);	
 // for($i=1;$i<sizeof($unitArr);$i++){
  for($order=1;$order<sizeof($unitArr);$order++){
  	$showflag = 0;
  	$readonly = 0;
  	$def_flag = 0; 	
  	$confArr = explode('-',$newOrderArr[$order]);	
 		if($order< sizeof($unitOrderArr) && $confArr[1] != 'h'){
				$showflag = 1;
		}
  	$i = $confArr[0];
  	if($confArr[1] == 'r'){
  		$readonly = 1; 	
  	}
  	if(isset($confArr[2])){
  		$def_flag = 1; 	
  		$defaultVaule = $confArr[2];
  	}  	
		//unit input name
		$unitName = "unit_".$no.'_'.$i;

		//explode by '[u]'
				
		$tlvArr = explode('[u]',$unitArr[$i]);
		if(sizeof($tlvArr) <= 1 ){
			echo "<u><b>{$unitArr[$i]}</b></u>";
			continue;
		}

		if($instanceNo =='flag'){
			if($tlvArr[0] == 'flag'){
//				echo "$tlvArr[1]";
				return $tlvArr[1];
			}
			else{
				continue;
			}	
		}
		
		
		//explode by '-'
		$offsetArr = explode('-',$tlvArr[1]);
		$bgnOffsetArr = explode('.',$offsetArr[0]);
		$bgnByte = $bgnOffsetArr[0];
		$bgnBit  = $bgnOffsetArr[1];
		$endOffsetArr = explode('.',$offsetArr[1]);
		$endByte = $endOffsetArr[0];
		$endBit  = $endOffsetArr[1];
		$byteLen = $endByte - $bgnByte + 1;
		$byteValue = substr($setValue,$bgnByte*2,$byteLen*2);
		//--><-//$byteValue = strrev($byteValue);
			
	
		if($DEBUG) echo "<br>byteValue = $byteValue";
		$bitValue = '';
		if($bgnBit > 0 ||$endBit < 7){
			if($DEBUG) echo "<br>$bgnBit > 0 ||$endBit < 7";
			$bitValue = HexDec($byteValue);
			$bitValue = DecBin($bitValue);
			if($DEBUG) echo "<br>bitValue = $bitValue";
			$bitLen   = $byteLen*8;//1 byte = 8 bit
			$bitValue = omcStrFill($bitValue,$bitLen,'high','0');
			if($DEBUG) echo "<br>omcStrFill($bitValue,$bitLen,'high','0')";
			
			$bitValue = strrev($bitValue);
			$catBitLen = $endByte*8+$endBit - ($bgnByte*8+$bgnBit) + 1; //1 byte = 8 bit
			if($DEBUG) echo "<br>bitValue = substr($bitValue,$bgnBit,$catBitLen)";
			$bitValue = substr($bitValue,$bgnBit,$catBitLen);
			$bitValue = strrev($bitValue);
			if($DEBUG) echo "<br>bitValue = $bitValue";
		}
	
		//explode by '[v]'
		$valueArr = explode('[v]',$tlvArr[2]);
		$typeAddTitleArr = explode('[t]',$valueArr[0]);
		$operType = chop($typeAddTitleArr[0]);
		$titleStr = chop($typeAddTitleArr[1]);
		$valueArr[1] = chop($valueArr[1]);
	
		if($showflag){
			if($webname=="BSC")
				echo "\n <tr style=\"DISPLAY: none\"><td width=\"50%\"  title=\"$titleStr\" valign=middle>";
			else
				echo "\n <tr><td width=\"50%\"  title=\"$titleStr\" valign=middle>";	
		}else{
			echo "\n <tr style=\"DISPLAY: none\"><td width=\"50%\"  valign=middle>";
		}
		
		//show Unit Name
		echo "$tlvArr[0]";

		echo "&nbsp;</td><td>";
		if($DEBUG) echo "$tlvArr[1]";
		
		if($DEBUG) echo "<br>operType = $operType";
		switch($operType){
			case 'input'://
				//explode by '-'
				$defArr = explode('-',$valueArr[1]);
				if($DEBUG) echo "<br>defArr = $defArr[0],$defArr[1],$defArr[2]";
				switch($defArr[0]){
					case 'toDec':
						if(strlen($bitValue) > 0){
							$inputValue = BinDec($bitValue);
						}else{
							$inputValue = HexDec($byteValue);
						} 
						break;
					case 'keepDec':
						$inputValue = $byteValue;
						break;
					case 'toHex':
						echo "<br>Error:toHex";
						break;
					case 'keepHex':
						$inputValue = $byteValue;
						break;
					case 'toAscii':
						$charValue = "";
						if($bgnBit > 0 ||$endBit < 7){
							echo "<br>Error:toAscii";
							exit(1);
						}else{
							$tmpLen=strlen($byteValue);
							for($charCount=0;$charCount<$tmpLen;$charCount++){
								$unitByte = substr($byteValue,$charCount,2);
								//$unitChar = chr(HexDec($unitByte)); // hex -> ascii
								$unitChar = chr(HexDec($unitByte)); // hex -> ascii
								if($DEBUG) echo "<br>unitChar=$unitChar";
								$charValue .= $unitChar;
								$charCount++;
							}
							$charValue = trim($charValue);
							$inputValue = $charValue;
						}
						break;
					default: 
						echo "<br>Error:valueType=$defArr[0]";
						break;
				}
				if($DEBUG) echo "<br>inputValue = $inputValue";
				switch($defArr[1]){
					case 'high':
						switch($defArr[2]){
							case '0':
								if($defArr[0] == 'toHex' || $defArr[0] == 'keepHex'){
									//$inputValue = str_replace('0','',$inputValue);
								}else{
									$inputValue = $inputValue - 0;
								}
								break;
							case 'E':
								echo "Error:high fill E";
								break;
							default: break;
						}
						break;
					case 'low':
						if ("toAscii" != $defArr[0]) {
							switch($defArr[2]){
								case '0':
									$inputValue = str_replace('00','',$inputValue);
									break;
								case 'E':
									$inputValue = str_replace('E','',$inputValue);
									break;
								case 'F':   //modify zane 20051004
									$inputValue = str_replace('F','',$inputValue);
									break;	
								default: break;
							}
						}
						break;
					default: break;
				}
				if($DEBUG) echo "<br>$valueType == $nOctStr";
				if($def_flag){
					$inputValue	= $defaultVaule;
				}				
				if($valueType == $nOctStr){
					if($defArr[0] == 'toAscii'){
						$inputLen = $byteLen;
					}elseif($defArr[0] == 'toHex' || $defArr[0] == 'keepHex'){
						$inputLen = $byteLen *2;
					}else{
						$inputLen = $byteLen *3;
					}
					//echo "<input type=\"text\" size=\"$inputLen\" maxLength =\"$inputLen\" name=\"$unitName\" value=\"$inputValue\" class=\"text\">";
					if($readonly){
						echo "<input type=\"text\" style=\"DISPLAY: none\" style=width:\"$nShowsize\" maxLength =\"$inputLen\" name=\"$unitName\" value=\"$inputValue\" class=\"text\">";
						echo "$inputValue";
					}else{
						echo "<input type=\"text\" style=width:\"$nShowsize\" maxLength =\"$inputLen\" name=\"$unitName\" value=\"$inputValue\" class=\"text\">";
					}
					
				}else{
					//echo "<input type=\"text\" size=\"8\" name=\"$unitName\" value=\"$inputValue\" onchange=\"checkInt(this)\" class=\"text\">";
					if($readonly){
						echo "<input type=\"text\" style=\"DISPLAY: none\" style=width:\"$nShowsize\" name=\"$unitName\" value=\"$inputValue\" onchange=\"checkInt(this)\" class=\"text\">";
						echo "$inputValue";
					}else{
						echo "<input type=\"text\" style=width:\"$nShowsize\" name=\"$unitName\" value=\"$inputValue\" onchange=\"checkInt(this)\" class=\"text\">";
					}
					echo "<input type=\"hidden\" name=\"$unitName"."_min\" value=\"$minValue\">";
					echo "<input type=\"hidden\" name=\"$unitName"."_max\" value=\"$maxValue\">";
					echo "<input type=\"hidden\" name=\"$unitName"."_old\" value=\"$inputValue\">";
				}
				break;
			case 'select':
				if($valueType == $nOctStr){
					if($bitValue != ''){
						$selectValue = BinDec($bitValue);
					}else{
						$selectValue = HexDec($byteValue);
					}
				}else{
					$selectValue=$byteValue;
				}
				if($def_flag){
					$selectValue	= $defaultVaule;
				}					
	
				if($DEBUG) echo "<br>bitValue = $bitValue";
				if($DEBUG) echo "<br>selectValue = $selectValue";
				if($DEBUG) echo "<br>$valueType =?= $nOctStr(nOctStr)";
				if($readonly){
					echo "<select size=\"1\" name=\"$unitName\" style=\"DISPLAY: none\" style=width:\"$nShowsize\">";					
				}else{
					echo "<select size=\"1\" name=\"$unitName\" style=width:\"$nShowsize\">";
				}
				$isSelected = 0;
				for($j=1;$j<sizeof($valueArr);$j++){
					//explode by '[opt]'
					$defArr = explode('[opt]',$valueArr[$j]);
					if(sizeof($defArr) < 2){
						echo "<option value=\"$selectValue\" selected>Reserved Value</option>";
						$selectshwo = "Reserved Value";
						break;
					}elseif($defArr[0] ==  $selectValue){
						
							echo "<option value=\"$defArr[0]\" selected>$defArr[1]</option>";
						
						$selectshwo ="$selectValue";
						$isSelected = 1;
					}else{
						echo "<option value=\"$defArr[0]\">$defArr[1]</option>";
					}
				}
				
				if($isSelected ==0 && $j == sizeof($valueArr)){
					echo "<option value=\"$selectValue\" selected>Undefined Value</option>";
					$selectshwo = "Undefined Value";			
				}
				echo "</select>";
				if($readonly){
					echo "$selectshwo";
				}															
				break;
			default: echo "<br>Error:operType =|$operType|";
				break;
		}//end of switch(..)
		//like:unitDef_1 = 1.0-2.0-select-keepHex-high-0 -->$tlvArr[1]-$operType-
		
		if($operType == 'select'){ //select
			if($valueType == $nOctStr){
				$tempDef = $tlvArr[1].'-'.$operType.'-'.'toDec-high-0';
			}else{
				$tempDef = $tlvArr[1].'-'.$operType.'-'.'keepDec-high-0';
			}
		}else{
			$tempDef = $tlvArr[1].'-'.$operType.'-'.$valueArr[1];
		}
		$tempDef = str_replace(" ", "", $tempDef);
		$tempDef = chop($tempDef);
		$unitDefName = "unitDef_".$no.'_'.$i;
		echo "\n <input type=\"hidden\" name=\"$unitDefName\" value=\"$tempDef\">";
		echo "</td></tr>";
	}//end of for(..)
		
	$unitNum = $order-1; 
	
	echo "\n<input type=\"hidden\" name=\"unitNum_$no\" value=\"$unitNum\">";
} 
?>
<script LANGUAGE="JavaScript">  
	
	function checkInput_patch(term)
	{
		
		
		term.value = term.value.toUpperCase();
		var checkStr = term.value;	
		
		var checkOK="0123456789";
		/*
		for (i = 0;  i < checkStr.length;  i++){
			ch = checkStr.charAt(i);
			for (j = 0;  j < checkOK.length;  j++){
				if (ch == checkOK.charAt(j))
					break;
			}
			if (j == checkOK.length){
				allValid = false;
				break;
			}
		}*/
		
		//if (!allValid){  
		if(isNaN(checkStr))
		{
			alert("Parameter must be a decimal value！");
			term.focus();
			term.value = 0;
			return (false);
		}	
		
	}
function checkInput(term,flag,maxValue,minValue)
{
	term.value = term.value.toUpperCase();
    if (flag == 16)
    {
    	var checkOK = "0123456789ABCDEF";
    	var showmsg ="Parameter must be a hexadecimal value";
    }
    else 
    {
    	var checkOK = "0123456789";
    	var showmsg ="Parameter must be a decimal value";
    }

    var checkStr = term.value;
    var allValid = true;
    for (i = 0;  i < checkStr.length;  i++){
		ch = checkStr.charAt(i);
		for (j = 0;  j < checkOK.length;  j++){
			if (ch == checkOK.charAt(j))
				break;
		}
		if (j == checkOK.length){
			allValid = false;
			break;
		}
	}
	if(checkStr == '')
	{
		showmsg = "Parameter can't be blank";
		alert(showmsg+"！");	
	}
	
	if (!allValid){  
		alert(showmsg+"！");
		term.focus();
		term.value = 0;
		return (false);
	}
	if (maxValue != 0)
	{
		if (checkStr >= maxValue)
		{
			showmsg = "Parameter must less then "+ maxValue;
			alert(showmsg+"！");
			term.value = maxValue;
			term.focus();
			return (false);
		}
	}
	if (minValue != '')
	{
		if (checkStr < minValue)
		{
			maxValue = maxValue;
			showmsg = "Parameter must between "+ minValue + " and " + maxValue;
			alert(showmsg+"！");
			term.value = minValue;
			term.focus();
			return (false);
		}
	}
}
function selCheckBox(thisCheckBox)
{
	if(thisCheckBox.checked == true){
		thisCheckBox.value=1;
	}else{
		thisCheckBox.value=0;
	}
}
function CheckInsNo(insNo)
{
	if(insNo == -1)
	{	
		alert("Unable to add!The parameter table is full!");
	}
}

function selectAllToDel(formName,flag,thisCheckBox,bgnNo,endNo)
{
	var p;
	var tmpCheckBox;
	if(thisCheckBox.checked == true)
	{
		for(p=bgnNo; p < endNo; p++){
			tmpCheckBox=eval("document."+formName+"."+flag+"checkBox_"+p);
			tmpCheckBox.checked = true;
			tmpCheckBox.value=1;
		}
	}else{ 
		for(p=bgnNo; p < endNo; p++){
			tmpCheckBox=eval("document."+formName+"."+flag+"checkBox_"+p);
			tmpCheckBox.checked = false;
			tmpCheckBox.value=0;
		}
	}
}

function delSelected(formName,flag,bgnNo,endNo,addurl)
{
	y = document.body.scrollTop;
	
	var haveSelected = 0;
	for(p=bgnNo; p < endNo; p++)
	{
		tmpCheckBox=eval("document."+formName+"."+flag+"checkBox_"+p);
		if(tmpCheckBox.value==1)
		{
			haveSelected = 1;
			break;
		}
	}
	if(haveSelected==0)
	{
		alert("Select elements, first!");
		return;
	}
	if(confirm('Do you want to delete the selected?') != true)
		return;
	else
	{
		var p;
		var delNoStr;
		var tmpCheckBox;
		var tmpDelNo;
		delNoStr='';
		for(p=bgnNo; p < endNo; p++)
		{
			tmpCheckBox=eval("document."+formName+"."+flag+"checkBox_"+p);
			tmpDelNo=eval("document."+formName+"."+flag+"deleteno_"+p);
			if(tmpCheckBox.value==1)
			{
				delNoStr += tmpDelNo.value + '.';
			}
		}
		window.location.href='<?php echo $PHP_SELF;?>?&delNoStr='+delNoStr+'&delflag='+flag+'&scroll_y='+y+'&'+addurl;
	}

}


function selectToDel(thisCheckBox)
{
	if(thisCheckBox.checked == true)
		thisCheckBox.value=1;
	else
		thisCheckBox.value=0;
}


function newError(errtype)
{
	switch(errtype){
		case 'BTS':
			window.alert("There is no BTS to added!");
			break;
		case 'E1':
		case 'AAS':
			window.alert("There is no E1 to added!");
			break;
		case 'LAC':
			window.alert("Please Set LAC First!");
			break;
		default:
			window.alert("Add Error!");
	}			
}
function backpage(flag,backurl)
{
	if(flag){
		if(confirm('Do you want back without save your change?')==true){
			window.location.href=backurl;			
		}else{
			history.go(-1)			
		}	
	}else{
		window.location.href=backurl;
	}
}

function checkIP(item)
{
	var pattern=/^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/;
//	var pattern =/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/;
	if(!pattern.test(item.value))		
	{
		alert("IP address format error!");
		this.focus();
	}
}

</script>


<style type="text/css">
<!--
.style3 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 8pt;background: url(--.gif); border: 0px; width: 30px; height: 17px;color:blue}
.style4 {cursor:pointer;font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 8pt;background: url(--.gif); border: 0px 0; width: 30px; height: 17px;color:red; text-decoration: underline }
.style5 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 8pt;background: url(--.gif); border: 0px; width: 60px; height: 13px;color:blue}
.style6 {cursor:pointer;font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 8pt;background: url(--.gif); border: 0px 0; width: 60px; height: 13px;color:red; text-decoration: underline }
.style7 {font-family: Verdana, Arial, Helvetica, sans-serif; font-weight:bold; font-size: 8pt;background: url(--.gif); border: 0px; width: 30px; height: 17px;color:blue}
.style8 {cursor:pointer;font-family: Verdana, Arial, Helvetica, sans-serif; font-weight:bold; font-size: 8pt;background: url(--.gif); border: 0px 0; width: 30px; height: 17px;color:red; text-decoration: underline }
.style9 {font-family: Verdana, Arial, Helvetica, sans-serif; text-align:left;font-size: 8pt; border: 0px; height: 16px;}
-->
</style> 

<?php
	$buttonStyle = "cursor:pointer; left: 1; top: 2; width: 80; height: 22; position: relative";
?>
