<?php
// delete_file.php — Hapus file laporan
require_once '../../config/config.php';
require_once '../../config/database.php';
require_once '../../core/helpers.php';
requireRole('admin');

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

$file = Database::fetchOne("SELECT * FROM file_laporan WHERE id=? AND kegiatan_id=?", [$id, $keg]);
if ($file) {
    deleteFile('dokumen', $file['nama_file']);
    Database::execute("DELETE FROM file_laporan WHERE id=?", [$id]);
    setFlash('success','File berhasil dihapus.');
}
redirect(BASE_URL.'/modules/kegiatan/form.php?id='.$keg);
