<?php 
session_start();

if (isset($_GET['checking'])) {
	$checking = $_GET['checking'];
}
else { 
	$checking = false;
}

if ($checking == true) {
	// initialize systems
	$system_LYR = false;
	$system_NAL = false;
	$system_ISR = false;
	$system_HOR = false;
        $system_NAQ = false;
        $system_IQA = false;
        $system_SNK = false;
        $system_UNH = false;
	
	// set up user id and password
	//$ftp_userid = "admin";
	//$ftp_passwd = "ULF!@unh";
	
	// set up system ip
	$ftp_LYR = "158.39.49.130";
	$ftp_NAL = "193.156.10.165";
//	$ftp_ISR = "";
//	$ftp_HOR = "";
//	$ftp_NAQ = "";
        $ftp_IQA = "216.126.253.173";
//	$ftp_SNK = "";
	$ftp_UNH = "132.177.207.89";
	

	// LYR
	$conn_id = ftp_connect($ftp_LYR, 21, 2); // set up basic connection
	if ($conn_id) { // check connection
		// login with username and password
		//$login_result = ftp_login($conn_id, $ftp_userid, $ftp_passwd); 
		$system_LYR = true;
		ftp_close($conn_id);
	}
	
	
	// NAL
	$conn_id = ftp_connect($ftp_NAL, 21, 2);
	if ($conn_id) {
		$system_NAL = true;
		ftp_close($conn_id); 
	}
	
	// IQA
	$conn_id = ftp_connect($ftp_IQA, 21, 2);
	if ($conn_id) {
		$system_IQA = true;
		ftp_close($conn_id); 
	}
	
	// UNH
	$conn_id = ftp_connect($ftp_UNH, 21, 2);
	if ($conn_id) {
		$system_UNH = true;
		ftp_close($conn_id);
	}
}

?>


<html>
<head>
<title>ULF Magnetometer System - Network Connection Status</title>

<script type="text/javascript">

function Load()
{
	document.body.style.cursor = "default";
}

function Check()
{
	button_check.style.cursor = "wait";
	document.body.style.cursor = "wait";
	document.location = "ulf_systemstatus.php?checking=true";
}

</script>
</head>

<body onload="Load()">

<!-- Banner Start -->
<table border="0" cellpadding="0" cellspacing="0" height="80" width="100%" bgcolor="#004E9B">
	<tr>
		<td>
		<img src="mirl_logo.jpg" width="94" height="100%">
		</td>
		<td align="left">
		<font style="font-family:arial; font-size:20px; color:#FFFFFF"><b>ULF Magnetometer System<br>
		<font style="font-family:arial; font-size:18px; color:#FFFFAA">Magnetosphere and Ionosphere Research Laboratory at UNH
		</td>
	</tr>
</table>
<!-- Banner End -->

<!-- Header Start -->
<div id="header">
<h2>System Network Connection Status: </h2>
</div>
<!-- Header End -->

<!-- Main Start -->
<div id="content">
<p>
This page shows each system's network connection status only. 
Even if the network connection is established, it may be possible that the system doesn't work properly. 
Check data plot to confirm the health of the system. <br><br>
Click the button below to start checking. It may take a while to complete the system check. <br>
</p>

<p>	
&nbsp;
<?php
if ($checking == true) {
	echo("<input id=\"button_check\" type=\"button\" value=\"Check again\" onclick=\"Check()\">");
}
else {
	echo("<input id=\"button_check\" type=\"button\" value=\"Check systems\" onclick=\"Check()\">");
}
?>
</p>

<p>
&nbsp;
<table cellspacing="2" cellpadding="2">
	
	<tr>
		<td class="leftAlign"><font style="font-family:arial; font-size:18px; color:#000000">Ny Alesund</td>
		<td class="leftAlign"><font style="font-family:arial; font-size:18px; color:#000000">(NAL)</td>
		<?php 
		if ($checking == true) {
			if ($system_NAL == true) 
				echo("<td class=\"leftAlign\"><font style=\"font-family:arial; font-size:18px; color:#0000ff\">: Okay</td>");
			else
				echo("<td class=\"leftAlign\"><font style=\"font-family:arial; font-size:18px; color:#ff0000\">: Failed</td>");
		}
		else {
			echo("<td class=\"leftAlign\"><font style=\"font-family:arial; font-size:18px; color:#777777\">: </td>");
		}
		?>
	</tr>
	<tr>
		<td class="leftAlign"><font style="font-family:arial; font-size:18px; color:#000000">Longyearbyen</td>
		<td class="leftAlign"><font style="font-family:arial; font-size:18px; color:#000000">(LYR)</td>
		<?php 
		if ($checking == true) {
			if ($system_LYR == true) 
				echo("<td class=\"leftAlign\"><font style=\"font-family:arial; font-size:18px; color:#0000ff\">: Okay</td>");
			else
				echo("<td class=\"leftAlign\"><font style=\"font-family:arial; font-size:18px; color:#ff0000\">: Failed</td>");
		}
		else {
			echo("<td class=\"leftAlign\"><font style=\"font-family:arial; font-size:18px; color:#777777\">: </td>");
		}
		?>
	</tr>
	<tr>
		<td class="leftAlign"><font style="font-family:arial; font-size:18px; color:#000000">Isfjord</td>
		<td class="leftAlign"><font style="font-family:arial; font-size:18px; color:#000000">(ISR)</td>
		<td class="leftAlign"><font style="font-family:arial; font-size:18px; color:#777777">: N/A</td>
	</tr>
        <tr>
                <td class="leftAlign"><font style="font-family:arial; font-size:18px; color:#000000">Hornsund</td>
                <td class="leftAlign"><font style="font-family:arial; font-size:18px; color:#000000">(HOR)</td>
                <td class="leftAlign"><font style="font-family:arial; font-size:18px; color:#777777">: N/A</td>
        </tr>
        <tr>
                <td class="leftAlign"><font style="font-family:arial; font-size:18px; color:#000000">Narsarsuaq</td>
                <td class="leftAlign"><font style="font-family:arial; font-size:18px; color:#000000">(NAQ)</td>
                <td class="leftAlign"><font style="font-family:arial; font-size:18px; color:#777777">: N/A</td>
        </tr>
	<tr>
		<td class="leftAlign"><font style="font-family:arial; font-size:18px; color:#000000">Iqaluit</td>
		<td class="leftAlign"><font style="font-family:arial; font-size:18px; color:#000000">(IQA)</td>
		<?php 
		if ($checking == true) {
			if ($system_IQA == true) 
				echo("<td class=\"leftAlign\"><font style=\"font-family:arial; font-size:18px; color:#0000ff\">: Okay</td>");
			else
				echo("<td class=\"leftAlign\"><font style=\"font-family:arial; font-size:18px; color:#ff0000\">: Failed</td>");
		}
		else {
			echo("<td class=\"leftAlign\"><font style=\"font-family:arial; font-size:18px; color:#777777\">: </td>");
		}
		?>
	</tr>
        <tr>
                <td class="leftAlign"><font style="font-family:arial; font-size:18px; color:#000000">Sanikiluaq</td>
                <td class="leftAlign"><font style="font-family:arial; font-size:18px; color:#000000">(SNK)</td>
                <td class="leftAlign"><font style="font-family:arial; font-size:18px; color:#777777">: N/A</td>
        </tr>
	<tr>
		<td class="leftAlign"><font style="font-family:arial; font-size:18px; color:#000000">U. New Hampshire</td>
		<td class="leftAlign"><font style="font-family:arial; font-size:18px; color:#000000">(UNH)</td>
		<?php 
		if ($checking == true) {
			if ($system_UNH == true) 
				echo("<td class=\"leftAlign\"><font style=\"font-family:arial; font-size:18px; color:#0000ff\">: Okay</td>");
			else
				echo("<td class=\"leftAlign\"><font style=\"font-family:arial; font-size:18px; color:#ff0000\">: Failed</td>");
		}
		else {
			echo("<td class=\"leftAlign\"><font style=\"font-family:arial; font-size:18px; color:#777777\">: </td>");
		}
		?>
	</tr>

</table>

</div>
<!-- Main End -->

</body>
</html>
