Undefined variable and Undefined offset in ajax-gizmo.php and ajax-dashboard.php

I transitioned from the Windows version of WD to a Pi running the Linux version about a year ago. I run the Saratoga templates on the webserver. At that time, some of my variables were not updating that I finally tracked down to needing copy testtags.txt to wxlocal.html. Yay!

I just noticed that my error.log file on hosting provider is growing. There errors are Undefined variable and Undefined offset in ajax-gizmo.php and ajax-dashboard.php.

On another forum, I found a clue that it is related to missing testtags.php in the proper format.

PHP Notice:  Undefined variable: moonage in /home/ybdxtooj/public_html/ajax-dashboard.php on line 275

The moonage line is is this in the current testags.php is

$moonage =  '5 ';	// current age of the moon (days since new moon)

If I look at one from my Windows setup from a couple of years ago I see this:

$moonage =  'Moon age: 21 days,8 hours,19 minutes,59%';	// current age of the moon (days since new moon)

Ajax-dashbord.php is looking for “Moon age:”

if($SITE['WXsoftware'] == 'WD') {
// Sample from WD: $moonage = "Moon age: 10 days,10 hours,41 minutes,80%";	// current age of the moon (days since new moon)
// Sample from WD: $moonphase = "80%";	// Moon phase %
  $moonagedays = preg_replace('|^Moon age:\s+(\d+)\s.*$|is',"\$1",$moonage);
  if($moonphase == '') { // MAC version of WD is missing this value
    preg_match_all('|(\d+)|is',$moonage,$matches);
    $moonphase  = $matches[1][3];
	if(isset($matches[1][4])) {
	  $moonphase .= '.' . $matches[1][4]; // pick up decimal;
	  $moonphase = round($moonphase,0);
	}
	$moonphase .= '%';
  }
} else { // perform non-WD moon stuff
	$mooninfo = cGetMoonInfo();  /* Note:  getMoonInfo() is located in common.php */

I am using the testtags.txt that is in the Linux wd distro: Version 1.07 - 22-Jul-2011.

I am thinking there is something amiss in the Linux version of wdconsole and the creation of testtags.php. Am I missing somethign obvious? Something I overlooked in setup?

I think it’s one of the differences between WD on Windows and WD on Linux. The dashboard is expecting to see the full $moonage from windows as your showed above. It’s getting the truncated version, so you get the undefined Notice.

You can avoid the problem by changing

if($SITE['WXsoftware'] == 'WD') {

to

if(false and $SITE['WXsoftware'] == 'WD') {

in two places in ajax-dashboard.php – then it will avoid decoding the (faulty) $moonage and rely on internal calculations instead.

Thanks. I will give that a go.

Thanks again Ken for the suggestion above.

The remaining piece was in the moonphase function . ajax-gizmo and ajax-dashboard are much happier.

function moonphase ($WDmoonage) {

  preg_match_all('|(\d+)|is',$WDmoonage,$matches);
//  print "<!-- matches=\n" . print_r($matches,true) . "-->\n";
  $mdays = $matches[1][0];        
  //$mhours = $matches[1][1];   // linux version of WD returns only in days
  //$mmins = $matches[1][2];    // linux version of WD returns only in days
  //$mpct  = $matches[1][3];    // linux version of WD returns only in days
  //
  
  //  Set to zero because moonage returns something different DAE 1-1-2022  (See line 272)
  $mhours = 0;
  $mmins = 0;
  $mpct  = 0;
  
  $mdaysd = $mdays + ($mhours / 24) + ($mmins / 1440);

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.