<?php
    error_reporting(E_ALL);
    ini_set('display_errors', 1);
    session_start();
    $base=$_SERVER["DOCUMENT_ROOT"];
    include_once $base."/function.php";
    include $base."/dbsetup.php";
    include $base."/inc_defaults.php";
    $lastpage="/";
    if(isset($_SESSION['lastpage'])) $lastpage=$_SESSION['lastpage'];
    $action="";
    $agentid=0;
    $propertyid=0;
    if(isset($_GET['agentid'])) $agentid=$_GET['agentid'];
    if(isset($_GET['propertyid'])) $propertyid=$_GET['propertyid'];
    $agentname="";
    $canonical="https://".$domain.$_SERVER["REQUEST_URI"];;
    if(strlen($agentid)==9)
    {
        $sql="select agentname,agenttelephone from agents where agentid='$agentid'";
        $res=mysqli_query($linklocal,$sql);
        if(mysqli_num_rows($res)==1)
        {
            $agents=mysqli_fetch_array($res);
            $agentname=$agents['agentname'];
            $agenttelephone=$agents['agenttelephone'];
            $action="/contactagent_send.php";
//            $canonical="https://".$domain."/contactagent/".$agentid."/";
        } else {
            $agentname="Not Available";
            $agenttelephone="";
            $action="";
        }
    } else{
        $agentname="Agent no longer listed";
        $agenttelephone="";
    }
    if(!isset($search_town)) $search_town="";
    if(!isset($search_county)) $search_county="";
    if($propertyid>0 and is_numeric($propertyid))
    {
        $sql="select * from property where propertyid='$propertyid'";
        $res=mysqli_query($linklocal,$sql);
        if(mysqli_num_rows($res)==1)
        {
            $property=mysqli_fetch_array($res);
            $address=$property['address'];
            $postcode=$property['postcode'];
            $bedrooms=$property['bedrooms'];
            $proptype=$property['proptype'];
            $price=$property['price'];
            $letagreed=$property['letagreed'];
            $price=number_format($price,0);
            $freq=$property['freq'];
            $propref=$property['propref'];
            $action="/contactagent_send.php";
        } else {
            $address="";
            $postcode="";
            $bedrooms="";
            $proptype="";
            $price="0";
            $letagreed=0;
            $price=number_format($price,0);
            $freq="";
            $propref="";
        }
    } else {
        $address="";
        $postcode="";
        $bedrooms="";
        $proptype="";
        $price="0";
        $letagreed=0;
        $price=number_format($price,0);
        $freq="";
        $propref="";
    }
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
    <head>
        <meta name=description content="Contact <?php print $agentname; ?> from <?php print $domain; ?>" />
        <meta name=keywords content="Contact <?php print $agentname; ?>" />
        <title>Contact <?php print $agentname; ?> from <?php print $domain; ?></title>
        <meta charset=utf-8>
        <meta http-equiv="Cache-control" content="public">
        <meta name="msvalidate.01" content="F8D5D758D49A1700EB3D8AE5FE6DC180">
<?php
            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='yes'>\n";
?>
        <META NAME="Rating" CONTENT="General">
        <META NAME="language" CONTENT="en">
        <META NAME="distribution" CONTENT="global">
        <link rel="canonical" href="<?php print $canonical; ?>">
<?php include_once $base."/stylesheet/inc_stylesheet.php"; ?>
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=yes" />
        <meta name="apple-mobile-web-app-capable" content="yes" />
        <meta name="apple-mobile-web-app-status-bar-style" content="black" />
        <meta name="apple-mobile-web-app-title" content="rentright" />
        <link rel="apple-touch-icon" sizes="57x57" href="/apple-icon-57x57.png">
        <link rel="apple-touch-icon" sizes="60x60" href="/apple-icon-60x60.png">
        <link rel="apple-touch-icon" sizes="72x72" href="/apple-icon-72x72.png">
        <link rel="apple-touch-icon" sizes="76x76" href="/apple-icon-76x76.png">
        <link rel="apple-touch-icon" sizes="114x114" href="/apple-icon-114x114.png">
        <link rel="apple-touch-icon" sizes="120x120" href="/apple-icon-120x120.png">
        <link rel="apple-touch-icon" sizes="144x144" href="/apple-icon-144x144.png">
        <link rel="apple-touch-icon" sizes="152x152" href="/apple-icon-152x152.png">
        <link rel="apple-touch-icon" sizes="180x180" href="/apple-icon-180x180.png">
        <link rel="icon" type="image/png" sizes="192x192"  href="/android-icon-192x192.png">
        <link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
        <link rel="icon" type="image/png" sizes="96x96" href="/favicon-96x96.png">
        <link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
        <link rel="manifest" href="/manifest.json">
        <meta name="msapplication-TileColor" content="#ffffff">
        <meta name="msapplication-TileImage" content="/ms-icon-144x144.png">
        <meta name="theme-color" content="#ffffff">
<?php include $base."/js.php"; ?>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
function validateform()
{
        var frm=document.forms.mainform;
        if (frm.contact_first_name.value==null || frm.contact_first_name.value=="")
        {
                alert("First name must be filled out");
                frm.contact_first_name.focus();
                return false;
        }
        if (frm.contact_last_name.value==null || frm.contact_last_name.value=="")
        {
                alert("Last name must be filled out");
                frm.contact_last_name.focus();
                return false;
        }
        if (frm.contact_email.value==null || frm.contact_email.value=="")
        {
                alert("Email address must be filled out");
                frm.contact_email.focus();
                return false;
        }
        var atpos=frm.contact_email.value.indexOf("@");
        var dotpos=frm.contact_email.value.lastIndexOf(".");
        if (atpos<1 || dotpos<atpos+2 || dotpos+2>=frm.contact_email.length)
        {
                alert("Not a valid e-mail address");
                frm.contact_email.focus();
                return false;
        }
        if (frm.contact_captcha.value==null || frm.contact_captcha.value=="" || frm.contact_captcha.value != 9)
        {
                alert("Please complete the sum to complete the form. (Proves you are human!)");
                frm.contact_captcha.focus();
                return false;
        }
    }
</script>
</head>
<body>
<?php include $base."/google.php"; ?>
        <div class="wrapper">
        	<div class="hold">
<?php include $base."/menubar.php"; ?>
                <a name='top'></a>
                <div class="contactform">
                    <form name="mainform" action="<?php print $action; ?>" method="post" onsubmit="return validateform()">
<?php
        print "<input type='hidden' name='lastpage' value='$lastpage'>\n";
        print "<input type='hidden' name='agentid' value='$agentid'>\n";
        print "<input type='hidden' name='agentname' value='$agentname'>\n";
        print "<input type='hidden' name='propertyid' value='$propertyid'>\n";
        print "<input type='hidden' name='propref' value='$propref'>\n";
        print "<input type='hidden' name='postcode' value='$postcode'>\n";
        print "<input type='hidden' name='bedrooms' value='$bedrooms'>\n";
        print "<input type='hidden' name='address' value='$address'>\n";
        print "<input type='hidden' name='price' value='$price ($freq)'>\n";
?>
                    <div class="detailwrapper">
                        <div class="detail">
                            <h1>Contact <?php print $agentname; ?></h1>
                        </div>
<?php
    if($propertyid>0)
    {
?>
                        <div class="detail">
                            <div class="sumlabel">Agent:&nbsp;</div>
                            <div class="suminfo"><?php print $agentname; ?></div>
                        </div>
                        <div class="detail">
                            <div class="sumlabel">Ref:&nbsp;</div>
                            <div class="suminfo"><?php print $propref; ?></div>
                        </div>
<?php
    if($letagreed==1)
    {
print "                        <div class='detail'>\n";
print "                            <div class='sumlabel'>Let Status:</div>\n";
print "                            <div class='suminfo' style='color:#FF0A0A'>Let Agreed</div>\n";
print "                        </div>\n";
    }
?>
                        <div class="detail">
                            <div class="sumlabel">Address:&nbsp;</div>
                            <div class="suminfo"><?php print $address.", ".$postcode; ?></div>
                        </div>
                        <div class="detail">
                            <div class="sumlabel">Price:&nbsp;</div>
                            <div class="suminfo"><?php print "&pound;$price ($freq)"; ?></div>
                        </div>
<?php
    }
?>
                    </div>
                        <div class="detail">
                            <div style='width:90%;white-space:nowrap;overflow:hidden;padding-bottom:10px;'><?php print $agentname; ?></div>
                            <div class="sumlabel">I would like:&nbsp;</div>
                            <div class="suminfo">
<input name="contact_more_info" type="checkbox" id="contact_more_info" checked="checked" /><label for='contact_more_info'>More Details</label>
                            </div>
                        </div>
                        <div class="detail">
                            <div class="sumlabel">&nbsp;</div>
                            <div class="suminfo">
<input name="contact_viewing" type="checkbox" id="contact_viewing" /><label for='contact_viewing'>To view a property</label>
                            </div>
                        </div>
                        <div class="detailfooter">
                <p>Please complete the form below and click 'send email' to contact the agent.</p>
                        </div>
                        <div class="name">
                            <div class="label">Name:</div>
                            <div class="info">
                                <input type="text" placeholder="Mr." name="contact_title" id="contact_title">
                                <input type="text" placeholder="First" name="contact_first_name" id="contact_first_name" required>
                                <input type="text" placeholder="Surname" name="contact_last_name" id="contact_last_name" required>
                            </div>
                        </div>
                        <div class="email">
                            <div class="label">Email:</div>
                            <div class="info">
                                <input type="email" placeholder="email@address.com" name="contact_email" id="contact_email" required>
                            </div>
                        </div>
                        <div class="address">
                            <div class="label">Address:</div>
                            <div class="info">
                                <textarea placeholder="House Number, Street name, County" name="contact_address" id="contact_address"></textarea>
                            </div>
                        </div>
                        <div class="postcode">
                            <div class="label">Postcode:</div>
                            <div class="info">
                                <input type="text" placeholder="postcode" name="contact_postcode" id="contact_postcode">
                            </div>
                        </div>
                        <div class="telephone">
                            <div class="label">Telephone:</div>
                            <div class="info">
                                <input type="tel" placeholder="Tel no." name="contact_phone" id="contact_phone">
                            </div>
                        </div>
                        <div class="comments">
                            <div class="label">Comments:</div>
                            <div class="info">
                                <textarea placeholder="Please enter any comments" name="contact_comments" id="contact_comments" required></textarea>
                            </div>
                        </div>
                        <div class="sum">
                            <div class="label">What's 3+6:</div>
                            <div class="info">
                                <input type="text" name="contact_captcha" id="contact_captcha" value="" placeholder="3+6">
                            </div>
                        </div>
                        <div class="detailfooter">
                            <div class="label"></div>
                            <div class="info">
<?php
    if($agentid>0)
    {
        print "<input name='contact_continueButton' type='submit' id='contact_continueButton' value='send email' class='sub'>\n";
    }
?>

                            </div>
                        </div>
                        <div class="detaildisclaimer">
                <p>Please note that <?php print $domain; ?> will send the above details to <?php print $agentname; ?>. By submitting this form, you confirm that you agree to our website <a href="javascript: void(0);" onclick="window.open('/terms.php', 'Terms', 'scrollbars=yes,width=810,height=700');">Terms and Conditions</a>.</p>
                <p>&nbsp;</p>
                <p>&nbsp;</p>
                        </div>
                    <div class="button"><a href='<?php print $lastpage; ?>'>Back to list</a></div>
                    <div class="clear"></div>
                    <p>&nbsp;</p>
                </form>
                <h3><a href="#top">go to top</a></h3>
            </div>

        	</div>
        </div>
        <div class="wrapper">
<?php include $base."/footer.php"; ?>
        </div>
<script>
    document.getElementById("contact_title").focus();
</script>
</body>
</html>