<?php 
/*****************************************************   
*********************************************************/    
require("../sub_inc/commfunc.php");
$DEBUG	= 0;
$TEST	= ($TEST > 0)?$TEST:0;

//echo "page_top:$page_top<br>";
//test
//echo "smsFormatShow:$isShowSms<br>";

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

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


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

if($instanceNo == -1)
{
	echo "<script LANGUAGE=\"JavaScript\">";
	echo " location='$backurl';"; 
	echo "</script>";
}

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===================

if($set == 'Save'){
	$oIdstrarr = explode('-',$objIdStr);	
	$externID = explode('-',$instanceNo);
	if($instanceNo == 'new'){
		$instanceNo = ${$setname};
	}
	
	
	if($setname =='Linkset'){
		$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' 
					";
//			echo "$paramSql";
		$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>";		
		
		if($trunkgp =="" && !($webname =='HLR' ||$webname =='VLR' || $webname =='MSC')){
			$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_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);		
			
			
		}
		
	}
	if($setname =='Prefix')
	{
		$setPrefix = strtoupper($unit_1_1);
		$setTonIn = $unit_2_1;
		$setTonOut = $unit_2_2;
		checkDupPrefix($instanceNo,$setPrefix,$setTonIn,$setTonOut);
	}

	for($j=1;$j<sizeof($oIdstrarr);$j++)
	{
		if($setname == 'Linkset' ||$setname == 'TrunkGroup' ||$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);		
		
		}
	}
	
	{//关联参数设置
		$oIdstrarr = explode('-',$objIdStr);
		switch($setname){
		case 'TrunkGroup':
		{
				$RAoffsetarr = array(
						"0.0-0.7","2.0-2.7","4.0-4.7","6.0-6.7",
						"8.0-8.7","10.0-10.7","12.0-12.7","14.0-14.7",
						"16.0-16.7","18.0-18.7","20.0-20.7","22.0-22.7",
						"24.0-24.7","26.0-26.7","28.0-28.7","30.0-30.7",
						"32.0-32.7");
			
				$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);
				//echo "$paramSql";
				$RAC 		= hexdec(getBitValue($Row[initValue],'10.0-10.7'));
				$RAC    = $RAC <= 15 ? $RAC : 16;
				$externID[1] = $externID[1] <= 15 ? $externID[1] : 16;
				
			
				$objstrset='2.1.3';
				$objWhereStr =getLevelWhere($objstrset);				
				$paramSql = " SELECT initValue,readValue,instanceNo FROM $paramTable  
										WHERE $objWhereStr
										";											
				$Result = mysqli_query($pubConn,$paramSql);				
				while($Row = mysqli_fetch_array($Result))
				{
					$tempGp = hexdec(getBitValue($Row[initValue],$RAoffsetarr[$externID[1]]));
						
						if($trunkgp == $tempGp)
						{
							//$tmp = $externID[1];
							$Row[initValue] = setBitValue($Row[initValue],$RAoffsetarr[$externID[1]],FF);
							$tempGp = dechex($tempGp);
							$tempGp = omc_keep_length($tempGp,0,2);
							$Row[initValue] = setBitValue($Row[initValue],$RAoffsetarr[$RAC],$tempGp);			
							$updSql = "UPDATE $paramTable SET initValue = '$Row[initValue]'   
							WHERE $objWhereStr AND instanceNo = '$Row[instanceNo]'
							";										
							mysqli_query($pubConn,$updSql);									
						}
				}
			
				break;
		}
		case 'Linkset':
		{
		  switch($webname){
				case	'HLR':
					$SSN = 6;
					break;
				case	'VLR':
					$SSN = 7;
					break;
				case	'MSC':
					$SSN = 8;
					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' 
						";
//			echo "$paramSql";
			$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 =='HLR' ||$webname =='VLR' || $webname =='MSC'){
				$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);				
				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 && $GTT_SSN ==$SSN && $flag == 1 && $GTT_NetID == $oldNetID){
							$DPC_GTT				=	hexdec($DPC);
							$DPC_GTT    = omc_keep_length($DPC_GTT,0,6);
							$Row[initValue]	= setBitValue($Row[initValue],'24.0-26.7',$DPC_GTT);
							$SSN_GTT				=	hexdec($SSN);
							$SSN_GTT    = omc_keep_length($SSN_GTT,0,2);
							$Row[initValue]	= setBitValue($Row[initValue],'27.0-27.7',$SSN_GTT);
							$NetID_GTT				=	hexdec($NetID);
							$NetID_GTT    = omc_keep_length($NetID_GTT,0,2);
							$Row[initValue]	= setBitValue($Row[initValue],'23.0-23.7',$NetID_GTT);								
							$updSql = "UPDATE $tmpTable SET initValue = '$Row[initValue]'   
								WHERE $objWhereStr AND instanceNo = '$Row[instanceNo]'
								";
							mysqli_query($pubConn,$updSql);								
						}
				}					
			}
			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);

				$updSql = "UPDATE $tmpTable SET initValue = '$Row[initValue]'   
					WHERE $objWhereStr AND instanceNo = '$trunkgp'
					";
				mysqli_query($pubConn,$updSql);									
			}

			//修改routing DPC
			//修改AAS OPC
			{
				$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);
					$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);
						$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 = $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);
						}
						$updSql = "UPDATE $paramTable SET initValue = '$Row_1[initValue]'   
							WHERE $objWhereStr_new AND instanceNo = '$Row_1[instanceNo]'
							";
//							echo "$Alternative<br>";
//							echo "$updSql<br>";
						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;
//							echo "$oidstr";
						$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;
//							echo "$oidstr";
						$objWhereStr= '';
						$objWhereStr =getLevelWhere($oidstr);
						$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 'E1':
		{
			$objstrset='2.4.2';
			$objWhereStr= '';
			$objWhereStr =getLevelWhere($objstrset);
			$zero		= $trunkgp < 15 ? '0' :'';
			$HEXtrunkgp = strtoupper($zero.dechex($trunkgp));
			$updSql = "UPDATE $paramTable SET initValue = '$HEXtrunkgp'   
			WHERE $objWhereStr AND instanceNo = '$instanceNo'
			";
			mysqli_query($pubConn,$updSql);	
			//set flag=1
		
			$oidstr = '2.4.4';
			$objWhereStr= '';
			$objWhereStr =getLevelWhere($oidstr);						
			$defSql = " SELECT initValue FROM $paramTable WHERE $objWhereStr AND instanceNo ='$instanceNo'";
			$defRes = mysqli_query($pubConn,$defSql);
			$row = mysqli_fetch_array($defRes);
			
			$flagoffset = "1.0-1.7";			
			$row[initValue] = setBitValue($row[initValue],$flagoffset,'01');
				$delSql = "UPDATE $paramTable SET initValue = '$row[initValue]' 
		            WHERE $objWhereStr AND instanceNo ='$instanceNo'";
			$delRes = mysqli_query($pubConn,$delSql);

			break;
		}
		case 'Prefix':
		case 'Def Prefix':
		{
			if($setname=='Prefix')
				$setTG = $trunkgp;
			else
				$setTG = $defPrefixTg;
			//echo "trunktg:$trunkgp<br>";	
			//echo "defPrefixTg:$defPrefixTg<br>";
			$objstrset='2.1.3';
			$objDb = 'OBJ_322';
			$paramTable = 'param_99';
			$objWhereStr =getLevelWhere($objstrset);				
			$hex_set_tg = $HEXtrunkgp = omc_keep_length(dechex($setTG),0,2);
			$updSql = "UPDATE $paramTable SET initValue = '$hex_set_tg'   
						WHERE $objWhereStr AND instanceNo = '$instanceNo'";	
			//echo "<br>$updSql";									
			mysqli_query($pubConn,$updSql);
			//exit();

			//Set flag = 1
			$objstrset='2.1.2';
			$objWhereStr =getLevelWhere($objstrset);				
			$paramSql = " SELECT initValue,instanceNo FROM $paramTable  
									WHERE $objWhereStr AND instanceNo ='$instanceNo'
									";
			//echo "<br>$paramSql";						
			$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'
			";	
			//echo "<br>$updSql";											
			mysqli_query($pubConn,$updSql);				
			break;
		}
		case 'E1_link':	
		{
				$objstrset='2.5.1';
				$objWhereStr =getLevelWhere($objstrset);				
				$paramSql = " SELECT initValue,readValue,instanceNo FROM $paramTable  
				WHERE $objWhereStr AND instanceNo ='$instanceNo'
				";
//					echo "$paramSql<br>";
				$Result = mysqli_query($pubConn,$paramSql);				
				$Row		= mysqli_fetch_array($Result);
				$zero		= $linkset < 15 ? '0' :'';
				$HEXlinkset = strtoupper($zero.dechex($linkset));
				$Row[initValue]	= setBitValue($Row[initValue],'00.0-00.7',$HEXlinkset);
				$Row[initValue]	= setBitValue($Row[initValue],'06.1-06.1','1');
				$updSql = "UPDATE $paramTable SET initValue = '$Row[initValue]'   
				WHERE $objWhereStr AND instanceNo = '$instanceNo'
				";
				//Set flag = 1
				mysqli_query($pubConn,$updSql);	

						
			break;
		}
		case 'BTS':	
		{
				$objstrset='2.2.8';
				$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>";
				$tempGp = dechex($trunkgp);
				$tempGp = omc_keep_length($tempGp,0,2);					
				$Row[initValue]	= setBitValue($Row[initValue],'01.0-01.7',$tempGp);
				if($DEBUG) echo "$Row[initValue]<br>";					
				$LAC = dechex($externID[1]);
				$LAC = omc_keep_length($LAC,0,4);				
				$Row[initValue] = setBitValue($Row[initValue],'02.0-03.7',$LAC);					
				$Row[initValue] = setBitValue($Row[initValue],'0.0-0.7','01');					

				if($DEBUG) echo "$Row[initValue]<br>";										
				$Em_CellNum = getBitValue($Row[initValue],'04.0-05.7');
				$updSql = "UPDATE $paramTable SET initValue = '$Row[initValue]'   
				WHERE $objWhereStr AND instanceNo = '$instanceNo'
				";
				mysqli_query($pubConn,$updSql);	
				if($DEBUG) echo "$updSql<br>";										
				//----------------------------
				$objstrset='2.2.5';
				$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],'03.0-04.7',$Em_CellNum);
				$LAC = dechex($externID[1]);
				$LAC = omc_keep_length($LAC,0,4);				
				$Row[initValue] = setBitValue($Row[initValue],'01.0-02.7',$LAC);					
				$updSql = "UPDATE $paramTable SET initValue = '$Row[initValue]'   
				WHERE $objWhereStr AND instanceNo = '$instanceNo'
				";
				mysqli_query($pubConn,$updSql);	
			break;
		}
		case 'GTT':
		{
			  switch($webname){
					case	'HLR':
						$SSN = 6;
						break;
					case	'VLR':
						$SSN = 7;
						break;
					case	'MSC':
						$SSN = 8;
						break;
				}							
				//LINKSET DPC	
				$sysId = '222_99_99';
				
				$sysIdArr	= explode('_',$sysId);
				$sysTypeNo	= $sysIdArr[0];
				$sysNo		= $sysIdArr[1];
				$subSysNo	= $sysIdArr[2];
				
				$oidstr = '2.4.1';
				$objWhereStr= '';	
				$objWhereStr =getLevelWhere($oidstr);
				$objDb		= 'OBJ_'.$sysTypeNo;
				$paramTable = 'param_'.$sysNo;
				
				
				$paramSql = " SELECT initValue,readValue,instanceNo FROM $paramTable  
							WHERE subSysNo = '$subSysNo' AND  $objWhereStr AND instanceNo ='$linkset' 
							";
				$Result = mysqli_query($pubConn,$paramSql);				
				$Row		= mysqli_fetch_array($Result);
				$DPC		= getBitValue($Row[initValue],'0.0-2.7');
				$NetID 	= bindec(getBitValue($Row[initValue],'3.0-3.1'));

				//DPC END

				$sysId = '223_99_99';
				
				$sysIdArr	= explode('_',$sysId);
				$sysTypeNo	= $sysIdArr[0];
				$sysNo		= $sysIdArr[1];
				$subSysNo	= $sysIdArr[2];
				
				$oidstr = '2.2';
				$objWhereStr= '';	
				$objWhereStr =getLevelWhere($oidstr);
				$objDb		= 'OBJ_'.$sysTypeNo;
				$paramTable = 'param_'.$sysNo;
				$paramSql = " SELECT initValue,readValue,instanceNo FROM $paramTable  
				WHERE $objWhereStr AND instanceNo ='$instanceNo'
				";
//					echo "$paramSql<br>";
				$Result = mysqli_query($pubConn,$paramSql);				
				$Row		= mysqli_fetch_array($Result);
				
				$DPC		= omc_keep_length($DPC,"0","6");
				$Row[initValue]	= setBitValue($Row[initValue],'24.0-26.7',$DPC);
				$SSN		= omc_keep_length($SSN,"0","2");
				$Row[initValue]	= setBitValue($Row[initValue],'27.0-27.7',$SSN);
				$NetID = dechex($NetID);
				$NetID    = omc_keep_length($NetID,"0","2");
				$Row[initValue]	= setBitValue($Row[initValue],'23.0-23.7',$NetID);		
				$Row[initValue] = setBitValue($Row[initValue],'00.0-00.7','01');
				
				$updSql = "UPDATE $paramTable SET initValue = '$Row[initValue]'   
				WHERE $objWhereStr AND instanceNo = '$instanceNo'
				";
				//Set flag = 1
				mysqli_query($pubConn,$updSql);	

			
		}
		case 'Service number':
		{
			$smscTable = "OBJ_350.param_99";
			$setValue = omc_keep_length($unit_2_1,'E',16,0);
			$updSql = "update $smscTable set initValue='$setValue' where level_1=2 and level_2=2 and level_3=4 and instanceNo=0";
			mysqli_query($pubConn,$updSql);
			
			$setValue = omc_keep_length($unit_3_1,'E',16,0);
			$updSql = "update $smscTable set initValue='$setValue' where level_1=2 and level_2=2 and level_3=4 and instanceNo=1";
			mysqli_query($pubConn,$updSql);
			break;
		}
		default:
		}
//			echo "$updSql";
			echo mysqli_error($pubConn);		
	
		
		if($setname=='Prefix manipulation')//add by arwean 2006-9-1 16:21
		{
			//getElementInfo($infoNo,$elementInfoArr);
			//$eleName = $elementInfoArr[eleName];
			$eleName = "Info".$infoNo;
			$setDb = "OBJ_225";
			$levelWhere = getLevelWhere($oIdstrarr[1]);
			$selSql = "select initValue from param_99 where $levelWhere and instanceNo='$instanceNo'";
			$Result = mysqli_query($pubConn,$selSql);
			$Row = mysqli_fetch_array($Result);
			if(strlen($infoNo)==0)
				$eleName = $webname;
			//====get the ISDN title
			else
			{
				$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);
				do
				{
	
					//======assign tg
					$trunk_tmp=hexdec(getBitValue($rows[initValue],'3.0-3.7'))+0;
					if($trunk_tmp==$trunkgp)
					{
						//=======title
						$title=getBitValue($rows[initValue],'14.0-23.7');
						$temp="";
						for($num=0;$num<10;$num++)
						{
							$str=substr($title,$num*2,2);
							$str=hexdec($str);
							$str=chr($str);
							$temp.=$str;
						}
						$title=$temp;
						$eleName=$title;
						break;
					}					
				}while($rows=mysqli_fetch_array($result));
				
			}
				
			$tmpName = omc_keep_length(toHex($eleName),'0','16',0);//$webname=MSC,SWITCH,PPS.
			$setValue = setBitValue($Row[initValue],'35.0-42.7',$tmpName);
			$updSql = "update OBJ_225.param_99 set initValue='$setValue' where $levelWhere and instanceNo='$instanceNo'";
			mysqli_query($pubConn,$updSql);
			
		}
	
	}
	
	
	if($setname =='Local Prefix')
	{
		//local_prefix_text
		//====把值补到16个字节==
		$local_prefix_text=trim($local_prefix_text);
		
		$n=strlen($local_prefix_text);
		$m=16-$n;
		$set_value="";
		
		for($i=0;$i<$n;$i++)
		{
			$temp=substr($local_prefix_text,$i,1);
			$temp=ord($temp);
			$temp=dechex($temp);
			$set_value.=$temp;
		}
		for($i=0;$i<$m;$i++)
			$set_value.="00";
		
		
		$database="OMC_PUB";
		//==========set the value========
		$setsql = "update OBJ_370.param_99 set initValue='$set_value'	where level_1=2 and level_2=1 and level_3=7 and instanceNo=$instanceNo ";
		if($DEBUG) 
			echo "setsql=$setsql<br>";	
		
		mysqli_query($pubConn,$setsql);
		echo mysqli_error($pubConn);			
	}
	
	//=========set the white list number=======
	if($setname="white_list_number")
	{
		//====start imei type approval code
		$start_type_text=trim($start_type_text);
		$n=strlen($start_type_text);
		for($i=0;$i<6-$n;$i++)
		{
			$start_type_text="0".$start_type_text;
		}
		//====end imei type approval code========
		$end_type_text=trim($end_type_text);
		$n=strlen($end_type_text);
		for($i=0;$i<6-$n;$i++)
		{
			$end_type_text="0".$end_type_text;
		}
		//====start imei final assembly code=====
		$start_final_text=trim($start_final_text);
		$n=strlen($start_final_text);
		for($i=0;$i<2-$n;$i++)
		{
			$start_final_text="0".$start_final_text;
		}
		//=====end imei final assembly code=======
		$end_final_text=trim($end_final_text);
		$n=strlen($end_final_text);
		for($i=0;$i<2-$n;$i++)
		{
			$end_final_text="0".$end_final_text;
		}
		//=====start imei serial number========
		$start_serial_text=trim($start_serial_text);
		$n=strlen($start_serial_text);
		for($i=0;$i<6-$n;$i++)
		{
			$start_serial_text="0".$start_serial_text;
		}
		//=======end imei serial number==========
		$end_serial_text=trim($end_serial_text);
		$n=strlen($end_serial_text);
		for($i=0;$i<6-$n;$i++)
		{
			$end_serial_text="0".$end_serial_text;
		}
		//========start imei software version========
		$start_software_text=trim($start_software_text);
		$n=strlen($start_software_text);
		for($i=0;$i<2-$n;$i++)
		{
			$start_software_text="0".$start_software_text;
		}
		//=======end imei software version===========
		$end_software_text=trim($end_software_text);
		$n=strlen($end_software_text);
		for($i=0;$i<2-$n;$i++)
		{
			$end_software_text="0".$end_software_text;
		}
		
		$database="OMC_PUB";
		$set_value=$start_type_text.$start_final_text.$start_serial_text.$start_software_text;
		$set_value=$set_value.$end_type_text.$end_final_text.$end_serial_text.$end_software_text;
		/*
		$n=strlen($set_value);
		echo "\n<script language=\"JavaScript\">\n";
echo "alert('$n');\n";
echo "</script>\n";
*/
		//==========set the value========
		
		$setsql = "update OBJ_380.param_99 set initValue='$set_value'	where level_1=2 and level_2=1 and level_3=2 and instanceNo=$instanceNo ";
		if($DEBUG) 
			echo "setsql=$setsql<br>";	
		
		mysqli_query($pubConn,$setsql);
		echo mysqli_error($pubConn);
		
	}
	
if($DEBUG){
	echo "<br>debug";
}else{//return page
			echo "<script language='javascript'>";
			/*
			if($setname == 'E1_link' || $setname == 'Linkset')
				echo " location='./wxc2_sp_signaling.php?trunkgp=$trunkgp&linkset=$linkset';";  
			else
				echo " location='./wxc2_sp.php?trunkgp=$trunkgp&linkset=$linkset';";  
			*/	
			echo " location='$backurl';";  
			echo "</script>";
			exit();
}

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

//=======================Show GUI ========================
?> 
<body>
<script LANGUAGE="JavaScript"> 
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";?>" >
<?

echo "<table border=\"0\" width=\"100%\">";
echo "<tr>";
echo "<td width=\"50%\">";
if($from_bss==1)
	echo "$strConfiguration > <a href=\"../overview/overview.php\">Network</a> > <a href=\"$backurl\">BSS</a> > <a href=\"#\">$setname</a>";
else
	echo "$strConfiguration > <a href=\"../overview/overview.php\">Network</a> > <a href=\"$backurl\">$webname</a> > <a href=\"#\">$setname</a>";
echo "</td>";
echo "<td width=\"50%\" align=\"right\" title=\"Help\">";
//showHelp($helpId);
echo "</td>";
echo "</tr>";
echo "</table>";
echo "<br>";
$oIdstrarr = explode('-',$objIdStr);
$routingNo = explode('-',$instanceNo);

echo "<table width=\"100%\">";
echo "<tr>";
echo "<td width=\"70%\">&nbsp";
/*
	if($instanceNo == 'new' || $oIdstrarr[0] =='new'){
		echo "<b>Add a $setname:</b>&nbsp;&nbsp;";
	}else{
		echo "<b>Edit $setname:</b>&nbsp;&nbsp;";
	}
	*/
echo "</td>";

echo "<td width=\"20%\">";
	echo "<input type=\"submit\" name=\"set\" value=\"Save\" class=\"button\" style=\"left: 1; top: 2; width: 60; height: 25; position: relative\">";
	echo "&nbsp;&nbsp;&nbsp;";
	echo "<input type=\"reset\" name=\"Reset\" value=$strUndo class=\"button\" style=\"left: 1; top: 2; width: 60; height: 25; position: relative\">";
echo "</td>";

echo "<td width=\"10%\">";
//echo "$backurl";
$backurl=$backurl."&smsFormatShow=$isShowSms"."&scroll_y=".$sub_page_top;

echo "<p 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 "<br>";

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=="Local Prefix")
{
	//================get the value of the local prefix of mnp=========
	$database="OBJ_370";
	$sql="select initValue from param_99 where level_1=2 and level_2=1 and level_3=7 and instanceNo=$instanceNo ";
	$result=@mysqli_query($pubConn,$sql);
	$rows=@mysqli_fetch_array($result);
	$tmp_value=$rows[initValue];
	$temp="";
			for($num=0;$num<16;$num++)
			{
				$str=substr($tmp_value,$num*2,2);
				$str=hexdec($str);
				$str=chr($str);
				$temp.=$str;
			}
	$local_prefix_value=trim($temp);		
	echo "<tr>";
		echo "<td>Local Prefix</td>";
		echo "<td><input type=text name=\"local_prefix_text\" value='$local_prefix_value' maxlength=16></td>";
	echo "</tr>";
}

//=====================white list number for eir============================
if($setname=="white_list_number")
{
	//================get the value of this instanceNo=========
	$database="OBJ_380";
	$sql="select initValue from param_99 where level_1=2 and level_2=1 and level_3=2 and instanceNo=$instanceNo ";
	$result=@mysqli_query($pubConn,$sql);
	$rows=@mysqli_fetch_array($result);
	
	
	$start_type=getBitValue($rows[initValue],'0.0-2.7');
	$end_type=getBitValue($rows[initValue],'8.0-10.7');
	$start_final=getBitValue($rows[initValue],'3.0-3.7');
	$end_final=getBitValue($rows[initValue],'11.0-11.7');
	$start_serial=getBitValue($rows[initValue],'4.0-6.7');
	$end_serial=getBitValue($rows[initValue],'12.0-14.7');
	$start_software=getBitValue($rows[initValue],'7.0-7.7');
	$end_software=getBitValue($rows[initValue],'15.0-15.7');
	
	
	//=====start IMEI type approval code
	echo "<tr>";
		echo "<td>Start IMEI Type Approval Code</td>";
		echo "<td><input type=text name=\"start_type_text\" value=$start_type maxlength=6></td>";
	echo "</tr>";
	//=====end IMEI type approval code
	echo "<tr>";
		echo "<td>End IMEI Type Approval Code</td>";
		echo "<td><input type=text name=\"end_type_text\" value=$end_type maxlength=6></td>";
	echo "</tr>";	
	
	//=====start IMEI final assembly code
	echo "<tr>";
		echo "<td>Start IMEI Final Assembly Code</td>";
		echo "<td><input type=text name=\"start_final_text\" value=$start_final maxlength=2></td>";
	echo "</tr>";
	
	//=====end IMEI final assembly code
	echo "<tr>";
		echo "<td>End IMEI Final Assembly Code</td>";
		echo "<td><input type=text name=\"end_final_text\" value=$end_final maxlength=2></td>";
	echo "</tr>";
	
	//=====start IMEI serial number
	echo "<tr>";
		echo "<td>Start IMEI Serial Number</td>";
		echo "<td><input type=text name=\"start_serial_text\" value=$start_serial maxlength=6></td>";
	echo "</tr>";
	
	//=====end IMEI serial number
	echo "<tr>";
		echo "<td>End IMEI Serial Number</td>";
		echo "<td><input type=text name=\"end_serial_text\" value=$end_serial maxlength=6></td>";
	echo "</tr>";
	//=====start IMEI software version
	echo "<tr>";
		echo "<td>Start IMEI Software Version</td>";
		echo "<td><input type=text name=\"start_software_text\" value=$start_software maxlength=16></td>";
	echo "</tr>";
	//=====end IMEI software version
	echo "<tr>";
		echo "<td>End IMEI Software Version</td>";
		echo "<td><input type=text name=\"end_software_text\" value=$end_software maxlength=16></td>";
	echo "</tr>";
}

if($setname != 'BTS' && $oIdstrarr[0] !='no'){
	{//xxx No.
		echo "<tr>";
		echo "<td>$setname No.</td>";
			if($instanceNo == 'new')
			{
				switch($setname){
				case 'TrunkGroup':
					$nowid = $trunkgp;
					break;
				case 'Linkset':
					$nowid = $linkset;
					break;
				default:
					$nowid = $instanceNo;
				}
				$objDb 			= omcGetObjDb($sysTypeNo);
				$paramConfTable	= omcGetObjTbl($sysTypeNo,paramConf);
					
				$objWhereStr =getLevelWhere($oIdstrarr[0]);
				
//200510004				$paramTable = 'param_99';
				$getInstanceSql="SELECT initValue,instanceNo FROM $paramTable
									WHERE  $objWhereStr";
	//		echo "$getInstanceSql";
				$result=mysqli_query($pubConn,$getInstanceSql);
	
				$flagoffset = omcShowParam($oIdstrarr[0],$sysTypeNo,'flag',$language,'1');					
	
							
				echo "<td>";
				$nShowsize ='40%';
				echo "<select name=\"$setname\" size=\"1\" style=width:\"$nShowsize\">";
				
				while($row=mysqli_fetch_array($result))
				{
					if($nowid == $row[instanceNo]){
						echo "<option value=$row[instanceNo] selected>$row[instanceNo]</option>";
						continue;
					}
					$flag	=	BinDec(getBitValue($row[initValue],$flagoffset));
					if(!$flag)
						echo "<option value=$row[instanceNo]>$row[instanceNo]</option>";
				}
				echo "</select>";
				echo "</td>";
			}
			else
			{
				//echo "<td>$instanceNo</td>";
				echo "<td>$routingNo[0]</td>";
				
			}
		
		echo "</tr>";
	}
}
for($j=1;$j<sizeof($oIdstrarr);$j++)
{
	if($setname == 'Linkset' ||$setname == 'CIC'){
		$tmp = $j -1;
		$instNo = $routingNo[$tmp];
	}elseif($setname == 'TrunkGroup'){
		$instNo = $routingNo[0];
	}else{
		$instNo = $instanceNo;
	}
	omcShowParam($oIdstrarr[$j],$sysTypeNo,$instNo,$webname,$j);			
}

if($setname=='Def Prefix')
{
	{//other elements
		$othersElementObjIdStr='2.11';
		$levelWhere = getLevelWhere($othersElementObjIdStr);
		if($DEBUG) echo "<BR>levelWhere=$levelWhere";
		$othersElementParamTable='OBJ_225.param_99';
		$getSql="SELECT initValue,instanceNo FROM $othersElementParamTable 
					WHERE $levelWhere and initValue LIKE '01%'";
		if($DEBUG) echo "<BR>getSql=$getSql";
		$result	=mysqli_query($pubConn,$getSql);
		echo mysqli_error($pubConn);
		$typeOffset 	= '1.0-1.7';
		$tgOffset 		= '3.0-3.7';
		$nameOffset 	= '14.0-23.7';
		$i=0;
		while($rows=mysqli_fetch_array($result))
		{
			if($DEBUG)echo "<BR>initValue=$rows[initValue]";
			$tmpType=getBitValue($rows[initValue],$typeOffset);
			if($tmpType==0)
				continue;
			$type = hexdec($tmpType);
			if($type==16 || $type == 17)
			{
				$tg = hexdec(getBitValue($rows[initValue],$tgOffset));
				$name=getBitValue($rows[initValue],$nameOffset);
				if($name==0)
					$name=$tg;
				else
					$name=trim(toAscii($name));	
					
				$switchArr[$i][tg] = $tg;				
				$switchArr[$i][name] = $name;
				$i++;
			}
		}
	}//end otherelments
	
	echo "<tr>";
	echo "<td>Trunk Group</td>";
	echo "<td>";
		echo "<select name='defPrefixTg' style=width:'40%'>";
		for($i=0; $i< sizeof($switchArr); $i++)
		{
			echo "<option value=\"{$switchArr[$i][tg]}\" ";
			if($switchArr[$i][tg]==$defPrefixTg)
				echo " selected";	
			echo ">{$switchArr[$i][name]}";
		}
		echo "</select>";
	echo "</td>";
	echo "</tr>";
	
	
	

	
	
}
echo "</table>";
if(isset($convInstNo))
	echo "\n<input type=\"hidden\" name=\"convInstNo\" value=\"$convInstNo\">";
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=\"infoNo\" value=\"$infoNo\">";
echo "\n<input type=\"hidden\" name=\"sysId\" value=\"$sysId\">";
echo "\n<input type=\"hidden\" name=\"instanceNo\" value=\"$instanceNo\">";
echo "</Form>";
?>


<?php


?>
</body>
</html>
