-
Notifications
You must be signed in to change notification settings - Fork 0
/
bookRoomFromQueue.php
282 lines (250 loc) · 10.4 KB
/
bookRoomFromQueue.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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
<?include_once("global.php");?>
<?
if ($logged==0){
?>
<script type="text/javascript">
window.location = "./";
</script>
<?
}
$id = $_GET["id"];
//populate studentID and occupants
$query = "SELECT * from lib_bookingQueue where id='$id'";
$result = $con->query($query);
$i = 0;
if ($result->num_rows > 0)
{
while($row = $result->fetch_assoc())
{
$studentId = $row['studentId'];
$nStudents = $row['occupants'];
}
}
date_default_timezone_set("Asia/Karachi");
if(isset($_POST["room"]) && isset($_POST["reason"]) && isset($_GET["id"])){
$room = $_POST["room"];
//$studentId = $_POST["studentId"];
//$nStudents = $_POST["nStudents"];
$reason = $_POST["reason"];
$timeTaken = date("d-m-Y:h:i:sa");//strval(date("d-m-Y"))+strval(date("h:i:sa")) ;
$expiry = time()+ 3600*(2);
if((!$room)||(!$studentId)){
$message = "Please insert both fields.";
}
else{
//go
function generateRandomString($length = 10) {
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, $charactersLength - 1)];
}
return $randomString;
}
$bookingId = generateRandomString();
$sql="INSERT INTO `lib_bookings`(`studentId`, `dateTimeTaken`, `nStudents`, `room`, `expiry`, `status`, `bookingId`, `purpose`) VALUES ('$studentId', '$timeTaken', '$nStudents', '$room', '$expiry', 'booked', '$bookingId', '$reason')";
if(!mysqli_query($con,$sql))
{
echo"can not";
}
//update room status
$sql="update lib_room set status='booked', bookingId='$bookingId' where room='$room'";
if(!mysqli_query($con,$sql))
{
echo"can not";
}
$sql="update lib_bookingQueue set status='booked' where id='$id'";
if(!mysqli_query($con,$sql))
{
echo"can not";
}
?>
<script type="text/javascript">
window.location = "./dashboard.php";
</script>
<?
}}
//get flagged students:
?>
<script>
var flagged_students_lst = [];
var flagged_students_lst_reason = [];
var flagged_students_lst_timePlaced = [];
</script>
<?
$query = "SELECT `id`, `studentId`, `reason`, `timePlaced` FROM `lib_flags` where studentId=(select studentId from lib_bookingQueue WHERE id = '$id') order by id desc
";
$result = $con->query($query);
$i = 0;
if ($result->num_rows > 0)
{
while($row = $result->fetch_assoc())
{
?>
<script>
flagged_students_lst[<?echo $i?>] = "<?echo $row['studentId']?>"
flagged_students_lst_reason[<?echo $i?>] = "<?echo $row['reason']?>"
flagged_students_lst_timePlaced[<?echo $i?>] = "<?echo date('d-m-Y H:i', $row['timePlaced'])?>"
</script>
<?
$i +=1;
}
}
$query_makingRoomsExpire = "select
* from lib_room where status='free'";
$result_makingRoomsExpire = $con->query($query_makingRoomsExpire);
?>
<script>
console.log("flagged_students_lst", flagged_students_lst);
</script>
<!DOCTYPE html>
<html lang="en">
<?include_once("./phpParts/head.php");?>
<body class="">
<div class="wrapper ">
<div class="sidebar" data-color="purple" data-background-color="white" data-image="assets/img/sidebar-1.jpg">
<!--
Tip 1: You can change the color of the sidebar using: data-color="purple | azure | green | orange | danger"
Tip 2: you can also add an image using data-image tag
-->
<div class="logo">
<a href="./" class="simple-text logo-normal">
HU - Library
</a>
</div>
<div class="sidebar-wrapper">
<ul class="nav">
<li class="nav-item active ">
<a class="nav-link" href="./dashboard.php">
<i class="material-icons">dashboard</i>
<p>Dashboard</p>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="./history.php">
<i class="material-icons">library_books</i>
<p>History</p>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="./flagStudent.php">
<i class="material-icons">flag</i>
<p>Flag Students</p>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="./allDataDownload.php">
<i class="material-icons">import_export</i>
<p>Export data</p>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="./settings.php">
<i class="material-icons">settings</i>
<p>Settings</p>
</a>
</li>
</ul>
</div>
</div>
<div class="main-panel">
<!-- Navbar -->
<nav class="navbar navbar-expand-lg navbar-transparent navbar-absolute fixed-top ">
<div class="container-fluid">
<div class="navbar-wrapper">
<a class="navbar-brand" href="#pablo">Book a room - From Waiting Queue</a>
</div>
<button class="navbar-toggler" type="button" data-toggle="collapse" aria-controls="navigation-index" aria-expanded="false" aria-label="Toggle navigation">
<span class="sr-only">Toggle navigation</span>
<span class="navbar-toggler-icon icon-bar"></span>
<span class="navbar-toggler-icon icon-bar"></span>
<span class="navbar-toggler-icon icon-bar"></span>
</button>
</div>
</nav>
<!-- End Navbar -->
<div class="content">
<div class="container-fluid">
<div class="row">
<div class="col-md-12">
<div class="card">
<div class="card-header card-header-primary">
<h4 class="card-title ">Book Room - From Queue</h4>
</div>
<div class="card-body">
<div class="table-responsive">
<form style="margin:12px;" method="post" action="" autocomplete="off" >
<div class="form-row">
<div class="form-group col-md-6">
<label for="inputEmail4">Student ID</label>
<input id="studentIdBox" name="studentId" type="text" class="form-control" placeholder="" required readonly>
</div>
<div class="form-group col-md-6">
<label for="inputEmail4">Number of occupants</label>
<input id="nStudentsBox" id="nStudents" type="number" class="form-control" placeholder="" required readonly>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-6">
<label for="inputEmail4">Purpose</label>
<select name="reason" class="form-control selectpicker" data-style="btn btn-link">
<option value="noReasonSpecified">-- Specify reason --</option>
<option value="Group Study">Group Study</option>
<option value="Presentation">Presentation</option>
<option value="Assignment">Assignment</option>
<option value="Session">Session</option>
<option value="Interview">Interview</option>
</select>
</div>
<div class="form-group col-md-6">
<label for="inputEmail4">Room</label>
<select name="room" class="form-control selectpicker" data-style="btn btn-link">
<?
if ($result_makingRoomsExpire->num_rows > 0)
{
while($row = $result_makingRoomsExpire->fetch_assoc())
{
$room = $row['room'];
$capacity = $row['capacity'];
echo '<option value="'.$room.'">'.'R: '.$room.' Capacity: '.$capacity.'</option>';
}
}
?>
</select>
</div>
</div>
<div style="display:none" class="alert alert-warning" role="alert" id="flaggedStudentsBox">
Flag on Student! Reason:
</div>
<button type="submit" class="btn btn-primary">Book</button>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<?include_once("./phpParts/footer.php");?>
<script>
var $myList = $('#flaggedStudentsBox');
document.getElementById("flaggedStudentsBox").innerHTML = "Flag on Student! Reason:<hr>";
document.getElementById("flaggedStudentsBox").style.display = "block";
for (var i = 0; i < flagged_students_lst.length; i++) {
if(flagged_students_lst[i].indexOf(document.getElementById('studentIdBox').value.toLowerCase()) != -1)
{
console.log("flagged_students_lst_reason[i]", flagged_students_lst_timePlaced[i]);
var $deleteLink = $("<span>"+((flagged_students_lst_timePlaced[i])).substr(0,21)+": "+flagged_students_lst_reason[i]+"</span>");
$myList.append($deleteLink);
}
}
if(document.getElementById("flaggedStudentsBox").innerHTML == "Flag on Student! Reason:<hr>"){
document.getElementById("flaggedStudentsBox").innerHTML = " ";
document.getElementById("flaggedStudentsBox").style.display = "none";
}
document.getElementById('studentIdBox').value = "<?echo $studentId?>";
document.getElementById('nStudentsBox').value = "<?echo $nStudents?>";
</script>
</body>
</html>