<?php
// require("../sub_inc/commfunc.php");
require("../sub_inc/operwebfunc.inc");

$DEBUG = 0;

if($DEBUG) echo "<br>正在调试中，给您的工作带来不便，请原谅！！：）";
?>
<script LANGUAGE="JavaScript">
	
function selectToDel(thisCheckBox)
{
	if(thisCheckBox.checked == true)
		thisCheckBox.value=1;
	else
		thisCheckBox.value=0;
}

function selectAllToDel(flag,thisCheckBox,bgnNo,endNo)
{
	var p;
	var tmpCheckBox;
	if(thisCheckBox.checked == true)
	{
		for(p=bgnNo; p < endNo; p++){
			tmpCheckBox=eval("document.update."+flag+"checkBox_"+p);
			tmpCheckBox.checked = true;
			tmpCheckBox.value=1;
		}
	}else{
		for(p=bgnNo; p < endNo; p++){
			tmpCheckBox=eval("document.update."+flag+"checkBox_"+p);
			tmpCheckBox.checked = false;
			tmpCheckBox.value=0;
		}
	}
}

function delSelected(flag,bgnNo,endNo)
{
	y = document.body.scrollTop;
	
	var haveSelected = 0;
	for(p=bgnNo; p < endNo; p++)
	{
		tmpCheckBox=eval("document.update."+flag+"checkBox_"+p);
		if(tmpCheckBox.value==1)
		{
			haveSelected = 1;
			break;
		}
	}
	if(haveSelected==0)
	{
		alert("Select elements, first!");
		return;
	}
	if(confirm('Do you want to delete the selected?') != true)
		return;
	else
	{
		var p;
		var delNoStr;
		var tmpCheckBox;
		var tmpDelNo;
		delNoStr='';
		for(p=bgnNo; p < endNo; p++)
		{
			tmpCheckBox=eval("document.update."+flag+"checkBox_"+p);
			tmpDelNo=eval("document.update."+flag+"deleteno_"+p);
			if(tmpCheckBox.value==1)
			{
				delNoStr += tmpDelNo.value + '.';
			}
		}
		window.location.href='<?php echo $PHP_SELF;?>?&delNoStr='+delNoStr+'&delflag='+flag+'&scroll_y='+y;
	}

}
function openErr()
{
	alert('There is no more prefix to set!');
	return;
}
function delFirm(flag,No,No1,thisCheck)
{
	var delValue,x,y;
	x = document.body.scrollLeft;
	y = document.body.scrollTop;
    
	if(confirm('Do you want to delete the selected?') != true)
	{
		if(thisCheck.checked == true){
			thisCheck.checked=false;
		}else{
			thisCheck.checked=true;
		}
	}
	else
		window.location.href='<?php echo $PHP_SELF;?>?&delValue='+No+'&delValue1='+No1+'&delflag='+flag;
}
function openSet(instanceNo,objIdStr,sysId,webname,setname,backurl)
{
	y = document.body.scrollTop;
	backurl = backurl+'?scroll_y='+y;
	backurl=escape(backurl);
	
	URL="./paramconf.php?instanceNo="+instanceNo+"&objIdStr="+objIdStr+"&sysId="+sysId+"&webname="+webname+"&setname="+setname+"&backurl="+backurl+"&sub_page_top="+y;	
	window.location.href=URL;
}
function openSetPrefix(trunkgp,instanceNo,objIdStr,sysId,webname,setname,backurl)
{
	y = document.body.scrollTop;
	backurl = backurl+'?scroll_y='+y;
	backurl=escape(backurl);
	//alert(backurl);
	URL="./paramconf.php?instanceNo="+instanceNo+"&trunkgp="+trunkgp+"&objIdStr="+objIdStr+"&sysId="+sysId+"&webname="+webname+"&setname="+setname+"&backurl="+backurl+"&sub_page_top="+y;	
	window.location.href=URL;
}
function linkTo(url, param, backurl)
{
	if(param=="resetDevice=1")
	{
		if(!(confirm("The MSC,SCCP and MTP3 will be reset now, are you sure?")))
			return;
	}
	y = document.body.scrollTop;
	if(backurl=='-1')
		URL = url + "?scroll_y=" + y + "&" + param;
	else
	{
		backurl = backurl+'?scroll_y='+y;
		backurl=escape(backurl);
		
		
		
		
		
		URL=url+"?backurl="+backurl+"&"+param;	
		if(param=='')
			URL += "scroll_y="+y;
		else 
			URL += "&scroll_y="+y;
			
		if(param=="clock")
			URL +="&clock=1";
		if(param=="signal")
			URL +="&signal=1"	
	}
	window.location.href=URL;
}
var statusmsg=""
function hidestatus()
{
	//window.status=statusmsg
	return true
}
</script>

<?php

$scroll_y = isset($scroll_y) ? $scroll_y : 0;
echo "<body topmargin=\"0\" onLoad=\"self.scrollBy(0,$scroll_y);\" leftmargin=\"12\">";

$backurl = "./msc.php";
$pubDb			= 'OMC_PUB';

$sqltable_sccp	="OBJ_223.param_99";

$net_paramTable		='OBJ_225.param_99';//xapp
$net_paramConf		='OBJ_225.paramConf';


$vlr_paramTable		='OBJ_325.param_99';//vlr
$vlr_paramConf		='OBJ_325.paramConf';

$msc_paramTable		='OBJ_322.param_99';
$msc_paramConf		='OBJ_322.paramConf';

$mtp3_sqlTable = 'OBJ_222.param_99';

$sqltable_spc = 'OBJ_222.param_99';

$sysStatTable='OMC_PUB.sysStat';
$sysinfo = 'OMC_PUB.sysInfo';
$sysTypeNo = '322';

$localPrefixTg = 251;
//000000004B0302FD0000000000000000
//000000000B0302FF0000000000000000
$setsql = "update $msc_paramTable set initValue = '000000004B0302FD0000000000000000'
			where level_1 = '2' and level_2 = '1' and level_3 = '4' and instanceNo ='$localPrefixTg'";
//$setsql = "update $msc_paramTable set initValue = '000000000B0302FF0000000000000000'
//			where level_1 = '2' and level_2 = '1' and level_3 = '4' and instanceNo ='$localPrefixTg'";
//echo "<br>setsql=$setsql";
mysqli_query($pubConn,$setsql);
echo mysqli_error($pubConn);	

$spcTree_array = array(
	array('INT',	'14-bit',	'2.3.1'),
	array('INT-S',	'14-bit',	'2.3.2'),
	array('NAT',	'14-bit',	'2.3.3'),
	array('NAT-S',	'14-bit',	'2.3.4'),
	array('INT',	'24-bit',	'2.3.5'),
	array('INT-S',	'24-bit',	'2.3.6'),
	array('NAT',	'24-bit',	'2.3.7'),
	array('NAT-S',	'24-bit',	'2.3.8'),
);					

$sysId_arr=array(
	array('oid'=>'2.1.8',		'sysid'=> '223_99_99',		'selectsysid'=>'-1'), 										
	array('oid'=>'2.1.146',		'sysid'=> '223_99_99',		'selectsysid'=>'-1'),
	array('oid'=>'2.1.254',		'sysid'=> '223_99_99',		'selectsysid'=>'-1'), 										
	array('oid'=>'2.2',			'sysid'=> '223_99_99',		'selectsysid'=>'-1'),
	
	array('oid'=>'2.1.0',		'sysid'=> '225_99_99',		'selectsysid'=>'-1'),
	array('oid'=>'2.2.0',		'sysid'=> '225_99_99',		'selectsysid'=>'-1'),
	array('oid'=>'2.3.0',		'sysid'=> '225_99_99',		'selectsysid'=>'-1'),
	array('oid'=>'2.4.0',		'sysid'=> '225_99_99',		'selectsysid'=>'-1'),
	array('oid'=>'2.5.0',		'sysid'=> '225_99_99',		'selectsysid'=>'-1'),
	array('oid'=>'2.6.0',		'sysid'=> '225_99_99',		'selectsysid'=>'-1'),
	array('oid'=>'2.8.0',		'sysid'=> '225_99_99',		'selectsysid'=>'-1'),
	
	array('oid'=>'2.1.13',		'sysid'=> '325_99_99',		'selectsysid'=>'-1'),

	array('oid'=>'2.1',			'sysid'=> '322_99_99',		'selectsysid'=>'-1'),
	array('oid'=>'2.2',		    'sysid'=> '322_99_99',		'selectsysid'=>'-1'),
	array('oid'=>'2.2',		    'sysid'=> '322_99_99',		'selectsysid'=>'-1'),
	array('oid'=>'2.3.1',		'sysid'=> '322_99_99',		'selectsysid'=>'-1'),
	array('oid'=>'2.3.7',		'sysid'=> '322_99_99',		'selectsysid'=>'-1'),
	array('oid'=>'2.4.1',		'sysid'=> '322_99_99',		'selectsysid'=>'-1'),
	array('oid'=>'2.4.2',		'sysid'=> '322_99_99',		'selectsysid'=>'-1'),
	array('oid'=>'2.4.3',		'sysid'=> '322_99_99',		'selectsysid'=>'-1'),
	array('oid'=>'2.6.3',		'sysid'=> '322_99_99',		'selectsysid'=>'-1'),
);

//when set mtp3's parameters, sccp'c parameter will be reset. so, should set mtp3's param at first.
$sysId_arr1=array(
	array('oid'=>'2.2',			'sysid'=> '222_99_99',		'selectsysid'=>'-1'),
	array('oid'=>'2.3',			'sysid'=> '222_99_99',		'selectsysid'=>'-1'),
	array('oid'=>'2.4.1',		'sysid'=> '222_99_99',		'selectsysid'=>'-1'),
	array('oid'=>'2.5.1',		'sysid'=> '222_99_99',		'selectsysid'=>'-1'),
	array('oid'=>'2.6.4',		'sysid'=> '222_99_99',		'selectsysid'=>'-1'),
	array('oid'=>'2.7.1',		'sysid'=> '222_99_99',		'selectsysid'=>'-1'),
);

$SaveArr=array(
	array('oidstr'=>'3.7',	'setvalue'=>'02'	,'sysid'=>'222_99_99'),//mtp3	
	array('oidstr'=>'3.2',	'setvalue'=>'02'	,'sysid'=>'223_99_99'),//sccp	
//	array('oidstr'=>'3.2',	'setvalue'=>'01'	,'sysid'=>'225_99_99'),//XAPP
	array('oidstr'=>'3.2',	'setvalue'=>'B5'	,'sysid'=>'322_99_99'),//MSC
);

	$getsql = "SELECT sysNo FROM $sysinfo where sysTypeNo = $sysTypeNo";
	if($DEBUG) echo "getsql = $getsql<br>";
	$Result = @mysqli_query($pubConn,$getsql);
	while($Rows = mysqli_fetch_array($Result))
	{
		$vlrSysId = "325_".$Rows[sysNo]."_0";
		$SaveArr[] = array('oidstr'=>'3.3',	'setvalue'=>'01'	,'sysid'=> $vlrSysId);
	}

$vlrConfArr = array(
	array('Start','0.0-7.7','2.1.13'),
	array('End','8.0-15.7','2.1.13')
	);

$localNodeConfArr=array(
	array('NetID',		'00.0-00.7'),
	array('MSISDN',		'01.0-10.7'),
	array('IP0',		'11.0-14.7'),
	array('IP1',		'15.0-18.7')
);

$NetworkCodeArr=array(
//	array('oid',	'inputName',	'Maxlength','showName'),
	array('2.3.0',	'CC'	,		'4',		'CC'),
	array('2.4.0',	'NDC'	,		'6',		'NDC'), 
	array('2.1.0',	'MCC'	,		'4',		'MCC'),
	array('2.2.0',	'MNC'	,		'4',		'MNC'), 
	array('2.5.0',	'IPrefix'	,	'4',		'Int prefix'),
	array('2.6.0',	'NPrefix'	,	'4',		'Nat prefix')
);


$CDR_status=array(
	//	  name				//order
	array('MO',				'12'),
	array('MT',				'11'),
	array('OutGateway',		'8'),
	array('InGateway',		'9'),
	array('Roaming',		'10'),
	array('Transit',		'7'),		
	array('Sorm',			'3'),
	array('MCT',			'4'),
	array('MO SMS',			'6'),
	array('MT SMS',			'5'),		
//	array('Redirection',	'0.3-0.3'),
//	array('Feature Request','0.2-0.2')		
);

$max_duration = array(
	array('Duration','0.0-0.7','2.3.7')
	);

$obj_array = array(
	array('SCCP','223_99_99','2.1','OBJ_223.param_99','WHERE level_1=\'2\' and level_2 = \'1\' '),
	array('XAPP','225_99_99','2','OBJ_225.param_99','WHERE level_1=\'2\' '),
	array('VLR','325_99_99','2.1.3','OBJ_325.param_99','WHERE level_1=\'2\' and level_2 = \'1\' and level_3 = \'3\' '),
	array('CCF','322_99_99','2','OBJ_322.param_99','WHERE level_1=\'2\' '),
	array('MTP3','222_99_99','2','OBJ_222.param_99','WHERE level_1=\'2\' '),
	array('8KE1_0','111_0_99','2','OBJ_111.param_0','WHERE level_1=\'2\' '),
	array('8KE1_1','111_1_99','2','OBJ_111.param_1','WHERE level_1=\'2\' '),
	array('AAS_0','311_0_0','2.5','OBJ_311.param_0','WHERE level_1=\'2\' and level_2 = \'5\' '),
	array('AAS_1','311_1_0','2.5','OBJ_311.param_1','WHERE level_1=\'2\' and level_2 = \'5\' ')
	);
			
//loading
if($load_flag == 1)
{
	echo "<br>Loading";
	
	GetParam($sysId_arr1,1);//1 means return to overview if getting parameters fails.
	GetParam($sysId_arr,1);//1 means return to overview if getting parameters fails.
			
	echo "<script LANGUAGE=\"JavaScript\">";
	if(!$DEBUG){
		echo "\n window.location.href=\"./msc.php\";";
	} 
	else exit();
	echo "\n </script>";
}

//get default value of local prefix(conv prefix)
$getsql = "select initValue from $net_paramConf where level_1 = '2' and level_2 = '8' and level_3 = '0'";  
$conv_pre_def = @mysqli_query($pubConn,$getsql);
$conv_pre_def = @mysqli_fetch_array($conv_pre_def);
$conv_pre_def = $conv_pre_def[0];
echo mysqli_error($pubConn);
if($DEBUG) 
	echo "conv_pre_def = $conv_pre_def<br>";

if(isset($doingOtherFlag))
{
	//=====set NITX name then set namc DCS ,name length======
	if($setNITZName==1)
	{
		//===to get the old value from database
		$database="OBJ_322";
		$sql="select initValue from param_99 where level_1=2 and level_2=2 and level_3=5 ";
		$result=@mysqli_query($pubConn,$sql);
		$rows=@mysqli_fetch_array($result);
		$oldValue=$rows[initValue];
		$tempV=substr($oldValue,4);
		$name_DCS="00";
		//======get the name length
		$tmp=substr($tempV,0,64);
		$count=0;
		for($i=0;$i<32;$i++)
		{
			$t=substr($tmp,$i*2,2);
			if($t!="00")
				$count++;
		}
		
		//$count=6;
		$name_length=hexdec($count)."";
		if(strlen($name_length)==1)
			$name_length="0".$name_length;
		
		$newValue=$name_DCS.$name_length.$tempV;
		$update_sql="update OBJ_322.param_99 set initValue = '$newValue' 
				where level_1 ='2' and level_2 ='2' and level_3='5' ";
		mysqli_query($pubConn,$update_sql);		
		echo mysqli_error($pubConn);	
		exit;
		
	}
	
	
	if($setMSC_spc==1){
		changeGTT($newValue,$netId,$oldValue,$netId);
		
		$setSPC = strtoupper(omc_keep_length(dechex($newValue),'0','6'));
		$setsql = "update $mtp3_sqlTable set initValue = '$setSPC'
					where level_1 = '2' and level_2 = '3' and (level_3-1)%4 = '$netId'";
		mysqli_query($pubConn,$setsql);
		echo mysqli_error($pubConn);	
		exit;		
	}
	if($setMsrnStart==1 || $setMsrnEnd==1||$setLocalCliType==1)
	{

		$getsql = "select initValue from $vlr_paramTable where level_1 = '2' and level_2 = '1' and level_3 = '13'";  
		$msrn_rst = @mysqli_query($pubConn,$getsql);
		echo mysqli_error($pubConn);
		if($DEBUG) echo "getsql = $getsql<br>";
		
		$msrn_row = @mysqli_fetch_array($msrn_rst);
		$msrn_start=getBitValue($msrn_row[0],'00.0-07.7');
		$msrn_start = str_replace('F','',$msrn_start);
		$msrn_end = getBitValue($msrn_row[0],'08.0-15.7');
		$msrn_end = str_replace('F','',$msrn_end);
		
		$getsql = "select initValue from $msc_paramTable where level_1 = '2' and level_2 = '1' and level_3 = '2' and instanceNo='249'";  
		$msrnPrefixAtt_rst = @mysqli_query($pubConn,$getsql);
		echo mysqli_error($pubConn);
		if($DEBUG) 
			echo "getsql = $getsql<br>";
		$msrnPrefixAtt_row = @mysqli_fetch_array($msrnPrefixAtt_rst);
		
		$msrnPrefixAtt=$msrnPrefixAtt_row[initValue];
		
		$local_cliType=getBitValue($msrnPrefixAtt,'17.0-17.7');
		$msrnPrefixAtt=setBitValue('4400EEEEEEEEEEEEEEEE890000EEEEEEEE030100','17.0-17.7',$local_cliType);
			
		//set some roaming prefixs automatically
		if($newValue!==$oldValue)
		{
			{//delete old msrn prefix
				$selSql = "select instanceNo,initValue from $msc_paramTable where level_1 = '2' and level_2 = '1' and level_3 = '2'";
				$Result = mysqli_query($pubConn,$selSql);
				while($Rows=mysqli_fetch_array($Result))
				{
					$flag = getBitValue($Rows[initValue],'10.7-10.7');
					$property = bindec(getBitValue($Rows[initValue],'10.2-10.3'));
					if($flag && $property==2)//msrn
					{
						delPrefix($Rows[instanceNo]);
					}
				}
			}//end delete
			if(strlen($msrn_end)== strlen($msrn_start) && strlen($msrn_start)>0)
			{
				$i=0; 
				while(substr($msrn_start,$i,1)==substr($msrn_end,$i,1))
				{
					$i++;
				}
				$start = substr($msrn_start,$i,1);
				$end = substr($msrn_end,$i,1);
				//echo "<br>start:$start, end:$end";
				
				if($start == 0 && $end==9)
				{
					$roamPreArr[0][prefix]=substr($msrn_start,0,$i);
					$roamPreArr[0][inst] = 249;
				}
				else
				{
					for($k=0,$j=$start; $j<= $end; $j++,$k++)
					{
						$roamPreArr[$k][prefix]=substr($msrn_start,0,$i) . $j;
						$roamPreArr[$k][inst] = 249 - $k;
					}
				}
				for($i=0; $i< sizeof($roamPreArr); $i++)
				{
					
					$roamingPrefix = omc_keep_length($roamPreArr[$i][prefix],'E','16','0');
					$setsql = "update $msc_paramTable set initValue = '$roamingPrefix' 
					where level_1 = '2' and level_2 = '1' and level_3 = '1' and instanceNo ='{$roamPreArr[$i][inst]}'";
					mysqli_query($pubConn,$setsql);
					echo mysqli_error($pubConn); 
					
					$setsql = "update $msc_paramTable set initValue = '$msrnPrefixAtt'
					where level_1 = '2' and level_2 = '1' and level_3 = '2' and instanceNo ='{$roamPreArr[$i][inst]}'";
					//echo "<br>setsql=$setsql";
					mysqli_query($pubConn,$setsql);
					echo mysqli_error($pubConn);	
					
					$setPrefixTG = omc_keep_length(dechex($localPrefixTg),'0','2');
					$setsql = "update $msc_paramTable set initValue = '$setPrefixTG'
					where level_1 = '2' and level_2 = '1' and level_3 = '3' and instanceNo ='{$roamPreArr[$i][inst]}'";
					mysqli_query($pubConn,$setsql);
					echo mysqli_error($pubConn);	
				}
			}
			//else{
			//	$msg="MSRN Range is error";
			//	alertMsgAndGoLast($msg);	
			//}
		}//end set a roaming prefix
		exit;
	}
	{//set system ip
		for($i=0; $i < 2; $i++)
		{
			$getsql = "SELECT ip FROM $sysinfo where sysTypeNo = $sysTypeNo and sysNo = '$i'";
			if($DEBUG) echo "getsql = $getsql<br>";
			$ip_init = @mysqli_query($pubConn,$getsql);
			$ip_init = mysqli_fetch_array($ip_init);
			$ip_init = $ip_init[0];
			$ip_array = explode('.',$ip_init);
			
			for($j = 0;$j < sizeof($ip_array);$j++)
			{
				$ip = $ip_array[$j];
				$mss_ip[$i] .= omc_keep_length(dechex($ip),'0','2');
			}	
		}
		$mss_ip[0] = strtoupper(omc_keep_length($mss_ip[0],'0','8'));
		$mss_ip[1] = strtoupper(omc_keep_length($mss_ip[1],'0','8'));
		if($DEBUG)
		{
			echo "<br>mss0_ip = $mss_ip[0]<br>";	
			echo "mss1_ip = $mss_ip[1]<br>";	
		}
		
		$sysId = "223_99_99";
		if($setMscGtt==1)//msc
		{
			$oidStr = "2.1.8";
			setParamValue($mss_ip[0],$sysId,$oidStr,3);
			setParamValue($mss_ip[1],$sysId,$oidStr,4);
		}
		if($setSsfGtt==1)//ssf
		{
			$oidStr = "2.1.146";
			setParamValue($mss_ip[0],$sysId,$oidStr,3);	
			setParamValue($mss_ip[1],$sysId,$oidStr,4);
		}
		if($setAifNI==1)//aif
		{
			$oidStr = "2.1.254";
			setParamValue($mss_ip[0],$sysId,$oidStr,3);
			setParamValue($mss_ip[1],$sysId,$oidStr,4);
		}
	}//end set system ip
	exit;
}	

if($_SERVER['REQUEST_METHOD'] == "POST")
{
	if(isset($setSys) || isset($getSys))
	{
		if(isset($setSys))
		{
			echo "<br>Setting parameters<br>";
					
			SetParam($sysId_arr1);	
			SetParam($sysId_arr);	
						
			$showType="Set";
			echo "<br>Sending save command<br>";
			SaveParam($SaveArr);
			
			echo "<script LANGUAGE=\"JavaScript\">";
			if(!$DEBUG)
				//echo "\n window.location.href=\"../overview/overview.php\";";
			echo "\n </script>";	
			//exit();	
	
		}
		else
		{ 
			echo "<br>Getting parameters<br>";
			session_register("GetFlag");
			GetParam($sysId_arr1);
			GetParam($sysId_arr);
			$showType="Get";
		}
	}
//exit;	
	echo "<script LANGUAGE=\"JavaScript\">";
	if(!$DEBUG)
		echo "\n window.location.href=\"./msc.php?scroll_y=$scroll_y\";";
	echo "\n </script>";	
	exit();	
}
	
if(isset($delflag))
{
	if($DEBUG) echo "delValue = $delValue<br>";
	if($DEBUG) echo "delflag = $delflag<br>";
	if($delflag == 'pp')	//pstn prefix
	{
		$objWhereStr = getLevelWhere('2.8.0');	
		$setsql = "update $net_paramTable set initValue = '$conv_pre_def' where $objWhereStr and instanceNo='$delValue'";		
		mysqli_query($pubConn,$setsql);
		echo mysqli_error($pubConn);
		if($DEBUG) echo "<br>$setsql<br>";
	}
	else if($delflag == 'dailing')	//Dailing prefix
	{
		$delNoStr = rtrim($delNoStr,'.');
		$delNoArr = explode('.',$delNoStr);
		$instNoWhereStr = '';
		for($i=0; $i< sizeof($delNoArr); $i++)
		{
			if($i==0)
				$instNoWhereStr = "(instanceNo='$delNoArr[$i]'";
			else
				$instNoWhereStr .= " or instanceNo='$delNoArr[$i]'" ;
		}
		$instNoWhereStr .= ')';
		{//delete localprefix
			$sysId = '322_99_99';
		
			$sysIdArr	= explode('_',$sysId);
			$sysTypeNo	= $sysIdArr[0];
			$sysNo		= $sysIdArr[1];
			$subSysNo	= $sysIdArr[2];
		
			$objDb		= 'OBJ_'.$sysTypeNo;
			$paramTable = 'param_'.$sysNo;
					
			$oidstr = '2.1.2';
			$objWhereStr= '';
			$objWhereStr =getLevelWhere($oidstr);		
			
			$defSql = " SELECT initValue FROM paramConf WHERE $objWhereStr";
			$defRes = @mysqli_query($pubConn,$defSql);
			$row = @mysqli_fetch_array($defRes);
			
			$flagoffset = "10.7-10.7";			
			$row[initValue] = setBitValue($row[initValue],$flagoffset,0);
		
			$delSql = "UPDATE $paramTable SET initValue = '$row[initValue]' 
		            WHERE subSysNo = '$subSysNo' AND $objWhereStr AND $instNoWhereStr";
			if($DEBUG) echo "<br>delSql=$delSql";
			$delRes = @mysqli_query($pubConn,$delSql);
			echo mysqli_error($pubConn);
		
			$oidstr = '2.1.1';
			$objWhereStr= '';
			$objWhereStr =getLevelWhere($oidstr);		
			
			$defSql = " SELECT initValue FROM paramConf WHERE $objWhereStr";
			$defRes = @mysqli_query($pubConn,$defSql);
			$row = @mysqli_fetch_array($defRes);
			
			$delSql = "UPDATE $paramTable SET initValue = '$row[initValue]' 
		            WHERE subSysNo = '$subSysNo' AND $objWhereStr AND $instNoWhereStr";
			if($DEBUG) echo "<br>delSql=$delSql";
			$delRes = @mysqli_query($pubConn,$delSql);
			echo mysqli_error($pubConn);
			
			$oidstr = '2.1.3';
			$objWhereStr= '';
			$objWhereStr =getLevelWhere($oidstr);		
			
			$defSql = " SELECT initValue FROM paramConf WHERE $objWhereStr";
			$defRes = @mysqli_query($pubConn,$defSql);
			$row = @mysqli_fetch_array($defRes);
			
			$delSql = "UPDATE $paramTable SET initValue = '$row[initValue]' 
		            WHERE subSysNo = '$subSysNo' AND $objWhereStr AND $instNoWhereStr";
			if($DEBUG) echo "<br>delSql=$delSql";
			$delRes = @mysqli_query($pubConn,$delSql);
			echo mysqli_error($pubConn);	
		}
	}
	else if($delflag == 'conv')	//conv prefix
	{
		$delNoStr = rtrim($delNoStr,'.');
		$delNoArr = explode('.',$delNoStr);
		$instNoWhereStr = '';
		for($i=0; $i< sizeof($delNoArr); $i++)
		{
			if($i==0)
				$instNoWhereStr = "(instanceNo='$delNoArr[$i]'";
			else
				$instNoWhereStr .= " or instanceNo='$delNoArr[$i]'" ;
		}
		$instNoWhereStr .= ')';
		
		$objWhereStr = getLevelWhere('2.8.0');	
		$setsql = "update $net_paramTable set initValue = '$conv_pre_def' where $objWhereStr and $instNoWhereStr";		
		mysqli_query($pubConn,$setsql);
		echo mysqli_error($pubConn);
		if($DEBUG) echo "<br>$setsql<br>";
	}
	
	if(!$DEBUG)
	{
		echo "<script LANGUAGE=\"JavaScript\">";
		echo "\n window.location.href=\"$PHP_SELF?scroll_y=$scroll_y\";";
		echo "\n </script>";
	}
}

if(isset($resetDevice))//reset mss,sccp,mtp3 
{
	$resetArr=array(
		array('oidstr'=>'3.2',	'setvalue'=>'5A'	,'sysid'=>'322_99_99'),//MSC
		array('oidstr'=>'3.7',	'setvalue'=>'01'	,'sysid'=>'222_99_99'),//mtp3	
		array('oidstr'=>'3.2',	'setvalue'=>'00'	,'sysid'=>'223_99_99'),//sccp	
	);	
	SaveParam($resetArr);
	echo "<script LANGUAGE=\"JavaScript\">";
	if(!$DEBUG)
		echo "\n window.location.href=\"./msc.php?scroll_y=$scroll_y\";";
	echo "\n </script>";	
	exit();	
}//end reset.

?>

<?php
//==========================================================
//输出并显示数据
//========================================================== 
echo "<form method=\"POST\" name=\"update\" action=\"$PHP_SELF?scroll_y=$scroll_y\">";
echo "<table border=\"0\" width=\"100%\">";
echo "<tr>";
echo "<td width=\"50%\">";
echo "Configuration > <a href=\"../overview/overview.php\">Network</a> > <a href=\"#\">MSC</a>";
echo "<td width=\"50%\" align=\"right\" title=\"Help\">";
$helpId = '2.1.1.1';
showHelp($helpId);
echo "</td>";
echo "</tr>";
echo "</table>";
echo "<br>";

{
	echo "<table width=\"100%\">";
	echo "<tr>";
		//echo "<td width=\"60%\">";
			//echo "<b>Mobile Switching Center:&nbsp;&nbsp;</b>";
		//echo "</td>";
		echo "<td width=\"30%\" align=\"right\">";
				echo "<input type=\"submit\" title=\"$strTitleGet\" name=\"getSys\" value=\"$strGet\" class=\"button\" style=\"$buttonStyle\">";
				echo "&nbsp;&nbsp;&nbsp;";
				echo "<input type=\"submit\" title=\"$strTitleSet\" name=\"setSys\" value=\"$strSet\" class=\"button\" style=\"$buttonStyle\">";
			echo "</td>";
		echo "<td width=\"10%\">";
			echo "<p align=\"right\"><a href=\"../overview/overview.php?scroll_y=$page_top\"><img align=absBottom border=0 src=\"../../images/left.gif\" width=\"14\" height=\"14\">$strBack</a>";
		echo "</td>";
	echo "</tr>";
	echo "</table>";
}
?>

<TABLE  border="1"  cellpadding="2" cellspacing="0" bordercolor="#666666" bordercolordark="#FFFFFF" bgcolor="#FFFFFF" width="100%">

<?
//==========================================================
//输出Signaling point
//========================================================== 
{
	$querysql = "select initValue from $mtp3_sqlTable where level_1 = '2' and level_2 = '2'  and level_3 = '0'";
	$result = mysqli_query($pubConn,$querysql);
	$indicator = mysqli_fetch_array($result);
	echo mysqli_error($pubConn);
	if($DEBUG)echo "<br>indicator = {$indicator[0]}<br>";
		
	for($i = 0; $i < 4; $i++)
	{
		$flag = getBitValue($indicator[0],"0.$i");
		if ($flag == 0)
			$spc_index[$i] = $i;
		else
			$spc_index[$i] = $i+4;	
	}
}
echo "<tr>" ;
echo "<td width=\"20%\" bgcolor=\"#E6E6E6\"><b>Signaling point code</b></td>";
echo "<td width=\"80%\"><table width=100%><tr>";
$sysId = "222_99_99";
for($i=0; $i<4; $i++){
	echo "<td width=\"24%\" align=\"left\">{$spcTree_array[$i][0]}:&nbsp;";
	showParameter($sysId,'2.2',$i+1,1);
	echo "&nbsp;";
	showParameter($sysId,'2.2',$i+5,1);
	echo "&nbsp;";
	$doingOtherUlr="$PHP_SELF?doingOtherFlag=1&setMSC_spc=1&netId=$i";
	showParameter($sysId,$spcTree_array[$spc_index[$i]][2],1,1,0,$doingOtherUlr);
}

echo "<td align=\"right\"> <a href=\"javascript:linkTo('../toElement/ACNconf.php','sysId=222_99_99&instanceNo=0&objIdStr=2.7.1&sysTypeNo=222&setname=ACN','../mss/msc.php');\"><b>ACN</b></a></td>";
echo "</tr></table></td>";
echo "</tr>";

//==========================================================
//输出Global title
//========================================================== 
//msc
$sysId = "223_99_99";
$oidStr = "2.1.8";
$instanceNo=0;
echo "<tr>";
echo "<td width=\"20%\" bgcolor=\"#E6E6E6\" ><b>$strE164Number(MSC)</b></td>";
echo "<td width=\"80%\" ><table width=100%>";

	echo "<td align=\"left\" width=50%>";
	$doingOtherUlr="$PHP_SELF?doingOtherFlag=1&setMscGtt=1";
		showParameter($sysId,$oidStr,2,1,$instanceNo,$doingOtherUlr);
	echo "</td>";
	
	echo "<td align=\"left\" width=50%>";
		showParameter($sysId,$oidStr,1,1);
	echo "</td>";
echo "</table></td></tr>";

//ssf
$oidStr = "2.1.146";
echo "<tr >" ;
echo "<td bgcolor=\"#E6E6E6\" ><b>$strE164Number(SSF)</b></td><td><table width=100%>";
	echo "<td align=\"left\" width=50%>";
		$doingOtherUlr="$PHP_SELF?doingOtherFlag=1&setSsfGtt=1";
		showParameter($sysId,$oidStr,2,1,$instanceNo,$doingOtherUlr);
	echo "</td>";
	
	echo "<td align=\"left\" width=50%>";
		showParameter($sysId,$oidStr,1,1);
	echo "</td>";
echo "</table></td></tr>";

//aif
$oidStr = "2.1.254";
echo "<tr >" ;
echo "<td bgcolor=\"#E6E6E6\" ><b>AIF network indicator</b></td>";
	echo "<td align=\"left\" width=50%>&nbsp;";
		$doingOtherUlr="$PHP_SELF?doingOtherFlag=1&setAifNI=1";
		showParameter($sysId,$oidStr,1,1,$instanceNo,$doingOtherUlr);
	echo "</td>";
echo "</tr>";

//==========================================================
//输出Network
//========================================================== 
$NetworkCodeArr=array(
//	array('oid',	'showName'),
	array('2.3.0',	'CC'),
	array('2.4.0',	'NDC'), 
	array('2.1.0',	'MCC'),
	array('2.2.0',	'MNC'), 
	array('2.5.0',	'Int prefix'),
	array('2.6.0',	'Nat prefix')
);
echo "<tr >" ;
echo "<td bgcolor=\"#E6E6E6\" rowspan=2><b>Network</b></td>";
echo "<tr>";



echo "<td ><table width=\"100%\" cellpadding=\"1\" cellspacing=\"0\">";
$sysId = "225_99_99";
for($i=0;$i < sizeof($NetworkCodeArr);$i+=2)
{
	echo "<tr>";
	echo "<td width=10%>{$NetworkCodeArr[$i][1]}</td>";
	echo "<td width=40% align=\"left\">";
		$oidStr = $NetworkCodeArr[$i][0];
	
		
		showParameter($sysId,$oidStr,1,1);
	echo "</td>";
	$j = $i+1;
	echo "<td width=10%>{$NetworkCodeArr[$j][1]}</td>";
	echo "<td width=40% align=\"left\">";
		$oidStr = $NetworkCodeArr[$j][0];
		if($i==0)
			showParameter($sysId,$oidStr,1,4);
		else
			showParameter($sysId,$oidStr,1,1);
	echo "</td>";
	echo "</tr>";	
}
echo "</table></td>";
echo "</tr>";

//echo "<tr><td colspan=4><hr></td></tr>";
echo "</tr>";
echo "<tr>";
echo "<td bgcolor=\"#E6E6E6\"><b>NITZ</b></td>";
echo "<td ><table width=\"100%\" cellpadding=\"1\" cellspacing=\"0\">";
//=====add NITZ parameter=================
{
	$sysIdd="322_99_99";
	$oidStrr="2.2.5";
	$doingOtherUlr="$PHP_SELF?doingOtherFlag=1&setNITZName=1";
	echo "<tr>";
	echo "<td width=\"10%\">Name";
	echo "</td>";
	echo "<td width=\"40%\">";
	showParameter($sysIdd,$oidStrr,3,3,0,$doingOtherUlr);
	echo "</td>";
	echo "<td width=\"10%\">Time Flag";
	echo "</td>";
	echo "<td width=\"40%\">";
	showParameter($sysIdd,$oidStrr,4,3);
	echo "</td>";
	echo "</tr>";
	echo "<tr>";
	echo "<td width=\"10%\">Time Zone";
	echo "</td>";
	echo "<td width=\"40%\">";
	showParameter($sysIdd,$oidStrr,5,1);
	echo "</td>";
	echo "</tr>";
}
//=====================
echo "</table></td>";
echo "</tr>";
echo "</tr>";

{//输出MSRN Range   
	$sysId = "325_99_99";
	$oidStr = "2.1.13";
	$instanceNo = 0;
	echo "<tr>";
		echo "<td bgcolor=\"#E6E6E6\"><b>MSRN range</b></td>";
		echo "<td>";
			echo "<table width=\"100%\" cellpadding=\"1\" cellspacing=\"0\">";
				echo "<tr>";
				echo "<td width=\"10%\">Start:</td>";
				echo "<td width=\"40%\">";
					$doingOtherUlr="$PHP_SELF?doingOtherFlag=1&setMsrnStart=1";
					showParameter($sysId,$oidStr,1,1,$instanceNo,$doingOtherUlr);
				echo "</td>";
				
				echo "<td width=\"10%\">End:</td>";
				echo "<td width=\"40%\">";
					$doingOtherUlr="$PHP_SELF?doingOtherFlag=1&setMsrnEnd=1";
					showParameter($sysId,$oidStr,2,1,$instanceNo,$doingOtherUlr);
				echo "</td>";
				echo "</tr>";
			echo "</table>";
		echo "</td>";
	echo "</tr>";
}	

/*
{//输出Local CLI type   
	$sysId = "322_99_99";
	$oidStr = "2.1.2";
	$instanceNo = 249;
	echo "<tr>";
		echo "<td bgcolor=\"#E6E6E6\"><b>Local CLI type</b></td>";
		echo "<td>";
		$doingOtherUlr="$PHP_SELF?doingOtherFlag=1&setLocalCliType=1";
		showParameter($sysId,$oidStr,15,1,$instanceNo,$doingOtherUlr);
		echo "</td>";
	echo "</tr>";
}
*/

{//输出dailing prefix
	{//get all local prefix
		//find prefix
		$sysId = '322_99_99';
		
		$sysIdArr	= explode('_',$sysId);
		$sysTypeNo	= $sysIdArr[0];
		$sysNo		= $sysIdArr[1];
		$subSysNo	= $sysIdArr[2];
		
		$objDb		= 'OBJ_'.$sysTypeNo;
		$paramTable = 'param_'.$sysNo;
		
		{//get all enable prefix No
		$oidstr = '2.1.2';
		$objWhereStr= '';
		$objWhereStr =getLevelWhere($oidstr);		
		
		$defSql = " SELECT initValue,instanceNo FROM $paramTable 
					WHERE $objWhereStr and instanceNo<252
					ORDER BY instanceNo";
		//echo $defSql;
		$defRes = @mysqli_query($pubConn,$defSql);
		echo mysqli_error($pubConn);
		$offset_enable = "10.7-10.7";
		$offset_Properties = "10.2-10.3";	
		$offset_calltype = "10.4-10.6";
		$prefix_num=0;	
		while($row = @mysqli_fetch_array($defRes))
		{
			$prefix_enable=bindec(getBitValue($row[initValue],$offset_enable));
			$prefix_property=bindec(getBitValue($row[initValue],$offset_Properties));
			$prefix_calltype=bindec(getBitValue($row[initValue],$offset_calltype));
			//echo "<br>{$row[instanceNo]}->enable:$prefix_enable; property:$prefix_property; callType:$prefix_calltype";
			//$flag = ($prefix_enable && ($prefix_property==1) && ($prefix_calltype==0));//enable,msisdn,normalcall
			//$flag = ($prefix_enable && ($prefix_calltype==0));
			//$flag = ($prefix_enable );
			//$flag = ($prefix_enable && $prefix_property!=2 && $prefix_calltype!=4);
			$flag = ($prefix_enable && $prefix_calltype!=4);
			//$emFlag = $prefix_enable && $prefix_calltype==1;
			if($flag)
			{
				$enablePrefix[$prefix_num][inst_no]=$row[instanceNo];
				$enablePrefix[$prefix_num][init_value]=$row[initValue];
				//echo "<br>".$prefix_num . ": ".$enablePrefix[$prefix_num][inst_no];
				$prefix_num++;
			}
			if($prefix_enable==0 && !isset($unused_ins))
				$unused_ins = $row[instanceNo];
		}	
		}//end get enable prefix No
		{
		$oidstr = '2.1.3';
		$objWhereStr= '';
		$objWhereStr =getLevelWhere($oidstr);	
		
		$paramSql = " SELECT initValue,instanceNo FROM $paramTable  
					WHERE subSysNo = '$subSysNo' AND  $objWhereStr and instanceNo<252
					ORDER BY instanceNo 
					";
		//echo "<br>paramSql: $paramSql";
		$Result_1 = mysqli_query($pubConn,$paramSql);	
		$prefix_no=0;
		$valid_num=0;	
		while($Row_1 = mysqli_fetch_array($Result_1))
		{
			if($Row_1[instanceNo]==$enablePrefix[$prefix_no][inst_no])
			{
				$tmpTg=hexdec($Row_1[initValue]);
				//echo "<br>{$Row_1[instanceNo]}->tmpTg: $tmpTg";
				if($tmpTg == $localPrefixTg)
				{
					$validPrefix[$valid_num][inst_no] = $enablePrefix[$prefix_no][inst_no];
					$validPrefix[$valid_num][init_value] = $enablePrefix[$prefix_no][init_value];
					$validPrefix[$valid_num][tg] = $tmpTg;
					$valid_num++;
				}
				$prefix_no++;
			}
			if($prefix_no >= $prefix_num)
				break;		
		}
		}
		{//get prefix value
		$oidstr = '2.1.1';
		$objWhereStr= '';
		$objWhereStr =getLevelWhere($oidstr);	
		
		$paramSql = " SELECT initValue,instanceNo FROM $paramTable  
					WHERE subSysNo = '$subSysNo' AND  $objWhereStr  and instanceNo<252
					ORDER BY instanceNo 
					";
	//				echo "$paramSql";
		$Result_1 = mysqli_query($pubConn,$paramSql);	
		$prefix_no=0;			
		while($Row_1 = mysqli_fetch_array($Result_1))
		{
			if($Row_1[instanceNo]==$validPrefix[$prefix_no][inst_no])
			{
				$tempprefix=strtoupper($Row_1[initValue]);
				$prefix = explode('E',$tempprefix);
				if($prefix[0] =="")
					$prefix[0]="--";
				$validPrefix[$prefix_no][prefix]=$prefix[0];
				//echo "<br>".$validPrefix[$prefix_no][prefix];
				$prefix_no++;
			}
			if($prefix_no >= $valid_num)
				break;		
		}
		}//end get prefix value
	}//end get all local prefix
	$dailingPre_nrow = $valid_num + 1;
	$objIdStr='no-2.1.1-2.1.2';
	$sysId = '322_99_99';
	$webname="MSC";
	$setname="Prefix";
	$backurl="./msc.php";
	
	echo "<tr>" ;
		echo "<td bgcolor=\"#E6E6E6\">";
			echo "<table width=\"100%\" cellpadding=\"1\" cellspacing=\"0\" ><tr >";
			echo "<td align=left><b>WXC2 <br>subscriber prefix</b></td>";
			echo "<td align=\"right\"><a href=javascript:openSetPrefix('$localPrefixTg','$unused_ins','$objIdStr','$sysId','$webname','$setname','$backurl')><font size=4>+</font></a></td>";
			echo "</tr></table>";
		echo "</td>";
		if($valid_num == 0) echo "<td>&nbsp;--</td>";
		else
		{
			$flag = 'dailing';
			$showNum = $valid_num >= 4 ? 4 : $valid_num;
			$slctNum = ($$flag==1) ? $valid_num : $showNum;
		echo "<td>";
			echo "<table width=\"100%\" cellpadding=\"1\" cellspacing=\"0\">";
			echo "<tr bgcolor=\"#E6E6E6\">";
				echo "<td width=\"10%\">No.</td>";
				echo "<td width=\"15%\">Prefix</td>";
				echo "<td width=\"15%\">TON-in</td>";
				echo "<td width=\"15%\">TON-out</td>";
				echo "<td width=\"15%\">Properties</td>";
				echo "<td width=\"15%\">Call Type</td>";
				//echo "<td >CDR</td>";
				echo "<td width=\"15%\" align=right><a href=\"javascript:delSelected('$flag',0,$slctNum)\" title=\"Delete all selected.\">Delete</a>";
				echo "<input type=\"checkbox\" name=\"seleceAll\" title=\"Select all to delete\"  value=\"1\" onClick=selectAllToDel('$flag',this,0,$slctNum)>";
				echo "</td>";
			echo "</tr>";
			
			$TON_in 	= array('Spare','MSISDN','Unkown','NDD','IDD','Spare');
			$TON_out 	= array('Spare','MSISDN','Unkown','NDD','IDD','Spare');
			$Properties = array('Trunk','MSISDN','MSRN','MSC');	
			$callTypeArr= array('Normal Call','Emergency','MCT','VMS','IN');
			
			for($i=0;$i < $valid_num;$i++)
			{
				$checkBoxName=$flag . 'checkBox_'.$i;
				$deleteNo = $flag . 'deleteno_'.$i;
				
				$tmpInitValue = $validPrefix[$i][init_value];
				$tmpInst	= $validPrefix[$i][inst_no];
				echo "<tr  onMouseOver=\"this.bgColor='#D2F0FF'\" onMouseOut=\"this.bgColor='#ffffff'\">";
					echo "<td width=\"10%\"><a  href=javascript:openSetPrefix('$localPrefixTg','{$validPrefix[$i][inst_no]}','$objIdStr','$sysId','$webname','$setname','$backurl')>$i</a></td>";
					$oTON_in		= BinDec(getBitValue($tmpInitValue,'0.0-0.3'));
					$oTON_out 		= BinDec(getBitValue($tmpInitValue,'0.4-0.7'));
					$oProperties 	= BinDec(getBitValue($tmpInitValue,'10.2-10.3'));
					$oCallType      = BinDec(getBitValue($tmpInitValue,'10.4-10.6'));
					$oCDR			= BinDec(getBitValue($tmpInitValue,'10.0-10.0'));
					$oCDR			= ($oCDR) ? ("ON") : ("OFF");
					
					$oRano			= $validPrefix[$i][prefix];
					echo "<td width=\"15%\">$oRano&nbsp</td>";
					echo "<td width=\"15%\">$TON_in[$oTON_in]&nbsp;</td>";
					echo "<td width=\"15%\">$TON_out[$oTON_out]&nbsp;</td>";
					echo "<td width=\"15%\">$Properties[$oProperties]&nbsp;</td>";
					echo "<td width=\"15%\">$callTypeArr[$oCallType]&nbsp;</td>";
				//		echo "<td >$oCDR&nbsp</td>";
				
					echo "<td align=right><input type=\"checkbox\" name=\"$checkBoxName\" value=\"0\" onClick=\"javascript:selectToDel(this)\"></td>";
					echo "<input type=\"hidden\" name=\"$deleteNo\" value=\"{$validPrefix[$i][inst_no]}\"";	
				echo "</tr>";	
				if(($i< $valid_num-1)&& $i==$showNum-1 && $$flag==0)
				{
					echo "<tr><td><a href=\"javascript:linkTo('./msc.php','$flag=1','-1')\">more >></a></td></tr>";
					break;
				}
			}
			if($$flag)
				echo "<tr><td><a href=\"javascript:linkTo('./msc.php','$flag=0','-1')\">Hide <<</a></td></tr>";

			echo "</table>";
		echo "</td>";
		}
	echo "</tr>";
}//end 输出 Dialing prefix
{//default prefix
echo "<tr>" ;
	echo "<td bgcolor=\"#E6E6E6\">";
		echo "<table width=\"100%\" cellpadding=\"1\" cellspacing=\"0\" ><tr >";
		echo "<td align=left><b>Default prefix</b></td>";
		echo "<td align=\"right\"></td>";
		echo "</tr></table>";
	echo "</td>";
	$flag = 'Default';
	echo "<td>";
		echo "<table width=\"100%\" cellpadding=\"1\" cellspacing=\"0\">";
		echo "<tr bgcolor=\"#E6E6E6\">";
			echo "<td width=\"10%\">No.</td>";
			echo "<td width=\"15%\">Prefix</td>";
			echo "<td width=\"15%\">TON-in</td>";
			echo "<td width=\"15%\">TON-out</td>";
			echo "<td width=\"15%\">Properties</td>";
			echo "<td width=\"15%\">Call Type</td>";
			//echo "<td >CDR</td>";
			echo "<td width=\"15%\" align=right>Switch</a>";
			echo "</td>";
		echo "</tr>";
		$objIdStr='no-2.1.1-2.1.2';
		$sysId = '322_99_99';
		$webname="MSC";
		$setname="Def Prefix";
		$backurl="./msc.php";
		{//get all DefPrefix
			$oidstr = '2.1.2';
			$objWhereStr =getLevelWhere($oidstr);		
			
			$selSql = " SELECT initValue,instanceNo FROM $paramTable 
						WHERE $objWhereStr and instanceNo>251 ORDER BY instanceNo";
			//echo $defSql;
			$result = @mysqli_query($pubConn,$selSql);
			echo mysqli_error($pubConn);
			$offset_enable = "10.7-10.7";
			$offset_Properties = "10.2-10.3";	
			$offset_calltype = "10.4-10.6";
			$valid_num=0;	
			while($row = @mysqli_fetch_array($result))
			{
				$prefix_enable=bindec(getBitValue($row[initValue],$offset_enable));
				if($prefix_enable==0)
				{
					if($row[instanceNo]==252)
					{
						$tmpInst = 252;
						$tmpSetValue = '2200EEEEEEEEEEEEEEEE810000EEEEEEEE030000';
					}
					if($row[instanceNo]==253)
					{
						$tmpInst = 253;
						$tmpSetValue = '4202EEEEEEEEEEEEEEEE810000EEEEEEEE030000';
						$objStr_2 = '2.1.1';
						$levelWhere_2 = getLevelWhere($objStr_2);
						$updSql_2 = "update $paramTable set initValue='00EEEEEEEEEEEEEE' where $levelWhere_2 and instanceNo=$tmpInst";
						mysqli_query($pubConn,$updSql_2);
					}
					if($row[instanceNo]==254)
					{
						$tmpInst = 254;
						$tmpSetValue = '3300EEEEEEEEEEEEEEEE810000EEEEEEEE030000';
					}
					if($row[instanceNo]==255)
					{
						$tmpInst = 255;
						$tmpSetValue = '4400EEEEEEEEEEEEEEEE810000EEEEEEEE030000';
					}
				
					$tmpUpdSql = "update $paramTable set initValue='$tmpSetValue' where $objWhereStr and instanceNo='$tmpInst'";
					mysqli_query($pubConn,$tmpUpdSql);
				}
				$prefix_property=bindec(getBitValue($row[initValue],$offset_Properties));
				$prefix_calltype=bindec(getBitValue($row[initValue],$offset_calltype));
				$validPrefix[$valid_num][inst_no]=$row[instanceNo];
				$validPrefix[$valid_num][init_value]=$row[initValue];
				$valid_num++;
			}	
			$oidstr = '2.1.1';
			$objWhereStr =getLevelWhere($oidstr);		
			
			$selSql = " SELECT initValue,instanceNo FROM $paramTable 
						WHERE $objWhereStr and instanceNo>251 ORDER BY instanceNo";
			//echo $defSql;
			$result = @mysqli_query($pubConn,$selSql);
			$valid_num = 0;
			while($row = @mysqli_fetch_array($result))
			{
				$tempprefix=strtoupper($row[initValue]);
				$prefix = explode('E',$tempprefix);
				if($prefix[0] =="")
					$prefix[0]="--";
				$validPrefix[$valid_num][prefix]=$prefix[0];
				$valid_num++;
			}	
			
			{//other elements
				$othersElementObjIdStr='2.11';
				$levelWhere = getLevelWhere($othersElementObjIdStr);
				if($DEBUG) echo "<BR>levelWhere=$levelWhere";
				$othersElementParamTable='OBJ_225.param_99';
				$getSql="SELECT initValue,instanceNo FROM $othersElementParamTable 
							WHERE $levelWhere and initValue LIKE '01%'";
				if($DEBUG) echo "<BR>getSql=$getSql";
				$result	=mysqli_query($pubConn,$getSql);
				echo mysqli_error($pubConn);
				$typeOffset 	= '1.0-1.7';
				$tgOffset 		= '3.0-3.7';
				$nameOffset 	= '14.0-23.7';
				while($rows=mysqli_fetch_array($result))
				{
					if($DEBUG)echo "<BR>initValue=$rows[initValue]";
					$tmpType=getBitValue($rows[initValue],$typeOffset);
					if($tmpType==0)
						continue;
					$type = hexdec($tmpType);
					if($type==16 || $type == 17)
					{
						$tg = hexdec(getBitValue($rows[initValue],$tgOffset));
						$name=getBitValue($rows[initValue],$nameOffset);
						if($name==0)
							$name=$tg;
						else
							$name=trim(toAscii($name));	
						$SwitchNameArr[$tg] = $name;
					}
				}
			}//end otherelments
			$oidstr = '2.1.3';
			$objWhereStr =getLevelWhere($oidstr);	
			$selSql =" SELECT initValue,instanceNo FROM $paramTable 
						WHERE $objWhereStr and instanceNo>251 ORDER BY instanceNo";
			$result = @mysqli_query($pubConn,$selSql);
			$valid_num = 0;
			while($row = @mysqli_fetch_array($result))
			{
				$validPrefix[$valid_num][tg]=$tmpTg=hexdec($row[initValue]);
				$validPrefix[$valid_num][tgName] = $SwitchNameArr[$tmpTg];
				$valid_num++;
			}	
		}//end get enable prefix No
		$TON_in 	= array('Spare','MSISDN','Unkown','NDD','IDD','Spare');
		$TON_out 	= array('Spare','MSISDN','Unkown','NDD','IDD','Spare');
		$Properties = array('Trunk','MSISDN','MSRN','MSC');	
		$callTypeArr= array('Normal Call','Emergency','MCT','VMS','IN');
		for($i=0;$i < $valid_num;$i++)
		{
			$checkBoxName=$flag . 'checkBox_'.$i;
			$deleteNo = $flag . 'deleteno_'.$i;
			
			$tmpInitValue = $validPrefix[$i][init_value];
			$tmpInst	= $validPrefix[$i][inst_no];
			echo "<tr  onMouseOver=\"this.bgColor='#D2F0FF'\" onMouseOut=\"this.bgColor='#ffffff'\">";
				echo "<td width=\"10%\"><a  href=\"javascript:openSetPrefix('$localPrefixTg','{$validPrefix[$i][inst_no]}','$objIdStr','$sysId','$webname','$setname','$backurl')\">$i</a></td>";
				$oTON_in		= BinDec(getBitValue($tmpInitValue,'0.0-0.3'));
				$oTON_out 		= BinDec(getBitValue($tmpInitValue,'0.4-0.7'));
				$oProperties 	= BinDec(getBitValue($tmpInitValue,'10.2-10.3'));
				$oCallType      = BinDec(getBitValue($tmpInitValue,'10.4-10.6'));
				$oCDR			= BinDec(getBitValue($tmpInitValue,'10.0-10.0'));
				$oCDR			= ($oCDR) ? ("ON") : ("OFF");
				
				$oRano			= $validPrefix[$i][prefix];
				echo "<td width=\"15%\">$oRano&nbsp</td>";
				echo "<td width=\"15%\">$TON_in[$oTON_in]&nbsp;</td>";
				echo "<td width=\"15%\">$TON_out[$oTON_out]&nbsp;</td>";
				echo "<td width=\"15%\">$Properties[$oProperties]&nbsp;</td>";
				echo "<td width=\"15%\">$callTypeArr[$oCallType]&nbsp;</td>";
			//		echo "<td >$oCDR&nbsp</td>";
				$showSwithName = sizeof($validPrefix[$i][tgName])==0 ? '--' : $validPrefix[$i][tgName];
				echo "<td align=right>$showSwithName</td>";
			echo "</tr>";	
		}
		echo "</table>";
	echo "</td>";
echo "</tr>";
}//end default prefix
//==========================================================
//输出Call control
//========================================================== 
echo "<tr>";
echo "<td bgcolor=\"#E6E6E6\" rowspan=6><b>Call control</b></td>";
echo "<td ><table width=100%><tr>";

echo "<td>CDR</td>";
echo "<td><table width=100%><tr>";
for ($i = 0;$i < sizeof($CDR_status);$i ++)
{
	$width = '10%';
	echo "<td width=\"$width\"><table>";
	echo "<tr><td align=\"left\">{$CDR_status[$i][0]}</td></tr>";
	echo "<tr><td align=\"left\">";
	showParameter('322_99_99','2.1.5',$CDR_status[$i][1],1);	
	echo "</td></tr>";
	echo "</table></td>";
}
echo "</tr>";

echo "</tr></table></td>"; 
echo "</tr></table></td></tr>";

//output Suspend Timer,Call Diverty Display,Repeat Paging Times
{
	echo "<tr><td><table width=100%>";
	$sysId = '322_99_99';
	echo "<tr>";
	
	echo "<td  width=\"30%\">ISUP suspend timer:&nbsp;&nbsp;";
	$oidStr = "2.2.1";
	showParameter($sysId,$oidStr,1,1);
	echo "&nbsp;&nbsp;minutes</td>";
	echo "</td>";
	
	echo "<td width=\"30%\">Call divert display:&nbsp;&nbsp;";
	$oidStr = "2.2.2";
	showParameter($sysId,$oidStr,1,1);
	echo "</td>";
	
	echo "<td width=\"30%\">Repeat paging times:&nbsp;&nbsp;";
	$oidStr = "2.2.3";
	showParameter($sysId,$oidStr,1,1);
	echo "</td>";
	
	echo "</tr></table></td></tr>";
}

//output max call Duration,Location Number
{
	$sysId = '322_99_99';
	echo "<tr><td ><table width=100%>";
	echo "<tr>";
	echo "<td width=\"30%\">Max call duration:&nbsp;&nbsp;";
	$oidStr = "2.3.7";
	showParameter($sysId,$oidStr,1,1);
	echo "&nbsp;&nbsp;&nbsp;minutes</td>";
	
	$oidStr = "2.3.1";
	
	echo "<td width=\"30%\">Location number:&nbsp;&nbsp;";
	showParameter($sysId,$oidStr,2,1);
	echo "</td>";
	
	echo "<td width=\"30%\">Len of location number:&nbsp;&nbsp;";
	showParameter($sysId,$oidStr,1,1);
	echo "</td>";
	

	echo "</tr></table></td></tr>";
}
{//out put Announcement and Warning tone timer
    echo "<tr><td ><table width=100%><tr>";
    	echo "<td width=30%><a  href=javascript:linkTo('./announcement.php','','$backurl')>Announcement</a></td>";
    	echo "<td width=70%>Warning tone timer:&nbsp;&nbsp;";
        	$oidStr = "2.1.7";
    	    showParameter($sysId,$oidStr,1,1);
    	echo "&nbsp;&nbsp;seconds</td>";
    echo "</tr></table></td></tr>";
}

//output E1 port
{
	$e1_oid = array('2.1.4','2.4.1','2.4.2','2.4.3');
	$link_oid = '2.5.1';
	echo "<tr><td ><table width=100%><tr>";
	/*echo "<td width=30%><a  href=\"./loop_back.php\">Inter-Connection</a></td>";*/
	echo "<td width=30%><a  href=javascript:linkTo('./loop_back.php','','$backurl')>Inter-Connection</a></td>";
	$objWhereStr = getLevelWhere($link_oid);
	$getsql = "SELECT initValue FROM $mtp3_sqlTable where $objWhereStr";
	if($DEBUG) echo "getsql = $getsql<br>";
	$e1_link_result = @mysqli_query($pubConn,$getsql);
		
	$objWhereStr = getLevelWhere($e1_oid[2]);//2.4.2 
	$defSql = "select initValue from $msc_paramConf where $objWhereStr";
	$defRes = @mysqli_query($pubConn,$defSql);
	$defRow = @mysqli_fetch_array($defRes);
	$defValue = $defRow[0];
	
	$getsql="SELECT initValue,instanceNo FROM $msc_paramTable
					WHERE $objWhereStr AND initValue != '$defValue'	";					
	if($DEBUG) echo "getsql = $getsql<br>";
	$result = @mysqli_query($pubConn,$getsql);
	$e1_253_num = 0;
	$e1_254_num = 0;
	$e1_e1_num = 0;
	while($e1_tg = mysqli_fetch_array($result))
	{
		$insNo = $e1_tg[instanceNo];	
		$e1_tg = hexdec($e1_tg[0]);
		
		$objWhereStr = getLevelWhere($e1_oid[3]);//2.4.3
		$getsql = "SELECT initValue FROM $msc_paramTable where $objWhereStr and instanceNo = '$insNo'";
		if($DEBUG) echo "getsql = $getsql<br>";
		$e1_cic = mysqli_query($pubConn,$getsql);
		$e1_cic = mysqli_fetch_array($e1_cic);
		$e1_cic = hexdec($e1_cic[0]);
		
		if($e1_tg == 253)
		{
			$e1_253[$e1_253_num] = $insNo;	
			$e1_253_cic[$e1_253_num] = $e1_cic;
			$e1_253_num++;
			
		}
		else if ($e1_tg == 254)
		{
			$e1_254[$e1_254_num] = $insNo;
			$e1_254_cic[$e1_254_num] = $e1_cic;	
			$e1_254_num++;
		}		
	}
	
	if($DEBUG) echo "e1_253_num = $e1_253_num<br>";
	
	$total_num = ($e1_253_num >= $e1_254_num) ? $e1_253_num : $e1_254_num;
	
	//used for exception handle
	{
		$e1_253_cic[$total_num] = hexdec('FFFFFFFF')+2;
		$e1_254_cic[$total_num] = hexdec('FFFFFFFF')+2;
		//$e1_253[$total_num] = -1;
		//$e1_254[$total_num] = -1;
	}
	for($i=0; $i < $total_num; $i++)
	{
		$e1_253_min = 0;
		$e1_254_min = 0;	
		for($j=0; $j < $total_num; $j++)
		{
			if(!isset($e1_253_cic[$j])) $e1_253_cic[$j] = hexdec('FFFFFFFF')+2;//used for exception handle
			if($e1_253_cic[$j] < $e1_253_cic[$e1_253_min]) 
			{
				$e1_253_min = $j;	
			}
			if(!isset($e1_254_cic[$j])) $e1_254_cic[$j] = hexdec('FFFFFFFF')+2;//used for exception handle
			if($e1_254_cic[$j] < $e1_254_cic[$e1_254_min]) 
			{
				$e1_254_min = $j;	
			}
		}
		//used for exception handle
		if($e1_253_cic[$e1_253_min] != $e1_254_cic[$e1_254_min])
		{
			$e1_253_cic[$e1_253_min] > $e1_254_cic[$e1_254_min] ? ($e1_253_min = $total_num) : ($e1_254_min = $total_num);
		}
		if($DEBUG) echo "<br>e1_253_cic[$e1_253_min] = $e1_253_cic[$e1_253_min]<br>";
		if($DEBUG) echo "e1_254_cic[$e1_254_min] = $e1_254_cic[$e1_254_min]<br>";
		
		//if($e1_254_cic[$e1_254_min] != $e1_253_cic[$e1_253_min])
			//continue;
		
		$e1_show_253[$i] = $e1_253[$e1_253_min];
		$e1_show_254[$i] = $e1_254[$e1_254_min];

		$e1_253_cic[$e1_253_min] = hexdec('FFFFFFFF')+2;
		$e1_254_cic[$e1_254_min] = hexdec('FFFFFFFF')+2;	
	}
	if($total_num == 0)
	{
		echo "<td width=35%>MSC0 E1: --</td>";
		echo "<td>MSC1 E1: --</td>";
	}
	else
	{
		echo "<td width=35%>MSC0 E1: ";
		for($i=0; $i < sizeof($e1_show_253); $i++)
		{
			echo "<ins>$e1_show_253[$i]</ins>&nbsp;";
			$e1_no .= $e1_show_253[$i];
			$e1_no .= '_';
		}
		echo "</td>";
		
		echo "<td>MSC1 E1: ";
		for($i=0; $i < sizeof($e1_show_253); $i++)
		{
			echo "<ins>$e1_show_254[$i]</ins>&nbsp;";
			$e1_no .= $e1_show_254[$i];
			if($i != sizeof($e1_show_253)-1) $e1_no .= '_';
		}
		echo "</td>";
	}
	echo "</tr>";
	echo "</table></td></tr>";
	
	echo "<input type=\"hidden\" name=\"e1_no\" value=\"$e1_no\">";
}

//Cell Parameter automatically add 112 at instanceNo 1023
{
	$oidEmergency = '2.2.7';
	$objWhereStr =getLevelWhere($oidEmergency);
	$Em_paramUpdSql = "update $msc_paramTable set initValue='000000000000112EEEEEEEEEEEEE000000' WHERE $objWhereStr and instanceNo=1023";
	$Em_Result = mysqli_query($pubConn,$Em_paramUpdSql);
}
echo "<tr><td ><table width=100%><tr>";
	echo "<td width=30%><a  href=javascript:linkTo('./toneAnnounce.php','','$backurl')>Tone</a></td>";
	echo "<td width=35%><a  href=javascript:linkTo('./clock.php','clock','$backurl')>Clock</a></td>";
	echo "<td width=35%><a  href=javascript:linkTo('./clock.php','signal','$backurl')>Signaling channel</a></td>";


echo "</tr>";
echo "</table></td></tr>";

{//输出 conv prefix
	$objIdStr='no-2.8';
	$sysId = '225_99_99';
	$webname="MSC";
	$setname="Prefix manipulation";
	$backurl="./msc.php";
	
	$oidStr = '2.8.0';
	$levelWhere = getLevelWhere($oidStr);
	
	$getsql = "select initValue,instanceNo from $net_paramTable where $levelWhere and initValue!='$conv_pre_def'";  
	$result = @mysqli_query($pubConn,$getsql);
	echo mysqli_error($pubConn);
	$convNo=0;
	while($pre_row = @mysqli_fetch_array($result))
	{
		$nameFlag = toAscii(getBitValue($pre_row[initValue],'35.0-42.7'));
		if($nameFlag == $webname)
		{
			$convPrefix[$convNo][initValue]=$pre_row[initValue];
			$convPrefix[$convNo][inst_no] = $pre_row[instanceNo];
			$prefix = getBitValue($pre_row[initValue],'00.0-15.7');
			if($convPrefix != 0)
				$prefix = toAscii($prefix);
			else
				$prefix = '--';
			$addDigs = getBitValue($pre_row[initValue],'18.0-33.7');
			if($addDigs != 0)
				$addDigs = toAscii($addDigs);
			else
				$addDigs = '--';
			$convPrefix[$convNo][prefix] = $prefix;
			$convPrefix[$convNo][delLen] = hexdec(getBitValue($pre_row[initValue],'16.0-16.7'));
			$convPrefix[$convNo][addLen] = hexdec(getBitValue($pre_row[initValue],'17.0-17.7'));
			$convPrefix[$convNo][addDigs] = $addDigs;
			$convPrefix[$convNo][valiLen] = hexdec(getBitValue($pre_row[initValue],'34.0-34.7'));
			//echo "<br>convPrefix[$convNo][prefix]:{$convPrefix[$convNo][initValue]}";
			$convNo++;
		}
	}//end while
	$getsql = "select initValue,instanceNo from $net_paramTable where $levelWhere and initValue='$conv_pre_def'";  
	//echo "<br>getsql: $getsql;";
	$result = @mysqli_query($pubConn,$getsql);
	$Row = @mysqli_fetch_array($result);
	$newConvInst=$Row[instanceNo];
	$conv_nrow = $convNo + 1;
	
	echo "<tr>" ;
	echo "<td bgcolor=\"#E6E6E6\">";
	echo "<table width=\"100%\" cellpadding=\"1\" cellspacing=\"0\" ><tr >";
	echo "<td align=left><b>Prefix manipulation</b></td>";
	echo "<td align=\"right\">";
	if($newConvInst=='')
	{
		echo "<a href=\"javascript:openErr()\">+</a></td>";
	}
	else
		echo "<a href=\"javascript:openSet('$newConvInst','$objIdStr','$sysId','$webname','$setname','$backurl')\"><font size=4>+</font></a></td>";
	echo "</tr></table></td>";
	if($convNo == 0) echo "<td>&nbsp;--</td>";
	else
	{
		echo "<td>";
		echo "<table width=\"100%\" cellpadding=\"1\" cellspacing=\"0\">";
		$flag = 'conv';
		$showNum = $convNo >= 4 ? 4 : $convNo;
		$slctNum = ($$flag==1) ? $convNo : $showNum;
		echo "<tr bgcolor=\"#E6E6E6\">";
			echo "<td width=\"10%\">No.</td>";
			echo "<td width=\"15%\">Prefix</td>";
			echo "<td width=\"15%\">Delete length</td>";
			echo "<td width=\"15%\">Add length</td>";
			echo "<td width=\"15%\">Add digits</td>";
			echo "<td width=\"15%\">Valid length</td>";
			echo "<td width=\"15%\" align=right><a href=\"javascript:delSelected('$flag',0,$slctNum)\" title=\"Delete all selected.\">Delete</a>";
			echo "<input type=\"checkbox\" name=\"seleceAll\" title=\"Select all to delete\"  value=\"1\" onClick=selectAllToDel('$flag',this,0,$slctNum)>";
			echo "</td>";
		echo "</tr>";
		for($i=0; $i< $convNo; $i++)
		{
			$checkBoxName=$flag . 'checkBox_'.$i;
			$deleteNo = $flag . 'deleteno_'.$i;
			echo "<tr  onMouseOver=\"this.bgColor='#D2F0FF'\" onMouseOut=\"this.bgColor='#ffffff'\">";
				echo "<td width=\"10%\"><a href=\"javascript:openSet('{$convPrefix[$i][inst_no]}','$objIdStr','$sysId','$webname','$setname','$backurl')\">{$convPrefix[$i][inst_no]}</a></td>";
		
				echo "<td width=\"15%\">{$convPrefix[$i][prefix]}&nbsp</td>";
				echo "<td width=\"15%\">{$convPrefix[$i][delLen]}&nbsp;</td>";
				echo "<td width=\"15%\">{$convPrefix[$i][addLen]}&nbsp;</td>";
				echo "<td width=\"15%\">{$convPrefix[$i][addDigs]}&nbsp;</td>";
				echo "<td width=\"15%\">{$convPrefix[$i][valiLen]}&nbsp;</td>";
				
				echo "<td width=\"15%\" align=right><input type=\"checkbox\" name=\"$checkBoxName\" value=\"0\" onClick=\"javascript:selectToDel(this)\"></td>";
				echo "<input type=\"hidden\" name=\"$deleteNo\" value=\"{$convPrefix[$i][inst_no]}\"";	
			echo "</tr>";
			if($i<$convNo-1 && $i==$showNum-1 && $$flag==0)
			{
				echo "<tr><td><a href=\"javascript:linkTo('./msc.php','$flag=1','-1')\">more >></a></td></tr>";
				break;
			}
		}
		if($$flag)
			echo "<tr><td><a href=\"javascript:linkTo('./msc.php','$flag=0','-1')\">Hide <<</a></td></tr>";
		
		echo "</table>";
		echo "</td>";
	}
	echo "</tr>";
}

/*
{//license
	echo "<tr >" ;
	echo "<td bgcolor=\"#E6E6E6\"  ><b>License control</b></td>";
	echo "<td>&nbsp;";
	    $sysId = '322_99_99';
		$oidStr = "2.6.3";
		showParameter($sysId,$oidStr,1,1,0,'','','Update');
	echo "</td>";	
	echo "</tr>";
}//end license
*/
$flag = 'deviceReset';
if(!$$flag)
	echo "<tr><td colspan=2 align=\"right\"><a href=\"javascript:linkTo('./msc.php','$flag=1','-1')\">More >></a></td></tr>";
if($$flag)
{
	echo "<tr><td bgcolor=\"#E6E6E6\"><b>System reset</b></td>";
	echo "<td><a href=\"javascript:linkTo('./msc.php','resetDevice=1','-1')\">&nbsp;Reset</td>";
	echo "</tr>";
	echo "<tr><td colspan=2 align=\"right\"><a href=\"javascript:linkTo('./msc.php','$flag=0','-1')\">Hide <<</a></td></tr>";
}

echo "<input type=\"hidden\" name=\"scroll_y\" value=\"$scroll_y\"";
echo "</form>";


{
	echo "<table width=\"100%\">";
	echo "<tr>";
		echo "<td width=\"50%\">";
			echo "&nbsp;&nbsp;";
		echo "</td>";
		echo "<td width=\"40%\" align=\"right\">";
				echo "<input type=\"submit\" title=\"$strTitleGet\" name=\"getSys\" value=\"$strGet\" class=\"button\" style=\"$buttonStyle\">";
				echo "&nbsp;&nbsp;&nbsp;";
				echo "<input type=\"submit\" title=\"$strTitleSet\" name=\"setSys\" value=\"$strSet\" class=\"button\" style=\"$buttonStyle\">";
			echo "</td>";
		echo "<td width=\"10%\">";
			echo "<p align=\"right\"><a href=\"../overview/overview.php?scroll_y=$page_top\"><img align=absBottom border=0 src=\"../../images/left.gif\" width=\"14\" height=\"14\">$strBack</a>";
		echo "</td>";
	echo "</tr>";
	echo "</table>";
}

echo "<br><br>";
?>
 
</table>
</body>
</html>
