#!/usr/bin/perl -w use strict; use Date::Calc qw(Add_Delta_Days Delta_Days); use Time::Local; use lib '/var/chroot/home/content/17/10541917/html/lib/Geo-Hashing-0.06/lib'; use Geo::Hashing; use CGI qw(warningsToBrowser fatalsToBrowser); $\ = "\n"; my $t = localtime; my @u = split /\s/,$t; $t=join '-',@u; my $filename = "$t.kml"; #can also use $t=time; for number of seconds since the epoch. my $q = CGI->new; # create new CGI object if ((! $q->param('submit')) && (! $q->param('submitToGoogle'))){ print $q->header; print $q->start_html('Geohashing History'), # start the HTML h1('Welcome to the Geohashing History Calculator.'); print $q->start_form(); #Latitude print $q->p("Latitude for the graticule you're interested in:"); print $q->textfield(-name=>'lat', -value=>'39', -size=>3, -maxlength=>3); print $q->br; #Longitude print $q->p("Longitude for the graticule you're interested in:"); print $q->textfield(-name=>'lon', -value=>'-77', -size=>3, -maxlength=>3); print $q->br; #Begin date (must be after XXXX) print $q->p("Begin date of date range (in YYYY-MM-DD format)"); print $q->textfield(-name=>'begindate', -value=>'2013-03-21', -size=>10, -maxlength=>10); print $q->br; #End date # Grab the current date so we can set the default my ($a,$b,$c,$todayday,$todaymonth,$todayyear,$d,$e,$f) = localtime(time); # Do some interim math. $todayyear = $todayyear+1900; $todaymonth = $todaymonth+1; print $q->p("End date of date range (in YYYY-MM-DD format)"); print $q->textfield(-name=>'enddate', -value=>sprintf("$02d-%02d-%04d",$todayyear,$todaymonth,$todayday), -size=>10, -maxlength=>10); print $q->br; #Filename? #Submit button print $q->submit(-name=>'submit', -value=>'submit information'); print $q->end_form(); print $q->end_html; # end the HTML }elsif (param('submit')){ #print $q->header, # create the HTTP header # start_html('Geohashing History Results'), # start the HTML # h3('Geohashing History Results'); # level 1 header #Latitude #print $q->start_form; ##print $q->h3("You submitted the form."); #my $startdate=param('begindate'); #my ($year, $month, $day) = split /-/ , $startdate; #my ($startyear, $startmonth, $startday) = split /-/ , $startdate; #my $enddate=param('enddate'); #my ($endyear, $endmonth, $endday) = split /-/ , $enddate; #my $delta = Delta_Days(($startyear, $startmonth, $startday),($endyear,$endmonth,$endday)); # #print $q->h6("You have $delta days in your date range."); # #my $lat = param('lat'); #my $lon=param('lon'); ## Translate months for placemark titles. #my @months = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec); ## Output file header xml stuff # #open FH, "> $filename" || die "Can't open $filename: $!"; #print $q->FH " # # #Historical Geohash Points for ",$lat,",",$lon," #"; # ## Main loop #for (my $i = 0; $i <= $delta; $i++) { # # # format date for Geo::Hashing # my $date = sprintf("%04d-%02d-%02d", $year, $month, $day); # # # magic happens! # my $geo = new Geo::Hashing(lat => $lat, lon => $lon, date => $date); # # # output placemark xml # print $q->FH ""; # print $q->FH ""; # print $q->FH $months[$month-1]," ",$day,", ",$year; # print $q->FH ""; # print $q->FH "",$geo->lat,", ",$geo->lon,""; # print $q->FH "",$geo->lon,",",$geo->lat,""; # print $q->FH "","\n"; # # # increment day and loop again! # ($year, $month, $day) = Add_Delta_Days($startyear, $startmonth, $startday, $i); #} # ## finish up xml file #print $q->FH " #"; # #print $q->submit(-name=>'submitToGoogle', -value=>'View Results in Google Maps'); # #print $q->end_html; # end the HTML }elsif(param->('submitToGoogle')){ print $q->header; # create the HTTP header print $q->start_html('Redirect page'), # start the HTML h3('Redirect Page'); # level 1 header #print $q->redirect("https://maps.google.com/maps?q=http:%2F%2Fpqrs.be%2Fmisc%2F$filename"); print $q->end_html; # end the HTML }else{ print $q->header; # create the HTTP header print $q->start_html("Shouldn't be here"), # start the HTML h3('You are here in error.'); #print $q->redirect("https://maps.google.com/maps?q=http:%2F%2Fpqrs.be%2Fmisc%2F$filename"); print $q->end_html; # end the HTML }