#!C:\perl64\bin\perl.exe use lib "C:/ba97"; use Win32::ODBC; use BA97; use CGI::Cookie; use CGI qw(:standard); use DBI; use MIME::Base64; my %opts = (); my %params = (); my $db; my $debug = "false"; $debug = "true" if (param('debug') ne ''); my $DSN = BA97::getDSN; die("Unable to connect to DB\n") if (!($db = new Win32::ODBC($DSN))); ############# ## Cookie fun my %cookies = CGI::Cookie->fetch; my $handle; my @appdata; if($cookies{'ba97appdata'}) { @appdata = $cookies{'ba97appdata'}->value; foreach (@appdata) { my ($key,$value) = split(/=/,$_); $cookie_params{decode_base64($key)} = decode_base64($value); } $handle = $cookie_params{'uname'}; } ## End of Cookie fun #################### $handle = substr(param('handle'),0,32) if (param('handle') ne ''); my $lt = substr(param('lt'),0,5); my $gt = substr(param('gt'),0,5); $gt = 0 if ($gt eq ''); $lt = 12420 if ($lt eq ''); my $start = substr(param('start'),0,4); my $finish = substr(param('finish'),0,4); my %regions; my $SqlStatement = "SELECT airport_identifier, region FROM ba97_airports a, ba97_regions r WHERE a.airport_country = r.country"; if ($db->Sql($SqlStatement)) { print "SQL failed."; print "Error: " . $db->Error() . ""; } else { while($db->FetchRow()) { %data = $db->DataHash(); $regions{$data{'region'}}++; my $region = $data{'region'}; $region =~ s/\s+//g; $region =~ s/\///g; $airport_region{$data{'airport_identifier'}} = $region; } } ## Set all the origin/destination checkboxes to be checked my %orgdes; foreach ('origin','destination') { foreach my $region (keys %regions) { $region =~ s/\s+//g; $region =~ s/\///g; $orgdes{$_ . "_" . $region} = 'checked'; } } ## If this page was regenerated by hitting the submit button... my $showcodes = 'checked'; my $imagefilter = $ENV{"QUERY_STRING"}; if (param('submit') ne '') { $showcodes = '' if (param('showcodes') eq ''); foreach ('origin','destination') { ## ...uncheck the boxes if they weren't checked on the form submitted foreach my $region (keys %regions) { $region =~ s/\s+//g; $region =~ s/\///g; delete $orgdes{$_ . "_" . $region} if (param($_ . "_" . $region) eq ''); $filter{$_} = 'true'; } } } print header(); if ($db->Sql($SqlStatement)) { print "SQL failed."; print "Error: " . $db->Error() . ""; } else { } my $title_string = "Flight Map for $handle"; if (($start ne '') && ($start eq $finish)) { $title_string .= " (" . $start . ")"; } elsif ($start ne '') { $title_string .= " (" . $start . " to " . $finish . ")"; } print<
$title_string

EOF ; my $handle = substr(param('handle'),0,32) if (param('handle') ne ''); $handle =~ s/\'//; $handle =~ s/\"//; $handle =~ s/\;//; my $lt = substr(param('lt'),0,5); my $gt = substr(param('gt'),0,5); $gt = 0 if ($gt eq ''); $lt = 12420 if ($lt eq ''); my $start = substr(param('start'),0,4); my $finish = substr(param('finish'),0,4); my %airport_regions; my %regions; my $SqlStatement = "SELECT airport_identifier, region FROM ba97_airports a, ba97_regions r WHERE a.airport_country = r.country"; if ($db->Sql($SqlStatement)) { print "SQL failed."; print "Error: " . $db->Error() . ""; } else { while($db->FetchRow()) { %data = $db->DataHash(); $regions{$data{'region'}}++; my $region = $data{'region'}; $region =~ s/\s+//g; $region =~ s/\///g; $airport_region{$data{'airport_identifier'}} = $region; } } my %orgdes; foreach ('origin','destination') { foreach my $region (keys %regions) { $region =~ s/\s+//g; $region =~ s/\///g; if ((param($_ . "_" . $region) eq 'on') || (param('submit') eq '')) { $orgdes{$_ . "_" . $region} = 'checked'; } } } $SqlStatement=<= $gt AND distance <= $lt AND airline_identifier NOT IN ('9F','GNER') ) UNION DISTINCT ( SELECT origin, destination FROM ba97_sectors_archive WHERE handle='$handle' AND distance >= $gt AND distance <= $lt AND airline_identifier NOT IN ('9F','GNER') ) EOF ; if ($start ne '') { $SqlStatement =~ s/WHERE/WHERE flight_date \>=\'$start-01-01 00:00\'\nAND\t/g; } if ($finish ne '') { $SqlStatement =~ s/WHERE/WHERE\tflight_date \<=\'$finish-12-31 23:59\'\nAND\t/g; } if ($db->Sql($SqlStatement)) { print "SQL failed."; print "Error: " . $db->Error() . ""; } else { while($db->FetchRow()) { %data = $db->DataHash(); my $print_sector = 'true'; foreach ('origin','destination') { if ((param($_.'_'.$airport_region{$data{$_}}) ne 'on') && (param('submit') ne '')) { $print_sector = 'false'; } } if ($print_sector eq 'true') { print "Print " . $data{'origin'} . "-" . $data{'destination'} . "
\n" if ($debug eq 'true'); if (($sectors{$data{'origin'}."-".$data{'destination'}} eq '') && ($sectors{$data{'destination'}."-".$data{'origin'}} eq '')) { if (($data{'origin'} !~ m/^[0-9]/) && ($data{'destination'} !~ m/^[0-9]/)) { $sectors{$data{'origin'}."-".$data{'destination'}}++; } } } else { print "DO NOT Print " . $data{'origin'} . "-" . $data{'destination'} . "
\n" if ($debug eq 'true'); } } } my $img_string = "http://www.gcmap.com/mapui?P="; $img_string .= "$_," foreach (keys %sectors); $img_string =~ s/,$//; $img_string .= "&MS=bm&MR=30&MX=875x500&PM="; $img_string .= "*" if ((param('submit') eq '') || (param('showcodes') eq 'on')); print<Open your map at gcmap.com!

EOF ; print "\n"; print "\n\n\n\n\n"; foreach my $region (keys %regions) { my $input_region = $region; $input_region =~ s/\s+//g; $input_region =~ s/\///g; print "\n"; print "\n"; foreach ('origin','destination') { print "\n"; } print "\n"; } print "
OriginDest
" . $region . "
\n"; print<

Distances

More than miles
Less than miles EOF ; $SqlStatement = "(select distinct date_format(flight_date,\"\%Y\") 'year' " . "from ba97_sectors " . "where handle='" . $handle . "') " . "UNION DISTINCT " . "(select distinct date_format(flight_date,\"\%Y\") 'year' " . "from ba97_sectors_archive " . "where handle='" . $handle . "') " . "ORDER BY year ASC"; my $options = ""; my $first_year, $last_year = ""; if ($db->Sql($SqlStatement)) { print "SQL failed."; print "Error: " . $db->Error() . ""; } else { while($db->FetchRow()) { %data = $db->DataHash(); $options .= "\n"; $first_year = $data{'year'} if ($first_year eq ''); $last_year = $data{'year'}; } } my $startYears = $options; my $finishYears = $options; $start = $first_year if ($start eq ''); $finish = $last_year if ($finish eq ''); $startYears =~ s/\
EOF ;