<?php
/*********************************************************      
 程序说明：         
    功能说明：E1参数配置

    调用关系：调用: header.inc     
              被调用:   
 
    变量说明：

     返回值：无

 作者：   
      
修改注释：      
NO.1      
姓名：            
时间：      
修改说明：      
*********************************************************/  
require("../../inc/header.inc");
$DEBUG = 0;
?>
<script LANGUAGE="JavaScript">           
function openSet(){
	URL="./e1Edit.php";
	var msgWindow = open(URL, 'newWin', 'toolbar=no,directories=no,menubar=no,scrollbars=yes,resizable=yes,status=yes,width=400,height=350');
	msgWindow.focus();
}
</script>
<?
$sysTypeNo_0 = "111";

if($thisOmcType==10){
	$sysTypeNo_1 = "251";
}else{
	$sysTypeNo_1 = "322";
}

$db_0 = "OBJ_".$sysTypeNo_0;
$db_1 = "OBJ_".$sysTypeNo_1;

$tb_0 = "param_0";
$tb_1 = "param_1";
$tb_2 = "param_99";

$temTb = ${tb_.$sNum};
$subSysNo = floor($pNum/8);
if($DEBUG)echo "<br>subSysNo=$subSysNo";
$portNo = $pNum%8;
if($DEBUG)echo "<br>portNo=$portNo";

$tgTypeArr=array(
			array('num' => '0',  'remark' => 'PSTN',		'color' => '#FF0000'),
			array('num' => '1',  'remark' => 'HPLMN',	'color' => '#0000FF'),
			array('num' => '2',  'remark' => 'VPLMN',	'color' => '#0000FF'),
			array('num' => '3',  'remark' => 'subscriber',	'color' => '#0000FF'),
			array('num' => '4',  'remark' => '--',			'color' => '#0000FF')
);
$netTypeArr=array(
			array('num' => '0',  'remark' => 'International',		'color' => '#FF0000'),
			array('num' => '1',  'remark' => 'International spare',	'color' => '#0000FF'),
			array('num' => '2',  'remark' => 'National ',			'color' => '#0000FF'),
			array('num' => '3',  'remark' => 'National spare',		'color' => '#0000FF'),
			array('num' => '4',  'remark' => '--',					'color' => '#0000FF')
);
$cirTypeArr=array(
			array('num' => '0',  'remark' => 'clockwise',		'color' => '#FF0000'),
			array('num' => '1',  'remark' => 'anti-clockwise',	'color' => '#0000FF'),
			array('num' => '2',  'remark' => 'odd',				'color' => '#0000FF'),
			array('num' => '3',  'remark' => 'even',			'color' => '#0000FF'),
			array('num' => '4',  'remark' => '--',				'color' => '#0000FF')
);


$pageCellTypeArr=array(
		array('num' => '0',  'remark' => '--'),
		array('num' => '1',  'remark' => '--'),
		array('num' => '2',  'remark' => '--'),
		array('num' => '3',  'remark' => '--'),
		array('num' => '4',  'remark' => '--'),
		array('num' => '5',  'remark' => 'by LAC'),
		array('num' => '6',  'remark' => 'in All Cell')
);

//Attributes of TG
$oidTg = "2.2.6"; 
$pTg = explode(".",$oidTg);
$i = 0;
$wTg = '';
while(isset($pTg[$i]))
{
	$lNum = $i+1;
	if($DEBUG) echo "<br>pTg[$i]=$pTg[$i]";
	$wTg = $wTg." AND level_$lNum = $pTg[$i] ";
	$i++;
}

/************get default value**************/
$defSql = " SELECT initValue FROM paramConf WHERE keyId > 0 ".$wTg;
$defRes = @mysqli_query($pubConn,$defSql);
$defRow = @mysqli_fetch_array($defRes);
$defaultValue = $defRow[initValue];
//echo "<br>defaultValue=$defaultValue";

if($set || $add)
{	
	$field_0 = omc_keep_length(DecHex(BinDec($cellFlag)),0,2);
	if($DEBUG)echo "<br>field_0=$field_0";
	
	$field_1 = omc_keep_length(DecHex($tgNum),0,2);
	if($DEBUG)echo "<br>field_1=$field_1";

	if($add){
		$cellFlag = 1;
	}

	$field_2 = omc_keep_length(DecHex($lacNum),0,4);
	if($DEBUG)echo "<br>field_2=$field_2";

	$field_3 = omc_keep_length(DecHex($cellType),0,2);
	if($DEBUG)echo "<br>field_3=$field_3";

	$initValue = $field_0.$field_1.$field_2.$field_3;
	$initValue = strtoupper($initValue);
	if($DEBUG)echo "<br>initValue=$initValue";

	$uTgSql = " UPDATE $tb_2 set initValue = '$initValue' WHERE subSysNo = '99' AND instanceNo = '$tNum' ".$wTg; 
	if($DEBUG)echo "<br>uTgSql=$uTgSql";
	$uTgRes = @mysqli_query($pubConn,$uTgSql);
	echo mysqli_error($pubConn);

	echo "<script LANGUAGE=\"JavaScript\">";
	echo "window.opener.location.href='./cellConf.php?scroll_x=$scroll_x&scroll_y=$scroll_y';";		
	echo "\n window.close();";
	echo "\n </script>";
}

/************select value to see************/
//Attributes of TG
$tgSql = " SELECT instanceNo,initValue,editValue,readValue FROM $tb_2 WHERE subSysNo = '99' AND instanceNo = '$tNum' ".$wTg." ORDER BY instanceNo "; 
if($DEBUG) echo "<br>tgSql=$tgSql";
$tgRes = @mysqli_query($pubConn,$tgSql);
$tgRow = @mysqli_fetch_array($tgRes);
echo mysqli_error($pubConn);
$wDef = " AND (";
do
{
	$instanceNo = $tgRow[instanceNo];
	$initValue = $tgRow[initValue];
	if($DEBUG) echo "<br>initValue=$initValue";

	if($initValue == $defaultValue){
		$tgShow[$instanceNo] = 0;
	}else{
		$tgShow[$instanceNo] = 1;
		
		$wDef = $wDef." instanceNo = $instanceNo OR ";
	}
	
	//echo "<br>tgShow[$instanceNo]=$tgShow[$instanceNo]";

	$hex_0 = substr($initValue,0,2);
	if($DEBUG)echo "<br>hex_0=$hex_0";
	$bin_0 = omc_keep_length(DecBin(HexDec($hex_0)),0,8);
	if($DEBUG)echo "<br>bin_0=$bin_0";

	$cellFlag = $cellArr[$instanceNo][0] = substr($bin_0,7,1);
	if($DEBUG)echo "<br>cellFlag=$cellFlag";


	$tgNum = $cellArr[$instanceNo][1] = HexDec(substr($initValue,2,2));
	if($DEBUG)echo "<br>tgNum=$tgNum";

	$hLac = substr($initValue,4,2);
	$lLac = substr($initValue,6,2);
	$lacNum = $hLac.$lLac;
	$lacNum = $cellArr[$instanceNo][2] = HexDec($lacNum);
	if($DEBUG)echo "<br>lacNum=$lacNum";
	
	$cellType = substr($initValue,8,2);
	$cellType = $cellArr[$instanceNo][3] = HexDec($cellType);
	if($DEBUG)echo "<br>cellType=$cellType";
}while($tgRow = @mysqli_fetch_array($tgRes));



echo "<form method=\"POST\" name=\"confForm\" action=\"$PHP_SELF\">";
echo "<table border=\"0\" cellpadding=\"2\" cellspacing=\"2\" width=\"100%\">";

if($oType){
	$tgFlagSql = " SELECT instanceNo,initValue,editValue,readValue FROM $tb_2 WHERE subSysNo = '99' ".$wTg." ORDER BY instanceNo "; 
	if($DEBUG)echo "<br>tgFlagSql=$tgFlagSql";
	$tgFlagRes = @mysqli_query($pubConn,$tgFlagSql);
	$tgFlagRow = @mysqli_fetch_array($tgFlagRes);
	echo mysqli_error($pubConn);
	do
	{
		$instanceNo = $tgFlagRow[instanceNo];
		$initValue = $tgFlagRow[initValue];
		if($DEBUG)echo "<br>initValue=$initValue";
		
		//echo "<br>$initValue == $defaultValue";
		if($initValue == $defaultValue){
			$tgShow[$instanceNo] = 0;
		}else{
			$tgShow[$instanceNo] = 1;
			$wDef = $wDef." instanceNo = $instanceNo OR ";
		}

		if($DEBUG)echo "<br>tgShow[$instanceNo]=$tgShow[$instanceNo]";
		$hex_7 = substr($initValue,14,2);
		if($DEBUG)echo "<br>hex_7=$hex_7";
		$bin_7 = omc_keep_length(DecBin(HexDec($hex_7)),0,8);
		if($DEBUG)echo "<br>bin_7=$bin_7";

		$cellFlag = $cellArr[$instanceNo][0] = substr($bin_7,7,1);
		if($DEBUG)echo "<br>cellFlag=$cellFlag";
	}while($tgFlagRow = @mysqli_fetch_array($tgFlagRes));
	
	
	echo "<tr>";
	echo "<td colspan=\"4\"><b>Add trunk group</b></td>";
	echo "</tr>";

	
	echo "<tr>";
	echo "<td width=\"60\" valign=middle><nobr>Cell</nobr></td>";
	echo "<td colspan=\"2\">";
	echo "<select style=\"font-family: Verdana; font-size: 8pt\" size=\"1\" name=\"tNum\" id=\"tNum\">";
	for($i=0;$i<256;$i++)
	{
		if(!$tgShow[$i])
			echo "<option value=\"$i\">$i</option>";
	}
	echo "</select>";
	echo "</td>";
	echo "</tr>";


}else{
	echo "<tr>";
	echo "<td colspan=\"4\"><b>Location $tNum</b></td>";
	echo "</tr>";
}
echo "<tr>";
echo "<td width=\"60\" valign=middle><nobr>Enable</nobr></td>";
if($cellFlag){
	echo "<td width=\"30\" colspan=\"2\"><nobr><input type=\"radio\" value=\"1\" name=\"cellFlag\" checked>Yes";
	echo "<input type=\"radio\" name=\"cellFlag\" value=\"0\">No&nbsp;</nobr></td>";
}else{
	echo "<td width=\"30\" colspan=\"2\"><nobr><input type=\"radio\" value=\"1\" name=\"cellFlag\">Yes";
	echo "<input type=\"radio\" name=\"cellFlag\" value=\"0\" checked>No&nbsp;</nobr></td>";
}
echo "</tr>";

echo "<tr>";
echo "<td width=\"60\" valign=middle><nobr>Trunk group</nobr></td>";
echo "<td colspan=\"2\"><input type=\"text\" name=\"tgNum\" size=\"3\" value=\"$tgNum\" maxLength=\"3\"></td>";
echo "</tr>";

echo "<tr>";
echo "<td width=\"60\" valign=middle><nobr>LAC</nobr></td>";
echo "<td colspan=\"2\"><input type=\"text\" name=\"lacNum\" size=\"5\" value=\"$lacNum\" maxLength=\"5\"></td>";
echo "</tr>";

echo "<tr>";
echo "<td width=\"60\" valign=middle><nobr>Page Cell ID Type</nobr></td>";
echo "<td colspan=\"2\">";
echo "<select style=\"font-family: Verdana; font-size: 8pt\" size=\"1\" name=\"cellType\" id=\"cellType\">";
if($cellType == 5){
	echo "<option value=\"5\" selected>{$pageCellTypeArr[5][remark]}</option>";
	echo "<option value=\"6\">{$pageCellTypeArr[6][remark]}</option>";
}else{
	echo "<option value=\"5\">{$pageCellTypeArr[5][remark]}</option>";
	echo "<option value=\"6\" selected>{$pageCellTypeArr[6][remark]}</option>";

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

echo "</table>";
//echo "<br><u><b>Remark:</b></u>";
echo "<br>";
if($oType){
	echo "<input type=\"submit\" name=\"add\" value = \"Add\" class=\"button\">"; 
	echo "&nbsp;&nbsp;";
}else{
	echo "<input type=\"submit\" name=\"set\" value = \"Set\" class=\"button\">"; 
	echo "&nbsp;&nbsp;";
	echo "<input type=\"hidden\" name=\"tNum\" value =\"$tNum\">";
}
echo "<input type=\"reset\" name=\"Reset\" value =\"Reset\" class=\"button\">";
echo "<input type=\"hidden\" name=\"scroll_x\" value =\"$scroll_x\">";
echo "<input type=\"hidden\" name=\"scroll_y\" value =\"$scroll_y\">";

echo "</form>";
?>
<B>Remarks:</B><br><br>
Manage the MS location by correlating TG, LAC and cell ID. Totally 256 locations
  

</body>
</html>