<?php
require("../sub_inc/commfunc.php");
$DEBUG = 0;
if($DEBUG) echo "<br>正在调试中！！";
?>

<body topmargin="0" leftmargin="12">

<?php

$helpID = "1.1.1";

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

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

$sqltable = 'OBJ_225.param_99';
$sqltable_hlr = 'OBJ_330.param_99';
$pubdb = 'OMC_PUB';

$NetworkCodeArr=array(
//	array('oid',	'inputName',	'Maxlength','showName',							'loc in HPLMN'),
	array('2.3.0',	'CC'	,		'4',		'Country code(CC)',					'00.0-01.7'),
	array('2.4.0',	'NDC'	,		'6',		'National destination code(NDC)', 	'02.0-04.7'), 
	array('2.1.0',	'MCC'	,		'4',		'Mobile country code(MCC)'),
	array('2.2.0',	'MNC'	,		'4',		'Mobile network code(MNC)'), 
	array('2.5.0',	'IPrefix'	,	'4',		'International prefix'),
	array('2.6.0',	'NPrefix'	,	'4',		'National prefix')	
);

if($_SERVER['REQUEST_METHOD'] == "POST")
{
	for($i=0;$i < sizeof($NetworkCodeArr);$i++)
	{
		$levelArr=explode('.',$NetworkCodeArr[$i][0]);
		for($j=0;$j<sizeof($levelArr);$j++)
		{
			$levelNo=$j+1;
			${"level_$levelNo"}=$levelArr[$j];
		}
		
		$sqltable = 'OBJ_225.param_99';
		$tmpValue = ${$i};
		if($DEBUG) echo "tmpValue = $tmpValue<br>";
		if($tmpValue == 0 && ($i == 2 || $i == 3))
			$initValue = omc_keep_length($tmpValue,'0',$NetworkCodeArr[$i][2],'0');				
		else
			$initValue = omc_keep_length($tmpValue,'E',$NetworkCodeArr[$i][2],'0');
			
		//write cc, ndc to HLR-HPLMN
		if($i < 2)
		{
			$objWhereStr = getLevelWhere('2.1.11');
			$getsql = "select initValue from $sqltable_hlr where $objWhereStr";
			$result = mysqli_query($pubConn,$getsql);
			$hplmn_init = mysqli_fetch_array($result);
			$hplmn_init = $hplmn_init[0];
			if($DEBUG) echo "hplmn_init = $hplmn_init<br>";
			if($DEBUG) echo "NetworkCodeArr[$i][4] = {$NetworkCodeArr[$i][4]}<br>";
			$hplmn_init = setBitValue($hplmn_init,$NetworkCodeArr[$i][4],$initValue);
			
			$setsql = "update $sqltable_hlr set initValue = '$hplmn_init' where $objWhereStr";
			mysqli_query($pubConn,$setsql);
			echo mysqli_error($pubConn);
			if($DEBUG) echo "$setsql<br>";
		}
		
		$setsql = "update $sqltable set initValue = '$initValue' 
			where level_1 = '$level_1' and level_2 = '$level_2' and level_3 = '$level_3'";
		
		mysqli_query($pubConn,$setsql);
		echo mysqli_error($pubConn);
		if($DEBUG) echo "$setsql<br>";
	}
	
	if(!$DEBUG)
	{
		echo "<script LANGUAGE=\"JavaScript\">";
		echo "\n window.location.href=\"./msc.php\";";
		echo "\n </script>";
	}	
}	

//==========================================================
//取数据库数据
//========================================================== 
for ($i = 0;$i < sizeof($NetworkCodeArr);$i++)
{
	
	$sqltable = 'OBJ_225.param_99';
		
	$levelArr=explode('.',$NetworkCodeArr[$i][0]);
	for($j=0;$j<sizeof($levelArr);$j++)
	{
		$levelNo=$j+1;
		${"level_$levelNo"}=$levelArr[$j];
		if($DEBUG) echo "<BR>levelArr[$j]={$levelArr[$j]}";
	}
	$getsql = "SELECT initValue FROM $sqltable
	where level_1='$level_1' and level_2 = '$level_2' ";
	if($DEBUG) echo "<br>getsql = $getsql";
	$result = @mysqli_query($pubConn,$getsql);
	$Net_row = @mysqli_fetch_array($result);
	
	${$NetworkCodeArr[$i][1]} = str_replace('E','',$Net_row[0]);
	echo mysqli_error($pubConn);
};
//==========================================================
//输出并显示数据
//==========================================================
echo "<form method=\"POST\" name=\"Set\" action=\"$PHP_SELF\">";

echo "<table border=\"0\" width=\"100%\">";
echo "<tr>";
echo "<td width=\"50%\">";
echo "$strConfiguration > <a href=\"../overview/overview.php\">Network</a> > <a href=\"$backurl\">MSC</a> > <a href=\"#\">Network</a>";
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>Network edit:&nbsp;&nbsp;</b>";
echo "</td>";
echo "<td width=\"20%\">";
echo "<input type=\"submit\" value=$strSave class=\"button\" name=\"Set\" style=\"left: 1; top: 2; width: 60; height: 25; position: relative\">";	
echo "&nbsp;&nbsp;&nbsp;&nbsp;";
echo "<input type=\"reset\" value=$strReset  class=\"button\" name=\"Reset\" style=\"left: 1; top: 2; width: 60; height: 25; position: relative\">";
echo "</td>";
echo "<td width=\"10%\" align=\"right\"><a href=\"./msc.php\"><img align=absBottom border=0 src=\"../../images/left.gif\" width=\"14\" height=\"14\">$strBack</a>";
echo "</td></tr>";
echo "</table>";
?>
<table  width=100%   border="1"  cellpadding="1" cellspacing="0"  bordercolor="#666666" bordercolordark="#FFFFFF" bgcolor="#FFFFFF"> 
<?php

echo "<tr>";
echo "<td width=50% bgcolor=\"#E6E6E6\"><b>Parameters</b></td>";
echo "<td width=50% bgcolor=\"#E6E6E6\"><b>Value</b></td>";
echo "</tr>";
for($i=0;$i < sizeof($NetworkCodeArr);$i++)
{
	if($i==$clrFlag)
		echo "<tr bgcolor=\"$flagColor\">";
	else
		echo "<tr>";
	echo "<td>{$NetworkCodeArr[$i][3]}</td>";
		
	echo "<td align=\"left\"><INPUT TYPE=\"text\" NAME=\"$i\" size=\"10\" maxlength=\"{$NetworkCodeArr[$i][2]}\" 
			value=\"${$NetworkCodeArr[$i][1]}\" class=\"text\" onchange = checkInput(this,10,0)></td>"  ;  

	echo "</tr>";
}

echo "</table>";

echo "</form>";

?>
