station;
$network = $ctx->network;
$metadata = $ctx->metadata;
$alertmsg = "";
if (
isset($_GET["lat"]) &&
$_GET["lat"] != "move marker" &&
floatval($_GET["lat"]) != 0 &&
floatval($_GET["lat"]) != 1 &&
floatval($_GET["lat"]) != -1 &&
floatval($_GET["lon"]) != 0 &&
floatval($_GET["lon"]) != 1 &&
floatval($_GET["lon"]) != -1
) {
$client_ip = getClientIp();
// Log the request so to effectively do some DOS protection.
$pgconn = iemdb("mesosite");
$stname = iem_pg_prepare(
$pgconn,
"INSERT into weblog ".
"(client_addr, uri, referer, http_status) " .
"VALUES ($1, $2, $3, $4)"
);
pg_execute(
$pgconn,
$stname,
array(
$client_ip,
"/sites/site.php?network={$network}&station={$station}",
$_SERVER["HTTP_REFERER"],
404,
)
);
$newlat = floatval($_GET["lat"]);
$newlon = floatval($_GET["lon"]);
$email = get_str404("email", 'n/a');
$name = get_str404("name", "n/a");
$delta = (
($newlat - $metadata["lat"]) ** 2 +
($newlon - $metadata["lon"]) ** 2) ** 0.5;
$eburl = IEMConfig::EXTERNAL_BASEURL;
$msg = << REMOTE_ADDR: {$client_ip}
> ID: {$station}
> NAME: {$name} OLD: {$metadata["name"]}
> NETWORK: {$network}
> LON: {$newlon} OLD: {$metadata["lon"]}
> LAT: {$newlat} OLD: {$metadata["lat"]}
> EMAIL: {$email}
Review with suggested location: {$eburl}/sites/site.php?network={$network}&station={$station}&suggested_lat={$newlat}&suggested_lon={$newlon}
Original location: {$eburl}/sites/site.php?network={$network}&station={$station}
EOM;
if ((($delta > 0.0001) && ($delta < 0.5)) || (strpos($email, '@') > 0)) {
mail("akrherz@iastate.edu", "Please move {$station} {$network}", $msg);
}
// We are doing a GET request, so we don't want folks to bookmark this
header("Location: site.php?station={$station}&network={$network}&moved=1&suggested_lat={$newlat}&suggested_lon={$newlon}");
exit();
}
if (isset($_GET["moved"])) {
$moved_lat = isset($_GET["suggested_lat"]) ? sprintf("%.5f", floatval($_GET["suggested_lat"])) : null;
$moved_lon = isset($_GET["suggested_lon"]) ? sprintf("%.5f", floatval($_GET["suggested_lon"])) : null;
$coord_info = "";
if ($moved_lat && $moved_lon) {
$coord_info = " The red circle on the map shows your suggested location (Lat: {$moved_lat}, Lon: {$moved_lon}).";
}
$alertmsg = <<Thanks! Your suggested move was submitted for
evaluation.{$coord_info}
EOM;
}
$lat = sprintf("%.5f", $metadata["lat"]);
$lon = sprintf("%.5f", $metadata["lon"]);
// Check for suggested coordinates
$suggested_lat = isset($_GET["suggested_lat"]) ? sprintf("%.5f", floatval($_GET["suggested_lat"])) : null;
$suggested_lon = isset($_GET["suggested_lon"]) ? sprintf("%.5f", floatval($_GET["suggested_lon"])) : null;
$suggested_coordinates_info = "";
if ($suggested_lat && $suggested_lon) {
$suggested_coordinates_info = <<
Suggested Location Review: The blue marker shows the current database location,
and the red circle shows a suggested new location (Lat: {$suggested_lat}, Lon: {$suggested_lon})
submitted for review.
EOM;
}
$t = new MyView();
$t->iemselect2 = true;
$t->title = sprintf("Site Info: %s %s", $station, $metadata["name"]);
$t->headextra = <<
EOM;
$t->jsextra = <<
EOM;
$t->sites_current = "base";
/**
* Pretty print functions for station attribute keys and values.
* @param string $key The attribute key.
* @return string The pretty printed value.
*/
function pretty_key($key)
{
if ($key == "TRACKS_STATION") {
return "Data tracks station";
}
return $key;
}
/**
* Pretty print functions for station attribute values.
* @param string $key The attribute key.
* @param string $value The attribute value.
* @return string The pretty printed value.
*/
function pretty_value($key, $value)
{
if ($key == "TRACKS_STATION") {
$tokens = explode("|", $value);
return sprintf(
'%s [%s]',
$tokens[0],
$tokens[1],
$tokens[0],
$tokens[1]
);
}
return $value;
}
$attrtable = "";
if (sizeof($metadata["attributes"]) > 0) {
$attrtable .= <<Station Attributes:
These are key value pairs used by the IEM to do data management.
| Key / Description | Value |
EOM;
foreach ($metadata["attributes"] as $key => $value) {
$attrtable .= sprintf(
"| %s | %s |
",
pretty_key($key),
pretty_value($key, $value)
);
}
$attrtable .= "
";
}
$threading = "";
if ((strpos($network, "CLIMATE") > 0) && (substr($station, 2, 1) == "T")) {
$pgconn = iemdb("mesosite");
$stname = iem_pg_prepare(
$pgconn,
"SELECT t.id, t.network, t.name, s.begin_date, s.end_date " .
"from station_threading s " .
"JOIN stations t on (s.source_iemid = t.iemid) WHERE s.iemid = $1 " .
"ORDER by s.begin_date ASC"
);
$result = pg_execute($pgconn, $stname, array($metadata["iemid"]));
if (pg_num_rows($result) > 0) {
$threading = <<Station Threading:
This station threads together data from multiple stations to provide a
long term record for the location.
| Station | Begin Date | End Date |
EOM;
}
while ($row = pg_fetch_assoc($result)) {
$threading .= sprintf(
"| %s (%s) | %s | %s |
",
$row["id"],
$row["network"],
$row["name"],
$row["id"],
$row["begin_date"],
$row["end_date"],
);
}
if (pg_num_rows($result) > 0) {
$threading .= "
";
}
}
/**
* Format a DateTime object as a string.
*
* @param DateTime|null $val The DateTime object to format.
* @return string The formatted date string or an empty string if null.
*/
function df($val){
if (is_null($val)){
return "";
}
return $val->format("Y-m-d");
}
$ab = df($metadata["archive_begin"]);
$ae = df($metadata["archive_end"]);
$wigos = "";
if (! is_null($metadata["wigos"])){
$wigos = sprintf(
"| WIGOS ID: | ".
"%s |
",
$metadata["wigos"],
$metadata["wigos"]);
}
$update_interface = <<Location Update Request
Is the location shown for this station wrong?
If so, please consider submitting a location submission by moving the marker
on the map and completing this form below.
{$suggested_coordinates_info}
EOM;
if (strpos($network, "COCORAHS") > 0) {
$update_interface = <<
Location information and name is controlled by the CoCoRaHS organization.
The IEM hopefully automagically syncs updates from them to the IEM database.
EOM;
}
$t->content = <<
| IEM Internal ID: | {$metadata["iemid"]} |
{$wigos}
| Station Identifier: | {$station} |
| Station Name: | {$metadata["name"]} |
| Network: | {$network} |
| County: | {$metadata["county"]} |
| State: | {$metadata["state"]} |
| Latitude: | {$lat} |
| Longitude: | {$lon} |
| Elevation [m]: | {$metadata["elevation"]} |
| Time Zone: | {$metadata["tzname"]} |
| Archive Begin: | {$ab} |
| Archive End: | {$ae} |
{$attrtable}
{$threading}
EOM;
$t->render('sites.phtml');