46 lines
1.4 KiB
PHP
46 lines
1.4 KiB
PHP
<?php
|
|
require_once 'session.php';
|
|
check_admin();
|
|
require_once 'db/config.php';
|
|
|
|
$id = $_POST['id'] ?? null;
|
|
$property_id = $_POST['property_id'] ?? null;
|
|
|
|
if (!$id) {
|
|
header('Location: index.php');
|
|
exit;
|
|
}
|
|
|
|
try {
|
|
$db = db();
|
|
$stmt = $db->prepare("SELECT * FROM files WHERE id = :id");
|
|
$stmt->bindParam(':id', $id, PDO::PARAM_INT);
|
|
$stmt->execute();
|
|
$file = $stmt->fetch(PDO::FETCH_ASSOC);
|
|
|
|
if ($file) {
|
|
// Delete file from server
|
|
if (file_exists($file['file_path'])) {
|
|
unlink($file['file_path']);
|
|
}
|
|
|
|
// Delete record from database
|
|
$stmt = $db->prepare("DELETE FROM files WHERE id = :id");
|
|
$stmt->bindParam(':id', $id, PDO::PARAM_INT);
|
|
$stmt->execute();
|
|
}
|
|
|
|
if ($property_id) {
|
|
header('Location: edit_property.php?id=' . $property_id . '&message=File deleted successfully');
|
|
} elseif ($tenant_id = $_GET['tenant_id'] ?? null) {
|
|
header('Location: edit_tenant.php?id=' . $tenant_id . '&message=File deleted successfully');
|
|
} elseif ($payment_id = $_GET['payment_id'] ?? null) {
|
|
header('Location: edit_payment.php?id=' . $payment_id . '&message=File deleted successfully');
|
|
} else {
|
|
header('Location: index.php?page=properties&message=File deleted successfully');
|
|
}
|
|
exit;
|
|
} catch (PDOException $e) {
|
|
die("DB ERROR: " . $e->getMessage());
|
|
}
|
|
?>
|