#!/usr/bin/perl

print "Content-type: text/html\n\n";

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; }
	}
}





if ($INPUT{action} eq "listingsend") { &listingsend; }
elsif ($INPUT{action} eq "listingmain") { &listingmain; }
elsif ($INPUT{action} eq "searchsend") { &searchsend; }
else { &searchmain; }





sub searchsend {

if ($INPUT{script} eq "res") {
$extension = "";
}
else {
$extension = "\_$INPUT{script}";
}

open(MAIL,"|/usr/sbin/sendmail -t");
print MAIL "To: $INPUT{ToEmail}\n";
print MAIL "From: $INPUT{FromEmail}\n";
print MAIL "Subject: You have been E-Mailed A Property Search From Eagle Real Estate MuncieMLS.com!\n\n";
print MAIL "Hello $INPUT{To}\,\n\n$INPUT{From} has just sent you the following listing from Eagle Real Estate MuncieMLS.com. To view this search, please click the below link:\n\nEagle Real Estate MuncieMLS.com/search$extension\.idx?$INPUT{string}\n\n$INPUT{From} also left the following message:\n\n$INPUT{Message}\n\n";
close(MAIL);


print <<"STARTTHEPAGE";

<html>
<head>
<title>Eagle Real Estate MuncieMLS.com E-Mail Search</title>
<link rel="stylesheet" TYPE="text/css" href="includes/style.css">
</head>
<body bgcolor="white">
<table border="0" cellpadding="3" width="375" cellspacing="0">
<tr>
<td valign="top" width="100%">
<center>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td valign="top">
<font size="3" color="#990000"><b>Search Has Successfully Been E-Mailed!</b></font><br>Thank you for using the Eagle Real Estate MuncieMLS.com E-Mail Search.<br><br></font><br><br><br><br><br><a href="javascript:self.close()">[ Close This Window ]</a><br>
</td>
</tr>
</table>
</center>
</td>
</tr>
</table>

</body>
</html>

STARTTHEPAGE


}



sub searchmain {


print <<"STARTTHECOMOTION";

<html>
<head>
<title>Eagle Real Estate MuncieMLS.com E-Mail Search</title>
<link rel="stylesheet" TYPE="text/css" href="includes/style.css">
</head>
<body bgcolor="white">
<table border="0" cellpadding="3" width="375" cellspacing="0">
<tr>
<td valign="top" width="100%">
<center>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td valign="top" colspan="2">
<font size="3" color="#990000"><b>Who would you like to E-Mail this seasrch to?</b></font><br>Please specify your name and the recipients name below<br><br></font>
</td>
</tr>
<tr>
<form method="Post" action="email.idx">
<input type=hidden name=action value=searchsend>
<input type=hidden name=type value="s">
<input type=hidden name=script value="$INPUT{script}">
<input type=hidden name=string value="$ENV{QUERY_STRING}">
<td valign="top" colspan="2"><font face="Verdana, Arial, Helvetica, sans-serif"><font size=2><b>Enter Details Below:</b><br><br></td>
</tr>
<tr>
<td valign="top" width="55%"><font face="Verdana, Arial, Helvetica, sans-serif"><font size=2>Your Name:</td><td valign="top" width="45%"><input type="text" value="" name="From"><br></td>
</tr>
<td valign="top" width="55%"><font face="Verdana, Arial, Helvetica, sans-serif"><font size=2>Your E-Mail Address:</td><td valign="top" width="45%"><input type="text" value="" name="FromEmail"><br></td>
</tr>
<tr>
<td colspan="2"><br><img src="images/black_fill.gif" alt="line" width="340" height="1"><br><br></td>
</tr>
<tr>
<td width="55%" valign="top"><font face="Verdana, Arial, Helvetica, sans-serif"><font size=2>Recipients Name:</td><td valign="top" width="45%"><input type="text" value="" name="To"><br></td>
</tr>
<tr>
<td width="55%" valign="top"><font face="Verdana, Arial, Helvetica, sans-serif"><font size=2>Recipients E-Mail Address:</td><td valign="top" width="45%"><input type="text" value="" name="ToEmail"><br></td>
</tr>
<tr>
<td colspan="2"><br><img src="images/black_fill.gif" alt="line" width="340" height="1"><br><br></td>
</tr>
<tr>
<td colspan="2" valign="top"><font face="Verdana, Arial, Helvetica, sans-serif"><font size=2>
Message to Recipient:<br><br>
<textarea rows="5" name="Message" cols="35"></textarea><br><br>
<input type="submit" value="E-Mail This Home">
</form>
</td>
</tr>
</table>
</center>
</td>
</tr>
</table>

</body>
</html>










STARTTHECOMOTION

}

sub listingsend {

open(MAIL,"|/usr/sbin/sendmail -t");
print MAIL "To: $INPUT{ToEmail}\n";
print MAIL "From: $INPUT{FromEmail}\n";
print MAIL "Subject: You have been E-Mailed A Listing From Eagle Real Estate MuncieMLS.com!\n\n";
print MAIL "Hello $INPUT{To}\,\n\n$INPUT{From} has just sent you the following listing from Eagle Real Estate MuncieMLS.com.  To view this listing, please click on the following link:\n\n http://www.munciemls.com/showdetails$INPUT{type}\.idx?gate=email&mlsnumber=$INPUT{mlsnumber}\n\n$INPUT{From} attached the following message:\n\n$INPUT{Message}\n\n";
close(MAIL);

print <<"STARTTHEPAGE";

<html>
<head>
<title>Eagle Real Estate MuncieMLS.com E-Mail Listing</title>
<link rel="stylesheet" TYPE="text/css" href="includes/style.css">
</head>
<body bgcolor="white">
<table border="0" cellpadding="3" width="375" cellspacing="0">
<tr>
<td valign="top" width="100%">
<center>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td valign="top">
<font size="3" color="#990000"><b>Listing Has Successfully Been E-Mailed!</b></font><br>Thank you for using the Eagle Real Estate MuncieMLS.com E-Mail Listing Service.<br><br></font><br><br><br><br><br><a href="javascript:self.close()">[ Close This Window ]</a><br>
</td>
</tr>
</table>
</center>
</td>
</tr>
</table>

</body>
</html>


STARTTHEPAGE


}













sub listingmain {


print <<"SAVESTUFFPAGE";

<html>
<head>
<title>Eagle Real Estate MuncieMLS.com E-Mail Listing</title>
<link rel="stylesheet" TYPE="text/css" href="includes/style.css">
</head>
<body bgcolor="white">
<table border="0" cellpadding="3" width="375" cellspacing="0">
<tr>
<td valign="top" width="100%">
<center>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td valign="top" colspan="2">
<font size="3" color="#990000"><b>Who would you like to E-Mail this listing to?</b></font><br>Please specify your name and the recipients name below<br><br></font>
</td>
</tr>
<tr>
<form method="Post" action="email.idx">
<input type=hidden name="action" value="listingsend">
<input type=hidden name="type" value="$INPUT{type}">
<input type=hidden name="mlsnumber" value="$INPUT{mlsnumber}">
<td valign="top" colspan="2"><font face="Verdana, Arial, Helvetica, sans-serif"><font size=2><b>Enter Details Below:</b><br><br></td>
</tr>
<tr>
<td valign="top" width="55%"><font face="Verdana, Arial, Helvetica, sans-serif"><font size=2>Your Name:</td><td valign="top" width="45%"><input type="text" value="" name="From"><br></td>
</tr>
<td valign="top" width="55%"><font face="Verdana, Arial, Helvetica, sans-serif"><font size=2>Your E-Mail Address:</td><td valign="top" width="45%"><input type="text" value="" name="FromEmail"><br></td>
</tr>
<tr>
<td colspan="2"><br><img src="images/black_fill.gif" alt="line" width="340" height="1"><br><br></td>
</tr>
<tr>
<td width="55%" valign="top"><font face="Verdana, Arial, Helvetica, sans-serif"><font size=2>Recipients Name:</td><td valign="top" width="45%"><input type="text" value="" name="To"><br></td>
</tr>
<tr>
<td width="55%" valign="top"><font face="Verdana, Arial, Helvetica, sans-serif"><font size=2>Recipients E-Mail Address:</td><td valign="top" width="45%"><input type="text" value="" name="ToEmail"><br></td>
</tr>
<tr>
<td colspan="2"><br><img src="images/black_fill.gif" alt="line" width="340" height="1"><br><br></td>
</tr>
<tr>
<td colspan="2" valign="top"><font face="Verdana, Arial, Helvetica, sans-serif"><font size=2>
Message to Recipient:<br><br>
<textarea rows="5" name="Message" cols="35"></textarea><br><br>
<input type="submit" value="E-Mail This Home">
</form>
</td>
</tr>
</table>
</center>
</td>
</tr>
</table>

</body>
</html>

SAVESTUFFPAGE




}