<?php
require("../../inc/header.inc");
?>
<body onload="javascript:adjust();" onresize="javascript:adjust();" leftmargin="15" style="overflow:hidden;overflow-x:hidden;overflow-y:hidden;">

<script language="JavaScript">
	
	function saveParameter(saveType)
	{
		var mcc=document.myform.mcc_text.value;
		var mnc=document.myform.mnc_text.value;
		var tadig=document.myform.tadig_text.value;
		var serverIP=document.myform.serverIP_text.value;
		var loginName=document.myform.loginName_text.value;
		var loginPass=document.myform.loginPass_text.value;
		var interval=document.myform.interval_text.value;
		var reportDir=document.myform.reportDir_text.value;
		var nrtrdeDir=document.myform.nrtrdeDir_text.value;
		window.location.href="./operation.php?saveType="+saveType+"&operation=save&edit_mcc="+mcc+"&edit_mnc="+mnc+"&edit_tadig="+tadig+"&edit_serverIP="+serverIP+"&edit_loginName="+loginName+"&edit_loginPass="+loginPass+"&edit_interval="+interval+"&edit_reportDir="+reportDir+"&edit_nrtrdeDir="+nrtrdeDir;
	}
	
	
	function closeWindow()
	{
		//window.opener.location.href="./hpmnInfo.php";
		//window.close();
	}
</script>	

<?php
adjust_head();
adjust_title_head();
echo "<TABLE id=\"table_up\" border=\"0\" width=\"100%\">";
echo "<TR>";
echo "<TD width=\"50%\" align=\"left\">";
echo "$strMaintenance > Control Panel > NRTRDE HPMN";
echo "</TD>";
echo "<TD width=\"50%\" align=\"right\" title=\"Help\">";
$helpId="5.2.2";
showHelp($helpId);
echo "</TD>";
echo "</TR>";
echo "</TABLE>";

adjust_title_tail();
adjust_content_head();
echo "<br>";
	$DEBUG=0;
	
	if($DEBUG)
		echo "mcc=$mcc,mnc=$mnc,operation=$operation<br>";
	
	echo "<form name=\"myform\" action=\"./hpmnInfo.php\">";	
	
	if($operation=="save")
	{
		$pubDb="OMC_PUB";
		if($saveType=="edit")
			$updSql = "UPDATE hpmnConf SET tadig='$edit_tadig',serverIP='$edit_serverIP',loginName='$edit_loginName',loginPass='$edit_loginPass',timeslot='$edit_interval',reportDir='$edit_reportDir',nrtrdeDir='$edit_nrtrdeDir' WHERE mcc='$edit_mcc' AND mnc='$edit_mnc' ";
		else
			$updSql = "INSERT INTO hpmnConf values('$edit_mcc','$edit_mnc','$edit_tadig','$edit_serverIP','$edit_loginName','$edit_loginPass','$edit_interval','$edit_reportDir','$edit_nrtrdeDir') ";
		if($DEBUG) echo "<BR>updSql=$updSql";
		mysqli_query($pubConn,$updSql);
		echo mysqli_error($pubConn);
		
		echo "\n<script language=\"JavaScript\">\n";
		echo "window.location.href=\"./hpmnInfo.php\";\n";
		echo "</script>\n";
	}
	//Add a new hpmn server
	else if($operation=="new")
	{

		echo "<p><table border=\"1\" width=\"100%\" cellpadding=\"1\" cellspacing=\"0\" bordercolor=\"#666666\" bordercolordark=\"#FFFFFF\">";
		echo "<tr bgcolor=\"#E6E6E6\">";
		echo "<td width=\"50%\">Name</td><td width=\"50%\">Value</td>";
		echo "</tr>";
		
		//mcc
		echo "<tr>";
		echo "<td>MCC</td>";
		echo "<td><input type=text class=\"text\" size=5 maxlength=3 name=\"mcc_text\" value=\"\"></text></td>";
		echo "</tr>";
		
		//mnc
		echo "<tr>";
		echo "<td>MNC</td>";
		echo "<td><input type=text class=\"text\" size=5 maxlength=2 name=\"mnc_text\" value=\"\"></text></td>";
		echo "</tr>";
		
		//tadig
		echo "<tr>";
		echo "<td>Tadig</td><td><input type=text class=\"text\" size=7 maxlength=5 name=\"tadig_text\" value=\"$HpmnTadig\"></text></td>";
		echo "</tr>";
		
		//serverIP
		echo "<tr>";
		echo "<td>Server IP</td><td><input type=text class=\"text\" size=16 maxlength=16 name=\"serverIP_text\" value=\"\"></text></td>";
		echo "</tr>";
		
		//loginName
		echo "<tr>";
		echo "<td>Login Name</td><td><input type=text class=\"text\" size=16 maxlength=16 name=\"loginName_text\" value=\"\"></text></td>";
		echo "</tr>";
		
		//loginPass
		echo "<tr>";
		echo "<td>Login Password</td><td><input type=text class=\"text\" size=16 maxlength=16 name=\"loginPass_text\" value=\"\"></text></td>";
		echo "</tr>";
		
		//timeslot
		$valueList=array(900,1800,3600,7200,10800,14400);
		$valueLabel=array("15 Min","30 Min","1 Hour","2 Hours","3 Hours","4 Hours");
		echo "<tr>";
		echo "<td>Interval</td>";
		echo "<td><select name=\"interval_text\">";
		for($i=0;$i< sizeof($valueList);$i++)
		{
			if($i==2)
				echo "<option value=\"{$valueList[$i]}\" selected>{$valueLabel[$i]}</option>";
			else
				echo "<option value=\"{$valueList[$i]}\">{$valueLabel[$i]}</option>";
		}
		echo "</select></td>";
		//echo "<td><input type=text class=\"text\" size=16 maxlength=16 name=\"interval_text\" value=\"$HpmnTimeSlot\"></text></td>";
		echo "</tr>";
		
		//reportDir
		echo "<tr>";
		echo "<td>Report Directory</td><td><input type=text class=\"text\" size=32 maxlength=64 name=\"reportDir_text\" value=\"\"></text></td>";
		echo "</tr>";
		
		//nrtrdeDir
		echo "<tr>";
		echo "<td>NRTRDE Directory</td><td><input type=text class=\"text\" size=32 maxlength=64 name=\"nrtrdeDir_text\" value=\"\"></text></td>";
		echo "</tr>";
		
		echo "</table>";
	}
	//Edit a hpmn server
	else if($operation=="edit")
	{
		//Get the hpmn server info from database
		$database="OMC_PUB";
		$selSql = "SELECT * FROM hpmnConf where mcc='$mcc' and mnc='$mnc' ";
		$selRes = @mysqli_query($pubConn,$selSql);
		$HpmnCount=mysqli_num_rows($selRes);
		echo mysqli_error($pubConn);
		//echo "count:$HpmnCount<br>";
	
		$selRow = @mysqli_fetch_array($selRes);
		$HpmnMcc=$selRow[mcc];
		$HpmnMnc=$selRow[mnc];
		$HpmnTadig=$selRow[tadig];
		$HpmnServerIP=$selRow[serverIP];
		$HpmnLoginName=$selRow[loginName];
		$HpmnLoginPass=$selRow[loginPass];
		$HpmnTimeSlot=$selRow[timeslot];
		$HpmnReportDir=$selRow[reportDir];
		$HpmnNrtrdeDir=$selRow[nrtrdeDir];


		echo "<p><table border=\"1\" width=\"100%\" cellpadding=\"1\" cellspacing=\"0\" bordercolor=\"#666666\" bordercolordark=\"#FFFFFF\">";
		echo "<tr bgcolor=\"#E6E6E6\">";
		echo "<td width=\"50%\">Name</td><td width=\"50%\">Value</td>";
		echo "</tr>";
		
		//mcc
		echo "<tr>";
		echo "<td>MCC</td><td>$HpmnMcc</td>";
		echo "<input type=\"hidden\" name=\"mcc_text\" value=$HpmnMcc>";
		//echo "<td>MCC</td><td><input type=text readonly class=\"text\" size=5 maxlength=3 name=\"mcc_text\" value=\"460\"></text></td>";
		echo "</tr>";
		
		//mnc
		echo "<tr>";
		echo "<td>MNC</td><td>$HpmnMnc</td>";
		echo "<input type=\"hidden\" name=\"mnc_text\" value=$HpmnMnc>";
		//echo "<td>MNC</td><td><input type=text readonly class=\"text\" size=5 maxlength=2 name=\"mnc_text\" value=\"460\"></text></td>";
		echo "</tr>";
		
		//tadig
		echo "<tr>";
		echo "<td>Tadig</td><td><input type=text class=\"text\" size=7 maxlength=5 name=\"tadig_text\" value=\"$HpmnTadig\"></text></td>";
		echo "</tr>";
		
		//serverIP
		echo "<tr>";
		echo "<td>Server IP</td><td><input type=text class=\"text\" size=16 maxlength=16 name=\"serverIP_text\" value=\"$HpmnServerIP\"></text></td>";
		echo "</tr>";
		
		//loginName
		echo "<tr>";
		echo "<td>Login Name</td><td><input type=text class=\"text\" size=16 maxlength=16 name=\"loginName_text\" value=\"$HpmnLoginName\"></text></td>";
		echo "</tr>";
		
		//loginPass
		echo "<tr>";
		echo "<td>Login Password</td><td><input type=text class=\"text\" size=16 maxlength=16 name=\"loginPass_text\" value=\"$HpmnLoginPass\"></text></td>";
		echo "</tr>";
		
		//timeslot
		$valueList=array(900,1800,3600,7200,10800,14400);
		$valueLabel=array("15 Min","30 Min","1 Hour","2 Hours","3 Hours","4 Hours");
		echo "<tr>";
		echo "<td>Interval</td>";
		echo "<td><select name=\"interval_text\">";
		for($i=0;$i< sizeof($valueList);$i++)
		{
			if($HpmnTimeSlot==$valueList[$i])
				echo "<option value=\"{$valueList[$i]}\" selected>{$valueLabel[$i]}</option>";
			else
				echo "<option value=\"{$valueList[$i]}\">{$valueLabel[$i]}</option>";
		}
		echo "</select></td>";
		//echo "<td><input type=text class=\"text\" size=16 maxlength=16 name=\"interval_text\" value=\"$HpmnTimeSlot\"></text></td>";
		echo "</tr>";
		
		//reportDir
		echo "<tr>";
		echo "<td>Report Directory</td><td><input type=text class=\"text\" size=32 maxlength=64 name=\"reportDir_text\" value=\"$HpmnReportDir\"></text></td>";
		echo "</tr>";
		
		//nrtrdeDir
		echo "<tr>";
		echo "<td>NRTRDE Directory</td><td><input type=text class=\"text\" size=32 maxlength=64 name=\"nrtrdeDir_text\" value=\"$HpmnNrtrdeDir\"></text></td>";
		echo "</tr>";
		
		echo "</table>";
	}
	//save button
	echo "<input type=button onClick=\"javascript:saveParameter('$operation');javascript:closeWindow();\" value=\"Save\" class=\"button\">";
	
	//remark
	echo "<p><b>Remark:</b><p>";
	echo "Interval: The interval to make NRTRDE files for the HPMN<br><br>";
	echo "Report Directory: The directory to send the report files to<br><br>";
	echo "NRTRDE Directory: The directory to send the NRTRDE files to<br><br>";
	
	echo "</form>";
adjust_content_tail();
?>
