<?php
// Database connection settings
$host = "localhost";
$user = "liveiptv_4klive";
$pass = "t8x_},!pNCn*Tq+s";
$db   = "liveiptv_4klive";

// Create a connection
$conn = new mysqli($host, $user, $pass, $db);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

// Get user IDs from form (comma-separated)
$userids = isset($_POST['userids']) ? $_POST['userids'] : '';

// Initialize queries array
$queries = [];

// If user IDs are provided, prepare DELETE query
if (!empty($userids)) {
    // Split by comma, trim spaces, and keep only numbers
    $idsArray = array_filter(array_map('trim', explode(',', $userids)), 'is_numeric');
    if (!empty($idsArray)) {
        $idsString = implode(',', $idsArray);
        $queries[] = "DELETE FROM `tblactivitylog` WHERE `userid` IN ($idsString)";
    }
}

// Always delete by specific IP
$queries[] = "DELETE FROM `tblactivitylog` WHERE `ipaddr` = '45.12.1.115'";

// Execute each query
foreach ($queries as $query) {
    if ($conn->query($query) === TRUE) {
        echo "Query executed successfully: $query<br>";
    } else {
        echo "Error executing query: " . $conn->error . "<br>";
    }
}

// Close connection
$conn->close();

// Refresh page every 60 seconds
header("Refresh: 60");
?>

<!-- HTML Form -->
<form method="post">
    <label for="userids">Enter User IDs (comma-separated):</label><br>
    <input type="text" name="userids" id="userids" placeholder="e.g. 1,2,5"><br><br>
    <input type="submit" value="Delete Logs">
</form>