Okay...give this a shot....
1) Add third sub-routine, but in your
db.cgi, called
sub add_votes. The sub-routine should look something like this:
Code:
sub add_votes {
#-------------------------------------------
# Add votes to Rating Field
my $id = $in{'db_key'}
my $vote = $in{'vote'}
my $time = time();
# Check for proper rating
unless (($vote =~ /^\d\d?/) and ($vote >= 1) and ($vote <= 10)) {
&html_vote_failure ("Your rating '$rating' is invalid.");
return;
}
# Let's get the link information.
my %rec = &get_record;
($rec{$db_key} eq $id) or (&html_vote_failure ("Unable to find link with ID '$id'.") and return);
# Increase the vote.
if (open (HIT, "<$db_rates_path/$id")) {
my $input = <HIT>; chomp $input;
($votes, $old_rating) = split /\s/, $input;
chomp ($old_time = <HIT> );
chomp (@IP = <HIT> );
(($time - $old_time) > 172800) and (@IP = ());
foreach $ip (@IP) {
$ip eq $ENV{'REMOTE_ADDR'} and ($visited++ and last);
}
close HIT;
if (!$visited) {
open (DB, "<$db_file_name") or &cgierr("error in modify_records. unable to open db file: $db_file_name.\nReason: $!");
if ($db_use_flock) { flock(DB, 1); }
@lines = <DB>; # Slurp the database into @lines..
close DB;
LINE: foreach $line (@lines) {
if ($line =~ /^$/) { next LINE; }
if ($line =~ /^#/) { $output .= $line; next LINE; }
chomp ($line);
@data = &split_decode($line);
if ($data[$db_key_pos] eq $rec{$db_key}) {
$votes = $votes + 1;
$rec{'Teller'} = $rating + $old_rating;
$output .= &join_encode(%rec);
}
else {
$output .= $line . "\n";
}
}
open (DB, ">$db_file_name") or &cgierr("error in modify_records. unable to open db file: $db_file_name.\nReason: $!");
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_vote_success;
}
else {
&html_vote_failure ("Sorry, you've already rated this resource once recently.");
}
}
2) Create another sub-routine in your
html.pl called
sub html_vote_failure. This routine should look similar to your
sub html_add_failure.
3) Create another directory variable in your
default.cfg file called:
This can be put in your DBMAN directory as a sub-directory. Make sure that you change the permission of this directory to
777.
4) Change the following codes in your
sub html_vote_form:
Code:
<INPUT TYPE="SUBMIT" NAME="vote" VALUE="Vote">
to the following:
Code:
<INPUT TYPE="SUBMIT" NAME="add_votes" VALUE="Vote">
5) Rename your
sub html_vote in the
html.pl file to
sub html_vote_success.
6) Change the following codes:
Code:
<input type=hidden name="Teller" value="$rec{'Teller'}">
to the following:
Code:
Rate this Record:
<select name="Teller">
<option value="---"></option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
</select>
See if this works!
Regards,
------------------
Eliot Lee Anthro TECH,L.L.C
www.anthrotech.com * Be sure to visit the
Resource Center for
FAQ's,
Modifications and
Extra Goodies!!
* Search Forums!
* Say NO to Duplicate Threads.
----------------------
[This message has been edited by Eliot (edited January 30, 2000).]
[This message has been edited by Eliot (edited January 30, 2000).]