<?php
include_once ("include/main.inc.php");
$admin_sql = mysqli_query($GLOBALS['dbcon'], "select * from admin_details");
$admin_res = mysqli_fetch_array($admin_sql);
$w_number = $admin_res['whatsapp_no'];
?>
<?php
$referer = $_SERVER['HTTP_REFERER'];
$ip = $_SERVER['REMOTE_ADDR'];
$mobileNumber = "";
if (isset($_POST['contact-submit'])) {
    $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'] : '';
    $code = (!empty($_POST['code']))?$_POST['code']:'';
    $countryNames = (!empty($_POST['countryName']))?$_POST['countryName']:'';
    $countryName1= explode('(',$countryNames);
    $countryName=$countryName1[0];
    $code =$code!=''?$code:'91';
    $countryName= $countryName!=''?$countryName:'India';
    $mobileNumbers= '+'.$code.' - '.$mobileNumber;
    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($quantity,'#')!==false || strpos($quantity,'%')!==false || strpos($quantity,'@')!==false || strpos($quantity,'&')!==false || strpos($quantity,'~')!==false || strpos($quantity,'https')!==false || strpos($quantity,'http')!==false || strpos($quantity,'www')!==false || strpos($quantity,'?')!==false) {
        $errMsgs = 'URL(s) and special characters are not allowed!';
    } else {

        if ($name != '' && $email != '' && $mobileNumber != '' && $location != '' && $message != '' && $ip != '') {

            //$qry=mysql_query($sql_ens);	
            //reCAPTCHA validation
            if (isset($_POST['g-recaptcha-response']) && !empty($_POST['g-recaptcha-response'])) {

                $secret = '6LdFkMIiAAAAANA4qioXICaAUQoouU_Mx6hvDgDQ';
                //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) {
                    $errMsgs = '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_zcode='$code',en_country_name='$countryName', en_url='$referer', en_ip='$ip', en_date=now()";
                    $qry = mysqli_query($GLOBALS['dbcon'], $sql_ens);

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

            Url: " . $referer . "

            Name: " . $name . "

            Email: " . $email . "

            Mobile: " . $mobileNumbers . "

            Location:" . $location . "

            Country: ".$countryName."

            Message: " . $message . "
            ";

                    // $to = $admin_res['email'];
                    // $to2 = $admin_res['cc'];
                    // $to3 = 'webpulseindia@gmail.com';
                    $to3 = 'tanuja.wpsranchi@gmail.com';

                    $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 {
                $errMsgs = 'Robot verification failed, please try again.';
            }
        } else {
            $errMsgs = 'All the fields are Mandatory!';
        }

    }
}
?>
<a href="tel:<?= $admin_res['mobile']; ?>" title="Call Now" class="call-style">
    <i class="fa fa-phone"></i></a>

<a href="javascript:void()" data-bs-toggle="modal" data-bs-target="#enquire_now" class="send_enquiry"
    title="Send Enquiry">
    <i class="fa fa-envelope"></i><span>Send Enquiry</span></a>
<a href="https://api.whatsapp.com/send?phone=<?= $w_number; ?>" target="_blank" title="Whatsapp Now"
    class="whatsapp-style">
    <i class="fa fa-whatsapp"></i></a>

<div class="modal fade" id="enquire_now" tabindex="-1" role="dialog">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <div class="modal-title text-white" id="myModalLabel">Send Enquiry</div>
                <button type="button" class="close" data-bs-dismiss="modal" aria-hidden="true">&times;</button>
            </div>
            <div class="modal-body">
                <form id="enq_pop_form" method="post">
                    <div id="enq_pop_up"></div>
                    <div class="row">
                        <div class="col-lg-6">
                            <div class="form-group">
                                <input class="form-control" type="hidden" name="catID" id="catID">
                                <input type="text" tabindex="1" value="" name="name" placeholder="Your Name*"
                                    onkeyup="validateOnlyTextField(this)" required>
                            </div>
                        </div>
                        <div class="col-lg-6">
                            <div class="form-group">
                                <input type="email" value="" tabindex="2" placeholder="Your Email*" name="email"
                                    required>
                            </div>
                        </div>
                        <div class="col-lg-6">
                            <!-- <div class="form-group">
                                <input value="" placeholder="Your Mobile Number*" type="text" tabindex="3" name="mobile"
                                    onkeypress="return isNumberKey(event)" maxlength="10" required>
                            </div> -->
                            <div class="form-group">
                                <input type="hidden" class="countryName countryName" name="countryName" value="">
                                <input type="hidden" name="code" class="code" value="">
                                <input class="form-control telePhone mobile" value="" type="tel" name="mobile"
                                    placeholder="Mobile Number*"
                                    onkeyup="if (/\D/g.test(this.value)) this.value = this.value.replace(/\D/g,'')"
                                    minlength="10" maxlength="10" required="" autocomplete="off"
                                    style="padding-left: 84px;">
                            </div>
                        </div>
                        <div class="col-lg-6">
                            <div class="form-group">
                                <input type="text" placeholder="Your Location *" tabindex="4" name="location" value=""
                                    onFocus="geolocate()" required>
                            </div>
                        </div>
                        <div class="col-lg-12">
                            <div class="form-group">
                                <textarea name="message" tabindex="5" placeholder="Your Message*" class="form-control"
                                    required></textarea>
                            </div>
                        </div>
                        <div class="col-lg-12">
                            <div class="form-group">
                                <div class="g-recaptcha" tabindex="106" data-sitekey="<?= site_key; ?>"
                                    style="transform:scale(0.70);-webkit-transform:scale(0.70); transform-origin:0 0;-webkit-transform-origin:0 0;">
                                </div>
                            </div>
                        </div>
                        <div class="col-lg-6">
                            <div class="form-group">
                                <button name="submit_enq" class="read_more01" tabindex="7" type="submit"
                                    id="contact-submit" data-submit="...Sending">Submit</button>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.3.1/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/wow/1.0.2/wow.min.js"></script>
<script src="<?= SITE_URL_PATH; ?>/designer/js/slick.min.js"></script>
<script src="<?= SITE_URL_PATH; ?>/designer/js/slick-animation.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.9.0/jquery.validate.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/fancybox/3.1.20/jquery.fancybox.min.js"></script>
<script src="<?= SITE_URL_PATH; ?>/designer/js/themes.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/intl-tel-input/17.0.13/js/intlTelInput-jquery.min.js"></script>

<script>
    $(".telePhone").intlTelInput({
        preferredCountries: ["in", "us"],
        initialCountry: "in",
        separateDialCode: true,
    });
</script>

<script>

    setTimeout(function () {
        $('.YTD_video').append('<iframe src="https://www.youtube.com/embed/fh5PGPnMVqc" title="YouTube video player" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>');
    }, 5000);

</script>

<script>
    $(function () {
        $(".accordian .title").click(function (e) {
            $($(e.target).find('.fa.fa-plus').toggleClass('open'));
            $(".accordian ul .ac-dropdown").slideUp();
            if ($(this).next().is(":hidden")) {
                $(this).next().slideDown();
            }
        });
    });

    $(document).ready(function () {

        $("#enq_pop_form").validate({
            rules: {
                name: "required",
                message: {
                    required: true,

                },
                location: {
                    required: true,

                },

                 

                email: {
                    required: true,

                },
                mobile: {
                    required: true,
                    number: true,
                    minlength: 10,
                    maxlength: 10,
                }
            },
            messages: {
                name: "Please enter your name",
                message: {
                    required: "Please enter your message",

                },

                email: {
                    required: "Please enter your email address"
                },
                location: {
                    required: "Please Enter Your Location",

                },

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

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

                        }
                    }
                });

            }
        });
    });

    function validateOnlyTextField(element) {
        var str = element.value;
        if (!(/^[a-zA-Z]+$/.test(str))) {
            // console.log('String contain number characters');
            str = str.substr(0, str.length - 1);
            element.value = "";
        }
    }

    $(document).ready(function () {

        $("#product_pop_form1").validate({
            rules: {
                name: "required",
                message: {
                    required: true,

                },


                quantity: {
                required: true,

                },

                location: {
                    required: true,

                },
                email: {
                    required: true,

                },
                mobile: {
                    required: true,
                    number: true,
                    minlength: 10,
                    maxlength: 10,
                }
            },
            messages: {
                name: "Please enter your name",
                message: {
                    required: "Please enter your message",

                },

                email: {
                    required: "Please enter your email address"
                },
                location: {
                    required: "Please Enter Your Location",

                },

                quantity: {

                required: "Please enter Your MOQ (Minimum Order Quantity)",

                },

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

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

                        }
                    }
                });

            }
        });
    });



    function ValidateAlpha(evt) {

        var keyCode = (evt.which) ? evt.which : evt.keyCode

        if ((keyCode < 65 || keyCode > 90) && (keyCode < 97 || keyCode > 123) && keyCode != 32)

            return false;

        return true;

    }

    function isNumberKey(evt) {

        //var e = evt || window.event;

        var charCode = (evt.which) ? evt.which : evt.keyCode

        if (charCode != 46 && charCode > 31 &&

            (charCode < 48 || charCode > 57))

            return false;

        return true;

    }

    function validateOnlyTextField(element) {

        var str = element.value;

        if (str == ' ') {

            element.value = "";

        }

        if (!(/^[a-zA-Z\s]+$/.test(str))) {

            // console.log('String contain number characters');

            str = str.substr(0, str.length - 1);

            element.value = "";

        }

    }

    $(".telePhone").intlTelInput({

preferredCountries: ["in", "us"],

initialCountry: "in",

separateDialCode: true,

});

$('.iti__country-list li').click(function(){

$("#code").val($(this).data('dial-code'));

$(".mobile").val($(this).data('country-code-code'));

$('#countryName').val($(".iti__country-name", this).text());

$(".code").val($(this).data('dial-code'));

$('.countryName').val($(".iti__country-name", this).text()); 

})

</script>