<?php
// delete_foto.php — Hapus foto kegiatan
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);

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