<?php
    session_start();
    error_reporting(E_ALL);
    ini_set('display_errors', 1);
    $base=$_SERVER["DOCUMENT_ROOT"];
    include_once $base."/function.php";
    include $base."/dbsetuprentright.php";
    include $base."/inc_defaults.php";
    $propertyprefix=0;
    if(isset($_GET['propertyprefix'])) $propertyprefix=$_GET['propertyprefix'];
    $_SESSION['lastpage']=$_SERVER["REQUEST_URI"];
    $thisurl="https://".$domain.$_SERVER["REQUEST_URI"];;
    $pics=array("picthumb","picmain","pic3","pic4","pic5","pic6","pic7","pic8","pic9","pic10","pic11","pic12","pic13","pic14","pic15");
    if(!isset($source)) $source="";
    if($source>"") $_SESSION['search_source']=$source;
    if(isset($token))
    {
        $sql="select * from regusers where emailtoken='$token'";
        $tmp=fn_query($linkhits,$sql);
        if(mysqli_num_rows($tmp)==1)
        {
            $regusers=mysqli_fetch_array($tmp);
            $id=$regusers['id'];
            $emailid=$regusers['emailid'];
            $key=md5($emailid);
            $rem=$key;
            $_SESSION['id']=$id;
            $_SESSION['emailid']=$emailid;
            $_SESSION['valid']=1;
            $_SESSION['key']=$key;
            $now=date("Y-m-d H:i:s");
            $sql="update regusers set logindate='$now',hash='$key',domain='$domain' where id='$id'";
            $tmp=mysqli_query($linkhits,$sql);
        }
    }
    $sql="select * from ".$sitefile[$domain]." where propertyid='$propertyid'";
    $res=fn_query($linkhits,$sql);
    $found=mysqli_num_rows($res);

    $ipad=1;
    $propavail=0;
    $propfound=0;
    if($found==1)
    {
        $property=mysqli_fetch_array($res);
        $agentid=$property['propertyprefix'];
        $propavail=$property['propavail'];
        $propfound=1;
    }
    if($propavail==0) $found=0;
    if($found==1)
    {
        $rightnow=date("Y-m-d H:i:s");
        if($source=="email")
        {
            $sqltmp="insert into ".$sitefilehits[$domain]." (agentid,propertyid,hits,detailclick,lastupdate,emailclick) values ('$agentid','$propertyid',1,1,'$rightnow',1) ON DUPLICATE KEY UPDATE detailclick=detailclick+1, lastupdate='$rightnow',emailclick=emailclick+1";
        } else {
            $sqltmp="insert into ".$sitefilehits[$domain]." (agentid,propertyid,hits,detailclick,lastupdate) values ('$agentid','$propertyid',1,1,'$rightnow') ON DUPLICATE KEY UPDATE detailclick=detailclick+1, lastupdate='$rightnow'";
        }
        $tmp=mysqli_query($linkhits,$sqltmp);
        $sql="select * from agents where agentid='$agentid'";
        $res=fn_query($linkhits,$sql);
        $agents=mysqli_fetch_array($res);
        $premium=1;
        $logo=$agents['logo'];
        $website=$agents['website'];
        if($website>"")
        {
            $website=strtolower($website);
            $website=str_replace("http://","",$website);
        }
        $islandlord=$agents['islandlord'];
        if($islandlord==1)
        {
            $agentname=$agents['agentname'];
//            if($property['llcontactname']>"") $agentname=$property['llcontactname'];
            $agenttelephone=$agents['agenttelephone'];
//            if($property['llcontacttelephone']>"") $agenttelephone=$property['llcontacttelephone'];
            $agentaddress="";
            $website="";
            $logo="";
        } else {
            $agentname=$agents['agentname'];
            $agenttelephone=$agents['agenttelephone'];
            $agentaddress=$agents['agentaddress'];
        }
        $updateremote=$agents['updateremote'];
        $imgsite=$domain;
        $imageurl="https://".$domain."/property/".$agentid;
        if($updateremote=="1") $imageurl="http://www.".$agents['agenturl']."/property";
        $property_county=$property['towncounty'];
        $county=$property_county;
        $property_town=$property['town'];
        $town=$property_town;
        if($town==$county) $town="";
        $property_address=$property['address'];
        $property_address=str_replace("'","&lsquo;",$property_address);
        $property_address=str_replace("\r\n",",",$property_address);
        $property_price=$property['price'];
        $property_freq=$property['freq'];
        if(strtolower($property_freq)=="monthly") $property_freq="pcm";
        $property_beds=$property['bedrooms'];
        $property_bathrooms=$property['bathrooms'];
        $property_proptype=$property['proptype'];
        $property_propref=$property['propref'];
        $property_dateavailable=$property['dateavailable'];
        $checkdate=strtotime($property_dateavailable);
        if($checkdate>0) $property_dateavailable=date("d-M-Y",$checkdate);
        $property_pricetype=$property['pricetype'];
        $property_details=$property['details'];
        $property_details=str_replace("£","&pound;",$property_details);
        $property_details=str_replace(chr(92)."&lsquo;","&lsquo;",$property_details);
        $property_details=str_replace(chr(92).'"',"&quot;",$property_details);
        $property_details=$property_details."<!-- ".$domain." yyz20170724yyz -->\n";
        $property_lat=$property['lat'];
        $property_lng=$property['lng'];
        $property_letagreed=$property['letagreed'];
        $property_deposit=$property['deposit'];
        $property_epc=$property['epc'];
        $property_epcsmall=$property['epcsmall'];
        if($property_letagreed==1) $property_dateavailable="<span class='letagreed'>Let Agreed</span>";
        if($property_beds==0)
        {
            $property_beds="Studio";
        } else {
            $property_beds=$property_beds." bed";
        }
        if(strtolower($property_proptype)=="unspecified") $property_proptype="Property";
        $property_proptype=str_replace("(unspecified)","",$property_proptype);
        $scotland=array("AB","DD","DG","EH","FK","G1","G2","G3","G4","G5","G6","G7","G8","G9","HS","IV","KA","KW","KY","ML","PA","PH","TD","ZE");
        $proppostcode=$property['postcode'];
        $feesapply=false;
        $pp=substr($proppostcode,0,2);
        $pp=strtoupper($pp);
        if(in_array($pp,$scotland)) $feesapply=false;
    } else {
        $agentid="0";
        $property_town="(property removed)";
        $town=$property_town;
        $county="(property removed)";
        if($town==$county) $town="";
        $property_county="(property removed)";
        $feesapply=false;
        $agentname="";
        $property_proptype="";
        $property_beds=0;
        $property_bathrooms=0;
        $proppostcode="";
        $property_address="";
        $property_price=0;
        $property_freq="";
        $logo="";
        $agenttelephone="";
        $agentaddress="";
        $property_lat=0;
        $property_lng=0;
        $property_deposit=0;
        $property_propref="Property removed";
        $property_dateavailable="n/a";
        $property_pricetype="";
        $property_epc="";
        $property_epcsmall="";
        $property_details="This property is no longer available. It has either been removed by the agent or archived.<br /><br /><br /><br /><br />";
        $premium=0;
        $islandlord=0;
        if($propfound==1)
        {
            $property_county=$property['towncounty'];
            $county=$property_county;
            $property_town=$property['town'];
            $town=$property_town;
            if($town==$county) $town="";
            $property_address=$property['address'];
            $property_address=str_replace("'","&lsquo;",$property_address);
            $property_address=str_replace("\r\n",",",$property_address);
            $property_price=$property['price'];
            $property_freq=$property['freq'];
            if(strtolower($property_freq)=="monthly") $property_freq="pcm";
            $property_beds=$property['bedrooms'];
            $property_bathrooms=$property['bathrooms'];
            $property_proptype=$property['proptype'];
            $property_propref=$property['propref'];
        }
    }
    $picdefs[0]="picthumb";
    $picdefs[1]="picmain";
    $picdefs[2]="pic3";
    $picdefs[3]="pic4";
    $picdefs[4]="pic5";
    $picdefs[5]="pic6";
    $picdefs[6]="pic7";
    $picdefs[7]="pic8";
    $picdefs[8]="pic9";
    $picdefs[9]="pic10";
    $picdefs[10]="pic11";
    $picdefs[11]="pic12";
    $picdefs[12]="pic13";
    $picdefs[13]="pic14";
    $picdefs[14]="pic15";
    for ($i=0; $i<=14; $i=$i+1)
    {
        $image[$i]="";
    }

    $shortlist=0;
    $shortlisticon="/images/savethis_icon.png";
    if(isset($_SESSION["id"]))
    {
        $sqltmp="select * from rentrightshortlist where propertyprefix='$agentid' and propertyid='$propertyid' and regusersid='".$_SESSION["id"]."'";
        $tmp=mysqli_query($linkhits,$sqltmp);
        $shortlist=mysqli_num_rows($tmp);
    }
    if($shortlist==1) $shortlisticon="/images/saved_icon.png";
?>
<!DOCTYPE html>
<!-- Microdata markup added by Google Structured Data Markup Helper. -->
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
    <head>
<?php include_once $base."/inc_propertydetail_title.php"; ?>
<?php include_once $base."/stylesheet/inc_stylesheet.php"; ?>
    <meta charset='windows-1252'>
    <meta http-equiv="Cache-control" content="public">
<?php
    if($found==0)
    {
        print "        <META NAME='Robots' CONTENT='noindex,follow'>\n";
        print "        <meta name='msnbot' content='noindex, follow'>\n";
        print "        <META NAME='googlebot' CONTENT='noindex,follow'>\n";
        print "        <META NAME='allow-search' CONTENT='no'>\n";
    } else {
        print "        <META NAME='Robots' CONTENT='index,follow'>\n";
        print "        <meta name='msnbot' content='index, follow'>\n";
        print "        <META NAME='googlebot' CONTENT='index,follow'>\n";
        print "        <META NAME='allow-search' CONTENT='yes'>\n";
    }
?>
    <META NAME="Rating" CONTENT="General">
    <META NAME="language" CONTENT="en">
    <META NAME="distribution" CONTENT="global">
    <meta property="og:type" content="product">
    <meta property="og:url" content="<?php print $thisurl; ?>">
    <meta property="og:site_name" content="<?php print $domain; ?>">
    <meta property="og:title" content="<?php print $pagetitle; ?>">
    <meta property="og:country-name" content="United Kingdom">
    <meta property="og:description" content="<?php print $pagedescription; ?>">
    <meta property="og:region" content="United Kingdom">
    <meta property="og:locality" content="United Kingdom">
    <meta property="og:postal-code" content="<?php print $proppostcode; ?>">
<?php
        $mainpic="/images/photo_not_available.png";
        if($found==1)
        {
           if($property["picthumb"]>"") $mainpic=$imageurl."/".$property["picthumb"];
        }
?>
    <meta property="og:image" content="<?php print $mainpic; ?>">
    <meta property="og:image:width" content="800">
    <meta property="og:image:height" content="600">
    <meta property="og:image:type" content="image/jpeg">
    <meta name="twitter:card" content="summary">
    <meta name="twitter:site" content="@rentright">
    <meta name="twitter:title" content="<?php print $pagetitle; ?>">
    <meta name="twitter:image" content="<?php print $mainpic; ?>">
    <meta name="twitter:url" content="<?php print $thisurl; ?>">
    <meta name="twitter:description" content="<?php print $pagedescription; ?>">
    <meta name="referrer" content="always">
<?php
    $breadcrumb="<a href='/'>Home</a> > Property to rent > ";
    $canonical="https://".$domain."/agentproperties/".$agentid."/";
    if($property_county=="postcode")
    {
        $breadcrumb=$breadcrumb.strtoupper($town);
    } else {
        $countylink=strtolower($property_county);
        $countylink=str_replace(" ","_",$countylink);
        $townlink=strtolower($property_town);
        $townlink=str_replace(" ","_",$townlink);
        $breadcrumb=$breadcrumb."<a href='/property-rent/".$countylink."/'>".ucwords($county)."</a>";
        $breadcrumb=$breadcrumb." > "."<a href='/property-rent/".$countylink."/".$townlink."/'>".ucwords($town)."</a>";
        $canonical="https://".$domain."/agentproperties/".$agentid."/";
    }
    $canonical=$thisurl;
    $breadcrumb=$breadcrumb." > ".$propertyid;
?>
    <link rel="canonical" href="<?php print $canonical; ?>">

<?php include_once $base."/inc_meta.php"; ?>
<style type="text/css">
<!--
@media only screen and (min-width: 100px) and (max-width:999px)
{
    .mobile_searcharea { display:none; }
    .hide_searcharea_options { display: inline-block; }
}
@media only screen and (min-width: 1000px)
{
    .hide_searcharea_options { display: none; }
    .hide_searcharea_options_hide { display: none; }
    .mobile_searcharea { display:inline-block; width:100%;}
}
-->
</style>
<?php include $base."/js.php"; ?>
<script type="text/javascript">

function showfees(propertyid)
{
    var url="/feesdisplayer.php?propertyid=" + propertyid;
    var opts="toolbar=no,location=no,directories=no,menubar=no,scrollbars=yes,resizable=yes,status=yes,width=520,height=620";
    window.open(url,"fees",opts).focus();
}
</script>
<script type="application/ld+json">
{
    "@context": "https://schema.org",
    "@type": "House",
    "name": "<?php print $pagetitle; ?>",
    "description": "<?php print $pagedescription; ?>",
    "image": "<?php print $mainpic; ?>",
    "url": "<?php print $thisurl; ?>",
    "address": {
        "@type": "PostalAddress",
        "streetAddress": "<?php print $property_address; ?>",
        "addressLocality": "<?php print $property_town; ?>",
        "addressRegion": "<?php print $property_county; ?>",
        "postalCode": "<?php print $proppostcode; ?>",
        "additionalProperty": [
            {
                "@type": "PropertyValue",
                "name": "Bedrooms",
                "value": "<?php print $property_beds; ?>"
            },
            {
                "@type": "PropertyValue",
                "name": "Bathrooms",
                "value": "<?php print $property_bathrooms; ?>"
            },
            {
                "@type": "PropertyValue",
                "name": "Property Type",
                "value": "<?php print $property_proptype; ?>"
            }
        ]

    }
}
</script>

    </head>
<body>
<?php include $base."/google.php"; ?>
<?php
    if(isset($rem))
    {
        if($domain!="rentright.co.uk") print "<img src='https://rentright.co.uk/setremotelogin.php?hash=$rem' style='display:none;'>\n";
        if($domain!="rentrightcommercial.co.uk") print "<img src='https://rentrightcommercial.co.uk/setremotelogin.php?hash=$rem' style='display:none;'>\n";
        if($domain!="rentrightstudents.co.uk") print "<img src='https://rentrightstudents.co.uk/setremotelogin.php?hash=$rem' style='display:none;'>\n";
    }
?>

        <div class="wrapper">
        	<div class="hold">

<?php include $base."/menubar.php"; ?>
<?php include $base."/inc_searchbar.php"; ?>
<span><h1 itemprop="name"><?php print $agentname." - Ref: ".$property_propref; ?></h1>

                <div class="breadcrumb"><?php print $breadcrumb; ?></div>
        	    <div class="propertyview">
                    <div class="left">
                        <div class="main"><a name='mainimg'></a>
<?php
            if($found==1)
            {
                if($property["picthumb"]>"") $mainpic=$imageurl."/".$property["picthumb"];
                print "<div class='image' id='imgmain' style=\"background: url('".$mainpic."') no-repeat top center; background-size: auto 100%;\" alt=\"$property_address\" title=\"$property_address\">\n";
                if($domain!="rentrightcommercial.co.uk")
                {
                    print "<div class='beds'>\n";
                    print "<img src='/images/beds-icon.png' height='18' width='29' alt='$property_beds Bedroom property to rent in ".$property_town.", ".$property_county."' title='$property_beds Bedroom property to rent in ".$property_town.", ".$property_county."'>".$property['bedrooms'];
                    print "</div>\n";
                    if($property['petsconsidered']==0)
                    {
                        print "<div class='beds'>\n";
                        print "<img src='/images/petsno.png' height='18' width='20' alt='No Pets' title='No Pets'>";
                        print "</div>\n";
                    }
                    if($property['petsconsidered']==1)
                    {
                        print "<div class='beds'>\n";
                        print "<img src='/images/pets.png' height='18' width='20' alt='Pets Considered' title='Pets Considered'>";
                        print "</div>\n";
                    }
                    if($property['petsconsidered']==2)
                    {
                        print "<div class='beds'>\n";
                        print "<img src='/images/petsmaybe.png' height='18' width='20' alt='Ask about pets' title='Ask about pets'>";
                        print "</div>\n";
                    }
                    if($property['landlord']==1)
                    {
                        if($property['parking']>0)
                        {
                            print "<div class='beds' >\n";
                            print "<img src='/images/parking.png' height='18' width='19' alt='Parking' title='Parking'>";
                            print "</div>\n";
                        }
                    }
                    if($property['garden']>0)
                    {
                        print "<div class='beds' >\n";
                        print "<img src='/images/garden.png' height='18' width='19' alt='Garden/Outside Space' title='Garden/Outside Space'>";
                        print "</div>\n";
                    }
                    if($property['student']==1)
                    {
                        print "<div class='students' alt='Suitable for Students' title='Suitable for Students' >\n";
                        print "<span>student</span>";
                        print "</div>\n";
                    }
                }
                if($property['commercial']==1)
                {
                    print "<div class='students' alt='Commercial Property' title='Commercial Property' >\n";
                    print "<span>commercial</span>";
                    print "</div>\n";
                }
                if($property['landlord']==1)
                {
                    if($property['onlineagent']==1)
                    {
                        print "<div class='students' alt='Letting Agent' title='Online Letting Agent' >\n";
                        print "<span>online agent</span>";
                        print "</div>\n";
                    } else {
                        print "<div class='students' alt='Letting Agent' title='Private Landlord' >\n";
                        print "<span>landlord</span>";
                        print "</div>\n";
                    }
                }
                if($property['student']==0 and $property['commercial']==0 and $property['landlord']==0)
                {
                    print "<div class='students' alt='Letting Agent' title='Letting Agent' >\n";
                    print "<span>agent</span>";
                    print "</div>\n";
                }
                if(isset($_SESSION['emailid']))
                {
                        print "<div class='savethisproperty' alt='My shortlist' title='My shortlist'>\n";
                        print "<img src='".$shortlisticon."' onclick=\"return shortlistthis('".$agentid."','".$propertyid."');\" id='shortlist_".$propertyid."'>\n";
                        print "</div>\n";
                } else {
                    print "<div class='savethisproperty' alt='Log in to add this to my shortlist' title='Log in to add this to my shortlist'>\n";
                    print "<img class='savethisproperty' src='".$shortlisticon."' alt='Log in to add this to my shortlist' title='Log in to add this to my shortlist' onclick=\"return logintosavethis('".$agentid."','".$propertyid."');\" id='shortlist_".$propertyid."'>\n";
                    print "</div>\n";
                }
                if($property_letagreed==1)
                {
                    print " <div class='letagreed'>\n";
                    print "     <img src='/images/letagreed.png' alt='Let Agreed'>";
                    print " </div>\n";
                }
            print "</div>\n";
            } else {
                print "<img src='/images/photo_not_available.png' title='' id='imgmain'>";
            }
?>
                        </div>
                        <div class='clear:both'></div>
                        <div style='width:100%'>
<?php
    print "<meta itemprop='image' content='".$mainpic."'>\n";
    $counter=0;
    if($found==1)
    {
        if($premium==1 or $islandlord==1)
        {
            foreach($picdefs as $ref)
            {
                if($property[$ref]>"")
                {
//                    print "<div class='gallery'>";
                    print "<a href='#mainimg'><div class='gallery' name='Photo $counter' style=\"cursor:pointer;background: url('".$imageurl."/".$property[$ref]."') no-repeat top center; background-size: auto 100%;\" alt=\"Photo $counter\" title=\"Photo $counter\" id='img".$counter."' onmouseover=\"swapBGImage('".$imageurl."/".$property[$ref]."')\"  onclick=\"swapBGImage('".$imageurl."/".$property[$ref]."')\"></div></a>\n";
//                    print "<a href='".$imageurl."/".$property[$ref]."'><img src='".$imageurl."/".$property[$ref]."' alt='Photo $counter' name='Photo $counter' border='0' style='border: 1px solid #99CC33;' id='img".$counter."' title='Photo $counter' onmouseover=\"MM_swapImage('imgmain','','".$imageurl."/".$property[$ref]."',1)\" border='0'></a>\n";
                    $counter=$counter+1;
                }
            }
        } else {
            print "<p>&nbsp;</p>\n";
            print "<p>Please contact the agent for more photos</p>\n";
            print "<p>&nbsp;</p>\n";
            print "<div class='showoptions' style='margin-left:10px;'>\n";
            if($islandlord==1)
            {
                print "    <a href='/contactlandlord/$agentid/$propertyid/'>Request details</a>\n";
            } else {
                print "    <a href='/contactagent/$agentid/$propertyid/'>Request details</a>\n";
            }
            print "</div>\n";
        }
        print "<div class='clear'></div>\n";
    }
?>

                        </div>
                    </div>
                    <div class="right">
                        <div class="propertydetails">
                            <div class="detleft" itemprop="description" >
                                <h2>
<?php
    if($domain=="rentrightcommercial.co.uk")
    {
        print $property_proptype." to rent.";
    } else {
        print $property_beds." ".$property_proptype." to rent.";
    }
?>                                </h2>
                                <div class='infoaddress'><?php print $property_address; ?></div>
                            </div>
                            <div class="detright" itemprop="offers" itemscope itemtype="http://schema.org/Offer">
                                <h3><?php print "&pound;<span itemprop='price'>".number_format($property_price,0,".","")."</span> ".$property_freq; ?></h3>
<?php
    if($feesapply==true)
    {
        print "<p><a href=\"javascript:void(showfees('$propertyid'));\">fees apply</a></p>\n";
    }
?>
                            </div>
                        </div>
<?php
    if($premium==1 or $islandlord==1)
    {
        print "                <div class='propertyinfo'>\n";
        print "                    <div class='infoleft'>\n";

        if($logo>"")
        {
            print "					     <a href='"."/agent/".str_replace(" ","_",$agentname)."/".$agentid."/"."'><img src='".$conn_type."rentright.co.uk/logos/$logo' alt='$agentname'></a>\n";
        }
        print "                    </div>\n";
        if($islandlord==1)
        {
            print "                    <div class='inforight'>\n";
            print "                        <div class='infoagentname'>$agentname</div>\n";
            print "                        <div class='infoaddress'>$agentaddress</div>\n";
            print "                    </div>\n";
            print "                    <div class='infowide'>\n";
            print "                      <div class='contactall'>\n";
            print "                         <a href='/contactlandlord/$agentid/$propertyid/' >Contact Landlord</a>\n";
            print "                      </div>\n";
            print "                      <div class='callagentajax' onclick=\"updatetelephoneclicksnew('$agentid','tel://$agenttelephone')\">\n";
            print "                         ".$agenttelephone."\n";
            print "                      </div>\n";
        } else {
            print "                    <div class='inforight'>\n";
            print "                        <div class='infoagentname'><a href='"."/agent/".str_replace(" ","_",$agentname)."/".$agentid."/"."'>$agentname</a></div>\n";
            print "                        <div class='infoaddress'>$agentaddress</div>\n";
            print "                    </div>\n";
            print "                    <div class='infowide'>\n";
            print "                      <div class='contactall'>\n";
            print "                         <a href='/contactagent/$agentid/$propertyid/' >Contact Agent</a>\n";
            print "                      </div>\n";
            print "                      <div class='callagentajax' onclick=\"updatetelephoneclicksnew('$agentid','tel://$agenttelephone')\">\n";
            print "                         ".$agenttelephone."\n";
            print "                      </div>\n";
        }
        if($website>"")
        {
//            print "                       <div class='weblink'>\n";
//            print "                         <a href='/weblink/".$agentid."/' target='web_".$agentid."' >Agent's website</a>\n";
//            print "                      </div>\n";
        }
        print "                    </div>\n";
        print "                </div>\n";
    }
?>
                        <div id="map" class="map"></div>
<?php
        if($property_lat==0 or $property_lng==0)
        {
        } else {
            $stations_list="            <h4>Nearest stations</h4>\n";
            $howmany=3;
            if(stripos($property_county,"london")>1) $howmany=5;
            $sql = "select *,(((acos(sin(($property_lat*pi()/180)) * sin((lat*pi()/180)) + cos(($property_lat*pi()/180)) * cos((lat*pi()/180)) * cos((($property_lng - lng)*pi()/180))))*180/pi())*60*1.1515) as distance FROM stations order by distance limit 0,$howmany";
$property_lat = (float)$property_lat;
$property_lng = (float)$property_lng;
$showhowmany  = max(1, (int)$howmany);

$sql = "
        SELECT
                *,
                (
                        ACOS(
                                LEAST(
                                        1,
                                        GREATEST(
                                                -1,
                                                SIN(RADIANS($property_lat)) * SIN(RADIANS(lat))
                                                +
                                                COS(RADIANS($property_lat)) * COS(RADIANS(lat))
                                                * COS(RADIANS($property_lng - lng))
                                        )
                                )
                        ) * 3958.7613
                ) AS distance
        FROM stations
        WHERE lat <> 0
            AND lng <> 0
        ORDER BY distance
        LIMIT $showhowmany
";

            $result=fn_query($linkhits,$sql);
            $stations_map="";
            while($stations=mysqli_fetch_array($result))
            {
                $distance=$stations['distance'];
                $distance=round($distance,1);
                $name=$stations['name'];
                $name=str_replace("'","&lsquo;",$name);
                $type=$stations['type'];
                $stations_lat=$stations['lat'];
                $stations_lng=$stations['lng'];
                $icon="icon_".$type.".png";
                $disp="<div><img src='/images/".$icon."' align='middle'>&nbsp;&nbsp;$name&nbsp;&nbsp;$distance miles</div>\n";
                $stations_list=$stations_list.$disp;
                $stations_map=$stations_map."var marker = new google.maps.Marker({ position: {lat:".$stations_lat.", lng:".$stations_lng."},icon: My".$type.",map: map,title: '".$name."' });\n";
            }

?>
        <script type="text/javascript">
            function initMap()
            {
                var MyIcon = { url:'http://maps.google.com/mapfiles/ms/micons/red-pushpin.png' };
                var Mytube = { url:'https://<?php print $domain; ?>/images/tube_pin_map.png' };
                var Myrail = { url:'https://<?php print $domain; ?>/images/rail_pin_map.png' };
                var myLatLng = {lat: <?php print $property_lat; ?>, lng: <?php print $property_lng; ?>};
                var map = new google.maps.Map(document.getElementById('map'), {
                    zoom: 13,
                    zoomControl: true,
                    mapTypeControl: true,
                    scaleControl: true,
                    rotateControl: true,
                    streetViewControl: true,
                    fullscreenControl: true,
                    center: myLatLng
                });
                var marker = new google.maps.Marker({
                    position: myLatLng,
                    icon: <?php print "{ url:'https://$domain/images/maps/number_".$property['bedrooms'].".png' }"; ?>,
                    map: map,
                    title: "<?php print $property_address; ?>"
                });
                <?php print $stations_map; ?>
            }
        </script>
    <script async defer src="https://maps.googleapis.com/maps/api/js?key=<?php print $apikey[$domain]; ?>&callback=initMap" type="text/javascript"></script>
                        <div class="stations">
<?php
            print $stations_list;
        }
?>
                        </div>
                    </div>
                    <div class='clear'></div>

                    <div class="detailstext">
<section>
                        <h2>Property Information</h2>
                        <p>Ref ID: <?php print $property_propref; ?></p>
                        <p>Date available: <?php print $property_dateavailable; ?></p>
<?php
                            if($domain=="rentrightcommercial.co.uk")
                            {
                            } else {
                                print "<p>Furnishing: $property_pricetype</p>\n";
                            }
?>
                        <p>Property type: <?php print $property_proptype; ?></p>
<?php
    if($property_deposit>0) print "<p>Deposit: &pound;".number_format($property_deposit,2)."</p>\n";
    if($property_epc>"") print "<p>EPC: <a href='".$imageurl."/".$property_epc."' target='_blank'>click here</a></p>\n";
?>
                        <p>&nbsp;</p>
                        <h2>Details</h2>
                        <article><p><?php print $property_details; ?></p></article>
<?php
    if($found==1)
    {
        print "                <div class='showoptions'>\n";
        if($islandlord==1)
        {
            print "                    <a href='/contactlandlord/$agentid/$propertyid/'>Request details</a>\n";
        } else {
            print "                    <a href='/contactagent/$agentid/$propertyid/'>Request details</a>\n";
        }
        print "                </div>\n";
    }
?>
                <div class="clear"></div>
                <div class='similarproperties'>
<?php
                $sql="select *, (((acos(sin(($property_lat*pi()/180)) * sin((lat*pi()/180)) + cos(($property_lat*pi()/180)) * cos((lat*pi()/180)) * cos((($property_lng - lng)*pi()/180))))*180/pi())*60*1.1515) as distance from $propertyfile where propavail='1' and (((acos(sin(($property_lat*pi()/180)) * sin((lat*pi()/180)) + cos(($property_lat*pi()/180)) * cos((lat*pi()/180)) * cos((($property_lng - lng)*pi()/180))))*180/pi())*60*1.1515) <= 10 and rentorsale='R'  and bedrooms = '$property_beds' and propertyid != '$propertyid' and picthumb >'' and letagreed='0' order by distance asc limit 4";
                $ressimilar=fn_query($linkhits,$sql);
                $found_similar=mysqli_num_rows($ressimilar);
                if($found_similar>0)
                {
                    print "<div class='similarproperties'></div>\n";
                    print "<div class='clear'></div>\n";
                    print "<div class='spacermid'></div>\n";
                    print "<h2>$found_similar similar properties nearby</h2>";
                    while($similar=mysqli_fetch_array($ressimilar))
                    {
                        $agentid=$similar['propertyprefix'];
                        $similar_propertyid=$similar['propertyid'];
                        $sql="select * from agents where agentid='$agentid'";
                        $res=fn_query($linkhits,$sql);
                        while($agents=mysqli_fetch_array($res))
                        {
                            $thisagentname=$agents['agentname'];
                            $logo=$agents['logo'];
                            $updateremote=$agents['updateremote'];
                            $imageurl="https://".$domain."/property/".$agentid;
                            if($updateremote=="1") $imageurl="http://www.".$agents['agenturl']."/property";
                            $sql="select * from $propertyfile where propertyid='$similar_propertyid'";
                            $tmp=fn_query($linkhits,$sql);
                            $property=mysqli_fetch_array($tmp);
                            $property_address=$property['address'];
                            $property_bedrooms=$property['bedrooms'];
                            $property_proptype=$property['proptype'];
                            $property_town=$property['town'];
                            $property_address=strip_tags($property_address);
                            $url_address=$property_address;
                            $url_address=str_replace(" ","-",$url_address);
                            $url_address=str_replace(",","-",$url_address);
                            $url_address=str_replace("--","-",$url_address);
                            $url_address=str_replace("%","-",$url_address);
                            $url_address=str_replace("*","-",$url_address);
                            $url_town=$property['townname'];
                            $url_town=str_replace(" ","-",$url_town);
                            $url_town=str_replace("'","-",$url_town);
                            $url_postcode=$property['postcode'];
                            $url_postcode=str_replace(" ","-",$url_postcode);
                            $propertyurl=strtolower("/property/$similar_propertyid/$url_address/$url_town/$url_postcode/");
                            print "			<div class='recents'>\n";
                            if($domain=="rentrightcommercial.co.uk")
                            {
                                $titletext=$property_proptype." for rent in ".$property_town.". From ".$thisagentname;
                            } else {
                                $titletext=$property_bedrooms." bed ".$property_proptype." for rent in ".$property_town.". From ".$thisagentname;
                            }
                                print "				<a href='$propertyurl'><img src='".$imageurl."/".$property['picthumb']."' alt=\"$titletext\" title=\"$titletext\"></a>\n";
                    //        print "				<img src='/images/property2.jpg' alt='Property image' >\n";
                            print "			<div class='txt'><h4>&pound;".number_format($property['price'])." ".$property['freq']."</h4>\n";
                            if($domain=="rentrightcommercial.co.uk")
                            {
                                print $property['proptype']."<br>\n";
                            } else {
                                print $property['bedrooms']." Bed ".$property['proptype']."<br>\n";
                            }
                            print $property['town']." (".number_format($similar['distance'],2)." miles)<br>\n";
                            print "ref:".$property['propref']."<br></div>\n";
                            print "			</div>\n";
                        }
                    }
                }
?>
                </div>
                <div class='clear'></div>
                <div class="spacermid"></div>
                <div class="propertydisclaimer">
<p><b>Disclaimer</b></p>
<p>Property reference <b><?php print $property_propref; ?></b>. The information displayed about this property comprises a property advertisement. <?php print $domain; ?> makes no warranty as to the accuracy or completeness of the advertisement or any linked or associated information, and Rentright has no control over the content. This property advertisement does not constitute property particulars. The information is provided and maintained by <b><?php print $agentname; ?></b>.</p>
                </div>
                    </section>
                    </div>
                </div>
<meta itemprop="url" content="http://<?php print $domain.$_SERVER["REQUEST_URI"]; ?>">
</span>
        <h3><a href="#top">go to top</a></h3>

        	</div>
        </div>

        <div class="wrapper">
<?php include $base."/footer.php"; ?>
        </div>
    </body>
</html>