#!/usr/bin/perl

print "Content-type: text/html\n\n";
require "config.idx";

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,County,ListingOffice1Name,AgentName,AgentPhone,AgentID,MLSNUM,Bedrooms,YearBuilt,TotalSqFt,FullBaths,HalfBaths,Acres,AgentID,Remarks from listings_res3 WHERE ListingOffice1ID = '48'");
$uasth->execute;

$google_build_xml .=qq~<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:g="http://base.google.com/ns/1.0">
<channel>
~;

while (($Price,$AddressNumber,$AddressDirection,$AddressStreet,$City,$Zip,$County,$ListingOffice1Name,$AgentName,$AgentPhone,$AgentID,$MLSNUM,$Bedrooms,$YearBuilt,$TotalSqFt,$FullBaths,$HalfBaths,$Acres,$AgentID,$Remarks) = $uasth->fetchrow_array()) {

if ($HalfBaths > 0) { $HalfBaths = ($HalfBaths/2); }
$bathrooms = ($FullBaths+$HalfBaths);

$Remarks =~ s/\'//gi;
$Remarks =~ s/\’//gi;
$Remarks =~ s/\"//gi;
$Remarks =~ s/\&//gi;
$Remarks =~ s/\<//gi;
$Remarks =~ s/\>//gi;
$Remarks =~ s/\-//gi;
$Remarks =~ s/\–//gi;

$google_build_xml .=qq~<item>
<title>$AddressNumber $AddressDirection $AddressStreet, $City</title>
<link>http://$MLSNUM.MuncieMLS.com</link>
<description><![CDATA[$Remarks]]></description>
<g:listing_type>for sale</g:listing_type>
<g:location>$AddressNumber $AddressDirection $AddressStreet, $City, IN $Zip</g:location>
<g:price>$Price</g:price>
<g:bathrooms>$bathrooms</g:bathrooms>
<g:bedrooms>$Bedrooms</g:bedrooms>
<g:broker>Eagle Real Estate Inc.</g:broker>
<g:id>$MLSNUM</g:id>
<g:image_link>http://media2.idxnow.com/meiar/thumbnail/meiarmls$MLSNUM.jpg</g:image_link>
<g:listing_status>active</g:listing_status>
<g:mls_listing_id>$MLSNUM</g:mls_listing_id>
<g:mls_name>Mid Eastern Indiana Association</g:mls_name>
<g:property_type>Residential</g:property_type>
<g:provider_class>broker</g:provider_class>
<g:year>$YearBuilt</g:year>
<g:area>$TotalSqFt</g:area>
<g:agent>$AgentName</g:agent>
</item>~;
}
$google_build_xml .=qq~
</channel>
</rss>~;


$data="rss_google.xml";
open(DAT,">>$data") || die("Cannot Open File");
print DAT "$google_build_xml\n"; 
close(DAT);


print qq~
$data File Updated
~;