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


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><a href=\"http://www.munciemls.com/agents.idx?action=showagent&agent=$AgentID\">$AgentName</a><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>";
}



&pull_photo_data_for_property_details_page($MLSNUM,4);  # routine at the bottom of config.idx



if (-e "/home/muncieml/public_html/pdf/$MLSNUM\.pdf") {
$showpdf = "
<table border=\"0\" cellpadding=\"4\" cellspacing=\"0\">
<tr>
<td valign=\"top\">
<a href=\"pdf/$MLSNUM.pdf\" target=\"_blank\"><img src=\"images/pdficon.gif\" border=\"0\"></a><br>
</td>
<td valign=\"middle\">
<a href=\"pdf/$MLSNUM.pdf\" target=\"_blank\">View Full Color<br>PDF Brochure</a><br>
</td>
</tr>
</table>
<br>
";
}


if (totalpictures > 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_lan.idx?$searchstrings\">Return To Search Results</a>";
}
else {
$showresultsback = "";
}

if ($INPUT{gate} eq "email") {
$checksave = "";
}
else {
$checksave = "<a href=\"javascript:save=window.open('save.idx?mlsnumber=$MLSNUM&type=lan','save','width=320, height=325, scrollbars=no'); save.focus();\"><img src=\"images/actions/savethishome.gif\" border=0></a><br>";
}

print qq~
<html>
<head>
<title>The ORR Home Selling Team >> Lots and Land Details</title>
<script Language="JavaScript">
testurl = new Array($bigcount);

$buildscript



			function showupdate(photoIndex, photoDisplayType)
			{
			document['picture'].src = testurl[photoIndex];
			
			return;
			}
			
</script>
~;

&header;

print qq~
<td valign="top" width="581">
<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="Lots & Land Property Details"><Br>
</td>
</tr>
<td valign="top">&nbsp;</td>
<td valign="top" align="right">
<img src="images/line_spacer.gif" alt="" width="4" height="1">$showresultsback <br><br>
</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">
	<img src="$showpicture" name=picture><br>
<img src="images/line_spacer.gif" height="3" width="1"><br>
<center>
<table border="0" cellpadding="0" cellspacing="0" width="300">
<tr>
<td colspan="3" valign="top">
<font face="Arial, Helvetica, sans-serif"><font size="3">visitor<b>actions</b></font></font><br>
<img src="images/line_spacer.gif" height="1" width="1"><br>
<img src="images/black_fill.gif" height="1" width="335"><br>
<img src="images/line_spacer.gif" height="1" width="1"><br>
</td>
</tr>
<tr>
<td valign="top" width="150">
<center>
<a href="http://www.gettherightloan.com/loan.cgi"><img src="images/actions/applyforloan.gif" border=0></a><br>
<a href="javascript:email=window.open('email.idx?action=listingmain&mlsnumber=$MLSNUM&type=_land','email','width=375, height=450, scrollbars=no'); email.focus();"><img src="images/actions/emailthishome.gif" border=0></a><br>
<a href="http://www.mapquest.com/maps/map.adp?country=US&address=$AddressNumber $AddressDirection $AddressStreet&city=$City&State=$State&zipcode=$Zip" target="_new"><img src="images/actions/mapproperty.gif" border="0"></a><br>
</center>
</td>
<td valign="top" width="150">
<center>
<a href="javascript:requestshowing=window.open('showing.idx?mls=$MLSNUM&address=$AddressNumber $AddressDirection $AddressStreet&city=$City&state=IN&zip=$Zip','requestshowing','width=465, height=540, scrollbars=yes'); requestshowing.focus();"><img src="images/actions/requestashowing.gif" border=0></a><br>
<a href="javascript:printversion=window.open('showdetails_land_print.idx?mlsnumber=$MLSNUM','printversion','width=635, height=540, scrollbars=yes'); printversion.focus();"><img src="images/actions/printer.gif" border="0" alt="Printer Friendly Version"></a><br>
$checksave
</center>
</td>
</tr>
</table>
</center>
<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><a href="javascript:mortgagechange=window.open('mortgagechange.idx?price=$preprice&mlsnum=$MLSNUM&mortgagetax=$EstimatedAnnualTax','mortgagechange','width=384, height=385, scrollbars=yes'); mortgagechange.focus();">[Change Assumptions]</a><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>
$showgallery
$showpdf
<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

~;
}

@variables = ($Cook{userid},$INPUT{mlsnumber});
$sql_query = "INSERT INTO hits values (?,?,'res',now())";
my $zzaasth = $dbh->do($sql_query, undef, @variables);

my $uasth = $dbh->do("update users set lastlogin = now() where userid = '$Cook{userid}'");

$dbh->disconnect;


&footer;

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




