<?php 
/*********************************************************    
利用原模板程序显示需设置的参数
目前应范围在：linkset参数,TG参数,Prefix参数,BTS参数。。。

*********************************************************/    
//require("../../inc/header.inc");
require("../sub_inc/commfunc.php");
?>
<script language="JavaScript">
	function protocol_stack_select_change()
	{
		var p_stack=document.confForm.protocol_stack_select.value;
		//==ITU
		if(p_stack==0)
		{
			document.confForm.nfas_flag_select.disabled=1;
			document.confForm.Primary_D_channel_text.disabled=1;
			document.confForm.Backup_D_channel_text.disabled=1;
		}
		//==ANSI
		else
		{
			document.confForm.nfas_flag_select.disabled=0;
			document.confForm.Primary_D_channel_text.disabled=0;
			document.confForm.Backup_D_channel_text.disabled=0;
		}
	}
	function radio_channel_control_select_change()
	{
		var r_channel_control=document.confForm.radio_channel_control_select.value;
		//alert(r_channel_control);
		//======depend on ms
		if(r_channel_control==0)
		{
			document.confForm.full_rate_speech_v3_checkbox.disabled=1;
			
			document.confForm.full_rate_speech_v2_checkbox.disabled=1;
			document.confForm.full_rate_speech_v1_checkbox.disabled=1;
			document.confForm.half_rate_speech_v3_checkbox.disabled=1;
			document.confForm.half_rate_speech_v1_checkbox.disabled=1;
			
		}
		//======control by operator
		else
		{
			document.confForm.full_rate_speech_v3_checkbox.disabled=0;
			
			document.confForm.full_rate_speech_v2_checkbox.disabled=0;
			document.confForm.full_rate_speech_v1_checkbox.disabled=0;
			document.confForm.half_rate_speech_v3_checkbox.disabled=0;
			document.confForm.half_rate_speech_v1_checkbox.disabled=0;
			
		}
	}
	function select_checkbox(thisCheckBox)
	{
		
		if(thisCheckBox.checked == true)
		{
			thisCheckBox.value=1;
			
		}
		else
		{
			thisCheckBox.value=0;
			
		}
		//alert(thisCheckBox.value);
	}
</script>
<?php
$DEBUG	= 0;

//value Type
//$backurl = rawurldecode($backurl);
//*****
//$url_temp=$_SERVER["REQUEST_URI"];
//echo "This page URL:$url_temp<br>";




$sysIdArr	= explode('_',$sysId);
$sysTypeNo	= $sysIdArr[0];
$sysNo		= $sysIdArr[1];
$subSysNo	= $sysIdArr[2];

$objDb		= 'OBJ_'.$sysTypeNo;
$paramTable = 'param_'.$sysNo;

function checkInput($upstr,$flag)
{   
    if ($flag == 16)
    {
    	$checkOK = "0123456789ABCDEF";
    	$checkOK_length = 16;
    	$showmsg ="Parameter must be a hexadecimal value!";
    }
    else 
    {
    	$checkOK = "0123456789";
    	$checkOK_length = 10;
    	$showmsg ="Parameter must be a decimal value!";
    }

    $checkStr = $upstr;
    $allValid = 1;
    $chkstr_len = strlen($checkStr);
    for ($i = 0;  $i < $chkstr_len;  $i++){
		$ch = substr($checkStr,$i,1);
		for ($j = 0;  $j < $checkOK_length;  $j++){
			if ($ch == substr($checkOK,$j,1))
				break;
		}
		if ($j == $checkOK_length){
			$allValid = 0;
			break;
		}
	}
	
	if (!$allValid){  
		echo "<script language='javascript'>";  
		echo "window.alert(\"$showmsg\");";	
		echo "history.go(-1)";
		echo "</script>";						
		exit();
	}
}

function omcGetObjDb($sysTypeNo){
	$dbName = 'OBJ_'.$sysTypeNo;
	return($dbName);
}

function omcGetObjTbl($sysTypeNo,$tableType){
	$dbName = 'OBJ_'.$sysTypeNo;
	$tableName = $dbName.'.paramConf';
	return($tableName);
}

//=======================Get value From submit===================
//$unit_x_y表示显示页面第x组oid，第y个参数
if($set == 'Save')
{
	
	
	$oIdstrarr = explode('-',$objIdStr);	
	$externID = explode('-',$instanceNo);
	if($instanceNo == 'new')
	{
		$instanceNo = $newID;
	}
	//保存前检查Prefix设置参数
	if($setname == 'Prefix')//check prefix valid arwean: 
	{		
		$sysId = '322_99_99';
		
		$sysIdArr	= explode('_',$sysId);
		$sysTypeNo	= $sysIdArr[0];
		$sysNo		= $sysIdArr[1];
		$subSysNo	= $sysIdArr[2];
		
		$objDb		= 'OBJ_'.$sysTypeNo;
		$paramTable = 'param_'.$sysNo;
		
		{//get all valid prefix No
		$oidstr = '2.1.2';
		$objWhereStr= '';
		$objWhereStr =getLevelWhere($oidstr);		
		
		$defSql = " SELECT initValue,instanceNo FROM $paramTable WHERE $objWhereStr ORDER BY instanceNo";
		//echo $defSql;
		$defRes = @mysqli_query($pubConn,$defSql);
		echo mysqli_error($pubConn);
		$offset_enable = "10.7-10.7";
		$offset_Properties = "10.2-10.3";	
		$offset_calltype = "10.4-10.6";
		$offset_ton_in = "0.0-0.3";
		$offset_ton_out="0.4-0.7";
		$prefix_num=0;	
		while($row = @mysqli_fetch_array($defRes))
		{
			$prefix_enable=hexdec(getBitValue($row[initValue],$offset_enable));
			if($prefix_enable)//enable
			{
				$validPrefix[$prefix_num][inst_no]=$row[instanceNo];
				$validPrefix[$prefix_num][init_value]=$row[initValue];
				$validPrefix[$prefix_num][ton_in]=BinDec(getBitValue($row[initValue],$offset_ton_in));
				$validPrefix[$prefix_num][ton_out]=BinDec(getBitValue($row[initValue],$offset_ton_out));
//				echo "<br>".$prefix_num . ": ".$validPrefix[$prefix_num][inst_no];
//				echo "validPrefix[$prefix_num][ton_in]: {$validPrefix[$prefix_num][ton_in]}";
				$prefix_num++;

			}
		}	
		}//end get valid prefix No
		
		{//get prefix value
		$oidstr = '2.1.1';
		$objWhereStr= '';
		$objWhereStr =getLevelWhere($oidstr);	
		
		$paramSql = " SELECT initValue,readValue,instanceNo FROM $paramTable  
					WHERE subSysNo = '$subSysNo' AND  $objWhereStr
					ORDER BY instanceNo 
					";
		//				echo "$paramSql";
		$Result_1 = mysqli_query($pubConn,$paramSql);	
		$prefix_no=0;			
		while($Row_1 = mysqli_fetch_array($Result_1))
		{
			if($Row_1[instanceNo]==$validPrefix[$prefix_no][inst_no])
			{
				$tempprefix=strtoupper($Row_1[initValue]);
				$prefix = explode('E',$tempprefix);
				if($prefix[0] =="")
					$prefix[0]="--";
				$validPrefix[$prefix_no][prefix]=$prefix[0];
				//echo "<br>asas->".$validPrefix[$prefix_no][prefix];
				$prefix_no++;
			}
			if($prefix_no >= $prefix_num)
				break;		
		}
		}//end get prefix value
		//exit;
		$setPrefix = strtoupper($unit_1_1);
		$setTonIn = $unit_2_1;
		$setTonOut = $unit_2_2;

		for($i=0; $i< $prefix_num; $i++)
		{
			//echo "<br>".$validPrefix[$i][inst_no].":".$validPrefix[$i][prefix].":".$validPrefix[$i][ton_in].":".$validPrefix[$i][ton_out];
			if($instanceNo==$validPrefix[$i][inst_no])
				continue;
			if(($setPrefix==$validPrefix[$i][prefix])
				&&($setTonIn==$validPrefix[$i][ton_in])
				/*&&($setTonOut==$validPrefix[$i][ton_out])*/)
			{
				echo "<script language='javascript'>";  
				echo "window.alert(\"Prefix, TON_in are all the same to PrefixNo:{$validPrefix[$i][inst_no]},Please check!\");";
				echo "history.go(-1)";
				echo "</script>";											 		
				exit();
			}
		}
	}
	//保存前检查dpc有没有设重
	//$unit_1_1表示显示页面是 第1组oid，第1个参数
	//$unit_1_2表示显示页面是 第1组oid，第2个参数
	if($setname =='Linkset')
	{
		checkInput($unit_1_1,10);	
		
		$tmpDb = 'OBJ_222';
		$tmpTable = 'param_99';
		$tmpoid = '2.4.1';
		$objWhereStr = getLevelWhere($tmpoid);
		
		$setDPC = omc_keep_length(dechex($unit_1_1),0,6);
		$setDPC = strtoupper($setDPC);
		$setNetID = $unit_1_2;
		
		if($webname!='CNF')//cnf与cnf的dpc和ni可以重复。
		{	
			//dpc ni不能设重
			$paramSql = " SELECT initValue,readValue,instanceNo FROM $tmpTable  
						WHERE $objWhereStr AND instanceNo !='$linkset' 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(\"DPC,Network indicator is already used!\");";
					echo "history.go(-1)";
					echo "</script>";											 		
					exit();
				}
			}
		}

		//不能与 spc 重复
		{
		$oidstr = '2.2';
		$link_Db = 'OBJ_222';	
		$link_Table  = 'param_99';
		
		$subSysNo = 99;
		$spcobjWhereStr= '';
		$spcobjWhereStr =getLevelWhere($oidstr);
		$paramSql = " SELECT initValue,readValue,instanceNo FROM $link_Table  
					WHERE $spcobjWhereStr
					";
		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;
		$spcobjWhereStr= '';
		$spcobjWhereStr =getLevelWhere($oidstr);
		$paramSql = "SELECT initValue FROM $link_Table
								WHERE $spcobjWhereStr AND instanceNo = '0'
								";									
		$Result   = mysqli_query($pubConn,$paramSql);
		$Row	= mysqli_fetch_array($Result);
		$WXC2DPC = strtoupper($Row[initValue]);
		
		//$setDPC is hex
//		if($setDPC == $WXC2PC)
		if(hexdec($setDPC) == hexdec($WXC2DPC))
		{
			echo "<script language='javascript'>";  
			echo "window.alert(\"DPC,Network indicator is already used!\");";
			echo "history.go(-1)";
			echo "</script>";											 		
			exit();				
		}
		}
											
		//old dpc NI
		$paramSql = " SELECT initValue,readValue,instanceNo FROM $tmpTable  
					WHERE $objWhereStr AND instanceNo ='$linkset' 
					";
		$Result = mysqli_query($pubConn,$paramSql);				
		$Row		= mysqli_fetch_array($Result);
		$oldDPC 	= hexdec(getBitValue($Row[initValue],'0.0-2.7'));		
		$oldNetID 	= getBitValue($Row[initValue],'3.0-3.1');			
		$oldNetID	= bindec($oldNetID);

		if($DEBUG)	echo "Row[initValue] = $Row[initValue]<br>";
		if($DEBUG)	echo "oldNetID = $oldNetID<br>";		
		
		//TG未定,选择一条未用的TG
		if($trunkgp =="" && !($webname =='HLR' ||$webname =='VLR' || $webname =='MSC'||$webname=='SMSC')){
			$TGsysId = '322_99_99';			
			$TG_sysIdArr	= explode('_',$TGsysId);
			$TG_sysTypeNo	= $TG_sysIdArr[0];
			$TG_sysNo		= $TG_sysIdArr[1];
			$TG_subSysNo	= $TG_sysIdArr[2];
			
			$TG_oidstr = '2.1.4';
			$TG_objWhereStr = getLevelWhere($TG_oidstr);	
			$TG_objDb		= 'OBJ_'.$TG_sysTypeNo;
			$TG_paramTable = 'param_'.$TG_sysNo;
			
			$TG_defSql = " SELECT initValue FROM paramConf WHERE $TG_objWhereStr";
			$TG_defRes = @mysqli_query($pubConn,$TG_defSql);
			$TG_row = @mysqli_fetch_array($TG_defRes);
			
			$TG_paramSql = " SELECT initValue,readValue,instanceNo FROM $TG_paramTable  
						WHERE $TG_objWhereStr AND initValue ='$TG_row[initValue]' 
						";	
			if($DEBUG)  echo "TG_paramSql = $TG_paramSql<br>";					
			$TG_Result = mysqli_query($pubConn,$TG_paramSql);				
			$TG_Row		 = mysqli_fetch_array($TG_Result);
			$trunkgp = $TG_Row[instanceNo];
			$strnew = "trunkgp=".$trunkgp;
			$backurl = str_replace("trunkgp=",$strnew,$backurl);
			if($DEBUG)  echo "instanceNo = $TG_Row[instanceNo]<br>";					
			$flagoffset = "4.0-4.0";			
			$TG_Row[initValue] = setBitValue($TG_Row[initValue],$flagoffset,1);
			$TG_Row[initValue] = strtoupper($TG_Row[initValue]);
			$TG_upSql = "UPDATE $TG_paramTable SET initValue = '$TG_Row[initValue]' 
		            WHERE $TG_objWhereStr AND instanceNo='$trunkgp'";
		  if($DEBUG)  echo "GPGPGPPGPGPGPGP = $trunkgp<br>";
			$delRes = @mysqli_query($pubConn,$TG_upSql);
			echo mysqli_error($pubConn);		
		}
	}
	//保存前检查BTS设置参数
	//$unit_1_4表示显示页面是 第1组oid，第4个参数
	if($setname=='BTS')
	{
		if($unit_1_1==1)//Emergency Call flag==by Cell.
		{//CELL ID 不能设重
			$objstrset='2.2.7';
			$objWhereStr =getLevelWhere($objstrset);				
			$paramSql = " SELECT initValue,readValue,instanceNo FROM $paramTable  
			WHERE $objWhereStr AND instanceNo!='$externID[0]'
			";			
			$Result = mysqli_query($pubConn,$paramSql);				
			
			while($Row=mysqli_fetch_array($Result))
			{
				$CELLID=hexdec(getBitValue($Row[initValue],'03.0-04.7'));					
				$cellPrefix=hexdec(getBitValue($Row[initValue],'5.0-5.7'));					
				if($CELLID==$unit_1_3 && $set_PrefixNo == $cellPrefix)
				{
					echo "<script language='javascript'>"; 
					if($unit_1_3==0)
						 echo "window.alert(\"Cell ID should not be zero!\");";
					else
						echo "window.alert(\"Cell ID is already used!\");";
					echo "history.go(-1)";
					echo "</script>";											 		
					exit();					
				}
			}						
		}
		
		$objstrset='2.2.7';
		$objWhereStr =getLevelWhere($objstrset);				
		$paramSql = " SELECT initValue,readValue,instanceNo FROM $paramTable  
		WHERE $objWhereStr AND instanceNo ='$instanceNo'
		";
		$Result = mysqli_query($pubConn,$paramSql);				
		$Row		= mysqli_fetch_array($Result);
		if($DEBUG) echo "$paramSql<br>";
		if($DEBUG) echo "$Row[initValue]<br>";
		$Em_prefix_old = hexdec(getBitValue($Row[initValue],'05.0-5.7'));
	}
	
	
	for($j=1;$j<sizeof($oIdstrarr);$j++)
	{
		if($setname == 'Linkset' ||$setname == 'Trunk Group' ||$setname =='CIC')
		{
			$tmp = $j -1;
			$instanceNo = $externID[$tmp];
		}
		if($setname == 'BTS')
		{
			$instanceNo = $externID[0];			
		}
		
		{//gather setValue
		//sort by offset
//			echo "${'unitNum_'.$j}-";
//			echo "$unitDef_1_1";
//			echo "<br>$oIdstrarr[$j]";
		$unitNum = ${'unitNum_'.$j};
//			echo "<br>num:$unitNum<br>";
		for($i=1;$i<=$unitNum;$i++)
		{
			$tmpDef = ${'unitDef_'.$j.'_'.$i};
			$tmpValue = ${'unit_'.$j.'_'.$i};
			if($DEBUG) echo "<br>tmpDef = $tmpDef";
			$defArr[$j][$i] = $tmpDef;
			$tmpDefArr[$j] = explode('-',$tmpDef);
			$sortArr[$j][$i] = $tmpDefArr[$j][0];
			$valueArr[$j][$i] = $tmpValue;
			
//				echo "$tmpValue<br>";

		}
		$lastValue = '';
		$k = 0;
		
		asort($sortArr[$j]);
		for(reset($sortArr[$j]); $key = key($sortArr[$j]); next($sortArr[$j]))
		{
			$unitValue = $valueArr[$j][$key];

			$unitDefArr = explode('-',$defArr[$j][$key]); //例:0.0-0.7-input -toDec-high-0
			if(sizeof($unitDefArr) <= 1)
			{
					if($DEBUG) echo "<br>nothing,just a name";
					continue;
			}
			$bgnOffset	= $unitDefArr[0];
			$endOffset	= $unitDefArr[1];
			$operType	= $unitDefArr[2];
			$valueType  = $unitDefArr[3];
			$fillWay	= $unitDefArr[4];
			$fillChar	= $unitDefArr[5];
			
			$bgnOffsetArr = explode('.',$bgnOffset);
			$bgnByte = $bgnOffsetArr[0];
			$bgnBit  = $bgnOffsetArr[1];
			$endOffsetArr = explode('.',$endOffset);
			$endByte = $endOffsetArr[0];
			$endBit  = $endOffsetArr[1];
			$byteLen = $endByte - $bgnByte + 1;
			$byteValue = '';
			if($DEBUG) echo "<br>valueType = $valueType";
			switch($valueType)
			{
				case 'toDec':
					if($bgnBit > 0 ||$endBit < 7)
					{
						$bitLen = $byteLen*8 - $bgnBit - (7 - $endBit) ; //1 BYTE = 8 bit
						$bitValue = DecBin($unitValue);
						if($DEBUG) echo "<br>bitValue = $bitValue ";
						$bitValue  = omcStrFill($bitValue,$bitLen,$fillWay,$fillChar);
						if($DEBUG) echo "<br>omcStrFill($bitValue,$bitLen,$fillWay,$fillChar)";
						$bitValueArr[$k] = $bitValue;
						if($DEBUG) echo "<br>bitValueArr[$k] = {$bitValueArr[$k]}";
						if($endBit == 7)
						{//发现这个单元结束，并没有跨byte，这时需要组成一个byte值
							$bitValue = '';
							for($bitNo=0; $bitNo<=$k; $bitNo++)
							{
								if($DEBUG) echo "<br>bitValueArr[$bitNo] = {$bitValueArr[$bitNo]}";
								$bitValue = $bitValueArr[$bitNo].$bitValue;
							}
							$k=0;
							if($DEBUG) echo "<br>bitValue = $bitValue";
							$byteLen = strlen($bitValue) / 8;
							if($DEBUG) echo "<br>byteLen = $byteLen";
							$byteValue = BinDec($bitValue);
							$byteValue = DecHex($byteValue);
							$strLen = $byteLen*2;
							if($DEBUG) echo "<br>omcStrFill($byteValue,$strLen,$fillWay,$fillChar)";
							$byteValue = omcStrFill($byteValue,$strLen,$fillWay,$fillChar);
						}
						else
						{//否则，继续组合下一个bit组
							$byteValue = '';
							$k++;
						}
					}
					else
					{
						$byteValue = DecHex($unitValue);
						$strLen = $byteLen*2;
						$byteValue = omcStrFill($byteValue,$strLen,$fillWay,$fillChar);
						if($DEBUG) echo "<br>omcStrFill($byteValue,$strLen,$fillWay,$fillChar)";
					}
					if($DEBUG) echo "<br>byteValue = $byteValue";
					break;
				case 'keepDec':
					//echo "<br>Error:keepDec";
					$byteValue = $unitValue - 0;
					break;
				case 'toHex':
					echo "<br>Error:toHex";
					break;
				case 'keepHex':
					if($bgnBit > 0 || $endBit < 7)
					{//这里的处理不够全面,没有对=7的进行收尾
						$byteValue = $unitValue;
						$strLen = $byteLen;
						$byteValue = omcStrFill($byteValue,$strLen,$fillWay,$fillChar);
						$bitValue = DecBin(HexDec($byteValue));
						$byteValue='';
						$bitLen = $byteLen*8 - $bgnBit - (7 - $endBit) ; //1 BYTE = 8 bit
						$bitValue  = omcStrFill($bitValue,$bitLen,'high','0');
						if($DEBUG) echo "<br>bitValue = $bitValue";
						$bitValueArr[$k] = $bitValue;
						$k++;
					}
					else
					{
						$k=0;
						$byteValue = $unitValue;
						$strLen = $byteLen*2;
						$byteValue = omcStrFill($byteValue,$strLen,$fillWay,$fillChar);
						if($DEBUG) echo "<br>omcStrFill($byteValue,$strLen,$fillWay,$fillChar)";
					}
					break;
				case 'toAscii':
					if($bgnBit > 0 ||$endBit < 7)
					{
						echo "<br>Error:toAscii";
						exit(1);
					}
					else
					{
						$tmpLen=strlen($unitValue);
						for($i=0;$i<$tmpLen;$i++)
						{
							$unitChar = substr($unitValue,$i,1);
							$decValue = ord($unitChar); //ascii -> dec
							$byteValue .= DecHex($decValue);
							if(strlen($byteValue) < 2)
							{
								$byteValue = '0'.$byteValue;
							}
						}
						$strLen = $byteLen*2;
						$byteValue = omcStrFill($byteValue,$strLen,$fillWay,$fillChar);
					}
					break;
				default: 
					echo "Error:Unknown valueType";
					break;
			}
			if($DEBUG) echo "<br>byteValue  = $byteValue ";
			//--><-//$lastValue = $byteValue.$lastValue;
			$lastValue = $lastValue.$byteValue;

		}
		
		if($DEBUG) echo "<br>lastValue  = $lastValue ";
		$setValue = $lastValue;
		}
		
		{
		$objWhereStr =getLevelWhere($oIdstrarr[$j]);
		$setValue = strtoupper($setValue);
		checkInput($setValue,16);
		$updSql = "UPDATE $paramTable SET initValue = '$setValue'   
				WHERE $objWhereStr AND instanceNo = '$instanceNo'
				";
		mysqli_query($pubConn,$updSql);	
		echo mysqli_error($pubConn);			
		}
	}
	if($setname=='BTS')
	{
		{//update the lac value of cell
		$sysId = '322_99_99';
		$sysIdArr	= explode('_',$sysId);
		$sysTypeNo	= $sysIdArr[0];
		$sysNo		= $sysIdArr[1];
		$subSysNo	= $sysIdArr[2];
		$oidstr = '2.2.7';
		$objWhereStr =getLevelWhere($oidstr);
		
		$objDb		= 'OBJ_'.$sysTypeNo;
		$paramTable = 'param_'.$sysNo;
		
		$istNo = $externID[0];
		//$lacValue = $externID[1];
		$lacValueHex = omc_keep_length(strtoupper(dechex($LAC)),0,4);
		$selSql = "select initValue from $paramTable where $objWhereStr  AND instanceNo ='$istNo'";
		$Result = mysqli_query($pubConn,$selSql);
		echo mysqli_error($pubConn);
		$row=@mysqli_fetch_array($Result);
		$setValue = $row[initValue];
		$setValue = setBitValue($setValue,'1.0-2.7',$lacValueHex);
		$updSql = "update $paramTable set initValue = '$setValue'
						where $objWhereStr AND instanceNo ='$istNo' ";
		mysqli_query($pubConn,$updSql);
		}
	}
	
{//关联参数设置
	$oIdstrarr = explode('-',$objIdStr);
	switch($setname)
	{
		case 'Trunk Group':
		{
			if($webname!='BSC')//bsc don't need to set alternative TG
			{//add by arwean
				$objstrset='2.1.4';
				$objWhereStr =getLevelWhere($objstrset);
			
				$paramSql = " SELECT initValue FROM $paramTable  
										WHERE $objWhereStr AND instanceNo ='$trunkgp' 
										";
				$Result = mysqli_query($pubConn,$paramSql);				
				$Row		= mysqli_fetch_array($Result);
				
				$hex_setAltTg = strtoupper(DecHex($set_AlterTg));
				$hex_setAltTg = omc_keep_length($hex_setAltTg,0,2);
				if($alterTgFlag==1)
					$Row[initValue] = setBitValue($Row[initValue],'7.0-7.7',$hex_setAltTg);
				$Row[initValue] = setBitValue($Row[initValue],'4.6-4.6',$alterTgFlag);
				//echo $Row[initValue];
				//exit();
				$updSql = "update $paramTable set initValue = '$Row[initValue]'
							where $objWhereStr AND instanceNo ='$trunkgp' ";
				mysqli_query($pubConn,$updSql);
			}//end add
			
			break;
		}
		case 'Linkset'://修改linkset的dpc,ni修改相应routing与TG,GTT的dpc,ni
		{
			switch($webname)
			{
				case	'HLR':
					$SSN = 6;
					break;
				case	'VLR':
					$SSN = 7;
					break;
				case	'MSC':
					$SSN = 8;
					break;
				case	'SMSC':
					$SSN = 11;
					break;
			}							
			
			$tmpDb = 'OBJ_222';
			$tmpTable = 'param_99';
			$tmpoid = '2.4.1';
			$objWhereStr = getLevelWhere($tmpoid);
			
			$paramSql = " SELECT initValue,readValue,instanceNo FROM $tmpTable  
						WHERE $objWhereStr AND instanceNo ='$linkset' 
						";
			$Result = mysqli_query($pubConn,$paramSql);				
			$Row		= mysqli_fetch_array($Result);
			$DPC 		= hexdec(getBitValue($Row[initValue],'0.0-2.7'));		
			$NetID 	= getBitValue($Row[initValue],'3.0-3.1');			
			$NetID	= bindec($NetID);
			$newNetID = $NetID;
			if($DEBUG)	echo "Row[initValue] = $Row[initValue]";
			if($DEBUG)	echo "NetID = $NetID";
			
			//关联GTT的DPC  关联GTT的Network indicator
			if($webname =='Switch' || $webname =='VSS' || $webname =='HLR' ||$webname =='VLR' || $webname =='MSC'|| $webname =='SMSC')
			{
				$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 = 1;
				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);
						$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++;
					}
				}
			}
			//else//关联TG的DPC  关联TG的Network indicator
			{					
				$tmpDb = 'OBJ_322';
				$tmpTable = 'param_99';
				$tmpoid = '2.1.4';
				$objWhereStr = getLevelWhere($tmpoid);
				$paramSql = " SELECT initValue,readValue,instanceNo FROM $tmpTable  
							WHERE $objWhereStr AND instanceNo ='$trunkgp' 
							";
				$Result = mysqli_query($pubConn,$paramSql);				
				$Row		= mysqli_fetch_array($Result);
				$DPC_TG		= dechex($DPC);
				$DPC_TG    = omc_keep_length($DPC_TG,0,8);	
				$Row[initValue]	= setBitValue($Row[initValue],'0.0-3.7',$DPC_TG);
				$NetID		= dechex($NetID);
				$NetID    = omc_keep_length($NetID,0,2);
				$Row[initValue]	= setBitValue($Row[initValue],'5.0-5.7',$NetID);
				$Row[initValue] = strtoupper($Row[initValue]);
				$updSql = "UPDATE $tmpTable SET initValue = '$Row[initValue]'   
					WHERE $objWhereStr AND instanceNo = '$trunkgp'
					";
				mysqli_query($pubConn,$updSql);									
			}
			//修改routing DPC
			{
				$routeNO = $externID[1];
				$DPC 	= dechex($DPC);
				$DPC    = omc_keep_length($DPC,0,6);
				$AlternativeArr=array(
					array('Linkset DPC',		'0.0-2.7',	'DPC'),
					array('Normal linkset',	'3.0-3.7',	'linkset'),
					array('Alternative linkset',	'4.0-4.7',	'Alternative')
					);
				$objDb = 'OBJ_222';	
				$paramTable  = 'param_99';
				
				if($oldNetID == $newNetID){
					$temp = $newNetID+1;
					$oidstr = '2.6.'.$temp;
					$objWhereStr= '';
					$objWhereStr =getLevelWhere($oidstr);
		
					$paramSql = " SELECT initValue,readValue,instanceNo FROM $paramTable  
								WHERE $objWhereStr AND instanceNo = '$routeNO'
								";
					$Result_2 = mysqli_query($pubConn,$paramSql);
					$Row_2		= mysqli_fetch_array($Result_2);
					$Row_2[initValue] = setBitValue($Row_2[initValue],$AlternativeArr[0][1],$DPC);
					$Row_2[initValue] = strtoupper($Row_2[initValue]);
					$updSql = "UPDATE $paramTable SET initValue = '$Row_2[initValue]'   
						WHERE $objWhereStr AND instanceNo = '$routeNO'
						";
					mysqli_query($pubConn,$updSql);
				/*	
					if('AAS' == $externID[2]){
						$NIoffset = array("0.0-0.0","0.1-0.1","0.2-0.2","0.3-0.3");
						$oidstr = '2.2';
						$aas_link_Db = 'OBJ_222';	
						$aas_link_Table  = 'param_11';
						//$subSysNo = $externID[3];
						$subSysNo = 99;
						$objWhereStr= '';
						$objWhereStr =getLevelWhere($oidstr);
						$paramSql = " SELECT initValue,readValue,instanceNo FROM $aas_link_Table  
									WHERE $objWhereStr AND subSysNo = '$subSysNo'
									";
						if($DEBUG) echo "$paramSql<br>";			
						$aas_Result = mysqli_query($pubConn,$paramSql);
						$aas_Row		= mysqli_fetch_array($aas_Result);
													
						$NIbit	= getBitValue($aas_Row[initValue],$NIoffset[$newNetID]);
						$tmp = $newNetID+1+$NIbit*4;
						$oidstr = '2.3.'.$tmp;
						if($DEBUG) echo "oldNetID = $oldNetID<br>";
						if($DEBUG) echo "newNetID = $newNetID<br>";
						if($DEBUG) echo "$NIbit<br>";
						if($DEBUG) echo "$oidstr<br>";
						$objWhereStr= '';
						$objWhereStr =getLevelWhere($oidstr);
						$DPC = strtoupper($DPC);
						$updSql = "UPDATE $aas_link_Table SET initValue = '$DPC'   
												WHERE $objWhereStr AND instanceNo = '0' AND subSysNo = '$subSysNo'
												";
						if($DEBUG) echo "$updSql<br>";						
						mysqli_query($pubConn,$updSql);
					}
				*/
				}else{
					$temp = $oldNetID+1;
					$oidstr = '2.6.'.$temp;						
					$objWhereStr_old= '';
					$objWhereStr_old =getLevelWhere($oidstr);
					$paramSql = " SELECT initValue,readValue,instanceNo FROM $paramTable  
								WHERE $objWhereStr_old AND instanceNo = '$routeNO'
								";
					$Result_2 = mysqli_query($pubConn,$paramSql);
					$Row_2		= mysqli_fetch_array($Result_2);
					$Alternative = getBitValue($Row_2[initValue],$AlternativeArr[2][1]);	
					$updSql = "UPDATE $paramTable SET initValue = '0000008080'   
						WHERE $objWhereStr_old AND instanceNo = '$routeNO'
						";
					mysqli_query($pubConn,$updSql);									
					
					$temp = $oldNetID+2;
					$oidstr = '2.7.'.$temp;	
					$objWhereStr_old= '';
					$objWhereStr_old =getLevelWhere($oidstr);
					
					$paramSql = " SELECT initValue,readValue,instanceNo FROM $paramTable  
								WHERE $objWhereStr_old AND instanceNo = '$routeNO'
								";
					$Result_2 = mysqli_query($pubConn,$paramSql);
					$Row_2		= mysqli_fetch_array($Result_2);
					$ACNoldvalue = $Row_2[initValue];						
					
					$paramSql = " SELECT initValue FROM paramConf	WHERE $objWhereStr_old
								";
					$Result_2 = mysqli_query($pubConn,$paramSql);
					$Row_2		= mysqli_fetch_array($Result_2);
					$ACNdefvalue= $Row_2[initValue];
											
					$updSql = "UPDATE $paramTable SET initValue = '$ACNdefvalue'   
						WHERE $objWhereStr_old AND instanceNo = '$routeNO'
						";
					mysqli_query($pubConn,$updSql);						
					
					{//拷贝
						$temp = $newNetID+1;
						$oidstr = '2.6.'.$temp;
						$objWhereStr_new= '';
						$objWhereStr_new =getLevelWhere($oidstr);
						$paramSql = " SELECT initValue,readValue,instanceNo FROM $paramTable  
									WHERE initValue = '0000008080' AND  $objWhereStr_new
									";
						$Result_1 = mysqli_query($pubConn,$paramSql);
						$Row_1 = mysqli_fetch_array($Result_1);
								
						$Row_1[initValue] = setBitValue($Row_1[initValue],$AlternativeArr[0][1],$DPC);
						$hex_linkset = dechex($linkset);
						$hex_linkset = omc_keep_length($hex_linkset,0,2);
						$Row_1[initValue] = setBitValue($Row_1[initValue],$AlternativeArr[1][1],$hex_linkset);
						if(isset($Alternative)){
							$Alternative = omc_keep_length($Alternative,0,2);
							$Row_1[initValue] = setBitValue($Row_1[initValue],$AlternativeArr[2][1],$Alternative);
						}
						$Row_1[initValue] = strtoupper($Row_1[initValue]);
						$updSql = "UPDATE $paramTable SET initValue = '$Row_1[initValue]'   
							WHERE $objWhereStr_new AND instanceNo = '$Row_1[instanceNo]'
							";
						mysqli_query($pubConn,$updSql);
						$temp = $newNetID+2;
						$oidstr = '2.7.'.$temp;
						$objWhereStr_new= '';
						$objWhereStr_new =getLevelWhere($oidstr);							
						$updSql = "UPDATE $paramTable SET initValue = '$ACNoldvalue'   
							WHERE $objWhereStr_new AND instanceNo = '$Row_1[instanceNo]'
							";							
						mysqli_query($pubConn,$updSql);	
					}	
	/*
					if('AAS' == $externID[2]){
						$aas_link_Db = 'OBJ_222';	
						$aas_link_Table  = 'param_11';						
						$NIoffset = array("0.0-0.0","0.1-0.1","0.2-0.2","0.3-0.3");
	//							$subSysNo = $externID[3];
						$subSysNo = 99;
														
						$oidstr = '2.2';
						$objWhereStr= '';
						$objWhereStr =getLevelWhere($oidstr);
						$paramSql = " SELECT initValue,readValue,instanceNo FROM $aas_link_Table  
									WHERE $objWhereStr AND subSysNo = '$subSysNo'
									";
						if($DEBUG) echo "$paramSql<br>";
						$aas_Result = mysqli_query($pubConn,$paramSql);
						$aas_Row		= mysqli_fetch_array($aas_Result);
													
						$NIbit	= getBitValue($aas_Row[initValue],$NIoffset[$oldNetID]);
						$tmp = $oldNetID+1+$NIbit*4;
						$oidstr = '2.3.'.$tmp;
						$objWhereStr= '';
						$objWhereStr =getLevelWhere($oidstr);
						$updSql = "UPDATE $aas_link_Table SET initValue = '000000'   
												WHERE $objWhereStr AND instanceNo = '0' AND subSysNo = '$subSysNo'
												";
						if($DEBUG) echo "$paramSql<br>";
						mysqli_query($pubConn,$updSql);
						
						$NIbit_new	= getBitValue($aas_Row[initValue],$NIoffset[$newNetID]);
						$tmp = $newNetID+1+$NIbit_new*4;
						$oidstr = '2.3.'.$tmp;
						$objWhereStr= '';
						$objWhereStr =getLevelWhere($oidstr);
						$DPC = strtoupper($DPC);
						$updSql = "UPDATE $aas_link_Table SET initValue = '$DPC'
												WHERE $objWhereStr AND instanceNo = '0' AND subSysNo = '$subSysNo'
												";
						if($DEBUG) echo "$paramSql<br>";						
						mysqli_query($pubConn,$updSql);							
					}
	*/						
				}
			}
			break;
		}
		case 'Prefix':
		{		
			$tempRAC=11;		
			$objstrset='2.1.3';
			$objWhereStr =getLevelWhere($objstrset);				
			$hex_set_tg = $HEXtrunkgp = omc_keep_length(dechex($trunkgp),0,2);
			$updSql = "UPDATE $paramTable SET initValue = '$hex_set_tg'   
						WHERE $objWhereStr AND instanceNo = '$instanceNo'";	
			//echo $updSql;
			if($webname != 'BSC')//Emergency prefix'TG 不一定要是相应的BTS对应tg，所以不用改变。2006-7-18 14:56 arwean							
				mysqli_query($pubConn,$updSql);
			//exit();
			
			//Set flag = 1
			$objstrset='2.1.2';
			$objWhereStr =getLevelWhere($objstrset);				
			$paramSql = " SELECT initValue,readValue,instanceNo FROM $paramTable  
									WHERE $objWhereStr AND instanceNo ='$instanceNo'
									";
									
			$Result = mysqli_query($pubConn,$paramSql);				
			$Row	= mysqli_fetch_array($Result);					
			$Row[initValue] = setBitValue($Row[initValue],'10.7-10.7','1');		
			$Row[initValue] = strtoupper($Row[initValue]);
			$updSql = "UPDATE $paramTable SET initValue = '$Row[initValue]'   
			WHERE $objWhereStr AND instanceNo = '$instanceNo'
			";										
			mysqli_query($pubConn,$updSql);						
			break;
		}
		case 'BTS':	//修改BTS Prefix
		{
			$objstrset='2.2.7';
			$objWhereStr =getLevelWhere($objstrset);		
			
			$paramSql = " SELECT initValue,instanceNo FROM $paramTable  
						WHERE $objWhereStr AND instanceNo ='$instanceNo' ";
			$Result = mysqli_query($pubConn,$paramSql);				
			$Row	= mysqli_fetch_array($Result);
			$org_PrefixNo=hexdec(getBitValue($Row[initValue],'5.0-5.7'));
			if($org_Prefix==0 || $org_PrefixNo != $set_PrefixNo)//由于prefixno默认为0，所以也要更新一下
			{
				
				$hexPrefixNo = strtoupper(omc_keep_length(dechex($set_PrefixNo),'0','2'));
				$setValue = setBitValue($Row[initValue],'5.0-5.7',$hexPrefixNo);
				
				$updSql = "update $paramTable set initValue='$setValue' 
							where $objWhereStr and instanceNo='$instanceNo' ";
				mysqli_query($pubConn,$updSql);	
				
				//update prefixno (enable, Emergency call)
				{
					$oidstr = '2.1.2';
					$objWhereStr= '';
					$objWhereStr =getLevelWhere($oidstr);		
					
					$offset_enable = "10.7-10.7";
					$offset_calltype = "10.4-10.6";
					
					$selSql = " SELECT initValue,instanceNo FROM $paramTable WHERE $objWhereStr and instanceNo='$set_PrefixNo' ";
					//echo $defSql;
					$selRes = @mysqli_query($pubConn,$selSql);
					$Row = @mysqli_fetch_array($selRes);
					$Row[initValue] = setBitValue($Row[initValue],$offset_enable,'1');
					$Row[initValue] = setBitValue($Row[initValue],$offset_calltype,'001');

					$updSql = "update $paramTable set initValue='$Row[initValue]' where $objWhereStr and instanceNo='$set_PrefixNo'";
					@mysqli_query($pubConn,$updSql);		
				}
				//delete the org_PrefixNo if there is no other cells use it.
				if($org_PrefixNo != $set_PrefixNo)
				{
					$objstrset='2.2.7';
					$objWhereStr =getLevelWhere($objstrset);		
					
					$paramSql = " SELECT initValue FROM $paramTable  
								WHERE $objWhereStr ";
					$result = mysqli_query($pubConn,$paramSql);
					$otherUsed=0;	
					while($row	= mysqli_fetch_array($result))
					{
						$prefixNo=hexdec(getBitValue($row[initValue],'5.0-5.7'));
						if($prefixNo==$org_PrefixNo)
						{
							$otherUsed=1;
							break;
						}
					}
					if($otherUsed==0)//delete $org_PrefixNo.
					{
						$tmpParamConfTable='paramConf';
						$tmpObjIdStr='2.1';
						$levelWhere = getLevelWhere($tmpObjIdStr);
						if($DEBUG) echo "<BR>levelWhere=$levelWhere";
					
						$getSql="SELECT initValue,level_3 FROM $tmpParamConfTable 
									WHERE $levelWhere AND (level_3='1' OR level_3='2' OR level_3='3') ORDER BY level_3
								";
						if($DEBUG) echo "<BR>getSql=$getSql";
						$result	=mysqli_query($pubConn,$getSql);
						echo mysqli_error($pubConn);
						$i=0;
						unset($tmpDefaultValueArr);
						while($rows=mysqli_fetch_array($result)){
							if($DEBUG) 
							echo "<BR>initValue=$rows[initValue]"; 
							$tmpDefaultValueArr[$i][initValue]=$rows[initValue];
							//echo "<BR>level_3=$rows[level_3]";
							$tmpDefaultValueArr[$i][level_3]=$rows[level_3];
							$i++;
						}
						if($DEBUG) 	echo "<BR>$aasprefixArr<br>";
												
						for($i=0;$i<sizeof($tmpDefaultValueArr);$i++)
						{
							$updateSql="UPDATE OBJ_322.param_99 SET 	
										initValue='{$tmpDefaultValueArr[$i][initValue]}'
										WHERE $levelWhere AND level_3='{$tmpDefaultValueArr[$i][level_3]}' AND (instanceNo='$org_PrefixNo'";
							for($j=1;$j<sizeof($tmpInstanceNoArr);$j++){
								$updateSql=$updateSql." OR instanceNo='".$tmpInstanceNoArr[$j]."'";
							}
							$updateSql=$updateSql.")";
							if($DEBUG) echo "<BR>updateSql=$updateSql";
							mysqli_query($pubConn,$updateSql);
							echo mysqli_error($pubConn);	
						}
//					exit;
					}				
				}
			}
			break;
		}
		default:
	}
	echo mysqli_error($pubConn);			
}



if($setname=='Trunk Group')
{
	
	
	
	//==================trunk group back off flag for all system=========================
	$database="OBJ_322";
	$sql="select instanceNo,initValue from param_99 where level_1=2 and level_2=1 and level_3=4 and instanceNo=$trunkgp";
	$result=@mysqli_query($pubConn,$sql);
	$rows=@mysqli_fetch_array($result);
	$old_initValue=$rows[initValue];
	//back_off_flag_checkbox
	$new_initValue=setBitValue($old_initValue,'6.2',$back_off_flag_checkbox);
	
	$updSql = "UPDATE param_99 SET initValue = '$new_initValue'   
				WHERE level_1=2 and level_2=1 and level_3=4 and instanceNo=$trunkgp
				";
		mysqli_query($pubConn,$updSql);	
		echo mysqli_error($pubConn);
	
	if($webname=='BSC')
	{
		
		$database="OBJ_322";
		$sql="select instanceNo,initValue from param_99 where level_1=2 and level_2=1 and level_3=4 and instanceNo=$trunkgp";
		$result=@mysqli_query($pubConn,$sql);
		$rows=@mysqli_fetch_array($result);
		$old_initValue=$rows[initValue];
		//=================CDR flag==========
		$new_initValue=setBitValue($old_initValue,'4.1',$cdr_flag_select);
		
		//=================location===========
		if($location_select==0)
		{
			$bit0=0;
			$bit1=0;
		}
		else if($location_select==1)
		{
			$bit0=1;
			$bit1=0;
		}
		else if($location_select==2)
		{
			$bit0=0;
			$bit1=1;
		}
		else if($location_select==3)
		{
			$bit0=1;
			$bit1=1;
		}
		
		$new_initValue=setBitValue($new_initValue,'6.6',$bit0);
		$new_initValue=setBitValue($new_initValue,'6.7',$bit1);
		
		//============radio channel control=======				
		$new_initValue=setBitValue($new_initValue,'10.7',$radio_channel_control_select);
		
		//=============protocol stack for BSC=======
		$new_initValue=setBitValue($new_initValue,'12.7',0);
		$new_initValue=setBitValue($new_initValue,'12.6',0);
		$new_initValue=setBitValue($new_initValue,'12.5',0);
		$new_initValue=setBitValue($new_initValue,'12.4',0);
		$new_initValue=setBitValue($new_initValue,'12.3',0);
		$new_initValue=setBitValue($new_initValue,'12.2',0);
		$new_initValue=setBitValue($new_initValue,'12.1',0);
		$new_initValue=setBitValue($new_initValue,'12.0',$protocol_stack_bsc_select);
		
		
		
		$new_initValue=strtoupper($new_initValue);
		$updSql = "UPDATE param_99 SET initValue = '$new_initValue'   
				WHERE level_1=2 and level_2=1 and level_3=4 and instanceNo=$trunkgp
				";
		mysqli_query($pubConn,$updSql);	
		echo mysqli_error($pubConn);
		
		//=======================Full rate speech V3======================================
		//half_rate_speech_v1_checkbox
		$database="OBJ_322";
		$sql="select instanceNo,initValue from param_99 where level_1=2 and level_2=1 and level_3=4 and instanceNo=$trunkgp";
		$result=@mysqli_query($pubConn,$sql);
		$rows=@mysqli_fetch_array($result);
		$old_initValue=$rows[initValue];
		
		if(!isset($full_rate_speech_v3_checkbox))
			$full_rate_speech_v3_checkbox=0;
		if(!isset($full_rate_speech_v2_checkbox))
			$full_rate_speech_v2_checkbox=0;
		if(!isset($full_rate_speech_v1_checkbox))
			$full_rate_speech_v1_checkbox=0;
		if(!isset($half_rate_speech_v3_checkbox))
			$half_rate_speech_v3_checkbox=0;
		if(!isset($half_rate_speech_v1_checkbox))
			$half_rate_speech_v1_checkbox=0;	
			
		$new_initValue=setBitValue($old_initValue,'10.0',$full_rate_speech_v3_checkbox);
		$new_initValue=setBitValue($new_initValue,'10.1',$full_rate_speech_v2_checkbox);
		$new_initValue=setBitValue($new_initValue,'10.2',$full_rate_speech_v1_checkbox);
		$new_initValue=setBitValue($new_initValue,'10.3',$half_rate_speech_v3_checkbox);
		$new_initValue=setBitValue($new_initValue,'10.4',$half_rate_speech_v1_checkbox);
		
		$updSql = "UPDATE param_99 SET initValue = '$new_initValue'   
				WHERE level_1=2 and level_2=1 and level_3=4 and instanceNo=$trunkgp
				";
		mysqli_query($pubConn,$updSql);	
		echo mysqli_error($pubConn);
		
	}
}

//======================add the trunk three parameters==========
	
	if($setname=='Trunk Group'&&$webname=='IUA')
	{
		$database="OBJ_322";
		$sql="select instanceNo,initValue from param_99 where level_1=2 and level_2=1 and level_3=4 and instanceNo=$trunkgp";
		$result=@mysqli_query($pubConn,$sql);
		$rows=@mysqli_fetch_array($result);
		$old_initValue=getBitValue($rows[initValue],'0.0-12.7');
		
		//==NFAS_flag
		$nfas_flag_hex=dechex($nfas_flag_select);
		if(strlen($nfas_flag_hex)==1)
			$nfas_flag_hex="0".$nfas_flag_hex;
		//==Primary_D_channel
		$Primary_D_channel_hex=dechex($Primary_D_channel_text);
		if(strlen($Primary_D_channel_hex)==1)
			$Primary_D_channel_hex="0".$Primary_D_channel_hex;
		//==Backup_D_channel
		$Backup_D_channel_hex=dechex($Backup_D_channel_text);
		if(strlen($Backup_D_channel_hex)==1)
			$Backup_D_channel_hex="0".$Backup_D_channel_hex;
			
		$new_initValue=$old_initValue.$nfas_flag_hex.$Primary_D_channel_hex.$Backup_D_channel_hex;
		//==protocol stact
		//$protocol_stact_hex=dechex($protocol_stack_select);
		//if(strlen($protocol_stact_hex)==1)
		$protocol_stack_select=$protocol_stack_select+0;
		if($protocol_stack_select==0)
			$v='0';
		else
			$v='1';	
		
		$new_initValue=setBitValue($new_initValue,'12.0',$v);
		/*
		echo "<script language=\"JavaScript\">\n";
		echo "alert('$new_initValue');\n";
		echo "</script>";
		*/
		
		$updSql = "UPDATE param_99 SET initValue = '$new_initValue'   
				WHERE level_1=2 and level_2=1 and level_3=4 and instanceNo=$trunkgp
				";
		mysqli_query($pubConn,$updSql);	
		echo mysqli_error($pubConn);
		
		/*
		echo "<script language=\"JavaScript\">\n";
		echo "alert('$new_initValue');\n";
		echo "</script>\n";
		*/
	}
	





if($DEBUG){
	echo "<br>debug";
}else{//return page
	echo "<script language='javascript'>";
	echo " location='$backurl';";  
	echo "</script>";
	exit();
}


	
	


}//end of if($set == 1)

//=======================Show GUI ========================
?> 
<body>
<script LANGUAGE="JavaScript"> 
	
function selCheckBox(thisCheckBox)
{
	var alterTg;
	alterTg = eval("document.confForm.set_AlterTg");
	if(thisCheckBox.checked == true)
	{
		thisCheckBox.value=1;
		alterTg.disabled = false;
	}
	else
	{
		thisCheckBox.value=0;
		alterTg.disabled = true;
	}
	//alert(thisCheckBox.value);
}

function checkInt(term){    
    var checkOK = "0123456789";
    var checkStr = term.value;
    var allValid = true;
	var termName = term.name;
	var minValue = eval("document.confForm."+termName+"_min.value");
	var maxValue = eval("document.confForm."+termName+"_max.value");
	var oldValue = eval("document.confForm."+termName+"_old.value");
	//alert(minValue+'<'+term.value+'<'+maxValue);
    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){  
		var errAlert="parameter Must be a dec number!";
		alert(errAlert);
		term.value=oldValue;
		term.focus();
		return (false);
	}

	if((minValue - term.value) > 0){
		var errAlert="Too little!";
		alert(errAlert);
		term.value=oldValue;
		term.focus();
		return (false);
	}
	if((term.value - maxValue) > 0){
		var errAlert="Too Big!";
		alert(errAlert);
		term.value=oldValue;
		term.focus();
		return (false);
	}

}




</script>
<body topmargin="0" leftmargin="12">
<form method="POST" name="confForm" action="<?php echo"$PHP_SELF";?>" >
<?
$oIdstrarr = explode('-',$objIdStr);
$routingNo = explode('-',$instanceNo);

echo "<table border=\"0\" width=\"100%\">";
echo "<tr>";
echo "<td width=\"50%\">";
echo "Configuration > <a href=\"../overview/overview.php\">Network</a> > ";
if(isset($devicename))
{
	$backurl1 = str_replace("wxc2_sp_signaling","wxc2_sp",$backurl);
	echo "<a href=\"$backurl1\">$devicename</a> > ";
}
$tmp_name = strstr($instanceNo,$routingNo[2]);//if instanceNo = 0-0-bss-0, the name should be bss-0 but not bss.
$showLink = $setname=='Linkset' ? $tmp_name : $webname;

echo "<a href=\"$backurl\">$showLink</a> > ";
echo "<a href=\"#\">$setname</a>";
echo "</td>";
echo "<td width=\"50%\" align=\"right\" title=\"Help\">";
switch ($showLink)
{
	case 'BSC':
	if($setname=='BTS')
	$helpId='2.19';
	break;
	
	default:
	$helpId='2';
	break;
}
//showHelp($helpId);
echo "</td>";
echo "</tr>";
echo "</table>";
echo "<br>";


echo "<table width=\"100%\">";
echo "<tr><td width=\"60%\">";
/*
if($instanceNo == 'new' || $oIdstrarr[0] =='new'){
	echo "<b>Add a $setname:</b>&nbsp;&nbsp;";
}else{
	echo "<b>Edit $setname:</b>&nbsp;&nbsp;";
}*/
echo "&nbsp</td>";
$buttonStyle = "cursor:pointer; left: 1; top: 2; width: 80; height: 22; position: relative";
echo "<td width=\"30%\">";
echo "<input type=\"submit\" name=\"set\" value=\"Save\" class=\"button\" style=\"$buttonStyle\">";
echo "&nbsp;&nbsp;&nbsp;";
echo "<input type=\"reset\" name=\"Reset\" value=\"Undo\" class=\"button\" style=\"$buttonStyle\">";
echo "</td>";

echo "<td width=\"10%\" align=\"right\"><a href=\"$backurl\"><img align=absBottom border=0 src=\"../../images/left.gif\" width=\"14\" height=\"14\">$strBack</a>";
echo "</td></tr>";
echo "</table>";


echo "<table border=\"1\" width=\"100%\" cellpadding=\"1\" cellspacing=\"0\" bordercolor=\"#666666\" bordercolordark=\"#FFFFFF\">";	
echo "<tr bgcolor=\"#E6E6E6\">";
echo "<td width=\"50%\"><b>Parameters</b></td>";
echo "<td><b>Value</b></td>";
echo "<tr>";


if($setname != 'BTS' && $oIdstrarr[0] !='no')
{
	{//xxx No.
	 //第0组用来查找未用的instanceNo，查找时与默认值比较，相同为可用instanceNo
	echo "<tr>";
	echo "<td>$setname No.</td>";
		if($instanceNo == 'new')
		{
			$objDb 			= omcGetObjDb($sysTypeNo);
			$paramConfTable	= omcGetObjTbl($sysTypeNo,paramConf);
			$objWhereStr =getLevelWhere($oIdstrarr[0]);

			$defSql = " SELECT initValue FROM paramConf WHERE $objWhereStr";
			$defRes = @mysqli_query($pubConn,$defSql);
			$defRow = @mysqli_fetch_array($defRes);
			$DefValue	= $defRow[initValue];						
			$paramSql = " SELECT initValue,readValue,instanceNo FROM $paramTable  
						WHERE initValue = '$DefValue' AND  $objWhereStr  order by instanceNo
						";
			if($setname=='Prefix')
			{
				$paramSql = " SELECT initValue,readValue,instanceNo FROM $paramTable  
							WHERE $objWhereStr order by instanceNo	";
			}
			$result = mysqli_query($pubConn,$paramSql);
			$nShowsize ='40%';				
			$find=0;
			echo "<td>";
		/*	
			echo "<select name=\"newID\" size=\"1\" style=width:\"$nShowsize\">";
			while($row=mysqli_fetch_array($result))
			{
				if($setname=='Prefix')
				{
					$pre_Flag	= BinDec(getBitValue($row[initValue],'10.7-10.7'));
					if($pre_Flag) continue;						
				}
				echo "<option value=$row[instanceNo]>$row[instanceNo]</option>";
				$find=1;
			}
			echo "</select>";
		*/
			//change to select a prefix no automatically
			while($row=mysqli_fetch_array($result))
			{
				if($setname=='Prefix')
				{
					$pre_Flag	= BinDec(getBitValue($row[initValue],'10.7-10.7'));
					if($pre_Flag==0)
					{	
						$find=1;			
						break;	
					}
				}
			}
			echo "{$row[instanceNo]}";
			echo "<input type=\"hidden\" name=\"newID\" value=\"{$row[instanceNo]}\">";
			if(!$find)
			{
				echo "<script language='javascript'>";  
				echo "window.alert(\"There is no $setname to added!\");";	
				echo "history.go(-1)";
				echo "</script>";					
			}
			echo "</td>";
		}
		else{
			echo "<td>$routingNo[0]</td>";				
		}
	
	echo "</tr>";
	}
}
//要显示参数的oid，必须是同一个sysTypeNo 下的oid
for($j=1;$j<sizeof($oIdstrarr);$j++)
{
	if($setname == 'Linkset' ||$setname == 'CIC')
	{
		$tmp = $j -1;
		$instNo = $routingNo[$tmp];
	}
	elseif($setname == 'Trunk Group')
	{
		$instNo = $routingNo[0];
	}
	else
	{
		$instNo = $instanceNo;
	}
	//if($webname!="BSC")
	omcShowParam($oIdstrarr[$j],$sysTypeNo,$instNo,$webname,$j);		

}


//echo "</table>";
if($setname=="Trunk Group")
{
	//===============BSC parameter CDR_flag,location,Radion channel control,protocol stack=====
	
	if($webname=='BSC')
	{
			$database="OBJ_322";
			$sql="select instanceNo,initValue from param_99 where level_1=2 and level_2=1 and level_3=4 and instanceNo=$trunkgp";
			$result=@mysqli_query($pubConn,$sql);
			$rows=@mysqli_fetch_array($result);
			
			//======CDR flag
			$cdr_flag=getBitValue($rows[initValue],'4.1-4.1')+0;
			$cdr_flag_label=array(0=>"OFF",1=>"ON");
			echo "<tr>";
				echo "<td>CDRR Flag</td>";
				echo "<td>";
					echo "<select style=\"width:40%\" name=\"cdr_flag_select\">";
						for($i=0;$i<2;$i++)
						{
							if($i==$cdr_flag)
								echo "<option value=$i selected>{$cdr_flag_label[$i]}</option>";
							else
								echo "<option value=$i>{$cdr_flag_label[$i]}</option>";		
						}
					echo "</select>";
				echo "</td>";
			echo "</tr>";			
			//======location
			$location=bindec(getBitValue($rows[initValue],'6.6-6.7'))+0;
			$location_label=array(0=>"MSC-0",1=>"MSC-1",2=>"Both",3=>"Spare");
			echo "<tr>";
				echo "<td>Location</td>";
				echo "<td>";
					echo "<select style=\"width:40%\" name=\"location_select\">";
						for($i=0;$i<4;$i++)
						{
							if($i==$location)
								echo "<option value=$i selected>{$location_label[$i]}</option>";
							else
								echo "<option value=$i>{$location_label[$i]}</option>";		
						}
					echo "</select>";
				echo "</td>";
			echo "</tr>";
			//======Radio channel control
			$radio_channel_control=getBitValue($rows[initValue],'10.7-10.7')+0;
			$radio_channel_control_label=array(0=>"Depend On MS",1=>"Control By Operator");
			echo "<tr>";
				echo "<td>Radio Channel Control</td>";
				echo "<td>";
					echo "<select style=\"width:40%\" name=\"radio_channel_control_select\" onChange=\"javascript:radio_channel_control_select_change()\">";
						for($i=0;$i<2;$i++)
						{
							if($i==$radio_channel_control)
								echo "<option value=$i selected>{$radio_channel_control_label[$i]}</option>";
							else
								echo "<option value=$i>{$radio_channel_control_label[$i]}</option>";		
						}
					echo "</select>";
				echo "</td>";
			echo "</tr>";
			//======protocol stack on BSC
			$protocol_stack_bsc=hexdec(getBitValue($rows[initValue],'12.0-12.7'))+0;
			$protocol_stack_bsc_label=array(0=>"ITU",1=>"ANSI");
			echo "<tr>";
				echo "<td>Protocol Stack</td>";
				echo "<td>";
					echo "<select style=\"width:40%\" name=\"protocol_stack_bsc_select\">";
						for($i=0;$i<2;$i++)
						{
							if($i==$protocol_stack_bsc)
								echo "<option value=$i selected>{$protocol_stack_bsc_label[$i]}</option>";
							else
								echo "<option value=$i>{$protocol_stack_bsc_label[$i]}</option>";		
						}
					echo "</select>";
				echo "</td>";
			echo "</tr>";
			
	}
	
	//================================add Back off flag parameter to all system==========
		{
			
			
			$database="OBJ_322";
			$sql="select instanceNo,initValue from param_99 where level_1=2 and level_2=1 and level_3=4 and instanceNo=$trunkgp";
			$result=@mysqli_query($pubConn,$sql);
			$rows=@mysqli_fetch_array($result);
			//=====get the parameter of Back off flag 6.2-6.2
			$back_off_flag=getBitValue($rows[initValue],'6.2-6.2')+0;
			if($back_off_flag==1)
				$is_checked="checked";
			else	
				$is_checked="";	
			
			echo "<tr>";
				echo "<td>Back Off Flag</td>";
				echo "<td>";
				echo "<input type=checkbox name=\"back_off_flag_checkbox\" value=$back_off_flag $is_checked onClick=\"javascript:select_checkbox(this)\">Enable";
				echo "</td>";
			echo "</tr>";			
		}
		//===================add parameter 'Full Rate Speech V3' 'Full Rate Speech V2' ======
		//==========='Full Rate Speech V1'  'Half Rate Speech V3' 'Half Rate Speech V1' ======
		if($webname=='BSC')
		{
			$database="OBJ_322";
			$sql="select instanceNo,initValue from param_99 where level_1=2 and level_2=1 and level_3=4 and instanceNo=$trunkgp";
			$result=@mysqli_query($pubConn,$sql);
			$rows=@mysqli_fetch_array($result);
			//=========radio Channel Control====
			$tmp_radio_channel_control=getBitValue($rows[initValue],'10.7-10.7')+0;
			if($tmp_radio_channel_control==1)
				$is_disabled="";
			else
				$is_disabled="disabled";	
			//=====parameter of 'Full Rate Speech V3'
			$full_rate_speech_v3=getBitValue($rows[initValue],'10.0-10.0')+0;
			if($full_rate_speech_v3==1)
				$is_checked="checked";
			else	
				$is_checked="";	
			
			echo "<tr>";
				echo "<td>Full Rate Speech V3</td>";
				echo "<td>";
				echo "<input $is_disabled type=checkbox name=\"full_rate_speech_v3_checkbox\" value=$full_rate_speech_v3 $is_checked onClick=\"javascript:select_checkbox(this)\">Enable";
				echo "</td>";
			echo "</tr>";		
				
			//=====parameter of 'Full Rate Speech V2'
			$full_rate_speech_v2=getBitValue($rows[initValue],'10.1-10.1')+0;
			if($full_rate_speech_v2==1)
				$is_checked="checked";
			else	
				$is_checked="";	
			
			echo "<tr>";
				echo "<td>Full Rate Speech V2</td>";
				echo "<td>";
				echo "<input $is_disabled type=checkbox name=\"full_rate_speech_v2_checkbox\" value=$full_rate_speech_v2 $is_checked onClick=\"javascript:select_checkbox(this)\">Enable";
				echo "</td>";
			echo "</tr>";		
			
			//=====parameter of 'Full Rate Speech V1'
			$full_rate_speech_v1=getBitValue($rows[initValue],'10.2-10.2')+0;
			if($full_rate_speech_v1==1)
				$is_checked="checked";
			else	
				$is_checked="";	
			
			echo "<tr>";
				echo "<td>Full Rate Speech V1</td>";
				echo "<td>";
				echo "<input $is_disabled type=checkbox name=\"full_rate_speech_v1_checkbox\" value=$full_rate_speech_v1 $is_checked onClick=\"javascript:select_checkbox(this)\">Enable";
				echo "</td>";
			echo "</tr>";		
			
			//=====parameter of 'Half Rate Speech V3'
			$half_rate_speech_v3=getBitValue($rows[initValue],'10.3-10.3')+0;
			if($half_rate_speech_v3==1)
				$is_checked="checked";
			else	
				$is_checked="";	
			
			echo "<tr>";
				echo "<td>Half Rate Speech V3</td>";
				echo "<td>";
				echo "<input $is_disabled type=checkbox name=\"half_rate_speech_v3_checkbox\" value=$half_rate_speech_v3 $is_checked onClick=\"javascript:select_checkbox(this)\">Enable";
				echo "</td>";
			echo "</tr>";		
			
			//=====parameter of 'Half Rate Speech V1'
			$half_rate_speech_v1=getBitValue($rows[initValue],'10.4-10.4')+0;
			if($half_rate_speech_v1==1)
				$is_checked="checked";
			else	
				$is_checked="";	
			
			echo "<tr>";
				echo "<td>Half Rate Speech V1</td>";
				echo "<td>";
				//onClick=\"javascript:selCheckBox(this)\"
				echo "<input $is_disabled type=checkbox name=\"half_rate_speech_v1_checkbox\" value=$half_rate_speech_v1 $is_checked onClick=\"javascript:select_checkbox(this)\">Enable";
				echo "</td>";
			echo "</tr>";		
			
		}
}


if($setname=="Trunk Group" && $webname!='BSC')
{
	//echo "<br>$webname";
	{//get all TG (added by arwean 2006-03-29)
	$tmpDB = 'OBJ_222';
	$tmpobjIdStr='2.4.1';
	$levelWhere = getLevelWhere($tmpobjIdStr);
	$paramTab='param_99';
	$getSql="SELECT initValue,instanceNo FROM $paramTab 
				WHERE $levelWhere
			";
	if($DEBUG) echo "<BR>getSql=$getSql";
	$result	=mysqli_query($pubConn,$getSql);
	echo mysqli_error($pubConn);
	
	$i=0;
	while($rows=mysqli_fetch_array($result))
	{
		if($DEBUG)echo "<BR>initValue=$rows[initValue]";
		$unitValue=getBitValue($rows[initValue],'4.0-4.7');//system type
		$usedLinksetArr[$i][type]=hexdec($unitValue);
		if($unitValue==0)
			continue;
		if(($webname=='PCR' || $webname=='Switch')
			&& ($usedLinksetArr[$i][type]==1 || $usedLinksetArr[$i][type]==2 || $usedLinksetArr[$i][type]==3))//don't need bsc
			continue;
		if($webname=='AAS' && $usedLinksetArr[$i][type]!=2)
			continue;
		if($webname=='VSS' && $usedLinksetArr[$i][type]!=3)
			continue;
		$usedLinksetArr[$i][sysNo]=hexdec(getBitValue($rows[initValue],'5.0-5.7'));
		$usedLinksetArr[$i][dpc]=getBitValue($rows[initValue],'0.0-2.7');
		$usedLinksetArr[$i][name]=getBitValue($rows[initValue],'7.0-16.7');
		if($usedLinksetArr[$i][name]==0)
			$usedLinksetArr[$i][name]=$rows[instanceNo];
		else
			$usedLinksetArr[$i][name]=trim(toAscii($usedLinksetArr[$i][name]));		
		$usedLinksetArr[$i][ni]=bindec(getBitValue($rows[initValue],'3.0-3.1'));
		$usedLinksetArr[$i][linkset]=$rows[instanceNo];
		if($DEBUG)
		echo "<BR>linkset={$usedLinksetArr[$i][linkset]}";
		$i++;	
	}
	
	//============hide temp====
	/*
	for($i=0; $i< sizeof($usedLinksetArr); $i++)
	{
	
		$ElementNo=sizeof($ElementArr);	
		
		$tmpOpcValue=strtoupper(omc_keep_length($usedLinksetArr[$i][dpc],0,8));
		$tmpWhere="initValue LIKE "."'$tmpOpcValue"."%'";
		$tmpDB='OBJ_322';
		$tmpTab = 'param_99';
		$tmpObjIdStr='2.1.4';
		$levelWhere = getLevelWhere($tmpObjIdStr);
		$getSql="SELECT initValue,instanceNo FROM $tmpTab
					WHERE $levelWhere AND $tmpWhere
				";
		if($DEBUG) 
			echo "<BR>getSql=$getSql";
		$result	=mysqli_query($pubConn,$getSql);
		echo mysqli_error($pubConn);
		
		while($rows=mysqli_fetch_array($result))
		{
			if(hexdec(getBitValue($rows[initValue],'5.0-5.7'))==$usedLinksetArr[$i][ni])
			{				
				$ElementArr[$ElementNo][tg]=$rows[instanceNo];
				$ElementArr[$ElementNo][name]=$usedLinksetArr[$i][name];
				break;
			}
		}
	}
	*/
	//====================================================
	//==========================get the ss7 and isdn tg no===========================

	if($webname=='IUA'||$webname=='Switch')
	{
		$database="OBJ_225";
		$sql="select instanceNo,initValue from param_99 where level_1=2 and level_2=11 ";
		$result=@mysqli_query($pubConn,$sql);
		$rows=@mysqli_fetch_array($result);
		$alternative_tg_count=0;
		if($rows)
		{
			do{
	
				$device_type_tmp=hexdec(getBitValue($rows[initValue],'1.0-1.7'))+0;
				$tg_tmp=hexdec(getBitValue($rows[initValue],'3.0-3.7'))+0;
				$title_tmp=getBitValue($rows[initValue],'14.0-23.7');
				if($device_type_tmp==16||$device_type_tmp==17)
				{
					if($tg_tmp!=$trunkgp)
					{
						$temp="";
						for($num=0;$num<10;$num++)
						{
							$str=substr($title_tmp,$num*2,2);
							$str=hexdec($str);
							$str=chr($str);
							$temp.=$str;
						}
						$ElementArr[$alternative_tg_count][tg]=$tg_tmp;
						$ElementArr[$alternative_tg_count][name]=trim($temp);
						$alternative_tg_count++;
					}
				}
				
				//echo "Flag=$Flag<br>";
			}while($rows=mysqli_fetch_array($result));
		}
	}
	else if($webname=='VSS')
	{
		$database="OBJ_225";
		$sql="select instanceNo,initValue from param_99 where level_1=2 and level_2=11 ";
		$result=@mysqli_query($pubConn,$sql);
		$rows=@mysqli_fetch_array($result);
		$alternative_tg_count=0;
		if($rows)
		{
			do{
	
				$device_type_tmp=hexdec(getBitValue($rows[initValue],'1.0-1.7'))+0;
				$tg_tmp=hexdec(getBitValue($rows[initValue],'3.0-3.7'))+0;
				$title_tmp=getBitValue($rows[initValue],'14.0-23.7');
				if($device_type_tmp==3)
				{
					if($tg_tmp!=$trunkgp)
					{
						$temp="";
						for($num=0;$num<10;$num++)
						{
							$str=substr($title_tmp,$num*2,2);
							$str=hexdec($str);
							$str=chr($str);
							$temp.=$str;
						}
						$ElementArr[$alternative_tg_count][tg]=$tg_tmp;
						$ElementArr[$alternative_tg_count][name]=trim($temp);
						$alternative_tg_count++;
					}
				}
				
				//echo "Flag=$Flag<br>";
			}while($rows=mysqli_fetch_array($result));
		}
	}
	else if($webname=='PCR')
	{
		$database="OBJ_225";
		$sql="select instanceNo,initValue from param_99 where level_1=2 and level_2=11 ";
		$result=@mysqli_query($pubConn,$sql);
		$rows=@mysqli_fetch_array($result);
		$alternative_tg_count=0;
		if($rows)
		{
			do{
	
				$device_type_tmp=hexdec(getBitValue($rows[initValue],'1.0-1.7'))+0;
				$tg_tmp=hexdec(getBitValue($rows[initValue],'3.0-3.7'))+0;
				$title_tmp=getBitValue($rows[initValue],'14.0-23.7');
				if($device_type_tmp==4)
				{
					if($tg_tmp!=$trunkgp)
					{
						$temp="";
						for($num=0;$num<10;$num++)
						{
							$str=substr($title_tmp,$num*2,2);
							$str=hexdec($str);
							$str=chr($str);
							$temp.=$str;
						}
						$ElementArr[$alternative_tg_count][tg]=$tg_tmp;
						$ElementArr[$alternative_tg_count][name]=trim($temp);
						$alternative_tg_count++;
					}
				}
				
				//echo "Flag=$Flag<br>";
			}while($rows=mysqli_fetch_array($result));
		}
	}
	else if($webname=='CNF')
	{
		$database="OBJ_225";
		$sql="select instanceNo,initValue from param_99 where level_1=2 and level_2=11 ";
		$result=@mysqli_query($pubConn,$sql);
		$rows=@mysqli_fetch_array($result);
		$alternative_tg_count=0;
		if($rows)
		{
			do{
	
				$device_type_tmp=hexdec(getBitValue($rows[initValue],'1.0-1.7'))+0;
				$tg_tmp=hexdec(getBitValue($rows[initValue],'3.0-3.7'))+0;
				$title_tmp=getBitValue($rows[initValue],'14.0-23.7');
				if($device_type_tmp==5)
				{
					if($tg_tmp!=$trunkgp)
					{
						$temp="";
						for($num=0;$num<10;$num++)
						{
							$str=substr($title_tmp,$num*2,2);
							$str=hexdec($str);
							$str=chr($str);
							$temp.=$str;
						}
						$ElementArr[$alternative_tg_count][tg]=$tg_tmp;
						$ElementArr[$alternative_tg_count][name]=trim($temp);
						$alternative_tg_count++;
					}
				}
				
				//echo "Flag=$Flag<br>";
			}while($rows=mysqli_fetch_array($result));
		}
	}
	
	//===============================================================================
	if($webname=='Switch' || $webname=='PCR'||$webname=='IUA'||$webname=='VSS'||$webname=='CNF')
	{
		$tmpEleNo=sizeof($ElementArr);
		$ElementArr[$tmpEleNo][tg]=253;
		$ElementArr[$tmpEleNo][name]='Loopback';
	}
	}//end get all tg
	{
	$objstrset='2.1.4';
	$objWhereStr =getLevelWhere($objstrset);

	$paramSql = " SELECT initValue,readValue,instanceNo FROM $paramTable  
							WHERE $objWhereStr AND instanceNo ='$trunkgp' 
							";
	$Result = mysqli_query($pubConn,$paramSql);				
	$Row		= mysqli_fetch_array($Result);
	$alternativeTG 	= hexdec(getBitValue($Row[initValue],'7.0-7.7'));
	$alterTgFlag = (getBitValue($Row[initValue],'4.6-4.6'));
	}
	{//alterTgFlag
		echo "<tr>";
			echo "<td width=\"50%\">Alternative TG Flag</td>";
			echo "<td width=\"50%\">";
			$checkeStr = $alterTgFlag == 1 ? 'checked':'';
				echo "<input type=\"checkbox\" name=\"alterTgFlag\" value=\"$alterTgFlag\" onClick=\"javascript:selCheckBox(this)\" $checkeStr>Enable";
			echo "</td>";	
		echo "</tr>";
	}//end flag
	
	
//	echo "<table border=\"1\" width=\"100%\" cellpadding=\"1\" cellspacing=\"0\" bordercolor=\"#666666\" bordercolordark=\"#FFFFFF\">";
		echo "<tr>";
			echo "<td width=\"50%\">Alternative TG</td>";
			echo "<td width=\"50%\">";
			{
				if($alterTgFlag==1)
					echo "<select name='set_AlterTg' style=width:'40%'>";
				else
					echo "<select name='set_AlterTg' style=width:'40%' disabled>";
				for($i=0; $i< sizeof($ElementArr); $i++)
				{
					if($ElementArr[$i][tg]==$trunkgp || $ElementArr[$i][name]=="CNF Center")
						continue;
					echo "<option value=\"{$ElementArr[$i][tg]}\" ";
					if($ElementArr[$i][tg]==$alternativeTG)
						echo " selected";	
					echo ">{$ElementArr[$i][name]}";
				}
				//echo "<option>$trunkgp</option>";
				echo "</select>";
			}
			echo "</td>";	
		echo "</tr>";
		//=================================webname=IUA==========================================
		if($webname=="IUA")
		{
			
			//===============get the all ports instanceNo belong the ISDN trunk group=========
			$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
			{
				$temp_trunk_no=hexdec(getBitValue($rows[initValue],'0.0-0.7'))+0;
				if($trunkgp==$temp_trunk_no)
				{
					$e1_contain[$e1_count]=$rows[instanceNo];
					$e1_count++;
				}
				
			}while($rows=mysqli_fetch_array($result));
			/*
			echo "<script language=\"JavaScript\">\n";
			echo "alert('$e1_count');\n";
			echo "</script>";
			*/
			//===============get the ISDN trunk group parameter=============================
			$database="OBJ_322";
			$sql="select instanceNo,initValue from param_99 where level_1=2 and level_2=1 and level_3=4 and instanceNo=$trunkgp";
			$result=@mysqli_query($pubConn,$sql);
			$rows=@mysqli_fetch_array($result);
			//=====get the parameter of trunk protocol stack 12.0-12.7
			$protocol_stack=hexdec(getBitValue($rows[initValue],'12.0-12.7'))+0;
			$protocol_stack_label=array(0=>"ITU",1=>"ANSI");
			
			echo "<tr>";
				echo "<td>Protocol Stack</td>";
				echo "<td>";
				//
					echo "<select style=\"width:40%\" name=\"protocol_stack_select\" onChange=\"javascript:protocol_stack_select_change()\">";
						for($i=0;$i<2;$i++)
						{
							if($i==$protocol_stack)
								echo "<option value=$i selected>{$protocol_stack_label[$i]}</option>";
							else
								echo "<option value=$i>{$protocol_stack_label[$i]}</option>";		
						}
					echo "</select>";
				echo "</td>";
			echo "</tr>";			
			//=====get the parameter of trunk NFAS Flag
			$NFAS_flag=hexdec(getBitValue($rows[initValue],'13.0-13.7'))+0;
			$NFAS_flag_label=array(0=>"Disable",1=>"Enable");
			echo "<tr>";
				echo "<td>NFAS Flag</td>";
				echo "<td>";
				//==ITU
				if($protocol_stack==0)
					echo "<select style=\"width:40%\" name=\"nfas_flag_select\" disabled>";
				//==ANSI
				else 
					echo "<select style=\"width:40%\" name=\"nfas_flag_select\">";	
						for($i=0;$i<2;$i++)
						{
							if($i==$NFAS_flag)
								echo "<option value=$i selected>{$NFAS_flag_label[$i]}</option>";
							else
								echo "<option value=$i>{$NFAS_flag_label[$i]}</option>";	
						}
					echo "</select>";
				echo "</td>";
			echo "</tr>";
			//=======get the parameter of trunk Primary D-channel
			$Primary_D_channel=hexdec(getBitValue($rows[initValue],'14.0-14.7'))+0;
			echo "<tr>";
			echo "<td>Primary D-channel</td>";
			echo "<td>";
			//==ITU
			if($protocol_stack==0)
			{
				//echo "<input disabled type=\"text\" size=21 maxlength=3 name=\"Primary_D_channel_text\" value=$Primary_D_channel>";
				echo "<select style=\"width:40%\" disabled size=1 name=\"Primary_D_channel_text\">";
				if($e1_count!=0)
				{
					for($index=0;$index<$e1_count;$index++)
					{
						if($e1_contain[$index]==$Primary_D_channel)
							echo "<option value={$e1_contain[$index]} selected>{$e1_contain[$index]}</option>";
						else
							echo "<option value={$e1_contain[$index]}>{$e1_contain[$index]}</option>";	
					}
				}
				else 
					echo "<option value=0 selected>None</option>";
				echo "</select>";
			}
			//==ANSI
			else
			{
				//echo "<input type=\"text\" size=21 maxlength=3 name=\"Primary_D_channel_text\" value=$Primary_D_channel>";
				echo "<select style=\"width:40%\" size=1 name=\"Primary_D_channel_text\">";
				if($e1_count!=0)
				{
					for($index=0;$index<$e1_count;$index++)
					{
						if($e1_contain[$index]==$Primary_D_channel)
							echo "<option value={$e1_contain[$index]} selected>{$e1_contain[$index]}</option>";
						else
							echo "<option value={$e1_contain[$index]}>{$e1_contain[$index]}</option>";	
					}
				}
				else 
					echo "<option value=0 selected>None</option>";
				echo "</select>";
			}
			echo "</td>";
			echo "</tr>";
			//=========get the parameter of trunk Backup D-channel
			$Backup_D_channel=hexdec(getBitValue($rows[initValue],'15.0-15.7'))+0;
			echo "<tr>";
			echo "<td>Backup D-channel</td>";
			echo "<td>";
			//==ITU
			if($protocol_stack==0)
			{
				//echo "<input disabled type=\"text\" size=21 maxlength=3 name=\"Backup_D_channel_text\" value=$Backup_D_channel>";
				echo "<select style=\"width:40%\" disabled size=1 name=\"Backup_D_channel_text\">";
				if($e1_count!=0)
				{
					for($index=0;$index<$e1_count;$index++)
					{
						if($e1_contain[$index]==$Backup_D_channel)
							echo "<option value={$e1_contain[$index]} selected>{$e1_contain[$index]}</option>";
						else
							echo "<option value={$e1_contain[$index]}>{$e1_contain[$index]}</option>";	
					}
				}
				else 
					echo "<option value=0 selected>None</option>";
				echo "</select>";
			}
			//==ANSI
			else
			{
				//echo "<input type=\"text\" size=21 maxlength=3 name=\"Backup_D_channel_text\" value=$Backup_D_channel>";
				echo "<select style=\"width:40%\" size=1 name=\"Backup_D_channel_text\">";
				if($e1_count!=0)
				{
					for($index=0;$index<$e1_count;$index++)
					{
						if($e1_contain[$index]==$Backup_D_channel)
							echo "<option value={$e1_contain[$index]} selected>{$e1_contain[$index]}</option>";
						else
							echo "<option value={$e1_contain[$index]}>{$e1_contain[$index]}</option>";	
					}
				}
				else 
					echo "<option value=0 selected>None</option>";
				echo "</select>";
			}
			echo "</td>";
			echo "</tr>";
			
		}
		//
		
	
	echo "</table>";
}





if($setname=="BTS")
{
	
	
	
	{//get all prefix use bye BTS
		$oidstr = '2.1.2';
		$objWhereStr= '';
		$objWhereStr =getLevelWhere($oidstr);		
		
		$defSql = " SELECT initValue,instanceNo FROM $paramTable WHERE $objWhereStr ORDER BY instanceNo";
		//echo $defSql;
		$defRes = @mysqli_query($pubConn,$defSql);
		echo mysqli_error($pubConn);
		$offset_enable = "10.7-10.7";
		$offset_Properties = "10.2-10.3";	
		$offset_calltype = "10.4-10.6";
		$offset_ton_in = "0.0-0.3";
		$offset_ton_out="0.4-0.7";
		$i=0;	
		while($row = @mysqli_fetch_array($defRes))
		{
			$prefix_enable=hexdec(getBitValue($row[initValue],$offset_enable));
			$prefix_calltype=hexdec(getBitValue($row[initValue],$offset_calltype));
			if($prefix_enable && $prefix_calltype==1)//enable,Emergency
			{
				$PrefixNoArr[$i][no]=$row[instanceNo];
				//getPrefix
				$oidstr = '2.1.1';
				$objWhereStr =getLevelWhere($oidstr);		
		
				$tmpSql = " SELECT initValue from $paramTable WHERE $objWhereStr and instanceNo='$row[instanceNo]'";
				$tmpRes = @mysqli_query($pubConn,$tmpSql);
				$tmpRow = @mysqli_fetch_array($tmpRes);
				$tmpPrefix=str_replace('E','',$tmpRow[initValue]);
				if(strlen($tmpPrefix)==0)
					//$tmpPrefix = "PrefixNo " . $row[instanceNo];
					$tmpPrefix = '--';
					
				//$PrefixNoArr[$i][prefix]=$row[instanceNo] . "(prefix=$tmpPrefix)";
				$PrefixNoArr[$i][prefix]=$tmpPrefix;
				$i++;
			}
		}
		
		{//增加一个新的备选prefix
			$oidstr = '2.1.2';
			$objWhereStr= '';
			$objWhereStr =getLevelWhere($oidstr);		
			
			$defSql = " SELECT initValue,instanceNo FROM $paramTable WHERE $objWhereStr ORDER BY instanceNo";
			//echo $defSql;
			$defRes = @mysqli_query($pubConn,$defSql);
			echo mysqli_error($pubConn);
			$offset_enable = "10.7-10.7";
			while($row = @mysqli_fetch_array($defRes))
			{
				$prefix_enable=hexdec(getBitValue($row[initValue],$offset_enable));
				if(!$prefix_enable)//disable
				{
					$newInstanceNo=$row[instanceNo];
					//getPrefix
					$oidstr = '2.1.1';
					$objWhereStr =getLevelWhere($oidstr);		
			
					$tmpSql = " SELECT initValue $paramTable WHERE $objWhereStr and instanceNo='$row[instanceNo]'";
					$tmpRes = @mysqli_query($pubConn,$tmpSql);
					$tmpRow = @mysqli_fetch_array($tmpRes);
					$newPrefix=str_replace('E','',$tmpRow[initValue]);					
					break;
				}
			}
			$PrefixNoArr[$i][no]=$newInstanceNo;
			//$PrefixNoArr[$i][prefix]="New {$newInstanceNo}";
			$PrefixNoArr[$i][prefix]="New";
		}
	}
	{//get org prefix
		$objstrset='2.2.7';
		$objWhereStr =getLevelWhere($objstrset);		
		
		$paramSql = " SELECT initValue,instanceNo FROM $paramTable  
					WHERE $objWhereStr AND instanceNo ='$instanceNo' ";
		$Result = mysqli_query($pubConn,$paramSql);				
		$Row	= mysqli_fetch_array($Result);
		
		$PrefixNo = hexdec(getBitValue($Row[initValue],'5.0-5.7'));
	}
	{//show select
//	echo "<table border=\"1\" width=\"100%\" cellpadding=\"1\" cellspacing=\"0\" bordercolor=\"#666666\" bordercolordark=\"#FFFFFF\">";
		echo "<tr>";
			echo "<td width=\"50%\">Prefix</td>";
			echo "<td width=\"50%\">";
			{
				echo "<select name='set_PrefixNo' style=width:'40%'>";
				for($i=0; $i< sizeof($PrefixNoArr); $i++)
				{
					echo "<option value=\"{$PrefixNoArr[$i][no]}\" ";
					if($PrefixNoArr[$i][no]==$PrefixNo)
						echo " selected";	
					echo ">{$PrefixNoArr[$i][prefix]}";
				}
				echo "</select>";
			}
			echo "</td>";	
		echo "</tr>";
	}
	
	{//get all lac belong to this BSS
		$oidstr = '2.2.6';
		$objWhereStr =getLevelWhere($oidstr);
		
		$objDb		= 'OBJ_'.$sysTypeNo;
		$paramTable = 'param_'.$sysNo;
		
		$paramSql = " SELECT initValue,readValue,instanceNo FROM $paramTable  
					WHERE $objWhereStr ORDER BY instanceNo
					";
		$Result = mysqli_query($pubConn,$paramSql);
		$n=0;
		while($Row = mysqli_fetch_array($Result))
		{
			$tempGp = hexdec(getBitValue($Row[initValue],'01.0-01.7'));
			$tempFlag = hexdec(getBitValue($Row[initValue],'0.0-0.7'));
			
			if( $tempFlag == 1 && $trunkgp == $tempGp)
			{
				$LAC_value[$n] = hexdec(getBitValue($Row[initValue],'02.0-03.7'));
				$LAC_inst[$n] = $Row[instanceNo];
				//$LAC_pageType[$n] = hexdec(getBitValue($Row[initValue],'4.0-4.7'));
				$n++;
			}
		}
	}//end get lacs
	{//show lac select
		$externID = explode('-',$instanceNo);
		$lacValue = $externID[1];
		echo "<tr>";
			echo "<td width=\"50%\">LAC</td>";
			echo "<td width=\"50%\">";
			{
				echo "<select name='LAC' style=width:'40%'>";
				for($i=0; $i< sizeof($LAC_value); $i++)
				{
					echo "<option value=\"{$LAC_value[$i]}\" ";
					if($LAC_value[$i]==$lacValue)
						echo " selected";	
					echo ">{$LAC_value[$i]}";
				}
				echo "</select>";
			}
			echo "</td>";	
		echo "</tr>";
	}
}//end $setName="BTS"

echo "</table>";
echo "\n<input type=\"hidden\" name=\"webname\" value=\"$webname\">";
echo "\n<input type=\"hidden\" name=\"backurl\" value=\"$backurl\">";
echo "\n<input type=\"hidden\" name=\"linkset\" value=\"$linkset\">";
echo "\n<input type=\"hidden\" name=\"trunkgp\" value=\"$trunkgp\">";
echo "\n<input type=\"hidden\" name=\"language\" value=\"$language\">";
echo "\n<input type=\"hidden\" name=\"setname\" value=\"$setname\">";
echo "\n<input type=\"hidden\" name=\"objIdStr\" value=\"$objIdStr\">";
echo "\n<input type=\"hidden\" name=\"sysId\" value=\"$sysId\">";
echo "\n<input type=\"hidden\" name=\"instanceNo\" value=\"$instanceNo\">";
echo "</Form>";
?>
</body>
</html>
