<?php
require_once __DIR__ . '/../config/db.php';
require_once __DIR__ . '/../auth/protect_admin.php';

$id = isset($_GET['id']) ? (int)$_GET['id'] : 0;
if ($id) {
    // ambil UID dulu
    $stmt = $pdo->prepare("SELECT uid FROM siswa WHERE id = :id LIMIT 1");
    $stmt->execute([':id'=>$id]);
    $uid = $stmt->fetchColumn();
    if ($uid) {
        // hapus dari siswa
        $pdo->prepare("UPDATE siswa SET uid = NULL WHERE id = :id")->execute([':id'=>$id]);
        // kembalikan ke pool
        $pdo->prepare("INSERT INTO uid_pool (uid) VALUES (:uid) ON DUPLICATE KEY UPDATE first_seen=first_seen")
            ->execute([':uid'=>$uid]);
    }
}
header('Location: /presensi_v1/pages/manage_uid.php');
exit;
