#!/usr/bin/perl # report_results.pl # require "/web/seawifs/htdocs/sdps/cgi/common/cgi-lib.pl"; require "/web/seawifs/htdocs/sdps/cgi/common/sdpswebdb.pl"; &ReadParse; &setupdb; $| = 1; my $procname = $in{procname}; my $fromdate = "$in{frommonth} $in{fromday} $in{fromyear} 00:00:00"; my $todate = "$in{tomonth} $in{today} $in{toyear} 23:59:59"; my $datatypes = $in{datatypes}; my $locations = $in{locations}; my $email_list = $in{email_list}; my $rptmode = $in{rptmode}; my $need_date = $in{need_date}; my $need_dtype = $in{need_dtype}; my $need_loc = $in{need_loc}; my $monitor = $in{monitor}; if ($datatypes) { $datatypes =~ s/\\0/ /g; } if (!$datatypes) { $datatypes = "ALL"; } if ($locations) { $locations =~ s/\\0/ /g; } if (!$locations) { $locations = "ALL"; } #print STDERR "need_date: $need_date\n"; #print STDERR "need_dtype: $need_dtype\n"; #print STDERR "need_loc: $need_loc\n"; my $dbcmd; if ($need_date && $need_dtype && $need_loc) { $dbcmd = "$procname '$fromdate','$todate','$datatypes','$locations'"; } elsif ($need_date && $need_dtype) { $dbcmd = "$procname '$fromdate','$todate','$datatypes'"; } elsif ($need_date && $need_loc) { $dbcmd = "$procname '$fromdate','$todate','$locations'"; } elsif ($need_date) { $dbcmd = "$procname '$fromdate','$todate'"; } else { $dbcmd = "$procname"; } #print STDERR "dbcmd: $dbcmd\n"; if ($email_list =~ /\`/) { $bq = 1; } else { $bq = 0; } if ($bq == 0) { print STDERR "Setting up command\n"; my $rptgen = "$ENV{SDPS_BIN}/report_generator"; my $mailflag = ($email_list) ? 1 : 0; $ENV{SEAWIFS_TEMP} = "/usr/tmp"; $ENV{SDPS_BIN} = $ENV{SDPS_BIN}; $cmd = "$rptgen \"$dbcmd\" $mailflag \"$email_list\" $rptmode 2> /dev/null"; #print STDERR "$cmd\n"; my $randomstring; if ($monitor) { print "Content-type: multipart/x-mixed-replace;boundary=ThisRandomString\n\n"; $randomstring = "--ThisRandomString"; print "$randomstring\n"; } } print <<"EOT"; Content-type: text/html Report Results EOT if ($bq) { print "Nice try.\n"; print "$email_list\n"; print "BQ: $bq\n"; } else { print <<"EOT";

Report Results

Start Over | SDPS Home

EOT


RUNIT: my $results = `$cmd`;
my $cmdstat = ($? >> 8);

if ($cmdstat == 0 && $rptmode) {
   print "$results";
}
elsif ($cmdstat == 0) {
   print "

Your report has run successfully

\n"; } else { print "

An error occurred while trying to run your report

\n"; } print "
\n"; } print <<"EOT"; EOT if ($monitor && $cmdstat == 0 && $rptmode) { print "$randomstring\n"; sleep 5; goto RUNIT; }