#!/usr/bin/perl

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

print <<"top";

<table border="0" cellpadding="3" cellspacing="0" width="121" bgcolor="\white">
<tr>
<td valign="middle">
<b><font color="Red">Featured Property</font></b>
</td>
</tr>
</table>
<table border="0" cellpadding="6" cellspacing="0" width="121"> 
top

$d_name = "muncieml_db1";
$d_username = "muncieml_db1";
$d_pass = "\@rockdb1";


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 $uasth = $dbh->prepare("select Price,AddressNumber,AddressDirection,AddressStreet,City,Zip,Status,MLSNUM,Bedrooms,FullBaths,HalfBaths,TotalSqFt,Acres,AgentID,AgentName,CoAgentID,CoAgentName,ListingOffiice1Name,ListingOffice1Phone,ListingOffice1ID,Remarks from listings_res where ListingOffice1ID = '130' order by RAND() limit 1");
$uasth->execute;

$dbh->disconnect;

while (($Price,$AddressNumber,$AddressDirection,$AddressStreet,$City,$Zip,$Status,$MLSNUM,$Bedrooms,$FullBaths,$HalfBaths,$TotalSqFt,$Acres,$AgentID,$AgentName,$CoAgentID,$CoAgentName,$ListingOffiice1Name,$ListingOffice1Phone,$ListingOffice1ID,$Remarks) = $uasth->fetchrow_array()) {


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

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

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

if (-e "/home/muncieml/public_html/images/photos/thumbnail/meiar$MLSNUM\.jpg") {
$photourl = "images/photos/thumbnail/meiar$MLSNUM\.jpg";
}
else {
$photourl = "http://www.eagle-online.com/images/featured_nophoto.gif";
}

$Price = &commas($Price);

print qq~

<tr>
<td valign="top">
<font color="white" size="1">
<b>$AddressNumber $AddressDirection $AddressStreet<br>
$City, Indiana $Zip<br></b>
<b>Offered at \$$Price</b>
<br><b><font color="silver">Presented By:</font></b><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="agents.cgi?agent=$AgentID" class="uright">$AgentName</a><br><br>
<center><a href="showdetails.idx?mlsnumber=$MLSNUM"><img src="$photourl" border="0"></a></center><br>
<center><font size="2"><b><a class="uright" href="showdetails.idx?mlsnumber=$MLSNUM">View Listing Details</a></b></font></center><br>
<b>Remarks:</b> $Remarks
</font>
<br><br>
</td>
</tr>
~;
}


print <<"TheEND";
</table>
TheEND



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

