#!/usr/local/bin/perl5_8
# Cash Balance program; processes data from main menu program.
use strict;
use ncw_com_library; # contains common subs (commify, timeout, etc.)
use HTML::Template;
use Time::Local;
use DBI;
use CGI ':standard';
my $CGI = CGI->new;
# Clear buffers and set up web page (required)
$|=1;
# [some attributes code snipped out that I believe is irrelevant]
my ($attr_descr, $attr_exists, $sth_attr);
$dbh=DBI->connect("dbi:Oracle:".$databs,$userid,$passwd) ||
die "conn attr_sql";
$sth_attr = $dbh->prepare($attr_sel) ||
die "prep attr_sql";
$sth_attr ->execute || die "exec attr_sql";
while ( $attr_exists = $sth_attr->fetch )
{ $project = $attr_exists->[0];
$attr_descr = $attr_exists->[1];
print "attr_descr before $attr_descr
";
# Put in HTML-friendly characters for any odd characters
&ncw_com_library::cleanup($attr_descr);
print "attr_descr after $attr_descr
";
# [some more fetched fields snipped out]
}
# [snipped out other financial data loops for HTML:TEMPLATE;
# no issues there]
#################### Begin Section ##############################
# Pass parameters from @loop arrays to template; print report
# [snipped out irrelevant params below]
$template->param(
passdata => \@loop_data,
attr_descr => $attr_descr,
project => $project
);
print $template->output();
#++++++++++++++++++++ End Section ++++++++++++++++++++++++++++++
******************************************************************
# This is my library
******************************************************************
package ncw_com_library;
# Contains various common subroutines used by the WRS Reports
1;
use strict;
use DBI;
use Exporter ();
our @ISA = 'Exporter';
our @EXPORT;
use vars @EXPORT=qw/ $asofdt $auth_fail $message $projects
$proj_descr $rpt_dates $rpt_id $rpt_unavail $status /;
# [snipped out unrelated subroutines]
sub cleanup
# Replaces various characters with HTML-friendly characters
{
print "attr_descr entering cleanup $_
";
local $_ = shift @_;
1 while $_ =~ s/^(.*)(')(.*)/$1’$3/gm;
print "attr_descr exiting cleanup $_
";
return $_;
}
# This sub works with the financial data so I used it as the basis for
# the cleanup sub above.
sub commify
# Formats numbers to two decimal places, put in commas, make negs red)
{
local $_ = sprintf "%.2f", shift @_;
1 while $_ =~ s/^(-?\d+)(\d\d\d)/$1,$2/;
$_ =~ s/^(-)(.*)/\($2\)/;
{ if ( $_ =~ m/^\(.*/ )
{ $_ = "style=\"color:#B22222;\">" . $_ }
else { $_ = "style=\"color:black;\">" . $_ }
}
return $_;
}