<?php

include_once("include/main.inc.php");

date_default_timezone_set('Asia/Kolkata');

$enq_date = date('Y-m-d H:i:s');

$hover = "contact";
$admin_sql = mysqli_query(
    $GLOBALS['dbconn'],
    "select * from admin_details"
);
$admin_res = mysqli_fetch_array($admin_sql);

$page_metatitle = "Contact Us - " . COMPANY_NAME;

$page_metakey = "Contact Us - " . COMPANY_NAME;

$page_metadesc = "Contact Us - " . COMPANY_NAME;

$referer = $_SERVER['HTTP_REFERER'];

$ip = $_SERVER['REMOTE_ADDR'];

if (isset($_POST['submit_contact'])) {

    $name = !empty($_POST['name']) ? $_POST['name'] : '';

    $email = !empty($_POST['email']) ? $_POST['email'] : '';

    $mobileNumber = (!empty($_POST['mobile'])) ? $_POST['mobile'] : '';

    $location = !empty($_POST['location']) ? $_POST['location'] : '';

    $message = !empty($_POST['message']) ? $_POST['message'] : '';

    $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($location, '#') !== false || strpos($location, '%') !== false || strpos($location, '@') !== false || strpos($location, '&') !== false || strpos($location, '~') !== false || strpos($location, 'https') !== false || strpos($location, 'http') !== false || strpos($location, 'www') !== false || strpos($location, '?') !== false || strpos($name, '#') !== false || strpos($name, '%') !== false || strpos($name, '@') !== false || strpos($name, '&') !== false || strpos($name, '~') !== false || strpos($name, 'https') !== false || strpos($name, 'http') !== false || strpos($name, 'www') !== false || strpos($name, '?') !== false) {

        $resp = [

            'message_response' => 'URL(s) and special characters are not allowed',

            'status' => false

        ];

        echo json_encode($resp);

        exit;
    } else {

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

            if (isset($_POST['g-recaptcha-response']) && !empty($_POST['g-recaptcha-response'])) {

                $secret = SECRET_KEY;

                $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) {

                    $resp = [

                        'message_response' => 'Robot verification failed, please try again.',

                        'status' => false

                    ];

                    echo json_encode($resp);

                    exit;
                }

                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='$enq_date',en_zcode='$code',en_country_name='$countryName', en_ip='$ip'";

                    $qry = mysqli_query(
                        $GLOBALS['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."

                    // ";

                    $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;">' . $mobileNumbers . '</span></td>

      </tr>

      <tr>

  <td>

    <strong>Country : </strong></td>

  <td>

    <span style="margin-top: 15px;">' . $countryName . '</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 = 'webpulseindia@gmail.com';

                    // $to3 = 'developer.wpsrnc@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);

                    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 {
                $resp = [
                    'message_response' => 'Please check the recaptcha box!',
                    'status' => false
                ];
                echo json_encode($resp);
                exit;
            }
        } else {

            $resp = [

                'message_response' => 'All the fields are Mandatory!',

                'status' => false

            ];

            echo json_encode($resp);

            exit;
        }
    }
}
?>
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title><?= $page_metatitle; ?></title>
    <meta name="description" content="<?= $page_metadesc; ?>">
    <meta name="keywords" content="<?= $page_metakey; ?>">
    <?php include "app_top.php"; ?>
</head>

<body>
    <?php include 'app_header.php'; ?>
    <section class="heading_banner" style="background-image: url(<?= theme_url; ?>/images/contact-banner.jpg)">
        <div class="container">
            <div class="row">
                <div class="col-xxl-12 col-xl-12 col-lg-12 col-md-12 col-sm-12 col-12 text-center">
                    <h1 class="cat_title">STEEL OVERSEAS CONTACT DETAILS</h1>
                </div>
            </div>
        </div>
    </section>
    <div class="inner_breadcrumb hidden_xs">
        <div class="container">
            <div class="row">
                <div class="col-xxl-12 col-xl-12 col-lg-12 col-md-12 col-sm-12 col-12">
                    <ul class="breadcrumb">
                        <li><a href="<?= site_url; ?>" title="Home">Home</a></li>
                        <li class="active">Contact Us</li>
                    </ul>
                </div>
            </div>
        </div>
    </div>
    <section class="contact_page">
        <div class="container">
            <div class="contact_form_grid1">
                <div class="row">
                    <div class="col-xxl-5 col-xl-5 col-lg-5 col-md-5 col-sm-12 col-12 contact_details">
                        <h2 class="title_h2">STEEL OVERSEAS CONTACT DETAILS</h2>
                        <p>Write to us or call us, get quick response powered by our advanced customer support team .
                        </p>
                        <ul class="address_list">
                            <li> <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor"
                                    viewBox="0 0 16 16">
                                    <path
                                        d="M12.166 8.94c-.524 1.062-1.234 2.12-1.96 3.07A31.493 31.493 0 0 1 8 14.58a31.481 31.481 0 0 1-2.206-2.57c-.726-.95-1.436-2.008-1.96-3.07C3.304 7.867 3 6.862 3 6a5 5 0 0 1 10 0c0 .862-.305 1.867-.834 2.94zM8 16s6-5.686 6-10A6 6 0 0 0 2 6c0 4.314 6 10 6 10z" />
                                    <path d="M8 8a2 2 0 1 1 0-4 2 2 0 0 1 0 4zm0 1a3 3 0 1 0 0-6 3 3 0 0 0 0 6z" />
                                </svg>

                                Address: <?= $admin_res['address']; ?>
                            </li>
                            <li> <a href="tel:+919769298598"> <svg xmlns="http://www.w3.org/2000/svg" width="16"
                                        height="16" fill="currentColor" viewBox="0 0 16 16">
                                        <path
                                            d="M3.654 1.328a.678.678 0 0 0-1.015-.063L1.605 2.3c-.483.484-.661 1.169-.45 1.77a17.568 17.568 0 0 0 4.168 6.608 17.569 17.569 0 0 0 6.608 4.168c.601.211 1.286.033 1.77-.45l1.034-1.034a.678.678 0 0 0-.063-1.015l-2.307-1.794a.678.678 0 0 0-.58-.122l-2.19.547a1.745 1.745 0 0 1-1.657-.459L5.482 8.062a1.745 1.745 0 0 1-.46-1.657l.548-2.19a.678.678 0 0 0-.122-.58L3.654 1.328zM1.884.511a1.745 1.745 0 0 1 2.612.163L6.29 2.98c.329.423.445.974.315 1.494l-.547 2.19a.678.678 0 0 0 .178.643l2.457 2.457a.678.678 0 0 0 .644.178l2.189-.547a1.745 1.745 0 0 1 1.494.315l2.306 1.794c.829.645.905 1.87.163 2.611l-1.034 1.034c-.74.74-1.846 1.065-2.877.702a18.634 18.634 0 0 1-7.01-4.42 18.634 18.634 0 0 1-4.42-7.009c-.362-1.03-.037-2.137.703-2.877L1.885.511z">
                                        </path>
                                    </svg> Call:<?= $admin_res['mobile']; ?></a></li>
                            <!-- <li><a href="mailto:<?= $admin_res['email']; ?>"><span class="fa fa-envelope"></span> E-mail: <?= $admin_res['email']; ?></a></li> -->
                        </ul>
                    </div>
                    <div class="col-xxl-7 col-xl-7 col-lg-7 col-md-7 col-sm-12 col-12 form_grid">
                        <h3 class="title_h2">We want to hear from you!</h3>
                        <form name="contact-form" method="post" id="contact_form">
                            <div id="pop_up"></div>
                          <?php if (!empty($message_response)): ?><div class="alert alert-danger"><?php echo $message_response; ?></div><?php endif; ?>
                                <?php if (!empty($message_response)): ?><div class="alert alert-success"><?php echo $message_response; ?></div><?php endif; ?>
                            <div class="row">
                                <div class="col-xxl-6 col-xl-6 col-lg-6 col-md-6 col-sm-6 col-12">
                                    <div class="form-group"> <input class="form-control" type="text" name="name" onkeypress="return ValidateAlpha(event)"
                                            placeholder="Full Name*" required> </div>
                                </div>
                                <div class="col-xxl-6 col-xl-6 col-lg-6 col-md-6 col-sm-6 col-12">
                                    <div class="form-group"> <input class="form-control" type="email" name="email"
                                            placeholder="Email ID*" required> </div>
                                </div>
                                <div class="col-xxl-6 col-xl-6 col-lg-6 col-md-6 col-sm-6 col-12">
                                    <input type="hidden" class="countryName" name="countryName" value="India">
                                    <input type="hidden" name="code" class="code" value="+91">
                                    <div class="form-group">
                                        <input class="form-control telePhone" type="text" name="mobile" onkeyup="this.value=this.value.replace(/[^0-9]/g,'')"
                                        oninput="this.value = this.value.replace(/[^0-9.]/g, '').replace(/(\..*)\./g, '$1');" placeholder="Phone No*" required>
                                    </div>
                                </div>
                                <div class="col-xxl-6 col-xl-6 col-lg-6 col-md-6 col-sm-6 col-12">
                                    <div class="form-group">
                                        <input class="form-control" type="text" onkeypress="return ValidateAlpha(event)" name="location"
                                            placeholder="Location*" 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"> <textarea class="form-control" rows="5"
                                            placeholder="Comments Here*" required name="message"></textarea> </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" style="margin-bottom: 0;">
                                        <div class="g-recaptcha" data-sitekey="<?= SITE_KEY; ?>"></div>
                                    </div>
                                </div>
                                <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                                    <div class="form-group"> <button type="submit"
                                            class="read_more_btn_2" name="submit_contact">Submit</button> </div>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </section>
    <?php include "app_footer.php"; ?>
    <?php include "app_bottom.php"; ?>
</body>

</html>