View Source to straighten things out ;-) (isset($SITE['uomTemp']) ? substr($SITE['uomTemp'], -1) : 'F'),
'rain' => (isset($SITE['uomRain']) ? substr($SITE['uomRain'], 1) : 'in'),
'wind' => (isset($SITE['uomWind']) ? substr($SITE['uomWind'], 1) : 'mph'),
'baro' => (isset($SITE['uomBaro']) ? substr($SITE['uomBaro'], 1) : 'inHg')
);
// language ........
$default_lang = 'en'; // 'look-up' array to use if not passed or defined elsewhere
// get language files - nothing for you here !!
(@include_once 'betel_dayfile_languages.php') OR die('FATAL ERROR - Language File FAIL !!');
// look for a 'posted' lang - change $_REQUEST['???'] name if DIY necessary
if (isset($_REQUEST["lang"]) && $_REQUEST["lang"] != '') { // change from $default_lang
if(array_key_exists($_REQUEST["lang"], $translit)) $dayfileLang = $_REQUEST["lang"];
// weatherbyyou check
} elseif (isset($_REQUEST["langue"]) && $_REQUEST["langue"] != '') { // change from $default_lang
if(array_key_exists($_REQUEST["langue"], $translit)) $dayfileLang = $_REQUEST["langue"];
// saratogaWX $SITE default lang
} else { // nothing found so far
if(isset($SITE["lang"])) { // Override $default_lang to $SITE default language
if(array_key_exists($SITE["lang"], $translit)) $dayfileLang = $SITE["lang"];
}
}
if(!isset($dayfileLang)) $dayfileLang = $default_lang;
// OK - continue ;-)
// which default 'table' do we want ?
if (!isset($_REQUEST["pane"])) {
$pane = 0; // 0 default - show 'daily', 1 - show 'seasonal'
} else {
$pane = $_REQUEST["pane"];
}
/*
$label_items FORMAT
array(*var name of data*,
menu button text,
table heading,
true OR false = show menu button - DO NOT COMMENT OUT LINE !!
NB: IF YOU DON'T HAVE or EVER HAD eg. a solar kit - SET TO false !
field# in data file (available from http://wiki.sandaysoft.com/a/Dayfile.txt),
'type' OR null = for units picker
'a' AND/OR 's' AND/OR 'h' AND/OR 'l' OR null - display (a)verage and / or (s)um, (h)i, (l)o for month(s)
)
*var name of data* - anything new MUST have any parsing / display code added !!
NOTE: Menu buttons will be displayed in the same order as the array ;-)
so adjust order to suit your options.
If you add any new items don't forget the trailing ',' on all but the last array line !
*/
$label_items = array(
'maxtemp' => array($translit[$dayfileLang]['maxtemp'][0], $translit[$dayfileLang]['maxtemp'][1], true, 6, 'temp', 'ahl'),
'mintemp' => array($translit[$dayfileLang]['mintemp'][0], $translit[$dayfileLang]['mintemp'][1], true, 4, 'temp', 'ahl'),
'tdiff' => array($translit[$dayfileLang]['tdiff'][0], $translit[$dayfileLang]['tdiff'][1], true, array(6, 4), 'temp', 'ahl'), // NB: Example of more than one data value grab
'avgtemp' => array($translit[$dayfileLang]['avgtemp'][0], $translit[$dayfileLang]['avgtemp'][1], true, 15, 'temp', 'ahl'),
'tappmax' => array($translit[$dayfileLang]['tappmax'][0], $translit[$dayfileLang]['tappmax'][1], true, 27, 'temp', 'ahl'),
'tappmin' => array($translit[$dayfileLang]['tappmin'][0], $translit[$dayfileLang]['tappmin'][1], true, 29, 'temp', 'ahl'),
'dpmax' => array($translit[$dayfileLang]['dpmax'][0], $translit[$dayfileLang]['dpmax'][1], true, 35, 'temp', 'ahl'),
'dpmin' => array($translit[$dayfileLang]['dpmin'][0], $translit[$dayfileLang]['dpmin'][1], true, 37, 'temp', 'ahl'),
'rhmax' => array($translit[$dayfileLang]['rhmax'][0], $translit[$dayfileLang]['rhmax'][1], true, 21, null, 'ahl'),
'rhmin' => array($translit[$dayfileLang]['rhmin'][0], $translit[$dayfileLang]['rhmin'][1], true, 19, null, 'ahl'),
'rainfall' => array($translit[$dayfileLang]['rainfall'][0], $translit[$dayfileLang]['rainfall'][1], true, 14, 'rain', 'sah'),
'windspd' => array($translit[$dayfileLang]['windspd'][0], $translit[$dayfileLang]['windspd'][1], true, 17, 'wind', 'ah'),
'windgust' => array($translit[$dayfileLang]['windgust'][0], $translit[$dayfileLang]['windgust'][1], true, 1, 'wind', 'ah'),
'windrun' => array($translit[$dayfileLang]['windrun'][0], $translit[$dayfileLang]['windrun'][1], true, 16, null, 'sah'),
'winddir' => array($translit[$dayfileLang]['winddir'][0], $translit[$dayfileLang]['winddir'][1], true, array(39, 17), null, 'a'), // NB: also looks for a windspeed to to be valid
'baromax' => array($translit[$dayfileLang]['baromax'][0], $translit[$dayfileLang]['baromax'][1], true, 10, 'baro', 'ahl'),
'baromin' => array($translit[$dayfileLang]['baromin'][0], $translit[$dayfileLang]['baromin'][1], true, 8, 'baro', 'ahl'),
'HoursSun' => array($translit[$dayfileLang]['HoursSun'][0], $translit[$dayfileLang]['HoursSun'][1], true, 24, null, 'sah'),
'Solar' => array($translit[$dayfileLang]['Solar'][0], $translit[$dayfileLang]['Solar'][1], true, 42, null, 'ah'),
'HighUV' => array($translit[$dayfileLang]['HighUV'][0], $translit[$dayfileLang]['HighUV'][1], true, 44, null, 'ah'),
'evt' => array($translit[$dayfileLang]['evt'][0], $translit[$dayfileLang]['evt'][1], true, 23, 'rain', 'sah'),
'heatday' => array($translit[$dayfileLang]['heatday'][0], $translit[$dayfileLang]['heatday'][1], true, 40, 'temp', 'sah'),
'coolday' => array($translit[$dayfileLang]['coolday'][0], $translit[$dayfileLang]['coolday'][1], true, 41, 'temp', 'sah')
);
// Cumulus provides 0 or 0.0 for missing or invalid data - this can make a nonsense of minimum and average values.
// The best thing to do is to edit your dayfile.txt and nullify (,,) any false data.
// However; depending upon your location, some datasets can reasonably be expected to be > 0 (remember these are daily values)
// These COULD include:
// ... 'windspd', 'windgust', 'windrun', 'HoursSun', 'Solar', 'HighUV', 'evt'
$SANITIZE = true; // true OR false - attempt to ignore zero in the following datasets:
// $zero_as_null = array('windspd', 'windgust', 'windrun', 'HoursSun', 'Solar', 'HighUV'); // datasets to 'fix' - EDIT TO SUIT
$zero_as_null = array('windspd', 'windgust', 'windrun'); // datasets to 'fix' - EDIT TO SUIT
// *** END * END * END USER VARIABLES *********************************************************************************************************
// parse / display code for defined datasets
function formatOP() {
global $rainDayInfo, $gradFactor, $thisValue, $part2, $dataSet, $decimals, $native, $maxsunhours, $bg_daily, $sunAvailable, $run_sun, $translit, $dayfileLang, $delim;
if ($thisValue <> '' || $thisValue == 0) {
if ($dataSet == 'windgust') {
$col = gustColour(DoWind($thisValue, 'mph')); // format to colour range uom
$part2 .= ' style="background-color:#' . $col[0] . '; color:#' . $col[1] . ';"';
$native = $thisValue;
$thisValue = delimIT(DoWind($thisValue, null)); // format to DISPLAY uom
}
if ($dataSet == 'windspd') {
$col = windColour(DoWind($thisValue, 'mph')); // format to colour range uom
$part2 .= ' style="background-color:#' . $col[0] . '; color:#' . $col[1] . ';"';
$native = $thisValue;
$thisValue = delimIT(DoWind($thisValue, null)); // format to DISPLAY uom
}
if ($dataSet == 'maxtemp' || $dataSet == 'mintemp' || $dataSet == 'avgtemp' || $dataSet == 'tappmax' || $dataSet == 'tappmin' || $dataSet == 'dpmax' || $dataSet == 'dpmin') {
$col = tempColour(DoTemp($thisValue, 'C')); // format to colour range uom
$part2 .= ' style="background-color:#' . $col[0] . '; color:#' . $col[1] . ';"';
$native = $thisValue;
$thisValue = delimIT(DoTemp($thisValue, null)); // format to DISPLAY uom
}
/* An example of a calculated value using more than one data field.
$thisValue *should* be an ARRAY of the data requested - the array will only exist if ALL data is present.
YOU need to remember in what order you asked for the data !
In the example below $thisValue[0] is max temp and $thisValue[1] is min temp.
HOWEVER: when doing averages, hi, lo, etc. OR heat / cooling days it will be a single value !!
NOTE: Although this is temp 'type', changing eg. one degree C > F is NOT the same as 1 deg C > F !!!
so we need another bit of code that does NOT give 32 +/- offset
*/
if ($dataSet == 'tdiff' || $dataSet == 'heatday' || $dataSet == 'coolday') {
if(is_array($thisValue)){ // we need to do some calculations with the multiple data
$native = $thisValue[0] - $thisValue[1]; // used to populate arrays for hi / lo / average
$col = tempColour(DoTempDiff($native, 'C')); // format to colour range uom
$thisValue = delimIT(DoTempDiff($native, null)); // format to DISPLAY uom
} else { // is a single value from hi / lo / avg
$native = $thisValue; // used to populate array for seasonal average
$col = tempColour(DoTempDiff($thisValue, 'C')); // format to colour range uom
$thisValue = delimIT(DoTempDiff($thisValue, null)); // format to DISPLAY uom
}
$part2 .= ' style="background-color:#' . $col[0] . '; color:#' . $col[1] . '"';
}
// END calculated example
if(!$gradFactor) $gradFactor = 1; // currently being used by rainfall / evt / windrun
if ($dataSet == 'rainfall' || $dataSet == 'evt') {
$col = rainColour(DoRain($thisValue / $gradFactor, 'mm')); // format to colour range uom;
$part2 .= ' style="background-color:#' . $col[0] . '; color:#' . $col[1] . '"';
$native = $thisValue;
$thisValue = delimIT(DoRain($thisValue, null)); // format to DISPLAY uom
}
if ($dataSet == 'windrun') {
$col = runColour(DoWind($thisValue / $gradFactor, 'mph')); // format to colour range uom;
$part2 .= ' style="background-color:#' . $col[0] . '; color:#' . $col[1] . '"';
$native = $thisValue;
$thisValue = delimIT(DoWind($thisValue, null)); // format to DISPLAY uom
}
if ($dataSet == 'winddir' && intval($thisValue) > 0) {
$thisValue = getHeading(intval($thisValue));
}
if ($dataSet == 'baromax' || $dataSet == 'baromin') {
$col = baroColour(DoBaro($thisValue, 'hPa')); // format to colour range uom;
$part2 .= ' style="background-color:#' . $col[0] . '; color:#' . $col[1] . '"';
$native = $thisValue;
$thisValue = delimIT(DoBaro($thisValue, null)); // format to DISPLAY uom
}
if ($dataSet == 'rhmax' || $dataSet == 'rhmin') {
$col = tempColour(((100 - $thisValue) / 2.5) -10); // a fiddle ;-)
$part2 .= ' style="background-color:#' . $col[0] . '; color:#' . $col[1] . '"';
$native = $thisValue;
// no Unit conversions to do - so 'format' directly
$thisValue = number_format((float)$thisValue, 0, '.' , '');
}
if ($dataSet == 'HighUV') {
$col = uvColour($thisValue);
$part2 .= ' style="background-color:#' . $col[0] . '; color:#' . $col[1] . '"';
$native = $thisValue;
// no Unit conversions to do - so 'format' directly
$thisValue = delimIT(number_format((float)$thisValue, 1, '.' , ''));
}
if ($dataSet == 'HoursSun'){ // based on code by Mark Crossley
$sundecimals = 1; // special case - not handled elsewhere
if($bg_daily === true) $maxsunhours = $sunAvailable;
$actual_txt = delimIT(round($thisValue, $sundecimals));
if($run_sun) {
$available_txt = (string)$sunAvailable;
} else {
$availble_txt = ''; // shouldn't be seen anyway !
}
$available_txt = delimIT($available_txt);
$part2 .= '>
' .
'' . $actual_txt . '
View Source to straighten things out ;-)";
readfile($filenameReal);
exit;
} else {
echo "
Tough ! - I changed the password !!! ";
}
}
// $disp DEcode look-up array
// (t)emp, (r)ain, (w)ind, (b)aro
$plank['t'] = array('0' => 'C', '1' => 'F');
$plank['r'] = array('0' => 'mm', '1' => 'in');
$plank['w'] = array('0' => 'mph', '1' => 'm/s', '2' => 'km/h', '3' => 'kts');
$plank['b'] = array('0' => 'hPa', '1' => 'mb', '2' => 'inHg');
// print_r($plank);
/* TABLE DISPLAY Units Of Measure */
$displayUOM = array('temp' => null, 'rain' => null, 'wind' => null, 'baro' => null); //
if (isset($_COOKIE["theseUOM"])) {
$displayUOM = $_COOKIE["theseUOM"]; // is an array from users browser if allowed
}
if (!isset($_REQUEST["disp"])) { // 1st time in - populate display units array from cookies if available else defaults
$disp = "";
if(!isset($displayUOM['temp'])) $displayUOM['temp'] = $uom['temp']; // no history - use default
if(!isset($displayUOM['rain'])) $displayUOM['rain'] = $uom['rain']; // no history - use default
if(!isset($displayUOM['wind'])) $displayUOM['wind'] = $uom['wind']; // no history - use default
if(!isset($displayUOM['baro'])) $displayUOM['baro'] = $uom['baro']; // no history - use default
} else {
$disp = $_REQUEST["disp"];
}
if (isset($_REQUEST["change"])) { // we already have display UOM set one way or another but user wants to change them
$flag1 = substr($_REQUEST["change"], 0, 1);
$flag2 = substr($_REQUEST["change"], 1, 1);
if($flag1 == "t"){
$displayUOM['temp'] = $plank['t'][$flag2];
}
if($flag1 == "r"){
$displayUOM['rain'] = $plank['r'][$flag2];
}
if($flag1 == "w"){
$displayUOM['wind'] = $plank['w'][$flag2];
}
if($flag1 == "b"){
$displayUOM['baro'] = $plank['b'][$flag2];
}
} // display units array has been updated
if (isset($_REQUEST["change"]) || !isset($_REQUEST["disp"])) { // rebuild $disp (to be carried around pages)
$disp = "";
if($displayUOM['temp'] == "C") $disp .= "t0";
if($displayUOM['temp'] == "F") $disp .= "t1";
if($displayUOM['rain'] == "mm") $disp .= "r0";
if($displayUOM['rain'] == "in") $disp .= "r1";
if($displayUOM['wind'] == "mph") $disp .= "w0";
if($displayUOM['wind'] == "m/s") $disp .= "w1";
if($displayUOM['wind'] == "km/h") $disp .= "w2";
if($displayUOM['wind'] == "kts") $disp .= "w3";
if($displayUOM['baro'] == "hPa") $disp .= "b0";
if($displayUOM['baro'] == "mb") $disp .= "b1";
if($displayUOM['baro'] == "inHg") $disp .= "b2";
}
// By now $disp MUST now exist AND be uptodate - However; $displayUOM might not be !!
// DEcode $disp to ensure $displayUOM is uptodate
$thislen = strlen($disp);
for($x = 0; $x <= $thislen-2; $x+=2) {
if(substr($disp, $x, 2) == "t0") $displayUOM['temp'] = "C";
if(substr($disp, $x, 2) == "t1") $displayUOM['temp'] = "F";
if(substr($disp, $x, 2) == "r0") $displayUOM['rain'] = "mm";
if(substr($disp, $x, 2) == "r1") $displayUOM['rain'] = "in";
if(substr($disp, $x, 2) == "w0") $displayUOM['wind'] = "mph";
if(substr($disp, $x, 2) == "w1") $displayUOM['wind'] = "m/s";
if(substr($disp, $x, 2) == "w2") $displayUOM['wind'] = "km/h";
if(substr($disp, $x, 2) == "w3") $displayUOM['wind'] = "kts";
if(substr($disp, $x, 2) == "b0") $displayUOM['baro'] = "hPa";
if(substr($disp, $x, 2) == "b1") $displayUOM['baro'] = "mb";
if(substr($disp, $x, 2) == "b2") $displayUOM['baro'] = "inHg";
}
// speed conversions --- mph, kts, m/s, km/h
$mph = array(1, 0.8689762, 0.44704, 1.60934);
$kts = array(1.1507794, 1, 0.514444, 1.852);
$ms = array(2.23694, 1.9438445, 1, 3.6);
$kmh = array(0.621371, 0.5399568, 0.277778, 1);
// temperature gradient colours
$tempGrad = array_merge(
gradient('3D0060','6100A7',100), // -50 > -40
gradient('6100A7','BA00FF',100), // -40 > -30
gradient('BA00FF','000096',100), // -30 > -20
gradient('000096','54509F',100), // -20 > -10
gradient('54509F','00FFD4',100), // -10 > 0
gradient('00FFD4','48FF00',100), // 0 > 10
gradient('48FF00','FFDD00',100), // 10 > 20
gradient('FFDD00','FF0000',100), // 20 > 30
gradient('FF0000','BC0000',100), // 30 > 40
gradient('BC0000','640000',100) // 40 > 50
);
// average wind speed colours
$windGrad0to50 = gradient('FFFFFF','FF0000',50);
// gust wind speed colours
$gustGrad0to80 = gradient('FFFFFF','FF0000',80);
// rainfall colours
$rainGrad0to30 = gradient('E8E8FF','0000FF',30);
// windrun colours
$runGrad0to300 = gradient('FFFFFF','00C000',300);
// barometer colours
$baroGrad900to1100 = gradient('FFFFFF','449a36',70);
// solar irradiance colours
$sunGrad0to10 = gradient('FFFF00','FF0000',1500); // value suggested by Graham64
// UV-I colours (=<1.6 is lo, >= 10 is hi) - gradients suggested by nossis
$uvGrad = array_merge(
gradient('96CC00','FFFF00',14), // 1.6 - 3.0
gradient('FFFF00','FF9928',30), // 3.0 - 6.0
gradient('FF9928','FF0000',20), // 6.0 - 8.0
gradient('FF0000','BF00BF',30), // 8.0 - 11.0
gradient('BF00BF','7D76AD',50) // 11.0 - 16.0
);
// windrun 'lookup' units
$wrun = array(
'mph' => "- miles",
'm/s' => "- km",
'km/h' => "- km",
'kts' => "- nm"
);
// ##### betel NEW graph stuff ###################################################################################################################
if(isset($_REQUEST['bgraph'])){ // TEST SITE ONLY - check for 'posted' value
$maxsunhours = $_REQUEST['bgraph'];
}
/************ Function Definitions *************/
function DoTemp($value, $to){ // convert temperatures
global $displayUOM, $uom, $decimals;
$temp_dec = 1;
$decimals = $temp_dec;
if(!$to) $to = $displayUOM['temp'];
if( $to== "F" && $uom['temp'] == "C"){ // C => F
return number_format((1.8* $value) + 32, $temp_dec, '.' , '');
} elseif($to == "C" && $uom['temp'] == "F"){ // F => C
return number_format(($value - 32) / 1.8, $temp_dec, '.' , '');
} else { // no change
return number_format((float)$value, $temp_dec, '.' , '');
}
} // END function DoTemp()
function DoTempDiff($value, $to){ // convert temperatures relative
global $displayUOM, $uom, $decimals;
$temp_dec = 1;
$decimals = $temp_dec;
if(!$to) $to = $displayUOM['temp'];
if( $to== "F" && $uom['temp'] == "C"){ // C => F
return number_format((1.8* $value), $temp_dec, '.' , '');
} elseif($to == "C" && $uom['temp'] == "F"){ // F => C
return number_format($value / 1.8, $temp_dec, '.' , '');
} else { // no change
return number_format((float)$value, $temp_dec, '.' , '');
}
} // END function DoTempDiff()
function DoRain($value, $to){ // convert rain units
global $displayUOM, $uom, $decimals;
if($displayUOM['rain'] == 'mm'){
$rain_dec = 1;
} else {
$rain_dec = 2;
}
$decimals = $rain_dec;
if(!$to) $to = $displayUOM['rain'];
if($uom['rain'] == "in" && $to == "mm"){ // in => mm
return number_format(($value * 25.4), $rain_dec, '.' , '');
} elseif($uom['rain'] == "mm" && $to == "in"){ // mm => in
return number_format(($value / 25.4), $rain_dec, '.' , '');
} else { // no change
return number_format((float)$value, $rain_dec, '.' , '');
}
} // END function DoRain()
function DoWind($value, $to) { // convert windspeeds
global $displayUOM, $uom, $mph, $kts, $kmh, $ms, $dataSet, $decimals;
$wind_dec = ($dataSet == 'windrun' ? 0: 1);
$decimals = $wind_dec;
if(!$to) $to = $displayUOM['wind'];
if($to == "mph") {
$ethel=0;
} else {
if($to == "kts") {
$ethel=1;
} else {
if($to == "m/s") {
$ethel= ($dataSet == 'windrun' ? 3 : 2);
} else {
if($to == "km/h") {
$ethel=3;
}}}
}
if($uom['wind'] == "mph") {
$factor = $mph[$ethel];
}
if($uom['wind'] == "kts") {
$factor = $kts[$ethel];
}
if($uom['wind'] == "m/s") {
$factor = ($dataSet == 'windrun' ? $kmh[$ethel] : $ms[$ethel]);
}
if($uom['wind'] == "km/h") {
$factor = $kmh[$ethel];
}
if($factor != 1){ // conversion required
return number_format($value * $factor, $wind_dec, '.' , '');
} else {
return number_format((float)$value, $wind_dec, '.' , '');
}
} // END function DoWind()
function DoBaro($value, $to){ // convert pressure units
global $displayUOM, $uom, $decimals;
$baro_dec = ($displayUOM['baro'] == 'inHg' ? 2 : 1);
$decimals = $baro_dec;
if(!$to) $to = $displayUOM['baro'];
if(($to == "hPa" || $to == "mb") && $uom['baro'] == "inHg"){ // inHg => hPa or mb
return number_format($value * 33.86388158,$baro_dec, '.' , '');
} elseif($to == "inHg" && ($uom['baro'] == "hPa" || $uom['baro'] == "mb")){ // hPa or mb => inHg
return number_format($value / 33.86388158,$baro_dec, '.' , '');
} else { // no change
return number_format((float)$value, $baro_dec, '.' , '');
}
} // END function DoBaro()
// *** MAIN table creation function *** //
function drawCalendar($tableYear) {
global $rainDayInfo, $gradFactor, $dataSet, $tableYear, $label_items, $data, $year_list, $displayUOM, $disp, $wrun, $season_data, $translit, $dayfileLang, $decimals, $type_data, $type_year, $thisValue, $part2, $pane, $native, $show_year_averages, $SANITIZE, $zero_as_null, $north_hemisphere, $buttons, $this_file_name, $windrunUnit, $maxsunhours, $bg_daily, $sunAvailable, $run_sun, $bg_maxyear, $delim, $typeS_year;
insane(); // user vars checks
readDayfile($tableYear, $dataSet);
what_delim();
$tablelayout = '
\n";
// END 'menu' and table 'title'
$tablelayout .= "
\n";
// daily summaries table
$tablelayout .= "
\n
\n";
$tablelayout .= "\n";
$tablelayout .= ''.$year_list.' ';
$monWindDir = array();
for ($m = 1; $m <= 12; $m++) {
$tablelayout .= '';
$monWindDir[$m] = array(0 => 0, 1 => 0, 2 => 0, 3 => 0, 4 => 0, 5 => 0, 6 => 0, 7 => 0, 8 => 0); // 'twitch fix'
}
$tablelayout .= " \n";
$wetday = array(1 => null, 2 => null, 2 => null, 3 => null, 4 => null, 5 => null, 6 => null, 7 => null, 8 => null, 9 => null, 10 => null, 11 => null, 12 => null);
$rd_season_data = array();
$monSum = array();
$bg_monSum = array();
for ($d = 1; $d <= 31; $d++) {
$tablelayout .= '';
$part1 = '';
$part2 = '';
for ($m = 1; $m <= 12; $m++) {
if ($d <= cal_days_in_month(CAL_GREGORIAN, $m, $tableYear)) {
$theDate = mktime(0,0,0,$m,$d,$tableYear);
$theDay = $translit[$dayfileLang]['dy'][date('w', $theDate)];
$part1 .= ''.$theDay.' ';
$part2 .=' ''){ // belts'n'braces
if($dataSet == 'winddir'){
if($thisValue[0] >0 && $thisValue[1] >0 ) {
$wval = round($thisValue[0] / 45);
$monWindDir[$m][$wval]++; // creating a 'counter' whose 'key' is the direction (0 > 7)
$thisValue = $thisValue[0];
} else {
$thisValue = '';
}
}
if($thisValue <> '') {
if($dataSet == "HoursSun" && $run_sun) $sunAvailable = maxsunhours($theDate); // new
formatOP(); // $thisValue is a global so doesn't need to be 'passed'
$part2 .= '>';
$part2 .= $thisValue; // may have been converted by formatOP()
if($dataSet == 'rainfall' && $native > 0) $wetday[$m] += 1;
$monSum[$m][] = $native;
if($dataSet == "HoursSun" ) $bg_monSum[$m][] = $sunAvailable; // new
if($dataSet == "HoursSun") $thisValue = true; // a fiddle because of the way it is formatted
}
}
}
}
}
if($thisValue == '') $part2 .= "\"> "; // *** attempted logic fix
} else { // not a valid day of month
$part2 .= ' ';
} // END valid days upto 31
$part2 .= ' ';
} // END months 1 > 12
$tablelayout .= $part1 .= ' ' .$d. '' . $part2; // stitch table together
$tablelayout .= " \n";
} // END days upto 31
// total / avg / hi / lo outputs (on-demand)
$line = false;
$exception = false;
if($calcSum){
if($dataSet == 'windrun') $decimals = 0;
$tablelayout .= "".$translit[$dayfileLang]['total'].": \n";
for ($m = 1; $m < 13; $m++) {
if(array_key_exists($m, $monSum)){
$short = (count($monSum[$m]) < cal_days_in_month(CAL_GREGORIAN, $m, $tableYear) ? "* " : "");
if($short) $exception = true;
$thisValue = array_sum($monSum[$m]);
$gradFactor = 30;
$part2 = '';
if($dataSet != 'HoursSun') formatOP();
$thatValue = "";
if($dataSet == 'HoursSun' && $run_sun) { // new stuff
if(array_key_exists($m, $bg_monSum)){
$bg_value = array_sum($bg_monSum[$m]);
$thatValue = ' title="' .$thisValue. ' (' .$bg_value. ' ' .$translit[$dayfileLang]['sunAdvisory'][4]. ')"';
$sunAvailable = round($bg_value, 1);
}
$tablelayout .= '' .$short.$thisValue. ' ';
} else { // NOT HoursSun
$tablelayout .= '' .$short.$thisValue. ' ';
}
} else {
$tablelayout .= ' ';
}
}
$tablelayout .= " \n";
$line = true;
} // END calcSum
if($calcAvg){ // windirection is an exception where we need to find 'dominant' value
if($dataSet == 'windrun') $decimals = 0;
$fixthis = ($line ? '' : ' topborder');
$tablelayout .= "".($dataSet == 'winddir' ? $translit[$dayfileLang]['dom'] : $translit[$dayfileLang]['avg']).": \n";
for ($m = 1; $m <= 12; $m++) {
$tablelayout .= ' $v){
if($v == $workMax){ // see if number of occurences = max
$thisValue = ($k === 0 ? 44 : $k * 45); // sort of put back into a degree range
break; // only looking for first (clockwise) event
}
}
} else { // everything that really needs averages
$thisValue = array_sum($monSum[$m]) / count($monSum[$m]);
if($dataSet == 'HoursSun' && $run_sun) { // new
$bg_value = array_sum($bg_monSum[$m]) / count($bg_monSum[$m]);
$sunAvailable = round($bg_value, 1);
}
$gradFactor = 1;
}
if($thisValue <> '' || (float)$thisValue === 0){
formatOP();
$short = (count($monSum[$m]) < cal_days_in_month(CAL_GREGORIAN, $m, $tableYear) ? "* " : "");
if($short) $exception = true;
$tablelayout .= " class=\"datacell" .$fixthis."\"".$part2.">".($dataSet != 'HoursSun' ? $short : '').$thisValue." ";
}else {
$tablelayout .= " class=\"datacell" .$fixthis."\"> ";
}
}else{
$tablelayout .= " class=\"datacell" .$fixthis."\"> ";
}
}
$tablelayout .= " \n";
$line = true;
} // END calcAvg
if($calcHi){
$fixthis = ($line ? '' : ' topborder');
$tablelayout .= "".$translit[$dayfileLang]['hi'].": \n";
for ($m = 1; $m <= 12; $m++) {
$tablelayout .= ' '' || (float)$thisValue === 0){
formatOP();
$short = (count($monSum[$m]) < cal_days_in_month(CAL_GREGORIAN, $m, $tableYear) ? "* " : "");
if($short) $exception = true;
$tablelayout .= " class=\"datacell" .$fixthis."\"".$part2.">".($dataSet != 'HoursSun' ? $short : '').$thisValue." ";
}else {
$tablelayout .= " class=\"datacell" .$fixthis."\"> ";
}
}else{
$tablelayout .= " class=\"datacell" .$fixthis."\"> ";
}
}
$tablelayout .= " \n";
$line = true;
} // END calcHi
if($calcLo){
$fixthis = ($line ? '' : ' topborder');
$tablelayout .= "".$translit[$dayfileLang]['lo'].": \n";
for ($m = 1; $m <= 12; $m++) {
$tablelayout .= ' '' || (float)$thisValue === 0){
formatOP();
$short = (count($monSum[$m]) < cal_days_in_month(CAL_GREGORIAN, $m, $tableYear) ? "* " : "");
if($short) $exception = true;
$tablelayout .= " class=\"datacell" .$fixthis."\"".$part2.">".($dataSet != 'HoursSun' ? $short : '').$thisValue." ";
}else {
$tablelayout .= " class=\"datacell" .$fixthis."\"> ";
}
}else{
$tablelayout .= " class=\"datacell" .$fixthis."\"> ";
}
}
$tablelayout .= " \n";
$line = true;
} // END calcLo
if($dataSet == 'rainfall' && $rainDayInfo === true) {
$fixthis = ($line ? '' : ' topborder');
$tablelayout .= " ";
for ($m = 1; $m <= 12; $m++) {
$tablelayout .= "" .$wetday[$m].($wetday[$m] ? "d" : ""). " ";
}
$tablelayout .=" \n";
}
$sanitized = '';
if($SANITIZE){ // we want to try to 'nullify' zero values in some datasets
foreach($zero_as_null as $S){
if($S == $dataSet){ // is this one of them ?
$sanitized = ' - '.$translit[$dayfileLang]['note'][2]; // prepare 'Note;' advisory
break;
}
}
}
$advisory = ""; // new
if($dataSet == "HoursSun") {
$advisory = " " .$translit[$dayfileLang]['sunAdvisory'][0]. " = ";
if($bg_daily) $advisory .= " " .$translit[$dayfileLang]['sunAdvisory'][1];
if($bg_maxyear) $advisory .= $maxsunhours. "h " .$translit[$dayfileLang]['sunAdvisory'][2];
if(!$bg_daily && !$bg_maxyear) $advisory .= $maxsunhours. "h " .$translit[$dayfileLang]['sunAdvisory'][3];
// 'daily' top note & key info
$tablelayout .= "" .$translit[$dayfileLang]['note'][0].": " . $advisory.
" " .$translit[$dayfileLang]['sunAdvisory'][8]. ": " .($bg_daily ? "max" : $maxsunhours). " " . (!$bg_daily ? "" .$translit[$dayfileLang]['sunAdvisory'][6]. " " : '').
($run_sun ? "(" .$translit[$dayfileLang]['sunAdvisory'][4]. ") " : ''). "" .$translit[$dayfileLang]['sunAdvisory'][7]. " 0
\n";
}
// 'Note:' line
$tablelayout .= "".$translit[$dayfileLang]['note'][0].": \n ".($exception ? "* ".$translit[$dayfileLang]['note'][1] : '').$sanitized. $advisory. " \n";
$tablelayout .= "
\n";
// END daily summaries table
// START year avg table
$tablelayout .= "
\n";
$tablelayout .= "\n";
// *** NEW for rain / evt / windrun totals
// put correct 'title / symbol' at side of top row
if($dataSet == 'winddir') {
$tablelayout .= ''.$translit[$dayfileLang]['dom'].' ';
} else {
if($dataSet == 'rainfall' || $dataSet == 'evt' || $dataSet == 'windrun') {
$tablelayout .= ''.$translit[$dayfileLang]['total'].' ';
} else {
$tablelayout .= ''.$translit[$dayfileLang]['avg'].' ';
}
}
$gradFactor = 30;
//
$tablelayout .= ''.$translit[$dayfileLang]['mn'][0].' '.$translit[$dayfileLang]['mn'][1].' '.$translit[$dayfileLang]['mn'][2].' '.$translit[$dayfileLang]['mn'][3].' '.$translit[$dayfileLang]['mn'][4].' '.$translit[$dayfileLang]['mn'][5].' '.$translit[$dayfileLang]['mn'][6].' '.$translit[$dayfileLang]['mn'][7].' '.$translit[$dayfileLang]['mn'][8].' '.$translit[$dayfileLang]['mn'][9].' '.$translit[$dayfileLang]['mn'][10].' '.$translit[$dayfileLang]['mn'][11].' ';
$tablelayout .= " \n";
$bert = count($type_year) -1;
$alltime = array(1 => array(), 2 => array(), 3 => array(), 4 => array(), 5 => array(), 6 => array(), 7 => array(), 8 => array(), 9 => array(), 10 => array(), 11 => array(), 12 => array());
$rtime = array(1 => array(), 2 => array(), 3 => array(), 4 => array(), 5 => array(), 6 => array(), 7 => array(), 8 => array(), 9 => array(), 10 => array(), 11 => array(), 12 => array());
$bg_alltime = array(1 => array(), 2 => array(), 3 => array(), 4 => array(), 5 => array(), 6 => array(), 7 => array(), 8 => array(), 9 => array(), 10 => array(), 11 => array(), 12 => array());
if($dataSet == 'winddir') {
for($zz = 1; $zz <= 12; $zz++){
$alltime[$zz] = array( 0 => 0, 1 => 0, 2 => 0, 3 => 0, 4 => 0, 5 => 0, 6 => 0, 7 => 0, 8 => 0);
}
}
$shortMon = array();
for ($d = $bert; $d >= 0; $d--) { // latest year first
$shortMon[$d] = array();
$tablelayout .= '';
$tablelayout .= ''.$type_year[$d].' ';
$yeartot = 0;
for ($m = 1; $m <= 12; $m++) {
$shortMon[$d][$m] = false;
$windd = array(0 => 0, 1 => 0, 2 => 0, 3 => 0, 4 => 0, 5 => 0, 6 => 0, 7 => 0, 8 => 0); // twitch fix
$wetday = array(1 => 0, 2 => 0, 2 => 0, 3 => 0, 4 => 0, 5 => 0, 6 => 0, 7 => 0, 8 => 0, 9 => 0, 10 => 0, 11 => 0, 12 => 0);
$tablelayout .= ' $v){
if($v <> ''){ // only take account of non null entries
if($dataSet == 'winddir'){
if($v[0] >0 && $v[1] >0) $windd[round($v[0] / 45)]++ ; // increment wind dir count
$v = '';
}
if(is_array($v)){ // we are dealing with something that needs calculating
$thisValue = $v;
formatOP(); // only want to use 'native' result
$thisValue = ''; // reset
$part2 = ''; // reset
$turd[] = $native;
} else { // 'normal' single piece of data
$turd[] = $v; // a 'normal' single data entry
if($dataSet == 'rainfall' && $v > 0) $wetday[$m] += 1;
// bargraph stuff #############
if($dataSet == "HoursSun" && $run_sun) {
$bg_y = $type_year[$d];
$bg_when = mktime(0,0,0, $m, $k, $bg_y);
$bg_turd[] = maxsunhours($bg_when);
}
// ### end
}
}
}
if($turd){
if($dataSet == 'winddir'){
$workMax = max($windd); // find highest occurrence
$found = false;
foreach($windd as $k => $v){
$alltime[$m][$k] += $v;
if($found !== true && $v == $workMax){ // see if number of occurrences = max
$thisValue = ($k == 0 ? 44 : $k * 45); // sort of put back into a degree range
$found = true; // only looking for first (clockwise) event
}
}
} else { // everything that really needs averages
// *** NEW FOR RAIN / EVT / WINDRUN TOTALS **
// do correct daily total OR avg calculation
if($dataSet == 'rainfall' || $dataSet == 'evt' || $dataSet == 'windrun') {
$thisValue = array_sum($turd);
// new experiment
$yeartot += array_sum($turd);
} else {
$thisValue = array_sum($turd) / count($turd);
}
//
// bar graph stuff ####################################
$thatvalue = "";
if($dataSet == 'HoursSun' && $run_sun){
$bg_value = round(array_sum($bg_turd) / count($bg_turd), 1);
$sunAvailable = $bg_value;
}
// end
}
}
if($thisValue || $thisValue == 0){
if($dataSet != 'winddir') $alltime[$m][] = $thisValue;
if($dataSet == 'rainfall' && $rainDayInfo) {
$rtime[$m][] = $wetday[$m];
if($m <3){
$rdy = $type_year[$d] - 1;
} else {
$rdy = $type_year[$d];
}
$rd_season_data[$rdy][$m] = $wetday[$m];
}
if($dataSet == 'HoursSun' && $run_sun) $bg_alltime[$m][] = $bg_value; // ### NEW bargraph stuff
$gradFactor = 30;
formatOP();
$short = (count($turd) < cal_days_in_month(CAL_GREGORIAN, $m, $type_year[$d]) ? "* " : "");
if(count($turd) < cal_days_in_month(CAL_GREGORIAN, $m, $type_year[$d])) $shortMon[$d][$m] = true ;
$tablelayout .= " class=\"datacell2\"".$part2.">".($dataSet != 'HoursSun' ? $short : '').$thisValue." ";
}else {
$tablelayout .= ' class="nondate"> ';
}
}else{
$tablelayout .= ' class="nondate"> ';
}
} // END month walk
$tablelayout .= " \n";
// echo "\n";
} // END year walk
// now do overall month averages
$tablelayout .= '';
if($dataSet == 'rainfall' && $rainDayInfo) {
$extra = " ϴ ";
}
$tablelayout .= ''.($dataSet == 'winddir' ? $translit[$dayfileLang]['dom'] : $translit[$dayfileLang]['avg']).' ';
for ($m = 1; $m <= 12; $m++) {
$tablelayout .= ' $v){
if($v == $workMax){ // see if number of occurences = max
$thisValue = ($k == 0 ? 44 : $k * 45); // sort of put back into a degree range
break; // only looking for first (clockwise) event
}
}
} else {
if(is_array($alltime[$m])) {
if(count($alltime[$m]) != 0) $thisValue = array_sum($alltime[$m]) / count($alltime[$m]);
}
}
if($thisValue){
if($dataSet == 'rainfall' && $rainDayInfo){ // how can I deal with genuine nowt ?
// echo "\n\n";
if(is_array($rtime[$m])) {
$extra .= " " .round((array_sum($rtime[$m]) / count($rtime[$m])), 1). "d ";
} else {
$extra .= " ";
}
}
if($dataSet == 'HoursSun' && $run_sun){
if(is_array($bg_alltime[$m])) {
if(count($bg_alltime[$m]) != 0) $bg_value = round(array_sum($bg_alltime[$m]) / count($bg_alltime[$m]), 1);
$sunAvailable = $bg_value;
}
}
$gradFactor = 30;
formatOP();
$short = "";
for ($d = $bert; $d >= 0; $d--) { // latest year first (not important)
if($shortMon[$d][$m]){
$short = "* ";
break;
}
}
$tablelayout .= " class=\"datacell2 topborder\"".$part2.">".($dataSet != 'HoursSun' ? $short : '').$thisValue."";
}else {
$tablelayout .= ' class="nondate topborder"> ';
}
}else{
$tablelayout .= ' class="nondate topborder"> ';
}
} // END month walk
$tablelayout .= " \n";
if($dataSet == 'rainfall') $tablelayout .= $extra. "\n";
// END overall year averages
$tablelayout .= "
\n
\n";
// END year averages table
// print_r($rd_season_data);
// SEASONAL summaries table
$tablelayout .= "
\n";
// $m_offset = array(null, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11); // simple offset 'look-up'
$m_offset = array(null, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2); // simple offset 'look-up'
$exception = false;
$tablelayout .= "
\n";
$tablelayout .='';
$tablelayout .=' ';
$tablelayout .=' ';
$tablelayout .=' ';
$tablelayout .=' ';
$tablelayout .=' ';
$tablelayout .=' ';
$tablelayout .=' ';
$tablelayout .=' ';
$tablelayout .=' ';
$tablelayout .=' ';
$tablelayout .=' ';
$tablelayout .=' ';
$tablelayout .=' ';
$tablelayout .= "\n";
$tablelayout .= ' ';
if($north_hemisphere) {
// $tablelayout .= ''.$translit[$dayfileLang]['season_1'].' ';
$tablelayout .= ''.$translit[$dayfileLang]['season_2'].' ';
$tablelayout .= ''.$translit[$dayfileLang]['season_3'].' ';
// $tablelayout .= ''.$translit[$dayfileLang]['season_4'].' ';
$tablelayout .= ''.$translit[$dayfileLang]['season_4'].' ';
$tablelayout .= ''.$translit[$dayfileLang]['season_1'].' ';
} else {
// $tablelayout .= ''.$translit[$dayfileLang]['season_3'].' ';
$tablelayout .= ''.$translit[$dayfileLang]['season_4'].' ';
$tablelayout .= ''.$translit[$dayfileLang]['season_1'].' ';
// $tablelayout .= ''.$translit[$dayfileLang]['season_2'].' ';
$tablelayout .= ''.$translit[$dayfileLang]['season_2'].' ';
$tablelayout .= ''.$translit[$dayfileLang]['season_3'].' ';
}
$tablelayout .= "\n ";
// months header row as a separate var so as it can be duplicated after predetermined # of entries
$monthRow = "\n";
$monthRow .= ' ';
// $monthRow .= ''.$translit[$dayfileLang]['mn'][11].' '.$translit[$dayfileLang]['mn'][0].' '.$translit[$dayfileLang]['mn'][1].' ';
$monthRow .= ''.$translit[$dayfileLang]['mn'][2].' '.$translit[$dayfileLang]['mn'][3].' '.$translit[$dayfileLang]['mn'][4].' ';
$monthRow .= ''.$translit[$dayfileLang]['mn'][5].' '.$translit[$dayfileLang]['mn'][6].' '.$translit[$dayfileLang]['mn'][7].' ';
$monthRow .= ''.$translit[$dayfileLang]['mn'][8].' '.$translit[$dayfileLang]['mn'][9].' '.$translit[$dayfileLang]['mn'][10].' ';
$monthRow .= ''.$translit[$dayfileLang]['mn'][11].' '.$translit[$dayfileLang]['mn'][0].' '.$translit[$dayfileLang]['mn'][1].' ';
$monthRow .= " \n";
$bert = count($typeS_year) -1;
for ($d = $bert; $d >= 0; $d--) { // latest year first
if($dataSet == 'rainfall' && $rainDayInfo) $rd_season_extra = " ";
$seasonTot = array(0 => array(), 1 => array(), 2 => array(), 3 => array());
$bg_seasonTot = array(0 => array(), 1 => array(), 2 => array(), 3 => array());
$thehardway = 0;
$shortSeason = array();
$sT = 0;
$season = array();
$rd_season = array();
$bg_season = array();
if($dataSet == 'winddir') {
for($zz = 0; $zz < 4; $zz++) {
$season[$zz] = array(0 => null, 1 => null, 2 => null, 3 => null, 4 => null, 5 => null, 6 => null, 7 => null, 8 => null);
}
}
$s = 0;
$fixrow = ($d === 0 ? "" : " bottomborder");
$widget = ''.$typeS_year[$d].' ';
if($dataSet == 'rainfall' && $rainDayInfo) {
// every 3 years show months row
if($bert - $d === 0 || $bert - $d === 3 || $bert - $d === 6 || $bert - $d === 9 || $bert - $d === 12 || $bert - $d === 15) $tablelayout .= $monthRow;
} else {
// every 5 years show months row
if($bert - $d === 0 || $bert - $d === 5 || $bert - $d === 10 || $bert - $d === 15) $tablelayout .= $monthRow;
}
// come on ... how long do you expect this prog or Cumulus to be used ????
// we will ALWAYS be at least outputting Avg
//total value - month (optional)
if($calcSum){
$gradFactor = 30;
$tablelayout .= '';
$tablelayout .= ''.$widget.$translit[$dayfileLang]['total'].' ';
$widget = '';
for ($m = 1; $m <= 12; $m++) {
if($m <4) $sT = 0;
if($m >= 4 && $m < 7) $sT = 1;
if($m >= 7 && $m < 10) $sT = 2;
if($m >= 10) $sT = 3;
$fixcol = ($m === 3 || $m === 6 || $m === 9 ? " rightborder" : "");
$tablelayout .= ' $v){
$native = '';
if($v <> ''){ // only take account of non null entries
if(is_array($v)){ // we are dealing with something that needs calculating
$thisValue = $v;
formatOP(true); // only want to use 'native' result
$thisValue = ''; // reset
$part2 = ''; // reset
$turd[] = $native;
} else { // 'normal' single piece of data
$turd[] = $v; // a 'normal' single data entry
// bargraph stuff #############
if($dataSet == "HoursSun" && $run_sun) {
$bg_y = $typeS_year[$d];
$bg_m = $m_offset[$m];
if($bg_m <3) $bg_y++; // I think I need to do that ??????????????
$bg_when = mktime(0,0,0, $bg_m, $k, $bg_y);
$bg_turd[] = maxsunhours($bg_when);
}
// ### end
}
}
}
if($turd) $thisValue = array_sum($turd);
if($dataSet == 'HoursSun' && $run_sun) $bg_value = array_sum($bg_turd);
if($thisValue){
$seasonTot[$sT][$thehardway] = $thisValue;
if($dataSet == 'HoursSun' && $run_sun) $bg_seasonTot[$sT][$thehardway] = $bg_value;
$thehardway++;
if($dataSet == 'HoursSun') {
$msh = $maxsunhours;
$sunAvailable = $bg_value;
$maxsunhours = $maxsunhours * count($turd);
}
if($dataSet != 'HoursSun') formatOP(true);
if($dataSet == 'HoursSun') $maxsunhours = $msh;
$short = (count($turd) < cal_days_in_month(CAL_GREGORIAN, $m_offset[$m], $typeS_year[$d]) ? "* " : ""); // doesn't matter about 'previous' December - will always be 31
if(count($turd) < cal_days_in_month(CAL_GREGORIAN, $m_offset[$m], $typeS_year[$d])) {
$shortSeason[$sT] = true;
}
// need this if we DON'T use formatOP
$actual_txt = delimIT($thisValue);
if($run_sun && $dataSet == "HoursSun") {
$available_txt = delimIT($bg_value);
} else {
$availble_txt = ''; // shouldn't be seen anyway !
}
if($dataSet != 'HoursSun') {
$tablelayout .= " class=\"datacell ".$fixcol."\"".$part2.">".$short.$actual_txt." ";
} else {
$tablelayout .= " class=\"graphcell ".$fixcol."\"".$part2.">".$short.$actual_txt. ($dataSet == 'HoursSun' && $run_sun ? " (" .$available_txt. ")" : "") ."";
}
} else {
$tablelayout .= ' class="nondate'.$fixcol.'"> ';
}
} else {
$tablelayout .= ' class="nondate'.$fixcol.'"> ';
}
}
$tablelayout .= " \n";
// total - season(s)
$tablelayout .= '';
$tablelayout .= ''.$widget.$translit[$dayfileLang]['total'].' ';
for($x = 0; $x < 4; $x++){ // step through seasons
$tablelayout .= '".$short.$actual_txt." ";
} else {
$tablelayout .= " class=\"graphcell" . $fixcol."\">".$short. $avail_txt.$actual_txt . "";
}
} else {
$tablelayout .= ' class="nondate'.$fixcol.'"> ';
}
}else{
$tablelayout .= ' class="nondate'.$fixcol.'"> ';
}
}
$tablelayout .= " \n";
} // END total(s) (option)
//hi value - must have
if($dataSet != 'winddir'){
$gradFactor = 1;
$tablelayout .= '';
$tablelayout .= ''.$widget.$translit[$dayfileLang]['hi'].' ';
$widget = '';
for ($m = 1; $m <= 12; $m++) {
$fixcol = ($m === 3 || $m === 6 || $m === 9 ? " rightborder" : "");
$tablelayout .= ' $v){
$native = '';
if($v <> ''){ // only take account of non null entries
if(is_array($v)){ // we are dealing with something that needs calculating
$thisValue = $v;
formatOP(); // only want to use 'native' result
$thisValue = ''; // reset
$part2 = ''; // reset
$turd[] = $native;
} else { // 'normal' single piece of data
$turd[] = $v; // a 'normal' single data entry
// bargraph stuff #############
if($dataSet == "HoursSun" && $run_sun) {
$bg_y = $typeS_year[$d];
$bg_m = $m_offset[$m];
if($bg_m <3) $bg_y++; // I think I need to do that ???????????????????????????????????????????????
$bg_when = mktime(0,0,0, $bg_m, $k, $bg_y);
$bg_turd[] = maxsunhours($bg_when);
}
// ### end
}
}
}
if($turd) $thisValue = max($turd);
if($dataSet == 'HoursSun') $sunAvailable = max($bg_turd);
if($thisValue){
formatOP();
if($dataSet == 'HoursSun') $maxsunhours = $msh;
$short = (count($turd) < cal_days_in_month(CAL_GREGORIAN, $m_offset[$m], $typeS_year[$d]) ? "* " : ""); // doesn't matter about 'previous' December - will always be 31
$tablelayout .= " class=\"datacell".$fixcol."\"".$part2.">".($dataSet != 'HoursSun' ? $short : '').$thisValue." ";
}else {
$tablelayout .= ' class="nondate'.$fixcol.'"> ';
}
}else{
$tablelayout .= ' class="nondate'.$fixcol.'"> ';
}
}
$tablelayout .= " \n";
} // END hi
//lo value - must have
if($dataSet != 'winddir' && $calcLo){
$gradFactor = 1;
$tablelayout .= '';
$tablelayout .= ''.$widget.$translit[$dayfileLang]['lo'].' ';
$widget = '';
for ($m = 1; $m <= 12; $m++) {
$fixcol = ($m === 3 || $m === 6 || $m === 9 ? " rightborder" : "");
$tablelayout .= ' $v){
$native = '';
if($v <> ''){ // only take account of non null entries
if(is_array($v)){ // we are dealing with something that needs calculating
$thisValue = $v;
formatOP(); // only want to use 'native' result
$thisValue = ''; // reset
$part2 = ''; // reset
$turd[] = $native;
} else { // 'normal' single piece of data
$turd[] = $v; // a 'normal' single data entry
}
}
}
if($turd) $thisValue = min($turd);
if($thisValue <> '' || $thisValue == 0){
formatOP();
$short = (count($turd) < cal_days_in_month(CAL_GREGORIAN, $m_offset[$m], $typeS_year[$d]) ? "* " : ""); // doesn't matter about 'previous' December - will always be 31
$tablelayout .= " class=\"datacell".$fixcol."\"".$part2.">".($dataSet != 'HoursSun' ? $short : '').$thisValue." ";
}else {
$tablelayout .= ' class="nondate'.$fixcol.'"> ';
}
}else{
$tablelayout .= ' class="nondate'.$fixcol.'"> ';
}
}
$tablelayout .= " \n";
} // END lo
// month avg value - must have
$tablelayout .= '';
$tablelayout .= ''.$widget.$translit[$dayfileLang]['avg'].' ';
$widget = '';
for ($m = 1; $m <= 12; $m++) {
$windd = array( 0 => 0, 1 => 0, 2 => 0, 3 => 0, 4 => 0, 5 => 0, 6 => 0, 7 => 0, 8 => 0);
if($m <4) $s = 0;
if($m >= 4 && $m < 7) $s = 1;
if($m >= 7 && $m < 10) $s = 2;
if($m >= 10) $s = 3;
$fixcol = ($m == 3 || $m == 6 || $m == 9 ? " rightborder" : "");
$tablelayout .= ' $v){
$native = '';
if($v <> ''){ // only take account of non null entries
if(is_array($v)){ // we are dealing with something that needs calculating
$thisValue = $v;
formatOP(); // only want to use 'native' result
$thisValue = ''; // reset
$part2 = ''; // reset
$turd[] = $native;
if($dataSet != 'winddir') $season[$s][] = $native;
} else { // 'normal' single piece of data
$turd[] = $v; // a 'normal' single data entry
$season[$s][] = $v;
// bargraph stuff #############
if($dataSet == "HoursSun" && $run_sun) {
$bg_y = $typeS_year[$d];
$bg_m = $m_offset[$m];
if($bg_m <3) $bg_y++; // I think I need to do that ??????????????????????????????????????????????????????????????????????????????????
$bg_when = mktime(0,0,0, $bg_m, $k, $bg_y);
$bg_turd[] = $bg_season[$s][] = maxsunhours($bg_when);
}
// ### end
}
}
if($dataSet == 'winddir' && isset($v[0]) && isset($v[1])){
if($v[0] >0 && $v[1] > 0) $windd[round($v[0] / 45)]++ ; // increment wind dir count
}
}
if($turd){
if($dataSet == 'winddir'){
$workMax = max($windd); // find highest occurrence
$season[$s] = array(0, 0, 0, 0, 0, 0, 0, 0, 0);
$found = false;
foreach($windd as $k => $v){
$season[$s][$k] += $v;
if($found !== true && $v == $workMax){ // see if number of occurrences = max
$thisValue = ($k == 0 ? 44 : $k * 45); // sort of put back into a degree range
$found = true; // only looking for first (clockwise) event
}
}
} else { // everything that really needs averages
$thisValue = array_sum($turd) / count($turd);
if($dataSet == 'HoursSun') $sunAvailable = round(array_sum($bg_turd) / count($bg_turd), 1);
}
}
if($thisValue || $thisValue === 0){
$gradFactor = 1;
formatOP();
if($dataSet == 'HoursSun') $maxsunhours = $msh;
$short = (count($turd) < cal_days_in_month(CAL_GREGORIAN, $m_offset[$m], $typeS_year[$d]) ? "* " : ""); // doesn't matter about 'previous' December - will always be 31
if(count($turd) < cal_days_in_month(CAL_GREGORIAN, $m_offset[$m], $typeS_year[$d])) $shortSeason[$s] = true;
$tablelayout .= " class=\"datacell".$fixcol."\"".$part2.">".($dataSet != 'HoursSun' ? $short : '').$thisValue." ";
}else {
$tablelayout .= ' class="nondate'.$fixcol.'"> ';
}
}else{
$tablelayout .= ' class="nondate'.$fixcol.'"> ';
}
if($dataSet == 'rainfall' && $rainDayInfo) {
if(array_key_exists($m_offset[$m], $rd_season_data[$typeS_year[$d]])) {
$rd_v = $rd_season_data[$typeS_year[$d]][$m_offset[$m]]; // ********************
} else {
$rd_v = 0;
}
$rd_season[$s][] = $rd_v;
$rd_season_extra .= "".$rd_v."d ";
}
} // end month walkthrough
$tablelayout .= " \n";
if($dataSet == 'rainfall' && $rainDayInfo) {
$rd_season_extra .= "\n";
}
// END month avg
// and finally (unless raindays is selected) ... season(s) avg value
$tablelayout .= '';
if($dataSet == 'rainfall' && $rainDayInfo) $fixrow = false;
$tablelayout .= ''.$translit[$dayfileLang]['avg'].' ';
for($x = 0; $x < 4; $x++){ // step through seasons
$tablelayout .= ' $v){
if($v == $workMax){ // see if number of occurences = max
$thisValue = ($k == 0 ? 44 : $k * 45); // sort of put back into a degree range
if($thisValue == 44) $thisValue = ''; // unhappy fiddle
break; // only looking for first (clockwise) event
}
}
} else {
$thisValue = '*';
}
} else {
$thisValue = array_sum($season[$x]) / count($season[$x]);
if($dataSet == 'HoursSun') $sunAvailable = round(array_sum($bg_season[$x]) / count($bg_season[$x]), 1);
}
if($thisValue != '*'){
if($thisValue || $thisValue === 0){
$gradFactor = 1;
formatOP();
$short = "";
if(array_key_exists($x, $seasonTot) && array_key_exists($x, $shortSeason)){
$short = "* ";
$exception = true;
}
$tablelayout .= " class=\"datacell center".$fixcol.$fixrow."\"".$part2.">".($dataSet != 'HoursSun' ? $short : '').$thisValue." ";
} else {
$tablelayout .= ' class="nondate'.$fixcol.$fixrow.'"> ';
}
}else{
$tablelayout .= ' class="nondate'.$fixcol.$fixrow.'"> ';
}
}else{
$tablelayout .= ' class="nondate'.$fixcol.$fixrow.'"> ';
}
} // END season walkthrough
$tablelayout .= " \n";
if($dataSet == 'rainfall' && $rainDayInfo) { // raindays
$tablelayout .= $rd_season_extra;
$fixrow = true;
$tablelayout .= ' ϴ ';
for($x = 0; $x < 4; $x++){ // step through seasons
$tablelayout .= '".$thisValue."d ";
} else {
$tablelayout .= ' class="nondate'.$fixcol.$fixrow.'"> ';
// $tablelayout .= ' class="nondate'.$fixcol.$fixrow.'"> ';
}
} // END season walkthrough
$tablelayout .= " \n";
} // end raindays
// *****************
} // END year walk-through
// bargraph - 'note' bar
$advisory = "";
if($dataSet == "HoursSun") {
$advisory = " " .$translit[$dayfileLang]['sunAdvisory'][0]. " = ";
if($bg_daily) $advisory .= " " .$translit[$dayfileLang]['sunAdvisory'][5];
if($bg_maxyear) $advisory .= $maxsunhours. "h " .$translit[$dayfileLang]['sunAdvisory'][2];
if(!$bg_daily && !$bg_maxyear) $advisory .= $maxsunhours. "h " .$translit[$dayfileLang]['sunAdvisory'][3];
$tablelayout .= "" .$translit[$dayfileLang]['note'][0].": " . $advisory.
" " .$translit[$dayfileLang]['sunAdvisory'][8]. ": " .($bg_daily ? "max" : $maxsunhours). " " . (!$bg_daily ? "" .$translit[$dayfileLang]['sunAdvisory'][6]. " " : '').
($run_sun ? "(" .$translit[$dayfileLang]['sunAdvisory'][4]. ") " : ''). "" .$translit[$dayfileLang]['sunAdvisory'][7]. " 0
\n";
}
// 'Note:' line
$tablelayout .= "".$translit[$dayfileLang]['note'][0].": \n ".($exception ? "* ".$translit[$dayfileLang]['note'][1] : '').$sanitized. $advisory. " \n";
$tablelayout .= "
\n";
$tablelayout .= "\n
\n"; // END season table 'holder'
$tablelayout .= "\n
\n"; // END tables 'holder
$tablelayout .= "
\n"; // END 'gilliam'
// output table(s) to page
echo $tablelayout;
//print_r($rd_season_data);
// 'write' page JavaScript
$script = '';
echo $script;
} // END function drawCalendar()
function readDayfile($tableYear, $dataSet) { // grab datafile and collect data 'type'
global $dayfile, $tableYear, $year_list, $disp, $label_items, $season_data, $type_data, $type_year, $translit, $dayfileLang, $delim, $SANITIZE, $zero_as_null, $delim, $date_sunsensorOK, $date_sunsensorFAIL, $testOK, $testFAIL, $typeS_year;
$current_year = '';
$season_year = ''; // shouldn't this be a GLOBAL array ?
$new_year = '';
$year_list = '
';
$typeS_year = array();
$sensor_flag = 0; // for HoursSun outside of loop
$fix = false;
if($SANITIZE){
foreach($zero_as_null as $S){
if($S == $dataSet){
$fix = true;
break;
}
}
}
foreach($label_items as $k => $v) {
if($k == $dataSet){
$dayfilecol = $v[3];
break;
}
}
$handle = @ fopen($dayfile, "r");
if($handle) {
@fseek($handle, 0);
$test_buff = fgets($handle); // trial
$field_delimiter = substr($test_buff, 8, 1); // trial
$testData = explode($field_delimiter, $test_buff); // trial
$date_delimiter = substr($testData[0], 2, 1); // trial
// cheat to see if . is dec delimiter
if (strpos($testData[4], ".") !==FALSE ){ // looking at 'must have' temperature, if true must be . #### moved ! trial
$delim = 0;
} else {
$delim = 1; // we assume dec delimiter must be ,
}
$handle = @ fopen($dayfile, "r");
// routine to check year of last data entry, will ONLY work if file path is relative NOT full url - beteljuice
@fseek($handle, -2, SEEK_END); // ### dosen't seem to be working any more ????? WAS -1
$pos = ftell($handle);
$LastLine = "";
// Loop backward until "\n" is found.
while((($C = fgetc($handle)) != "\n") && ($pos > 0)) {
$LastLine = $C.$LastLine;
@fseek($handle, $pos--);
}
@fseek($handle,0);
$lastData = explode($field_delimiter, $LastLine);
if ($lastData[0] != "") {
$datearr = explode($date_delimiter, $lastData[0]);
if ('20'.$datearr[2] < $tableYear) { $tableYear = '20'.$datearr[2];}
}
$valid_data = 0; // extra new for year null in drop down
while (!feof($handle)) {
$buffer = fgets($handle);
$buf_arr = explode($field_delimiter, $buffer);
if ($buf_arr[0] != "") {
$datearr = explode($date_delimiter, $buf_arr[0]);
$multi = is_array($dayfilecol);
if($multi){ // we are looking for more than one daily value
$stage1 = 0;
foreach($dayfilecol as $v){
($v < count($buf_arr) ? $stage1++ : $stage1--); // check if ALL fields exist
}
$ok = ($stage1 == count($dayfilecol) ? true : false);
} else { // looking for a single field
$ok = ($dayfilecol < count($buf_arr) ? true : false);
}
if($ok){
if($multi){ // we are looking for more than one daily value
$this_op = array();
foreach($dayfilecol as $v){
if($buf_arr[$v] <> ''){ // check field for content
$this_op[] = $buf_arr[$v];
}
}
if(count($dayfilecol) != count($this_op)) $this_op = ''; // if ALL requested values do NOT exist - junk it !
} else { // looking for a single field
$this_op = $buf_arr[$dayfilecol];
}
if($delim) $this_op = str_replace(",", ".", $this_op);
if($dataSet == "HoursSun" || $dataSet == "Solar" || $dataSet == "HighUV" && (float)$this_op == 0) {
$bg_m = (int)$datearr[1];
$bg_d = (int)$datearr[0];
$bg_y = (2000 + (int)$datearr[2]);
$data_when = mktime(0,0,0, $bg_m, $bg_d, $bg_y);
if(array_key_exists($sensor_flag, $testOK)) {
$rubicon = explode("/", $testOK[$sensor_flag]);
$checkOK_when = mktime(0,0,0, $rubicon[1], $rubicon[2], $rubicon[0]);
if($data_when < $checkOK_when) { // before OK - need to fix
$fix = true;
} else { // now it gets devious - what if there are subsequent fail dates ?
if(array_key_exists($sensor_flag, $testFAIL)) {
$rubicon = explode('/', $testFAIL[$sensor_flag]);
if(isset($rubicon[0]) && $rubicon[0] != "") {
$checkFAIL_when = mktime(0,0,0, $rubicon[1], $rubicon[2], $rubicon[0]);
if($data_when >= $checkFAIL_when) { // we are in a period of failure
if(array_key_exists($sensor_flag +1, $testOK)) $sensor_flag++; // at least one more period of OK to come
$fix = true;
} else { // we are inbetween OK and FAIL
$fix = false;
}
} else { // isset false
$fix = false;
} // end isset
} else { // after OK but no fail date(s)
$fix = false;
} // end sensorFAIL check
}
} else { // OK date(s) DOESN'T exist
$fix = true;
} // end OK date exists
}
if(!$fix || $fix && (float)$this_op > 0){
$valid_data++; // #### beteljuice NEW
if((int)$datearr[1] <= 2){ // record month
$pad = (int)$datearr[2]; // record year
if($pad > 10){
$pad = $pad -1;
}else{
$pad = '0'.($pad -1); // I was putting Dec into next year
}
if($this_op != null) $season_data['20'.$pad][(int)$datearr[1]][(int)$datearr[0]] = $this_op;
$new_year = '20'.$pad;
}else{
if($this_op != null) $season_data['20'.$datearr[2]][(int)$datearr[1]][(int)$datearr[0]] = $this_op;
$new_year = '20'.$datearr[2];
}
if($this_op != null) $type_data['20'.$datearr[2]][(int)$datearr[1]][(int)$datearr[0]] = $this_op;
}
}
if($season_year != $new_year){
if(!in_array($new_year, $typeS_year))$typeS_year[] = $new_year;
$season_year = $new_year;
}
//if(!in_array($new_year, $typeS_year))$typeS_year[] = $new_year;
if($valid_data > 0){ // #### beteljuice NEW condition line
if ('20'.$datearr[2] != $current_year) {
$current_year = '20'.$datearr[2];
if($valid_data == 1 && $tableYear < $current_year) $tableYear = $current_year; // earliest data shown if later than request year
$year_list .= '';
$type_year[] = '20'.$datearr[2]; // ### NEW
}
} // #### beteljuice END NEW condition Line
}
}
fclose($handle);
} else {
echo "Failed to open day file.";
}
$year_list .= ' ';
} // END function readDayfile()
function getHeading($deg) {
global $translit, $dayfileLang;
return $translit[$dayfileLang]['compass_headings'][round($deg / 45)];
} // END function getHeading()
function tempColour($temp) { // expects deg C
global $tempGrad;
$scaledVal = ($temp < -50 ? -50 : $temp);
$scaledVal = ($temp > 50 ? 50 : $temp);
$scaledVal = ($scaledVal *10) +500;
if($scaledVal == 1000) $scaledVal = 999;
$betel = $tempGrad[$scaledVal];
$text = ($temp >= 24 || $temp <= -4 ? 'FFF': '000');
$ret = array($betel, $text);
return $ret;
} // END function tempColour()
function gustColour($val) { // expects mph
global $gustGrad0to80;
$val =(int)$val;
if ($val > 79) $val = 79;
$text = ($val >= 36 ? 'FFF' : '000');
return array($gustGrad0to80[$val], $text);
} // END function gustColour()
function windColour($val) { // expects mph
global $windGrad0to50;
$val =(int)$val;
if ($val > 49) $val = 49;
$text = ($val >= 20 ? 'FFF' : '000');
return array($windGrad0to50[$val], $text);
} // END function windColour()
function runColour($val) { // expects miles
global $runGrad0to300;
$val =(int)$val;
if ($val > 299) $val = 299;
$text = ($val >= 200 ? 'FFF' : '000');
return array($runGrad0to300[$val], $text);
} // END function runColour()
function rainColour($val) { // expects mm
global $rainGrad0to30;
if ($val > 29) $val = 29;
$text= ($val >= 8 ? 'FFF' : '000');
$val = round($val);
if($val > 0){
return array($rainGrad0to30[$val],$text);
} else {
return array('FFF', $text);
}
} // END function rainColour()
function baroColour($val) { // expects hPa
global $baroGrad900to1100; // really 980 > 1050
$scaledVal = round(($val - 980));
if ($scaledVal < 0) $scaledVal = 0;
if ($scaledVal >= 69) $scaledVal = 69;
$text = ($val >= 1030 ? 'FFF' : '000');
return array($baroGrad900to1100[$scaledVal],$text);
} // END function baroColour()
function uvColour($val) {
global $uvGrad;
$text = ($val >= 7 ? 'FFF' : '000');
$val *= 10;
if ($val < 16) $val = 16;
$val -= 16;
if ($val > 99) $val = 99;
return array($uvGrad[$val],$text);
} // END function uvColour()
function sunColour($val) { // being used for irradiance
global $sunGrad0to10;
$text = ($val >= 800 ? 'FFF' : '000');
if ($val > 1499) $val = 1499;
return array($sunGrad0to10[$val],$text);
} // END function sunColour()
function gradient($startcol, $endcol, $graduations=10) {
$graduations--;
$RedOrigin = hexdec(substr($startcol,0,2));
$GrnOrigin = hexdec(substr($startcol,2,2));
$BluOrigin = hexdec(substr($startcol,4,2));
$GradientSizeRed = (hexdec(substr($endcol,0,2))-$RedOrigin)/$graduations; //Graduation Size Red
$GradientSizeGrn = (hexdec(substr($endcol,2,2))-$GrnOrigin)/$graduations;
$GradientSizeBlu = (hexdec(substr($endcol,4,2))-$BluOrigin)/$graduations;
for($i=0; $i<=$graduations; $i++) {
$RetVal[$i] =
str_pad(dechex($RedOrigin+($GradientSizeRed*$i)),2,'0',STR_PAD_LEFT) .
str_pad(dechex($GrnOrigin+($GradientSizeGrn*$i)),2,'0',STR_PAD_LEFT) .
str_pad(dechex($BluOrigin+($GradientSizeBlu*$i)),2,'0',STR_PAD_LEFT);
}
return $RetVal;
}
// build unit of measure options (call if required)
function picker($type) {
global $plank, $displayUOM, $disp, $tableYear, $dataSet;
$opt_list = '
';
$sub1 = substr($type, 0, 1);
$sub2 = 0;
foreach($plank[$sub1] as $k) {
$opt_list .= '';
$sub2++;
}
$opt_list .= " ";
return $opt_list;
} // END function picker()
// build dataset options (call if required)
function picker2() {
global $label_items, $displayUOM, $disp, $tableYear, $dataSet, $windrunUnit;
$opt_list = '
';
foreach($label_items as $k => $v) {
if($v[2] == true){
$opt_list .= '\n";
$whichOK = array('1972/1/1'); // early date so ALL readings will be treated as valid
$err_msg .= "FAIL: \$" .$commentOK. "(\'yyyy/m/d\') has at least one value MISSING\\n defaulting to \'1972/1/1\' ...\\n";
} else { // there is at least one entry - let's check it
echo "\n";
$error_check = '';
$davinci = explode("/", $whichOK[0]);
$mona = count($davinci);
if($mona != 3) $error_check .= "\$" .$commentOK. " - FAIL - wrongly formated " .$whichOK[0];
if($error_check) {
$whichOK = array('1972/1/1'); // early date so ALL readings will be treated as valid
echo "\n";
$err_msg .= "FAIL: \$" .$commentOK. "(\'yyyy/m/d\') wrongly formated \\n defaulting to (\'1972/1/1\') ...\\n";
}
} // end array_key etc
} else { // NOT an array !
echo "\n";
$whichOK = array('1972/1/1'); // early date so ALL readings will be treated as valid
$err_msg .= "FAIL: \$" .$commentOK. "(\'yyyy/m/d\') is NOT an array ! \\n defaulting to (\'1972/1/1\') ...\\n";
}
} else { // doesn't exist !!!
echo "\n";
$whickOK = array('1972/1/1'); // early date so ALL readings will be treated as valid
$err_msg .= "FAIL: \$" .$commentOK. "(\'yyyy/m/d\') DOES NOT EXIST ! \\n defaulting to (\'1972/1/1\') ...\\n";
} // end - OK date check - valid or sanitized values
$testOK = $whichOK;
echo "\n";
if($whichFAIL) { // check existence of date vars used for auto sanitize
if(is_array($whichFAIL)) {
if(!array_key_exists(0, $whichFAIL)) { // something missing
echo "\n";
$whichFAIL = array(''); // no date so ALL readings will be treated as valid
} else { // there is at least one entry - let's check it
echo "\n";
$error_check = '';
if(isset($whichFAIL[0]) && $whichFAIL[0] != '') {
$davinci = explode("/", $whichFAIL[0]);
$mona = count($davinci);
if($mona != 3) $error_check .= "\$" .$commentFAIL. " - FAIL - wrongly formated " .$whichFAIL[0];
} else {
$whichFAIL = array(''); // NO date so ALL readings will be treated as valid
echo "\n";
}
if($error_check) {
$whichFAIL = array(''); // NO date so ALL readings will be treated as valid
echo "\n";
$err_msg .= "FAIL: \$" .$commentFAIL. "(\'yyyy/m/d\') wrongly formated \\n defaulting to (\'\') ...\\n";
}
} // end array_key etc
} else { // NOT an array !
echo "\n";
$whichFAIL = array(''); // NO date so ALL readings will be treated as valid
$err_msg .= "FAIL: \$" .$commentFAIL. "(\'yyyy/m/d\') is NOT an array ! \\n defaulting to (\'\') ...\\n";
}
} else { // doesn't exist !!!
echo "\n";
$whichFAIL = array(''); // NO date so ALL readings will be treated as valid
$err_msg .= "FAIL: \$" .$commentFAIL. "(\'yyyy/m/d\') DOES NOT EXIST ! \\n defaulting to (\'\') ...\\n";
} // end - date sensor check - valid or sanitized values
$testFAIL = $whichFAIL;
echo "\n";
} // sensor date checks
if($dataSet == 'HoursSun') {
echo "\n\n";
if(isset($maxsunhours)) { // they've put some sort of something in there
echo "\n";
if(!is_numeric($maxsunhours) || $maxsunhours < 0 || $maxsunhours > 24 ) {
$err_msg .= "FAIL: \$maxsunhours invalid value: " .$maxsunhours. "\\n";
$maxsunhours = 24;
}
} else { // maxsunhours was NOT set
$maxsunhours = 24;
echo "\n";
$err_msg .= "FAIL: \$maxsunhours was NOT set\\n";
}
if(function_exists("date_sun_info")){ // check function existence !!!
echo "\n";
} else {
$run_sun = false;
echo "\n";
// fail 'quietly' $err_msg .= "FAIL: function date_sun_info does NOT exist ! : PHP v" .phpversion(). "\\n";
}
if($run_sun) { // no point in these checks if function doesn't exist
if(isset($bg_lat)) { // latitude checks
if(!is_numeric($bg_lat) || $bg_lat < -90 || $bg_lat > 90) {
$run_sun = false;
echo "\n";
$err_msg .= "FAIL: \$bg_lat Out Of Bounds: ".$bg_lat. " \\n";
}
} else { // wasn't set
$run_sun = false;
echo "\n";
$err_msg .= "FAIL: \$bg_lat NOT set ! \\n";
}
echo "\n";
if(isset($bg_lon)) { // longitude checks
if(!is_numeric($bg_lon) || $bg_lon < -180 || $bg_lon > 180) {
$run_sun = false;
echo "\n";
$err_msg .= "FAIL: \$bg_lon Out Of Bounds: ".$bg_lon. " \\n";
}
} else { // wasn't set
$run_sun = false;
echo "\n";
$err_msg .= "FAIL: \$bg_lon NOT set ! \\n";
}
echo "\n";
if(!isset($bg_time_zone)) { // nothing set - no other validation we can do really
echo "\n";
} else {
date_default_timezone_set($bg_time_zone); // set the tz as ordered
echo "\n";
}
} // end checks if run_sun OK (function exists)
if($maxsunhours == 0 || $maxsunhours == 1) {
if($run_sun) { // we can get max sun hours ;-)
if($maxsunhours == 0) { // longest day required
echo "\n";
if($bg_lat >= 0) {
$when = mktime(12, 0, 1, 6, 21); // longest day equator and North
} else {
$when = mktime(12, 0, 1, 12, 21); // longest day South
}
$maxsunhours = maxsunhours($when); // get longest day
$bg_maxyear = true;
} // END -longest day check and set
else { // $maxsunhours == 1 - daily scale wanted
echo "\n";
$bg_daily = true; // a flag that needs to be global
$maxsunhours = 24; // temp - will be set elsewhere
} // END $maxsunhours == 1 - daily scale wanted
} // END $run_sun true
else { // $run_sun_false
$maxsunhours = 24;
$sunAvailable = 0;
}
} // END $maxsunhours == 0 || $maxsunhours === 1)
// I think that's done it !!!!
echo "\n";
} // END Hours Sun checks
if($err_msg) {
// echo "";
echo "";
}
} // END function insane()
function maxsunhours($when) { // works out max available sun hours for a givenb datestamp
global $bg_lat, $bg_lon;
// $when is a unix time-stamp
$thisday = date( 'j',$when);
$sun_info = date_sun_info($when,$bg_lat, $bg_lon);
if($sun_info['sunrise'] > 1 ) { // numeric (datestamp) o/p
$upcheck = date( 'j',$sun_info['sunrise']);
if($upcheck != $thisday) {
$sun_info['sunrise'] = false;
}
}
if($sun_info['sunset'] > 1 ) { // numeric (datestamp) o/p
$downcheck = date( 'j',$sun_info['sunset']);
if($downcheck != $thisday) {
$sun_info['sunset'] = false;
}
}
if($sun_info['sunrise'] === true && $sun_info['sunset'] === true) $hours = 24;
if($sun_info['sunrise'] === false && $sun_info['sunset'] === false) $hours = 0;
if($sun_info['sunrise'] > 1 && $sun_info['sunset'] > 1) $hours = ($sun_info['sunset'] - $sun_info['sunrise']) /60 /60;
if($sun_info['sunrise'] > 1 && $sun_info['sunset'] === false){
$grunt = mktime( 23,59,59, date('n', $when), $thisday, date('Y',$when));
$hours = ($grunt - $sun_info['sunrise']) /60 /60;
}
// haven't seen this case in the wild
if($sun_info['sunrise'] === false && $sun_info['sunset'] > 1){
$grunt = mktime( 0,0,0, date('n', $when), $thisday, date('Y',$when));
$hours = round((($sun_info['sunset'] - $grunt) /60 /60),1);
}
$hours = round($hours, 1);
return $hours;
} // end function maxsunhours()
function what_delim() { // decide dec / comma o/p by language (country) code
global $dayfileLang, $delim;
// comma dec sep
// country iso 3166, two letter code lower-case
// turn o/p that no longer requires math into comma dec if required.
// suggested use could be:
// $actual_txt = (string)$thisValue;
// if($delim) $actual_txt = str_replace(".", ",", ''.$actual_txt);
$delim = false;
$comma_list = array(
'al', // Albania
'ad', // Andorra
'ao', // Angola
'ar', // Argentina
'am', // Armenia
'at', // Austria
'az', // Azerbaijan
'by', // Belarus
'be', // Belgium
'bo', // Bolivia
'ba', // Bosnia and Herzegovina
'br', // Brazil
'bg', // Bulgaria
'cm', // Cameroon
'cl', // Chile
'co', // Colombia
'cr', // Costa Rica
'cu', // Cuba
'cy', // Cyprus
'cz', // Czech Republic
'dk', // Denmark
'tl', // East Timor
'ec', // Ecuador
'ee', // Estonia
'fo', // Faroes
'fi', // Finland
'fr', // France
'de', // Germany
'ge', // Georgia
'gr', // Greece
'gl', // Greenland
'is', // Iceland
'id', // Indonesia
'it', // Italy
'kz', // Kazakhstan
'rs', // Kosovo (serbia)
'kg', // Kyrgyzstan
'lv', // Latvia
'lb', // Lebanon
'lt', // Lithuania
'mk', // Macedonia
'md', // Moldova
'mn', // Mongolia
'ma', // Morocco
'mz', // Mozambique
'na', // Namibia
'nl', // The Netherlands
'no', // Norway
'py', // Paraguay
'pe', // Peru
'pl', // Poland
'pt', // Portugal
'ro', // Romania
'ru', // Russia
'rs', // Serbia
'sk', // Slovakia
'si', // Slovenia
'za', // South Africa
'es', // Spain
'se', // Sweden
'tn', // Tunisia
'tr', // Turkey
'ua', // Ukraine
'uy', // Uruguay
'uz', // Uzbekistan
've', // Venezuela
'vn' // Vietnam
); // END countries with comma dec sep array
foreach($comma_list as $what) {
if($dayfileLang == $what) {
$delim = true; // any o/p will have , as decimal separater
break;
}
}
} // END function what_delim()
function delimIT($value) {
global $delim;
if(is_numeric($value)) $value = (string)$value;
if($delim) $value = str_replace(".", ",", $value);
return $value;
}
// ##### END new ##################
$data = '';
if (isset($_GET['year'])) {
$tableYear = $_GET['year'];
} else {
$tableYear = date('Y', strtotime('-1 day'));
}
if (isset($_GET['data'])) {
$dataSet = $_GET['data'];
} else {
$dataSet = 'maxtemp'; // default dataset
}
drawCalendar($tableYear);
?>