<?php
$OL = "10.6.1";
require_once "../../../config/settings.inc.php";
require_once "../../../include/myview.php";
require_once "../../../include/database.inc.php";
require_once "../../../include/forms.php";
$t = new MyView();
$t->iemselect2 = TRUE;

$station = isset($_GET['station']) ? xssafe($_GET["station"]) : "";
$network = isset($_GET["network"]) ? xssafe($_GET['network']) : "IA_ASOS";
$year = get_int404('year', date("Y"));
$month = get_int404('month', date("m"));

$t->headextra = <<<EOM
<link rel="stylesheet" href="/vendor/openlayers/{$OL}/ol.css" type="text/css">
<link type="text/css" href="/vendor/openlayers/{$OL}/ol-layerswitcher.css" rel="stylesheet" />
<link type="text/css" href="rainfall.css" rel="stylesheet" />
EOM;
$t->jsextra = <<<EOM
<script src="/vendor/openlayers/{$OL}/ol.js" type="text/javascript"></script>
<script src='/vendor/openlayers/{$OL}/ol-layerswitcher.js'></script>
<script src="/js/olselect.js"></script>
EOM;

$t->title = "Monthly Rainfall Traces";

$content = <<<EOM

<h3>Monthly Rainfall Traces</h3>

<p>This application creates a plot of observed precipitation versus 
climatology for a site of your choice in Iowa. 
EOM;
if (strlen($station) > 0) {
    $nselect = networkSelect($network, $station);
    $yselect = yearSelect(2004, $year, "year");
    $mselect = monthSelect($month);
    $content .= <<<EOM
<form name="ds" action="rainfall.phtml" method="GET">
<input type="hidden" value="{$network}" name="network">
<table cellspacing=2 border=1 cellpadding=2>
<tr><th>Site ID:</th><th>Select Year:</th><th>Select Month:</th></tr>
<tr><td>{$nselect}
<a href="rainfall.phtml?network={$network}">Select from map</a></td>
  <td>{$yselect}</td>
    <td>{$mselect}</td></tr>
</table>
<input type="submit" value="Make Plot">
</form>

<p><img src="/plotting/auto/plot/17/month:{$month}::year:{$year}::station:{$station}::network:{$network}::p:precip.png" alt="Time Series" />
EOM;
} else {
    $nselect = networkSelect($network, "");
    $content .= <<<EOM

<br /><a href="rainfall.phtml?network=IA_ASOS">Iowa ASOS</a> &nbsp; 
<a href="rainfall.phtml?network=AWOS">Iowa AWOS</a> &nbsp; 
<a href="rainfall.phtml?network=IA_COOP">Iowa NWS COOP</a> &nbsp; 
<a href="rainfall.phtml?network=KCCI">KCCI-TV SchoolNet</a> &nbsp; 

<form name="olselect">
<input type="hidden" value="{$network}" name="network">
<table><tr><th>Select Station</th>
<td>{$nselect}</td>
<td><input type="submit" value="Make Plot"></tr></table>
<div id="map" data-network="{$network}"></div>
</form>
EOM;
}
$t->content = $content;
$t->render('single.phtml');
