<?php 
include "ulf_util.php";
session_start();

// get year and month
if (isset($_GET['year']) && isset($_GET['month'])) {
	$year = $_GET['year'];
	$month = $_GET['month'];
}
else {
	$year = date("Y");
	$month = date("n");
}

// get number of days
$daysinmonth = array(31,28,31,30,31,30,31,31,30,31,30,31); 
$days = $daysinmonth[$month - 1];
$result = is_leap_year($year);
if ($month == 2 && $result == true) {
	$days = $days + 1;
}

// get previous and next month
if ($month == 1) {
	$prev_year = $year - 1;
	$prev_month = 12;
	
	$next_year = $year;
	$next_month = $month + 1;
}
else if ($month == 12) {
	$prev_year = $year;
	$prev_month = $month - 1;
	
	$next_year = $year + 1;
	$next_month = 1;
}
else {
	$prev_year = $year;
	$prev_month = $month - 1;
	
	$next_year = $year;
	$next_month = $month + 1;
}

// set data path of each system
// $stations = array("NAL", "LYR", "HOR", "SDY", "POK", "IQA", "ISR");
// $stationinitials = array("N", "L", "H", "S", "P", "I", "R");

//commented out the sites where we don't get data and changed the num_stations from 23 to 15 (done on 7/14/2026)
//$stations = array("NAL", "LYR", "ISR", "HOR", "NAQ", "UNH", "SNK", "IQA", "MCM", "SPA", "VNA", "KSS", "JBS", "HAL", "RTH", "ZK1", "ZK2", "ZK3", "SDY", "PG2", "PG3", "PG4", "PG5");

$stations = array("NAL", "LYR", "ISR", "HOR", "NAQ", "UNH", "SNK", "IQA", "MCM", "SPA", "VNA", "KSS", "JBS", "HAL", "RTH");

$stationinitials = array("N", "L", "R", "H", "Q", "D", "Y", "I", "M", "A", "U", "K", "J", "B", "R", "6", "7", "8", "S", "2", "3", "4", "5");
$num_stations = 15;
$datapath_plot = "/var/www/html/ULF/data_plot/";
$datapath_txt = "/var/www/html/ULF/";
$webpath_plot = "http://mirl-dolly.sr.unh.edu/ULF/data_plot/";
$webpath_txt = "http://mirl-dolly.sr.unh.edu/ULF/data_txt/";
$statuspath = "http://mirl-dolly.sr.unh.edu/ULF/status/";

?>

<html>
<head>
<title>ULF Data Status</title>

<script language='javascript'>

function MoveToMonth(year, month)
{
	document.location = "ulf_dbstatus.php?year=" + year + "&month=" + month;
}

function GoToMain()
{
	document.location = "ulf_svalbard.html";
}

</script>

<style type="text/css">
th {
	border-style: solid;
	border-width: 1px;
	border-color: #000000;
	font-family: arial; 
	font-size: 14px;
	font-color: #000000;
}

table.td {
	border-style: dotted;
	border-width: 1px;
	border-color: #AAAAAA;
	font-family: arial; 
	font-size: 14px;
	font-color: #000000;
}

</style>
</head>

<body>

<!-- 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 Database Status<br>
		<font style="font-family:arial; font-size:27px; color:#FFFFAA"><?php echo($year) ?> - <?php echo($month) ?>
		</td>
	</tr>
</table>
<!-- Banner End -->

<br/>
<input name="previous" type="button" value=<?php echo($prev_year . "-" . $prev_month) ?> onClick="MoveToMonth(<?php echo($prev_year)?>, <?php echo($prev_month)?>)";/>
<input name="next" type="button" value=<?php echo($next_year . "-" . $next_month) ?> onClick="MoveToMonth(<?php echo($next_year)?>, <?php echo($next_month)?>)";/>
<input name="gotomain" type="button" value="Go to main" onClick="GoToMain()";/>
<br><br><br>

<!-- Main Start -->
<table width="100%" cellspacing="0" border="0">
	<tr>
		<th></th>
		<?php 
			for ($i = 1; $i <= $days; $i++) {
				echo("<th width=18>" . $i . "</th>");
			}
		?>
	</tr>

<?php
	for ($n = 0; $n < $num_stations; $n++) {
		echo("<tr>");
		echo("<td width=20 height=40>" . $stations[$n] . "</td>");
		for ($i = 1; $i <= $days; $i++) {
			echo("<td width=18 height=40 align=center>");
			echo("<font style=\"font-family:arial; font-size:11px; color:#FFFFFF\">");
                        if (is_file_exists($datapath_plot . $stations[$n] . "/", $year, $month, $i, $stationinitials[$n], "pdf")) {
                                $plotpath = get_file_path($webpath_plot . $stations[$n] . "/", $year, $month, $i, $stationinitials[$n], "pdf");
                                echo("<a href=" . $plotpath . ">PDF</a><br>");
                        }
			else if (is_file_exists($datapath_plot . $stations[$n] . "/", $year, $month, $i, $stationinitials[$n], "jpg")) {
				$plotpath = get_file_path($webpath_plot . $stations[$n] . "/", $year, $month, $i, $stationinitials[$n], "jpg");
				echo("<a href=" . $plotpath . ">JPG</a><br>");
			} 
			else if (is_file_exists($datapath_plot . $stations[$n] . "/", $year, $month, $i, $stationinitials[$n], "png")) {
				$plotpath = get_file_path($webpath_plot . $stations[$n] . "/", $year, $month, $i, $stationinitials[$n], "png");
				echo("<a href=" . $plotpath . ">NOTE</a><br>");
			} 
			else {
			        echo("<a href=http://mirl-dolly.sr.unh.edu/ULF/NA.jpg>N/A</a><br>");
			}
			
			/*
			no longer text file posted
			if (is_file_exists($datapath_txt . $stations[$n] . "\/", $year, $month, $i, $stations[$n], "txt")) {
				$txtpath  = get_file_path($webpath_txt  . $stations[$n] . "/", $year, $month, $i, $stations[$n], "txt");
				echo("<a href=" . $txtpath . ">TXT</a>");
			}
			*/
			echo("</td>");
		}
		echo("</tr>");
	}
	
?>

</table>
<!-- Main End -->

    <td>
    <img src="Map_MICA_N_labels_2020.png" width="50%" height="50%">
    <img src="Map_MICA_S_2020.png" width="35%" height="50%">
    </td>

<br>
<?php
#echo("<a href=" . $statuspath . "Status_" . $year . "_" . $month . ".bmp>Database Import Status</a>");
?>
<br>

</body>
</html>
