December 2007 ################ # Suggested use: # ############## You need Monthly WD Report files from Weather Display Software, and they must be located on your web server http://www.weather-display.com/index.php This script is designed to be a plugin for TNET Weather - tws-avgext-script where the date string is used like this: sample.php?date=200712 http://www.tnetweather.com/tws-avgext-script.php This is a great addition to a great report script, it can save everyone having to edit the report page every month. Thanks to Kevin Reed at TNET Weather for offering his scripts I use it as a plugin on my tws-avgext-script Monthly Weather Reports page http://www.642weather.com/weather/monthly-stats.php ################ # How to use it: # ############## upload the contents of this file as include-get-month-files.php in the same directory as your reports page call it like this from the php page where your drop down list will be: Note: (make sure to change sample.php to the name of your php page) ##### copy below here #####
##### copy above here ##### */ ################# # begin settings # ############## # be sure to set the two settings variables below # enter 4 digit year of your oldest report on your server - example: 2006 $startyear = 2006; # Location of where the data files are located. # You may need to change this and it must end with a slash. # ./ is used if the files are in the same folder as your page with the dropdown list $webdir = './'; ################# # end settings # ############## if (isset($_REQUEST['sce']) && 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; } function getmonthfiles() { global $startyear, $webdir; # find out how many years do we need to list files for $thisyear = date('Y'); $yearcount = $thisyear - $startyear; # Saftey setting incase some goofy year is entered like 200 for $startyear setting # only allows 20 years in the past maximum. if($yearcount > 20) $yearcount = 20; $yearsarray = array(); for ($num=0; $num <= $yearcount; $num++ ) { $yearsarray[]=$thisyear; $thisyear--; } $monthsarray = array('12' => 'December','11' => 'November','10' => 'October','09' => 'September','08' => 'August','07' => 'July', '06' => 'June','05' => 'May','04' => 'April','03' => 'March','02' => 'February','01' => 'January'); # $datestring is used to keep the dropdown properly selected # see if it is there and 6 digits only # make sure a month selected exists # input sanity (allow only 6 digits for date query, nothing else) $defaultdatefound=0; $datestring = ''; $selected = ''; if ( isset($_GET['date'] ) && preg_match("/^[0-9]{6}$/", $_GET['date']) ) { if (is_file($webdir.$monthsarray[substr($_GET['date'],4,2)].substr($_GET['date'],0,4).'.htm')) { $datestring = $_GET['date']; $defaultdatefound=1; } } # this part properly sorts the files for the dropdown # start with this year and work back $count =1; foreach ($yearsarray as $yk => $yv) { # start with December and work towards January for each year we are working with foreach ($monthsarray as $mk => $mv) { # only files FOUND on the server are included if(is_file("$webdir$mv$yv.htm")){ # make the default month, the first one we actually have found # prevents January of a new year not found on Jan 1 because the file was not uploaded if ($count ==1) $firstdatestring = "$yv$mk"; if ($datestring == "$yv$mk") $selected = ' selected="selected"'; echo ''."\n"; $selected = ''; $count++; } } } # make the default month, the first one we actually have found if (!$defaultdatefound) $datestring = $firstdatestring; return $datestring; } ?>