39331-vm/archive_delete.php
Flatlogic Bot 522a55296c arsip_demo
2026-03-26 11:04:24 +00:00

27 lines
763 B
PHP

<?php
declare(strict_types=1);
require_once __DIR__ . '/archive_bootstrap.php';
ensure_archive_table();
$user = require_login();
verify_csrf_or_fail();
$id = (int) ($_POST['id'] ?? 0);
$record = fetch_record_by_id($id);
if (!$record || !can_delete_record($user, $record)) {
flash('error', 'Arsip tidak dapat dihapus oleh akun ini.');
header('Location: index.php');
exit;
}
$stmt = db()->prepare('DELETE FROM archive_records WHERE id = :id LIMIT 1');
$stmt->bindValue(':id', $id, PDO::PARAM_INT);
$stmt->execute();
if (!empty($record['attachment_path']) && is_file(__DIR__ . '/' . $record['attachment_path'])) {
@unlink(__DIR__ . '/' . $record['attachment_path']);
}
flash('success', 'Arsip berhasil dihapus.');
header('Location: index.php');