    
    <?php
        // Define the timeframe (in seconds) to consider a user "online"
        $online_threshold = 120; // 2 minutes

        // date_default_timezone_set("Africa/Lagos");

        try {
            // Prepare the SQL query to count online users
            $sql_online = "SELECT COUNT(*) AS online_count FROM user_activity WHERE UNIX_TIMESTAMP(recent_activity) >= UNIX_TIMESTAMP(NOW()) - :threshold";
            $stmt_online = $pdo->prepare($sql_online);
            $stmt_online->bindParam(':threshold', $online_threshold, PDO::PARAM_INT);
            $stmt_online->execute();
            $row_online = $stmt_online->fetch(PDO::FETCH_ASSOC);

            // Extract the count of online users
            $online_count = $row_online['online_count'];

            // Prepare the SQL query to count total users
            $sql_total = "SELECT COUNT(*) AS total_count FROM user_activity";
            $stmt_total = $pdo->query($sql_total);
            $row_total = $stmt_total->fetch(PDO::FETCH_ASSOC);


            // Extract the count of total users
            $total_count = $row_total['total_count'];

            // Calculate the count of offline users
            $offline_count = $total_count - $online_count;

            // // Count completed submissions
            // $sql_completed = "SELECT COUNT(*) AS completed_count FROM visitors WHERE s_status = 1";
            // $stmt_completed = $pdo->query($sql_completed);
            // $row_completed = $stmt_completed->fetch(PDO::FETCH_ASSOC);
            // $completed_count = $row_completed['completed_count'];
                        
        
        } catch (PDOException $e) {
            // Handle database errors
            echo "Error: " . $e->getMessage();
        }

        try {
            $sql_total = "SELECT COUNT(*) AS total_count FROM visitors";
            $stmt_total = $pdo->query($sql_total);
            $row_total = $stmt_total->fetch(PDO::FETCH_ASSOC);

            // Extract the count of online users
            $total_count = $row_total['total_count'];
        
        } catch (PDOException $e) {
            //Handle Database errors
            echo "Error: " .$e->getMessage();
        }

        
    ?>
    
    <div class="col-xl-4 col-lg-6">
        <div class="card mb-3">
            <div class="card-body">
            <div class="d-flex fw-bold small mb-3">
                <span class="flex-grow-1">TOTAL VISITORS</span>                           
            </div>
    
            <div class="row align-items-center mb-2">
                <div class="col-7">
                    <h3 class="mb-0"><?= $offline_count; ?></h3>
                </div>
                <div class="col-5">
                    <div class="mt-n2" data-render="apexchart" data-type="bar" data-title="Visitors" data-height="30"></div>
                </div>
            </div>                        
            </div>
            <div class="card-arrow">
            <div class="card-arrow-top-left"></div>
            <div class="card-arrow-top-right"></div>
            <div class="card-arrow-bottom-left"></div>
            <div class="card-arrow-bottom-right"></div>
            </div>
        </div>
    </div>
    <div class="col-xl-4 col-lg-6">
        <div class="card mb-3">
            <div class="card-body">
            <div class="d-flex fw-bold small mb-3">
                <span class="flex-grow-1">VICTIMS ONLINE</span> 
            </div>
            <div class="row align-items-center mb-2">
                <div class="col-7">
                <h3 class="mb-0"><?= $online_count; ?></h3>
                </div>
                <div class="col-5">
                    <div class="mt-n2" data-render="apexchart" data-type="line" data-title="Visitors" data-height="30"></div>
                </div>
            </div>                        
            </div>
            <div class="card-arrow">
            <div class="card-arrow-top-left"></div>
            <div class="card-arrow-top-right"></div>
            <div class="card-arrow-bottom-left"></div>
            <div class="card-arrow-bottom-right"></div>
            </div>
        </div>
    </div>
    <div class="col-xl-4 col-lg-6">
        <div class="card mb-3">
            <div class="card-body">
            <div class="d-flex fw-bold small mb-3">
                <span class="flex-grow-1">TOTAL VICTIMS</span>                           
            </div>
            <div class="row align-items-center mb-2">
                <div class="col-7">
                <h3 class="mb-0"><?= $total_count; ?></h3>
                </div>
                <div class="col-5">
                    <div class="mt-n3 mb-n2" data-render="apexchart" data-type="pie" data-title="Visitors" data-height="45"></div>
                </div>
            </div>                        
            </div>
            <div class="card-arrow">
            <div class="card-arrow-top-left"></div>
            <div class="card-arrow-top-right"></div>
            <div class="card-arrow-bottom-left"></div>
            <div class="card-arrow-bottom-right"></div>
            </div>
        </div>
    </div>