<?php
/*********************************************************      
 程序说明：         
    功能说明：设置七号信令中的 SPC Routing
    调用关系：调用: header.inc    
              被调用:        
    变量说明：
    作者：    
修改注释：      
NO.1      
姓名： Cui Ticun         
时间：2004-4-21
修改说明：Support OMC7.0,从advanced移到configuration中，修改和添加了上方的操作按钮
*********************************************************/
require("../../inc/header.inc");
$DEBUG = 0;
if($DEBUG) echo "<br>正在调试中！！";
//==========================================================
//变量定义
//==========================================================
$nGetComm	= 0;
$nSetComm	= 3;

$nProcFaileStat	= 0;
$nWaitProcStat	= 1;
$nInProcStat	= 2;
$nProcDoneStat	= 3;

$listPageUrl="./ss7spcRoutineList.php?setObjIdStr=$objIdStr&setInstanceNo=$instanceNo";
$pubDb			= 'OMC_PUB';
$paramTable		='OBJ_222.param_99';
$sysId		='222_99_99';
//$instanceNo	='0';
$valueName	='initValue';

function getSysCommStat($commId)
{
	$DEBUG = 0;
	$pubDb = 'OMC_PUB';
	$commTable = 'parameterComm';
	
	$getSql = "SELECT commState FROM $commTable WHERE commId ='$commId'";
	$result=mysqli_query($pubConn,$getSql);
	echo mysqli_error($pubConn);
	if($result){
		$row=mysqli_fetch_array($result);
		$commState=$row[commState];
		return($commState);
	}else{
		return(-1);
	}
}

//==========================================================
//输入变量
//==========================================================
if($DEBUG) echo "<BR>sysId		=$sysId";
if($DEBUG) echo "<BR>instanceNo	=$instanceNo";
if($DEBUG) echo "<BR>objIdStr	=$objIdStr";

//==========================================================
//数据处理
//==========================================================
$NetOPLenArr=array(
	//array('oid','offset', 'name'),
	array('International network','0.0'),
	array('International network spare','0.1'),
	array('National network','0.2'),
	array('National network spare','0.3')
);

$NetOPTypeArr=array(
	//array('oid','offset', 'name'),
	array('International network type','0.4'),
	array('International network spare type','0.5'),
	array('National network type','0.6'),
	array('National network spare type','0.7')
);//roger

$NetOPCArr=array(
   //array('oid', 'name'),
   array('2.3.1', '14bit international network'),
   array('2.3.2', '14bit international network -s'), 
   array('2.3.3', '14bit national network'), 
   array('2.3.4', '14bit national network -s'), 
   array('2.3.5', '24bit international network'), 
   array('2.3.6', '24bit internation network -s'), 
   array('2.3.7', '24bit national network'), 
   array('2.3.8', '24bit national network -s')
);
$RoutingArr=array(
   array('2.6.1', 'International network'), 
   array('2.6.2', 'International network spare'), 
   array('2.6.3', 'National network'), 
   array('2.6.4', 'National network spare')
);
$RoutingConfArr=array(
   //array('remark', 'offset','inputName','valueLen'), 
   array('DPC',					'0.0-2.7','DPC','6'), 
   array('Normal linkset',		'3.0-3.7','normalLinkset','2'), 
   array('Alternative linkset', '4.0-4.7','alterLinkSet','2'),
   array('M3UA Routing Context', '5.0-8.7','M3UARoutingContext','8')
);

$ACNArr=array( 
   array('2.7.1', 'Local ACN'),
   array('2.7.2', 'International network'),
   array('2.7.3', 'International network spare'),
   array('2.7.4', 'National network'), 
   array('2.7.5', 'National network spare') 
);
$ACNConfArr=array(
	array('Network Location Update',		'0.0-0.7',	'NLU','2'), 
	array('Location Cancel',				'1.0-1.7',	'LC','2'), 
	array('Roaming Number Enquiry',			'2.0-2.7',	'RNN','2'), 
	array('Location Info Retrieval',		'3.0-3.7',	'LIR','2'), 
	array('Reset Context',					'4.0-4.7',	'RC','2'), 
	array('Handover Control',				'5.0-5.7',	'HC','2'), 
	array('Equipment Management',			'6.0-6.7',	'EM','2'), 
	array('Info Retrieval',					'7.0-7.7',	'IR','2'), 
	array('Inter VLR Info Retrieval',		'8.0-8.7',	'IVIR','2'), 
	array('Subscriber Data Management',		'9.0-9.7',	'SDM','2'), 
	array('Tracing',						'10.0-10.7','Trac','2'), 
	array('Network Functional SS',			'11.0-11.7','NFSS','2'), 
	array('Network Unstructured SS',		'12.0-12.7','NUSS','2'), 
	array('Short Message Gateway',			'13.0-13.7','SMG','2'), 
	array('Short Messsage MO Relay',		'14.0-14.7','SMMOR','2'), 
	array('Short Message Alert',			'15.0-15.7','SMA','2'), 
	array('Short Message Waiting Data Management',	'16.0-16.7','SMWDM','2'), 
	array('Mobile Terminating Short Message Relay',	'17.0-17.7','MTSMR','2'), 
	array('IMSI Retrieval',					'18.0-18.7','IMSIR','2'), 
	array('MS Purging',						'19.0-19.7','MSP','2'), 
	array('Subscriber Info Enquiry',		'20.0-20.7','SIE','2'), 
	array('Any Time Info Enquiry',			'21.0-21.7','ATIE','2'), 
	array('Call Control Transfer',			'22.0-22.7','CCT','2'), 
	array('Invocation Notification',		'23.0-23.7','IN','2'), 
	array('SIWFS Allocation',				'24.0-24.7','SA','2'), 
	array('Group Call Control',				'25.0-25.7','GCC','2'), 
	array('GPRS Location Update',			'26.0-26.7','CLU','2'), 
	array('GPRS Location Info Retrieval',	'27.0-27.7','GLIR','2'), 
	array('Failure Report',					'28.0-28.7','FR','2'), 
	array('GPRS Notify',					'29.0-29.7','GN','2'), 
	array('Reporting',						'30.0-30.7','Repo','2'), 
	array('Call Completion',				'31.0-31.7','CallComp','2'), 
	array('Security Triplets',				'32.0-32.7','ST','2'), 
	array('Subscriber Interrogate',			'33.0-33.7','SI','2'), 
	array('HLR Subscriber Management',		'34.0-34.7','HLRSM','2'), 
	array('HLR Ping AUC',					'35.0-35.7','HLRPAUC','2')
);

//==========================================================
//输出并显示数据
//==========================================================
if($DEBUG) echo "<BR>";
?>

<script LANGUAGE="JavaScript">  
function selectType(){      
	var base_url,url_add,url; 
	base_url='<?php echo "$PHP_SELF?flag=1&objIdStr=$objIdStr&length_type=";?>';
  url_add=document.setForm.length_type.options[document.setForm.length_type.selectedIndex].value;      
	url=base_url+url_add;
	window.location=url;
}    
</script>

<BR>
<body topmargin="0" leftmargin="12">
<?php
echo "<form method=\"POST\" name=\"setForm\" action=\"$PHP_SELF\">";
$tableHeader  ="<table border=\"1\" width=\"100%\" cellpadding=\"1\" cellspacing=\"0\" ";
$tableHeader .="bordercolor=\"#666666\" bordercolordark=\"#FFFFFF\">";
switch($objIdStr){
	case '2.2.0':
	case '2.2.1':
	case '2.2.2':
	case '2.2.3':
		$levelArr=explode('.',$objIdStr);
		for($j=0;$j<sizeof($levelArr);$j++){
			$levelNo=$j+1;
			${"level_$levelNo"}=$levelArr[$j];
			if($DEBUG) echo "<BR>levelArr[$j]={$levelArr[$j]}";
		}
		$getInstanceSql="SELECT initValue 
			            FROM $paramTable
						WHERE  level_1='$level_1' AND level_2='$level_2'";
		$result=mysqli_query($pubConn,$getInstanceSql);
		$row=mysqli_fetch_array($result);
		
		if($_SERVER['REQUEST_METHOD'] == "POST"){
			//sysCommSend($sysId,$nGetComm,"2.2");
			//sleep(2);
			$getInstanceSql="SELECT initValue
			            FROM $paramTable
						WHERE  level_1='$level_1' AND level_2='$level_2' ";
			$result=mysqli_query($pubConn,$getInstanceSql);
			$row=mysqli_fetch_array($result);
			$row[0]=setBitValue($row[0],$NetOPLenArr[$level_3][1],$length_type);
			$row[0]=setBitValue($row[0],$NetOPTypeArr[$level_3][1],$type_type);//roger
			echo "$row[0]";
			$setSql="UPDATE $paramTable 
			          SET initValue='$row[0]' 
				      WHERE  level_1='$level_1' AND level_2='$level_2' ";
				      
			mysqli_query($pubConn,$setSql);
			echo mysqli_error($pubConn);
	 		echo "<script LANGUAGE=\"JavaScript\">";
			echo "\n window.opener.location.href=\"$listPageUrl\";";
			echo "\n window.opener.document.setForm.focus();";
			if(!$DEBUG){
	 			echo "\n window.close();";
			} 
			echo "\n </script>";
			exit();
		}
		switch($level_3){
			case '0':
				$opcArr="International Network";
			break;
			case '1':
				$opcArr="International Spare Network";
			break;
			case '2':
				$opcArr="National Network";
			break;
			case '3':
				$opcArr="National Spare Network";
			break;
		}

		echo "<table>";
		echo "<tr width=\"100%\">";
		echo "<td><b>$opcArr</b></td>"; 
		echo "</tr>";
		echo "</table>";
		echo "<table>";
		echo "<tr>";
		echo "<td><b>Length </b></td>";

		$arr_LengthType = array("14bit","24bit");
		$arr_TypeType = array("ITU","ANSI");
		if(!$flag)
			{
				$length_type=getBitValue($row[0],$NetOPLenArr[$level_3][1]);
				$type_type=getBitValue($row[0],$NetOPTypeArr[$level_3][1]);//roger
			}
		else
			{	
				$length_type=$length_type;
				$type_type=$type_type;//roger
			};
		echo "<td>";
		echo "<select  name=\"length_type\">"; //roger
																	  //language=javascript....
																	  //not refresh itself
		for ($i=0;$i<2;$i++)
		{
			echo "<option value=\"$i\" ";
		    if ($i == $length_type)
			{
				echo "selected";
			}
		    echo ">$arr_LengthType[$i]</option>";
		}
		echo "</select>"; 
		echo "</td>";
		//roger............................................................
		echo "<td><b>Type </b></td>";
		echo "<td>";
		echo "<select  name=\"type_type\">"; 
		for ($i=0;$i<2;$i++)
		{
			echo "<option value=\"$i\" ";
		    if ($i == $type_type)
			{
				echo "selected";
			}
		    echo ">$arr_TypeType[$i]</option>";
		}
		echo "</select>"; 
		echo "</td>";
		//roger...............................................................
		echo "</tr>";
		echo "</table>";
		break;
	case '2.3.1':
	case '2.3.2':
	case '2.3.3':
	case '2.3.4':
	case '2.3.5':
	case '2.3.6':
	case '2.3.7':
	case '2.3.8':
		$levelArr=explode('.',$objIdStr);
		for($j=0;$j<sizeof($levelArr);$j++){
			$levelNo=$j+1;
			${"level_$levelNo"}=$levelArr[$j];
			if($DEBUG) echo "<BR>levelArr[$j]={$levelArr[$j]}";
		}
		$getInstanceSql="SELECT initValue 
			            FROM $paramTable
						WHERE  level_1='$level_1' AND level_2='$level_2' AND level_3='$level_3'";
		$result=mysqli_query($pubConn,$getInstanceSql);
		$row=mysqli_fetch_array($result);
		$row[0] = hexdec($row[0]);
		if($_SERVER['REQUEST_METHOD'] == "POST"){
			$opc = dechex($opc);
			//if(strlen($opc) > 6)alertmax();
			$opc=omc_keep_length($opc,"0","6","1");
			$setSql="UPDATE $paramTable 
			          SET initValue='$opc' 
				      WHERE  level_1='$level_1' AND level_2='$level_2' AND level_3='$level_3' ";
			mysqli_query($pubConn,$setSql);
	 		echo mysqli_error($pubConn);
			echo "<script LANGUAGE=\"JavaScript\">";
			echo "\n window.opener.location.href=\"$listPageUrl\";";
			echo "\n window.opener.document.setForm.focus();";
			if(!$DEBUG){
	 			echo "\n window.close();";
			} 
			echo "\n </script>";
			exit();
		}

		switch($level_3){
			case '1':
			case '5':
				$opcArr="International Network";
			break;
			case '2':
			case '6':
				$opcArr="International Spare Network";
			break;
			case '3':
			case '7':
				$opcArr="National Network";
			break;
			case '4':
			case '8':
				$opcArr="National Spare Network";
			break;
		}

		echo "<table>";
		echo "<tr width=\"100%\">";
		echo "<td><b>$opcArr</b></td>"; 
		echo "</tr>";
		echo "</table>";
		echo "<table>";
		echo "<tr>";
		echo "<td><b>OPC (dec)</b></td>"; 
		echo "<td><nobr><input type=text name=\"opc\" maxlength=\"8\" value=\"$row[0]\"  class=\"text\"></nobr> </td>";
		echo "</tr>";
		echo "</table>";
		break;
	case '2.6.1':
	case '2.6.2':
	case '2.6.3':
	case '2.6.4':
	$levelArr=explode('.',$objIdStr);
			for($j=0;$j<sizeof($levelArr);$j++){
				$levelNo=$j+1;
				${"level_$levelNo"}=$levelArr[$j];
				if($DEBUG) echo "<BR>levelArr[$j]={$levelArr[$j]}";
			}
	if($instanceNo == 'new'){
		$RoutValue="000000808000000000";
	}else{
		$getSql="SELECT $valueName
		        FROM $paramTable 
				WHERE level_1='$level_1' AND level_2='$level_2' AND level_3='$level_3' AND instanceNo='$instanceNo'
			";
	    if($DEBUG) echo "<BR>getSql=$getSql";
	    $result	=mysqli_query($pubConn,$getSql);
		$rows= mysqli_fetch_array($result);
		$RoutValue=$rows[0];
	}
	if($DEBUG) echo "<BR>RoutValue=$RoutValue";
	if($DEBUG) echo "<BR>";
	if($_SERVER['REQUEST_METHOD'] == "POST"){	
		//保存改动
		$newRoutValue=$RoutValue;
		for($i=0;$i<sizeof($RoutingConfArr);$i++){
			$unitName=$RoutingConfArr[$i][2];
			$unitValue=${$unitName};
			$unitValue = dechex($unitValue);//roger
			$unitValue=omc_keep_length($unitValue,"0",$RoutingConfArr[$i][3],"1");
			//if($DEBUG) 
			echo "<BR>$unitName=$unitValue";
			$newRoutValue=setBitValue($newRoutValue,$RoutingConfArr[$i][1],$unitValue);
			//if($DEBUG) 
			echo "<BR>newRoutValue=$newRoutValue";
		}

        $moveSql="UPDATE $paramTable SET initValue ='$newRoutValue'
		        WHERE level_1='$level_1' AND level_2='$level_2' AND level_3='$level_3' AND instanceNo='$instanceNo'
			";
	    if($DEBUG) echo "<BR>getSql=$getSql";
	    mysqli_query($pubConn,$moveSql);
		echo "<script LANGUAGE=\"JavaScript\">";
		echo "\n window.opener.location.href=\"$listPageUrl\";";
		echo "\n window.opener.document.setForm.focus();";
		if(!$DEBUG){
			echo "\n window.close();";
		} 
		echo "\n </script>";
		exit();
	}else{
		//显示
		echo "\n $tableHeader";
		echo "\n <tr bgcolor=\"#E6E6E6\">";
		echo "<td>Name</td><td>Value</td>";
		echo "</tr>";
		if($instanceNo == 'new'){
			$getInstanceSql="SELECT instanceNo FROM $paramTable
							WHERE  level_1='$level_1' AND level_2='$level_2' AND level_3='$level_3'AND $valueName = '000000808000000000'";
			$result=mysqli_query($pubConn,$getInstanceSql);
			echo mysqli_error($pubConn);
			echo "<td>No.</td><td>";
			if($DEBUG) echo "<br>$getInstanceSql";
			echo "<select name=\"instanceNo\" size=\"1\">";
			while($row=mysqli_fetch_array($result)){
				echo "<option value=$row[instanceNo]>$row[instanceNo]</option>";
			}
			echo"</select>";
			echo"</td>";
		}

		for($i=0;$i<sizeof($RoutingConfArr);$i++){
			$unitShowName=$RoutingConfArr[$i][0];
			$unitValue=getBitValue($RoutValue,$RoutingConfArr[$i][1]);
			$unitValue = hexdec($unitValue);//roger

			if($DEBUG) echo "<br>unitValue=$unitValue";
			$unitInputName=$RoutingConfArr[$i][2];
			$unitLen=$RoutingConfArr[$i][3]+1;//roger
			if($DEBUG) 
			echo "<br>unitLen=$unitLen";
			echo "\n <tr>";
			echo "<td>$unitShowName</td>";
			if($i==0){
				echo "<td><input type=text name=\"$unitInputName\" maxlength=\"8\" value=\"$unitValue\"  class=\"text\">";//roger
			}else{
				echo "<td><input type=text name=\"$unitInputName\" maxlength=\"$unitLen\" value=\"$unitValue\"  class=\"text\">";
			}
			echo "&nbsp&nbsp(DEC)</td>";
			echo "</tr>";
		}
	}
		break;
	case '2.7.1':
	case '2.7.2':
	case '2.7.3':
	case '2.7.4':
	case '2.7.5':
		$levelArr=explode('.',$objIdStr);
		for($j=0;$j<sizeof($levelArr);$j++){
			$levelNo=$j+1;
			${"level_$levelNo"}=$levelArr[$j];
			if($DEBUG) echo "<BR>levelArr[$j]={$levelArr[$j]}";
		}
		$acnValue=getSysParamValue($sysId,$objIdStr,$instanceNo,$valueName);
		if($_SERVER['REQUEST_METHOD'] == "POST"){	
			//保存改动
			$newRoutValue=$acnValue;
			for($i=0;$i<sizeof($ACNConfArr);$i++){
				$unitName=$ACNConfArr[$i][2];
				$unitValue=${$unitName};
				$unitValue = dechex($unitValue);//roger
				$unitValue=omc_keep_length($unitValue,"0",$ACNConfArr[$i][3],"1");
				if($DEBUG) echo "<BR>$unitName=$unitValue";
				$newRoutValue=setBitValue($newRoutValue,$ACNConfArr[$i][1],$unitValue);
				if($DEBUG) echo "<BR>newRoutValue=$newRoutValue";
			}
			
			$moveSql="UPDATE $paramTable SET initValue ='$newRoutValue'
		        WHERE level_1='$level_1' AND level_2='$level_2' AND level_3='$level_3' AND instanceNo='$instanceNo'
			";
			if($DEBUG) echo "<BR>getSql=$getSql";
			mysqli_query($pubConn,$moveSql);
			
			echo "<script LANGUAGE=\"JavaScript\">";
			echo "\n window.opener.location.href=\"$listPageUrl\";";
			if(!$DEBUG){
				echo "\n window.close();";
			} 
			echo "\n </script>";
			exit();
		}else{
			//显示
			echo "\n $tableHeader";
			echo "\n <tr bgcolor=\"#E6E6E6\">";
			echo "<td>Operation</td><td>Suggested version</td>";
			echo "</tr>";
			for($i=0;$i<sizeof($ACNConfArr);$i++){
				$unitShowName=$ACNConfArr[$i][0];
				$unitValue=getBitValue($acnValue,$ACNConfArr[$i][1]);
				$unitValue = hexdec($unitValue);//roger
				$unitInputName=$ACNConfArr[$i][2];
				$unitLen=$ACNConfArr[$i][3]+1;
				echo "\n <tr>";
				echo "<td>$unitShowName</td>";
				echo "<td><input type=text name=\"$unitInputName\" maxlength=\"$unitLen\" value=\"$unitValue\" class=\"text\"></td>";
				echo "</tr>";
			}
		}
		break;
}
echo "\n </table>";


echo "\n <input type=\"hidden\" name=\"objIdStr\" value=\"$objIdStr\">";
if($instanceNo != 'new'){
	echo "\n <input type=\"hidden\" name=\"instanceNo\" value=\"$instanceNo\">";
}
echo "\n <input type=\"submit\" name=\"set\" value=\"Set\">&nbsp;&nbsp;";
echo "\n <input type=\"reset\" name=\"reset\" value=\"Reset\">";
/*
DPC: Destination point code of the MSC using this OPC<br><br>
Normal linkset: Linkset assigned to the link connected to the device using this DPC<br><br>
Alternative linkset: Alternative linkset of the normal linkset<br><br>
The ACN facility enables the version negotiation for the above messages, which make the WXC2 System more compatible with the other networks by means of flexible message version adjustment. The adjustable version includes Version 1, Version 2 and Version 3 
*/
?>

</form>
<b>Remarks:</b><br><br>
DPC: Specify a Destination Point Code to this route.<br><br>
Normal linkset: Assign a primary linkset to this route.<br><br>
Alternative linkset: Assign an alternative linkset to this route when the normal linkset becomes unavailable.<br><br>
M3UA Routing Context: For M3UA use only. Specify the M3UA Routing Context used by M3UA peers to identify a particular application server.
</body>
</html>