<?php
require("../sub_inc/commfunc.php");
$DEBUG = 0;
if($DEBUG) echo "<br>ÕýÔÚµ÷ÊÔÖÐ£¡£¡";
?>
	
<script LANGUAGE="JavaScript">  
function selectAll(thisCheckBox,formName,flag,bgnNo,endNo)
{
	var p;
	var tmpCheckBox;
	if(thisCheckBox.checked == true)
	{
		for(p=bgnNo; p < endNo; p++)
		{
			tmpCheckBox=eval("document."+formName+"."+flag+p);
			tmpCheckBox.checked = true;
			tmpCheckBox.value=1;
		}
	}
	else
	{
		for(p=bgnNo; p < endNo; p++)
		{
			tmpCheckBox=eval("document."+formName+"."+flag+p);
			tmpCheckBox.checked = false;
			tmpCheckBox.value=0;
		}
	}
}
</script>

<body topmargin="0" leftmargin="12">
<?php
$pubdb = 'OMC_PUB';
$sqltable = 'OBJ_330.param_99';      
$listPageUrl = "hlr.php?advanced=$advanced";                       


if($DEBUG) echo "instanceNo = $instanceNo<br>";
$csrr_array = array(
	array('Not allowed','0'),
	array('Allowed','1')
	);

$getsql = "select initValue from $sqltable
where level_1 = '2' and level_2 = '1' and level_3 = '13' and instanceNo ='$instanceNo' ";  
$result = @mysqli_query($pubConn,$getsql);
$row = @mysqli_fetch_array($result);
echo mysqli_error($pubConn);

if($_SERVER['REQUEST_METHOD'] == "POST")
{
	if($DEBUG) echo "csrr = $csrr<br>";
	$initValue = omc_keep_length($initValue,'0','64','0');
	$k = 255;
	for($i=0; $i < 32; $i++)
	{
		for($j=7; $j >= 0; $j--)
		{
			if(isset(${'no'.$k})) ${'no'.$k} = 1;
			else ${'no'.$k} = 0;
			//echo "$k=${$k}<br>";
			$loc = $i.'.'.$j;
			$initValue = setBitValue($initValue,$loc,${'no'.$k});
			$k--;
		}
	}
	if($DEBUG) echo "instanceNo = $instanceNo<br>";
	if($DEBUG) echo "initValue = $initValue<br>";
	$setsql = "update $sqltable set initValue = '$initValue' 
	where level_1 = '2' and level_2 = '1' and level_3 = '13' and instanceNo = '$instanceNo'";
	mysqli_query($pubConn,$setsql);
	echo mysqli_error($pubConn);
	
	echo "<script LANGUAGE=\"JavaScript\">";
	//echo "\n window.opener.location.href=\"$listPageUrl\";";
	if(!$DEBUG){
		echo "\n window.location.href=\"$listPageUrl\";";
		//echo "\n window.close();";
	} 
	echo "\n </script>";
}


$k=255;
for($i = 0;$i < 32; $i++)
{
	for($j=7; $j>=0; $j--)
	{
		$loc = $i.'.'.$j;
		$csrr[$k] = getBitValue($row[0],$loc);
		$k--;
	}
}

echo "<form method=\"POST\" name=\"Set\" action=\"$PHP_SELF\">";
echo "<table border=\"0\" width=\"100%\">";
echo "<tr>";
echo "<td width=\"80%\">";
//echo "Configuration > Network > Element > MSC > HLR CSRR";
echo "$strConfiguration > <a href=\"../overview/overview.php\">Network</a> > <a href=\"./hlr.php\">HLR</a> > <a href=\"#\">CSRR</a>";
echo "<td width=\"20%\" 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>CSRR Type $instanceNo list:&nbsp;&nbsp;</b>";
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%\"><p align=\"right\"><a href=\"./hlr.php?advanced=$advanced&scroll_y=$sub_page_top\"><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="2" cellspacing="0" bordercolor="#666666" bordercolordark="#FFFFFF" bgcolor="#FFFFFF"> 


<?php

echo "<tr bgcolor = \"#E6E6E6\">";
for($i=0; $i< 4; $i++)
{
	$start = $i*64;
	$end = $start + 64;
	echo "<td width=\"15% bgcolor=\"#E6E6E6\"><b>VPLMN roaming</b></td>";
	echo "<td width=\"10% bgcolor=\"#E6E6E6\"><b>Allowed</b>";
	$checkedStr = 'checked';
	for($j=$start; $j< $end; $j++)
	{
		if(1 != $csrr[$j])
		{
			$checkedStr = '';
			break;
		}
	}
	echo "<input type=\"checkbox\" name=\"seleceAll\" title=\"Select all\"  value=\"1\" onClick=\"JavaScript:selectAll(this,'Set','no',$start,$end);\" $checkedStr>";
	echo "</td>";
}
echo "</tr>";
for($i=0; $i< 64; $i++)
{
	echo "<tr>";
	for($j=0; $j< 4; $j++)
	{
		$no = $j * 64 + $i;
		echo "<td bgcolor = \"#E6E6E6\">VPLMN $no</td>";
		echo "<td>";
		if (1 == $csrr[$no])
			echo "<input type=\"checkbox\" name=\"no$no\" value=\"$csrr[$no]\" onClick=\"javascript:selCheckBox(this)\" checked>";
		else
			echo "<input type=\"checkbox\" name=\"no$no\" value=\"$csrr[$no]\" onClick=\"javascript:selCheckBox(this)\">";
		echo "$no</td>";
	}
	echo "</tr>";
}

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

echo "</table>";

?>

<?php
echo "</form>";
?>
