#!/usr/bin/perl
###############################
# Hot Links SQL 2.1 reviews.cgi
# Created by Mike Ramirez
# Nothing below here is configurable
###############################
require './source/headerfooter.pl';
require './source/config.pl';
require './source/banner.pl';
require './source/linkbuild.pl';
require './lang/langset.pl';
use CGI;
use DBI;
my $q = CGI->new;
print $q->header;
my $action = $q->param("action");
###########################################
# Get all the links
###########################################
my $dbh = DBI->connect("DBI:mysql:$dbname;$dbhost", $dblogin, $dbpass) || print "Could not connect to database
";
my $sth = $dbh->prepare("SELECT * FROM links ORDER BY id");
$sth->execute();
while (my $results = $sth->fetchrow_hashref) {
my $linkid = $results->{id};
my $category = $results->{category};
my $sitename = $results->{sitename};
my $url = $results->{url};
my $email = $results->{email};
my $name = $results->{name};
my $password = $results->{password};
my $description = $results->{description};
my $addedon = $results->{addedon};
my $edpick = $results->{edpick};
my $keywords = $results->{keywords};
my $activelink = $results->{activelink};
my $enddate = $results->{enddate};
my $udate = $results->{udate};
my $recipurl = $results->{recipurl};
my $affiliate = $results->{affiliate};
my $image = $results->{image};
push(@links, "$linkid|$category|$sitename|$url|$email|$name|$password|$description|$addedon|$edpick|$keywords|$activelink|$enddate|$udate|$recipurl|$affiliate|$image");
}
$sth->finish;
$dbh->disconnect;
###############################
if ($action eq 'rate') {&rateit}
elsif ($action eq 'review') {&reviewit}
elsif ($action eq 'dorate') {&dorating}
elsif ($action eq 'doreview') {&doreview}
elsif ($action eq 'showreviews') {&showreviews}
elsif ($action eq 'viewreview') {&viewreview}
else {&error}
###############################
sub showreviews {
###############################
my $id = $q->param("id");
my $dbh = DBI->connect("DBI:mysql:$dbname;$dbhost", $dblogin, $dbpass) || print "Could not connect to database
";
my $sth = $dbh->prepare("SELECT * FROM reviews WHERE id = '$id'") || print "could not access database";
$sth->execute();
my $n=0;
while (my $results = $sth->fetchrow_hashref) {
my $id = $results->{id};
my $name = $results->{name};
my $email = $results->{email};
my $review = $results->{review};
my $ip = $results->{ip};
$reviewshash{$n++} = "$id|$name|$email|$review|$ip";
}
$sth->finish;
$dbh->disconnect;
foreach $line (@links) {
chomp($line);
my @linkinfo = split(/\|/, $line);
if ($linkinfo[0] == $id) {$uselink = $line}
}
my @uselink = split(/\|/, $uselink);
&header;
print <<"HTML";
HTML
my $count=1;
foreach $value (values %reviewshash) {
my @reviewinfo = split(/\|/, $value);
my $emailaddy = $reviewinfo[2];
$emailaddy =~ s/\@/ /;
my $review = $reviewinfo[3];
$review =~ s/\r\n/ /g;
print <<"HTML";
| $revtext3 $count |
| $adtext24: | $reviewinfo[1] |
| $adtext56: | $emailaddy |
| $adtext143: | $review |
| IP: | $reviewinfo[4] |
| |
HTML
$count++;
}
print <<"HTML";
|
|
HTML
&footer;
}
###############################
sub rateit {
###############################
my $id = $q->param("id");
foreach $line (@links) {
chomp($line);
my @linkinfo = split(/\|/, $line);
if ($linkinfo[0] eq $id) {$uselink = $line}
}
my @uselink = split(/\|/, $uselink);
&header;
print <<"HTML";
|
HTML
if ($displayadverts == 1) {&showbanner(ALL)}
print <<"HTML";
|
HTML
&footer;
}
###############################
sub dorating {
###############################
my $ip = $ENV{'REMOTE_ADDR'};
my $id = $q->param("id");
my $dbh = DBI->connect("DBI:mysql:$dbname;$dbhost", $dblogin, $dbpass) || print "Could not connect to database
";
my $sth = $dbh->prepare("SELECT * FROM ratings WHERE ip = '$ip' AND id = '$id'") || print "could not access database";
$sth->execute();
unless ($sth->rows) {
$sth->finish;
my $rating = $q->param("rating");
my $sth = $dbh->prepare("INSERT INTO ratings VALUES (\"$id\", \"$rating\", \"$ip\")") || &error("Could not insert new row.");
$sth->execute();
$sth->finish;
&header;
print <<"HTML";
|
HTML
if ($displayadverts == 1) {&showbanner(ALL)}
print <<"HTML";
|
$revtext5 |
$revtext14
|
HTML
&footer;
} else {
&header;
print <<"HTML";
|
HTML
if ($displayadverts == 1) {&showbanner(ALL)}
print <<"HTML";
|
HTML
&footer;
}
}
###############################
sub reviewit {
###############################
my $id = $q->param("id");
&header;
print <<"HTML";
|
HTML
if ($displayadverts == 1) {&showbanner(ALL)}
print <<"HTML";
|
HTML
&footer;
}
###############################
sub doreview {
###############################
my $ip = $ENV{'REMOTE_ADDR'};
my $id = $q->param("id");
my $name = $q->param("name");
my $email = $q->param("email");
my $review = $q->param("review");
if ((!$name) || (!$email) || (!$review)) {&error2}
my $dbh = DBI->connect("DBI:mysql:$dbname;$dbhost", $dblogin, $dbpass) || print "Could not connect to database
";
my $sth = $dbh->prepare("SELECT * FROM reviews WHERE ip = '$ip' AND id = '$id'") || print "could not access database";
$sth->execute();
unless ($sth->rows) {
$sth->finish;
$sth = $dbh->prepare("INSERT INTO temp_reviews VALUES (\"$id\", \"$name\", \"$email\", \"$review\", \"$ip\")") || &error("Could not insert new row.");
$sth->execute();
$sth->finish;
if ($emailnotifications == 1) {
open (MAIL, "|$sendmail -t") || &error("$shtext9");
print MAIL "To: $adminemail\n";
print MAIL "From: $adminemail\n",
"Subject: $revtext19 $title\n\n",
"$revtext20\n $baseurl/admin.cgi?action=admin";
close (MAIL);
}
&header;
print <<"HTML";
|
HTML
if ($displayadverts == 1) {&showbanner(ALL)}
print <<"HTML";
|
$revtext17 |
$revtext21
|
HTML
&footer;
} else {
&header;
print <<"HTML";
|
HTML
if ($displayadverts == 1) {&showbanner(ALL)}
print <<"HTML";
|
HTML
&footer;
}
}
###############################
sub error {
###############################
&header;
print <<"HTML";
|
HTML
if ($displayadverts == 1) {&showbanner(ALL)}
print <<"HTML";
|
$altext24 |
| $revtext23 |
HTML
&footer;
exit;
}
###############################
sub error2 {
###############################
&header;
print <<"HTML";
|
HTML
if ($displayadverts == 1) {&showbanner(ALL)}
print <<"HTML";
|
$altext24 |
| $revtext24 |
HTML
&footer;
exit;
}
$dbh->disconnect;