<?php
require("../sub_inc/commfunc.php");
$DEBUG = 0;
if($DEBUG) echo "<br>正在调试中！！";
?>
<script LANGUAGE="JavaScript">       
function delFirm(No)
{
	var delValue,x,y;
	x = document.body.scrollLeft;
	y = document.body.scrollTop;
    
	if(confirm('Do you want to delete the selected?') != true)
		window.location.href='<?php echo $PHP_SELF;?>';
	else
		window.location.href='<?php echo $PHP_SELF;?>?&delValue='+No+'&delflag=1';
}
</script>

<body topmargin="0" leftmargin="12">

<?php

$helpID = "1.1.1";

$nProcFail = 0;//failure
$nWaitProc = 1;//wait
$nInProc   = 2;
$nOutProc  = 3;

$nGetComm = 0;
$nSetComm = 3;
	
$maxNum = 120;

$sysId	= '350_99_99';
$oidarr	= array('2.2.0');

$smpp_id	= '260_99_99';
$smpp_oid	= array('2.1.0');

/*
$sysId_arr = array(
	array('350_99_99',array('2.2.0'),'xx'),
	array('260_99_99',array('2.1.0'),'smpp'),
);
*/

$sysId_arr=array(
	array('oid'=>'2.2.0',		'sysid'=> '350_99_99',		'selectsysid'=>'-1'), 										
	array('oid'=>'2.1.0',		'sysid'=> '260_99_99',		'selectsysid'=>'-1'),
);

$SaveArr=array(
	array('oidstr'=>'3.3',	'setvalue'=>'01'	,'sysid'=>'350_99_99'),
	array('oidstr'=>'3.2',	'setvalue'=>'02'	,'sysid'=>'260_99_99')				
);	

$smpp_sqltable = 'OBJ_260.param_99';
$smsc_sqltable = 'OBJ_350.param_99';
$pubdb = 'OMC_PUB';

$curr_page = './smpp_detail.php';

$smpp_array = array(
	array('Link type',				'1.0-1.7'),
	array('Connection type',		'2.0-2.7'),
	array('Session type',			'3.0-3.7'),
	array('System ID',				'4.0-19.7'),
	array('Password',				'20.0-28.7'),
	array('Local GTT ',				'42.0-57.7'),
	array('Remote GTT',				'58.0-73.7'),
	array('Local IP',				'74.0-77.7'),
	array('Remote IP',				'78.0-81.7'),
	array('Session timer',			'82.0-85.7'),
	array('Enquire link timer',		'86.0-89.7'),
	array('Inactivity timer',		'90.0-93.7'),
	array('Response timer',			'94.0-97.7'),
	array('Opposite service number','98.0-105.7'),
	array('flag',					'0.0-0.7')
);
$smsc_array = array(
	array('flag',				'00.0-00.7'),
	array('Session type',		'01.0-01.7'),
	array('Service number',		'02.0-09.7'),
	array('Message mode',		'10.0-10.7'),
	array('Data Coding Scheme',	'11.0-11.7')
);

if($_SERVER['REQUEST_METHOD'] == "POST")
{	
	if(isset($setSys) || isset($getSys))
	{
		if(isset($setSys))
		{
			//echo "<br>Getting parameters<br>";
			//GetParam($sysId_arr);
						
			echo "<br>Setting parameters<br>";
			SetParam($sysId_arr);	
			session_register("SetFlag");
						
			$showType="Set";
			echo "<br>Sending save command<br>";
			SaveParam($SaveArr);
		}
		else
		{ 
			echo "<br>Getting parameters<br>";
			session_register("GetFlag");
			GetParam($sysId_arr);
			$showType="Get";
		}
	}
	/*
	elseif(isset($undoSet))
	{		
		echo "<br>Setting parameters<br>";
		SetParam(1);
	}
	*/
	if($setSys || $getSys  || $undoSet)
	{
		echo "<script LANGUAGE=\"JavaScript\">";
		if(!$DEBUG)
			echo "\n window.location.href=\"$PHP_SELF\";";
		echo "\n </script>";	
		exit();
	}	 
	
}	

if($delflag == 1)
{
	$setsql = "select initValue from $smpp_sqltable 
	WHERE level_1='2' AND level_2='1' AND level_3='0' and instanceNo='$delValue' ";
	$result = mysqli_query($pubConn,$setsql);
	echo mysqli_error($pubConn);
	if($DEBUG) echo "<br>$setsql<br>";	
	$smpp_del = mysqli_fetch_array($result);
	$session_type = getBitValue($smpp_del[0],'3.0-3.7');
	$opposite_num = getBitValue($smpp_del[0],'98.0-105.7');
		
	$setsql = "select initValue from $smsc_sqltable 
		WHERE level_1='2' AND level_2='2' AND level_3='0' ";
	$result = mysqli_query($pubConn,$setsql);
	echo mysqli_error($pubConn);
	if($DEBUG) echo "<br>$setsql<br>";	
	
	$smsc_ins = 0;
	while($smsc_row = mysqli_fetch_array($result))
	{
		$smsc_session_type = getBitValue($smsc_row[0],'01.0-01.7');	
		$smsc_opposite_num = getBitValue($smsc_row[0],'02.0-9.7');	
		if($smsc_session_type == $session_type && $smsc_opposite_num == $opposite_num)
			break;
		$smsc_ins++;
	}
	
	$initValue = omc_keep_length($initValue,'0','24');
	$setsql = "update $smsc_sqltable set initValue = '$initValue'
		where level_1 = '2' and level_2 = '2' and level_3 = '0' and instanceNo = '$smsc_ins' ";
	mysqli_query($pubConn,$setsql);
	echo mysqli_error($pubConn);
	if($DEBUG) echo "<br>$setsql<br>";
	
	$initValue = omc_keep_length($initValue,'0','212');
	$setsql = "update $smpp_sqltable set initValue = '$initValue'
		where level_1 = '2' and level_2 = '1' and level_3 = '0' and instanceNo = '$delValue' ";
	mysqli_query($pubConn,$setsql);
	echo mysqli_error($pubConn);
	if($DEBUG) echo "<br>$setsql<br>";
}

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

//==========================================================
//取数据库数据
//========================================================== 
$levelArr=explode('.',$smpp_oid[0]);
for($j=0;$j<sizeof($levelArr);$j++)
{
	$levelNo=$j+1;
	${"level_$levelNo"}=$levelArr[$j];
	//if($DEBUG) echo "<BR>levelArr[$j]={$levelArr[$j]}";
}
	
$setsql = "select initValue from $smpp_sqltable 
	WHERE level_1='$level_1' AND level_2='$level_2' AND level_3='$level_3'";
$result = mysqli_query($pubConn,$setsql);
echo mysqli_error($pubConn);
if($DEBUG) echo "<br>$setsql<br>";

$i = 0;
$n = 0;
while($smpp_row = mysqli_fetch_array($result))
{
	$enable_flag = getBitValue($smpp_row[0],$smpp_array[14][1]);	
	if ($DEBUG)echo "<br>smpp_row = $smpp_row[0] <br>";
	if($enable_flag == 0)
	{
		$i++;
		continue;
	}
	$link_type[$n]		= getBitValue($smpp_row[0],$smpp_array[0][1]);
	$connect_type[$n] 	= getBitValue($smpp_row[0],$smpp_array[1][1]);
	$session_type[$n]	= getBitValue($smpp_row[0],$smpp_array[2][1]);
	$system_id[$n] 		= toAscii(getBitValue($smpp_row[0],$smpp_array[3][1]));
	$password[$n] 		= toAscii(getBitValue($smpp_row[0],$smpp_array[4][1]));
	$local_gtt[$n] 		= toAscii(getBitValue($smpp_row[0],$smpp_array[5][1]));
	$remote_gtt[$n]		= toAscii(getBitValue($smpp_row[0],$smpp_array[6][1]));
	$local_ip[$n] 		= getBitValue($smpp_row[0],$smpp_array[7][1]);
	$remote_ip[$n]	 	= getBitValue($smpp_row[0],$smpp_array[8][1]);
	$session_timer[$n]	= hexdec(getBitValue($smpp_row[0],$smpp_array[9][1]));
	$enquire_timer[$n] 	= hexdec(getBitValue($smpp_row[0],$smpp_array[10][1]));
	$inact_timer[$n] 	= hexdec(getBitValue($smpp_row[0],$smpp_array[11][1]));
	$response_timer[$n] = hexdec(getBitValue($smpp_row[0],$smpp_array[12][1]));
	$opposite_num[$n] 	= toAscii(getBitValue($smpp_row[0],$smpp_array[13][1]));
	$ins_no[$n]			= $i;

	if($DEBUG)
	{
		echo "SMPP:<br>";
		echo "link_type=$link_type[$n]<br>";
		echo "connect_type=$connect_type[$n]<br>";
		echo "session_type=$session_type[$n]<br>";
		echo "system_id=$system_id[$n]<br>";	
		echo "password=$password[$n]<br>";
		echo "local_gtt=$local_gtt[$n]<br>";
		echo "remote_gtt=$remote_gtt[$n]<br>";
		echo "local_ip=$local_ip[$n]<br>";
		echo "remote_ip=$remote_ip[$n]<br>";
		echo "session_timer=$session_timer[$n]<br>";
		echo "enquire_timer=$enquire_timer[$n]<br>";
		echo "inact_timer=$inact_timer[$n]<br>";
		echo "response_timer=$response_timer[$n]<br>";
		echo "opposite_num=$opposite_num[$n]<br>";		
	}
	$levelArr=explode('.',$smsc_oid[0]);
	for($j=0;$j<sizeof($levelArr);$j++)
	{
		$levelNo=$j+1;
		${"level_$levelNo"}=$levelArr[$j];
		//if($DEBUG) echo "<BR>levelArr[$j]={$levelArr[$j]}";
	}
	$setsql = "select initValue from $smsc_sqltable 
		WHERE level_1='$level_1' AND level_2='$level_2' AND level_3='$level_3' ";
	$smsc_result = mysqli_query($pubConn,$setsql);
	echo mysqli_error($pubConn);
	if($DEBUG) echo "$setsql<br>";	
	
	$smsc_ins = 0;
	while($smsc_row = mysqli_fetch_array($smsc_result))
	{
		$smsc_session_type = getBitValue($smsc_row[0],$smsc_array[1][1]);	
		$smsc_opposite_num = toAscii(getBitValue($smsc_row[0],$smsc_array[2][1]));	
		if($smsc_session_type == $session_type[$n] && $smsc_opposite_num == $opposite_num[$n])
		{
			$smsc_dcs[$n] = getBitValue($smsc_row[0],$smsc_array[4][1]);
			break;
		}
		$smsc_ins++;
	}
	if($DEBUG) echo "dcs=$smsc_dcs[$n]<br>";
	
	$n++;
	$i++;
}
//==========================================================
//输出并显示数据
//========================================================== 
echo "<form method=\"POST\" name=\"Set\" action=\"$PHP_SELF\">";

echo "<input type=\"hidden\" name=\"back_page\" value=\"$back_page\">";
?>

<?php
echo "<table border=\"0\" width=\"100%\">";
echo "<tr>";
echo "<td width=\"50%\">";
echo "Configuration > Network > Element > SMSC";
echo "<td width=\"50%\" align=\"right\" title=\"Help\">";
showHelp($helpId);
echo "</td>";
echo "</tr>";
echo "</table>";
echo "<br>";

echo "<table width=\"100%\">";
echo "<tr><td>";
echo "<b>SMPP link:&nbsp;&nbsp;</b>";
echo "<input type=\"submit\" name=\"getSys\" value=\"$strGet\" class=\"button\" style=\"left: 1; top: 2; width: 60; height: 25; position: relative\">";
echo "<input type=\"submit\" name=\"setSys\" value=\"$strSet\" class=\"button\" style=\"left: 1; top: 2; width: 60; height: 25; position: relative\">";
if ( TRUE == session_is_registered("SetFlag") ) 
{
	echo "<input type=\"submit\" name=\"undoSet\" value=\"$strUndo\" class=\"button\"  style=\"left: 1; top: 2; width: 60; height: 25; position: relative\">";
}
else
{
	echo "<input type=\"submit\" name=\"undoSet\" value=\"$strUndo\" DISABLED class=\"button\"  style=\"left: 1; top: 2; width: 60; height: 25; position: relative\">";
}
echo "</td>";
echo "<td><a href=\"./smpp_edit.php?instanceNo=New&back_page=$curr_page\"><b>Add</b></td>";
echo "<td>";
echo "<p align=\"right\"><a href=\"./smsc.php\"><img align=absBottom border=0 src=\"../../images/left.gif\" width=\"14\" height=\"14\">$strBack</a>";
echo "</td></tr>";
echo "</table>";
?>

<TABLE  width=100%   border="1"  cellpadding="1" cellspacing="0"  bordercolor="#666666" bordercolordark="#FFFFFF" bgcolor="#FFFFFF"> 
<?php
echo "<tr bgcolor=\"#E6E6E6\">";
echo "<td align=\"middle\">No.</td>";
echo "<td align=\"middle\">Link type</td>";
echo "<td align=\"middle\">Connection type</td>";
echo "<td align=\"middle\">System ID</td>";
echo "<td align=\"middle\">Password</td>";
echo "<td align=\"middle\">DCS</td>";
echo "<td align=\"middle\">Service number</td>";
echo "<td align=\"middle\">Local GTT</td>";
echo "<td align=\"middle\">Opposite GTT</td>";
echo "<td align=\"middle\">Local IP</td>";
echo "<td align=\"middle\">Opposite IP </td>";
echo "<td align=\"middle\">Session init timer</td>";
echo "<td align=\"middle\">Enquire link timer</td>";
echo "<td align=\"middle\">Inactivity timer</td>";
echo "<td align=\"middle\">Response timer</td>";
echo "<td align=\"middle\">Del</td>";
echo "</tr>";

$i = 0;
while($n != 0)
{
echo "<tr>";
//==========================================================
//输出No.
//========================================================== 
echo "<td align=\"middle\"><a href=\"./smpp_edit?instanceNo=$ins_no[$i]&back_page=$curr_page\">$ins_no[$i]</td>";
//==========================================================
//输出Link type
//========================================================== 
if($DEBUG) echo "link_type_$i = $link_type[$i]<br>";
if ($link_type[$i] == 0)
{
	echo "<td align=\"middle\">UDP</td>";
}
else
{
	echo "<td align=\"middle\">TCP</td>";
}
//==========================================================
//输出Connection type
//========================================================== 
if ($connect_type[$i] == 0)
{
	echo "<td align=\"middle\">Client</td>";
}
else
{
	echo "<td align=\"middle\">Server</td>";
}
/*//==========================================================
//输出Session type
//========================================================== 
switch ($session_type[$i])
{
	case 0:
	{
		echo "<td align=\"middle\">BIND_TX</td>";
	}
	break;
	case 1:
	{
		echo "<td align=\"middle\">BIND_RX</td>";
	}
	break;
	case 2:
	{
		echo "<td align=\"middle\">BIND_TRX</td>";
	}
	break;
}*/
//==========================================================
//输出System ID
//========================================================== 
echo "<td align=\"middle\">$system_id[$i]&nbsp;</td>";
//==========================================================
//输出Password
//========================================================== 
echo "<td align=\"middle\">$password[$i]&nbsp;</td>";
//==========================================================
//输出DCS
//========================================================== 
switch ($smsc_dcs[$i])
{
	case 0:
	{
		echo "<td align=\"middle\">out=7bit,in=7bit</td>";
	}
	break;
	case 1:
	{
		echo "<td align=\"middle\">out=8bit,in=7bit</td>";
	}
	break;
	case 16:
	{
		echo "<td align=\"middle\">out=7bit,in=8bit</td>";
	}
	break;
	case 17:
	{
		echo "<td align=\"middle\">out=8bit,in=8bit</td>";
	}
	break;
}
//==========================================================
//输出Opposite service number
//========================================================== 
echo "<td align=\"middle\">$opposite_num[$i]&nbsp;</td>";
//==========================================================
//输出GT
//========================================================== 
if($link_type[$i] == 0)
{
	echo "<td align=\"middle\">$remote_gtt[$i]&nbsp;</td>";
	echo "<td align=\"middle\">$local_gtt[$i]&nbsp;</td>";
		
	echo "<td align=\"middle\">--</td><td align=\"middle\">--</td>";
}
//==========================================================
//输出IP
//========================================================== 
else
{
	echo "<td align=\"middle\">--</td><td align=\"middle\">--</td>";
	
//	echo "<td align=\"middle\">$remote_ip[$i]&nbsp;</td>";
		$rmt_ip[0] = hexdec(getBitValue($remote_ip[$i],'0.0-0.7'));
		$rmt_ip[1] = hexdec(getBitValue($remote_ip[$i],'1.0-1.7'));
		$rmt_ip[2] = hexdec(getBitValue($remote_ip[$i],'2.0-2.7'));
		$rmt_ip[3] = hexdec(getBitValue($remote_ip[$i],'3.0-3.7'));
		echo "<td align=\"middle\">";
		for($k=0; $k<4; $k++)
		{
			echo $rmt_ip[$k];
			if($k != 3)
				echo ".";
			
		}	
		echo "</td>";
//	echo "<td align=\"middle\">$local_ip[$i]&nbsp;</td>";		
		$lcl_ip[0] = hexdec(getBitValue($local_ip[$i],'0.0-0.7'));
		$lcl_ip[1] = hexdec(getBitValue($local_ip[$i],'1.0-1.7'));
		$lcl_ip[2] = hexdec(getBitValue($local_ip[$i],'2.0-2.7'));
		$lcl_ip[3] = hexdec(getBitValue($local_ip[$i],'3.0-3.7'));
		echo "<td align=\"middle\">";
		for($k=0; $k<4; $k++)
		{
			echo $lcl_ip[$k];
			if($k != 3)
				echo ".";
			
		}	
		echo "</td>";
}
//==========================================================
//输出Session timer
//========================================================== 
echo "<td align=\"middle\">$session_timer[$i]&nbsp;</td>";
//==========================================================
//输出Enquire link timer
//========================================================== 
echo "<td align=\"middle\">$enquire_timer[$i]&nbsp;</td>";
//==========================================================
//输出Inactivity timer
//========================================================== 
echo "<td align=\"middle\">$inact_timer[$i]&nbsp;</td>";
//==========================================================
//输出Response timer
//========================================================== 
echo "<td align=\"middle\">$response_timer[$i]&nbsp;</td>";

echo "<td align=\"middle\"><input type=\"checkbox\" name=\"$smpp_del\" value=\"ON\" 
		onClick=\"javascript:delFirm($ins_no[$i])\" ></td></tr>";
		
$n--;
$i++;
echo "</tr>";
}//end while

echo "</table>";

echo "</form>";
?>
