<?php
/*********************************************************      
 程序说明：         
    功能说明：设置七号信令中的 GTT
              
    调用关系：调用: header.inc    
              被调用:        
 
    变量说明：

    作者：
      
修改注释：      
NO.1      
姓名： Cui Ticun         
时间：2004-4-21
修改说明：Support OMC7.0,从advanced移到configuration中，修改
		 和添加了上方的操作按钮
*********************************************************/
require("../../inc/header.inc");
$DEBUG = 0;

if($DEBUG) echo "<br>正在调试中！！";
//==========================================================
//变量定义
//==========================================================
$pubDb			= 'OMC_PUB';
$numberPerPage	= 100;		//每页纪录数
$paramTable		='OBJ_223.param_99';
$db_1='OBJ_223';
$sysId		='223_99_99';
//$instanceNo	='0';
$valueName	='initValue';
$totalLen	= 45;

$nProcFailStat	= 0;
$nWaitProcStat	= 1;
$nInProcStat	= 2;
$nProcDoneStat	= 3;

$objIdStr='2.2';
$listPageUrl = "gttRemoteList.php?setObjIdStr=$objIdStr&setInstanceNo=$instanceNo";

/************get default value**************/
$defSql = " SELECT initValue FROM paramConf WHERE keyId > 0 AND level_1 = 2 AND level_2 = 2 AND paramType=2 ";
$defRes = @mysqli_query($pubConn,$defSql);
$defRow = @mysqli_fetch_array($defRes);
do
{
	$defaultValue = $defRow[initValue];
	//echo "<br>defaultValue[$leve_3]=$defaultValue[$leve_3]";
}while($defRow = @mysqli_fetch_array($defRes));

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

//获取命令执行状态
function getSysCommStat($commId)
{
	$DEBUG = 0;
	$pubDb = 'OMC_PUB';
	$commTable = 'parameterComm';
	
	$getSql = "SELECT commState FROM $commTable	WHERE commId ='$commId'";
	$result=mysqli_query($pubConn,$getSql);
	echo mysqli_error($pubConn);
	if($result){
		$row=mysqli_fetch_array($result);
		$commState=$row[commState];
		return($commState);
	}else{
		return(-1);
	}
}


$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('TT',						'02.0-02.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('Replacing number plan',	'32.0-32.7'),
	array('Replacing digits',		'33.0-42.7')
);

$NetIdConfArr=array(
	array('0','international'),
	array('1','international spare'),
	array('2','national'),
	array('3','national spare')
);

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

$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')
);

function showNumber($number){
	$newNumber =str_replace('F','',$number);
	/*
	if($newNumber == ''){
		$newNumber='--';
	}
	*/
	return($newNumber);
}
//==========================================================
//数据处理
//==========================================================
//保存改动
if($_SERVER['REQUEST_METHOD'] == "POST"){
	if($DEBUG){
		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");
	$nTt = omc_keep_length($nTt,"0","2","1");
	$nDPC = omc_keep_length($nDPC,"0","6","1");
	$nRep_digit = omc_keep_length($nRep_digit,"F","20","0");
	$nRep_start = omc_keep_length($nRep_start,"0","2","1");
	$nRep_end = omc_keep_length($nRep_end,"0","2","1");
	$nSSN = omc_keep_length($nSSN,"0","2","1");


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

	$levelArr=explode('.',$objIdStr);
		for($j=0;$j<sizeof($levelArr);$j++){
			$levelNo=$j+1;
			${"level_$levelNo"}=$levelArr[$j];
			if($DEBUG) echo "<BR>levelArr[$j]={$levelArr[$j]}";
	}

	$updSql = "UPDATE $paramTable SET initValue = '$totalValue'   
					WHERE level_1='$level_1' AND level_2='$level_2'  AND instanceNo='$instanceNo'
					";
	if($DEBUG) echo "<BR>updSql=$updSql";
	mysqli_query($pubConn,$updSql);
	echo mysqli_error($pubConn);
	//setSysParamValue($sysId,$objIdStr,$instanceNo,$totalValue);
	echo "<script LANGUAGE=\"JavaScript\">";
	echo "\n window.opener.location.href=\"$listPageUrl\";";
	if(!$DEBUG){
		echo "\n window.close();";
	} 
	echo "\n </script>";
	exit();
}


//==========================================================
//输出并显示数据
//==========================================================
if($DEBUG) echo "<BR>";
?>
<br>
<body topmargin="0" leftmargin="12">
<form method="POST" name="selectform" action="<?php echo "$PHP_SELF"; ?>">
<table border="1" width="100%" cellpadding="1" cellspacing="0" bordercolor="#666666" bordercolordark="#FFFFFF">
<?php 
echo "<tr bgcolor=\"#E6E6E6\"><td>Name</td><td>Value</td></tr>";

if($instanceNo == 'new'){
	$value	=$defaultValue;	
}else{
	$levelArr=explode('.',$objIdStr);
		for($j=0;$j<sizeof($levelArr);$j++){
			$levelNo=$j+1;
			${"level_$levelNo"}=$levelArr[$j];
			if($DEBUG) echo "<BR>levelArr[$j]={$levelArr[$j]}";
		}
		$getSql="SELECT $valueName
				FROM $paramTable 
				WHERE level_1='$level_1' AND level_2='$level_2' 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];
	//$value	=getSysParamValue($sysId,$objIdStr,$instanceNo,$valueName);
}
if($DEBUG) echo "<BR>value=$value";	

if($instanceNo == 'new'){
	$levelArr=explode('.',$objIdStr);
	for($j=0;$j<sizeof($levelArr);$j++){
		$levelNo=$j+1;
		${"level_$levelNo"}=$levelArr[$j];
		if($DEBUG) echo "<BR>levelArr[$j]={$levelArr[$j]}";
	}

	$getInstanceSql="SELECT instanceNo FROM $paramTable
					WHERE  level_1='$level_1' AND level_2='$level_2' AND  $valueName ='$defaultValue'"; 
	$result=mysqli_query($pubConn,$getInstanceSql);
	echo mysqli_error($pubConn);
	echo "<tr><td>No.</td><td>";
	if($DEBUG) echo "<br>$getInstanceSql";
	echo "<select name=\"instanceNo\" size=\"1\">";
	while($row=mysqli_fetch_array($result)){
		echo "<option value=$row[instanceNo]>$row[instanceNo]</option>";
	}
	echo"</select>";
	echo"</td></tr>";
}

$startDigit	=getBitValue($value,$GTTtableConfArr[0][1]);
//if($startDigit == 'FFFFFFFFFFFFFFFFFFFF') continue;
$startDigit	=showNumber($startDigit);
$endDigit	=getBitValue($value,$GTTtableConfArr[1][1]);
$endDigit	=showNumber($endDigit);
$enableFlag	=getBitValue($value,$GTTtableConfArr[2][1]);
/*
if($enableFlag > 0){
	$enableFlag ='Y';
}else{
	$enableFlag ='N';
}
*/

$numPlan	=getBitValue($value,$GTTtableConfArr[3][1]);
/*
for($j=0;$j<sizeof($numPlanConfArr);$j++){
	if($numPlan == $numPlanConfArr[$j][0]){
		$numPlanName = $numPlanConfArr[$j][1];
		break;
	}
}
*/

$tt		=getBitValue($value,$GTTtableConfArr[4][1]);
$NetID		=getBitValue($value,$GTTtableConfArr[5][1]);
if($DEBUG) echo "<br>NetID=$NetID";
for($j=0;$j<sizeof($NetIdConfArr);$j++){
	if($NetID == $NetIdConfArr[$j][0]){
		$NetIDName = $NetIdConfArr[$j][1];
		break;
	}
}
$DPC		=getBitValue($value,$GTTtableConfArr[6][1]);
$SSN		=getBitValue($value,$GTTtableConfArr[7][1]);
$RouterID	=getBitValue($value,$GTTtableConfArr[8][1]);
$addressID	=getBitValue($value,$GTTtableConfArr[9][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[10][1]);
$Rep_end	=getBitValue($value,$GTTtableConfArr[11][1]);
$outNumPlan	=getBitValue($value,$GTTtableConfArr[12][1]);
if($DEBUG) echo "<br>outNumPlan=$outNumPlan";
/*
for($j=0;$j<sizeof($numPlanConfArr);$j++){
	if($OutNumPlan == $numPlanConfArr[$j][0]){
		$OutNumPlanName = $numPlanConfArr[$j][1];
		break;
	}
}
*/
$Rep_digit	=getBitValue($value,$GTTtableConfArr[13][1]);
$Rep_digit	=showNumber($Rep_digit);

echo "<tr>";
echo "<td>Start GT number</td>";
echo "<td><input type=\"text\" maxlength=\"20\" value=\"$startDigit\" class=\"text\" name=\"nStartDigit\"></td>";
echo "</tr>";
echo "<tr>";
echo "<td>End GT number</td>";
echo "<td><input type=\"text\" maxlength=\"20\" value=\"$endDigit\" class=\"text\" name=\"nEndDigit\"></td>";
echo "</tr>";
echo "<tr>";
echo "<td>Enable</td>";
echo "<td>";
echo "<select name=\"nEnable\">";
	if($enableFlag==0){
		echo "<option value=\"00\" selected>N";	
		echo "<option value=\"01\">Y";
	}elseif($enableFlag>0){
		echo "<option value=\"00\">N";	
		echo "<option value=\"01\" selected>Y";
	}else{
		echo "<option value=\"00\">N";	
		echo "<option value=\"01\" selected>Y";
	}
echo "</select>";
echo "</td>";
echo "</tr>";
echo "<tr>";
echo "<td>Numbering Plan</td>";
echo "<td>";
echo "<select name=\"nNumPlan\">";
			for($j=0;$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>";

echo "<tr>";
echo "<td>TT(hex)</td>";
echo "<td><input type=\"text\" maxlength=\"2\" value=\"$tt\" class=\"text\" name=\"nTt\"></td>";
echo "</tr>";


echo "<tr>";
echo "<td>Network indicator</td>";
echo "<td>";
echo "<select name=\"nNetIDName\">";

			if($NetID==0){
				echo "<option value=\"00\" selected>$strInternationalNetwork";
				echo "<option value=\"01\">$strInternationalNetworkSpare";
				echo "<option value=\"02\">$strNationalNetwork";
				echo "<option value=\"03\">$strNationalNetworkSpare";
			}elseif($NetID==1){
				echo "<option value=\"00\">$strInternationalNetwork";
				echo "<option value=\"01\" selected>$strInternationalNetworkSpare";
				echo "<option value=\"02\">$strNationalNetwork";
				echo "<option value=\"03\">$strNationalNetworkSpare";
			}elseif($NetID==2){
				echo "<option value=\"00\">$strInternationalNetwork";
				echo "<option value=\"01\">$strInternationalNetworkSpare";
				echo "<option value=\"02\" selected>$strNationalNetwork";
				echo "<option value=\"03\">$strNationalNetworkSpare";
			}elseif($NetID==3){
				echo "<option value=\"00\">$strInternationalNetwork";
				echo "<option value=\"01\">$strInternationalNetworkSpare";
				echo "<option value=\"02\">$strNationalNetwork";
				echo "<option value=\"03\" selected>$strNationalNetworkSpare";
			}
			else{
				echo "<option value=\"00\" selected>$strInternationalNetwork";
				echo "<option value=\"01\">$strInternationalNetworkSpare";
				echo "<option value=\"02\">$strNationalNetwork";
				echo "<option value=\"03\">$strNationalNetworkSpare";
			}
echo "</select>";
echo "</td>";
echo "</tr>";
echo "<tr>";
echo "<td>Destination point code(hex)</td>";
echo "<td><input type=\"text\" maxlength=\"6\" value=\"$DPC\" class=\"text\" name=\"nDPC\"></td>";
echo "</tr>";
echo "<tr>";
echo "<td>SSN(hex)</td>";
echo "<td><input type=\"text\" maxlength=\"2\" value=\"$SSN\" class=\"text\" name=\"nSSN\"></td>";
echo "</tr>";
echo "<tr>";
echo "<td>Route indicator</td>";
echo "<td>";
echo "<select name=\"nRouterID\">";
			if($RouterID==0){
				echo "<option value=\"00\" selected>$RouteByGT";
				echo "<option value=\"01\">$RouteByDPCAndSSN";
			}elseif($RouterID==1){
				echo "<option value=\"00\">$RouteByGT";
				echo "<option value=\"01\" selected>$RouteByDPCAndSSN";
			}
			else{
				echo "<option value=\"00\" selected>$RouteByGT";
				echo "<option value=\"01\">$RouteByDPCAndSSN";
			}

echo "</select>";
echo "</tr>";
echo "<tr>";
echo "<td>Address indicator</td>";
echo "<td>";
echo "<select name=\"nAddressID\">";
			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]}";
			}
		/*	for($j=0;$j<sizeof($addressIdConfArr);$j++){
				if($addressID == $addressIdConfArr[$j][0]){
					echo "<option value=\"{$addressIdConfArr[$j][0]}\" selected>{$addressIdConfArr[$j][1]}";
				}else{
					echo "<option value=\"{$addressIdConfArr[$j][0]}\" >{$addressIdConfArr[$j][1]}";
				}
			}*/
echo "</select>";
echo "</td>";
echo "</tr>";
echo "<tr>";
echo "<td>Replaced start digit(hex)</td>";
echo "<td><input type=\"text\" maxlength=2 value=\"$Rep_start\" class=\"text\" name=\"nRep_start\"></td>";
echo "</tr>";
echo "<tr>";
echo "<td>Replaced end digit(hex)</td>";
echo "<td><input type=\"text\" maxlength=2 value=\"$Rep_end\" class=\"text\" name=\"nRep_end\"></td>";
echo "</tr>";
echo "<tr>";
echo "<td>Replacing number plan</td>";
echo "<td><select name=\"nOutNumPlan\">";
	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\" name=\"nRep_digit\"  value=\"$Rep_digit\" maxlength=\"20\" class=\"text\" ></td>";
echo "</tr>";

echo "</table>";
echo "<br>";
echo "\n <input type=\"hidden\" name=\"sysId\" value=\"$sysId\">";
echo "\n <input type=\"hidden\" name=\"objIdStr\" value=\"$objIdStr\">";
if($instanceNo != 'new'){
	echo "\n <input type=\"hidden\" name=\"instanceNo\" value=\"$instanceNo\">";
}
echo "\n <input type=\"submit\" name=\"set\" value=\"Set\">&nbsp;&nbsp;";
echo "\n <input type=\"reset\" name=\"reset\" value=\"Reset\">";

echo "</form>";
?>
<b>Remarks:</b><br>
<br>
<table border="1" width="100%" cellpadding="1" cellspacing="0" bordercolor="#666666" bordercolordark="#FFFFFF">
<tr bgcolor="#E6E6E6"><td>GTT setup</td><td>Explanation</td></tr>
<tr><td>Start GT number</td><td>
 Specify the beginning number of a group of consecutive numbers routed by GTT, for single-number GTT route, the start number is same as the end number
 </td></tr>
<tr><td>End GT number</td><td>Specify the end number of a group of consecutive number routed by GTT. If there are some inconsecutive numbers for a same destination, a different GTT record should be used. </td></tr>
<tr><td>Enable</td><td>Record enable or disable</td></tr>
<tr><td>Numbering plan</td><td>Numbering planning, include MSISDN (E.164), IMSI (E.212) and GT (E.214) </td></tr>
<tr><td>Network indicator</td><td> Network type, include international, international spare, national and national spare </td></tr>
<tr><td>Destination point code</td><td> Point code of the destination device </td></tr>
<tr><td>SSN</td><td> SSN of the destination device, 3=ISDN user part, 4=OMC, 5=MAP, 6=HLR, 7=VLR, 8=MSC, 9=EIR, 10=AUC, 11=SMSC, 254=A interface, 147=PPS </td></tr>
<tr><td>Route indicator</td><td> For IMSI and MSISDN, select "Route on SSN"
<tr><td>Address indicator</td><td>select the contribution of SCCP Address.</td></tr>
<br>For the record of the connected network, select "Route on GT"</td></tr>
<tr><td>Replaced start digit</td><td>Specify the beginning digit of a segment of digits to be replaced within a GT number, the replacement is for changing number and numbering plan </td></tr>
<tr><td>Replaced end digit</td><td> Specify the end digit of a segment of digits to be replaced within a GT number, the replacement is for changing number and numbering plan </td></tr>
<tr><td>Replacing digit</td><td> Replacing digits, the length of replacing digits and replaced digits may be different </td></tr>
<tr><td>Replacing number plan</td><td> Replacing number plan, include MSISDN, IMSI and GT </td></tr>
</table>
</body>
</html>