<?php
/*********************************************************      
 程序说明：         
    功能说明：E1参数配置
    调用关系：调用: header.inc     
              被调用:   
    变量说明：
    返回值：无
	作者：Lilong
	Date: 2004-8-30
      
修改注释：      
NO.1      
Name:
Date:
Description:
*********************************************************/  
require("../../inc/header.inc");
$DEBUG = 0;

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

$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";

$wAnd = " AND level_1 = 2 AND level_2 = 2 AND level_3 = 7 "; 

/************get default value**************/
$defSql = " SELECT initValue FROM paramConf WHERE keyId > 0 ".$wAnd;
$defRes = @mysqli_query($pubConn,$defSql);
$defRow = @mysqli_fetch_array($defRes);
$defaultValue = $defRow[initValue];
/*
$enableFlagArr=array(
	array('num' => '0',  'remark' => 'N', 'color' => '#FF0000'),
	array('num' => '1',  'remark' => 'Y', 'color' => '#0000FF')
);
*/
$emFlagArr = array(
		array('num' => '0', 'remark' => 'Disable'),
		array('num' => '1', 'remark' => 'By Cell'),
		array('num' => '2', 'remark' => 'By LAC'),
		array('num' => '3', 'remark' => 'By MSC')
);

$regionalZoneFlagArr = array(
		array('num' => '0', 'remark' => 'Disable'),
		array('num' => '1', 'remark' => 'Enable'),
);


if($set || $add)
{	
	$field_0= omc_keep_length($prefixNum,E,16,0);
	if($DEBUG)echo "<br>field_0=$field_0";
	/*
	if($add){
		$emFlag = 1;
	}
	*/
	
	if($DEBUG)echo "<br>emFlag=$emFlag";

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

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

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

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

	$field_4 = omc_keep_length($localEmNum,E,16,0);	
	if($DEBUG)	echo "<br>field_4=$field_4";

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

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

	$initValue = strtoupper($field_0.$field_1.$field_2.$field_3.$field_4.$field_5.$field_6);

	if($DEBUG)	echo "<br>initValue=$initValue";

	$uSql = " UPDATE $tb_2 set initValue = '$initValue' 
			WHERE subSysNo = '99' AND instanceNo = '$tNum' AND level_1 = 2 AND level_2 = 2 AND level_3 = 7 "; 
	//if($DEBUG)	
		echo "<br>uSql=$uSql";
	$uRes_1 = @mysqli_query($pubConn,$uSql);
	echo mysqli_error($pubConn);
	//exit();
	echo "<script LANGUAGE=\"JavaScript\">";
	echo "window.opener.location.href='./emergencyConf.php?scroll_x=$scroll_x&scroll_y=$scroll_y';";		
	echo "\n window.close();";
	echo "\n </script>";
}

/************select value to see************/
if($oType)
	$andSql = " SELECT instanceNo,initValue,editValue,readValue 
			FROM $tb_2 
			WHERE subSysNo = '99'".$wAnd."ORDER BY instanceNo";
else
	$andSql = " SELECT instanceNo,initValue,editValue,readValue 
			FROM $tb_2 
			WHERE subSysNo = '99' AND instanceNo = '$tNum' ".$wAnd; 
if($DEBUG)echo "<br>andSql=$andSql<br>db=$db_1";
$andRes = @mysqli_query($pubConn,$andSql);
$andRow = @mysqli_fetch_array($andRes);
echo mysqli_error($pubConn);

do{
	$instanceNo = $andRow[instanceNo];
	$initValue = $andRow[initValue];
	//echo "<br>initValue=$initValue";
	
	if($initValue == $defaultValue){
		$andShow[$instanceNo] = 0;
	}else{
		$andShow[$instanceNo] = 1;
	}

	$emFlag = hexdec(substr($initValue,0,2));
	if($DEBUG)	echo "emFlag=$emFlag<br>";
		
	$lac = hexdec(substr($initValue,2,4));
	if($DEBUG)echo "lac=$lac<br>";
		
	$ci = hexdec(substr($initValue,6,4));
	if($DEBUG)echo "ci=$ci<br>";

	$dialNum = hexdec(substr($initValue,10,2));
	if($DEBUG)echo "dialNum={$dialNum}<br>";

	$localEmNumArr	= explode("E",substr($initValue,12,16));
	$localEmNum		= $localEmNumArr[0];
	if($DEBUG)	echo "localEmNum=$localEmNum<br><br>";

	$regionalZoneFlag = hexdec(substr($initValue,28,2));
	if($DEBUG)echo "regionalZoneFlag={$regionalZoneFlag}<br>";

	$zoneCode = hexdec(substr($initValue,30,4));
	if($DEBUG)echo "zoneCode={$zoneCode}<br>";

}while($andRow = @mysqli_fetch_array($andRes));

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

if($oType){
	$emFlagSql = " SELECT instanceNo,initValue,editValue,readValue 
			FROM $tb_2 
			WHERE subSysNo = '99' AND level_1 = 2 AND level_2 = 2 AND  level_3 = 5 "." ORDER BY instanceNo "; 
	if($DEBUG)	echo "<br>emFlagSql=$emFlagSql";
	$emFlagRes = @mysqli_query($pubConn,$emFlagSql);
	$emFlagRow = @mysqli_fetch_array($emFlagRes);
	echo mysqli_error($pubConn);

	$emFlag = hexdec(substr($initValue,0,2));
	if($DEBUG) echo "enableFlag=$enableFlag<br>";

	echo "<tr>";
	echo "<td colspan=\"4\"><b>Add Cell parameter</b></td>";
	echo "</tr>";
	/*
	echo "<tr>";
	echo "<td width=\"60\" valign=middle><nobr>Cell Parameter no.</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(!$emFlagArr[$i][0])
			echo "<option value=\"$i\">$i</option>";
	}
	echo "</select>";
	echo "</td>";
	echo "</tr>";
	*/

	echo "<tr>";
	echo "<td width=\"60\" valign=middle><nobr>Cell Parameter no.</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<1024;$i++)	{
		if($andShow[$i] == 0)
			echo "<option value=\"$i\">$i</option>";
	}
	echo "</select>";
	echo "</td>";
	echo "</tr>";
}else{
	echo "<tr>";
	echo "<td colspan=\"4\"><b>Cell parameter $tNum</b></td>";
	echo "</tr>";
}
$DEBUG = 0;

echo "<tr>";
echo "<td width=\"60\" valign=middle><nobr>Flag</nobr></td>";
echo "<td colspan=\"2\">";
echo "<select style=\"font-family: Verdana; font-size: 8pt\" size=\"1\" name=\"emFlag\" id=\"emFlag\">";
for($i=0;$i<sizeof($emFlagArr);$i++)
{
	if($emFlag == $i)
		echo "<option value=\"$i\" selected>{$emFlagArr[$i][remark]}</option>";
	else
		echo "<option value=\"$i\">{$emFlagArr[$i][remark]}</option>";
}
echo "</select>";
echo "</td>";
echo "</tr>";

/*
echo "<tr>";
echo "<td width=\"60\" valign=middle><nobr>Emergency Flag</nobr></td>";
if($emFlag){
	echo "<td width=\"30\" colspan=\"2\"><nobr><input type=\"radio\" value=\"1\" name=\"emFlag\" checked>Yes";
	echo "<input type=\"radio\" name=\"emFlag\" value=\"0\">No&nbsp;</nobr></td>";
}else{
	echo "<td width=\"30\" colspan=\"2\"><nobr><input type=\"radio\" value=\"1\" name=\"emFlag\">Yes";
	echo "<input type=\"radio\" name=\"emFlag\" value=\"0\" checked>No&nbsp;</nobr></td>";
}
echo "</tr>";
*/

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

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

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

echo "<tr>";
echo "<td width=\"60\" valign=middle><nobr>Local emergency number</nobr></td>";
echo "<td colspan=\"2\"><input type=\"text\" name=\"localEmNum\" size=\"16\" value=\"$localEmNum\" maxLength=\"16\"></td>";
echo "</tr>";

echo "<tr>";
echo "<td width=\"60\" valign=middle><nobr>Regional Zone Flag</nobr></td>";
echo "<td colspan=\"2\">";
echo "<select style=\"font-family: Verdana; font-size: 8pt\" size=\"1\" name=\"regionalZoneFlag\" id=\"regionalZoneFlag\">";
for($i=0;$i<sizeof($regionalZoneFlagArr);$i++)
{
	if($regionalZoneFlag == $i)
		echo "<option value=\"$i\" selected>{$regionalZoneFlagArr[$i][remark]}</option>";
	else
		echo "<option value=\"$i\">{$regionalZoneFlagArr[$i][remark]}</option>";
}
echo "</select>";
echo "</td>";
echo "</tr>";

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

echo "</table>";
//echo "<br><u><b>Remark:</b></u>";
echo "<br>";
if($oType){
	echo "<input type=\"submit\" name=\"add\" value = \"Add\">"; 
}else{
	echo "<input type=\"submit\" name=\"set\" value = \"Set\">"; 
	echo "<input type=\"hidden\" name=\"tNum\" value =\"$tNum\">";
}
echo "<input type=\"reset\" name=\"Reset\" value =\"Reset\">";
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>
</body>
</html>