I think this should work.
In db.cgi, sub main, after
Code:
elsif ($in{'modify_form'}) { if ($per_mod) { &html_modify_form; } else { &html_unauth; } }
add
Code:
elsif ($in{'modify_comments_form'}) { if ($per_mod) { &html_modify_comments_form; } else { &html_unauth; } }
elsif ($in{'modify_comments'}) { if ($per_mod) { &modify_mulitiple_comments; } else { &html_unauth; } }
Add the following subroutine to db.cgi:
Code:
sub modify_mulitiple_comments {
# --------------------------------------------------------
my ($key,%modify_list,$rec_to_modify,@lines,$line,@data,$output);
foreach $key (keys %in) { # Build a hash of keys to modify.
if ($in{$key} eq "modify") {
$modify_list{$key} = 1;
$rec_to_modify = 1;
}
}
if (!$rec_to_modify) {
&html_modify_form_mult("You must mark at least one record to be modified.");
}
else {
open (DB, "<$db_file_name") or &cgierr("error in delete_records. unable to open db file:
$db_file_name. Reason: $!");
@lines = <DB>;
close DB;
LINE: foreach $line (@lines) {
if ($line =~ /^$/) { next LINE; }
if ($line =~ /^#/) { $output .= $line; next LINE; }
chomp ($line);
(@data) = &split_decode($line);
if ($modify_list{$data[$db_key_pos]}) {
foreach $key (keys %in) {
if ($key =~ /^\Q$data[$db_key_pos]\E-(.*)$/) {
$rec{$1} = $in{$key};
}
}
$output .= &join_encode (%rec);
}
else {
$output .= $line . "\n";
}
}
}
open (DB, ">$db_file_name") or &cgierr("error in modify_mult_records. unable to open db file:
$db_file_name. Reason: $!");
if ($db_use_flock) {
flock(DB, 2) or &cgierr("unable to get exclusive lock on $db_file_name.\nReason: $!");
}
print DB $output;
close DB;
&html_modify_comments_result;
}
In your links for the predefined searches, add
Code:
&modify_comments_form=1
Add the following to html.pl:
Code:
sub html_modify_comments_form {
# --------------------------------------------------------
my ($status, @hits) = &query("mod");
my ($numhits) = ($#hits+1) / ($#db_cols+1);
my ($maxhits); $in{'mh'} ? ($maxhits = $in{'mh'}) : ($maxhits = $db_max_hits);
my (%tmp);
$page_title = "Modify Comments";
&html_page_top;
$submit_button = "Modify Comments";
$reset_button = "Reset Form";
if ($status ne "ok") { # There was an error searching!
print qq|<P><$font_error>Error: $status</FONT></P>|;
&html_footer;
&html_page_bottom;
}
else {
# < -- Start page text -- >
print qq|
<p><$font>
Modify the comment on each record you wish to change and click the checkbox by
that record. Then click the "Modify Comments" button:<br>
Your search returned <b>$db_total_hits</b> matches.</font>
|;
# < -- End page text -->
if ($db_next_hits) { print "<br><$font>Pages: $db_next_hits</font>"; }
print qq|
<form action="$db_script_url" METHOD="POST">
<input type=hidden name="db" value="$db_setup">
<input type=hidden name="uid" value="$db_uid">
|;
# Go through each hit and convert the array to hash and send to
# html_record for printing. Also add a checkbox with name=key and value=delete.
print "<P>";
for (0 .. $numhits - 1) {
%tmp = &array_to_hash($_, @hits);
print qq|<TABLE BORDER=0><TR><TD>
<INPUT TYPE=CHECKBOX NAME="$tmp{$db_key}" VALUE="modify"></TD><TD>|;
&html_record (%tmp);
print qq|</TD></TR><TR><TD> </TD><TD>
<input type=text name="$tmp{$db_key}-Comment" value="$tmp{'Comment'}" size="20"
maxlength="$db_lengths{'Comment'}"></td></tr>|;
foreach $column (@db_cols) {
unless ($column eq 'Comment') {
print qq|<input type="hidden" name="$tmp{$db_key}-$column" value="$tmp{$column}">|;
}
}
print qq|</TABLE>\n|;
}
print qq|
<p><center>
<INPUT TYPE="SUBMIT" name="modify_comments" VALUE="$submit_button">
<INPUT TYPE="RESET" VALUE="$reset_button">
</center></p></form>
|;
if ($db_next_hits) { print "<br><$font>Pages: $db_next_hits</font>"; }
&html_footer;
&html_page_bottom;
}
}
sub html_modify_comments_result {
# --------------------------------------------------------
# This page let's the user know that the records were successfully
# deleted.
$page_title = "Comments Modified";
&html_page_top;
# < -- Start page text -- >
print qq|
<$font>Your comments have been modified.</font></p>
|;
# < -- End page text -->
&html_footer;
&html_page_bottom;
}
(You did say you're using the "user-friendly" html.pl file, didn't you?)
------------------
JPD