Mini Kabibi Habibi
Current Path : C:/xampp/htdocs/cid/system/ |
|
Current File : C:/xampp/htdocs/cid/system/delete_submitted_mqcais_report.php |
<?php
session_start();
@include 'include/config.php';
if (!isset($_SESSION['username_school'])) {
header('Location: login.php');
exit();
}
$username = $_SESSION['username_school'];
if (!isset($_GET['id']) || !is_numeric($_GET['id'])) {
die("Invalid request.");
}
$reportId = (int) $_GET['id'];
// First, verify that the report exists and belongs to the user
$stmt = $conn->prepare("SELECT file_path FROM submitted_mqcais_reports WHERE id = ? AND username = ?");
if (!$stmt) {
die("Prepare failed: " . $conn->error);
}
$stmt->bind_param("is", $reportId, $username);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows === 0) {
die("Report not found or you do not have permission to delete it.");
}
$row = $result->fetch_assoc();
$filePath = $row['file_path'];
// Optional: Delete the file from the server
if (!empty($filePath) && file_exists($filePath)) {
unlink($filePath);
}
// Now delete the report record from the database
$deleteStmt = $conn->prepare("DELETE FROM submitted_mqcais_reports WHERE id = ? AND username = ?");
if (!$deleteStmt) {
die("Prepare failed: " . $conn->error);
}
$deleteStmt->bind_param("is", $reportId, $username);
$deleteStmt->execute();
if ($deleteStmt->affected_rows > 0) {
header("Location: submitted_mqcais_reports.php?msg=deleted");
exit();
} else {
die("Failed to delete the report.");
}
?>