or similar if you wanted a subheading on a bigger page
// NOAA-style Climate Reports
}
// NOAA-reports.php
// Author: Ken True webmaster@saratoga-weather.org
// Version: 1.02 12-Mar-2006
//
// Permission is given to freely use and/or modify this script for
// private, non-commercial usage.
// No warranty is expressed or implied .. use at your own risk.
//
$Naming = 'WL'; // set to 'WL' or 'VWS'
// Note: WeatherLink conventions:
// NOAAMO.TXT, NOAAYR.TXT for current month and current year
// NOAAPRMO.TXT, NOAAPRYR.TXT for last month, last year
// NOAAyyyy.TXT for year 'yyyy' summary
// NOAAyyyy-mm.TXT for month 'mm' in year 'yyyy' summary
//
// VWS naming format
// noaamo.txt,noaayr.txt for current month and current year
// yyyy.txt for year 'yyyy' summary
// yyyy_mm.txt for month 'mm', year 'yyyy' summary.
//
// Weather-Display naming format
// (to be done)
//
// MK - added variable to get the server's absolute path to webroot.
// MK - assumes that this file lives in the "webroot/WeatherLink" folder.
// MK - assumes that WL report uploads are in the "webroot/WeatherLink/Reports" folder.
if ($Naming == 'WL') {
$NOAAdir = realpath($_SERVER["DOCUMENT_ROOT"]).'/WeatherLink/Reports'; // point to your NOAA file sub-directry
$ThisYearFile = "$NOAAdir/NOAAYR.TXT"; // point to your current NOAA yearly file
$ThisMonthFile= "$NOAAdir/NOAAMO.TXT"; // point to your current NOAA monthly file
$LastYearFile = "$NOAAdir/NOAAPRYR.TXT"; // point to your prior NOAA yearly file
$LastMonthFile= "$NOAAdir/NOAAPRMO.TXT"; // point to your prior NOAA monthly file
}
// MK - didn't change this bit as I'm not familiar with VWS
if ($Naming == 'VWS') {
$NOAAdir = './noaa'; // point to your NOAA file sub-directry
$ThisYearFile = "$NOAAdir/noaayr.txt"; // point to your current NOAA yearly file
$ThisMonthFile= "$NOAAdir/noaamo.txt"; // point to your current NOAA monthly file
}
// MK - Omit the reference to the file and replace with the full URI stripped of GET variables
// MK - use a code-snippet from http://stackoverflow.com/questions/1251582/beautiful-way-to-remove-get-variables-with-php
// to strip the querystrings from the URI
// $PHP_SELF = $_SERVER['PHP_SELF'];
$PHP_SELF = strtok($_SERVER['REQUEST_URI'], '?');
putenv("TZ=$ourTZ");
$now = getdate();
// print "\n";
$now_month = sprintf("%02d",$now['mon']);
$now_year = $now['year'];
$prior_month = $now['mon'] - 1;
$prior_year = $now['year'];
$last_year = $prior_year -1;
if ($prior_month < 1) {$prior_month = 12; $prior_year--;}
$prior_month = sprintf("%02d",$prior_month);
print "\n";
print "\n";
if ($Naming == 'WL') { // check for month/year rollover and update
if(! file_exists("$NOAAdir/NOAA$prior_year-$prior_month.TXT") and
file_exists($LastMonthFile) ) {
print "\n";
if (copy($LastMonthFile,"$NOAAdir/NOAA$prior_year-$prior_month.TXT")) {
print "\n";
} else {
print "\n";
}
}
if(! file_exists("$NOAAdir/NOAA$last_year.TXT") and
file_exists($LastYearFile) ) {
print "\n";
if (copy($LastYearFile,"$NOAAdir/NOAA$last_year.TXT")) {
print "\n";
} else {
print "\n";
}
}
}
$months = array( "01"=>"Jan", "02"=>"Feb", "03"=>"Mar",
"04"=>"Apr", "05"=>"May", "06"=>"Jun",
"07"=>"Jul", "08"=>"Aug", "09"=>"Sep",
"10"=>"Oct", "11"=>"Nov", "12"=>"Dec"
);
if ($handle = opendir("$NOAAdir")) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
$files[] = $file;
}
}
closedir($handle);
sort($files);
$lastyear = '';
echo "\n";
// set up the files and find the first and last year for reports
$first_year = "";
foreach ($files as $key => $file) {
if ($Naming == 'WL') {
$year = substr($file,4,4);
} elseif ($Naming == 'VWS') {
$year = substr($file,0,4);
}
if (! preg_match("/^\d{4}$/",$year) ) { continue;} //make sure year is numeric
$filesfound["$file"] = 1;
if (!$first_year) { $first_year = $year; }
$last_year = $year;
}
if (! $first_year) {
// MK - Change to
and omit as output is going into a page body.
// echo "
Sorry... no NOAA-style reports found.";
// echo "