#!/usr/bin/perl
#
use DBI;
require 'settings.ini';
require 'prices.ini';
require 'parse.cgi'; &parse_form();
$version = '1.1';
print "Content-Type: text/html\n\n";

$dbh = DBI->connect("DBI:mysql:$MySQL{'database'}:$MySQL{'host'}:$MySQL{'port'}", $MySQL{'user'}, $MySQL{'password'}, { RaiseError => 1, AutoCommit => 1});
$statement = "SELECT * from data "; $statement .= "ORDER BY RAND()" unless (!$Site{'scramble'});
$sth = $dbh->prepare($statement);
$rv = $sth->execute;

&header();
print qq|<p style="line-height: 1.5;">|;

#0 keyword
#1 oid
#2 buyer_site_name
#3 buyer_site_url
#4 buyer_name
#5 buyer_email
#6 date_purchased
#7 display_options

while(@row = $sth->fetchrow_array) {
	$row[0] =~ s/\b(\w+)\b/ucfirst($1)/ge; 
	if ($row[1]) {
		if ($row[5]) {
			@styles = split (/\|/, $row[7]);
			&styleit();
		}
		if ( ("\L$row[3]" !~ /^http:\/\//) && ("\L$row[3]" !~ /^https:\/\//) ) { $row[3] = "http://$row[3]"; } 
		print qq|<a href="$row[3]" class="link"$style$title>$row[0]</a> \n|;
	} else {
		$link = $row[0]; $link =~ s/ /_/g;
		print qq|<a href="$Site{'baseurl'}$Site{'cgi-bin'}/claim/$link.html" class="linkit">$row[0]</a> \n|;
	}
}
print "</p>";
&footer();

$rv = $sth->finish;
$rv = $dbh->disconnect;

sub styleit {
	$title = ""; $bold = ""; $color = "";
	$style = qq| style="|;
	foreach $st (@styles) {
		if ($st =~ /MOUSEOVER:/) { $st =~ s/MOUSEOVER://g; $title = qq| title="$st"|; }
		if ($st =~ /FONT:/) { $st =~ s/FONT://g; $style .= "font-size: $st\px;"; }
		if ($st =~ /COLOR:/) { $st =~ s/COLOR://g; $style .= "color: #$st;"; $color = "$st"; }
		if ($st eq "OL") { $style .= "border-top: thin solid #COLORSWAP;"; }
		if ($st eq "UL") { $style .= "text-decoration: underline;"; }
		if ($st eq "B") { $style .= "font-weight: bold;"; $bold = "true"; }
		if ($st eq "I") { $style .= "font-style: italic;"; }
	}
	if (!$color) { $color = "000000"; }
	$style =~ s/COLORSWAP/$color/g;
	#$style =~ s/border-top: thin solid/border-top: medium solid/g unless (!$bold);
	$style .= qq|"|;
}

sub header {
print qq|<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" id="sixapart-standard">
<head>
   <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
   <link rel="stylesheet" href="$Site{'baseurl'}/style.css" type="text/css" />
   
   <title>$Site{'name'}</title>
   
</head>

<body>

$Site{'header'}



$Site{'welcome'}
|;
}

sub footer {
print qq|<br>
<center>Don't see your zip code? <a href="$Site{'baseurl'}$Site{'cgi-bin'}/claim/set_your_own_keyword.html">Suggest your zip code</a>and claim it exclusively.  No one else can get the same zip code link!</a></center>

$Site{'footer'}

<p align="center" style="font-size: 12px; color: #808080;">Quikthinking Software Zip Code Links powered by LinkSizzler Version 1.1 - Copyright 2006 InfoMedia, Inc.</p>
</body>
</html>|;
}