File: /home/api/public_html/charlottesville/get-agent-listings.php
<?php
ini_set( "memory_limit", "128M" );
require( "php/config.php" );
$oRes = new Result( "SearchResults" );
$oSearch = new Search();
$oSearch->setActive( true );
foreach ( $_GET as $k => $v )
{
switch( strtolower( $k ) )
{
case "agentid":
if ( preg_match( "@^[[:alnum:],]+$@", $v ) === 1 )
$aAgentIDs = explode( ",", $v );
break;
case "sold":
if ( $v === "1" )
{
$oRes->aSearchReturnFields[] = "ClosedDate";
$oRes->aSearchReturnFields[] = "SalePrice";
}
$oSearch->setVal( 'propertystatus', 'off-market' );
$oSearch->setVal( "sortby", "SalePrice" );
break;
case "active":
if ( $v === "1" )
$bActive = true;
break;
case "limit":
if ( is_numeric( $v ) )
$oRes->setLimit( $v );
break;
}
}
if ( is_array( $aAgentIDs ) && ( count( $aAgentIDs ) > 0 ) )
$oSearch->setVal( "ListingAgentID", $aAgentIDs );
$aResult = $oSearch->doQuery();
if ( isset( $aResult["Data"] ) )
{
$oRes->addData( $aResult["Data"], "Data" );
$oRes->addData( $aResult['TotalRecords'], "TotalRecords" );
}
print $oRes->getJSON();