<?php
require("../../inc/header.inc");
?>

<style type="text/css">
<!--
.style {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 8pt;background: url(--.gif); border: 0px;  height: 16px;}
-->
</style>

<script language="JavaScript">
	function openSet(instanceNo,showIndex,operation)
	{
		URL="./operation.php?instanceNo="+instanceNo+"&showIndex="+showIndex+"&operation="+operation;
		//var setWindow = open(URL, 'newWin', 'toolbar=no,directories=no,menubar=no,scrollbars=yes,resizable=yes,status=yes,width=400,height=350');
		//setWindow.focus();
		window.location.href=URL;
	}

</script>
<body onload="javascript:adjust();" onresize="javascript:adjust();" leftmargin="15" style="overflow:hidden;overflow-x:hidden;overflow-y:hidden;">

<?php
adjust_head();
adjust_title_head();
echo "<FORM NAME=\"downForm\">";
echo "<table id=\"table_up\" border=\"0\" width=\"100%\">";
	echo "<tr>";
		echo "<td width=\"50%\">";
		echo "Template > File Transfer";
		echo "</td>";
		echo "<td width=\"50%\" align=\"right\" title=\"Help\">";
		//showHelp($helpId);
		echo "</td>";
	echo "</tr>";
echo "</table>";
adjust_title_tail();
adjust_content_head();
echo "<br>";

?>	

<?php
	$DEBUG=0;
	//delete one file transfer object
	if($delete==1)
	{
		
		if($DEBUG)echo "instanceNo=$instanceNo<br>";
		
		//delete from the wsmsServConf
		$pubDb="OMC_PUB";
		$delSql = "DELETE FROM fileTransConf WHERE instanceNo='$instanceNo' ";
		if($DEBUG) echo "<br>delSql=$delSql";
		$delRes = @mysqli_query($pubConn,$delSql);
		echo mysqli_error($pubConn);	
		
		echo "<font color=blue>Delete successfully!</font><br>";
		
		
	}
	


	//Get the hpmn server info from database
	$database="OMC_PUB";
	$selSql = "SELECT * FROM fileTransConf where srcDir IS NOT NULL and dstDir IS NOT NULL AND dstIP IS NOT NULL AND filter IS NOT NULL AND logName IS NOT NULL AND logPass IS NOT NULL ";
	$selRes = @mysqli_query($pubConn,$selSql);
	$FileTransObjCount=mysqli_num_rows($selRes);
	echo mysqli_error($pubConn);
	//echo "FileTransObjCount:$FileTransObjCount<br>";
	
	$typeLabel=array(0=>"FTP",1=>"SFTP");
	
	$FileTransObjIndex=0;
	while($selRow = @mysqli_fetch_array($selRes))
	{
		$FileTransObjInstanceNo[$FileTransObjIndex]=$selRow[instanceNo];
		$FileTransObjType[$FileTransObjIndex]=$selRow[type]+0;
		$FileTransObjSrcDir[$FileTransObjIndex]=$selRow[srcDir];
		$FileTransObjDstDir[$FileTransObjIndex]=$selRow[dstDir];
		$FileTransObjDstIP[$FileTransObjIndex]=$selRow[dstIP];
		$FileTransObjFilter[$FileTransObjIndex]=$selRow[filter];
		$FileTransObjLogName[$FileTransObjIndex]=$selRow[logName];
		$FileTransObjLogPass[$FileTransObjIndex]=$selRow[logPass];
		if(0)
		{
			echo "{$FileTransObjInstanceNo[$FileTransObjIndex]} {$typeLabel[$FileTransObjType[$FileTransObjIndex]]} {$FileTransObjSrcDir[$FileTransObjIndex]} {$FileTransObjDstDir[$FileTransObjIndex]} {$FileTransObjDstIP[$FileTransObjIndex]} {$FileTransObjFilter[$FileTransObjIndex]} {$FileTransObjLogName[$FileTransObjIndex]} {$FileTransObjLogPass[$FileTransObjIndex]}<br>";
		}
		$FileTransObjIndex++;
	}
	
	echo "<p><table border=\"1\" width=\"100%\" cellpadding=\"1\" cellspacing=\"0\" bordercolor=\"#666666\" bordercolordark=\"#FFFFFF\">";
	echo "<tr bgcolor=\"#E6E6E6\">";
	echo "<td width=\"5%\" align=center>No.</td>";
	echo "<td width=\"5%\" align=center>Type</td>";
	echo "<td width=\"4%\" align=center>Filter</td>";
	echo "<td width=\"4%\" align=center><nobr>Login Name</td>";
	echo "<td width=\"4%\" align=center><nobr>Login PW</td>";
	echo "<td width=\"14%\" align=center>Destination IP</td>";
	echo "<td width=\"30%\" align=center>Source Directory</td>";
	echo "<td width=\"30%\" align=center>Destination Directory</td>";
	echo "<td width=\"2%\" align=center>Delete</td>";
	echo "</tr>";
	
	for($i=0;$i<$FileTransObjCount;$i++)
	{
		echo "<tr>";
		$showIndex=$i+1;
		echo "<td align=center><a href=# onClick=\"javascript:openSet('{$FileTransObjInstanceNo[$i]}','$showIndex','edit')\">$showIndex</a></td>";
		echo "<td>{$typeLabel[$FileTransObjType[$i]]}</td>";
		echo "<td>{$FileTransObjFilter[$i]}</td>";
		echo "<td>{$FileTransObjLogName[$i]}</td>";
		echo "<td>{$FileTransObjLogPass[$i]}</td>";
		echo "<td>{$FileTransObjDstIP[$i]}</td>";
		echo "<td>{$FileTransObjSrcDir[$i]}</td>";
		echo "<td>{$FileTransObjDstDir[$i]}</td>";

		echo "<td><a href=\"./fileTransferConfiguration.php?instanceNo={$FileTransObjInstanceNo[$i]}&delete=1\">Delete</a></td>";
		echo "</tr>";
	}
	$ti=$FileTransObjCount+1;
	echo "<tr><td><a href=# onClick=\"javascript:openSet('','$ti','new')\">New</a></td><td>--</td><td>--</td><td>--</td><td>--</td><td>--</td><td>--</td><td>--</td><td>--</td>";
	
	echo "</table>";
adjust_content_tail();
?>
