<?php
  $title = "COVID-19 cases";
  $known = -1;

  if (isset($_GET["path"])) {
    if ($_GET["path"] == "jersey") {
      $location = "Jersey";
      $json = file_get_contents("https://www.gov.je/Datasets/ListOpenData?ListName=COVID19&type=json");
      $arr_json = json_decode($json, true);
      $cases = intval($arr_json["COVID19"][0]["CasesCurrentKnownActiveCases"]);
      $date = date("Y-m-d", strtotime($arr_json["COVID19"][0]["Date"]));
      $title = "Total current cases: " . $cases . " as of " . $date;
      $known = 1;
    } else {
      $title = "Unknown location specified";
      $known = 0;
    }
  }
?>
<!DOCTYPE html>
<html lang="en">
  <head>
    <title><?php echo $title; ?></title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <link rel="icon" type="image/png" href="favicon.png">
    <!-- Favicon from https://en.wikipedia.org/wiki/File:Coronavirus._SARS-CoV-2.png and licensed under CC BY-SA 4.0. -->
  </head>
  <body>
    <p>
<?php
  if ($known == 1) {
    echo "<small><a href=\"./\">Home</a></small></p>";
    echo "<p>Total current COVID-19 cases in " . $location . ": <b>" . $cases . "</b> as of <b>" . $date . "</b>\n";
  } else if ($known == 0) {
    echo "Unknown location specified\n";
  }

  if ($known != -1) {
    echo "</p><p>";
  }
?>
      Pick a location:<br>
      <a href="./jersey">Jersey</a>
    </p>
    <p>
      <small><a href="./index.phps">Source?</a></small>
    </p>
  </body>
</html>