<?php 
require_once "../../../config/settings.inc.php";
require_once "../../../include/forms.php";
require_once "../../../include/myview.php";
require_once "../../../include/network.php";

$t = new MyView();
$t->title = "Low Temperature Threshold Histograms";

$station1 = isset($_GET["station1"]) ? xssafe($_GET["station1"]): "";
$station2 = isset($_GET["station2"]) ? xssafe($_GET["station2"]): "";
$mode = isset($_GET["mode"]) ? xssafe($_GET["mode"]): "";

$nt = new NetworkTable("IACLIMATE");
$cities = $nt->table;

$s1 = "";
for(reset($cities); $key = key($cities); next($cities))
{
    $s1 .= "<option value=\"" . $cities[$key]["id"] ."\"";
    if ($cities[$key]["id"] == $station1) $s1 .= " SELECTED ";

    $s1 .= ">" . $cities[$key]["name"] . "\n";
}
$s2 = "";
for(reset($cities); $key = key($cities); next($cities))
{
    $s2 .= "<option value=\"" . $cities[$key]["id"] ."\"";
    if ($cities[$key]["id"] == $station2) $s2 .= " SELECTED ";

    $s2 .= ">" . $cities[$key]["name"] . "\n";
}
$ar = Array("o" => "One Station", "c" => "Compare Two");
$modeselect = make_select("mode", $mode, $ar);

if ($station1 != "" && $station2 != "")
{
    if ($mode == "c"){
        $imgurl = "<img src=\"threshold_histogram.php?station1=".$station1."&station2=".$station2."\">\n";

    }else {
        $imgurl = "<img src=\"threshold_histogram.php?station1=". $station1 ."\">\n";
    }
} else {
    $imgurl = "<p>Select your site above...</p>";
}

$t->content = <<<EOM
<ol class="breadcrumb">
<li><a href="/COOP/">NWS COOP</a></li>
<li class="active">COOP Low Temperature Thresholds</li>
</ol>


<form method="GET">

<table>
<tr>
  <th class="subtitle">Station 1</th>
  <th class="subtitle">Station 2</th>
  <td></td>
  <td></td>
</tr>

<tr>
<td>
<SELECT name="station1">
{$s1}
</SELECT>
</td>
<td>
<SELECT name="station2">
{$s2}
</SELECT>
</td>
<td>
{$modeselect}
</td>

<td>
<input type="SUBMIT" value="Make Plot">

</form>
</td>

</tr></table>

<div style="width:640px;">
<p>This application plots the frequency of years during which a threshold 
temperature was exceeded for a particular site for 1 day that winter.  You can select multiple
sites to compare them.  This page may take 30 seconds to load once you select
your sites.
</div>
<br />

{$imgurl}
EOM;
$t->render('single.phtml');
