Welcome to the Cumulus Support forum.

Latest Cumulus MX release 3.6.5 (build 3081) - 28 May 2020 (please see important announcement regarding releases since 3.5.0)
Legacy Cumulus 1 release v1.9.4 (build 1099) - 28 November 2014 (a patch is available for 1.9.4 build 1099 that extends the date range of the NOAA report and Snow Index drop-down menus to 2030)

See the Wiki to download the software or click on the Downloads link in the Forum Banner.

PHP Web 'viewer' for Cumulus NOAA Style reports

Other discussion about creating web sites for Cumulus that doesn't have a specific subforum

Moderator: daj

User avatar
PaulMy
Posts: 2129
Joined: Sun 28 Sep 2008 11:54 pm
Weather Station: Davis Vantage Pro 2+ w/Envoy USB
Operating System: Windows-8
Location: Komoka, ON Canada
Contact:

Re: PHP Web 'viewer' for Cumulus NOAA Style reports

Post by PaulMy »

Each month and years work and display fine from here. In IE10 and only on selecting 2011 and any months in 2011 then that array of Year/Month rearranges a bit but still works.

Paul

User avatar
duke
Posts: 840
Joined: Sun 03 Jul 2011 6:23 pm
Weather Station: Davis VP2 Plus - 24hr FARS
Operating System: Windows 10 - 64 bit
Location: Eastleigh, Hampshire, UK
Contact:

Re: PHP Web 'viewer' for Cumulus NOAA Style reports

Post by duke »

PaulMy wrote:only on selecting 2011 and any months in 2011 then that array of Year/Month rearranges a bit but still works.
Yeah I notice that, but beteljuice's example page does the same when you select the last year - http://www.beteljuice.co.uk/NOAA2/ug2.php?yr=2008&mo=11

edit: I have now saved all my NOAA reports in UTF-8 and removed beteljuice's work-around and no strange symbols.

On another slightly different note, I like to keep all my CSS in the same directory so I added:

line 90

Code: Select all

  $CSSdir = 'css/';      // point to your CSS directory
line 158

Code: Select all

if (!file_exists($CSSdir . 'noaarep.css')) { createcss();}
works fine but if I also modify line 626

Code: Select all

$handle = fopen($CSSdir . 'noaarep.css', 'w');
the script at this point fails to see the previous declaration at line 90 and throws an undeclared error.
Duke

Nightingale Weather
Eastleigh, Hampshire, UK
------------------------------------------------------
Validate your pages - often!

User avatar
mcrossley
Posts: 6479
Joined: Thu 07 Jan 2010 9:44 pm
Weather Station: Davis VP2
Operating System: Buster Lite rPi
Location: Wilmslow, Cheshire, UK
Contact:

Re: PHP Web 'viewer' for Cumulus NOAA Style reports

Post by mcrossley »

If line 626 is in a function (?), you will need to declare $CSSdir as a global variable.

User avatar
duke
Posts: 840
Joined: Sun 03 Jul 2011 6:23 pm
Weather Station: Davis VP2 Plus - 24hr FARS
Operating System: Windows 10 - 64 bit
Location: Eastleigh, Hampshire, UK
Contact:

Re: PHP Web 'viewer' for Cumulus NOAA Style reports

Post by duke »

mcrossley wrote:If line 626 is in a function (?), you will need to declare $CSSdir as a global variable.
Voila, and embarrassingly I should have realized that :shock:

Thanks Mark.
global $CSSdir;
$handle = fopen($CSSdir . 'noaarep.css', 'w');
fwrite($handle, $op);
fclose($handle);
} // END function createcss()
Duke

Nightingale Weather
Eastleigh, Hampshire, UK
------------------------------------------------------
Validate your pages - often!

dygon
Posts: 24
Joined: Tue 02 Dec 2014 9:04 pm
Weather Station: Oregon WMR200
Operating System: windows 7
Location: Italia

Re: PHP Web 'viewer' for Cumulus NOAA Style reports

Post by dygon »

Hi I have copied the zip file to the post 1 and made references to my .txt file, but I get this message:
Sorry ... no NOAA-style reports found.

where am I wrong?

User avatar
beteljuice
Posts: 2918
Joined: Tue 09 Dec 2008 1:37 pm
Weather Station: None !
Operating System: ex XP SP3 - now W10 laptop grr
Location: Dudley, West Midlands, UK

Re: PHP Web 'viewer' for Cumulus NOAA Style reports

Post by beteljuice »

Have any NOAA reports been uploaded to your site ?
Is the path/ to the directory correct ?
Image
......................Imagine, what you will KNOW tomorrow !

dygon
Posts: 24
Joined: Tue 02 Dec 2014 9:04 pm
Weather Station: Oregon WMR200
Operating System: windows 7
Location: Italia

Re: PHP Web 'viewer' for Cumulus NOAA Style reports

Post by dygon »

one:
http://meteosoresina.altervista.org/NOAA/NOAAYR2014.txt

two:
http://meteosoresina.altervista.org/NOAA/NOAAMO1214.txt

path: /NOAA

Code: Select all

<?php
//------------------------------------------------
// safely display NOAA style text report files
// Author:  Ken True - webmaster@saratoga-weather.org
// Version: 1.02  12-Mar-2006 - Initial release
// Version: 1.03  13-Aug-2006 - added downloader and include capability
// Version: 1.04  01-Dec-2007 - added WL auto update for prior month/year rollover
// initialize request variables
// Version: 1.05  01-Jan-2008 - added timezone to fix year rollover issue
// Version: 1.06  03-Oct-2008 - added variables for WL LastMonth/LastYear files

$ourTZ = 'PST8PDT';		

$yr = 	isset($_REQUEST['yr']) ? $_REQUEST['yr'] : '';
$mo =   isset($_REQUEST['yr']) ? $_REQUEST['mo'] : '';
	
if ( isset($_REQUEST['sce']) and strtolower($_REQUEST['sce']) == 'view' ) {
   //--self downloader --
   $filenameReal = __FILE__;
   $download_size = filesize($filenameReal);
   header('Pragma: public');
   header('Cache-Control: private');
   header('Cache-Control: no-cache, must-revalidate');
   header("Content-type: text/plain");
   header("Accept-Ranges: bytes");
   header("Content-Length: $download_size");
   header('Connection: close');
   
   readfile($filenameReal);
   exit;
}	

$IncludeMode = false;
if (isset($_REQUEST['inc']) and strtolower($_REQUEST['inc']) == 'y') {
  $IncludeMode = true;
}
if (isset($doInclude)) {
  $IncludeMode = $doInclude;
}
	
if (! $IncludeMode ) {
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Refresh" content="300" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Cache-Control" content="no-cache" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>NOAA style reports</title>
</head>
<body>
  <h1 id="pageName">NOAA-style Climate Reports  </h1>
<?php 
}
// 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 = 'VWS';              // 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)
//
if ($Naming == 'WL') {
  $NOAAdir = './NOAA-reports'; // point to your NOAA file sub-directry
  $ThisYearFile = "./NOAAYR.TXT"; // point to your current NOAA yearly file
  $ThisMonthFile= "./NOAAMO.TXT"; // point to your current NOAA monthly file
  $LastYearFile = "./NOAAPRYR.TXT"; // point to your prior NOAA yearly file
  $LastMonthFile= "./NOAAPRMO.TXT"; // point to your prior NOAA monthly file
}
if ($Naming == 'VWS') {
  $NOAAdir = './NOAA';      // point to your NOAA file sub-directry
  $ThisYearFile = "$NOAAdir/NOAAYR2014.txt"; // point to your current NOAA yearly file
  $ThisMonthFile= "$NOAAdir/NOAAMO1214.txt"; // point to your current NOAA monthly file
}

$PHP_SELF = $_SERVER['PHP_SELF'];
putenv("TZ=$ourTZ");
$now = getdate();
// print "<!-- now \n" . print_r($now,true) . " -->\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 "<!-- parms: yr='$yr' mo='$mo' -->\n";
print "<!-- now='$now_year'-'$now_month' prior='$prior_year'-'$prior_month' -->\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 "<!-- copying $LastMonthFile to $NOAAdir/NOAA$prior_year-$prior_month.TXT -->\n";
	   if (copy($LastMonthFile,"$NOAAdir/NOAA$prior_year-$prior_month.TXT")) {
	     print "<!-- copy successful -->\n";
	   } else {
	     print "<!-- unable to copy -->\n";
	   }
   }

  if(! file_exists("$NOAAdir/NOAA$last_year.TXT") and
       file_exists($LastYearFile) ) {
	   print "<!-- copying $LastYearFile to $NOAAdir/NOAA$last_year.TXT -->\n";
	   if (copy($LastYearFile,"$NOAAdir/NOAA$last_year.TXT")) {
	     print "<!-- copy successful -->\n";
	   } else {
	     print "<!-- unable to copy -->\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 "<pre style=\"font-size: 9pt;\">\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) {
   echo "<h2>Sorry... no NOAA-style reports found.</h2>";
   echo $first_year;
   echo "</body></html>";
   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 "<a href=\"$PHP_SELF?yr=$yy\"><b>$yy</b></a>: ";
	} else {
	  echo " <b>$yy</b>: ";
   }

   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 "<a href=\"$PHP_SELF?yr=$yy&mo=$mm\"><b>" . $months[$mm]. "</b></a> ";
     } else {
	   if ($yy == $now_year && $mm == $now_month) {
	      echo  "<a href=\"$PHP_SELF\"><b>" . $months[$mm] ."</b></a> ";
	   } else {
	      echo  "<b>" . $months[$mm] ."</b> ";
	   }
	 }
	 if ($m < 12) {
       echo "| ";
	 } else {
	   echo "\n";
	 }
   }
 }
 
// Now give out the reports

 if (! $yr && ! $mo) {  // special for 'current month'
    echo "<br /><b>Report for $now_year $now_month</b>\n";
    $rpt = implode("",file("$ThisMonthFile"));
	echo "<br />\n";
	$rpt = preg_replace('|<|Uis','<',$rpt);
	echo $rpt;
  }

 if ($yr == $now_year && ! $mo) { // special for current year
    echo "<br /><b>Report for $now_year</b>\n";
    $rpt = implode("",file("$ThisYearFile"));
	echo "<br />\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 "<br /><b>Report for $yr $mo</b>\n";
	    $rpt = implode("",file("$NOAAdir/$testfile"));
  	     echo "<br />\n";
		$rpt = preg_replace('|<|Uis','<',$rpt);
	     echo $rpt;

	  } else {
	    echo "<br /><b>Sorry, no report for $yr $mo.</b><br /><br />\n";
      }
   }
 }
 
} 
echo "</pre>\n";
// echo "------- debugging -----\n";
// print_r($filesfound);
if (! $IncludeMode ) {
?>
</body>
</html>
<?php
}
?>


User avatar
beteljuice
Posts: 2918
Joined: Tue 09 Dec 2008 1:37 pm
Weather Station: None !
Operating System: ex XP SP3 - now W10 laptop grr
Location: Dudley, West Midlands, UK

Re: PHP Web 'viewer' for Cumulus NOAA Style reports

Post by beteljuice »

That script is NOT the script from this site !!!
Image
......................Imagine, what you will KNOW tomorrow !

dygon
Posts: 24
Joined: Tue 02 Dec 2014 9:04 pm
Weather Station: Oregon WMR200
Operating System: windows 7
Location: Italia

Re: PHP Web 'viewer' for Cumulus NOAA Style reports

Post by dygon »

Perfect now works.
I was convinced to have it downloaded here

THANK YOU

malkie
Posts: 72
Joined: Sun 02 Jan 2011 9:38 am
Weather Station: Davis Vision-Vue
Operating System: Raspbian Jessie
Location: Stevenage, Herts, UK

Re: PHP Web 'viewer' for Cumulus NOAA Style reports

Post by malkie »

PaulMy wrote:In IE10 and only on selecting 2011 and any months in 2011 then that array of Year/Month rearranges a bit but still works.

Paul
I've been trying to work out why the reports menu gets jumbled when viewing reports from 2011:

http://www.elmnet-weather.net/NOAA_repo ... 2011&mo=04

Click on the 'expand' button next to the year and the menu looks like this:

Image

Tried it with IE11 and Chrome, no change.

I have changed the NOAA-reports.php file to the newest version, 3.3, no change.

I can't work out why it changes the menu when you select the drop down box for the first year, any suggestions?
Malcolm
North Herts, UK
http://elm30net.ddns.net
CumulusMX on Raspberry Pi B+, running on Raspbian jessie, from a Davis Vantage Vue.

User avatar
beteljuice
Posts: 2918
Joined: Tue 09 Dec 2008 1:37 pm
Weather Station: None !
Operating System: ex XP SP3 - now W10 laptop grr
Location: Dudley, West Midlands, UK

Re: PHP Web 'viewer' for Cumulus NOAA Style reports

Post by beteljuice »

Looks alright in Firefox.

The only thing I can see is that you have some 'orphan' closing html statements in your page.

Code: Select all


  </tr> <---- REMOVE
</table> <---- REMOVE

<p class="credits"><br />
Page updated 01/Feb/2015 12:00:02<br />
Image
......................Imagine, what you will KNOW tomorrow !

malkie
Posts: 72
Joined: Sun 02 Jan 2011 9:38 am
Weather Station: Davis Vision-Vue
Operating System: Raspbian Jessie
Location: Stevenage, Herts, UK

Re: PHP Web 'viewer' for Cumulus NOAA Style reports

Post by malkie »

beteljuice wrote:Looks alright in Firefox.

The only thing I can see is that you have some 'orphan' closing html statements in your page.

Code: Select all


  </tr> <---- REMOVE
</table> <---- REMOVE

<p class="credits"><br />
Page updated 01/Feb/2015 12:00:02<br />
Thanks for pointing that out, but it hasn't helped.

If I expand the menu while 2013 (for example) is displayed, the menu table has <br /> characters between lines:

<!-- parms: yr='2013' mo='' -->
<!-- now='2015'-'02' prior='2015'-'01' -->
<div class="noaa_rep_container">
<div class="noaa_rep_nav_container">
Select a Year or Month report<br />
<div id="all_nav" style="display: inline;">
<span id="nav_updown" class="noaa_rep_nav noaa_expand_alt" onClick="switch_nav();">V/&#923:
(All the month buttons in here:)
class="noaa_rep_nav ">Dec</span>
<br />
<span class="noaa_rep_nav noaa_expand_alt" onClick="switch_nav();">V/&#923
(All the month buttons in here:)
class="noaa_rep_nav ">Dec</a>
</span><br />

etc etc.......

If I expand the menu for 2011, the <br/> character between the rows is missing. So now I know what is happening, have to find out what creates it...

Edit:

I can see a line in NOAA-reports.php that reads:

if($yr != $first_year) { $full_nav2 .= "<br />\n";}

This is the only line that seems to be special for the first year of the reports.

I've looked through 'full_nav2' but cannot see anything missing. Mark's site works properly so I guess the script must be OK, but I can't see any reason why the line breaks should be missing only when the first year is selected and no month is selected other than something wrong in the script.

I need a drink!
Malcolm
North Herts, UK
http://elm30net.ddns.net
CumulusMX on Raspberry Pi B+, running on Raspbian jessie, from a Davis Vantage Vue.

User avatar
beteljuice
Posts: 2918
Joined: Tue 09 Dec 2008 1:37 pm
Weather Station: None !
Operating System: ex XP SP3 - now W10 laptop grr
Location: Dudley, West Midlands, UK

Re: PHP Web 'viewer' for Cumulus NOAA Style reports

Post by beteljuice »

How very odd, you may just have found a bug, but why it only seems to affect you ????

Try changing line #432:

Code: Select all

if($yr != $first_year) { $full_nav2 .= "<br />\n";}
To ..

Code: Select all

if($y != $first_year) { $full_nav2 .= "<br />\n";}
See if that fixes things.
Image
......................Imagine, what you will KNOW tomorrow !

User avatar
mcrossley
Posts: 6479
Joined: Thu 07 Jan 2010 9:44 pm
Weather Station: Davis VP2
Operating System: Buster Lite rPi
Location: Wilmslow, Cheshire, UK
Contact:

Re: PHP Web 'viewer' for Cumulus NOAA Style reports

Post by mcrossley »

malkie wrote:Mark's site works properly so I guess the script must be OK
My page is based on an old version of the script, and I have modded it, so don't make any assumptions based on my page. Now, I must go and see if my page has the same bug! ....

User avatar
jdc
Posts: 142
Joined: Tue 19 Jun 2012 8:51 pm
Weather Station: Davis VP2 : Instromet
Operating System: Win 10 : Win XP
Location: Berwick-upon-Tweed, England.
Contact:

Re: PHP Web 'viewer' for Cumulus NOAA Style reports

Post by jdc »

Had a play with mine and found adjusting 'noaa_rep_container' width could cause this.

Try setting (in noaarep.css) yours to 590px - currently 635px.

Code: Select all

.noaa_rep_container {
    font-family: courier new, courier, monospace;
    width: 590px;
    margin: 0 auto;
	align: right;
}

Post Reply