<?php
if (!isset($_GET['ids'])) {
    die("Nenhum ID recebido.");
}

$db1 = new SQLite3('a/.eggziedb.db');
$ids = explode(",", $_GET['ids']);

foreach ($ids as $id) {
    $id = intval($id);
    $result = $db1->query("SELECT usuario FROM sub_revenda WHERE id = $id");
    $row = $result->fetchArray();
    if (!$row) continue;

    $user = $row['usuario'];
    $db1->exec("DELETE FROM sub_revenda WHERE id = $id");
    $db1->exec("UPDATE ibo SET seller = 'ADM' WHERE seller = '$user'");

    // Remove arquivos relacionados
    @unlink("a/rtx/Setting_$user.json");
    @unlink("a/rtx/logo_filenames_$user.json");
    @unlink("a/rtx/image_filenames_$user.json");
    @unlink("a/note_$user.json");
    @unlink("api/theme_$user.json");

    $db2 = new SQLite3("api/.adb.db");
    $db2->exec("DELETE FROM ads WHERE owner = '$user'");
    $db3 = new SQLite3("api/intro.db");
    $db3->exec("DELETE FROM intro WHERE owner = '$user'");
}

header("Location: sub_revenda.php");
exit;
?>
