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

//************
$url_temp=$_SERVER["REQUEST_URI"];
//echo "This page URL:$url_temp<br>";
?>
<script language="JavaScript">
function openSet(instanceNo,objIdStr,sysId,webname,setname,backurl)
	{
		var tmpSetname;
		tmpSetname = setname;
		setname=escape(setname);
		webname=escape(webname);
		
		
		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 clickOnMoreHide(where,num,oper)
	{
		var cmd;
		//to change the more button to hide button or reverse
		if(oper=='show')
		{
			cmd="document.all.show"+where+".style.display='none'";
			eval(cmd);
			cmd="document.all.hide"+where+".style.display='block'";
			eval(cmd);
				
			for(var i=4;i<num;i++)
			{
				cmd="document.all."+where+i+".style.display='block'";
				eval(cmd);
			}
			
		}
		else
		{
			cmd="document.all.show"+where+".style.display='block'";
			eval(cmd);
			cmd="document.all.hide"+where+".style.display='none'";
			eval(cmd);
			
			for(var i=4;i<num;i++)
			{
				cmd="document.all."+where+i+".style.display='none'";
				eval(cmd);
			}
			
		}
		
	}
function selectAll(prefix_count)
	{
		
		
		if(document.all.select_all.checked==0)
		{
			document.all.select_all.checked=0;
			for(var i=0;i<prefix_count;i++)
			{
				var cmd='document.all.cb'+i+'.checked=0';
				eval(cmd);
			}
		}
		else
		{
			document.all.select_all.checked=1;
			for(var i=0;i<prefix_count;i++)
			{
				var cmd='document.all.cb'+i+'.checked=1';
				eval(cmd);
			}
		}
		
	}			
function delSelect(element_no)
	{

		//=========confirm=====
		
		//===get the select no======
		var select_no=0;
		var instanceNo_str="";
		for(var i=0;i<element_no;i++)
		{
			var cmd='document.all.cb'+i+'.checked';
			if(eval(cmd)==1)
			{
				cmd='document.all.cb'+i+'.value';
				instanceNo_str+=eval(cmd)+".";
				//alert(eval(cmd));
				select_no++;
			}
		}
		if(select_no==0)
		{
			alert("Select elements,first!");
			return;
		}	
		var re=confirm("Do you want to delete the selected");
		if(re==0)
			return;
		//alert(instanceNo_str);
		
		window.location.href="./eir.php?license=$licenese&users=$users&del_count="+select_no+"&instanceNo_str="+instanceNo_str+"&del=1";
		
		
	}	
</script>
<body topmargin="0" leftmargin="12">

<?php
if($del==1)
{
	//======get the default value of white list number========
	$database="OBJ_380";
	$sql="select initValue from paramConf where level_1=2 and level_2=1 and level_3=2 ";
	$result=@mysqli_query($pubConn,$sql);
	$rows=@mysqli_fetch_array($result);
	$white_list_number_default_value=$rows[initValue];
	//====================get the delete local prefix instanceNo=============
	$white_list_number_instanceNo_tmp=explode(".",$instanceNo_str);
	for($i=0;$i<$del_count;$i++)
	{
		//echo "{$local_prefix_instanceNo_tmp[$i]}<br>";
		//===============delete the local prefix by instanceNo==========
		$database="OMC_PUB";		
		$setsql = "update OBJ_380.param_99 set initValue='$white_list_number_default_value'	where level_1=2 and level_2=1 and level_3=2 and instanceNo={$white_list_number_instanceNo_tmp[$i]} ";
		if($DEBUG) 
			echo "setsql=$setsql<br>";	
		
		mysqli_query($pubConn,$setsql);
		echo mysqli_error($pubConn);
	}
	
	
	echo "\n<script language=\"JavaScript\">\n";
	echo "window.location.href='./eir.php?license=$license&users=$users';\n";
	echo "</script>\n";
}

$sysId	= '380_99_99';

$sqltable_sccp = 'OBJ_223.param_99';
$sysStatTable='OMC_PUB.sysStat';
$sqltable = 'OBJ_380.param_99';
$pubDb = 'OMC_PUB';
$sysinfo = 'OMC_PUB.sysInfo';
$sysTypeNo = '322';

$mtp3_sqlTable = 'OBJ_222.param_99';

$sysId_arr = array(
	//array('222_99_99',array('2.2','2.3'),'mtp3'),
	//array('223_99_99',array("2.1.9"),'sccp'),
	array('oid'=>'2.1.9','sysid'=>'223_99_99', 'selectsysid'=>'-1'),
	array('oid'=>'2.1.2','sysid'=>'380_99_99', 'selectsysid'=>'-1')
);
$NI_arr=array('International','International spare','National','National spare');
$SaveArr=array(
	//array('oidstr'=>'2.2.2',	'setvalue'=>'01'	,'sysid'=>'380_99_99'),
	array('oidstr'=>'3.2',	'setvalue'=>'02'	,'sysid'=>'223_99_99')				
);	
$backurl = "./eir.php";
//loading
if($load_flag == 1)
{
	echo "<br>Loading";
	
	GetParam($sysId_arr,1);//1 means return to overview if getting parameters fails.
			
	echo "<script LANGUAGE=\"JavaScript\">";
	if(!$DEBUG){
		echo "\n window.location.href=\"./eir.php\";";
	} 
	else exit();
	echo "\n </script>";
}

if(isset($doingOtherFlag))
{
	{//get 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'));
		
		$sysId = "223_99_99";
	}//end get system ip

	if($setEirGtt==1)
	{
		//scf_map
		$oidStr = "2.1.9";
		setParamValue($mss_ip[0],$sysId,$oidStr,3);
		setParamValue($mss_ip[1],$sysId,$oidStr,4);
	}
	
	exit;
}			
if($_SERVER['REQUEST_METHOD'] == "POST")
{
	if(isset($setSys) || isset($getSys))
	{
		if(isset($setSys))
		{
//			echo "<br>Getting parameters<br>";
//			GetParam(0,1);
						
			echo "<br>Setting parameters<br>";
			SetParam($sysId_arr);	
			session_register("acSetFlag");
						
			$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_arr);
			$showType="Get";
		}
	}
	
	echo "<script LANGUAGE=\"JavaScript\">";
	if(!$DEBUG)
		echo "\n window.location.href=\"./eir.php?license=$license&users=$users\";";
	echo "\n </script>";	
	exit();	
}	
																								
//==========================================================
//输出并显示数据
//========================================================== 
echo "<form method=\"POST\" name=\"Set\" action=\"$PHP_SELF\">";

?>

<?php
echo "<table border=\"0\" width=\"100%\">";
echo "<tr>";
echo "<td width=\"50%\">";
echo "Configuration > <a href=\"../overview/overview.php\">Network</a> > <a href=\"#\">EIR</a>";
echo "<td width=\"50%\" align=\"right\" title=\"Help\">";
$helpId = '2.1.1.7';
//showHelp($helpId);
echo "</td>";
echo "</tr>";
echo "</table>";
echo "<br>";

{
	echo "<table width=\"100%\">";
	echo "<tr>";
		echo "<td width=\"70%\">&nbsp";
			//echo "<b>Equipment Identity Register:&nbsp;&nbsp;</b>";
		echo "</td>";
		echo "<td width=\"20%\" align=\"right\">";
				echo "<input type=\"submit\" title=\"$strTitleGet\" name=\"getSys\" value=\"$strGet\" class=\"button\" style=\"cursor:pointer; left: 1; top: 2; width: 60; height: 25; position: relative\">";
				echo "&nbsp;&nbsp;&nbsp;";
				echo "<input type=\"submit\" title=\"$strTitleSet\" name=\"setSys\" value=\"$strSet\" class=\"button\" style=\"cursor:pointer; left: 1; top: 2; width: 60; height: 25; position: relative\">";
			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  width=100%   border="1"  cellpadding="1" cellspacing="0"  bordercolor="#666666" bordercolordark="#FFFFFF" bgcolor="#FFFFFF"> 
<?php

//==========================================================
//输出Signaling point
//========================================================== 
{
	$spcTree_array = array(
	array('INT',				'14-bit',	'spc_int_14',	 '2.3.1'),
	array('INT-S',				'14-bit',	'spc_int_sp_14', '2.3.2'),
	array('NAT',				'14-bit',	'spc_nat_14',	 '2.3.3'),
	array('NAT-S',				'14-bit',	'spc_nat_sp_14', '2.3.4'),
	array('International',		'24-bit',	'spc_int_24',	 '2.3.5'),
	array('International spare','24-bit',	'spc_int_sp_24', '2.3.6'),
	array('National',			'24-bit',	'spc_nat_24',	 '2.3.7'),
	array('National spare',		'24-bit',	'spc_nat_sp_24', '2.3.8')
	);
		
	$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;					
	}
		
	for($i = 0; $i < 4; $i ++)
	{
		$levelWhere = getLevelWhere($spcTree_array[$spc_index[$i]][3]);
		
		$getsql = "select initValue from $mtp3_sqlTable where $levelWhere";
		$result = mysqli_query($pubConn,$getsql);
		$row[$i] = mysqli_fetch_array($result);
		$row[$i] = hexdec($row[$i][0]);
		if($DEBUG)echo "getsql = $getsql<br>";
		if($DEBUG)echo "spc_$i=$row[$i]<br>";
	}
}

echo "<tr>" ;
echo "<td width=\"20%\" bgcolor=\"#E6E6E6\"><b>Signaling point code</b></td>";
echo "<td><table width=100%><tr>";
for($i=0; $i<4; $i++)
	echo "<td  width=\"25%\" align=\"left\">{$spcTree_array[$i][0]}&nbsp;:&nbsp;{$spcTree_array[$spc_index[$i]][1]}&nbsp;:&nbsp;$row[$i]</td>";
echo "</tr></table></td>";
echo "</tr>";

{//gtt
	echo "<tr>";
	echo "<td bgcolor=\"#E6E6E6\" ><b>$strE164Number</b></td><td><table width=\"100%\">";
	$sysId = "223_99_99";
	$oidStr = "2.1.9";
	$instanceNo=0;
	echo "<td align=\"left\" width=50% >";
	$doingOtherUlr="$PHP_SELF?doingOtherFlag=1&setEirGtt=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>";
}//end gtt	

/*
{//license
		echo "<tr >" ;
		echo "<td bgcolor=\"#E6E6E6\"  ><b>License control</b></td>";
		echo "<td>&nbsp;";
	    	$sysIdd = '380_99_99';
			$oidStrr = "2.2.4";
			//showParameter($sysIdd,$oidStrr,1,1,0,'','','Update');
			showParameter($sysIdd,$oidStrr,1,1,0,'','','Update');
		echo "</td>";	
		echo "</tr>";
}//end license
*/

//==================white list numbers===================
{
	//===========get the default value==
	$database="OBJ_380";
	$sql="select initValue from paramConf where level_1=2 and level_2=1 and level_3=2 ";
	$result=@mysqli_query($pubConn,$sql);
	$rows=@mysqli_fetch_array($result);
	$white_list_number_default_value=$rows[initValue];
	
	//====set every record to the default value============
	/*
	$updSql = "UPDATE param_99 SET initValue = '$white_list_number_default_value'   
				WHERE level_1=2 and level_2=1 and level_3=2
				";
		mysqli_query($pubConn,$updSql);	
		echo mysqli_error($pubConn);
	*/
	//===================================================
	
	//===================get the count of white list numbers========================
	$database="OBJ_380";
	$sql="select instanceNo,initValue from param_99 where level_1=2 and level_2=1 and level_3=2 ";
	$result=@mysqli_query($pubConn,$sql);
	$rows=@mysqli_fetch_array($result);
	$white_list_number_count=0;
	
	do{
		
		$initValue_tmp=$rows[initValue];
		if(strcmp($initValue_tmp,$white_list_number_default_value)!=0)
		{
			$white_list_number_instanceNo[$white_list_number_count]=$rows[instanceNo];
			$start_type[$white_list_number_count]=getBitValue($rows[initValue],'0.0-2.7');
			$end_type[$white_list_number_count]=getBitValue($rows[initValue],'8.0-10.7');
			$start_final[$white_list_number_count]=getBitValue($rows[initValue],'3.0-3.7');
			$end_final[$white_list_number_count]=getBitValue($rows[initValue],'11.0-11.7');
			$start_serial[$white_list_number_count]=getBitValue($rows[initValue],'4.0-6.7');
			$end_serial[$white_list_number_count]=getBitValue($rows[initValue],'12.0-14.7');
			$start_software[$white_list_number_count]=getBitValue($rows[initValue],'7.0-7.7');
			$end_software[$white_list_number_count]=getBitValue($rows[initValue],'15.0-15.7');
			
			$white_list_number_count++;
			
		}
			
	}while($rows=mysqli_fetch_array($result));
	
	//====================get the unused instanceNo of local prefix====
	$database="OBJ_380";
	$sql="select instanceNo,initValue from param_99 where level_1=2 and level_2=1 and level_3=2 ";
	$result=@mysqli_query($pubConn,$sql);
	$rows=@mysqli_fetch_array($result);
	do{
		
		$initValue_tmp=$rows[initValue];
		if(strcmp($initValue_tmp,$white_list_number_default_value)==0)
		{		
			$unused_white_list_number_instanceNo=$rows[instanceNo];
			break;
		}
	}while($rows=mysqli_fetch_array($result));
	
	
	//=======show the white list number

	
	echo "<tr>";
	echo "<td bgcolor=\"#E6E6E6\"><nobr><b>White List Number</b></nobr>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp";
		echo "<a href=\"javascript:openSet('$unused_white_list_number_instanceNo','no-2.1.2','380_99_99','EIR','white_list_number','$url_temp')\"><font size=4>+</font></a>";
	echo "</td>";
	echo "<td>";
		echo "<table width=\"100%\" cellspacing=0 cellpadding=0>";
			if($white_list_number_count==0)
			{
				echo "<tr style=\"display:none\" bgcolor=\"#E6E6E6\"><td>No.</td><td>Start IMEI Type Approval Code</td><td>Start IMEI Final Assembly Code</td><td align=\"right\"><a href=\"#\">Delete</a>";
				echo "<input type=checkbox id=\"select_all\"></td>";
				echo "</tr>";
			}
			else
			{
				echo "<tr bgcolor=\"#E6E6E6\"><td width=10%>No.</td><td>Start IMEI Type Approval Code</td><td>End IMEI Type Approval Code</td><td align=\"right\"><a href=\"javascript:delSelect('$white_list_number_count')\">Delete</a>";
				echo "<input type=checkbox id=\"select_all\" onClick=\"javascript:selectAll('$white_list_number_count')\"></td>";		
				echo "</tr>";
			}
			if($white_list_number_count==0)
			{
				echo "<tr><td>--</td></tr>";
			}
			else
			{
				for($i=0;$i<$white_list_number_count;$i++)
				{
					if($i>3)
						echo "<tr id=\"white_list_number$i\" style=\"display:none\">";
					else						
						echo "<tr id=\"white_list_number$i\">";
						//=====white list number instanceNo===
						echo "<td><a href=\"javascript:openSet('{$white_list_number_instanceNo[$i]}','no-2.1.2','380_99_99','EIR','white_list_number','$url_temp')\">{$white_list_number_instanceNo[$i]}</a></td>";
						//=====start type =============
						echo "<td>{$start_type[$i]}</td>";
						//=====end type =============
						echo "<td>{$end_type[$i]}</td>";
						//======delete select box=========
						echo "<td align=\"right\"><input type=\"checkbox\" id='cb$i' value='{$white_list_number_instanceNo[$i]}'></td>";
					echo "</tr>";
				}
				//======more and hide button================
				if($white_list_number_count>4)
				{
					echo "<tr id='showwhite_list_number' style=\"display:block\"><td><a href=\"javascript:clickOnMoreHide('white_list_number',$white_list_number_count,'show')\">More >></a></td></tr>"; 
					echo "<tr id='hidewhite_list_number' style=\"display:none\"><td><a href=\"javascript:clickOnMoreHide('white_list_number',$white_list_number_count,'hide')\">Hide >></a></td></tr>"; 
			
				}
			
			}
		echo "</table>";
	echo "</td>";
	
}



echo "</table>";


?>

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