-
Notifications
You must be signed in to change notification settings - Fork 3
/
user.php
202 lines (176 loc) · 8.89 KB
/
user.php
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
<!-- Starting a session -->
<?php
session_start();
?>
<!-- Connecting database -->
<?php include('./dbconnection.php') ?>
<?php
// Query for fetching all distinct hostels that are available
$hostel_list = $conn->query("select distinct Hostel from hostel where Availability=True");
$hostels_array = []; // hostels_array is an array that stores distinct hostels and their available rooms
while($row=$hostel_list->fetch_array()){
$hostels_array[$row["Hostel"]]=array();
}
// Query for getting hotel and rooms for available rooms
$hostel_query = $conn->query("select Hostel,Room from hostel where Availability=True");
// updating available rooms in the hostel array
while($row=$hostel_query->fetch_array()){
$hos=$row["Hostel"];
$room=$row["Room"];
array_push($hostels_array[$hos], $room);
}
// Storing the available hostels data (json encoded sting) as session vaiable for use in select input options
$_SESSION['hostel_array']=json_encode($hostels_array);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="./styles/user.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<title>Welcome to IIT MANDI Hostel Management System!!</title>
</head>
<body>
<div class="admin">
<div class="header">
<img src="./images/logo.jpg" alt="IITMANDILOGO" id="logo">
<h1>IIT MANDI HOSTEL MANAGEMENT SYSTEM</h1>
<div class="logout">
<a href="logout.php">Log Out</a>
</div>
</div>
<div class="container">
<div class="navbar">
<ul class="menu">
<li class="menu__item">
<div class="menu__link" id="book_link">BOOK</div>
</li>
<li class="menu__item">
<div class="menu__link" id="swap_link">SWAP</div>
</li>
<li class="menu__item">
<div class="menu__link" id="vacate_link">VACATE</div>
</li>
<li class="menu__item">
<div class="menu__link" id="hosav_link"> CHECK AVAILABLE ROOMS</div>
</li>
</ul>
</div>
<div class="user-info">
<ul>
<!--using session variables to display user details -->
<li>Name: <?php echo $_SESSION['user_Name'];?></li>
<li>RollNo: <?php echo $_SESSION['user_RollNo'];?></li>
<li>Hostel: <?php echo $_SESSION['user_Hostel'];?></li>
<li>Room: <?php echo $_SESSION['user_Room'];?></li>
</ul>
</div>
<div class="main">
<div class="book active">
<form action="book.php" method="post">
<label>Hostel </label>
<select id="Hostel" name="Hostel">
<option value="none" disabled selected>Select a Hostel</option>
<!-- displaying the available hostels in the select inputs -->
<?php
foreach(array_keys($hostels_array) as $x){
echo "<option value='${x}'>${x}</option>";
}
?>
</select><br>
<label>Room </label>
<select type="text" id="Room" name="Room">
<!-- these options are dynamically updated using javascript -->
<option value='none' selected disabled>Select Room No</option>
<option value='1'>1</option>
<option value='2'>2</option>
<option value='3'>3</option>
<option value='4'>4</option>
<option value='5'>5</option>
<option value='6'>6</option>
<option value='7'>7</option>
<option value='8'>8</option>
<option value='9'>9</option>
<option value='10'>10</option>
</select><br>
<label>Password </label><input type="password" id="Password" name="Password"><br>
<button type="submit">BOOK</button>
</form>
</div>
<div class="swap">
<form action="swap.php" method="post">
<label>Current Hostel </label><input type="text" id="curent-hostel" name="curent-hostel" value="<?php echo $_SESSION['user_Hostel']?>" disabled><br>
<label>Current Room</label><input type="text" id="curent-room" name="curent-room" value="<?php echo $_SESSION['user_Room']?>" disabled><br>
<label>Preffered Hostel</label><select <?php if(!$_SESSION['user_Hostel']){echo 'disabled';}?> type="text" id="preffered-hostel" name="preffered-hostel" ><option value='100' disabled selected>Select a Hostel</option><?php foreach(array_keys($hostels_array) as $x){echo "<option value='${x}'>${x}</option>";} ?></select><br>
<label>Preffered Room</label><select <?php if(!$_SESSION['user_Room']){echo 'disabled';}?> type="text" id="preffered-room" name="preffered-room" ><option value='100' selected disabled>Select Room No</option></select><br>
<label>Password</label><input type="password" id="Password" name="Password"><br>
<button type="submit">SWAP</button>
</form>
</div>
<div class="vacate">
<form action="vacate.php" method="post">
<label>Password</label><input type="password" id="Password" name="Password"><br>
<button type="submit">VACATE</button>
</form>
</div>
<div class="HosAv">
<form id='table-form'>
<label for="txt">Select Hostel</label>
<select type="text" id="txt" name="txt">
<option value=''>Show All</option>
<!-- displaying the available hostels in the select inputs -->
<?php
foreach(array_keys($hostels_array) as $x){
echo "<option value='${x}'>${x}</option>";
}
?>
</select>
<button type="submit">SEARCH</button><br>
</form>
<div id="table-section">
<table id="table">
<thead>
<tr>
<th>Hostel</th>
<th>Room No</th>
<th>Availability</th>
</tr>
</thead>
<tbody>
<tr><th>_</th><th>_</th><th>_</th></tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</body>
<!-- linking user.js -->
<script src="./user.js"></script>
<!-- script for updating available rooms in the dom -->
<script >
var hostel_array = JSON.parse('<?php echo $_SESSION['hostel_array']; ?>');
document.getElementById("Hostel").addEventListener("input", function(evt){
var datalist = document.getElementById("Room");
var hos = this.value;
var arr = hostel_array[`${hos}`];
var str = `<option value="none" diasbled selected>Select Room No</option>`;
for(let i=0;i < arr.length;i++ ){
str=str.concat(`<option value="${arr[i]}">${arr[i]}</option>`);
};
datalist.innerHTML=str;
})
document.getElementById("preffered-hostel").addEventListener("input", function(evt){
var datalist = document.getElementById("preffered-room");
var hos = this.value;
var arr = hostel_array[`${hos}`];
var str = `<option value="none" diasbled selected>Select Room No</option>`;
for(let i=0;i < arr.length;i++ ){
str=str.concat(`<option value="${arr[i]}">${arr[i]}</option>`);
};
datalist.innerHTML=str;
})
</script>
</html>