<?php
date_default_timezone_set('Asia/Kolkata');
include_once("include/main.inc.php"); 
date_default_timezone_set('Asia/Kolkata');
$date=date('Y-m-d H:i');

$admin_sql=mysqli_query($dbconn,"select * from admin_details");
$admin_res=mysqli_fetch_array($admin_sql);
$referer = $_SERVER['HTTP_REFERER'];
    $ip=$_SERVER['REMOTE_ADDR'];
    $mobileNumber = "";
    if (isset($_POST['submit-enq']))
    {
        $name = !empty($_POST['names'])?$_POST['names']:'';
        $email = !empty($_POST['emails'])?$_POST['emails']:'';
        $mobileNumber = (!empty($_POST['mobiles']))?$_POST['mobiles']:'';
        $location = !empty($_POST['locations'])?$_POST['locations']:'';
        $message = !empty($_POST['messages'])?$_POST['messages']:'';
      if(strpos($message,'#')!==false || strpos($message,'%')!==false || strpos($message,'@')!==false || strpos($message,'&')!==false || strpos($message,'~')!==false || strpos($message,'https')!==false || strpos($message,'http')!==false || strpos($message,'www')!==false || strpos($message,'?')!==false || strpos($message,'/')!==false){
      $errMsg ='URL(s) and special characters are not allowed!';
  } else {    
            if($name != '' && $email != '' && $mobileNumber != '' && $location != '' && $message != '' && $ip != '' ){
if(strlen($mobileNumber)==10){
//$qry=mysql_query($sql_ens);	
	//reCAPTCHA validation
               if(isset($_POST['g-recaptcha-response']) && !empty($_POST['g-recaptcha-response'])) {

        $secret = '6Lf6jT0iAAAAAEapAXKmph4SQwiH24I7sTcF6h_3';
		//get verify response data
        $data = array( 'secret' => $secret, 'response' => $_POST['g-recaptcha-response'] ); $verify = curl_init(); curl_setopt($verify, CURLOPT_URL, "https://www.google.com/recaptcha/api/siteverify"); curl_setopt($verify, CURLOPT_POST, true); curl_setopt($verify, CURLOPT_POSTFIELDS, http_build_query($data)); curl_setopt($verify, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($verify, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($verify); //var_dump($response);
        $response = json_decode($response);
        if (!$response->success) {
            $errMsg = 'Please click on the reCAPTCHA box.';
        }	
        
        if($response->success) {

            $sql_ens="insert into tbl_enquiry set en_name='$name', en_email='$email', en_mobile='$mobileNumber', en_country='$location', en_comment='$message', en_url='$referer', en_date=now()";
            $qry=mysqli_query($dbconn,$sql_ens);

            $subject = utf8_encode('Webpulseindia.com '.' - '. $admin_res['subject']);
            $htmlContent = "
            Customer Details:

            Url: ".$referer."

            Name: ".$name."

            Email: ".$email."

            Mobile: ".$mobileNumber."

            Location:".$location."

            Message: ".$message."
            ";
            
            $to =  $admin_res['email'];
$to2 = $admin_res['cc'];
$to3 = $admin_res['bcc'];
            
   $headers = 'From: '.'Webpulseindia.com'.' enquiry@webpulseindia.com' . "\r\n" .
            'Reply-To:  '.$name.'<'.$email.'>' . "\r\n" .
            'X-Mailer: PHP/' . phpversion();
            @mail($to,$subject,$htmlContent,$headers);
            @mail($to2,$subject,$htmlContent,$headers);
            @mail($to3,$subject,$htmlContent,$headers);
            $succMsg = 'Thank you for your enquiry. Our team will contact you soon.';
       }  
} else { $errMsg ='Robot verification failed, please try again.';}
} else { $errMsg ='Please Enter 10 Digit Mobile Number';}
} else { $errMsg ='All the fields are Mandatory!';}
}
}

?>

<div class="col-xxl-3 col-xl-3 col-lg-3 col-md-3 col-sm-3 col-lg-pull-9 col-md-pull-9 order-xxl-first order-xl-first order-lg-first order-md-first order-sm-first order-last">
     <div class="left_sidebar">
         <div class="left_title">Our Services</div>
         <ul>
             <?php
$sql=mysqli_query($dbconn,"select * from category_tbl where parentID='1' and status = 'Y' order by catOrder");
while($res=mysqli_fetch_array($sql))
{ 
?>
             <li><a href="<?=site_url;?>/<?=getValidFileName($res['catName']);?>.htm" title="<?=$res['catName']?>"><?=$res['catName']?></a></li>
<?php  } ?>
         </ul>


     </div>
     <div class="left_sidebar">

         <div class="left_title">Quick Contact</div>
           <form name="contact-forms" method="post" id="quick_form">
               <script src="https://www.google.com/recaptcha/api.js"></script>
            <?php if(!empty($errMsg)): ?><div class="alert alert-danger alert-dismissible fade show"><?php echo $errMsg; ?><button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button></div><?php endif; ?>
                            <?php if(!empty($succMsg)): ?><div class="alert alert-success alert-dismissible fade show"><?php echo $succMsg; ?><button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button></div><?php endif; ?>
             <div class="form-group">
                 <input placeholder="Full Name *" class="form-control" type="text" name="names"  value="" required=""  onkeypress="return ValidateAlpha(event)">
             </div>

             <div class="form-group">
                  <input placeholder="Email ID *" class="form-control" type="email" name="emails"  value="" required="">
             </div>

             <div class="form-group">
                   <input placeholder="Phone Number *" class="form-control" type="tel" name="mobiles" onkeyup="this.value=this.value.replace(/[^0-9]/g,'')" oninput="this.value = this.value.replace(/[^0-9.]/g, '').replace(/(\..*)\./g, '$1');" maxlength="10" value="" required="">
             </div>
             <div class="form-group">
                <input placeholder="Location*" class="form-control" type="text"  name="locations"  value="" required=""  onkeypress="return ValidateAlpha(event)">
             </div>
             <div class="form-group">
                 <textarea class="form-control" name="messages"  placeholder="Message*" required></textarea>
             </div>
             <div class="form-group" style="margin-bottom:5px;">
                 <div class="g-recaptcha" data-sitekey="6Lf6jT0iAAAAACzJctoG1Vcppxw_i7sj6-ed6IZ9"></div>
             </div>

             <div class="form-group">
                 <button type="submit" class="read_more" name="submit-enq">Submit</button>
             </div>
         </form>
     </div>

 </div>
