-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathroom_reallotment.php
More file actions
72 lines (57 loc) · 2.66 KB
/
room_reallotment.php
File metadata and controls
72 lines (57 loc) · 2.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
include 'include/connect.php';
if (!isset($_SESSION['user_id']) || $_SESSION['user_type'] !== 'student') {
header('Location: student_login.php');
}
$studentId = $_SESSION['user_id'];
$sql = "SELECT room_number, hostel_id FROM room WHERE student_1 = ? OR student_2 = ? OR student_3 = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("sss", $studentId, $studentId, $studentId);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows > 0) {
$currentRoom = $result->fetch_assoc();
}
$sql = "SELECT room_number, hostel_id, capacity FROM room WHERE (student_1 IS NULL OR student_2 IS NULL OR student_3 IS NULL) AND (hostel_id = ?)";
$stmt = $conn->prepare($sql);
$stmt->bind_param("s", $currentRoom['hostel_id']);
$stmt->execute();
$availableRooms = $stmt->get_result()->fetch_all(MYSQLI_ASSOC);
$stmt->close();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Room Reallotment Application</title>
<link rel="stylesheet" href="https://cdn.tailwindcss.com">
</head>
<body class="bg-gray-100 h-screen flex items-center justify-center">
<?php include 'include/header.php'; ?>
<div class="container mx-[40%] mt-[10vh]">
<h1 class="text-2xl font-bold mb-4">Room Reallotment Application</h1>
<?php if (isset($currentRoom)) { ?>
<p><strong>Current Room:</strong> <?php echo $currentRoom['room_number']; ?></p>
<form action="include/room_process.php" method="post">
<input type="hidden" name="type" value="room_reallotment">
<input type="hidden" name="hostel_id" value="<?php echo $currentRoom['hostel_id']; ?>">
<input type="hidden" name="room_number" value="<?php echo $currentRoom['room_number']; ?>">
<input type="hidden" name="description" value="Room Reallotment Application">
<input type="hidden" name="current_room" value="<?php echo $currentRoom['room_number']; ?>">
<label for="new_room" class="block mt-4">Select a new room:</label>
<select name="new_room" id="new_room" class="p-2 border rounded">
<?php foreach ($availableRooms as $room) { ?>
<?php if ($room['capacity'] > 0) { ?>
<option value="<?php echo $room['room_number']; ?>"><?php echo $room['room_number']; ?></option>
<?php } ?>
<?php } ?>
</select>
<button type="submit" class="p-2 bg-blue-500 text-white rounded mt-4">Submit Application</button>
</form>
<?php } else { ?>
<p>Error: Student not allocated to a room.</p>
<?php } ?>
</div>
</body>
</html>