<?php require_once("header1.php");

// Stop making changes below this line
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

require 'phpmailer/PHPMailer-master/src/Exception.php';
require 'phpmailer/PHPMailer-master/src/PHPMailer.php';
require 'phpmailer/PHPMailer-master/src/SMTP.php';
?>

<?php
if(isset($_POST['send']))
{	
	if($_POST['act_answer'] == $_POST['answer'])
	{
	    //SEND EMAIL TO ADMINISTRATOR
        $name = 'Properti Dost';
        $email = $contact_email;

		$email_account = "info@prismonline.in";
        $email_password = "~I5er1FU&bR0";

		// Recipient
		$mail = new PHPMailer;
		$mail->isSMTP();
		$mail->SMTPDebug = 0;

		$subject="A New Enquiry Posted";
		$message= '<table border="0" width="100%" cellspacing="2" cellpadding="2" align="center">
				<tr>
					<td colspan="2">A new enquiry has been posted. Details are below,</td>
				</tr>
				<tr>
					<td colspan="2">&nbsp;</td>
				</tr>
				<tr>
					<td width="30%">Name : </td>
					<td width="70%">'.stripslashes($_POST['contact_name']).'</td>
				</tr>
				<tr>
					<td>Phone No : </td>
					<td>'.stripslashes($_POST['contact_phone']).'</td>
				</tr>
				<tr>
					<td>Email Address : </td>
					<td>'.stripslashes($_POST['contact_email']).'</td>
				</tr>
				<tr>
					<td valign="top">Message : </td>
					<td>'.nl2br(stripslashes($_POST['contact_message'])).'</td>
				</tr>
				</table>';
				
		$mail->Host = 'mail.prismonline.in';
		$mail->Port = 587;
		$mail->SMTPAuth = true;
		$mail->SMTPSecure = "tls";
		$mail->Username = $email_account;
		$mail->Password = $email_password;

		$mail->setFrom('info@prismonline.in', "Properti Dost");
		$mail->addReplyTo('info@prismonline.in', "");
		$mail->addAddress($email);
		$mail->Subject = $subject;
		$TemplateMessage = $message;
		$mail->MsgHTML($TemplateMessage);
		$mail->send();
       // echo 'Message has been sent successfully';
       
        unset($_SESSION['CONTACT_NAME']);
        unset($_SESSION['CONTACT_EMAIL']);
        unset($_SESSION['CONTACT_PHONE']);
        unset($_SESSION['CONTACT_MESSAGE']);
       
		$_SESSION['msg_succ'] = 'Thank you. Your message has been successfully sent to administrator.';
		header("location: contact-us.php");
		exit;
	} 
    else
    {
        $_SESSION['CONTACT_NAME'] = $_POST['contact_name'];
        $_SESSION['CONTACT_EMAIL'] = $_POST['contact_email'];
        $_SESSION['CONTACT_PHONE'] = $_POST['contact_phone'];
        $_SESSION['CONTACT_MESSAGE'] = $_POST['contact_message'];
        
        $_SESSION['msg_fail'] = 'Your answer is incorrect. Please try again!';
    	header("location: contact-us.php");
    	exit;
    }
}

$a= rand(0,99);
$b = rand(0,99);
$c = $a+$b;
?>

			<script language="javascript" type="text/javascript">
			function echeck(str) 
			{
					var at="@"
					var dot="."
					var lat=str.indexOf(at)
					var lstr=str.length
					var ldot=str.indexOf(dot)
					if (str.indexOf(at)==-1){
						alert("Invalid email address");
					   return false;
					}
			
			
					if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
						alert("Invalid email address");
					   return false;
					}
			
			
					if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
						alert("Invalid email address");
						return false;
					}
			
			
					 if (str.indexOf(at,(lat+1))!=-1){
						alert("Invalid email address");
						return false;
					 }
			
			
					 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
						alert("Invalid email address");
						return false;
					 }
			
			
					 if (str.indexOf(dot,(lat+2))==-1){
						alert("Invalid email address");
						return false;
					 }
					
			
					 if (str.indexOf(" ")!=-1){
						alert("Invalid email address");
						return false;
					 }
					 return true;					
			}
			
			function form_validation()
			{
				if(document.getElementById('contact_name').value == "")
				{
					alert("Please enter name");
					document.getElementById('contact_name').focus();
					return false;
				}
				
				if(document.getElementById('contact_phone').value == "")
				{
					alert("Please enter phone no.");
					document.getElementById('contact_phone').focus();
					return false;
				}

				if(document.getElementById('contact_email').value == "")
				{
					alert("Please enter email address");
					document.getElementById('contact_email').focus();
					return false;
				}
			   
				if(echeck(document.getElementById('contact_email').value)==false){
					document.getElementById('contact_email').focus();
					return false;
				}
				
				if(document.getElementById('contact_message').value == "")
				{
					alert("Please enter message");
					document.getElementById('contact_message').focus();
					return false;
				}
				
				if(document.getElementById('answer').value == "")
				{
					alert("Please enter answer");
					document.getElementById('answer').focus();
					return false;
				}
			}
			</script>

			<!-- page template area start -->
			<section id="about">
				<div class="container mt-10 pb-10 pt-0">
					<div class="row">
						<div class="col-md-7">
							<h1 class="title mt-5 mb-10" style="text-align:left;">Send us a message</h1> 
							<h3 style="margin:0 0 15px 0; text-align:left; color:#777; font-size:17px;">For Any queries fill up the form below</h3>
						    <?php if(isset($_SESSION['msg_succ'])) { ?>
							<p class="text-left"><img src="images/tick.png" alt="" /> <?php echo $_SESSION['msg_succ'];?></p>
							<?php 
							unset($_SESSION['msg_succ']);
							} 
							?>
							<?php if(isset($_SESSION['msg_fail'])) { ?>
							<p class="text-left"><img src="images/cross.png" alt="" /> <?php echo $_SESSION['msg_fail'];?></p>
							<?php 
							unset($_SESSION['msg_fail']);
							} 
							?>
							<form id="contact_form" name="contact_form" class="" action="" method="post" onSubmit="return form_validation();">
							<div class="row">
								<div class="col-sm-12">
									<div class="form-group">
										<input name="contact_name" id="contact_name" class="form-control" type="text" placeholder="Enter Name *" value="<?php echo $_SESSION['CONTACT_NAME'];?>">
									</div>
								</div>
								<div class="col-sm-12">
									<div class="form-group">
										<input name="contact_phone" id="contact_phone" class="form-control" maxlength="10" type="text" placeholder="Enter Phone No. *" value="<?php echo $_SESSION['CONTACT_PHONE'];?>">
									</div>
								</div>
								<div class="col-sm-12">
									<div class="form-group">
										<input name="contact_email" id="contact_email" class="form-control" type="text" placeholder="Enter Email Address *" value="<?php echo $_SESSION['CONTACT_EMAIL'];?>">
									</div>
								</div>
							</div>
							<div class="form-group">
								<textarea name="contact_message" id="contact_message" class="form-control required" rows="5" placeholder="Enter Message *"><?php echo stripslashes($_SESSION['CONTACT_MESSAGE']);?></textarea>
							</div>
							<div class="form-group">
							    <p><?php echo $a;?>+<?php echo $b;?> = ?</p>
								<div class="form-group">
									<input name="answer" id="answer" class="form-control" type="text" placeholder="Enter Answer *">
								</div>
							</div>
							<div class="form-group">
								<input type="hidden" name="send" id="send" value="1" />
								<input type="hidden" name="act_answer" id="act_answer" value="<?php echo $c;?>" />
								<button type="submit" class="btn btn-flat btn-theme-colored border-left-theme-color-2-4px">Send Your Message</button>
							</div>
							</form>
						</div>
						<div class="col-md-5">
							<div class="row">
                            	<div class="col-xs-12 col-sm-12 col-md-12">
                            		<div class="icon-box left media p-25 mb-20" style="background:#003f7d; border-radius:5px;"> <a class="media-left pull-left" href="#"> <i class="pe-7s-map-2 text-theme-color-2"></i></a>
                            			<div class="media-body">
                            			    <h2 style="margin:0 0 10px 0; color:#fff;">Our Address</h2>
                            				<p class="text-white"><?php echo nl2br($contact_address);?></p>
                            			</div>
                            		</div>
                            	</div>
                            	<div class="col-xs-12 col-sm-6 col-md-12 text-white">
                            		<div class="icon-box left media p-25 mb-20" style="background:#003f7d; border-radius:5px;"> <a class="media-left pull-left" href="#"> <i class="pe-7s-call text-theme-color-2"></i></a>
                            			<div class="media-body">
                            			    <h2 style="margin:0 0 10px 0; color:#fff;">Our Contact Number</h2>
                            				    <p><?php echo $contact_no1;?><?php if($contact_no2!="") { ?><br><?php echo $contact_no2;?><?php } ?></p>
                            			</div>
                            		</div>
                            	</div>
                            	<div class="col-xs-12 col-sm-6 col-md-12 text-white">
                            		<div class="icon-box left media p-25 mb-20" style="background:#003f7d; border-radius:5px;"> <a class="media-left pull-left" href="#"> <i class="pe-7s-mail text-theme-color-2"></i></a>
                            			<div class="media-body">
                            			    <h2 style="margin:0 0 10px 0; color:#fff;">Our Contact Email</h2>
                            				    <p><?php echo $contact_email?></p>
                            			</div>
                            		</div>
                            	</div>
                            </div>
						</div>
					</div>
				</div>
			</section>
			<!-- page template area end -->

<?php require_once("footer1.php");?>