From 5661298dc516477c09edfaf4119f765dce8b9c05 Mon Sep 17 00:00:00 2001 From: agp8x Date: Sat, 29 Nov 2014 12:16:49 +0100 Subject: [PATCH] fixes issue #5: remove links to pages in the future, keep those to future days in the current month anyways --- config.default.php | 2 ++ function.php | 53 ++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 51 insertions(+), 4 deletions(-) diff --git a/config.default.php b/config.default.php index 5cd832e..95c570b 100644 --- a/config.default.php +++ b/config.default.php @@ -7,3 +7,5 @@ $database = array( 'database' => "temp", ); +$start_year_of_recordings=2012; + diff --git a/function.php b/function.php index 4bdcf3f..30d0e4e 100644 --- a/function.php +++ b/function.php @@ -314,9 +314,13 @@ function drawChart($myData,$target,$date,$type){ $myPicture->Render($target); } -function calendarDay($day,$year,$month,$selection){ +function calendarDay($day,$year,$month,$selection, $future){ $baselink="&year=".$year."&month=".$month."&day=".$day."'"; - return tempLink($baselink,$day,($selection=="temp")).humiLink($baselink,($selection=="humi")).ambiLink($baselink,($selection=="ambi")).baroLink($baselink,($selection=="baro")); + if($future){ + return $day." (H A B)"; + }else{ + return tempLink($baselink,$day,($selection=="temp")).humiLink($baselink,($selection=="humi")).ambiLink($baselink,($selection=="ambi")).baroLink($baselink,($selection=="baro")); + } } function tempLink($baselink,$day,$selected=false){ $link="\n\t<<  ".$month."   >>\n\n"; + $show['prev']=$prevYear >= $start_year_of_recordings; + $show['next']=! isFuture(array(date("j"),date("n"),date("Y")), 0, $nextMonth, $nextYear); + $links="
\n\t"; + if ($show['prev']){ + $links.="<< (".monthToName($prevMonth).")"; + }else{ + $links.=monthToName($prevMonth); + } + $links.="  ".monthToName($month)."   "; + if ($show['next']){ + $links.=">> (".monthToName($nextMonth).")"; + }else{ + $links.=monthToName($nextMonth); + } + $links.="\n
\n"; + return $links; +} +function monthToName($month){ + $dateObj = DateTime::createFromFormat('!m', $month); + $monthName = $dateObj->format('F'); + return $monthName; } function prependZero($number){ return ($number<10)? "0".$number : $number; @@ -393,7 +419,8 @@ function drawCalendar($date,$type){ }else{ $calendar.="\t\t"; } - $calendar.=calendarDay($day,$year,$month,($day==$selectedDay)? $type : false); + $future=isFuture($today, $day, $month, $year, false); + $calendar.=calendarDay($day,$year,$month,($day==$selectedDay)? $type : false, $future); $day++; }else{ $calendar.="\t\t  "; @@ -406,6 +433,24 @@ function drawCalendar($date,$type){ Letzte: 24h 48h 96h    Temperatur Heute"; return $calendar; } +function isFuture($today, $day, $month, $year, $overwriteDay=true){ + # check year + if ($today[2] < $year){ + return true; + } + if ($today[2] == $year){ + # check month + if ($today[1] < $month){ + return true; + } + if($today[1] == $month){ + # check day + return $today[0] < $day && $overwriteDay; + } + } + # base case + return false; +} function typeToSensorCount($type){ switch($type){