<?php
session_start();
require_once __DIR__."/config/config.php";

$id = (int)($_GET['id'] ?? 0);
$npsn = $_SESSION['npsn'] ?? '';

$q = mysqli_query($conn,"
    SELECT * FROM upload_laporan
    WHERE id_laporan=$id AND npsn='$npsn' AND status_verifikasi='disetujui'
");
$data = mysqli_fetch_assoc($q);
if(!$data) die("Akses ditolak");

if(isset($_POST['kirim'])){
    $alasan = mysqli_real_escape_string($conn, $_POST['alasan']);

    mysqli_query($conn,"
        UPDATE upload_laporan SET
            status_verifikasi='minta_buka_kunci',
            alasan_buka_kunci='$alasan'
        WHERE id_laporan=$id
    ");

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

<!DOCTYPE html>
<html>
<head>
<title>Buka Kunci Laporan</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body class="bg-light">

<div class="container mt-4">
<div class="card shadow-sm">
<div class="card-header bg-warning">
    <b>🔓 Permohonan Buka Kunci Laporan</b>
</div>
<div class="card-body">

<form method="post">
<div class="mb-3">
    <label class="form-label fw-bold">Alasan Buka Kunci</label>
    <textarea name="alasan" class="form-control" rows="4" required></textarea>
</div>

<div class="d-flex gap-2">
    <button type="submit" name="kirim" class="btn btn-success">📨 Kirim</button>
    <a href="list_laporan.php" class="btn btn-secondary">❌ Batal</a>
</div>
</form>

</div>
</div>
</div>

</body>
</html>
