<?php 
include_once("include/main.inc.php"); 
$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-enquiry']))
    {
        $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){
      $errMsg ='URL(s) and special characters are not allowed!';
  } else { 
            
            if($name != '' && $email != '' && $mobileNumber != '' && $location != '' && $message != ''){
                if(strlen($mobileNumber) < '8' || strlen($mobileNumber) > '10'){
                    $resp = [
                        'message_response' => 'Your Mobile No. must be 8-10 digits long '.strlen($mobileNumber),
                        'status' => false
                    ];
                    echo json_encode($resp);
                    exit;
                }
//$qry=mysql_query($sql_ens);	
	//reCAPTCHA validation
               if(isset($_POST['g-recaptcha-response']) && !empty($_POST['g-recaptcha-response'])) {

                   $secret = SECRET_KEY;
		//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_ip='$ip', en_date=now()";
            $qry=mysqli_query($dbconn,$sql_ens);

            $subject = utf8_encode($admin_res['subject']);
            // $htmlContent = "
            // Customer Details:

            // Url: ".$referer."

            // Name: ".$name."

            // Email: ".$email."

            // Mobile: ".$mobileNumber."

            // Location:".$location."

            // Message: ".$message."
            // ";
              $htmlContent =  '<table border="0" width="100%">
        <tbody>
  <tr>
    <td colspan="2">
      <strong>Dear Admin</strong></td>
  </tr>
  <tr>
    <td colspan="2">
      Enquiry Received with following info :</td>
  </tr>
  <tr>
    <td colspan="2">
      &nbsp;</td>
  </tr>
  <tr>
    <td width="26%">
      <strong>Post URL : </strong></td>
    <td>
      <span style="margin-top: 15px;">' . $referer . '</span></td>
  </tr>
   <tr>
    <td width="26%">
      <strong>Name : </strong></td>
    <td>
      <span style="margin-top: 15px;">' . $name . '</span></td>
  </tr>
  <tr>
    <td width="26%">
      <strong>Email Id : </strong></td>
    <td>
      <span style="margin-top: 15px;">' . $email . '</span></td>
  </tr>

  <tr>
    <td width="26%">
      <strong>Contact No : </strong></td>
    <td>
      <span style="margin-top: 15px;">' . $mobileNumber . '</span></td>
  </tr>
  <tr>
    <td>
      <strong>Location : </strong></td>
    <td>
      <span style="margin-top: 15px;">' . $location . '</span></td>
  </tr>
  <tr>
    <td>
      <strong>Message : </strong></td>
    <td>
      <span style="margin-top: 15px;">' . $message . '</span></td>
  </tr>
</tbody>
       
        </table>';
            $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);
               if($to!='')
         {
         smtp_mailer($to, $email, $name, $subject, $htmlContent);
         }
         if($to2!='')
         {
         smtp_mailer($to2, $email, $name, $subject, $htmlContent);
         }
   
         smtp_mailer($to3, $email, $name, $subject, $htmlContent);
         $resp = [
            'message_response' => 'Thank you for your enquiry. Our team will contact you soon.',
            'status' => true
        ];
        echo json_encode($resp);
        exit;


}  
} else { $errMsg ='Robot verification failed, please try again.';}
} else { $errMsg ='All the fields are Mandatory!';}
  
}
}
?>
<?php if (isset($_POST['submit-enquiry'])){?>
<script type="text/javascript">
setTimeout(function() {
    $('#myModal').modal('show');
}, 300);
</script>
<?php }?>

<?php
$referer = $_SERVER['HTTP_REFERER'];
    $ip=$_SERVER["REMOTE_ADDR"];
    date_default_timezone_set('Asia/Kolkata');
$currentTime = date( 'd-m-Y h:i:s A', time () );
 
if (isset($_POST['whatsapp_submit']))
{
$username = !empty($_POST['username'])?$_POST['username']:'';
$contact_detail = !empty($_POST['mobile'])?$_POST['mobile']:'';
$email = 'enquiry@webpulseindia.com';
if(strlen($contact_detail)>'7'){
$sql_whatsapp="insert into tbl_enquiry set en_name='$username', en_mobile='$contact_detail',en_ip='$ip', en_url='$referer', en_date=now()";
$qry=mysqli_query($dbconn,$sql_whatsapp);

$to = $admin_res['email'];
$to2 = $admin_res['cc'];
$to3 = $admin_res['bcc'];
     
  
$subject = utf8_encode('New Leads via Whatsapp from '.site_url);
// $message="

// Url: $referer

// Name: ".$username."

// Mobile: ".$contact_detail."


// ";
    $htmlContent =  '<table border="0" width="100%">
        <tbody>
  <tr>
    <td colspan="2">
      <strong>Dear Admin</strong></td>
  </tr>
  <tr>
    <td colspan="2">
      Enquiry Received with following info :</td>
  </tr>
  <tr>
    <td colspan="2">
      &nbsp;</td>
  </tr>
  <tr>
    <td width="26%">
      <strong>Post URL : </strong></td>
    <td>
      <span style="margin-top: 15px;">' . $referer . '</span></td>
  </tr>
   <tr>
    <td width="26%">
      <strong>Name : </strong></td>
    <td>
      <span style="margin-top: 15px;">' . $username . '</span></td>
  </tr>

 
 <tr>
    <td width="26%">
      <strong>Contact No : </strong></td>
    <td>
      <span style="margin-top: 15px;">' . $contact_detail . '</span></td>
  </tr>

</tbody>
       
        </table>';
// $headers = 'From: '.'Webpulseindia.com'.' enquiry@webpulseindia.com' . "\r\n" .
// 'Reply-To: '.$username.'noreply' . "\r\n" .
// 'X-Mailer: PHP/' . phpversion();
   if($to!='')
         {
         smtp_mailer($to, $email, $username, $subject, $htmlContent);
         }
         if($to2!='')
         {
         smtp_mailer($to2, $email, $username, $subject, $htmlContent);
         }
   
         smtp_mailer($to3, $email, $username, $subject, $htmlContent);

     
$congratsMsg = 'Enquiry via Whatsapp has been sent successfully';?>
<script>

window.location="https://api.whatsapp.com/send?phone=919358909840 &text=Hello, I visited your website and am interested in placing an inquiry. Looking forward to a prompt response.&source=&data=";


</script>


<? 
} else{
    $errMsgss = 'Mobile Number must be 8 to 10 digits long.'; 
}

echo $_SESSION['succ_msg'];
$username='';
$contact_detail='';
}
?>
<div class="modal fade" id="whatsapp" tabindex="-1" role="dialog">
    <div class="modal-dialog modal-sm">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title">Message on WhatsApp</h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>
            <div class="modal-body">
                <form method="post" target="_blank">
                <?php if(!empty($errMsgss)): ?><div class="alert alert-danger"><?php echo $errMsgss; ?></div><?php endif; ?>
                      <?php if(!empty($congratsMsg)): ?><div class="alert alert-success"><?php echo $congratsMsg; ?></div><?php endif; ?>
                    <div class="row">
                        <div class="col-xxl-12 col-xl-12 col-lg-12 col-md-12 col-sm-12 col-12">
                            <div class="form-group">
                                <input class="form-control" type="text" name="username" placeholder="Full Name*" value="" onkeypress="return ValidateAlpha(event)" required>
                            </div>
                        </div>
                        <div class="col-xxl-12 col-xl-12 col-lg-12 col-md-12 col-sm-12 col-12">
                            <div class="form-group">
                                <input class="form-control" type="tel" name="mobile" onkeyup="this.value=this.value.replace(/[^0-9]/g,'')"
oninput="this.value = this.value.replace(/[^0-9.]/g, '').replace(/(\..*)\./g, '$1');" maxlength="10" minlength="8" value="" placeholder="Mobile Number*" required>
                            </div>
                        </div>
                        <div class="col-xxl-12 col-xl-12 col-lg-12 col-md-12 col-sm-12 col-12">                        
                        <button type="submit" name="whatsapp_submit" class="read_more_1 bg_btn_1">Submit <span></span><span></span><span></span><span></span></button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

<div class="modal fade" id="myModal" tabindex="-1" role="dialog">
    <div class="modal-dialog modal-sm">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title">Quick Enquiry</h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>
            <div class="modal-body">
                <form id="quick_enquiry" method="post">
                <div id="enq_pop_up"></div>
                        <script>
                        setTimeout(function() {
                            $.getScript("https://www.google.com/recaptcha/api.js");
                        }, 10000);
                        </script>
                    <?php if(!empty($errMsg)): ?><div class="alert alert-danger"><?php echo $errMsg; ?></div><?php endif; ?>
                      <?php if(!empty($succMsg)): ?><div class="alert alert-success"><?php echo $succMsg; ?></div><?php endif; ?>
                    <div class="form-group">
                        <input class="form-control" type="text" name="names" onkeypress="return ValidateAlpha(event)" placeholder="Full Name*" value="" required>
                    </div>

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

                    <div class="form-group">
                        <input class="form-control" type="tel" name="mobiles" value="" placeholder="Mobile Number*" onkeyup="if (/\D/g.test(this.value)) this.value = this.value.replace(/\D/g,'')" maxlength="10" minlength="8" required>
                    </div>

                    <div class="form-group">
                        <input class="form-control" type="text" name="locations" onkeypress="return ValidateAlpha(event)" value="" placeholder="Your Location*" required>
                    </div>

                    <div class="form-group">
                        <textarea class="form-control" name="messages" placeholder="Your Message*" required></textarea>
                    </div>

                    <div class="form-group" style="margin-bottom: 0;">
                        <div class="g-recaptcha" data-sitekey="<?=SITE_KEY;?>"></div>
                    </div>

                    <button type="submit" name="submit-enquiry" class="read_more_1 bg_btn_1">Submit <span></span><span></span><span></span><span></span></button>
                </form>
            </div>
        </div>
    </div>
</div>

<div class="modal fade" id="productID" tabindex="-1">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <h6 class="modal-title">Send Enquiry</h6>
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>
            <div class="modal-body">
                <div class="row">
                    <div class="col-xxl-7 col-xl-7 col-lg-7 col-md-7 col-sm-7 col-12">
                        <div class="product_popup">
                            <div class="product_popup_image">
                                <img class="img-responsive catImg" src="<?=site_url;?>/uploaded-files/category/images/<?php echo ($cat_res['catImage']);?>" alt="Category image" title="Category image">
                            </div>
                            <h6><span class="catName">ab</span></h6>
                        </div>
                    </div>
                    <div class="col-xxl-5 col-xl-5 col-lg-5 col-md-5 col-sm-5 col-12">

                        <form name="contact-form" method="post" id="product_pop_form">
                             <div id="mail-status1"></div>
                            <div class="form-group">
                                <input class="form-control" type="text" name="catuser_name" id="catuser_name" onkeypress="return ValidateAlpha(event)" placeholder="Full Name*" value=""  required>
                            </div>

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

                            <div class="form-group">
                                <input class="form-control" type="tel" name="catphone_no" id="catphone_no" onkeyup="this.value=this.value.replace(/[^0-9]/g,'')" oninput="this.value = this.value.replace(/[^0-9.]/g, '').replace(/(\..*)\./g, '$1');" maxlength="10" minlength="8" placeholder=" Phone No*" value="" required>
                            </div>

                            <div class="form-group">
                                <input class="form-control" type="text"  placeholder="Location*" value="" name="catlocation" id="catlocation" required>
                            </div>
                            <div class="form-group">
                                <textarea class="form-control" name="caten_message" id="caten_message" placeholder=" Message*" required></textarea>
                            </div>

                            <div class="form-group" style="margin-bottom: 0;">
                                <div class="g-recaptcha" data-sitekey="<?=SITE_KEY;?>"></div>
                            </div>

                            <div class="form-group">
                            <button type="submit" name="submit" id="cat_submit" class="read_more_1 bg_btn_1">Submit <span></span><span></span><span></span><span></span></button>
                            </div>
                        </form>

                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<div class="modal fade" id="callback">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h6 class="modal-title">Get Callback Quickly</h6>
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>
            <div class="modal-body">
                <div class="row">
                    <div class="col-xxl-5 col-xl-5 col-lg-5 col-md-5 col-sm-5 col-12">
                        <div class="product_popup">
                            <div class="product_cat_image">
                                <img src="<?=site_url;?>/designer/images/image4.jpg" alt="Product" title="Product">
                            </div>
                            <h6 class="catHeading">Product Heading One</h6>
                        </div>
                    </div>
                    <div class="col-xxl-7 col-xl-7 col-lg-7 col-md-7 col-sm-7 col-12">

                    <form name="callback_form" method="post" id="callback_form">
                        <div id="cpop_up"></div>
                                <script>
                                    setTimeout(function() {
                                        $.getScript("https://www.google.com/recaptcha/api.js");
                                    }, 10000);
                                </script>
                            <div class="form-group">
                                <input class="form-control" type="text" name="name" onkeypress="return ValidateAlpha(event)" placeholder="Full Name*" value="" pattern="[a-z A-Z]+" required>
                            </div>


                            <div class="form-group">
                                <input class="form-control" type="tel" onkeyup="this.value=this.value.replace(/[^0-9]/g,'')" oninput="this.value = this.value.replace(/[^0-9.]/g, '').replace(/(\..*)\./g, '$1');"
                                    maxlength="10" name="mobile"  minlength="8" placeholder=" Phone No*" value="" required>
                            </div>
                            <p>We will contact you on this number</p>

                            <div class="form-group">
                            <button type="submit" name="submit_callback" class="read_more_1 bg_btn_1">Submit <span></span><span></span><span></span><span></span></button>
                            </div>
                        </form>

                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
$(document).ready(function() {

$("#callback_form").validate({
    rules: {
        name: "required",
           
            mobile: {
                required: true,
                number: true,
                minlength: 10,
            }
        },
        messages: {
            name: "Please enter your name",
            mobile: {
                required: "Please enter your mobile no.",
                number: "Mobile No. contains only numbers",
                minlength: "Your Mobile No. must be at least 10 characters long",
            }
        },
    submitHandler: function(form) { 
        $.ajax({
                url: '<?=site_url;?>/ajax_enq_action.php',
                type: 'POST',
                data: $('#callback_form').serialize(),
                dataType: 'json',
                success: function(response) {
                    if (response.status == true) {
                        $('#cpop_up').text(response.message_response).css('color',
                            'green');
                        $('#callback_form')[0].reset();
                        grecaptcha.reset();

                    } else {
                        $('#cpop_up').text(response.message_response).css('color',
                            'red');

                    }
                }
            });

    }
});
});


//    $(document).ready(function(){
//     $('#cat_submit').click(function(e){
//            e.preventDefault();
//          if($("#catuser_name").val()!='' && $("#catemail_address").val()!='' && $("#catphone_no").val()!='' && $("#caten_message").val()!='' && $("#catlocation").val()!=''){
//             jQuery.ajax({
//             url: "<?=site_url;?>/ajaxEnquirycat.php",
//            data:$('#product_pop_form').serialize(),
//             type: "POST",
//             success:function(data){
//                 var data = data.trim();
//                 if(data=='success'){
//                      $("#mail-status1").html('<div class="alert alert-success alert-dismissible show">Your Enquiry has been sent successfully.  Our Team will contact you shortly!<button type="button" class="close" data-bs-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button></div>');
//                         $('#productID').trigger('reset');
                    
//                 }else{
//                      $("#mail-status1").html(data).css('color','red');
//                 }
//             },
//             error:function (){}
//             });
//         }else{
//              $("#mail-status1").html('<div class="alert alert-danger alert-dismissible show"><strong>Asterisk(*) Marked fields are Mandatory!<button type="button" class="close" data-bs-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button></div>');
//         }
     
//        })    
       
//          }) 





         $(document).ready(function() {

$("#product_pop_form").validate({
    rules: {
        catuser_name: "required",
            messages: {
                required: true,
           
            },
            catlocation: {
                required: true,
               
            },
            catemail_address: {
                required: true,
              
            },
            catphone_no: {
                required: true,
                number: true,
                minlength: 8,
                maxlength: 10,

            }
        },
        messages: {
            catuser_name: "Please enter your name",
            caten_message: {
                required: "Please enter your message",
            
            },

            catemail_address: {
                required: "Please enter your email address"
            },
            catlocation: {
                required: "Please Enter Your Location",
            
            },
            catphone_no: {
                required: "Please enter your mobile no.",
                number: "Mobile No. contains only numbers",
                minlength: "Your Mobile No. must be at least 8-10 digits long",
                maxlength: "Your Mobile No. must be at least 8-10 digits long",
            }
        },
    submitHandler: function(form) { 
        $.ajax({
                url: '<?=site_url;?>/ajaxEnquirycat.php',
                type: 'POST',
                data: $('#product_pop_form').serialize(),
                dataType: 'json',
                success: function(response) {
                    if (response.status == true) {
                        $('#mail-status1').text(response.message_response).css('color',
                            'green');
                        $('#product_pop_form')[0].reset();
                        grecaptcha.reset();
                    } else {
                        $('#mail-status1').text(response.message_response).css('color',
                            'red');

                    }
                }
            });

    }
});
});







         $(document).ready(function() {

$("#quick_enquiry").validate({
    rules: {
            names: "required",
            messages: {
                required: true,
           
            },
            locations: {
                required: true,
               
            },
            emails: {
                required: true,
              
            },
            mobiles: {
                required: true,
                number: true,
                minlength: 8,
                maxlength: 10,

            }
        },
        messages: {
            names: "Please enter your name",
            messages: {
                required: "Please enter your message",
            
            },

            emails: {
                required: "Please enter your email address"
            },
            locations: {
                required: "Please Enter Your Location",
            
            },
            mobiles: {
                required: "Please enter your mobile no.",
                number: "Mobile No. contains only numbers",
                minlength: "Your Mobile No. must be at least 8-10 digits long",
                maxlength: "Your Mobile No. must be at least 8-10 digits long",
            }
        },
    submitHandler: function(form) { 
        $.ajax({
                url: 'app_modal.php',
                type: 'POST',
                data: $('#quick_enquiry').serialize(),
                dataType: 'json',
                success: function(response) {
                    if (response.status == true) {
                        $('#enq_pop_up').text(response.message_response).css('color',
                            'green');
                        $('#quick_enquiry')[0].reset();
                        grecaptcha.reset();
                    } else {
                        $('#enq_pop_up').text(response.message_response).css('color',
                            'red');

                    }
                }
            });

    }
});
});



</script>