#!/usr/bin/env perl use strict; use warnings; use DBI; use HTML::Template; use File::Basename; use POSIX 'strftime'; use CGI::Widget::Tabs; use CGI; my $basename = basename($0,".pl"); my $outfile="$ENV{'CAPS_OUTDIR'}/$basename.xls"; open (OUT_HTML_FILE, ">$ENV{'CAPS_OUTDIR'}/$basename.htm") or die "Can not open output html file: $basename.htm\n"; ## output the content-type so the web server knows my $script="$ENV{'HOME'}/scripts/template.pl"; my $template = HTML::Template->new(filename => $script); $template->param(TITLE=>'ENV Spreadsheet'); my $dbname = 'xxxxx'; # $ENV{ORACLE_SID}; my $user = 'xxxxx'; my $passwd = 'xxxxx'; my $dbh = DBI->connect("dbi:Oracle:$dbname", $user, $passwd, {RaiseError => 1}) or die "Oracle Connect Failed: ", DBI->errstr; my @reports = ('Football', 'Baseball'); my %queries = ( "Football" => qq{ select team as TEAM, url as URL from sports where sport = 'Football' }, "Baseball" => qq{ select team as TEAM, url as URL from sports where sport = 'Baseball' }, ); my $cgi = CGI->new; my $tab = CGI::Widget::Tabs->new; $tab->cgi_object($cgi); for (@reports) { my $sth = $dbh->prepare($queries{$_}); $sth->execute(); $tab->headings( qw/FOOTBALL BASEBALL/ ); $tab->wrap(3); # $tab->wrap(1); # |uncomment to see the effect of # $tab->indent(0); # |wrapping at 1 without indentation $tab->default("FOOTBALL"); $tab->display; my @headings; foreach (@{$sth->{NAME}}) { my %rowh; $rowh{HEADINGS} = $_; push @headings, \%rowh; } $template->param(HEADINGS=>\@headings); my @rows; while (my @data_row = $sth->fetchrow_array) { my %row; $row{TEAM} = $data_row[0]; $row{URL} = $data_row[1]; push @rows, \%row; } $template->param(ROWS=>\@rows); print OUT_HTML_FILE "Content-Type: text/html\n\n", $template->output; } #### <TMPL_VAR name=TITLE>