#!/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; }
	}
}





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 $pasth = $dbh->prepare("select * from listings_lan3 where MLSNUM = '$INPUT{mlsnumber}'");
$pasth->execute;

while (($MLSNUM, $Class, $Type, $Area, $Price, $AddressNumber, $AddressDirection, $AddressStreet, $Address2, $City, $State, $Zip, $Status, $SaleRent, $Tillable, $CityLimits, $Improvements, $Wooded, $CropRights, $FloodPlain, $OldMLSNUM, $AgentID, $AgentName, $AgentPhone, $ListingOffice1ID, $ListingOffice1Name, $ListingOffice1Phone, $CoAgentID, $CoAgentName, $CoAgentPhone, $ListingOffice2ID, $ListingOffice2Name, $ListingOffice2Phone, $Blank34, $Blank35, $Blank36, $Blank37, $LinkedMLSNUM, $Blank39, $County, $Township, $Subdivision, $Zoning, $Legal, $ApproxLotSize, $Irregular, $Acres, $PricePerAcre, $WoodedPercent, $TillablePercent, $Wetland, $IngressEgress, $RoadFrontage, $ElementarySchool, $MiddleSchool, $HighSchool, $Reserved, $Water, $Sewer, $Electric, $Gas, $SoilInfo, $CropYields, $CropPossession, $EasementAccess, $Blank66, $Directions, $DirectionsContinued, $Blank69, $TaxID, $LandValue, $ImproveValue, $EstimatedAnnualTax, $Exempt, $DitchFee, $OtherExp, $OtherExpPerQMY, $BlueRiverConsFee, $AssoDues, $AssocDuesPerQMY, $Auction, $AuctionDate, $Assumption, $Remarks, $Blank85, $Contract, $SellerAssisted, $Blank88, $Blank89, $Blank90, $Blank91, $Blank92, $Blank93, $Blank94, $Blank95, $Blank96, $Blank97, $Blank98, $Blank99, $Blank100, $Blank101, $Blank102, $Blank103, $Blank104, $Blank105, $Blank106, $Blank107, $Blank108, $UsesFeaturesDB) = $pasth->fetchrow_array()) {


open(DBFILE,"remarksdb.txt");
@dbfile = <DBFILE>;
close(DBFILE);

foreach $dbline (@dbfile) {
$dbline =~ s/\n//gi;
if ($dbline) {
$Remarks =~ s/(.*?)$dbline//gi;
}
#$makestuff .= "$dbline\n";
}


$preprice = $Price;

	$principal = "$Price";
	$interest = 6.5;
	$monthlyinterest = ($interest)/1200;
	$termyear = 30;
	$numberofmonths = $termyear*12;
	
	$temp = 1 + $monthlyinterest;
	
	$expon = 1;
	for ($p = 0; $p < $numberofmonths; $p++)
	{
		$expon = $temp * $expon;
	}
	
	$expon = 1 / $expon;
	$expon = 1 - $expon;
	$expon = $monthlyinterest / $expon;
	
	$monthlypayment = $principal * $expon;

	$monthlypayment=sprintf("%.2f",$monthlypayment);
	$monthlypayment = &commas($monthlypayment);

	$Price = &commas($Price);

	$monthlypayment = &commas($monthlypayment);
	$mortgagetax = $EstimatedAnnualTax;
	$EstimatedAnnualTax = &commas($EstimatedAnnualTax);


if ($SaleRent eq "S") {
$SaleRent = "For Sale";
}
else {
$SaleRent = "For Rent";
}

if ($Address2) {
$Address2 = "$Address2<br>";
}
else {
}

if ($ListingOffice1ID eq "130") {
$printoffice = "<table border=0 cellpadding=0 cellspacing=0><tr><td><img src=images/era_showlogo.gif></td><td><b>Offered By:</b><br>$AgentName<br>$ListingOffice1Name<br>765-741-9111</td></tr></table>"
}
else {
$printoffice = "<b>Offered By</b><br>$AgentName<br>$ListingOffice1Name<br>"
}

@thefeatures = split(/\|/,$UsesFeaturesDB);

$startcount = "0";
foreach $one (@thefeatures) {

$yasth = $dbh->prepare("select featurename,categoryname from features where codenum = '$one'");
$yasth->execute;

while (($realname,$categoryname) = $yasth->fetchrow_array()) {

$categoryname = lc($categoryname);
$realname = lc($realname);

$realname =~ s/CHR1/\'/gi;
$realname =~ s/CHR2/\"/gi;
$categoryname =~ s/CHR1/\'/gi;
$categoryname =~ s/CHR2/\"/gi;


$showfeaturestable .= "<td><img src=images/dot.gif>$categoryname<b>$realname</b></td>";

if ($startcount eq "2") {
$showfeaturestable .= "</tr><tr>";
$startcount = "0";
}
else {
$startcount++;
}

}
}


if ($FloodPlain) {
$cFloodPlain = "<img src=images/dot.gif>FloodZone <b>$FloodPlain</b><br>";
}
else {
}


if ($Zoning) {
$cZoning = "<img src=images/dot.gif>Zoning <b>$Zoning</b><br>";
}
else {
}

if ($Legal) {
$cLegal = "<img src=images/dot.gif>Legal <b>$Legal</b><br><img src=images/line_spacer.gif height=1 width=1><br>";
}
else {
}

if ($ApproxLotSize) {
$cApproxLotSize = "<img src=images/dot.gif>Lot Size <b>$ApproxLotSize</b><br><img src=images/line_spacer.gif height=1 width=1><br>";
}
else {
}

if ($Irregular) {
$cIrregular = "<img src=images/dot.gif>Irregular <b>$Irregular</b><br><img src=images/line_spacer.gif height=1 width=1><br>";
}
else {
}

if ($PricePerAcre) {
$cPricePerAcre = "<img src=images/dot.gif>Per / Acre <b>$PricePerAcre</b><br><img src=images/line_spacer.gif height=1 width=1><br>";
}
else {
}

if ($TaxID) {
$cTaxID = "<img src=images/dot.gif>TaxID <b>\#$TaxID</b><br><img src=images/line_spacer.gif height=1 width=1><br>";
}
else {
}

if ($LandValue) {
$LandValue = &commas($LandValue);
$cLandValue = "<img src=images/dot.gif>Land Value <b>\$$LandValue</b><br>";
}
else {
}

if ($ImproveValue) {
$ImproveValue = &commas($ImproveValue);
$cImproveValue = "<img src=images/dot.gif>Improv. Value <b>\$$ImproveValue</b><br>";
}
else {
}

if ($SoilInfo eq "" || $SoilInfo eq "0") {
$cSoilInfo = "";
}
else {
$cSoilInfo = "<img src=images/dot.gif>Soil Info <b>$SoilInfo</b><br>";
}

if ($CropYields eq "" || $CropYields eq "0") {
$cCropYields = "";
}
else {
$cCropYields = "<img src=images/dot.gif>Crop Yeilds <b>$CropYields</b><br>";
}

if ($CropPossession eq "" || $CropPossession eq "0") {
$cCropPossession = "";
}
else {
$cCropPossession = "<img src=images/dot.gif>Crop Possession <b>$CropPossession</b><br>";
}

if ($EasementAccess eq "" || $EasementAccess eq "0") {
$cEasementAccess = "";
}
else {
$cEasementAccess = "<img src=images/dit.gif>Easement Access <b>$EasementAccess</b><br>";
}




if ($LandValue eq "" || $LandValue eq "0") {
$cLandValue = "";
}
else {
$LandValue = &commas($LandValue);
$LandValue = "\$$LandValue";
$cLandValue = "<img src=images/dot.gif>Land Value <b>$LandValue</b><br>";
}

#$cLandValue = &commas($cLandValue);
#$cLandValue = "\$$cLandValue";





if ($Wooded eq "NO" || $Wooded eq "No") {
$cWoodedPercent = "";
}
else {
$cWoodedPercent = "<b>$WoodedPercent\%</b>";
}

if ($Tillable eq "NO" || $Tillable eq "No") {
$cTillablePercent = "";
}
else {
$cTillablePercent = "<b>$TillablePercent\%</b>";
}


if ($RoadFrontage eq "" || $RoadFrontage eq "0") {
$cRoadFrontage = "";
}
else {
$cRoadFrontage = "<img src=images/dot.gif>Road Frontage <b>$RoadFrontage</b><br>";
}


$starting = "";
$bigcount = "1";
$stop = "no";
$showthumbs = "";
$anypictures = "no";
$totalnumber = "0";

while ($stop ne "yes") {
#$showthumbs .= "<tr><td>tiny/meiar$MLSNUM$starting\.jpg</td></tr>";
if (-e "/home/muncieml/public_html/images/photos/tiny/meiar$MLSNUM$starting\.jpg") {
$anypictures = "yes";
#$buildscript .= "images\[$bigcount\] \= new Image\(\)\nimages\[$bigcount\]\.src \= \'images\/photos\/full\/meiar$MLSNUM$starting\.jpg\'\;\n\n";
$buildscript .= "	testurl[$bigcount]=\"http://www.munciemls.com/images/photos/full\/meiar$MLSNUM$starting\.jpg\"\n";

 $showthumbs .= "<td width=\"44\" valign=\"top\"><a href=\"javascript: showupdate($bigcount)\"><img src=\"images/photos/tiny/meiar$MLSNUM$starting\.jpg\" border=0></a><br></td>";
$totalnumber++;
#$showthumbs .= "<td width=\"62\"><a href=\"javascript: showupdate($bigcount)\"><img src=\"images/photos/tiny/meiar$MLSNUM$starting\.jpg\" border=0></a></td><td width=\"2\"><img src=\"images/white_bar.gif\" height=\"45\" width=\"1\"></td>";
$rowcount++;
if ($rowcount eq "5") {
$rowcount = "0";
$showthumbs .= "</tr><tr>";

}
$bigcount++;
}


if ($starting eq "") {
$starting = "a";
}
elsif ($starting eq "a") {
$starting = "b";
}
elsif ($starting eq "b") {
$starting = "c";
}
elsif ($starting eq "c") {
$starting = "d";
}
elsif ($starting eq "d") {
$starting = "e";
}
elsif ($starting eq "e") {
$starting = "f";
}
elsif ($starting eq "f") {
$starting = "g";
}
elsif ($starting eq "g") {
$starting = "h";
}
elsif ($starting eq "h") {
$stop = "yes";
$starting = "";
}
else {
$stop = "yes";
#print "Starting unknown for meiar$MLSNUMber$starting\.jpg...\n";
}

}



if (-e "/home/muncieml/public_html/images/photos/full/meiar$MLSNUM\.jpg") {
$showpicture = "http://www.munciemls.com/images/photos/full/meiar$MLSNUM\.jpg";
}
else {
$showpicture = "http://www.munciemls.com/images/nophoto.gif";
}



if ($totalnumber > "1") {
$showgallery = "<font face=\"Arial, Helvetica, sans-serif\"><font size=\"3\">photo<b>gallery</b></font></font><br><img src=\"images/line_spacer.gif\" height=\"3\" width=\"1\"><br><table border=\"0\" cellpadding=\"0\" cellspacing=\"1\"><tr>$showthumbs</tr></table><br>";
}
else {
$showgallery = "";
}

$searchstrings = "City=$INPUT{City}&County=$INPUT{County}&MinPrice=$INPUT{MinPrice}&MaxPrice=$INPUT{MaxPrice}&MinBed=$INPUT{MinBed}&MinBath=$INPUT{MinBath}&Acreage=$INPUT{Acreage}&YBuilt=$INPUT{YBuilt}&MinSF=$INPUT{MinSF}&MaxSF=$INPUT{MaxSF}&Address=$INPUT{Address}&Remarks=$INPUT{Remarks}&Show=$INPUT{Show}&sortby=$INPUT{sortby}&orderby=$INPUT{orderby}&Page=$INPUT{Page}";

if ($ENV{QUERY_STRING} =~ /City/) {
$showresultsback = "<a href=\"search.idx?$searchstrings\">Return To Search Results</a>";
}
else {
$showresultsback = "";
}


print <<"STARTPAGECONTENT";
<html>
<head>
<title>MuncieMLS.com MLS #$MLSNUM Listing Printout</title>
<link rel="stylesheet" TYPE="text/css" href="includes/style.css">
<script Language="JavaScript">
testurl = new Array($bigcount);

$buildscript



			function showupdate(photoIndex, photoDisplayType)
			{
			document['picture'].src = testurl[photoIndex];
			
			return;
			}
			
</script>
</head>
<body bgcolor="white">
<center>
<table border="0" cellpadding="0" cellspacing="0" widht="581">
<tr>
<td valign=top width=581>

<table border="0" cellpadding="0" cellspacing="0" width="581">
<tr>
<td colspan="2" width="581">
<table border="0" cellpadding="3" cellspacing="2" width="100%" bgcolor="#666666">
<tr>
<td valign="Top" width="100%" bgcolor="#E2E2E2" align="center">
<a href="javascript:printversion();">CLICK HERE TO PRINT THIS LISTING SHEET</a>     |     <a href="javascript:window.close()">CLOSE WINDOW</a><br>
</td>
</tr>
</table>
<hr color="#666666" width="581">
<font size="6" face="Arial Black">MuncieMLS.com</font>&nbsp;&nbsp;<font size="3" face="Arial"><b>Listing Sheet</b></font><br>
</td>
</table>
<table border="0" cellpadding="0" cellspacing="0" width="581">
<tr>
<td colspan="2">
<img src="images/headers/land_propertydetails.gif" height="33" width="581" alt="Land Property Details">
</td>
</tr>
</table>
<table border="0" cellpadding="0" cellspacing="0" width="581">
<tr>
<td width="341" valign="top">
<table border="0" cellpadding="6" cellspacing="0" width="341">
<tr>
<td width="335" valign="top">

<script language=javascript>
function sqftdetails(desktopURL){
        desktop =window.open(desktopURL,"name","toolbar=no,location=no,status=yes,menubar=no,scrollbars=no,width=384,height=325,resizable=no");
        }
function mortgagechange(desktopURL){
        desktop =window.open(desktopURL,"name","toolbar=no,location=no,status=yes,menubar=no,scrollbars=no,width=384,height=325,resizable=no");
        }
	function RequestShowing()
        {
        msgWindow=window.open("showing.idx?mls=$MLSNUM&address=$AddressNumber $AddressDirection $AddressStreet&city=$ShowCity{$City}&state=Indiana&zip=$Zip","displayWindow","toolbar=no,width=465,height=540,directories=no,status=no,scrollbars=yes,resize=no,menubar=no")
        }
function printversion(desktopURL)
	{
        window.print("showdetails_land_print.idx?mlsnumber=$MLSNUM","displayWindow","toolbar=no,width=635,height=540,directories=no,status=no,scrollbars=yes,resize=no,menubar=no")
        }
// -->
</script>

	<img src="$showpicture" name=picture><br>$showgallery<Br>
<img src="images/line_spacer.gif" height="3" width="1"><br>
<img src="images/line_spacer.gif" height="5" width="1"><br>
<font face="Arial, Helvetica, sans-serif"><font size="3">property<b>remarks</b></font></font><br>
<img src="images/line_spacer.gif" height="3" width="1"><br>
<img src="images/black_fill.gif" height="1" width="335"><br>
<img src="images/line_spacer.gif" height="1" width="11">$Remarks<br>
<img src="images/line_spacer.gif" height="3" width="1"><br>
<img src="images/line_spacer.gif" height="3" width="1"><br>
<img src="images/black_fill.gif" height="1" width="335"><br>
<img src="images/line_spacer.gif" height="3" width="1"><br>
<center>
<table border="0" cellpadding="0" cellspacing="0" width="335">
<tr>
<td valign="top" width="50%">
<img src="images/dot.gif">Tillable <b>$Tillable</b> $cTillablePercent<br>
<img src="images/dot.gif">City Limits <b>$CityLimits</b><br>
<img src="images/dot.gif">Improvements <b>$Improvements</b><br>
<img src="images/dot.gif">Wooded <b>$Wooded</b> $cWoodedPercent<br>
<img src="images/dot.gif">Crop Rights <b>$CropRights</b><br>
<img src="images/dot.gif">Flood Plain <b>$FloodPlain</b><br>
$cRoadFrontage

</td>
<td valign="top" width="50%">
<img src="images/dot.gif">Wetland <b>$Wetland</b><br>
<img src="images/dot.gif">Ingress/Egress <b>$IngressEgress</b><br>
<img src="images/dot.gif">Water <b>$Water</b><br>
<img src="images/dot.gif">Sewer <b>$Sewer</b><br>
<img src="images/dot.gif">Electric </b>$Electric</b><br>
<img src="images/dot.gif">Gas <b>$Gas</b><br>
$cSoilInfo
$cCropYields
$cCropPossession
$cEasementAccess
$cLandValue

</td>
</tr>
</table>
</center>

</td>
</tr>
</table>
</td>
<td width="240" valign="top" bgcolor="#E2E2E2">
<table border="0" cellpadding="6" cellspacing="0" width="100%">
<tr>
<td valign="top">
<font face="Arial, Helvetica, sans-serif"><font size="4">property<b>overview</b></font></font><br>
$Type <font color="green">$Status</font> $SaleRent<br>
$AddressNumber $AddressDirection $AddressStreet<br>
$Address2
$ShowCity{$City}, IN $Zip<br>
MLS <b>#$MLSNUM</b><br>
<font color="#990000"><b>\$$Price</b> / <b>\$$monthlypayment*</b> Monthly</font><br><br>
<br>
$printoffice
<br>
<table border="0" cellpadding="3" cellspacing="1" border="1" bgcolor="navy">
<tr>
<td valign="top" bgcolor="navy"><font color="white"><b>Unique Listing Address</b></font></td>
</tr>
<td valign="top" bgcolor="#E2E2E2">
 <a href="http://$MLSNUM.MuncieMLS.com">http://$MLSNUM.MuncieMLS.com</a>
</td>
</tr>
</table>
<br>
<font face="Arial, Helvetica, sans-serif"><font size="3">property<b>details</b></font></font><br>
<img src="images/line_spacer.gif" height="3" width="1"><br>
<img src="images/dot.gif">County <b>$County</b><br><img src="images/line_spacer.gif" height="1" width="1"><br>
<img src="images/dot.gif">Township <b>$Township</b><br><img src="images/line_spacer.gif" height="1" width="1"><br>
<img src="images/dot.gif">Area <b>$Area</b><br><img src="images/line_spacer.gif" height="1" width="1"><br>
<img src="images/dot.gif">Subdivision <b>$Subdivision</b><br><img src="images/line_spacer.gif" height="1" width="1"><br>
<img src="images/dot.gif">Acres <b>$Acres</b><br><img src="images/line_spacer.gif" height="1" width="1"><br>
<img src="images/dot.gif">Elem. School <b>$ElementarySchool</b><br><img src="images/line_spacer.gif" height="1" width="1"><br>
<img src="images/dot.gif">Middle School <b>$MiddleSchool</b><br><img src="images/line_spacer.gif" height="1" width="1"><br>
<img src="images/dot.gif">High School <b>$HighSchool</b><br><img src=images/line_spacer.gif height=1 width=1><br>
$cZoning
$cLegal
$cApproxLotSize
$cIrregular
<img src="images/dot.gif">Est. Annual Taxes <b>$EstimatedAnnualTax</b><img src="images/line_spacer.gif" height="1" width="1"><br>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td valign="top" width="15">
<img src="images/dot.gif">
</td><td valign="top" width="100%">Directions: <b>$Directions&nbsp;$DirectionsContinued</b><br></td></tr></table>
</td>
</tr>
</table>
</td>
</tr>
</table>
<br>
<table border="0" cellpadding="0" cellspacing="0" width="581">
<tr>
<td valign="top" width="6"><img src="images/line_spacer.gif" height="1" width="6"><br></td>
<td valign="top" width="576">
<font face="Arial, Helvetica, sans-serif"><font size="3">property<b>features</b></font></font><br>
<img src="images/line_spacer.gif" height="2" width="1"><br>
<img src="images/black_fill.gif" height="2" width="576"><br>
<img src="images/line_spacer.gif" height="2" width="1"><br>
<table border=0 cellpadding=0 cellspacing=0 width=100%><tr>
$showfeaturestable</tr>
</table>
</td>
</tr>
</table>
<br>
$makestuff
<br><br>
<table border="0" cellpadding="0" cellspacing="0" width="581">
<tr>
	<td width="40" valign="middle"><center><img src="images/eho.gif" alt="Equal Housing Opportunity"><br><img src="images/re.gif" alt="REALTOR"></center></td>
	<td width="541" valign="top"><b><font size="1" face="Arial, Helvetica, sans-serif">The materials contained within this page may not be reproduced without the express written consent of ERA Eagle Real Estate, Inc. or IDXNow IDX Real Estate Solutions.  The information herein is believed to be accurate and timely, but no warranty as such is expressed or implied.</font></b></td>
</tr>
<tr>
	<td width="40" valign="middle">&nbsp;</td>
	<td valign="top" width="541" align="center"><img src="images/idxnow.gif"><br><b>http://www.idxnow.com</b></td>
</tr>
</table>
</center>
</body>
</html>


STARTPAGECONTENT
}



$dbh->disconnect;

sub commas {
	local($_)=@_;
	1 while s/(.*\d)(\d\d\d)/$1,$2/;
	$_;
}




