version2.0
This commit is contained in:
parent
93d9b1d58f
commit
9d4612b106
160
admin/allocations.php
Normal file
160
admin/allocations.php
Normal file
@ -0,0 +1,160 @@
|
||||
<?php
|
||||
session_start();
|
||||
require_once '../db/config.php';
|
||||
|
||||
// Admin role check
|
||||
if (!isset($_SESSION['role']) || $_SESSION['role'] !== 'Admin') {
|
||||
header('Location: ../auth/login.php');
|
||||
exit();
|
||||
}
|
||||
|
||||
$pdo = db();
|
||||
|
||||
// Handle Allocation
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['allocate'])) {
|
||||
$student_id = $_POST['student_id'];
|
||||
$room_id = $_POST['room_id'];
|
||||
|
||||
// Check if room has capacity
|
||||
$stmt = $pdo->prepare("SELECT capacity, occupied FROM Rooms WHERE id = ?");
|
||||
$stmt->execute([$room_id]);
|
||||
$room = $stmt->fetch();
|
||||
|
||||
if ($room && $room['occupied'] < $room['capacity']) {
|
||||
// Allocate student
|
||||
$stmt = $pdo->prepare("INSERT INTO Allocations (student_id, room_id, allocation_date, status) VALUES (?, ?, CURDATE(), 'Allocated')");
|
||||
$stmt->execute([$student_id, $room_id]);
|
||||
|
||||
// Update room occupancy
|
||||
$stmt = $pdo->prepare("UPDATE Rooms SET occupied = occupied + 1 WHERE id = ?");
|
||||
$stmt->execute([$room_id]);
|
||||
}
|
||||
header('Location: allocations.php');
|
||||
exit();
|
||||
}
|
||||
|
||||
// Handle Deallocation
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['deallocate'])) {
|
||||
$allocation_id = $_POST['allocation_id'];
|
||||
|
||||
// Get allocation details
|
||||
$stmt = $pdo->prepare("SELECT room_id FROM Allocations WHERE id = ?");
|
||||
$stmt->execute([$allocation_id]);
|
||||
$allocation = $stmt->fetch();
|
||||
|
||||
if ($allocation) {
|
||||
// Remove allocation
|
||||
$stmt = $pdo->prepare("DELETE FROM Allocations WHERE id = ?");
|
||||
$stmt->execute([$allocation_id]);
|
||||
|
||||
// Update room occupancy
|
||||
$stmt = $pdo->prepare("UPDATE Rooms SET occupied = occupied - 1 WHERE id = ?");
|
||||
$stmt->execute([$allocation['room_id']]);
|
||||
}
|
||||
header('Location: allocations.php');
|
||||
exit();
|
||||
}
|
||||
|
||||
|
||||
// Fetch unallocated students
|
||||
$unallocated_students_stmt = $pdo->query("SELECT u.id, u.name FROM Users u LEFT JOIN Allocations a ON u.id = a.student_id WHERE a.id IS NULL AND u.role = 'Student'");
|
||||
$unallocated_students = $unallocated_students_stmt->fetchAll();
|
||||
|
||||
// Fetch available rooms
|
||||
$available_rooms_stmt = $pdo->query("SELECT id, room_no, block FROM Rooms WHERE occupied < capacity");
|
||||
$available_rooms = $available_rooms_stmt->fetchAll();
|
||||
|
||||
// Fetch current allocations
|
||||
$allocations_stmt = $pdo->query("SELECT a.id, u.name as student_name, r.room_no, r.block, a.allocation_date FROM Allocations a JOIN Users u ON a.student_id = u.id JOIN Rooms r ON a.room_id = r.id ORDER BY a.allocation_date DESC");
|
||||
$allocations = $allocations_stmt->fetchAll();
|
||||
|
||||
$pageTitle = "Room Allocations";
|
||||
include '../includes/header.php';
|
||||
?>
|
||||
|
||||
<div class="container-fluid">
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h4 class="card-title">Manual Room Allocation</h4>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<form action="allocations.php" method="POST">
|
||||
<div class="row">
|
||||
<div class="col-md-5">
|
||||
<div class="form-group">
|
||||
<label>Unallocated Student</label>
|
||||
<select name="student_id" class="form-control" required>
|
||||
<option value="">Select Student</option>
|
||||
<?php foreach ($unallocated_students as $student): ?>
|
||||
<option value="<?php echo $student['id']; ?>"><?php echo htmlspecialchars($student['name']); ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-5">
|
||||
<div class="form-group">
|
||||
<label>Available Room</label>
|
||||
<select name="room_id" class="form-control" required>
|
||||
<option value="">Select Room</option>
|
||||
<?php foreach ($available_rooms as $room): ?>
|
||||
<option value="<?php echo $room['id']; ?>"><?php echo htmlspecialchars($room['block'] . ' - ' . $room['room_no']); ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-2">
|
||||
<div class="form-group">
|
||||
<label> </label><br>
|
||||
<button type="submit" name="allocate" class="btn btn-primary btn-fill">Allocate Room</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row mt-4">
|
||||
<div class="col-md-12">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h4 class="card-title">Current Room Allocations</h4>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="table-responsive">
|
||||
<table class="table table-hover table-striped">
|
||||
<thead>
|
||||
<th>Student Name</th>
|
||||
<th>Room No</th>
|
||||
<th>Block</th>
|
||||
<th>Allocation Date</th>
|
||||
<th>Action</th>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($allocations as $allocation): ?>
|
||||
<tr>
|
||||
<td><?php echo htmlspecialchars($allocation['student_name']); ?></td>
|
||||
<td><?php echo htmlspecialchars($allocation['room_no']); ?></td>
|
||||
<td><?php echo htmlspecialchars($allocation['block']); ?></td>
|
||||
<td><?php echo htmlspecialchars($allocation['allocation_date']); ?></td>
|
||||
<td>
|
||||
<form action="allocations.php" method="POST" onsubmit="return confirm('Are you sure you want to deallocate this student?');">
|
||||
<input type="hidden" name="allocation_id" value="<?php echo $allocation['id']; ?>">
|
||||
<button type="submit" name="deallocate" class="btn btn-danger btn-sm">Deallocate</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php include '../includes/footer.php'; ?>
|
||||
54
admin/dashboard.php
Normal file
54
admin/dashboard.php
Normal file
@ -0,0 +1,54 @@
|
||||
<?php
|
||||
require_once '../includes/header.php';
|
||||
|
||||
if (!isset($_SESSION['id']) || $_SESSION['role'] !== 'Admin') {
|
||||
header('Location: ../auth/login.php');
|
||||
exit;
|
||||
}
|
||||
?>
|
||||
|
||||
<div class="container mt-5">
|
||||
<h1 class="text-center mb-4">Admin Dashboard</h1>
|
||||
<p class="text-center">Welcome, <?php echo htmlspecialchars($_SESSION['name']); ?>!</p>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-4 mb-4">
|
||||
<div class="card text-center">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">Manage Rooms</h5>
|
||||
<p class="card-text">Add, edit, and delete hostel rooms.</p>
|
||||
<a href="rooms.php" class="btn btn-primary">Go to Rooms</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-4 mb-4">
|
||||
<div class="card text-center">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">Manage Students</h5>
|
||||
<p class="card-text">View and manage student records.</p>
|
||||
<a href="students.php" class="btn btn-primary">Go to Students</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-4 mb-4">
|
||||
<div class="card text-center">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">Manage Allocations</h5>
|
||||
<p class="card-text">Allocate rooms to students.</p>
|
||||
<a href="allocations.php" class="btn btn-primary">Go to Allocations</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-4 mb-4">
|
||||
<div class="card text-center">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">Room Requests</h5>
|
||||
<p class="card-text">View and manage student room requests.</p>
|
||||
<a href="requests.php" class="btn btn-primary">Go to Requests</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php require_once '../includes/footer.php'; ?>
|
||||
80
admin/edit_room.php
Normal file
80
admin/edit_room.php
Normal file
@ -0,0 +1,80 @@
|
||||
<?php
|
||||
session_start();
|
||||
include_once '../includes/header.php';
|
||||
include_once '../db/config.php';
|
||||
|
||||
// Check if user is logged in and is an admin
|
||||
if (!isset($_SESSION['user_id']) || $_SESSION['role'] !== 'Admin') {
|
||||
header("Location: ../auth/login.php");
|
||||
exit();
|
||||
}
|
||||
|
||||
$db = db();
|
||||
$id = $_GET['id'] ?? null;
|
||||
|
||||
if (!$id) {
|
||||
header("Location: rooms.php");
|
||||
exit();
|
||||
}
|
||||
|
||||
// Handle Update Room
|
||||
if (isset($_POST['update_room'])) {
|
||||
$room_no = $_POST['room_no'];
|
||||
$block = $_POST['block'];
|
||||
$capacity = $_POST['capacity'];
|
||||
$type = $_POST['type'];
|
||||
|
||||
$stmt = $db->prepare("UPDATE Rooms SET room_no = ?, block = ?, capacity = ?, type = ? WHERE id = ?");
|
||||
$stmt->execute([$room_no, $block, $capacity, $type, $id]);
|
||||
|
||||
header("Location: rooms.php");
|
||||
exit();
|
||||
}
|
||||
|
||||
$stmt = $db->prepare("SELECT * FROM Rooms WHERE id = ?");
|
||||
$stmt->execute([$id]);
|
||||
$room = $stmt->fetch();
|
||||
|
||||
if (!$room) {
|
||||
header("Location: rooms.php");
|
||||
exit();
|
||||
}
|
||||
?>
|
||||
|
||||
<div class="container mt-5">
|
||||
<h2 class="text-center mb-4">Edit Room</h2>
|
||||
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<form action="edit_room.php?id=<?php echo $id; ?>" method="POST">
|
||||
<div class="row">
|
||||
<div class="col-md-3 mb-3">
|
||||
<label for="room_no" class="form-label">Room Number</label>
|
||||
<input type="text" class="form-control" id="room_no" name="room_no" value="<?php echo htmlspecialchars($room['room_no']); ?>" required>
|
||||
</div>
|
||||
<div class="col-md-3 mb-3">
|
||||
<label for="block" class="form-label">Block</label>
|
||||
<input type="text" class="form-control" id="block" name="block" value="<?php echo htmlspecialchars($room['block']); ?>" required>
|
||||
</div>
|
||||
<div class="col-md-2 mb-3">
|
||||
<label for="capacity" class="form-label">Capacity</label>
|
||||
<input type="number" class="form-control" id="capacity" name="capacity" value="<?php echo htmlspecialchars($room['capacity']); ?>" required>
|
||||
</div>
|
||||
<div class="col-md-2 mb-3">
|
||||
<label for="type" class="form-label">Room Type</label>
|
||||
<select class="form-select" id="type" name="type">
|
||||
<option value="Single" <?php echo ($room['type'] == 'Single') ? 'selected' : ''; ?>>Single</option>
|
||||
<option value="Double" <?php echo ($room['type'] == 'Double') ? 'selected' : ''; ?>>Double</option>
|
||||
<option value="Triple" <?php echo ($room['type'] == 'Triple') ? 'selected' : ''; ?>>Triple</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-md-2 d-flex align-items-end">
|
||||
<button type="submit" name="update_room" class="btn btn-primary w-100">Update Room</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php include_once '../includes/footer.php'; ?>
|
||||
89
admin/edit_student.php
Normal file
89
admin/edit_student.php
Normal file
@ -0,0 +1,89 @@
|
||||
<?php
|
||||
session_start();
|
||||
include_once '../db/config.php';
|
||||
|
||||
// Ensure the user is an admin
|
||||
if (!isset($_SESSION['user_id']) || $_SESSION['role'] !== 'Admin') {
|
||||
header("Location: ../auth/login.php");
|
||||
exit();
|
||||
}
|
||||
|
||||
$pdo = db();
|
||||
$student_id = $_GET['id'] ?? null;
|
||||
|
||||
if (!$student_id) {
|
||||
header("Location: students.php");
|
||||
exit();
|
||||
}
|
||||
|
||||
// Handle Form Submission
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$name = $_POST['name'];
|
||||
$email = $_POST['email'];
|
||||
$gender = $_POST['gender'];
|
||||
$year = $_POST['year'];
|
||||
$department = $_POST['department'];
|
||||
|
||||
$stmt = $pdo->prepare("UPDATE Users SET name = ?, email = ?, gender = ?, year = ?, department = ? WHERE id = ?");
|
||||
$stmt->execute([$name, $email, $gender, $year, $department, $student_id]);
|
||||
|
||||
header("Location: students.php?success=1");
|
||||
exit();
|
||||
}
|
||||
|
||||
// Fetch student data
|
||||
$stmt = $pdo->prepare("SELECT name, email, gender, year, department FROM Users WHERE id = ? AND role = 'Student'");
|
||||
$stmt->execute([$student_id]);
|
||||
$student = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
if (!$student) {
|
||||
header("Location: students.php");
|
||||
exit();
|
||||
}
|
||||
|
||||
include_once '../includes/header.php';
|
||||
?>
|
||||
|
||||
<div class="container mt-5">
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-md-8">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h4 class="mb-0">Edit Student Details</h4>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<form action="edit_student.php?id=<?php echo $student_id; ?>" method="POST">
|
||||
<div class="mb-3">
|
||||
<label for="name" class="form-label">Full Name</label>
|
||||
<input type="text" class="form-control" id="name" name="name" value="<?php echo htmlspecialchars($student['name']); ?>" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="email" class="form-label">Email Address</label>
|
||||
<input type="email" class="form-control" id="email" name="email" value="<?php echo htmlspecialchars($student['email']); ?>" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="gender" class="form-label">Gender</label>
|
||||
<select class="form-select" id="gender" name="gender" required>
|
||||
<option value="Male" <?php echo ($student['gender'] == 'Male') ? 'selected' : ''; ?>>Male</option>
|
||||
<option value="Female" <?php echo ($student['gender'] == 'Female') ? 'selected' : ''; ?>>Female</option>
|
||||
<option value="Other" <?php echo ($student['gender'] == 'Other') ? 'selected' : ''; ?>>Other</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="year" class="form-label">Year</label>
|
||||
<input type="number" class="form-control" id="year" name="year" value="<?php echo htmlspecialchars($student['year']); ?>" min="1" max="5">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="department" class="form-label">Department</label>
|
||||
<input type="text" class="form-control" id="department" name="department" value="<?php echo htmlspecialchars($student['department']); ?>">
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary">Update Student</button>
|
||||
<a href="students.php" class="btn btn-secondary">Cancel</a>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php include_once '../includes/footer.php'; ?>
|
||||
91
admin/requests.php
Normal file
91
admin/requests.php
Normal file
@ -0,0 +1,91 @@
|
||||
<?php
|
||||
require_once '../includes/header.php';
|
||||
require_once '../db/config.php';
|
||||
|
||||
if (!isset($_SESSION['id']) || $_SESSION['role'] !== 'Admin') {
|
||||
header('Location: ../auth/login.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
$pdo = db();
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$request_id = $_POST['request_id'];
|
||||
$student_id = $_POST['student_id'];
|
||||
$room_id = $_POST['room_id'];
|
||||
|
||||
if (isset($_POST['approve'])) {
|
||||
// Start transaction
|
||||
$pdo->beginTransaction();
|
||||
try {
|
||||
// 1. Add to Allocations
|
||||
$stmt = $pdo->prepare("INSERT INTO Allocations (student_id, room_id) VALUES (?, ?)");
|
||||
$stmt->execute([$student_id, $room_id]);
|
||||
|
||||
// 2. Update RoomRequest status
|
||||
$stmt = $pdo->prepare("UPDATE RoomRequests SET status = 'approved' WHERE request_id = ?");
|
||||
$stmt->execute([$request_id]);
|
||||
|
||||
// 3. Reject other pending requests for the same room
|
||||
$stmt = $pdo->prepare("UPDATE RoomRequests SET status = 'rejected' WHERE room_id = ? AND status = 'pending'");
|
||||
$stmt->execute([$room_id]);
|
||||
|
||||
// 4. Reject other pending requests from the same student
|
||||
$stmt = $pdo->prepare("UPDATE RoomRequests SET status = 'rejected' WHERE student_id = ? AND status = 'pending'");
|
||||
$stmt->execute([$student_id]);
|
||||
|
||||
$pdo->commit();
|
||||
} catch (Exception $e) {
|
||||
$pdo->rollBack();
|
||||
die("Error: " . $e->getMessage());
|
||||
}
|
||||
} elseif (isset($_POST['reject'])) {
|
||||
$stmt = $pdo->prepare("UPDATE RoomRequests SET status = 'rejected' WHERE request_id = ?");
|
||||
$stmt->execute([$request_id]);
|
||||
}
|
||||
header('Location: requests.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
$stmt = $pdo->query("SELECT rr.*, u.name as student_name, r.room_number FROM RoomRequests rr JOIN Users u ON rr.student_id = u.id JOIN Rooms r ON rr.room_id = r.id ORDER BY rr.request_date DESC");
|
||||
$requests = $stmt->fetchAll();
|
||||
?>
|
||||
|
||||
<div class="container mt-5">
|
||||
<h2>Room Requests</h2>
|
||||
<table class="table table-bordered">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Student</th>
|
||||
<th>Room</th>
|
||||
<th>Status</th>
|
||||
<th>Date</th>
|
||||
<th>Action</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($requests as $request): ?>
|
||||
<tr>
|
||||
<td><?php echo htmlspecialchars($request['student_name']); ?></td>
|
||||
<td><?php echo htmlspecialchars($request['room_number']); ?></td>
|
||||
<td><?php echo htmlspecialchars($request['status']); ?></td>
|
||||
<td><?php echo $request['request_date']; ?></td>
|
||||
<td>
|
||||
<?php if ($request['status'] === 'pending'): ?>
|
||||
<form method="POST" style="display: inline-block;">
|
||||
<input type="hidden" name="request_id" value="<?php echo $request['request_id']; ?>">
|
||||
<input type="hidden" name="student_id" value="<?php echo $request['student_id']; ?>">
|
||||
<input type="hidden" name="room_id" value="<?php echo $request['room_id']; ?>">
|
||||
<button type="submit" name="approve" class="btn btn-success btn-sm">Approve</button>
|
||||
<button type="submit" name="reject" class="btn btn-danger btn-sm">Reject</button>
|
||||
</form>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
<a href="dashboard.php" class="btn btn-secondary mt-3">Back to Dashboard</a>
|
||||
</div>
|
||||
|
||||
<?php require_once '../includes/footer.php'; ?>
|
||||
124
admin/rooms.php
Normal file
124
admin/rooms.php
Normal file
@ -0,0 +1,124 @@
|
||||
<?php
|
||||
session_start();
|
||||
include_once '../includes/header.php';
|
||||
include_once '../db/config.php';
|
||||
|
||||
// Check if user is logged in and is an admin
|
||||
if (!isset($_SESSION['user_id']) || $_SESSION['role'] !== 'Admin') {
|
||||
header("Location: ../auth/login.php");
|
||||
exit();
|
||||
}
|
||||
|
||||
$db = db();
|
||||
|
||||
// Handle Add Room
|
||||
if (isset($_POST['add_room'])) {
|
||||
$room_no = $_POST['room_no'];
|
||||
$block = $_POST['block'];
|
||||
$capacity = $_POST['capacity'];
|
||||
$type = $_POST['type'];
|
||||
|
||||
$stmt = $db->prepare("INSERT INTO Rooms (room_no, block, capacity, type) VALUES (?, ?, ?, ?)");
|
||||
$stmt->execute([$room_no, $block, $capacity, $type]);
|
||||
|
||||
header("Location: rooms.php");
|
||||
exit();
|
||||
}
|
||||
|
||||
// Handle Delete Room
|
||||
if (isset($_GET['delete_id'])) {
|
||||
$id = $_GET['delete_id'];
|
||||
$stmt = $db->prepare("DELETE FROM Rooms WHERE id = ?");
|
||||
$stmt->execute([$id]);
|
||||
|
||||
header("Location: rooms.php");
|
||||
exit();
|
||||
}
|
||||
|
||||
$rooms = $db->query("SELECT * FROM Rooms ORDER BY room_no ASC")->fetchAll();
|
||||
|
||||
?>
|
||||
|
||||
<div class="container mt-5">
|
||||
<h2 class="text-center mb-4">Room Management</h2>
|
||||
|
||||
<!-- Add Room Form -->
|
||||
<div class="card mb-4">
|
||||
<div class="card-header">
|
||||
Add New Room
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<form action="rooms.php" method="POST">
|
||||
<div class="row">
|
||||
<div class="col-md-3 mb-3">
|
||||
<label for="room_no" class="form-label">Room Number</label>
|
||||
<input type="text" class="form-control" id="room_no" name="room_no" required>
|
||||
</div>
|
||||
<div class="col-md-3 mb-3">
|
||||
<label for="block" class="form-label">Block</label>
|
||||
<input type="text" class="form-control" id="block" name="block" required>
|
||||
</div>
|
||||
<div class="col-md-2 mb-3">
|
||||
<label for="capacity" class="form-label">Capacity</label>
|
||||
<input type="number" class="form-control" id="capacity" name="capacity" required>
|
||||
</div>
|
||||
<div class="col-md-2 mb-3">
|
||||
<label for="type" class="form-label">Room Type</label>
|
||||
<select class="form-select" id="type" name="type">
|
||||
<option value="Single">Single</option>
|
||||
<option value="Double">Double</option>
|
||||
<option value="Triple">Triple</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-md-2 d-flex align-items-end">
|
||||
<button type="submit" name="add_room" class="btn btn-primary w-100">Add Room</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Room List -->
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
Existing Rooms
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<table class="table table-striped table-hover">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Room No.</th>
|
||||
<th>Block</th>
|
||||
<th>Capacity</th>
|
||||
<th>Occupied</th>
|
||||
<th>Type</th>
|
||||
<th>Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php if (empty($rooms)): ?>
|
||||
<tr>
|
||||
<td colspan="6" class="text-center">No rooms found.</td>
|
||||
</tr>
|
||||
<?php else: ?>
|
||||
<?php foreach ($rooms as $room): ?>
|
||||
<tr>
|
||||
<td><?php echo htmlspecialchars($room['room_no']); ?></td>
|
||||
<td><?php echo htmlspecialchars($room['block']); ?></td>
|
||||
<td><?php echo htmlspecialchars($room['capacity']); ?></td>
|
||||
<td><?php echo htmlspecialchars($room['occupied']); ?></td>
|
||||
<td><?php echo htmlspecialchars($room['type']); ?></td>
|
||||
<td>
|
||||
<a href="edit_room.php?id=<?php echo $room['id']; ?>" class="btn btn-sm btn-warning">Edit</a>
|
||||
<a href="rooms.php?delete_id=<?php echo $room['id']; ?>" class="btn btn-sm btn-danger" onclick="return confirm('Are you sure you want to delete this room?');">Delete</a>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
<?php endif; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php include_once '../includes/footer.php'; ?>
|
||||
85
admin/students.php
Normal file
85
admin/students.php
Normal file
@ -0,0 +1,85 @@
|
||||
<?php
|
||||
session_start();
|
||||
include_once '../db/config.php';
|
||||
|
||||
// Ensure the user is an admin
|
||||
if (!isset($_SESSION['user_id']) || $_SESSION['role'] !== 'Admin') {
|
||||
header("Location: ../auth/login.php");
|
||||
exit();
|
||||
}
|
||||
|
||||
$pdo = db();
|
||||
|
||||
// Handle Delete Request
|
||||
if (isset($_GET['delete_id'])) {
|
||||
$delete_id = $_GET['delete_id'];
|
||||
// Also delete related records if necessary (e.g., allocations, requests)
|
||||
$stmt = $pdo->prepare("DELETE FROM Allocations WHERE student_id = ?");
|
||||
$stmt->execute([$delete_id]);
|
||||
$stmt = $pdo->prepare("DELETE FROM Requests WHERE student_id = ?");
|
||||
$stmt->execute([$delete_id]);
|
||||
$stmt = $pdo->prepare("DELETE FROM Users WHERE id = ? AND role = 'Student'");
|
||||
$stmt->execute([$delete_id]);
|
||||
header("Location: students.php");
|
||||
exit();
|
||||
}
|
||||
|
||||
// Fetch all students
|
||||
$stmt = $pdo->query("SELECT id, name, email, gender, year, department FROM Users WHERE role = 'Student' ORDER BY name ASC");
|
||||
$students = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
include_once '../includes/header.php';
|
||||
?>
|
||||
|
||||
<div class="container mt-5">
|
||||
<h2 class="mb-4 text-center">Student Management</h2>
|
||||
|
||||
<?php if (isset($_GET['success'])): ?>
|
||||
<div class="alert alert-success">Student updated successfully!</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h5 class="mb-0">All Students</h5>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="table-responsive">
|
||||
<table class="table table-striped table-hover">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Email</th>
|
||||
<th>Gender</th>
|
||||
<th>Year</th>
|
||||
<th>Department</th>
|
||||
<th>Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php if (empty($students)): ?>
|
||||
<tr>
|
||||
<td colspan="6" class="text-center">No students found.</td>
|
||||
</tr>
|
||||
<?php else: ?>
|
||||
<?php foreach ($students as $student): ?>
|
||||
<tr>
|
||||
<td><?php echo htmlspecialchars($student['name']); ?></td>
|
||||
<td><?php echo htmlspecialchars($student['email']); ?></td>
|
||||
<td><?php echo htmlspecialchars($student['gender']); ?></td>
|
||||
<td><?php echo htmlspecialchars($student['year']); ?></td>
|
||||
<td><?php echo htmlspecialchars($student['department']); ?></td>
|
||||
<td>
|
||||
<a href="edit_student.php?id=<?php echo $student['id']; ?>" class="btn btn-sm btn-primary">Edit</a>
|
||||
<a href="students.php?delete_id=<?php echo $student['id']; ?>" class="btn btn-sm btn-danger" onclick="return confirm('Are you sure you want to delete this student?');">Delete</a>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
<?php endif; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php include_once '../includes/footer.php'; ?>
|
||||
47
assets/css/custom.css
Normal file
47
assets/css/custom.css
Normal file
@ -0,0 +1,47 @@
|
||||
html {
|
||||
scroll-behavior: smooth;
|
||||
scroll-padding-top: 70px;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
|
||||
background-color: #F8F9FA;
|
||||
}
|
||||
|
||||
.hero-section {
|
||||
background: linear-gradient(45deg, #0D6EFD, #0A58CA);
|
||||
padding: 100px 0;
|
||||
}
|
||||
|
||||
.navbar-brand {
|
||||
color: #0D6EFD !important;
|
||||
}
|
||||
|
||||
.nav-link {
|
||||
color: #6C757D;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.nav-link:hover, .nav-link.active {
|
||||
color: #0D6EFD;
|
||||
}
|
||||
|
||||
.card {
|
||||
border: none;
|
||||
border-radius: 0.5rem;
|
||||
box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075);
|
||||
transition: transform 0.2s ease-in-out;
|
||||
}
|
||||
|
||||
.card:hover {
|
||||
transform: translateY(-5px);
|
||||
}
|
||||
|
||||
.accordion-button:not(.collapsed) {
|
||||
color: #fff;
|
||||
background-color: #0D6EFD;
|
||||
}
|
||||
|
||||
.accordion-button:focus {
|
||||
box-shadow: none;
|
||||
}
|
||||
3
assets/js/main.js
Normal file
3
assets/js/main.js
Normal file
@ -0,0 +1,3 @@
|
||||
// This script can be used for custom interactions in the future.
|
||||
// For now, smooth scrolling is handled by CSS.
|
||||
console.log("Hostel Allocation System JS Loaded.");
|
||||
63
auth/forgot-password.php
Normal file
63
auth/forgot-password.php
Normal file
@ -0,0 +1,63 @@
|
||||
<?php
|
||||
require_once '../includes/header.php';
|
||||
require_once '../db/config.php';
|
||||
require_once '../mail/MailService.php';
|
||||
|
||||
$message = '';
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$email = $_POST['email'];
|
||||
$pdo = db();
|
||||
|
||||
$stmt = $pdo->prepare("SELECT * FROM Users WHERE email = ?");
|
||||
$stmt->execute([$email]);
|
||||
$user = $stmt->fetch();
|
||||
|
||||
if ($user) {
|
||||
$token = bin2hex(random_bytes(50));
|
||||
$expires = new DateTime('now');
|
||||
$expires->add(new DateInterval('PT1H')); // 1 hour expiration
|
||||
|
||||
$stmt = $pdo->prepare("UPDATE Users SET reset_token = ?, reset_token_expires = ? WHERE email = ?");
|
||||
$stmt->execute([$token, $expires->format('Y-m-d H:i:s'), $email]);
|
||||
|
||||
$reset_link = "http://" . $_SERVER['HTTP_HOST'] . "/auth/reset-password.php?token=" . $token;
|
||||
|
||||
$subject = "Password Reset Request";
|
||||
$body_html = "Click the following link to reset your password: <a href='{$reset_link}'>{$reset_link}</a>";
|
||||
$body_text = "Click the following link to reset your password: {$reset_link}";
|
||||
|
||||
MailService::sendMail($email, $subject, $body_html, $body_text);
|
||||
|
||||
$message = "A password reset link has been sent to your email address.";
|
||||
} else {
|
||||
$message = "No user found with that email address.";
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
<div class="container">
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-md-6">
|
||||
<div class="card mt-5">
|
||||
<div class="card-header">
|
||||
<h3>Forgot Password</h3>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<?php if ($message): ?>
|
||||
<div class="alert alert-info"><?php echo $message; ?></div>
|
||||
<?php endif; ?>
|
||||
<form action="forgot-password.php" method="POST">
|
||||
<div class="form-group">
|
||||
<label for="email">Email address</label>
|
||||
<input type="email" class="form-control" id="email" name="email" required>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary">Send Password Reset Link</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php require_once '../includes/footer.php'; ?>
|
||||
88
auth/login.php
Normal file
88
auth/login.php
Normal file
@ -0,0 +1,88 @@
|
||||
<?php
|
||||
session_start();
|
||||
|
||||
require_once __DIR__ . '/../db/config.php';
|
||||
|
||||
$errors = [];
|
||||
|
||||
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||
$email = trim($_POST['email']);
|
||||
$password = $_POST['password'];
|
||||
|
||||
if (empty($email) || !filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
||||
$errors[] = 'A valid email is required.';
|
||||
}
|
||||
if (empty($password)) {
|
||||
$errors[] = 'Password is required.';
|
||||
}
|
||||
|
||||
if (empty($errors)) {
|
||||
try {
|
||||
$pdo = db();
|
||||
$stmt = $pdo->prepare("SELECT * FROM Users WHERE email = ?");
|
||||
$stmt->execute([$email]);
|
||||
$user = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
if ($user && password_verify($password, $user['password'])) {
|
||||
// Password is correct, start session
|
||||
$_SESSION['id'] = $user['id'];
|
||||
$_SESSION['name'] = $user['name'];
|
||||
$_SESSION['role'] = $user['role'];
|
||||
|
||||
// Redirect based on role
|
||||
if ($user['role'] === 'Admin') {
|
||||
header("Location: /admin/dashboard.php");
|
||||
exit;
|
||||
} else {
|
||||
header("Location: /student/dashboard.php");
|
||||
exit;
|
||||
}
|
||||
} else {
|
||||
$errors[] = 'Invalid email or password.';
|
||||
}
|
||||
} catch (PDOException $e) {
|
||||
$errors[] = "Database error: " . $e->getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
require_once __DIR__ . '/../includes/header.php';
|
||||
?>
|
||||
|
||||
<div class="container mt-5">
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-md-6">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h2>Login</h2>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<?php if (!empty($errors)): ?>
|
||||
<div class="alert alert-danger">
|
||||
<?php foreach ($errors as $error): ?>
|
||||
<p><?php echo $error; ?></p>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<form action="login.php" method="post">
|
||||
<div class="form-group mb-3">
|
||||
<label for="email">Email address</label>
|
||||
<input type="email" class="form-control" id="email" name="email" required>
|
||||
</div>
|
||||
<div class="form-group mb-3">
|
||||
<label for="password">Password</label>
|
||||
<input type="password" class="form-control" id="password" name="password" required>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary w-100">Login</button>
|
||||
</form>
|
||||
</div>
|
||||
<div class="card-footer text-center">
|
||||
<p>Don't have an account? <a href="signup.php">Sign up here</a>.</p>
|
||||
<p><a href="forgot-password.php">Forgot Password?</a></p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php require_once __DIR__ . '/../includes/footer.php'; ?>
|
||||
7
auth/logout.php
Normal file
7
auth/logout.php
Normal file
@ -0,0 +1,7 @@
|
||||
<?php
|
||||
session_start();
|
||||
session_unset();
|
||||
session_destroy();
|
||||
header("Location: /auth/login.php");
|
||||
exit;
|
||||
?>
|
||||
73
auth/reset-password.php
Normal file
73
auth/reset-password.php
Normal file
@ -0,0 +1,73 @@
|
||||
<?php
|
||||
require_once '../includes/header.php';
|
||||
require_once '../db/config.php';
|
||||
|
||||
$message = '';
|
||||
$error = '';
|
||||
$token = $_GET['token'] ?? '';
|
||||
|
||||
if (!$token) {
|
||||
header("Location: /auth/login.php");
|
||||
exit();
|
||||
}
|
||||
|
||||
$pdo = db();
|
||||
$stmt = $pdo->prepare("SELECT * FROM Users WHERE reset_token = ? AND reset_token_expires > NOW()");
|
||||
$stmt->execute([$token]);
|
||||
$user = $stmt->fetch();
|
||||
|
||||
if (!$user) {
|
||||
$error = "Invalid or expired token.";
|
||||
}
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && $user) {
|
||||
$password = $_POST['password'];
|
||||
$password_confirm = $_POST['password_confirm'];
|
||||
|
||||
if ($password === $password_confirm) {
|
||||
$hashed_password = password_hash($password, PASSWORD_DEFAULT);
|
||||
$stmt = $pdo->prepare("UPDATE Users SET password = ?, reset_token = NULL, reset_token_expires = NULL WHERE id = ?");
|
||||
$stmt->execute([$hashed_password, $user['id']]);
|
||||
$message = "Your password has been reset successfully. You can now <a href='login.php'>login</a>.";
|
||||
} else {
|
||||
$error = "Passwords do not match.";
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<div class="container">
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-md-6">
|
||||
<div class="card mt-5">
|
||||
<div class="card-header">
|
||||
<h3>Reset Password</h3>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<?php if ($message): ?>
|
||||
<div class="alert alert-success"><?php echo $message; ?></div>
|
||||
<?php endif; ?>
|
||||
<?php if ($error): ?>
|
||||
<div class="alert alert-danger"><?php echo $error; ?></div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if (!$message && $user): ?>
|
||||
<form action="reset-password.php?token=<?php echo htmlspecialchars($token); ?>" method="POST">
|
||||
<div class="form-group">
|
||||
<label for="password">New Password</label>
|
||||
<input type="password" class="form-control" id="password" name="password" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="password_confirm">Confirm New Password</label>
|
||||
<input type="password" class="form-control" id="password_confirm" name="password_confirm" required>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary">Reset Password</button>
|
||||
</form>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php require_once '../includes/footer.php'; ?>
|
||||
147
auth/signup.php
Normal file
147
auth/signup.php
Normal file
@ -0,0 +1,147 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../includes/header.php';
|
||||
require_once __DIR__ . '/../db/config.php';
|
||||
|
||||
$errors = [];
|
||||
$success = '';
|
||||
|
||||
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||
// Sanitize and retrieve form data
|
||||
$name = trim($_POST['name']);
|
||||
$email = trim($_POST['email']);
|
||||
$password = $_POST['password'];
|
||||
$confirm_password = $_POST['confirm_password'];
|
||||
$gender = $_POST['gender'] ?? '';
|
||||
$year = $_POST['year'] ?? '';
|
||||
$department = trim($_POST['department']);
|
||||
|
||||
// Validation
|
||||
if (empty($name)) {
|
||||
$errors[] = 'Name is required.';
|
||||
}
|
||||
if (empty($email) || !filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
||||
$errors[] = 'A valid email is required.';
|
||||
}
|
||||
if (empty($password)) {
|
||||
$errors[] = 'Password is required.';
|
||||
}
|
||||
if ($password !== $confirm_password) {
|
||||
$errors[] = 'Passwords do not match.';
|
||||
}
|
||||
if (empty($gender)) {
|
||||
$errors[] = 'Gender is required.';
|
||||
}
|
||||
if (empty($year)) {
|
||||
$errors[] = 'Year is required.';
|
||||
}
|
||||
if (empty($department)) {
|
||||
$errors[] = 'Department is required.';
|
||||
}
|
||||
|
||||
if (empty($errors)) {
|
||||
try {
|
||||
$pdo = db();
|
||||
|
||||
// Check if email already exists
|
||||
$stmt = $pdo->prepare("SELECT COUNT(*) FROM Users WHERE email = ?");
|
||||
$stmt->execute([$email]);
|
||||
if ($stmt->fetchColumn() > 0) {
|
||||
$errors[] = 'Email address is already registered.';
|
||||
} else {
|
||||
// Hash password
|
||||
$hashed_password = password_hash($password, PASSWORD_DEFAULT);
|
||||
|
||||
// Set default role
|
||||
$role = 'Student';
|
||||
|
||||
// Insert user into database
|
||||
$sql = "INSERT INTO Users (name, email, password, role, gender, year, department) VALUES (?, ?, ?, ?, ?, ?, ?)";
|
||||
$stmt = $pdo->prepare($sql);
|
||||
|
||||
if ($stmt->execute([$name, $email, $hashed_password, $role, $gender, $year, $department])) {
|
||||
$success = 'Registration successful! You can now <a href="login.php">log in</a>.';
|
||||
} else {
|
||||
$errors[] = 'Something went wrong. Please try again later.';
|
||||
}
|
||||
}
|
||||
} catch (PDOException $e) {
|
||||
$errors[] = "Database error: " . $e->getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
<div class="container mt-5">
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-md-6">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h2>Sign Up</h2>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<?php if (!empty($errors)): ?>
|
||||
<div class="alert alert-danger">
|
||||
<?php foreach ($errors as $error): ?>
|
||||
<p><?php echo $error; ?></p>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php if ($success): ?>
|
||||
<div class="alert alert-success">
|
||||
<p><?php echo $success; ?></p>
|
||||
</div>
|
||||
<?php else: ?>
|
||||
<form action="signup.php" method="post">
|
||||
<div class="form-group mb-3">
|
||||
<label for="name">Full Name</label>
|
||||
<input type="text" class="form-control" id="name" name="name" required>
|
||||
</div>
|
||||
<div class="form-group mb-3">
|
||||
<label for="email">Email address</label>
|
||||
<input type="email" class="form-control" id="email" name="email" required>
|
||||
</div>
|
||||
<div class="form-group mb-3">
|
||||
<label for="password">Password</label>
|
||||
<input type="password" class="form-control" id="password" name="password" required>
|
||||
</div>
|
||||
<div class="form-group mb-3">
|
||||
<label for="confirm_password">Confirm Password</label>
|
||||
<input type="password" class="form-control" id="confirm_password" name="confirm_password" required>
|
||||
</div>
|
||||
<div class="form-group mb-3">
|
||||
<label for="gender">Gender</label>
|
||||
<select class="form-control" id="gender" name="gender" required>
|
||||
<option value="">Select Gender</option>
|
||||
<option value="Male">Male</option>
|
||||
<option value="Female">Female</option>
|
||||
<option value="Other">Other</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group mb-3">
|
||||
<label for="year">Year</label>
|
||||
<select class="form-control" id="year" name="year" required>
|
||||
<option value="">Select Year</option>
|
||||
<option value="1">First</option>
|
||||
<option value="2">Second</option>
|
||||
<option value="3">Third</option>
|
||||
<option value="4">Fourth</option>
|
||||
<option value="5">Fifth</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group mb-3">
|
||||
<label for="department">Department</label>
|
||||
<input type="text" class="form-control" id="department" name="department" required>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary w-100">Sign Up</button>
|
||||
</form>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<div class="card-footer text-center">
|
||||
<p>Already have an account? <a href="login.php">Login here</a>.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php require_once __DIR__ . '/../includes/footer.php'; ?>
|
||||
41
db/migrations/001_initial_schema.sql
Normal file
41
db/migrations/001_initial_schema.sql
Normal file
@ -0,0 +1,41 @@
|
||||
CREATE TABLE IF NOT EXISTS `Users` (
|
||||
`id` INT AUTO_INCREMENT PRIMARY KEY,
|
||||
`name` VARCHAR(255) NOT NULL,
|
||||
`email` VARCHAR(255) NOT NULL UNIQUE,
|
||||
`password` VARCHAR(255) NOT NULL,
|
||||
`role` ENUM('Admin', 'Student', 'Super Admin') NOT NULL,
|
||||
`gender` ENUM('Male', 'Female', 'Other'),
|
||||
`year` INT,
|
||||
`department` VARCHAR(255),
|
||||
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `Rooms` (
|
||||
`id` INT AUTO_INCREMENT PRIMARY KEY,
|
||||
`room_no` VARCHAR(50) NOT NULL,
|
||||
`block` VARCHAR(50),
|
||||
`capacity` INT NOT NULL,
|
||||
`occupied` INT DEFAULT 0,
|
||||
`type` VARCHAR(100),
|
||||
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `Allocations` (
|
||||
`id` INT AUTO_INCREMENT PRIMARY KEY,
|
||||
`student_id` INT NOT NULL,
|
||||
`room_id` INT NOT NULL,
|
||||
`allocation_date` DATE,
|
||||
`status` VARCHAR(100),
|
||||
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (`student_id`) REFERENCES `Users`(`id`) ON DELETE CASCADE,
|
||||
FOREIGN KEY (`room_id`) REFERENCES `Rooms`(`id`) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `Requests` (
|
||||
`id` INT AUTO_INCREMENT PRIMARY KEY,
|
||||
`student_id` INT NOT NULL,
|
||||
`room_preference` VARCHAR(255),
|
||||
`approval_status` VARCHAR(100) DEFAULT 'Pending',
|
||||
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (`student_id`) REFERENCES `Users`(`id`) ON DELETE CASCADE
|
||||
);
|
||||
9
db/migrations/002_create_room_requests_table.sql
Normal file
9
db/migrations/002_create_room_requests_table.sql
Normal file
@ -0,0 +1,9 @@
|
||||
CREATE TABLE IF NOT EXISTS `RoomRequests` (
|
||||
`request_id` INT AUTO_INCREMENT PRIMARY KEY,
|
||||
`student_id` INT NOT NULL,
|
||||
`room_id` INT NOT NULL,
|
||||
`status` VARCHAR(50) NOT NULL DEFAULT 'pending',
|
||||
`request_date` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (`student_id`) REFERENCES `Users`(`id`) ON DELETE CASCADE,
|
||||
FOREIGN KEY (`room_id`) REFERENCES `Rooms`(`id`) ON DELETE CASCADE
|
||||
);
|
||||
3
db/migrations/003_add_password_reset_to_users.sql
Normal file
3
db/migrations/003_add_password_reset_to_users.sql
Normal file
@ -0,0 +1,3 @@
|
||||
ALTER TABLE `Users`
|
||||
ADD COLUMN `reset_token` VARCHAR(255) NULL,
|
||||
ADD COLUMN `reset_token_expires` DATETIME NULL;
|
||||
5
includes/footer.php
Normal file
5
includes/footer.php
Normal file
@ -0,0 +1,5 @@
|
||||
</div> <!-- /container -->
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
||||
<script src="/assets/js/main.js?v=<?php echo time(); ?>"></script>
|
||||
</body>
|
||||
</html>
|
||||
41
includes/header.php
Normal file
41
includes/header.php
Normal file
@ -0,0 +1,41 @@
|
||||
<?php session_start(); ?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Hostel Room Allocation</title>
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link rel="stylesheet" href="/assets/css/custom.css">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
|
||||
<div class="container-fluid">
|
||||
<a class="navbar-brand" href="/">Hostel Allocation</a>
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
<div class="collapse navbar-collapse" id="navbarNav">
|
||||
<ul class="navbar-nav ms-auto">
|
||||
<?php if (isset($_SESSION['user_id'])): ?>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="#">Welcome, <?php echo htmlspecialchars($_SESSION['user_name']); ?></a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="/auth/logout.php">Logout</a>
|
||||
</li>
|
||||
<?php else: ?>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="/auth/login.php">Login</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="/auth/signup.php">Sign Up</a>
|
||||
</li>
|
||||
<?php endif; ?>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<main class="container mt-4">
|
||||
312
index.php
312
index.php
@ -1,150 +1,172 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
@ini_set('display_errors', '1');
|
||||
@error_reporting(E_ALL);
|
||||
@date_default_timezone_set('UTC');
|
||||
|
||||
$phpVersion = PHP_VERSION;
|
||||
$now = date('Y-m-d H:i:s');
|
||||
?>
|
||||
<!doctype html>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<title>New Style</title>
|
||||
<?php
|
||||
// Read project preview data from environment
|
||||
$projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? '';
|
||||
$projectImageUrl = $_SERVER['PROJECT_IMAGE_URL'] ?? '';
|
||||
?>
|
||||
<?php if ($projectDescription): ?>
|
||||
<!-- Meta description -->
|
||||
<meta name="description" content='<?= htmlspecialchars($projectDescription) ?>' />
|
||||
<!-- Open Graph meta tags -->
|
||||
<meta property="og:description" content="<?= htmlspecialchars($projectDescription) ?>" />
|
||||
<!-- Twitter meta tags -->
|
||||
<meta property="twitter:description" content="<?= htmlspecialchars($projectDescription) ?>" />
|
||||
<?php endif; ?>
|
||||
<?php if ($projectImageUrl): ?>
|
||||
<!-- Open Graph image -->
|
||||
<meta property="og:image" content="<?= htmlspecialchars($projectImageUrl) ?>" />
|
||||
<!-- Twitter image -->
|
||||
<meta property="twitter:image" content="<?= htmlspecialchars($projectImageUrl) ?>" />
|
||||
<?php endif; ?>
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;700&display=swap" rel="stylesheet">
|
||||
<style>
|
||||
:root {
|
||||
--bg-color-start: #6a11cb;
|
||||
--bg-color-end: #2575fc;
|
||||
--text-color: #ffffff;
|
||||
--card-bg-color: rgba(255, 255, 255, 0.01);
|
||||
--card-border-color: rgba(255, 255, 255, 0.1);
|
||||
}
|
||||
body {
|
||||
margin: 0;
|
||||
font-family: 'Inter', sans-serif;
|
||||
background: linear-gradient(45deg, var(--bg-color-start), var(--bg-color-end));
|
||||
color: var(--text-color);
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
min-height: 100vh;
|
||||
text-align: center;
|
||||
overflow: hidden;
|
||||
position: relative;
|
||||
}
|
||||
body::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 100 100"><path d="M-10 10L110 10M10 -10L10 110" stroke-width="1" stroke="rgba(255,255,255,0.05)"/></svg>');
|
||||
animation: bg-pan 20s linear infinite;
|
||||
z-index: -1;
|
||||
}
|
||||
@keyframes bg-pan {
|
||||
0% { background-position: 0% 0%; }
|
||||
100% { background-position: 100% 100%; }
|
||||
}
|
||||
main {
|
||||
padding: 2rem;
|
||||
}
|
||||
.card {
|
||||
background: var(--card-bg-color);
|
||||
border: 1px solid var(--card-border-color);
|
||||
border-radius: 16px;
|
||||
padding: 2rem;
|
||||
backdrop-filter: blur(20px);
|
||||
-webkit-backdrop-filter: blur(20px);
|
||||
box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
.loader {
|
||||
margin: 1.25rem auto 1.25rem;
|
||||
width: 48px;
|
||||
height: 48px;
|
||||
border: 3px solid rgba(255, 255, 255, 0.25);
|
||||
border-top-color: #fff;
|
||||
border-radius: 50%;
|
||||
animation: spin 1s linear infinite;
|
||||
}
|
||||
@keyframes spin {
|
||||
from { transform: rotate(0deg); }
|
||||
to { transform: rotate(360deg); }
|
||||
}
|
||||
.hint {
|
||||
opacity: 0.9;
|
||||
}
|
||||
.sr-only {
|
||||
position: absolute;
|
||||
width: 1px; height: 1px;
|
||||
padding: 0; margin: -1px;
|
||||
overflow: hidden;
|
||||
clip: rect(0, 0, 0, 0);
|
||||
white-space: nowrap; border: 0;
|
||||
}
|
||||
h1 {
|
||||
font-size: 3rem;
|
||||
font-weight: 700;
|
||||
margin: 0 0 1rem;
|
||||
letter-spacing: -1px;
|
||||
}
|
||||
p {
|
||||
margin: 0.5rem 0;
|
||||
font-size: 1.1rem;
|
||||
}
|
||||
code {
|
||||
background: rgba(0,0,0,0.2);
|
||||
padding: 2px 6px;
|
||||
border-radius: 4px;
|
||||
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
|
||||
}
|
||||
footer {
|
||||
position: absolute;
|
||||
bottom: 1rem;
|
||||
font-size: 0.8rem;
|
||||
opacity: 0.7;
|
||||
}
|
||||
</style>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Hostel Room Allocation System</title>
|
||||
<meta name="description" content="A comprehensive system to manage student registration, room availability, and automatic room assignment.">
|
||||
<meta name="keywords" content="hostel management, room allocation, student housing, dormitory management, university housing, student registration, room assignment, flatlogic">
|
||||
<meta property="og:title" content="Hostel Room Allocation System">
|
||||
<meta property="og:description" content="A comprehensive system to manage student registration, room availability, and automatic room assignment.">
|
||||
<meta property="og:image" content="<?php echo htmlspecialchars($_SERVER['PROJECT_IMAGE_URL'] ?? ''); ?>">
|
||||
<meta name="twitter:card" content="summary_large_image">
|
||||
<meta name="twitter:image" content="<?php echo htmlspecialchars($_SERVER['PROJECT_IMAGE_URL'] ?? ''); ?>">
|
||||
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
|
||||
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
|
||||
</head>
|
||||
<body>
|
||||
<main>
|
||||
<div class="card">
|
||||
<h1>Analyzing your requirements and generating your website…</h1>
|
||||
<div class="loader" role="status" aria-live="polite" aria-label="Applying initial changes">
|
||||
<span class="sr-only">Loading…</span>
|
||||
</div>
|
||||
<p class="hint"><?= ($_SERVER['HTTP_HOST'] ?? '') === 'appwizzy.com' ? 'AppWizzy' : 'Flatlogic' ?> AI is collecting your requirements and applying the first changes.</p>
|
||||
<p class="hint">This page will update automatically as the plan is implemented.</p>
|
||||
<p>Runtime: PHP <code><?= htmlspecialchars($phpVersion) ?></code> — UTC <code><?= htmlspecialchars($now) ?></code></p>
|
||||
</div>
|
||||
</main>
|
||||
<footer>
|
||||
Page updated: <?= htmlspecialchars($now) ?> (UTC)
|
||||
</footer>
|
||||
|
||||
<nav class="navbar navbar-expand-lg navbar-light bg-white shadow-sm sticky-top">
|
||||
<div class="container">
|
||||
<a class="navbar-brand fw-bold" href="#">Hostel Allocator</a>
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
<div class="collapse navbar-collapse" id="navbarNav">
|
||||
<ul class="navbar-nav ms-auto">
|
||||
<li class="nav-item"><a class="nav-link" href="/">Home</a></li>
|
||||
<li class="nav-item"><a class="nav-link" href="/auth/login.php">Login</a></li>
|
||||
<li class="nav-item"><a class="nav-link btn btn-primary text-white ms-2 px-3" href="/auth/signup.php">Sign Up</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<header id="home" class="hero-section text-white text-center">
|
||||
<div class="container">
|
||||
<h1 class="display-4 fw-bold">Hostel Room Allocation Made Easy</h1>
|
||||
<p class="lead my-4">A seamless, automated system for students and admins.</p>
|
||||
<a href="/auth/signup.php" class="btn btn-light btn-lg fw-bold">Get Started</a>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<main>
|
||||
<section id="about" class="py-5">
|
||||
<div class="container">
|
||||
<div class="row align-items-center">
|
||||
<div class="col-md-6">
|
||||
<h2 class="fw-bold mb-3">About the System</h2>
|
||||
<p class="text-muted">Our platform simplifies the entire hostel room allocation process, from initial student requests to final assignments. It's designed to be fair, transparent, and efficient for both students and administrators. We automate the heavy lifting so you can focus on what matters.</p>
|
||||
</div>
|
||||
<div class="col-md-6 text-center">
|
||||
<i class="bi bi-building-check display-1 text-primary"></i>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section id="rules" class="py-5 bg-light">
|
||||
<div class="container">
|
||||
<h2 class="text-center fw-bold mb-4">Hostel Rules</h2>
|
||||
<p class="text-center text-muted mb-5">Please read the following rules carefully.</p>
|
||||
<div class="row">
|
||||
<div class="col-md-4">
|
||||
<div class="card h-100 text-center p-3">
|
||||
<i class="bi bi-gender-ambiguous fs-1 text-primary"></i>
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">Gender Separation</h5>
|
||||
<p class="card-text">Rooms and floors are strictly separated by gender to ensure safety and comfort.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<div class="card h-100 text-center p-3">
|
||||
<i class="bi bi-clock-history fs-1 text-primary"></i>
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">Curfew</h5>
|
||||
<p class="card-text">All students must return to the hostel by the designated curfew time every night.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<div class="card h-100 text-center p-3">
|
||||
<i class="bi bi-person-x fs-1 text-primary"></i>
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">No Visitors</h5>
|
||||
<p class="card-text">Visitors are not permitted in student rooms to maintain privacy and security.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section id="faq" class="py-5">
|
||||
<div class="container">
|
||||
<h2 class="text-center fw-bold mb-5">Frequently Asked Questions</h2>
|
||||
<div class="accordion" id="faqAccordion">
|
||||
<div class="accordion-item">
|
||||
<h2 class="accordion-header" id="headingOne">
|
||||
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#collapseOne">
|
||||
How are rooms assigned?
|
||||
</button>
|
||||
</h2>
|
||||
<div id="collapseOne" class="accordion-collapse collapse" data-bs-parent="#faqAccordion">
|
||||
<div class="accordion-body">
|
||||
Rooms are assigned automatically based on your preferences (like room type), gender, and availability. The system follows a first-come, first-served principle.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="accordion-item">
|
||||
<h2 class="accordion-header" id="headingTwo">
|
||||
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#collapseTwo">
|
||||
Can I request a room change?
|
||||
</button>
|
||||
</h2>
|
||||
<div id="collapseTwo" class="accordion-collapse collapse" data-bs-parent="#faqAccordion">
|
||||
<div class="accordion-body">
|
||||
Yes. After your initial assignment, you can log in to the student portal to submit a room change request, which will be reviewed by the hostel admin.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="accordion-item">
|
||||
<h2 class="accordion-header" id="headingThree">
|
||||
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#collapseThree">
|
||||
What if I leave in the middle of the semester?
|
||||
</button>
|
||||
</h2>
|
||||
<div id="collapseThree" class="accordion-collapse collapse" data-bs-parent="#faqAccordion">
|
||||
<div class="accordion-body">
|
||||
You must inform the hostel admin. Your bed will be marked as available, and the system may reassign it to a waitlisted student. Refund policies will apply.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section id="contact" class="py-5 bg-light">
|
||||
<div class="container">
|
||||
<h2 class="text-center fw-bold mb-4">Contact Us</h2>
|
||||
<p class="text-center text-muted mb-5">Have questions? Get in touch with the administration.</p>
|
||||
<div class="row">
|
||||
<div class="col-md-8 mx-auto">
|
||||
<div class="card p-4">
|
||||
<p class="text-center">For any inquiries, please email us at <a href="mailto:support@yourhostel.com">support@yourhostel.com</a> or visit the admin office during work hours.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section id="request-form" class="py-5">
|
||||
<div class="container">
|
||||
<h2 class="text-center fw-bold mb-4">Room Request Form</h2>
|
||||
<p class="text-center text-muted mb-5">This is a placeholder for the room request form.</p>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
</main>
|
||||
|
||||
<footer class="py-4 bg-dark text-white text-center">
|
||||
<div class="container">
|
||||
<p>© <?php echo date("Y"); ?> Hostel Room Allocation System. All Rights Reserved.</p>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
||||
<script src="assets/js/main.js?v=<?php echo time(); ?>"></script>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
44
student/dashboard.php
Normal file
44
student/dashboard.php
Normal file
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
require_once '../includes/header.php';
|
||||
require_once '../db/config.php';
|
||||
|
||||
if (!isset($_SESSION['id']) || $_SESSION['role'] !== 'Student') {
|
||||
header('Location: ../auth/login.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
$pdo = db();
|
||||
$stmt = $pdo->prepare("SELECT r.room_number, r.details FROM Allocations a JOIN Rooms r ON a.room_id = r.id WHERE a.student_id = ?");
|
||||
$stmt->execute([$_SESSION['id']]);
|
||||
$allocation = $stmt->fetch();
|
||||
?>
|
||||
|
||||
<div class="container mt-5">
|
||||
<h1>Student Dashboard</h1>
|
||||
<p>Welcome, <?php echo htmlspecialchars($_SESSION['name']); ?>!</p>
|
||||
|
||||
<div class="card mt-4">
|
||||
<div class="card-header">
|
||||
My Room Allocation
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<?php if ($allocation): ?>
|
||||
<h5 class="card-title">You are allocated to Room: <?php echo htmlspecialchars($allocation['room_number']); ?></h5>
|
||||
<p class="card-text"><strong>Details:</strong> <?php echo htmlspecialchars($allocation['details']); ?></p>
|
||||
<?php else: ?>
|
||||
<p class="card-text">You have not been allocated a room yet.</p>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card mt-4">
|
||||
<div class="card-header">
|
||||
Room Request
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<a href="request_room.php" class="btn btn-primary">Request a Room</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php require_once '../includes/footer.php'; ?>
|
||||
61
student/request_room.php
Normal file
61
student/request_room.php
Normal file
@ -0,0 +1,61 @@
|
||||
<?php
|
||||
require_once '../includes/header.php';
|
||||
require_once '../db/config.php';
|
||||
|
||||
if (!isset($_SESSION['id']) || $_SESSION['role'] !== 'Student') {
|
||||
header('Location: ../auth/login.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
$student_id = $_SESSION['id'];
|
||||
$pdo = db();
|
||||
|
||||
// Check if student has a pending or approved request
|
||||
$stmt = $pdo->prepare("SELECT * FROM RoomRequests WHERE student_id = ? AND (status = 'pending' OR status = 'approved')");
|
||||
$stmt->execute([$student_id]);
|
||||
$existing_request = $stmt->fetch();
|
||||
|
||||
// Check if student is already allocated a room
|
||||
$stmt = $pdo->prepare("SELECT * FROM Allocations WHERE student_id = ?");
|
||||
$stmt->execute([$student_id]);
|
||||
$allocation = $stmt->fetch();
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['request_room']) && !$existing_request && !$allocation) {
|
||||
$room_id = $_POST['room_id'];
|
||||
$stmt = $pdo->prepare("INSERT INTO RoomRequests (student_id, room_id) VALUES (?, ?)");
|
||||
$stmt->execute([$student_id, $room_id]);
|
||||
header('Location: request_room.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
// Fetch available rooms (not occupied)
|
||||
$stmt = $pdo->query("SELECT * FROM Rooms WHERE id NOT IN (SELECT room_id FROM Allocations)");
|
||||
$available_rooms = $stmt->fetchAll();
|
||||
|
||||
?>
|
||||
|
||||
<div class="container mt-5">
|
||||
<h2>Request a Room</h2>
|
||||
<?php if ($allocation): ?>
|
||||
<div class="alert alert-info">You are already allocated to a room.</div>
|
||||
<?php elseif ($existing_request): ?>
|
||||
<div class="alert alert-warning">
|
||||
You have a <?php echo htmlspecialchars($existing_request['status']); ?> room request. Please wait for an admin to review it.
|
||||
</div>
|
||||
<?php else: ?>
|
||||
<form method="POST">
|
||||
<div class="form-group">
|
||||
<label for="room_id">Select a Room:</label>
|
||||
<select class="form-control" id="room_id" name="room_id" required>
|
||||
<?php foreach ($available_rooms as $room): ?>
|
||||
<option value="<?php echo $room['id']; ?>"><?php echo htmlspecialchars($room['room_number']); ?> - <?php echo htmlspecialchars($room['details']); ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
<button type="submit" name="request_room" class="btn btn-primary mt-3">Submit Request</button>
|
||||
</form>
|
||||
<?php endif; ?>
|
||||
<a href="dashboard.php" class="btn btn-secondary mt-3">Back to Dashboard</a>
|
||||
</div>
|
||||
|
||||
<?php require_once '../includes/footer.php'; ?>
|
||||
Loading…
x
Reference in New Issue
Block a user