
­­­­­­­­­­­­­­­­­­
<!DOCTYPE html>
<html>
<?php
session_start();

// Generate OTP and store in session
if (!isset($_SESSION['otp'])) {
    $_SESSION['otp'] = rand(100000, 999999);
    $_SESSION['otp_attempts'] = 0;
}

//$msg = "Your verfication code is: ".$otp;

function generateRandomBasedOnTime() {
    // Get the current date and time
    $date = date('YmdHis'); // Format: YearMonthDayHourMinuteSecond

    // Get the current microtime with microseconds
    $microtime = microtime();
    
    // Split the microtime into seconds and microseconds
    list($microseconds, $seconds) = explode(' ', $microtime);
    
    // Remove the decimal point from microseconds for integer combination
    $microseconds = str_replace('.', '', $microseconds);
    
    // Combine date, seconds, and microseconds into a single string
    $combined = $date . $seconds . $microseconds;
    
    // Convert the combined string into an integer and hash it for randomness
    $random = abs(crc32($combined) + mt_rand(0, 9999));

    return $random;
}

function send_sms2($number,$msg){

$username = "balubaidy8r60j1czfbbh6td";
$password = "lpfl8lzwmgsntg9uddaaoe74lz2yjsmg";    

 $rand = generateRandomBasedOnTime();

$number = "966".ltrim($number,"0");

$to = $number;
//$msg = $_POST['message'];
//$_GET['fromInput'] = $_POST['sender'];


//print_r($_POST);

//if($key == 'TGFWYUxvb24tSGFyYW0tVGFuYXFvbA=='){

       //$to = "966".ltrim($_GET['toInput'],"0");
        if ($to <> '') {
            $from = $_GET['fromInput'];
            //$messageId = $_POST['messageIdInput'];
            $text = $msg;
            //$text = $_GET['textInput'];
            //$notifyUrl = $_POST['notifyUrlInput'];
           // $notifyContentType = $_POST['notifyContentTypeInput'];
            //$callbackData = $_POST['callbackDataInput'];
           // $username = $_GET['username'];
        //    $password = $_GET['password'];

            $postUrl = "https://api.goinfinito.me/unified/v2/send";

            // creating an object for sending SMS
            $destination = array("to" => array("phoneNumber" => $to));
                
           // $whatsappMessage = array("text" => $msg
        //    , "imageUrl" => $attachment
         //   );
            $smsMessage = array("text" => "Failover Message API Testing");
            
            $message = '{
  "apiver": "1.0",
    "sms": {
    "ver": "2.0",
      "dlr": {
      "url": ""
    },
    "messages": [{
      "udh": "0",
      "coding": 2,
      "text": "'.$msg.'",
      "property": 0,
      "id": "'.$rand.'",
      "addresses": [{
        "from": "AUTOZONE",
        "to": "'.$number.'",
        "seq": "'.$rand.'",
        "tag": "AUTOZONE"
      }]
    }]
  }
}';

            $postData = $message;
            //$postDataJson = json_encode($postData);
            
            $postDataJson = $postData;

            $ch = curl_init();
            $header = array("Content-Type:application/json", "Accept:application/json",);

            curl_setopt($ch, CURLOPT_URL, $postUrl);
            curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
            curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
            curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password);
            curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
            curl_setopt($ch, CURLOPT_MAXREDIRS, 2);
            curl_setopt($ch, CURLOPT_POST, 1);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $postDataJson);

            // response of the POST request
            $response = curl_exec($ch);
            $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
            $responseBody = json_decode($response);
            curl_close($ch);
//print_r($response);
//return $response;
//return $message;
//print_r($postDataJson);

        } else {
            
  //          echo '<div class="alert alert-danger" role="alert">
//                <b>An error occurred!</b> Reason: Phone number is missing
  //          </div>';
            
        }

//file_put_contents('smslog.txt', $response);

error_log($response);
             
    
}

//send_sms2($mobile,$msg);

// Function to send OTP (simulated)
function sendOTP($mobile, $otp) {
    // Here, integrate an actual SMS API to send OTP

$msg = "Your verfication code is: ".$otp; 

send_sms2($mobile,$msg);
    
    return "OTP $otp sent to $mobile";
}



// Retrieve form data
$utm_source = $_POST['utm_source'] ?? '';
$utm_campaign = $_POST['utm_campaign'] ?? '';
$formtype = $_POST['formtype'] ?? '';
$offer_id = $_POST['offer_id'] ?? '';
$fullName = $_POST['fullName'] ?? '';
$email = $_POST['email'] ?? '';
$mobile = $_POST['mobile'] ?? '';
$salary = $_POST['salary'] ?? '';
$model = $_POST['model'] ?? '';
$nationality = $_POST['nationality'] ?? '';
$bank = $_POST['bank'] ?? '';
$gender = $_POST['gender'] ?? '';
$city = $_POST['city'] ?? '';
$branch = $_POST['branch'] ?? '';
$obligation = $_POST['obligation'] ?? '';
$realestateLoan = $_POST['realestateLoan'] ?? '';
$obligationAmount = $_POST['obligationAmount'] ?? '';
$purchaseTime = $_POST['purchaseTime'] ?? '';
$terms = $_POST['terms'] ?? '';

// Send OTP on page load
$otpMessage = sendOTP($mobile, $_SESSION['otp']);
?>

<!DOCTYPE html>
<html lang="ar">
<head>

<!-- Google Tag Manager -->
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-5QL8T48Q');</script>
<!-- End Google Tag Manager -->
    
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>التحقق من رمز التحقق</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css">
    
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.2/css/all.min.css">
     <link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Cairo:wght@200..1000&display=swap" rel="stylesheet">

    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>

    <style>
        body {
            font-family: 'Cairo', sans-serif;
            background-color: #f8f9fa;
            direction: rtl;
            text-align: right;
        }
  
        .btn {
            width: 100%;
        }
       .navbar {
            background-color: #FFFFFF;
        }
        .navbar-brand img {
            height: 5em;
        }
        .footer {
            background-color: #55556F;
            color: #ffb612;
            text-align: center;
            padding: 15px 0;
            margin-top: 30px;
        }
        .social-icons a {
            color: #ffb612;
            margin: 0 10px;
            font-size: 20px;
            text-decoration: none;
        }
        .card {
            border: none;
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
        }
        .countdown-container {
            display: flex;
            justify-content: center;
            margin-top: 10px;
        } 
        
        .third-button{
border: 0px;
    margin-bottom: 10px;
    transform: skew(-6deg, -0deg);
    border-radius: 0px;
    background: #ffb612; 
    color: #55556F;
            
        }  
    
    .third-button:hover{
    background: #55556F;
    color:#FFFFFF;
            
        }     
        
    </style>
</head>
<body>

<!-- Google Tag Manager (noscript) -->
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-5QL8T48Q"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<!-- End Google Tag Manager (noscript) -->    
    
    <nav class="navbar navbar-expand-lg navbar-dark">
        <div class="container">
            <a class="navbar-brand" href="#">
                <img style="height:auto;width:52%;" src="https://autozone.com.sa/wp-content/uploads/2025/01/AZ_Original_EN.png" alt="Autozone Logo">
            </a>
        </div>
    </nav>    

<div class="container mt-5" style="max-width:500px;">
        <div class="card shadow p-4">
    <h3 class="text-center">التحقق من رمز التحقق</h3>
    <p class="text-center">تم إرسال رمز التحقق إلى جوالك.</p>
    
    <form id="otpForm" method="post" action="https://specialoffers.autozone.com.sa/submit-lead-ar/">  
        <!-- Hidden Fields -->
        <input type="hidden" name="utm_source" value="<?php echo $utm_source; ?>">
        <input type="hidden" name="utm_campaign" value="<?php echo $utm_campaign; ?>">
        <input type="hidden" name="formtype" value="<?php echo $formtype; ?>">
        <input type="hidden" name="offer_id" value="<?php echo $offer_id; ?>">
        <input type="hidden" name="fullName" value="<?php echo $fullName; ?>">
        <input type="hidden" name="email" value="<?php echo $email; ?>">
        <input type="hidden" name="mobile" id="mobile" value="<?php echo $mobile; ?>">
        <input type="hidden" name="salary" value="<?php echo $salary; ?>">
        <input type="hidden" name="model" value="<?php echo $model; ?>">
        <input type="hidden" name="nationality" value="<?php echo $nationality; ?>">
        <input type="hidden" name="bank" value="<?php echo $bank; ?>">
        <input type="hidden" name="gender" value="<?php echo $gender; ?>">
        <input type="hidden" name="city" value="<?php echo $city; ?>">
        <input type="hidden" name="branch" value="<?php echo $branch; ?>">
        <input type="hidden" name="obligation" value="<?php echo $obligation; ?>">
        <input type="hidden" name="realestateLoan" value="<?php echo $realestateLoan; ?>">
        <input type="hidden" name="obligationAmount" value="<?php echo $obligationAmount; ?>">
        <input type="hidden" name="purchaseTime" value="<?php echo $purchaseTime; ?>">
        <input type="hidden" name="terms" value="<?php echo $terms; ?>">

        <div class="mb-3">
            <label for="otp" class="form-label">يرجى إدخال رمز التحقق</label>
            <input type="text" class="form-control" id="otp" name="otp" required>
        </div>
        
        <button type="submit" class="btn btn-primary third-button" id="submitBtn" disabled>تأكيد رمز التحقق</button>

        <div class="text-center mt-3">
            <button type="button" class="btn btn-secondary third-button" id="resendOtp" disabled>إعادة إرسال الرمز (60)</button>
            <button type="button" class="btn btn-danger mt-2 third-button" id="changeMobile">تغيير رقم الجوال</button>
        </div>
    </form>

<div style="height:64px;"></div>    
    
    </div>
</div>

 <footer class="footer">
        <div class="container">
            <p>&copy; <?php echo date('Y'); ?> Balubaid Automotives. All rights reserved.</p>
            <p>Toll-Free: 800-760-6000</p>
            <div class="social-icons">
                <a href="#"><i class="fa-brands fa-facebook"></i></a>
                <a href="#"><i class="fa-brands fa-twitter"></i></a>
                <a href="#"><i class="fa-brands fa-instagram"></i></a>
                <a href="#"><i class="fa-brands fa-linkedin"></i></a>
            </div>
        </div>
    </footer>

<script>
    let attemptCount = 0;
    let resendTimer = 60;

    function startResendTimer() {
        $("#resendOtp").prop("disabled", true);
        let interval = setInterval(() => {
            if (resendTimer > 0) {
                $("#resendOtp").text(`إعادة إرسال الرمز (${resendTimer})`);
                resendTimer--;
            } else {
                clearInterval(interval);
                $("#resendOtp").text("إعادة إرسال الرمز").prop("disabled", false);
                resendTimer = 60;
            }
        }, 1000);
    }

    $("#otpForm").on("submit", function (e) {
        e.preventDefault();
        let enteredOtp = $("#otp").val();
        
        $.post("https://specialoffers.autozone.com.sa/verify-otp-2-ar/", { otp: enteredOtp }, function (response) {
            if (response.trim() === "success") {
                $("#otpForm").off("submit").submit();
            } else {
                alert("رمز التحقق غير صحيح. حاول مرة أخرى.");
            }
        });
    });

    $("#resendOtp").on("click", function () {
        if (attemptCount < 3) {
            attemptCount++;
            $.post("https://specialoffers.autozone.com.sa/resend-otp/", { mobile: $("#mobile").val() }, function (response) {
                alert(response);
                startResendTimer();
            });
        } else {
            alert("لقد تجاوزت الحد الأقصى لإعادة الإرسال.");
            $("#resendOtp").prop("disabled", true);
        }
    });

    $("#changeMobile").on("click", function () {
    let newMobile = prompt("يرجى إدخال رقم الجوال الجديد:");

    if (newMobile) {
        // Convert Arabic numbers to English before validation
        newMobile = newMobile.replace(/[٠١٢٣٤٥٦٧٨٩]/g, function (d) {
            return "٠١٢٣٤٥٦٧٨٩".indexOf(d);
        });

        // Validation: Only numbers, starts with 05, length = 10
        let regex = /^(05|٠٥)\d{8}$/;
        if (!regex.test(newMobile)) {
            alert("رقم الجوال غير صحيح. يجب أن يبدأ بـ 05 أو ٠٥ ويتكون من 10 أرقام فقط.");
            return;
        }

        // Update the hidden input field with the new number
        $("#mobile").val(newMobile);

        // Send OTP to the new mobile number
        $.post("https://specialoffers.autozone.com.sa/resend-otp/", { mobile: newMobile }, function (response) {
            alert(response);
            startResendTimer();
        });
    }
});

    $(document).ready(function () {
        startResendTimer();
        $("#submitBtn").prop("disabled", false);
    });
</script>

<script src="https://d1v2u6by4izioz.cloudfront.net/e99ca47bc67c5a965f2a79618180ba22.min.js?o=NjU0NQ==" async="true"></script>

</body>
</html>