<?php
/*********************************************************      
 程序说明：         
    功能说明：设置七号信令中的 GTT
    调用关系：调用: header.inc    
              被调用:        
    变量说明：
    作者：hewd   2003-04-10      
修改注释：      
NO.1      
姓名： Cui Ticun         
时间：2004-4-21
修改说明：Support OMC7.0,从advanced移到configuration中，修改
		 和添加了上方的操作按钮
*********************************************************/
require("../sub_inc/commfunc.php");
$DEBUG = 0;

if($DEBUG) echo "<br>正在调试中！！";
//==========================================================
//变量定义
//==========================================================
$pubDb			= 'OMC_PUB';
$numberPerPage	= 100;		//每页纪录数
$paramTable		='OBJ_223.param_99';



$totalLen	= 43;

$nEnable = '01';

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


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

//==========================================================
//输入变量
//==========================================================
if($DEBUG) echo "<BR>sysId		= $sysId";
if($DEBUG) echo "<BR>instanceNo	= $instanceNo";
if($DEBUG) echo "<BR>objIdStr	= $objIdStr";


$GTTtableConfArr=array(
	array('Start number',			'03.0-12.7'),
	array('End number',				'13.0-22.7'),
	array('On/off',					'00.0-00.7'),
	array('Numbering plan',			'01.0-01.7'),
	array('Network indicator',		'23.0-23.7'),
	array('DPC',					'24.0-26.7'),
	array('SSN',					'27.0-27.7'),
	array('Route indicator',		'28.0-28.7'),
	array('Address indicator',		'29.0-29.7'),
	array('Replaced start digit',	'30.0-30.7'),
	array('Replaced end digit',		'31.0-31.7'),
	array('Outgoing number plan',	'32.0-32.7'),
	array('Replacing digits',		'33.0-42.7'),
	array('TT',						'02.0-02.7')
);

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

$numPlanConfArr=array(
	array('00','0'),
	array('01','MSISDN'),
	array('06','IMSI(E.212)'),
	array('07','GT(E.214)')
);

$addressIdConfArr=array(
	array('00','NULL'),
	array('01','DPC'),
	array('02','SSN'),
	array('03','DPC+SSN'),
	array('04','GT'),
	array('05','GT+DPC'),
	array('06','GT+SSN'),
	array('07','GT+DPC+SSN')
);

{//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);
	$tmpDb		= 'OBJ_'.$sysTypeNo;
	$tmpTable = 'param_'.$sysNo;
	
	
	$paramSql = " SELECT initValue,readValue,instanceNo FROM $tmpTable  
				WHERE subSysNo = '$subSysNo' AND  $objWhereStr AND instanceNo ='$linkset' 
				";
	$Result = mysqli_query($pubConn,$paramSql);				
	$Row		= mysqli_fetch_array($Result);
	$DPC		= hexdec(getBitValue($Row[initValue],'0.0-2.7'));
	$NetID 	= bindec(getBitValue($Row[initValue],'3.0-3.1'));
	$NetID	=	omc_keep_length($NetID,"0","2");
	//DPC END
}//end linset dpc

$offsetAppType='00.0-00.7';
$offsetGrpNo = '01.0-01.7';
$offsetBitFlag = '02.0-02.7';//if '1', global title.

$niTypeArr = getNiType();


function showNumber($number)
{
	$newNumber =str_replace('F','',$number);
	return($newNumber);
}
//==========================================================
//数据处理
//==========================================================


//保存改动
if($_SERVER['REQUEST_METHOD'] == "POST")
{
	if(0)
	{
		echo "<br>nStartDigit=$nStartDigit";
		echo "<br>nEndDigit=$nEndDigit";
		echo "<br>nEnable=$nEnable";
		echo "<br>nNumPlan=$nNumPlan";
		echo "<br>nNetIDName=$nNetIDName";
		echo "<br>nDPC=$nDPC";
		echo "<br>nSSN=$nSSN";
		echo "<br>nRouterID=$nRouterID";
		echo "<br>nAddressID=$nAddressID";
		echo "<br>nRep_start=$nRep_start";
		echo "<br>nRep_end=$nRep_end";
		echo "<br>nOutNumPlan=$nOutNumPlan";
		echo "<br>nRep_digit=$nRep_digit";
	}

	//补齐
	$nStartDigit = omc_keep_length($nStartDigit,"F","20","0");
	$nEndDigit = omc_keep_length($nEndDigit,"F","20","0");
	$nDPC = dechex($nDPC);
	$nDPC = omc_keep_length($nDPC,"0","6","1");
	$nSSN = dechex($nSSN);//roger
	$nSSN = omc_keep_length($nSSN,"0","2","1");//roger

	for($i=0;$i< $totalLen;$i++)
	{
		$totalValue=$totalValue."00";
	}
	$totalValue=setBitValue($totalValue,$GTTtableConfArr[0][1],$nStartDigit);
	//if($SSN == 6||$SSN == 11)
	if($appType == 1||$appType == 3||$appType == 5)
	{
		$totalValue=setBitValue($totalValue,$GTTtableConfArr[1][1],$nEndDigit);
	}
	else
	{
		$totalValue=setBitValue($totalValue,$GTTtableConfArr[1][1],$nStartDigit);		
	}
	$totalValue=setBitValue($totalValue,$GTTtableConfArr[2][1],$nEnable);
	$totalValue=setBitValue($totalValue,$GTTtableConfArr[3][1],$nNumPlan);
	$totalValue=setBitValue($totalValue,$GTTtableConfArr[4][1],$nNetIDName);
	$totalValue=setBitValue($totalValue,$GTTtableConfArr[5][1],$nDPC);
	$totalValue=setBitValue($totalValue,$GTTtableConfArr[6][1],$nSSN);
	$totalValue=setBitValue($totalValue,$GTTtableConfArr[7][1],$nRouterID);
	$totalValue=setBitValue($totalValue,$GTTtableConfArr[8][1],$nAddressID);
	$totalValue=setBitValue($totalValue,$GTTtableConfArr[9][1],$nRep_start);
	$totalValue=setBitValue($totalValue,$GTTtableConfArr[10][1],$nRep_end);
	$totalValue=setBitValue($totalValue,$GTTtableConfArr[11][1],$nOutNumPlan);
	$nRep_digit = omc_keep_length($nRep_digit,"F","20","0");
	$totalValue=setBitValue($totalValue,$GTTtableConfArr[12][1],$nRep_digit);
	$totalValue=setBitValue($totalValue,$GTTtableConfArr[13][1],$nTT);
if(0) echo "<br>totalValue=$nTT<br>";
	
	if($DEBUG) echo "<br><br>sysId=$sysId";
	if($DEBUG) echo "<br>objIdStr=$objIdStr";
	if($DEBUG) echo "<br>instanceNo=$instanceNo";
	if(0) echo "<br>totalValue=$totalValue<br>";

	$objIdStr='2.2';
	$objWhereStr =getLevelWhere($objIdStr);
	$totalValue = strtoupper($totalValue);
	$updSql = "UPDATE $paramTable SET initValue = '$totalValue'   
					WHERE $objWhereStr AND instanceNo='$instanceNo'";
	mysqli_query($pubConn,$updSql);
	echo mysqli_error($pubConn);
	
	{//set gtt attribution from 2.4
		$selSql = "select initValue from $paramTable where level_1='2' and level_2='4' and instanceNo='$instanceNo'";
		$Result = mysqli_query($pubConn,$selSql);
		$Row = mysqli_fetch_array($Result);
		$setValue = $Row[initValue];
		$tmpEleType = strtoupper(omc_keep_length(dechex($appType),'0',2));
		$tmpGrpNo=strtoupper(omc_keep_length(dechex($grpNo),'0',2));
		$tmpGtFlag = strtoupper(omc_keep_length(dechex($bitFlag),'0',2));
		$tmpEleName = omc_keep_length(toHex($eleName),"0",20,"0");
		
		$setValue = setBitValue($setValue,$offsetAppType,$tmpEleType);
		$setValue = setBitValue($setValue,$offsetGrpNo,$tmpGrpNo);
		$setValue = setBitValue($setValue,$offsetBitFlag,$tmpGtFlag);
		$setValue = setBitValue($setValue,'3.0-12.7',$tmpEleName);
		
		$updSql = "update $paramTable set initValue = '$setValue' where level_1='2' and level_2='4' and instanceNo='$instanceNo'";
		mysqli_query($pubConn,$updSql);
		echo mysqli_error($pubConn);
	}//end set gtt attribution form 2.4
						
	
	if(0) 
	{
		echo "<br>bitFlag:$bitFlag, grpNo:$grpNo";
		echo "<br>save:$save";
		echo "<BR>updSql=$updSql";
		exit;
	}
	//HPLMN VPLMN 设置判断
	if($DEBUG) echo "save=$save<br>";
	if($save == 1)
	{
		$hlr_sysId = "330_99_99";
		
		$hlr_sysIdArr	= explode('_',$hlr_sysId);
		$hlr_sysTypeNo	= $hlr_sysIdArr[0];
		$hlr_sysNo		= $hlr_sysIdArr[1];
		$hlr_subSysNo	= $hlr_sysIdArr[2];
		
		$hlr_oidstr = '2.1.12';
		$hlr_objWhereStr= '';	
		$hlr_objWhereStr =getLevelWhere($hlr_oidstr);
		
		$hlr_objDb		= 'OBJ_'.$hlr_sysTypeNo;
		$hlr_paramTable = 'param_'.$hlr_sysNo;

		$defSql = " SELECT initValue, instanceNo FROM $hlr_paramTable WHERE $hlr_objWhereStr AND instanceNo='$instanceNo'";
		if($DEBUG) echo "defSql=$defSql<BR>"; 
		$defRes = @mysqli_query($pubConn,$defSql);
		$row = @mysqli_fetch_array($defRes);
		
		
		$nHead = "$nCC"."$nNDC";
		$nHeadlen = strlen($nHead);
		$DigHead = substr($nStartDigit,0,$nHeadlen); 
		if($DigHead !=$nHead)
		{
			echo "<script language='javascript'>";  
			echo "window.alert(\"CC or NDC ERROR!\");";	
			echo "history.go(-1)";
			echo "</script>";						
			exit();
		}
		
		$stratSN	= substr($nStartDigit,$nHeadlen,12); 
		$nCC 	= omc_keep_length($nCC,"E","4","0");
		$nNDC = omc_keep_length($nNDC,"E","6","0");
		$stratSN =str_replace('F','E',$stratSN);
		
		if($DEBUG) echo "CC = $nCC<br>";
		if($DEBUG) echo "NDC = $nNDC<br>";
		if($DEBUG) echo " stratSN = $stratSN<br>";
		$row[initValue]=setBitValue($row[initValue],'00.0-01.7',$nCC);
		$row[initValue]=setBitValue($row[initValue],'02.0-04.7',$nNDC);
		$row[initValue]=setBitValue($row[initValue],'05.0-10.7',$stratSN);
		$row[initValue]=setBitValue($row[initValue],'11.0-16.7',$stratSN);

		$upSql = "UPDATE $hlr_paramTable SET initValue = '$row[initValue]' 
	            WHERE $hlr_objWhereStr AND instanceNo='$instanceNo'";
	  if($DEBUG) echo "upSql=$upSql<BR>"; 
		$upRes = @mysqli_query($pubConn,$upSql);
		echo mysqli_error($pubConn);
	}
	else if($save ==2) 
	{
		$hlr_sysId = "330_99_99";
		
		$hlr_sysIdArr	= explode('_',$hlr_sysId);
		$hlr_sysTypeNo	= $hlr_sysIdArr[0];
		$hlr_sysNo		= $hlr_sysIdArr[1];
		$hlr_subSysNo	= $hlr_sysIdArr[2];
		
		$hlr_oidstr = '2.1.12';
		$hlr_objWhereStr= '';	
		$hlr_objWhereStr =getLevelWhere($hlr_oidstr);
		
		$hlr_objDb		= 'OBJ_'.$hlr_sysTypeNo;
		$hlr_paramTable = 'param_'.$hlr_sysNo;

		$defSql = " SELECT initValue FROM paramConf WHERE $hlr_objWhereStr";
		$defRes = @mysqli_query($pubConn,$defSql);
		$row = @mysqli_fetch_array($defRes);

		$delSql = "UPDATE $hlr_paramTable SET initValue = '$row[initValue]' 
	            WHERE $hlr_objWhereStr AND instanceNo='$instanceNo'";
		$delRes = @mysqli_query($pubConn,$delSql);
		echo mysqli_error($pubConn);		
	}	

	if($DEBUG)
	{
		echo "DEBUG<br>";
	}
	else
	{	
		echo "<script LANGUAGE=\"JavaScript\">";
		echo " location='$backurl';";  
		echo "</script>";
		exit();
	}
}

//==========================================================
//输出并显示数据
//==========================================================
if($DEBUG) echo "<BR>";
?>
<br>
<body topmargin="0" leftmargin="12">
<form method="POST" name="selectform" action="<?php echo "$PHP_SELF?"; ?>">

<?php 

{
	echo "<table border=\"0\" width=\"100%\">";
	echo "<tr>";
	echo "<td width=\"50%\">";
	//echo "$strConfiguration > $strNetwork > Element >  GTT";
	echo "Configuration > <a href=\"../overview/overview.php\">Network</a> > ";
	echo "<a href=\"$backurl\">$strGttObjects</a> > ";
	echo "<a href=\"#\">GTT</a>";
	echo "</td>";
	echo "<td width=\"50%\" align=\"right\" title=\"Help\">";
	showHelp($helpId);
	echo "</td>";
	echo "</tr>";
	echo "</table>";
	echo "<br>";
	
	echo "<table width=\"100%\">";
	echo "<tr><td width=\"70%\">";
	echo "<b>&nbsp;&nbsp;</b>";
	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;&nbsp;";
	echo "<input type=\"reset\" name=\"Reset\" value=\"Reset\" class=\"button\" style=\"left: 1; top: 2; width: 60; height: 25; position: relative\">";
	echo "</td>";
	echo "<td width=\"10%\" align=\"right\">";
	
	echo "<a href=\"$backurl\"><img align=absBottom border=0 src=\"../../images/left.gif\" width=\"14\" height=\"14\">$strBack</a>";
	
	echo "<input type=\"hidden\" name=\"linkset\" value=\"$linkset\">";
	echo "<input type=\"hidden\" name=\"backurl\" value=\"$backurl\">";
	echo "<input type=\"hidden\" name=\"trunkgp\" value=\"$trunkgp\">";
	echo "<input type=\"hidden\" name=\"webname\" value=\"$webname\">";
	echo "</td></tr>";
	echo "</table>";
}
echo "<table border=\"1\" width=\"100%\" cellpadding=\"1\" cellspacing=\"0\" bordercolor=\"#666666\" bordercolordark=\"#FFFFFF\">";	

$objIdStr='2.2';
$objWhereStr =getLevelWhere($objIdStr);

if($instanceNo == 'new')
{
	/************get default value**************/
	$defSql = " SELECT initValue FROM paramConf WHERE $objWhereStr ";
	$defRes = @mysqli_query($pubConn,$defSql);
	$defRow = @mysqli_fetch_array($defRes);
	$defaultValue = $defRow[initValue];
	$value	=$defaultValue;	
}
else
{
	$getSql="SELECT initValue
			FROM $paramTable 
			WHERE $objWhereStr AND instanceNo='$instanceNo'
			";
	if($DEBUG) echo "<BR>getSql=$getSql";
	$result	=mysqli_query($pubConn,$getSql);
	echo mysqli_error($pubConn);
	$rows	=mysqli_fetch_array($result);
	echo mysqli_error($pubConn);
	$value=$rows[0];
}
if($DEBUG) echo "value=$value<BR>";

if($instanceNo == 'new')
{
	$SsnValue = $SSN;
	$addressID = '7';
}
else
{
	$SsnValue = hexdec(getBitValue($value,$GTTtableConfArr[6][1]));
	$addressID	=getBitValue($value,$GTTtableConfArr[8][1]);
}

$startDigit	=getBitValue($value,$GTTtableConfArr[0][1]);
$startDigit	=showNumber($startDigit);
$endDigit	=getBitValue($value,$GTTtableConfArr[1][1]);
$endDigit	=showNumber($endDigit);

$numPlan	=getBitValue($value,$GTTtableConfArr[3][1]);
if($DEBUG) echo "<br>NetID=$NetID";
for($j=0;$j<sizeof($NetIdConfArr);$j++)
{
	if($NetID == $NetIdConfArr[$j][0])
	{
		$NetIDName = $NetIdConfArr[$j][1];
		break;
	}
}
$RouterID	=getBitValue($value,$GTTtableConfArr[7][1]);

if($DEBUG) echo "<br>NetID=$NetID";
for($j=0;$j<sizeof($addressIdConfArr);$j++)
{
	if($addressID == $addressIdConfArr[$j][0])
	{
		$addressIDName = $addressIdConfArr[$j][1];
		break;
	}
}
$Rep_start	=getBitValue($value,$GTTtableConfArr[9][1]);
$Rep_end	=getBitValue($value,$GTTtableConfArr[10][1]);
$outNumPlan	=getBitValue($value,$GTTtableConfArr[11][1]);
if($DEBUG) echo "<br>outNumPlan=$outNumPlan";

$Rep_digit	=getBitValue($value,$GTTtableConfArr[12][1]);
$Rep_digit	=showNumber($Rep_digit);

$TT	=hexdec(getBitValue($value,$GTTtableConfArr[13][1]));

 
$ni=hexdec($NetID);
if($instanceNo=='new')
{
	$numPlan = omc_keep_length(dechex($NP),'0','2');

	if($niTypeArr[$ni]==0)//ITU
	{
		$TT = 0;
	}
	else//ansi
	{
		if($NP==1||$NP==0)
			$TT = 14;
		else
			$TT = 9;
		$numPlan='00';
	}
}
if($instanceNo == 'new')
{
	$getInstanceSql="SELECT initValue,instanceNo FROM $paramTable
					WHERE  $objWhereStr "; 
	$result=mysqli_query($pubConn,$getInstanceSql);
	echo mysqli_error($pubConn);
	if($DEBUG) echo "<br>$getInstanceSql";
	$ins_no = 0;
	while($row=mysqli_fetch_array($result))
	{
		$flag = hexDec(getBitValue($row[initValue],'0.0-0.7'));	
		//echo "$flag";
		if ($flag == 0)
		{
			$instanceNo = $row[instanceNo];
			$ins_no++;
			break;
		}		
	}
	if($ins_no == 0)
	{
		echo "<script language='javascript'>";  
		echo "window.alert(\"There is no GTT to added!\");";	
		echo "location='$backurl';";  
		echo "</script>";
		exit();
	}
}
echo "<tr bgcolor=\"#E6E6E6\"><td width=\"50%\"><b>Parameters</b></td><td><b>Value</b></td></tr>";

echo "<tr>";
echo "<td>Network indicator</td>";
echo "<td><input type=\"text\" style=\"DISPLAY: none\"  name=\"nNetIDName\" value=\"$NetID\" class=\"text\">";
echo "$NetIDName";
echo "</td>";
echo "</tr>";
echo "<tr>";
echo "<td>Destination point code</td>";
echo "<td><input type=\"text\" style=\"DISPLAY: none\" name=\"nDPC\" value=\"$DPC\" class=\"text\">";
echo "$DPC</td>";
echo "</tr>";

if($niTypeArr[$ni]==0)//ITU
{
	$tmpTT = omc_keep_length(dechex($TT),'0',2);
	echo "<input type=\"hidden\" name=\"nTT\" value=\"$tmpTT\"";
	
	echo "<tr>";
	echo "<td>Numbering Plan</td>";
	echo "<td>";
	if($NP==1||$NP==0)
	{
		for($j=0;$j<sizeof($numPlanConfArr);$j++)
		{
			if($numPlan == $numPlanConfArr[$j][0])
			{
				$NPName = $numPlanConfArr[$j][1];
				break;
			}
		}
		echo "$NPName";
		echo "<input type=\"hidden\" name=\"nNumPlan\" value=\"$numPlan\"";
	}
	elseif($NP==6)
	{
		echo "<select name=\"nNumPlan\" style=width:\"195\">";
		for($j=2;$j<sizeof($numPlanConfArr);$j++){
			if($numPlan == $numPlanConfArr[$j][0]){
				echo "<option value=\"{$numPlanConfArr[$j][0]}\" selected>{$numPlanConfArr[$j][1]}";
			}else{
				echo "<option value=\"{$numPlanConfArr[$j][0]}\" >{$numPlanConfArr[$j][1]}";
			}	
		}
		echo "</select>";
	}
	echo "</td>";
	echo "</tr>";
}
else//ansi
{
	echo "<input type=\"hidden\" name=\"nNumPlan\" value=\"$numPlan\"";
	
	$tmpTT = omc_keep_length(dechex($TT),'0',2);
	
	echo "<tr>";
	echo "<td>TT</td>";
	echo "<td>";
	if($NP==6)
	{
		echo "$TT";
		echo "<input type=\"hidden\" name=\"nTT\" value=\"$tmpTT\"";
	}
	elseif($NP==1||$NP==0)
	{
		$ttArr = array(array(14,'14(MSISDN)'),array(10,'10(MSISDN Element)'));
		echo "<select name=\"nTT\" style=width:\"195\">";
		for($j=0;$j<sizeof($ttArr);$j++)
		{
			$ttHex = omc_keep_length(dechex($ttArr[$j][0]),'0',2);
			if($TT == $ttArr[$j][0])
			{
				echo "<option value=\"$ttHex\" selected>{$ttArr[$j][1]}";
			}
			else
			{
				echo "<option value=\"$ttHex\" >{$ttArr[$j][1]}";
			}	
		}
		echo "</select>";
	}
	echo "</td>";
	echo "</tr>";
	
}
//=========================change the ssn to selection formation======================
/*
echo "<tr>";
echo "<td>$SsnValue</td>";
echo "<td><input type=\"text\" size=\"4\" name=\"nSSN\" value=\"$SsnValue\" class=\"text\"></td>";
echo "</tr>";
*/
//=================
$ssn_label=array(0=>"UNKNOW(0)",6=>"HLR(6)",7=>"VLR(7)",8=>"MSC(8)",9=>"EIR(9)",10=>"AUC(10)",11=>"SMSC(11)",22=>"SRF(22)",32=>"NPLR(32)",146=>"SSF(146)",147=>"SCF-CAP(147)",149=>"SGSN(149)",153=>"SCF-MAP(153)",254=>"AIF(254)");
echo "<tr>";
echo "<td>SSN</td>";
echo "<td>";
	echo "<select name=\"nSSN\" class=\"text\">";
		foreach($ssn_label as $key => $value)
		{
			if($key==$SsnValue)
				echo "<option value=$key selected>$value</option>";
			else
				echo "<option value=$key>$value</option>";
		}
	echo "</select>";
echo "</td>";
echo "</td>";



//if($SSN == 7)
if($appType == 2)
{
	//取数据
	$hlr_sysId = "330_99_99";
	
	$hlr_sysIdArr	= explode('_',$hlr_sysId);
	$hlr_sysTypeNo	= $hlr_sysIdArr[0];
	$hlr_sysNo		= $hlr_sysIdArr[1];
	$hlr_subSysNo	= $hlr_sysIdArr[2];
	
	$hlr_oidstr = '2.1.12';
	$hlr_objWhereStr= '';	
	$hlr_objWhereStr =getLevelWhere($hlr_oidstr);
	
	$hlr_objDb		= 'OBJ_'.$hlr_sysTypeNo;
	$hlr_paramTable = 'param_'.$hlr_sysNo;
	
	$hlr_paramSql = " SELECT initValue,readValue,instanceNo FROM $hlr_paramTable  
				WHERE $hlr_objWhereStr AND instanceNo = '$instanceNo'
				";
	$hlr_Result = mysqli_query($pubConn,$hlr_paramSql);
	$hlr_Row = mysqli_fetch_array($hlr_Result);
	
	$CC			= getBitValue($hlr_Row[initValue],'00.0-01.7');
	$CC			= str_replace('E','',$CC);
	$NDC		= getBitValue($hlr_Row[initValue],'02.0-04.7');
	$NDC		= str_replace('E','',$NDC);
	$Start_SN	= getBitValue($hlr_Row[initValue],'05.0-10.7');
	$Start_SN	= str_replace('E','',$Start_SN);
	
	$fullNum = "$CC"."$NDC"."$Start_SN";
	if(0) echo "cc:$CC"."ndc:$NDC"."start:$Start_SN<br>"."Hlr-fullNum=$fullNum<br>";
	if(0) echo "startDigit=$startDigit<br>";
	
	//显示
	echo "<tr>";
	echo "<td>Location</td>";
	echo "<td>";
	if($fullNum != $startDigit || $startDigit==0)
	{
		echo "<input type=\"radio\" name=\"save\" value=\"2\" checked onclick=\"javascript:hideIt('KB4Child','0');\">HPLMN&nbsp;";
		echo "<input type=\"radio\" name=\"save\" value=\"1\" onclick=\"javascript:hideIt('KB4Child','1');\">VPLMN&nbsp;";
		$cc_ndc_Show = 'none';
	}
	else
	{
		echo "<input type=\"radio\" name=\"save\" value=\"2\" onclick=\"javascript:hideIt('KB4Child','0');\">HPLMN&nbsp;";
		echo "<input type=\"radio\" name=\"save\" value=\"1\" onclick=\"javascript:hideIt('KB4Child','1');\" checked>VPLMN&nbsp;";
		$cc_ndc_Show = '';
	}
	echo "</td></tr>";
	
	echo "<tr id=KB4Child style=\"DISPLAY: $cc_ndc_Show\">";
	echo "<td>CC+NDC</td>";
	echo "<td>";
	if($fullNum != $startDigit)
	{
		echo "<input type=\"text\" size = \"4\" maxlength=\"4\" value=\"\" class=\"text\" name=\"nCC\" onchange = checkInput(this,10,0)>&nbsp;&nbsp;";
		echo "<input type=\"text\" size = \"4\" maxlength=\"6\" value=\"\" class=\"text\" name=\"nNDC\" onchange = checkInput(this,10,0)>";
	}
	else
	{	
		echo "<input type=\"text\" size = \"4\" maxlength=\"4\" value=\"$CC\" class=\"text\" name=\"nCC\" onchange = checkInput(this,10,0)>&nbsp;&nbsp;";
		echo "<input type=\"text\" size = \"4\" maxlength=\"6\" value=\"$NDC\" class=\"text\" name=\"nNDC\" onchange = checkInput(this,10,0)>";
	}	
	echo "</td></tr>";
}
//当startDigit与endDigit要设置为相同时只显示startDigit给用户设置
//if($SSN == 6||$SSN == 11)
if($appType == 1||$appType == 3||$appType == 5)
{
	if($bitFlag==1)
	{
		echo "<tr>";
		echo "<td>$strE164Number</td>";
		echo "<td><input type=\"text\" size = \"30\" maxlength=\"20\" value=\"$startDigit\" class=\"text\" name=\"nStartDigit\"  onchange = checkInput(this,10,0)></td>";
		echo "</tr>";						
	}
	else
	{
		echo "<tr>";
		echo "<td>Start GT number</td>";
		echo "<td><input type=\"text\" size = \"30\" maxlength=\"20\" value=\"$startDigit\" class=\"text\" name=\"nStartDigit\"  onchange = checkInput(this,10,0)></td>";
		echo "</tr>";
		echo "<tr>";
		echo "<td>End GT number</td>";
		echo "<td><input type=\"text\" size = \"30\" maxlength=\"20\" value=\"$endDigit\" class=\"text\" name=\"nEndDigit\"  onchange = checkInput(this,10,0)></td>";
		echo "</tr>";
	}
}
else
{
	echo "<tr>";
	echo "<td>GT number (CC+NDC+SN)</td>";
	echo "<td><input type=\"text\" size = \"30\" maxlength=\"20\" value=\"$startDigit\" class=\"text\" name=\"nStartDigit\"  onchange = checkInput(this,10,0)></td>";
	echo "<input type=\"hidden\" name=\"old_num\" value=\"$startDigit\">";
	echo "</tr>";
}


echo "<tr>";
echo "<td>Route indicator</td>";
echo "<td>";
echo "<select name=\"nRouterID\" style=width:\"195\">";
	if($RouterID==0)
	{
		echo "<option value=\"00\" selected>Route by GT";
		echo "<option value=\"01\">Route by DPC and SSN";
	}elseif($RouterID==1)
	{
		echo "<option value=\"00\">Route by GT";
		echo "<option value=\"01\" selected>Route by DPC and SSN";
	}
	else
	{
		echo "<option value=\"00\" selected>Route by GT";
		echo "<option value=\"01\">Route by DPC and SSN";
	}
echo "</select>";
echo "</tr>";
echo "<tr>";
echo "<td>Address indicator</td>";
echo "<td>";
echo "<select name=\"nAddressID\" style=width:\"195\">";
			if($addressID==0){
				echo "<option value=\"00\" selected>{$addressIdConfArr[0][1]}";
				echo "<option value=\"03\">{$addressIdConfArr[3][1]}";
				echo "<option value=\"06\">{$addressIdConfArr[6][1]}";
				echo "<option value=\"07\">{$addressIdConfArr[7][1]}";
			}elseif($addressID==3){
				echo "<option value=\"00\">{$addressIdConfArr[0][1]}";
				echo "<option value=\"03\" selected>{$addressIdConfArr[3][1]}";
				echo "<option value=\"06\">{$addressIdConfArr[6][1]}";
				echo "<option value=\"07\">{$addressIdConfArr[7][1]}";
			}elseif($addressID==6){
				echo "<option value=\"00\">{$addressIdConfArr[0][1]}";
				echo "<option value=\"03\">{$addressIdConfArr[3][1]}";
				echo "<option value=\"06\" selected>{$addressIdConfArr[6][1]}";
				echo "<option value=\"07\">{$addressIdConfArr[7][1]}";
			}else{
				echo "<option value=\"00\">{$addressIdConfArr[0][1]}";
				echo "<option value=\"03\">{$addressIdConfArr[3][1]}";
				echo "<option value=\"06\">{$addressIdConfArr[6][1]}";
				echo "<option value=\"07\" selected>{$addressIdConfArr[7][1]}";
			}

echo "</select>";
echo "</td>";
echo "</tr>";

echo "<tr>";
echo "<td>Replaced start digit</td>";
echo "<td><input type=\"text\" size = \"30\" maxlength=2 value=\"$Rep_start\" class=\"text\" name=\"nRep_start\"  onchange = checkInput(this,10,0)></td>";
echo "</tr>";
echo "<tr>";
echo "<td>Replaced end digit</td>";
echo "<td><input type=\"text\" size = \"30\" maxlength=2 value=\"$Rep_end\" class=\"text\" name=\"nRep_end\"  onchange = checkInput(this,10,0)></td>";
echo "</tr>";
echo "<tr>";
echo "<td>Outgoing number plan</td>";
echo "<td><select name=\"nOutNumPlan\" style=width:\"195\">";
	for($j=0;$j<sizeof($numPlanConfArr);$j++){
		if($outNumPlan == $numPlanConfArr[$j][0]){
			echo "<option value=\"{$numPlanConfArr[$j][0]}\" selected>{$numPlanConfArr[$j][1]}";
		}else{
			echo "<option value=\"{$numPlanConfArr[$j][0]}\" >{$numPlanConfArr[$j][1]}";
		}
	}
echo "</select>";
echo "</td>";
echo "</tr>";
echo "<tr>";
echo "<td>Replacing digits</td>";
echo "<td><input type=\"text\" size = \"30\" name=\"nRep_digit\"  value=\"$Rep_digit\" maxlength=\"20\" class=\"text\"  onchange = checkInput(this,10,0)></td>";
echo "</tr>";

echo "</table>";
echo "<br>";

echo "\n <input type=\"hidden\" name=\"appType\" value=\"$appType\">";
echo "\n <input type=\"hidden\" name=\"NP\" value=\"$NP\">";
echo "\n <input type=\"hidden\" name=\"SSN\" value=\"$SSN\">";
echo "\n <input type=\"hidden\" name=\"grpNo\" value=\"$grpNo\">";
echo "\n <input type=\"hidden\" name=\"bitFlag\" value=\"$bitFlag\">";
echo "\n <input type=\"hidden\" name=\"eleName\" value=\"$eleName\">";

echo "\n <input type=\"hidden\" name=\"instanceNo\" value=\"$instanceNo\">";

?>

<script LANGUAGE="JavaScript"> 
function hideIt(term, flag)
{
	whichEl = document.getElementById(term);
	if(flag==1)
		whichEl.style.display = "";
	if(flag==0)
		whichEl.style.display = "none";
}
function checkInput(term,flag,maxValue){
	term.value = term.value.toUpperCase();
    
    if (flag == 16)
    {
    	var checkOK = "0123456789ABCDEF";
    	var showmsg ="Parameter must be a hexadecimal value";
    }
    else 
    {
    	var checkOK = "0123456789";
    	var showmsg ="Parameter must be a decimal value";
    }

    var checkStr = term.value;
    var allValid = true;
    for (i = 0;  i < checkStr.length;  i++){
		ch = checkStr.charAt(i);
		for (j = 0;  j < checkOK.length;  j++){
			if (ch == checkOK.charAt(j))
				break;
		}
		if (j == checkOK.length){
			allValid = false;
			break;
		}
	}
	
	if (!allValid){  
		alert(showmsg+"!");
		term.focus();
		term.value = 0;
		return (false);
	}
	if (maxValue != 0)
	{
		if (checkStr > maxValue)
		{
			showmsg = "Parameter must less then "+ maxValue;
			alert(showmsg+"!");
			term.value = 0;
			term.focus();
			return (false);
		}
	}
}
</script>
