#!/usr/bin/perl ############################### # Hot Links SQL 2.1 out.cgi # Created by Mike Ramirez # Nothing below here is configurable ############################### require './source/headerfooter.pl'; require './source/config.pl'; require './lang/langset.pl'; use CGI; use DBI; my $q = CGI->new; my $dbh = DBI->connect("DBI:mysql:$dbname;$dbhost", $dblogin, $dbpass) || print "Could not connect to database
"; my $localtime = localtime(); $localtime =~ s/\d\d:\d\d:\d\d//; my $id = $q->param("id"); my $ip = $ENV{REMOTE_ADDR}; # If we're exiting from an advert # my $out = $q->param("out"); if ($out) { # Click logging code # my $sth = $dbh->prepare("SELECT count FROM clickcount WHERE id = $id") || print "could not access database"; $sth->execute(); my $current_count=0; if ($sth->rows) {$current_count = $sth->fetchrow; $ad_id_exists = 1;} $current_count++; $sth->finish; if ($ad_id_exists == 1) { my $sth = $dbh->prepare("UPDATE clickcount SET count = '$current_count' WHERE id = '$id'") || print "could not access database"; $sth->execute(); $sth->finish; } else { my $sth = $dbh->prepare("INSERT INTO clickcount VALUES ($id, $current_count)") || &error("Could not insert new row."); $sth->execute(); $sth->finish; } my $sendto = $q->param("sendto"); if ($usegateways == 1) { $scriptout = 1; print "Content-type: text/html\n\n"; &header($scriptout); print <<"HTML";
$outtext1 $sendto.
$outtext2 $outtext3.
HTML &footer; } else { print "Content-type: text/html\n\n"; print ""; } # If we're exiting from an listing # } else { my $sth = $dbh->prepare("SELECT * FROM hitlog WHERE id = '$id' AND localtime = '$localtime' AND ip = '$ip'") || print "could not access database"; $sth->execute(); while (my $results = $sth->fetchrow_hashref) { $found_id = $results->{id}; } if (!$found_id) { $testing = 'not found'; $sth->finish; # Log the visitors click in the hit log my $sth = $dbh->prepare("INSERT INTO hitlog VALUES (\"$id\", \"$localtime\", \"$ip\")") || &error("Could not insert new row."); $sth->execute(); $sth->finish; # Log the visitors click in the hit total # my $sth = $dbh->prepare("SELECT count FROM hittotal WHERE id = $id") || print "could not access database"; $sth->execute(); my $current_count=0; if ($sth->rows) {$current_count = $sth->fetchrow; $ht_id_exists = 1;} $current_count++; if ($ht_id_exists == 1) { my $sth = $dbh->prepare("UPDATE hittotal SET count = \"$current_count\" WHERE id = \"$id\"") || print "could not access database"; $sth->execute(); $sth->finish; } else { my $sth = $dbh->prepare("INSERT INTO hittotal VALUES (\"$id\", \"$current_count\")") || &error("Could not insert new row."); $sth->execute(); $sth->finish; } # Log the visitors click in the pop total # my $sth = $dbh->prepare("SELECT count FROM hitspop WHERE id = $id") || print "could not access database"; $sth->execute(); my $current_count=0; if ($sth->rows) {$current_count = $sth->fetchrow; $hp_id_exists = 1;} $current_count++; if ($hp_id_exists == 1) { my $sth = $dbh->prepare("UPDATE hitspop SET count = \"$current_count\" WHERE id = \"$id\"") || print "could not access database"; $sth->execute(); $sth->finish; } else { my $sth = $dbh->prepare("INSERT INTO hitspop VALUES (\"$id\", \"$current_count\", \"0\")") || &error("Could not insert new row."); $sth->execute(); $sth->finish; } } my $sth = $dbh->prepare("SELECT * FROM links WHERE id = '$id'") || print "could not access database"; $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}; $outlink = "$linkid|$category|$sitename|$url|$email|$name|$password|$description|$addedon|$edpick|$keywords|$activelink|$enddate|$udate|$recipurl|$affiliate|$image"; } $sth->finish; $dbh->disconnect; if ($usegateways == 1) { $scriptout = 1; my @sendout = split(/\|/, $outlink); my $sendto = $q->param("sendto"); print $q->header; &header($scriptout); print <<"HTML";
$outtext1 $sendto.
$outtext2 $outtext3.
HTML &footer; } else { my @sendout = split(/\|/, $outlink); print $q->header; print ""; #print "$id | $localtime | $ip - $testing"; } }