#!/usr/bin/perl

require "config.idx";

$long = $ENV{'QUERY_STRING'};

if ($long) {
	@pairs=split(/&/,$long);
	foreach $item(@pairs) {
		($name,$content)=split (/=/,$item,2);
		$content=~tr/+/ /;
		$content=~ s/%(..)/pack("c",hex($1))/ge;
		if ($INPUT{$name}) { $INPUT{$name} = $INPUT{$name}.",".$content; }
		else { $INPUT{$name} = $content; }
	}
}
else {
	read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
	@pairs = split(/&/, $buffer);
	foreach $pair (@pairs) {
		($name, $value) = split(/=/, $pair);
		$value =~ tr/+/ /;
		$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
		if ($INPUT{$name}) { $INPUT{$name} = $INPUT{$name}.",".$value; }
		else { $INPUT{$name} = $value; }
	}
}
print "Content-type: text/html\n\n";

use DBI;
my $dsn = "DBI:mysql:database=$d_name;host=localhost";
my $dbh = DBI->connect($dsn, $d_username, $d_pass, {RaiseError => 1}) || die $DBI::errstr;

	my $mesth = $dbh->prepare("select userid,email,firstname,lastname from users where email = '$INPUT{userid}'");
	$mesth->execute;

print <<"TITLE";
<html>
<head>
<title>ERA Eagle Real Estate MuncieMLS.com</title>
TITLE

&header;
	while (($userid,$email,$firstname,$lastname) = $mesth->fetchrow_array()) {

print qq~
<td valign="top" width="581">
<table border="0" cellpadding="0" cellspacing="0" width="581">
<tr>
<td valign="top" colspan="2" width="581">
<img src="images/headers/myhomes_account.gif" height="33" width="581" alt="MY HOMES Account"><br>
</td>
</tr>
</table>
<br>
<font size="4">
<b>
~;
if ($INPUT{now} eq "yes") {
	my $amesth = $dbh->prepare("UPDATE users set $INPUT{type} = 'n' where email = '$INPUT{userid}'");
	$amesth->execute;
print qq~
E-Mail to <u>$email</u> has been blocked!
~;
}
else {
print qq~
Are you sure you want to unsubscribe <u>$email</u>?<br>
<a href="unsubscribe.idx?type=$INPUT{type}&userid=$INPUT{userid}&now=yes">Yes Block Me</a>   --    <a href="http://www.MuncieMLS.com">No, Allow E-Mails</a>
</b></font>
</td>
~;
}
}
&footer;
