Hi Guys !!!
I want to make a mod called "vote.cgi" which is a mod of the "jump.cgi" but I don't have experience whith Perl. The objective is that when the remote user click in pre-definited link like eg: <a href"http://www.fulano.com/cgi-bin/vote.cgi?ID=01">Vote for My Site"</a> then the "vote.cgi" should be open a remote_hit_success.html template instead like they normally do in the same browser window whit a link to refer ID. The hits is count whith the same proccess in the "jump.cgi".
Look this code:
#############################################
---> eg. ratehome.cgi "I want anything like this, but I think that's could be more simple"
# Required Librariers
# --------------------------------------------------------
eval {
($0 =~ m,(.*)/[^/]+,) && unshift (@INC, "$1"); # Get the script location: UNIX /
($0 =~ m,(.*)\\[^\\]+,) && unshift (@INC, "$1"); # Get the script location: Windows \
require "admin/links.cfg"; # Change this to full path to links.cfg if you have problems.
require "$db_lib_path/db_utils.pl";
require "$db_lib_path/links.def";
$build_use_templates ?
require "$db_lib_path/site_html_templates.pl" :
require "$db_lib_path/site_html.pl";
};
if ($@) {
print "Content-type: text/plain\n\n";
print "Error including libraries: $@\n";
print "Make sure they exist, permissions are set properly, and paths are set correctly.";
exit;
}
# ========================================================
eval { &main; }; # Trap any fatal errors so the program hopefully
if ($@) { &cgierr("fatal error: $@"); } # never produces that nasty 500 server error page.
exit; # There are only two exit calls in the script, here and in in &cgierr.
sub main {
# --------------------------------------------------------
local (%in) = &parse_form;
if ($in{'R'}) {
&rate_it;
}
elsif ($in{$db_key} =~ /^\d+$/) {
my (%rec) = &get_record ($in{$db_key});
($rec{$db_key} eq $in{$db_key}) ?
&site_html_rate_form (%rec) :
&site_html_rate_failure ("Unkown Link ID: $in{$db_key}");
}
else {
print "Location: $build_ratings_url/\n\n";
}
}
sub rate_it {
# --------------------------------------------------------
my $id = $in{$db_key};
my $delim = quotemeta($db_delim);
my $time = time();
my $rating = $in{'R'};
# Make sure we have a valid rating.
unless (($rating =~ /^\d\d?/) and ($rating >= 1) and ($rating <= 10)) {
&site_html_rate_failure ("Your rating '$rating' is invalid.");
return;
}
# Let's get the link information.
my %rec = &get_record ($id);
($rec{$db_key} eq $id) or (&site_html_rate_failure ("Unable to find link with ID '$id'.") and return);
# Increase the rating.
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) > 21600) and (@IP = ());
foreach $ip (@IP) {
$ip eq $ENV{'REMOTE_ADDR'} and ($visited++ and last);
}
close HIT;
if (!$visited) {
push (@IP, $ENV{'REMOTE_ADDR'});
$votes = $votes + 1;
$rating = $rating + $old_rating;
open (HIT, ">$db_rates_path/$id") or &cgierr ("Can't open for output counter file. Reason: $!");
if ($db_use_flock) { flock (HIT, 2) or &cgierr ("Can't get file lock. Reason: $!"); }
local $" = "\n";
print HIT "$votes $rating\n$time\n@IP";
close HIT;
&home_site_html_rating_form_success($id, $url, $title, $votes, $rating);
}
else {
&site_html_rate_failure ("Sorry, you've already rated for this resource once recently.");
}
}
else {
open (HIT, ">$db_rates_path/$id") or &cgierr ("Can't increment counter file '$db_rates_path/$id'. Reason: $!");
print HIT "1 $rating\n$time\n$ENV{'REMOTE_ADDR'}";
close HIT;
&home_site_html_rating_form_success($id, $url, $title, $votes, $rating);
}
}
#############################################
"Probally this script is a mod of the jump.cgi"
What is necessary ???
Anyone have an easy way to do this?
Regards,
Marco Aurélio
I want to make a mod called "vote.cgi" which is a mod of the "jump.cgi" but I don't have experience whith Perl. The objective is that when the remote user click in pre-definited link like eg: <a href"http://www.fulano.com/cgi-bin/vote.cgi?ID=01">Vote for My Site"</a> then the "vote.cgi" should be open a remote_hit_success.html template instead like they normally do in the same browser window whit a link to refer ID. The hits is count whith the same proccess in the "jump.cgi".
Look this code:
#############################################
---> eg. ratehome.cgi "I want anything like this, but I think that's could be more simple"
# Required Librariers
# --------------------------------------------------------
eval {
($0 =~ m,(.*)/[^/]+,) && unshift (@INC, "$1"); # Get the script location: UNIX /
($0 =~ m,(.*)\\[^\\]+,) && unshift (@INC, "$1"); # Get the script location: Windows \
require "admin/links.cfg"; # Change this to full path to links.cfg if you have problems.
require "$db_lib_path/db_utils.pl";
require "$db_lib_path/links.def";
$build_use_templates ?
require "$db_lib_path/site_html_templates.pl" :
require "$db_lib_path/site_html.pl";
};
if ($@) {
print "Content-type: text/plain\n\n";
print "Error including libraries: $@\n";
print "Make sure they exist, permissions are set properly, and paths are set correctly.";
exit;
}
# ========================================================
eval { &main; }; # Trap any fatal errors so the program hopefully
if ($@) { &cgierr("fatal error: $@"); } # never produces that nasty 500 server error page.
exit; # There are only two exit calls in the script, here and in in &cgierr.
sub main {
# --------------------------------------------------------
local (%in) = &parse_form;
if ($in{'R'}) {
&rate_it;
}
elsif ($in{$db_key} =~ /^\d+$/) {
my (%rec) = &get_record ($in{$db_key});
($rec{$db_key} eq $in{$db_key}) ?
&site_html_rate_form (%rec) :
&site_html_rate_failure ("Unkown Link ID: $in{$db_key}");
}
else {
print "Location: $build_ratings_url/\n\n";
}
}
sub rate_it {
# --------------------------------------------------------
my $id = $in{$db_key};
my $delim = quotemeta($db_delim);
my $time = time();
my $rating = $in{'R'};
# Make sure we have a valid rating.
unless (($rating =~ /^\d\d?/) and ($rating >= 1) and ($rating <= 10)) {
&site_html_rate_failure ("Your rating '$rating' is invalid.");
return;
}
# Let's get the link information.
my %rec = &get_record ($id);
($rec{$db_key} eq $id) or (&site_html_rate_failure ("Unable to find link with ID '$id'.") and return);
# Increase the rating.
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) > 21600) and (@IP = ());
foreach $ip (@IP) {
$ip eq $ENV{'REMOTE_ADDR'} and ($visited++ and last);
}
close HIT;
if (!$visited) {
push (@IP, $ENV{'REMOTE_ADDR'});
$votes = $votes + 1;
$rating = $rating + $old_rating;
open (HIT, ">$db_rates_path/$id") or &cgierr ("Can't open for output counter file. Reason: $!");
if ($db_use_flock) { flock (HIT, 2) or &cgierr ("Can't get file lock. Reason: $!"); }
local $" = "\n";
print HIT "$votes $rating\n$time\n@IP";
close HIT;
&home_site_html_rating_form_success($id, $url, $title, $votes, $rating);
}
else {
&site_html_rate_failure ("Sorry, you've already rated for this resource once recently.");
}
}
else {
open (HIT, ">$db_rates_path/$id") or &cgierr ("Can't increment counter file '$db_rates_path/$id'. Reason: $!");
print HIT "1 $rating\n$time\n$ENV{'REMOTE_ADDR'}";
close HIT;
&home_site_html_rating_form_success($id, $url, $title, $votes, $rating);
}
}
#############################################
"Probally this script is a mod of the jump.cgi"
What is necessary ???
Anyone have an easy way to do this?
Regards,
Marco Aurélio