to

to suit inclusion in a page body. // MK - in original file this section is outside the php markers // // // // // // // // // NOAA style reports // // // MK - you could uncomment the next line and change to

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 ""; echo "

Sorry... no NOAA-style reports found.

"; return; } // now create the index links based on which files we have // for ($y = $first_year; $y <= $now_year; $y++) { // above will do ascending sort by year in index // but we like the Index links sorted in descending year so // newest reports are at the top of the list // for ($y = $now_year; $y >= $first_year; $y--) { $yy = sprintf("%04d",$y); if ($Naming == 'WL') {$t = "NOAA$yy.TXT"; } if ($Naming == 'VWS') {$t = "$yy.txt"; } if ($filesfound[$t] || $yy == $now_year) { echo "$yy: "; } else { echo " $yy: "; } for ($m = 1; $m <= 12; $m++) { $mm = sprintf("%02d",$m); if ($Naming == 'WL') {$testfile = "NOAA$yy-$mm.TXT";} if ($Naming == 'VWS') {$testfile = "$yy" . "_" . "$mm.txt"; } if ($filesfound[$testfile]) { echo "" . $months[$mm]. " "; } else { if ($yy == $now_year && $mm == $now_month) { echo "" . $months[$mm] ." "; } else { echo "" . $months[$mm] ." "; } } if ($m < 12) { echo "| "; } else { echo "\n"; } } } // Now give out the reports if (! $yr && ! $mo) { // special for 'current month' echo "
Report for $now_year $now_month\n"; $rpt = implode("",file("$ThisMonthFile")); echo "
\n"; $rpt = preg_replace('|<|Uis','<',$rpt); echo $rpt; } if ($yr == $now_year && ! $mo) { // special for current year echo "
Report for $now_year\n"; $rpt = implode("",file("$ThisYearFile")); echo "
\n"; $rpt = preg_replace('|<|Uis','<',$rpt); echo $rpt; } else { // otherwise, process the requested year or year/month if ($yr) { if ($mo) { // month given if ($Naming == 'WL') {$testfile = "NOAA$yr-$mo.TXT";} if ($Naming == 'VWS') {$testfile = "$yr" . "_" . "$mo.txt";} } else { // no month given if ($Naming == 'WL') {$testfile = "NOAA$yr.TXT";} if ($Naming == 'VWS') {$testfile = "$yr.txt";} } // no month given if ($filesfound[$testfile]) { echo "
Report for $yr $mo\n"; $rpt = implode("",file("$NOAAdir/$testfile")); echo "
\n"; $rpt = preg_replace('|<|Uis','<',$rpt); echo $rpt; } else { echo "
Sorry, no report for $yr $mo.

\n"; } } } } echo "

\n"; // echo "------- debugging -----\n"; // print_r($filesfound); if (! $IncludeMode ) { ?> // } ?>