<?php
global $metadata;
global $station;
global $network;
require_once dirname(__FILE__)."/../forms.php";
?>
<div class="hidden-print">
<form method="GET" name="automatic">
<?php
if (isset($savevars)){
    foreach($savevars as $k => $v){
        echo sprintf("<input type=\"hidden\" value=\"%s\" name=\"%s\" />",
        $v, $k);
    }
}
if (isset($_REQUEST["prod"])){
    echo "<input type='hidden' name='prod' value='". xssafe($_REQUEST["prod"]) ."'>\n";
}
if (isset($_REQUEST["month"])){
    echo "<input type='hidden' name='month' value='". xssafe($_REQUEST["month"]) ."'>\n";
}
if (isset($_REQUEST["year"])){
    echo "<input type='hidden' name='year' value='". xssafe($_REQUEST["year"]) ."'>\n";
}
if (isset($_REQUEST["day"])){
    echo "<input type='hidden' name='day' value='". xssafe($_REQUEST["day"]) ."'>\n";
}
?>
<input type="hidden" name="network" value="<?php echo $network; ?>">
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="/sites/locate.php">Station Data &amp; Metadata</a></li>
<li class="breadcrumb-item"><a href="/sites/locate.php?network=<?php echo $network; ?>"><?php echo $network; ?></a></li>
</ol>

<div class="d-flex align-items-center gap-2 mb-3">
    <label for="station-select" class="form-label mb-0">Select Station:</label>
    <?php echo networkSelectAuto($network, $station); ?>
    <input type="submit" class="btn btn-primary" value="Change Station" />
    <span class="text-muted">or</span>
    <a href="/sites/locate.php?network=<?php echo $network; ?>" class="btn btn-outline-secondary btn-sm">Select from map</a>
</div>
</form>

<div class="d-flex flex-wrap gap-2 mb-3">
<?php
$o = Array(
  "base" => Array("name" => "Information", "uri" => "/sites/site.php?",
          "metaok" => TRUE, "icon" => "info-circle"),
  "current" => Array("name" => "Last Ob", "uri" => "/sites/current.php?",
          "icon" => "clock"),
  "porclimo" => Array("name" => "Daily Climatology", "uri" => "/sites/porclimo.php?",
          "icon" => "table", "metaok" => TRUE),
  "pics" => Array("name" => "Photographs", "uri" => "/sites/pics.php?",
          "icon" => "camera"),
  "cal" => Array("name" => "Calibration", "uri" => "/sites/cal.phtml?",
        "icon" => "wrench",
        "networks" => Array("IA_ASOS", "IA_RWIS", "ISUAG", "ISUSM")),
  "meteo" => Array("name" => "Meteogram", "uri" => "/sites/meteo.php?",
          "icon" => "graph-up"),
  "tables" => Array("name" => "Network Table", "uri" => "/sites/networks.php?",
          "metaok" => TRUE, "icon" => "table"),
  "neighbors" => Array("name" => "Neighbors", "uri" => "/sites/neighbors.php?",
          "metaok" => TRUE, "icon" => "people"),
  "monthsum" => Array("name" => "Monthly Summaries",
          "uri" => "/sites/monthlysum.php?", "icon" => "calendar-month"),
  "obhistory" => Array("name" => "Observation History",
          "uri" => "/sites/obhistory.php?", "icon" => "clock-history"),
  "windrose" => Array("name" => "Wind Roses",
          "uri" => "/sites/windrose.phtml?", "icon" => "diagram-3"),
  "custom_windrose" => Array("name" => "Custom Wind Roses",
          "uri" => "/sites/dyn_windrose.phtml?", "icon" => "diagram-3"),
  "calendar" => Array("name" => "Data Calendar", "uri" => "/sites/hist.phtml?",
          "icon" => "calendar", "metaok" => TRUE),
);

foreach($o as $key => $val)
{
    if (($key == "meteo") && preg_match('/COOP/', $network) > 0){
        continue;
    }
    if (($key == "obhistory") && preg_match('/COCORAHS/', $network) > 0){
        continue;
    }
    if (($key == "porclimo") && (preg_match('/CLIMATE/', $network) == 0)){
        continue;
    }
     if ((array_key_exists("azos", $val) &&  preg_match('/ASOS|ISUSM/', $network) <= 0) &&
        (array_key_exists("rwis", $val) &&  preg_match('/RWIS/', $network) <= 0)){
        continue;
    }
    if (array_key_exists("networks", $val) && !in_array($network, $val["networks"])){
        continue;
    }
    // network has no wind direction
    if ($network == "USCRN" and ($key == 'custom_windrose' || $key == 'windrose')){
        continue;
    }
    // Do not display links to pages that only work for sites that produce
    // data that we consume!
    if ($network == 'RAOB' && $key == 'custom_windrose'){

    }
    else if ($metadata["metasite"] == 't' && ! array_key_exists("metaok", $val)){
        continue;
    }
      $uri = sprintf("%sstation=%s&amp;network=%s", $val["uri"], $station, $network);
      $active = ($this->sites_current == $key) ? " active": "";
    echo sprintf("<a href=\"%s\" class=\"btn btn-outline-primary%s\">".
          "<i class=\"bi bi-%s me-1\" aria-hidden=\"true\"></i><span class=\"visually-hidden\">%s</span>%s</a> ",
          $uri, $active, $val["icon"], ucfirst($val["icon"]), $val["name"]);
}

if (preg_match('/ASOS/', $network) > 0){
    if ($metadata["country"] == "US") {
        $uri = sprintf("/sites/scp.php?station=%s&amp;network=%s", $station, $network);
    echo sprintf("<a href=\"%s\" class=\"btn btn-outline-primary\"><i class=\"bi bi-cloud me-1\" aria-hidden=\"true\"></i><span class=\"visually-hidden\">Cloud</span>Satellite Cloud Product</a> ",
        $uri);
    }
    $uri = sprintf("/request/download.phtml?network=%s", $network);
    echo sprintf("<a href=\"%s\" class=\"btn btn-outline-primary\"><i class=\"bi bi-download me-1\" aria-hidden=\"true\"></i><span class=\"visually-hidden\">Download</span>Download</a> ",
            $uri);
    // TAF
    if (array_key_exists("HASTAF", $metadata["attributes"])){
        echo sprintf(
            '<a href="/sites/taf.php?station=%s&amp;network=%s" '.
            'class="btn btn-outline-primary"><i class="bi bi-cloud me-1" aria-hidden="true"></i><span class="visually-hidden">Cloud</span>Terminal Aerodome Forecast</a> ',
            $station, $network);
    }
}elseif (preg_match('/DCP/', $network) > 0){
    $uri = sprintf("/request/dcp/fe.phtml?network=%s", $network);
    echo sprintf("<a href=\"%s\" class=\"btn btn-outline-primary\"><i class=\"bi bi-download me-1\" aria-hidden=\"true\"></i><span class=\"visually-hidden\">Download</span>Download</a> ",
            $uri);

}elseif (preg_match('/RWIS/', $network) > 0){
    $uri = sprintf("/request/rwis/fe.phtml?network=%s", $network);
    echo sprintf(
        "<a href=\"%s\" class=\"btn btn-outline-primary\">".
        "<i class=\"bi bi-download me-1\" aria-hidden=\"true\"></i>".
        "<span class=\"visually-hidden\">Download</span>Download</a> ",
        $uri);
}
?>
</div>
</div>
