<?php

require("../../inc/header.inc");
$DEBUG = 0;
?>

<?
$sysTypeNo = "350";

$db = "OBJ_".$sysTypeNo;

$tb_0 = "param_0";
$tb_1 = "param_1";
$tb_2 = "param_99";

$maxNum = 20;

$nPubFlag = 99;
$nSubSysParam		= 0;
$nGlobalSubSysParam = 1;
$nGlobalSysParam	= 2;

$nGetComm = 0;
$nSetComm = 3;

$nInteger = 2;
$nOctStr = 4;

$nProcFail = 0;
$nWaitProc = 1;
$nInProc   = 2;	
$nOutProc  = 3;

$wSc = " AND level_1 = 2 AND (level_2 = 2 OR level_2 = 3)";

$pTypeArr = array('unknown','unknown','SMPP UDP','SMPP TCP');
if($set)
{	
	if($oType == 2)
	{
		$udtNum = 15;
		$showValue[5] = "00";//Address type
		$showValue[6] = omc_keep_length($showValue[6],E,18,0);//GTT number
		$showValue[7] = omc_keep_length(DecHex($showValue[7]),0,8);
		$showValue[8] = omc_keep_length(DecHex($showValue[8]),0,8);
		$showValue[9] = omc_keep_length(DecHex($showValue[9]),0,8);
		$showValue[10] = omc_keep_length(DecHex($showValue[10]),0,8);
	}elseif($oType == 3)
	{
		$udtNum = 15;
		$showValue[5] = "01";
		$p6 = explode('.',$showValue[6]);//Service address
		$showValue[6] = omc_keep_length(DecHex($p6[0]),0,2).omc_keep_length(DecHex($p6[1]),0,2).omc_keep_length(DecHex($p6[2]),0,2).omc_keep_length(DecHex($p6[3]),0,2);

		$p7 = explode('.',$showValue[7]);//Service address
		$showValue[7] = omc_keep_length(DecHex($p7[0]),0,2).omc_keep_length(DecHex($p7[1]),0,2).omc_keep_length(DecHex($p7[2]),0,2).omc_keep_length(DecHex($p7[3]),0,2);
		$showValue[8] = omc_keep_length(DecHex($showValue[8]),0,8);
		$showValue[9] = omc_keep_length(DecHex($showValue[9]),0,8);
		$showValue[10] = omc_keep_length(DecHex($showValue[10]),0,8);	
		$showValue[11] = omc_keep_length(DecHex($showValue[11]),0,8);
	}
	$showValue[14] = setBitValue(omc_keep_length(dechex($showValue[14]),'0',2),'0.0-0.0',1);//assigned
	$showValue[14] = setBitValue(omc_keep_length(dechex($showValue[14]),'0',2),'0.1-0.1',1);//unlocked

	$showValue[12] = omc_keep_length(DecHex($showValue[12]),0,2);

	$showValue[13] = omc_keep_length(DecHex($showValue[13]),0,8);

	for($i=1;$i<4;$i++){
		$valueLen = strLen($showValue[$i]);
		//echo "<br>valueLen=$valueLen";
		for($j=0;$j<$valueLen;$j++){
			$temValue[$j] = substr($showValue[$i],$j,1);
			$temValue[$j] = omc_keep_length(DecHex(Ord($temValue[$j])),0,2);	
		}
		$aNum = $j;
		$tValue = '';
		for($j=0;$j<$aNum;$j++){
			$tValue = $tValue.$temValue[$j];
		}
		if($DEBUG)echo "<br>tValue=$tValue";
		
		if($i == 1)
			$showValue[$i] = omc_keep_length($tValue,0,32,0);
		elseif($i == 2)
			$showValue[$i] = omc_keep_length($tValue,0,30,0);
		elseif($i == 3)
			$showValue[$i] = omc_keep_length($tValue,0,16,0);
	}
		
	$showValue[4] = omc_keep_length($showValue[4],E,16,0);//Service number
	
	for($i=1;$i< $udtNum;$i++){
		if($oType==2&&$i==11)
			continue;
		
		$udtSql = " UPDATE $tb_2 SET initValue = '$showValue[$i]' WHERE subSysNo = '99' AND level_2 = '$oType' AND level_3 = '$i' AND instanceNo = '$iNum' ".$wSc;
		$udtRes = @mysqli_query($pubConn,$udtSql);
		echo mysqli_error($pubConn);
	}
	echo "<script LANGUAGE=\"JavaScript\">";
	echo "window.location.href='$backurl';";		 
	echo "\n window.close();";
	echo "\n </script>";
}

/************select value to see************/
$scSql = " SELECT level_2,level_3,instanceNo,initValue,readValue FROM $tb_2 WHERE subSysNo = '99' AND level_2 = '$oType' AND instanceNo = '$iNum' ".$wSc." ORDER BY level_3 "; 
if($DEBUG) echo "<br>scSql=$scSql";
$scRes = @mysqli_query($pubConn,$scSql);
$scRow = @mysqli_fetch_array($scRes);
echo mysqli_error($pubConn);
do
{
	$level_2 = $scRow[level_2];
	$level_3 = $scRow[level_3];
	if($DEBUG)echo "<br>level_3=$level_3";
	$instanceNo = $scRow[instanceNo];
	//$showValue[$level_3] = $scRow[initValue];
	//if($DEBUG)echo "<br>showValue[$level_3]={$showValue[$level_3]}";

	if($level_3 > 0 && $level_3 < 4)
	{
		$valueLen = floor(strLen($scRow[initValue])/2);
		for($i=0;$i<$valueLen;$i++){
			$temValue[$i] = substr($scRow[initValue],$i*2,2);
			if($temValue[$i] == '00'){
				break;
			}else{
				$temValue[$i] = Chr(HexDec($temValue[$i]));
			}
		}
		$aNum = $i;
		$tValue = '';
		for($i=0;$i<$aNum;$i++){
			$tValue = $tValue.$temValue[$i];
		}
		//echo "<br>tValue=$tValue";
		$showValue[$level_3] = $tValue;
	}
	elseif($level_3 == 4)
	{
		$p4 = explode("E",$scRow[initValue]);
		$showValue[$level_3] = $p4[0];
	}
	elseif($level_3 == 6)
	{
		if($level_2 == 2)
		{
			$p6 = explode("E",$scRow[initValue]);
			$showValue[$level_3] = $p6[0];
		}
		elseif($level_2 == 3)
		{
			$valueLen = floor(strLen($scRow[initValue])/2);
			for($i=0;$i<$valueLen;$i++)
			{
				$temValue[$i] = HexDec(substr($scRow[initValue],$i*2,2));
			}
			$showValue[$level_3] = $temValue[0].".".$temValue[1].".".$temValue[2].".".$temValue[3];
		}
	}
	elseif($level_3 == 7)
	{
		if($level_2 == 2)
		{
			$showValue[$level_3] = HexDec($scRow[initValue]);
		}
		else
		{
			$valueLen = floor(strLen($scRow[initValue])/2);
			for($i=0;$i<$valueLen;$i++)
			{
				$temValue[$i] = HexDec(substr($scRow[initValue],$i*2,2));
			}
			$showValue[$level_3] = $temValue[0].".".$temValue[1].".".$temValue[2].".".$temValue[3];
		}
	}
	elseif($level_3 == 14)
	{
		$showValue[$level_3] = $scRow[initValue];
	}
	else
	{
		$showValue[$level_3] = HexDec($scRow[initValue]);
	}

}while($scRow = @mysqli_fetch_array($scRes));



echo "<form method=\"POST\" name=\"confForm\" action=\"$PHP_SELF\">";
{
	echo "<table border=\"0\" width=\"100%\">";
	echo "<tr>";
	echo "<td width=\"80%\">";
	echo "$strConfiguration > <a href=\"../overview/overview.php\">Network</a> > <a href=\"$backurl\">SMSC</a> > <a href=\"#\">{$pTypeArr[$oType]}</a>";

	echo "<td width=\"20%\" align=\"right\" title=\"Help\">";
	//showHelp($helpId);
	echo "</td>";
	echo "</tr>";
	echo "</table>";
	echo "<br>";
	
	echo "<table width=\"100%\">";
	echo "<tr><td width=\"%70\">";
	echo "<b>$pTypeArr[$oType]   $iNum:&nbsp;&nbsp;&nbsp;&nbsp;</b>";
	echo "</td>";
	echo "<td width=\"20%\">";
	echo "<input type=\"submit\" value = $strSave class=\"button\" name=\"set\" style=\"left: 1; top: 2; width: 60; height: 25; position: relative\">";	
	echo "&nbsp;&nbsp;&nbsp;&nbsp;";
	echo "<input type=\"reset\" value=$strUndo  class=\"button\" name=\"Reset\" style=\"left: 1; top: 2; width: 60; height: 25; position: relative\">";
	echo "</td>";
	echo "<td width=\"10%\"><p align=\"right\"><a href=\"$backurl\"><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="2" cellspacing="0" bordercolor="#666666" bordercolordark="#FFFFFF" bgcolor="#FFFFFF"> 
<?php
echo "<tr bgcolor = \"#E6E6E6\">";
echo "<td width=\"50%\"><b>Parameters</b></td>";
echo "<td width=\"50%\"><b>Value</b></td>";
echo "</tr>";

echo "<tr>";
echo "<td width=\"60\" valign=middle><nobr>Name</nobr></td>";
echo "<td colspan=\"2\"><input type=\"text\" name=\"showValue[1]\" size=\"32\" value=\"$showValue[1]\" maxLength=\"32\" class=\"input\"></td>";
echo "</tr>";

echo "<tr>";
echo "<td width=\"60\" valign=middle><nobr>System ID</nobr></td>";
echo "<td colspan=\"2\"><input type=\"text\" name=\"showValue[2]\" size=\"32\" value=\"$showValue[2]\" maxLength=\"32\" class=\"input\"></td>";
echo "</tr>";

echo "<tr>";
echo "<td width=\"60\" valign=middle><nobr>Password</nobr></td>";
echo "<td colspan=\"2\"><input type=\"text\" name=\"showValue[3]\" size=\"16\" value=\"$showValue[3]\" maxLength=\"16\" class=\"input\"></td>";
echo "</tr>";

echo "<tr>";
echo "<td width=\"60\" valign=middle><nobr>Service number</nobr></td>";
echo "<td colspan=\"2\"><input type=\"text\" name=\"showValue[4]\" size=\"16\" value=\"$showValue[4]\" maxLength=\"16\" class=\"input\"></td>";
echo "</tr>";

if($oType == 2){
	echo "<input type=\"hidden\" name=\"showValue[5]\" value =\"00\">";
//	echo "<tr>";
//	echo "<td width=\"60\" valign=middle><nobr>Destination addr. type</nobr></td>";
//	echo "<td colspan=\"2\"><input type=\"text\" name=\"showValue[5]\" size=\"18\" value=\"$showValue[5]\" maxLength=\"18\" 	class=\"input\"></td>";
//	echo "</tr>";
	
	echo "<tr>";
	echo "<td width=\"60\" valign=middle><nobr>GTT number</nobr></td>";
	echo "<td colspan=\"2\"><input type=\"text\" name=\"showValue[6]\" size=\"18\" value=\"$showValue[6]\" maxLength=\"18\" 	class=\"input\"></td>";
	echo "</tr>";
	
	echo "<tr>";
	echo "<td width=\"60\" valign=middle><nobr>Session timer</nobr></td>";
	echo "<td colspan=\"2\"><input type=\"text\" name=\"showValue[7]\" size=\"8\" value=\"$showValue[7]\" maxLength=\"8\" class=\"input\"></td>";
	echo "</tr>";

	echo "<tr>";
	echo "<td width=\"60\" valign=middle><nobr>Enquire link timer</nobr></td>";
	echo "<td colspan=\"2\"><input type=\"text\" name=\"showValue[8]\" size=\"8\" value=\"$showValue[8]\" maxLength=\"8\" class=\"input\"></td>";
	echo "</tr>";

	echo "<tr>";
	echo "<td width=\"60\" valign=middle><nobr>Inactivity timer</nobr></td>";
	echo "<td colspan=\"2\"><input type=\"text\" name=\"showValue[9]\" size=\"8\" value=\"$showValue[9]\" maxLength=\"8\" class=\"input\"></td>";
	echo "</tr>";

	echo "<tr>";
	echo "<td width=\"60\" valign=middle><nobr>Response timer</nobr></td>";
	echo "<td colspan=\"2\"><input type=\"text\" name=\"showValue[10]\" size=\"8\" value=\"$showValue[10]\" maxLength=\"8\" class=\"input\"></td>";
	echo "</tr>";

	echo "<tr>";
	echo "<td>DCS</td>";
	$arr_DCS=array(
		array('num' => '0',   'remark' => 'To smpp=7bit,default=7bit'),
		array('num' => '1',   'remark' => 'To smpp=8bit,default=7bit'),
		array('num' => '16',  'remark' => 'To smpp=7bit,default=8bit'),
		array('num' => '17',  'remark' => 'To smpp=8bit,default=8bit')
	);
	
	echo "<td>";
	echo "<select size=\"1\" name=\"showValue[12]\">";
	for ($i=0;$i<4;$i++){
		 if($arr_DCS[$i][num] != $showValue[12]){
			 echo "<option value=\"{$arr_DCS[$i][num]}\">{$arr_DCS[$i][remark]}</option>";       
         }else{
			 echo "<option value=\"{$arr_DCS[$i][num]}\" selected>{$arr_DCS[$i][remark]}</option>";
         }       
	}
	echo "</select>";
	echo "</td>";
	echo "</tr>";

	echo "<tr>";
	echo "<td width=\"60\" valign=middle><nobr>Time to live</nobr></td>";
	echo "<td colspan=\"2\"><input type=\"text\" name=\"showValue[13]\" size=\"10\" value=\"$showValue[13]\" maxLength=\"10\" class=\"input\"></td>";
	echo "</tr>";
}
elseif($oType == 3)
{
	echo "<input type=\"hidden\" name=\"showValue[5]\" value =\"01\">";

	echo "<tr>";
	echo "<td width=\"60\" valign=middle><nobr>Service IP</nobr></td>";
	echo "<td colspan=\"2\"><input type=\"text\" name=\"showValue[6]\" size=\"16\" value=\"$showValue[6]\" maxLength=\"16\" class=\"input\"></td>";
	echo "</tr>";

	echo "<tr>";
	echo "<td width=\"60\" valign=middle><nobr>Local IP</nobr></td>";
	echo "<td colspan=\"2\"><input type=\"text\" name=\"showValue[7]\" size=\"16\" value=\"$showValue[7]\" maxLength=\"16\" class=\"input\"></td>";
	echo "</tr>";

	echo "<tr>";
	echo "<td width=\"60\" valign=middle><nobr>Session timer</nobr></td>";
	echo "<td colspan=\"2\"><input type=\"text\" name=\"showValue[8]\" size=\"8\" value=\"$showValue[8]\" maxLength=\"8\" class=\"input\"></td>";
	echo "</tr>";

	echo "<tr>";
	echo "<td width=\"60\" valign=middle><nobr>Enquire link timer</nobr></td>";
	echo "<td colspan=\"2\"><input type=\"text\" name=\"showValue[9]\" size=\"8\" value=\"$showValue[9]\" maxLength=\"8\" class=\"input\"></td>";
	echo "</tr>";

	echo "<tr>";
	echo "<td width=\"60\" valign=middle><nobr>Inactivity timer</nobr></td>";
	echo "<td colspan=\"2\"><input type=\"text\" name=\"showValue[10]\" size=\"8\" value=\"$showValue[10]\" maxLength=\"8\" class=\"input\"></td>";
	echo "</tr>";

	echo "<tr>";
	echo "<td width=\"60\" valign=middle><nobr>Response timer</nobr></td>";
	echo "<td colspan=\"2\"><input type=\"text\" name=\"showValue[11]\" size=\"8\" value=\"$showValue[11]\" maxLength=\"8\" class=\"input\"></td>";
	echo "</tr>";

	echo "<tr>";
	echo "<td>DCS</td>";
	$arr_DCS=array(
		array('num' => '0',   'remark' => 'To smpp=7bit,default=7bit'),
		array('num' => '1',   'remark' => 'To smpp=8bit,default=7bit'),
		array('num' => '16',  'remark' => 'To smpp=7bit,default=8bit'),
		array('num' => '17',  'remark' => 'To smpp=8bit,default=8bit')
	);
	
	echo "<td>";
	echo "<select size=\"1\" name=\"showValue[12]\">";
	for ($i=0;$i<4;$i++){
		 if($arr_DCS[$i][num] != $showValue[12]){
			 echo "<option value=\"{$arr_DCS[$i][num]}\">{$arr_DCS[$i][remark]}</option>";       
         }else{
			 echo "<option value=\"{$arr_DCS[$i][num]}\" selected>{$arr_DCS[$i][remark]}</option>";
         }       
	}
	echo "</select>";
	echo "</td>";
	echo "</tr>";

	echo "<tr>";
	echo "<td width=\"60\" valign=middle><nobr>Time to live</nobr></td>";
	echo "<td colspan=\"2\"><input type=\"text\" name=\"showValue[13]\" size=\"10\" value=\"$showValue[13]\" maxLength=\"10\" class=\"input\"></td>";
	echo "</tr>";


}
echo "<input type=\"hidden\" name=\"showValue[14]\" value=\"$showValue[14]\">";

echo "</table>";
echo "<br>";
echo "&nbsp;&nbsp;";
echo "<input type=\"hidden\" name=\"iNum\" value =\"$iNum\">";
echo "<input type=\"hidden\" name=\"oType\" value =\"$oType\">";
echo "<input type=\"hidden\" name=\"backurl\" value =\"$backurl\">";
echo "</form>";
?>
</html>
