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

$uid = $_POST['uid'] ?? '';
$siswa_id = isset($_POST['siswa_id']) ? (int)$_POST['siswa_id'] : 0;
if ($uid && $siswa_id) {
    // set uid to siswa
    $pdo->prepare("UPDATE siswa SET uid=:uid WHERE id=:id")->execute([':uid'=>$uid, ':id'=>$siswa_id]);
    // remove from pool
    $pdo->prepare("DELETE FROM uid_pool WHERE uid = :uid")->execute([':uid'=>$uid]);
}
header('Location: /presensi_v1/pages/manage_uid.php');
exit;
