Spaces:
Sleeping
Sleeping
| // Include database connection and authentication | |
| require_once 'includes/db_connect.php'; | |
| require_once 'includes/domain_utils.php'; | |
| require_once 'includes/auth_check.php'; | |
| // Ensure only faculty can access this page | |
| requireFaculty(); | |
| // Initialize variables | |
| $error = ''; | |
| $domainNumber = isset($_GET['domain']) ? intval($_GET['domain']) : 0; | |
| $projectId = isset($_GET['id']) ? intval($_GET['id']) : 0; | |
| $confirm = isset($_GET['confirm']) && $_GET['confirm'] === 'yes'; | |
| $projectName = ''; | |
| $domainTable = "domain_" . $domainNumber; | |
| // Get domain descriptions | |
| $domainDescriptions = getDomainDescriptions($conn); | |
| $domainDescription = isset($domainDescriptions[$domainNumber]) ? $domainDescriptions[$domainNumber] : "Domain $domainNumber"; | |
| // Check if the domain and project ID are provided | |
| if ($domainNumber <= 0 || $projectId <= 0) { | |
| $error = "Invalid domain or project ID."; | |
| } else { | |
| // Check if the domain table exists | |
| $tableCheckQuery = "SHOW TABLES LIKE '$domainTable'"; | |
| $tableExists = $conn->query($tableCheckQuery)->num_rows > 0; | |
| if (!$tableExists) { | |
| $error = "Domain table does not exist."; | |
| } else { | |
| // Get project name field for this domain | |
| $projectNameField = getProjectNameField($conn, $domainTable); | |
| // Get the project details | |
| $projectQuery = "SELECT `$projectNameField` FROM $domainTable WHERE Project_ID = ? LIMIT 1"; | |
| $stmt = $conn->prepare($projectQuery); | |
| if ($stmt) { | |
| $stmt->bind_param('i', $projectId); | |
| $stmt->execute(); | |
| $result = $stmt->get_result(); | |
| if ($result && $result->num_rows > 0) { | |
| $project = $result->fetch_assoc(); | |
| $projectName = $project[$projectNameField]; | |
| // If confirmed, delete the project | |
| if ($confirm) { | |
| $deleteQuery = "DELETE FROM $domainTable WHERE Project_ID = ?"; | |
| $deleteStmt = $conn->prepare($deleteQuery); | |
| if ($deleteStmt) { | |
| $deleteStmt->bind_param('i', $projectId); | |
| if ($deleteStmt->execute()) { | |
| // Redirect to project management page with success message | |
| header("Location: project_manage.php?deleted=1&project=" . urlencode($projectName)); | |
| exit; | |
| } else { | |
| $error = "Error deleting project: " . $deleteStmt->error; | |
| } | |
| $deleteStmt->close(); | |
| } else { | |
| $error = "Error preparing delete query: " . $conn->error; | |
| } | |
| } | |
| } else { | |
| $error = "Project not found."; | |
| } | |
| $stmt->close(); | |
| } else { | |
| $error = "Error preparing query: " . $conn->error; | |
| } | |
| } | |
| } | |
| // Include header | |
| include 'includes/header.php'; | |
| <div class="row mb-4"> | |
| <div class="col-md-12"> | |
| <nav aria-label="breadcrumb"> | |
| <ol class="breadcrumb"> | |
| <li class="breadcrumb-item"><a href="index.php">Home</a></li> | |
| <li class="breadcrumb-item"><a href="project_manage.php">Manage Projects</a></li> | |
| <li class="breadcrumb-item active">Delete Project</li> | |
| </ol> | |
| </nav> | |
| <h2><i class="fas fa-trash-alt me-2"></i> Delete Project</h2> | |
| </div> | |
| </div> | |
| <?php if (!empty($error)): ?> | |
| <div class="alert alert-danger"> | |
| <i class="fas fa-exclamation-circle me-2"></i> <?php echo $error; ?> | |
| <div class="mt-3"> | |
| <a href="project_manage.php" class="btn btn-primary"> | |
| <i class="fas fa-arrow-left me-1"></i> Back to Project Management | |
| </a> | |
| </div> | |
| </div> | |
| <?php elseif (!$confirm): ?> | |
| <div class="row"> | |
| <div class="col-md-8 mx-auto"> | |
| <div class="card shadow-sm border-danger"> | |
| <div class="card-header bg-danger text-white"> | |
| <h5 class="mb-0"><i class="fas fa-exclamation-triangle me-2"></i> Confirm Deletion</h5> | |
| </div> | |
| <div class="card-body"> | |
| <p class="alert alert-warning"> | |
| <i class="fas fa-exclamation-circle me-2"></i> <strong>Warning:</strong> You are about to delete the following project: | |
| </p> | |
| <div class="card mb-4"> | |
| <div class="card-body"> | |
| <h5 class="card-title"><?php echo htmlspecialchars($projectName); ?></h5> | |
| <p class="card-text"> | |
| <strong>Domain:</strong> <?php echo htmlspecialchars("Domain $domainNumber: $domainDescription"); ?> | |
| </p> | |
| <p class="card-text"> | |
| <strong>Project ID:</strong> <?php echo $projectId; ?> | |
| </p> | |
| </div> | |
| </div> | |
| <p class="text-danger"><strong>This action cannot be undone.</strong> Are you sure you want to delete this project?</p> | |
| <div class="d-flex justify-content-between mt-4"> | |
| <a href="project_manage.php" class="btn btn-secondary"> | |
| <i class="fas fa-times me-1"></i> Cancel | |
| </a> | |
| <a href="project_delete.php?domain=<?php echo urlencode($domainNumber); ?>&id=<?php echo urlencode($projectId); ?>&confirm=yes" class="btn btn-danger"> | |
| <i class="fas fa-trash-alt me-1"></i> Yes, Delete Project | |
| </a> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| <?php endif; ?> | |
| <?php | |
| // Include footer | |
| include 'includes/footer.php'; | |
| // Close connection | |
| $conn->close(); | |
| ?> |