##
my %report_types = ( 0 => {name => "Report One",
opts => ['show_reqs', 'date'], coderef => \&report_type_two},
1 => {name => "Report Two",
opts => ['show_reqs', 'req_type', 'date'], coderef => \&report_type_three},
);
####
#!c:/perl/bin/perl.exe -T
use CGI qw(:standard);
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
use strict;
use warnings;
my $TITLE = "Reporting Utility";
# Options available for each report type
my %options = ( show_reqs => checkbox(-name=>'show_reqids', -checked=>0, -value=>'ON', -label=>'Show requirement IDs?'),
date => "Created: " . radio_group(-name=>'bef_since', -values=>['before', 'since'], -default=>'none',
-labels=>{'before' => 'before ', 'since' => 'since (inclusive)'}) . " Date (YYYY-MM-DD): " .
textfield(-name=>'date', -size=>10, -maxlength=>10),
req_type => "Requirement Type (e.g. BRQ): " . textfield(-name=>'reqtype', -size=>5, -maxlength=>5),
);
my %report_types = ( 0 => {name => "Project Requirements: Filtered by Creation Date", opts => ['show_reqs', 'date'], coderef => \&report_type_two},
1 => {name => "Project Requirement Revisions: Filtered by Creation Date, Type, and Version Reason", opts => ['show_reqs', 'req_type', 'date'], coderef => \&report_type_three},
);
# Hash for use with populating below radio_group
my %radio_hash;
foreach my $type (keys %report_types) {
$radio_hash{$type} = $report_types{$type}{'name'};
}
# Used to create the radio group of report types
my @rep_type_rad_gr = radio_group(-name=>'report_type', -values=>[sort {$a <=> $b} keys %radio_hash], -default=>'none', -labels=>\%radio_hash);
print header, start_html(-title=>$TITLE, -bgcolor=>"#ffcc99"), h2($TITLE), hr;
my $query = CGI->new();
if (defined $query->param('report_type')) { # If the user has made a selection
my $show_reqids = "false";
if ($query->param('show_reqids') eq "ON") {
$show_reqids = "true";
}
print("\n");
print h3("$report_types{$query->param('report_type')}->{'name'}"), "\n";
# Run report based on user selection, including all $query->param values as arguments
$report_types{$query->param('report_type')}{'coderef'}->($show_reqids, $query->param('bef_since'), $query->param('date'), $query->param('reqtype'), $query->param('ver_reason'));
$query->delete_all;
print start_form;
print defaults("Start over");
print end_form;
print("
\n");
}
else { # User has not made a selection
print("\n");
print p("Choose the type of report:
\n");
print start_form;
foreach my $i (0..$#rep_type_rad_gr) { # For each radio button
print "", $rep_type_rad_gr[$i], "";
foreach my $option ( @{$report_types{$i}->{opts}} ) { # Print the options associated with a given report type
print "
", $options{$option}, "\n";
}
print "
\n";
}
print p(submit("Submit"));
print end_form;
print("
\n");
}
print end_html;