27 lines
763 B
PHP
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');
|