I'll try once more.
Add lines to sub main (db.cgi):
Code:
elsif ($in{'analyze_search'}) { if ($per_view) { &html_analyze_search; } else { &html_unauth; } }
elsif ($in{'analyze_records'}) { if ($per_view) { &analyze_records; } else { &html_unauth; } }
Add a subroutine to db.cgi:
Code:
sub analyze_records {
# --------------------------------------------------------
my ($status, @hits) = &query("view");
if ($status eq "ok") {
&html_analyze_success(@hits);
}
else {
&html_analyze_failure($status);
}
}
Add a line to html_footer (html.pl):
Code:
print qq!| <A HREF="$db_script_link_url&analyze_search=1">Analysis</A> ! if ($per_view);
Add a subroutine to html.pl:
Code:
sub html_analyze_search {
# --------------------------------------------------------
open (DB, "<$db_file_name") or &cgierr("unable to open db file: $db_file_name.\nReason: $!");
if ($db_use_flock) { flock(DB, 1); }
@lines = <DB>;
close DB;
$mh=scalar(@lines);
&html_print_headers;
print qq|
<html>
<head>
<title>$html_title: Analyze the Database.</title>
</head>
<body bgcolor="#DDDDDD">
<form action="$db_script_url" method="GET">
<input type=hidden name="db" value="$db_setup">
<input type=hidden name="uid" value="$db_uid">
<input type=hidden name="mh" value="$mh">
<center>
<table border=1 bgcolor="#FFFFFF" cellpadding=5 cellspacing=3 width=500 align=center valign=top>
<tr><td colspan=2 bgcolor="navy">
<FONT FACE="MS Sans Serif, arial,helvetica" size=1 COLOR="#FFFFFF">
<b>$html_title: Analyze the Database</b>
</td></tr>
<tr><td>
<p><center><$font_title><b>
Analyze the Database
</b></font></center><br>
<$font>|;
&html_record_form();
print qq|
<select name="analysis">
<option>Name
<option>Person
<option>Both
</select>|;
print qq|</font></p>
<p><center> <INPUT TYPE="SUBMIT" NAME="analyze_records" VALUE="Analyze Records">
<INPUT TYPE="RESET" VALUE="Reset Form"></center></p>
|;
&html_footer;
print qq|
</td></tr>
</table>
</center>
</form>
</body>
</html>
|;
}
Add a subroutine to html.pl:
Code:
sub html_analyze_success {
# --------------------------------------------------------
my (@hits) = @_;
my ($numhits) = ($#hits+1) / ($#db_cols+1);
# change the values below to match the field numbers of your name, amount and person fields
$name_field = 2;
$amount_field = 3;
$person_field = 4;
for (0 .. $numhits - 1) {
$name = $hits[$_ * ($#db_cols+1) + $name_field];
$amount = $hits[$_ * ($#db_cols+1) + $amount_field];
$person = $hits[$_ * ($#db_cols+1) + $person_field];
$total{$name} += $amount;
++$count{$name};
$grand_total += $amount;
++$total_count;
if ($person) {
$person_total{$person} += $amount;
++$person_count{$person};
$grand_total_person += $amount;
++$total_person_count;
}
}
&html_print_headers;
print qq|
<html>
<head>
<title>$html_title: Analysis Results.</title>
</head>
<body bgcolor="#DDDDDD">
<blockquote>
<table border=1 bgcolor="#FFFFFF" cellpadding=5 cellspacing=3 width=500 valign=top>
<tr><td colspan=2 bgcolor="navy"><FONT FACE="MS Sans Serif, arial,helvetica" size=1 COLOR="#FFFFFF">
<b>$html_title: Analysis Results</b>
</font></td></tr>
</table>
<p><$font>
|;
if (($in{'analysis'} eq "Name") or ($in{'analysis'} eq "Both")) {
print "<table bgcolor=red>";
foreach $key (sort keys %total) {
print qq~<TR><TD>
Total numbers = $count{$key} </TD><TD>
Total amount of "$key" = $total{$key}</TD></tr>
~;
}
print qq| <TR><TD colspan=2>
===========================================
</TD></TR>
<TR><TD>Total numbers = $total_count </TD>
<TD>Total amount = $grand_total
</td></tr></table>|;
}
if (($in{'analysis'} eq "Person") or ($in{'analysis'} eq "Both")) {
print "<table bgcolor=green>";
foreach $key (sort keys %person_total) {
print qq~<TR><TD>
Total numbers = $person_count{$key} </TD>
<TD>Total amount of "$key" = $person_total{$key}</TD></tr>
~;
}
print qq| <TR><TD colspan=2>
===========================================</TD></TR>
<TR><TD>Total numbers = $total_person_count </TD>
<TD>Total amount = $grand_total_person</td></tr></table>|;
}
print qq|
<p>
<table border=0 bgcolor="#DDDDDD" cellpadding=5 cellspacing=3 width=500 valign=top>
<tr><td>|;
&html_footer;
print qq|</td></tr>
</table>
</blockquote>
</body>
</html>
|;
}
Add subroutine to html.pl:
Code:
sub html_analyze_failure {
# --------------------------------------------------------
my ($message) = $_[0];
open (DB, "<$db_file_name") or &cgierr("unable to open db file: $db_file_name.\nReason: $!");
if ($db_use_flock) { flock(DB, 1); }
@lines = <DB>;
close DB;
$mh=scalar(@lines);
&html_print_headers;
print qq|
<html>
<head>
<title>$html_title: Analysis Failed</title>
</head>
<body bgcolor="#DDDDDD">
<form action="$db_script_url" method="GET">
<input type=hidden name="db" value="$db_setup">
<input type=hidden name="uid" value="$db_uid">
<input type=hidden name="mh" value="$mh">
<center>
<table border=1 bgcolor="#FFFFFF" cellpadding=5 cellspacing=3 width=500 align=center valign=top>
<tr><td colspan=2 bgcolor="navy">
<FONT FACE="MS Sans Serif, arial,helvetica" size=1 COLOR="#FFFFFF">
<b>$html_title: Analysis Failed</b>
</td></tr>
<tr><td>
<p><center><$font_title><b>
Analysis Failed
</b></font></center><br>
<$font><$font>
<P>There were problems with the analysis. Reason: <FONT COLOR="red"><B>$message</B></FONT>
<BR>Please fix any errors and submit the record again.</p>|;
&html_record_form();
print qq|
<select name="analysis">
<option>Name
<option>Person
<option>Both
</select>|;
print qq|</font></p>
<p><center> <INPUT TYPE="SUBMIT" NAME="analyze_records" VALUE="Analyze Records">
<INPUT TYPE="RESET" VALUE="Reset Form"></center></p>
|;
&html_footer;
print qq|
</td></tr>
</table>
</center>
</form>
</body>
</html>
|;
}
------------------
JPD