/
publicListing.php
216 lines (189 loc) · 7.04 KB
/
publicListing.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
<?include_once("global.php");?>
<?
if ($logged==0){
?>
<script type="text/javascript">
window.location = "./";
</script>
<?
}
?>
<script>
var roomsStatus = []
var bookingQueue = []
</script>
<?
//number of rooms booked uptil now
$query = "select
r.room, r.capacity, b.expiry, r.status
from lib_room r inner join lib_bookings b on r.bookingId = b.bookingId order by r.id asc
";
$result = $con->query($query);
//waiting queue
$query_bookingQue = "select
*
from lib_bookingQueue where status='waiting' order by id asc
";
$result_bookingQue = $con->query($query_bookingQue);
?>
<!DOCTYPE html>
<html lang="en">
<?include("./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 class="simple-text logo-normal">
Booking Queue
</a>
</div>
<div class="sidebar-wrapper">
<ul class="nav">
<?
$i = 0;
if ($result_bookingQue->num_rows > 0)
{
while($row = $result_bookingQue->fetch_assoc())
{
?>
<script>
bookingQueue[<?echo $i?>] = "<?echo $row['studentId']?>";
</script>
<?
$i+=1;
echo '<li class="nav-item ">
<a class="nav-link">
<p>'.$row['id'].') St. Id: '.$row['studentId']." - Occupants".": ".$row['occupants'].'</p>
</a>
</li>';
}
}
?>
</ul>
</div>
</div>
<div class="main-panel" >
<nav class="navbar navbar-expand-lg navbar-transparent navbar-absolute fixed-top ">
<div class="container-fluid">
<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" style="margin-top:0px;">
<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 ">Rooms Status</h4>
<p class="card-category">Check all rooms status in realtime.</p>
</div>
<div class="card-body">
<div class="table-responsive">
<table class="table">
<thead class=" text-primary">
<th class="text-primary">
Room Number
</th>
<th>
Capacity
</th>
<th>
Status
</th>
<th>
Booking Till
</th>
</thead>
<tbody>
<?php
$i = 0;
if ($result->num_rows > 0)
{
while($row = $result->fetch_assoc())
{
?>
<script>
roomsStatus[<?echo $i?>] = "<?echo $row['status']?>";
</script>
<?
$i+=1;
date_default_timezone_set("Asia/Karachi");
$currentDateTime = date('Y/m/d H:i:s',$row['expiry']);
$newDateTime = date('h:i A', strtotime($currentDateTime));
echo"<tr>";
echo "<td>".$row['room']."</td>";
echo "<td>".$row['capacity']."</td>";
if($row['status']=='booked'){
echo '<td><button class="btn btn-success btn-sm" style="background-color: red; width: 100px;">BOOKED<div class="ripple-container"></div></button></td>';
echo "<td>".$newDateTime."</td>";
}
if($row['status']=='free'){
echo '<td><button class="btn btn-success btn-sm" style="background-color: green; width: 100px;">FREE<div class="ripple-container"></div></button></td>';
echo "<td>--</td>";
}
if($row['status']=='expired'){
echo '<td><button class="btn btn-success btn-sm" style="background-color: #d87e3c; width: 100px;">expired<div class="ripple-container"></div></button></td>';
echo "<td>--</td>";
}
echo "</tr>";
}
}
?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<?include("./phpParts/footer.php")?>
<div class="item"></div>
<script>
function arraysEqual(arr1, arr2) {
for(var i = arr1.length; i--;) {
if(arr1[i] !== arr2[i])
return false;
}
return true;
}
function sleep(delay) {
var start = new Date().getTime();
while (new Date().getTime() < start + delay);
}
$(".item").each(function() {
$this = $(this);
$.ajaxSetup({cache:false});
function timeLeft() {
$.ajax({
type: "POST",
url: "home_updater.php",
dataType: "html",
success: function(result) {
$this.html(result);
timeLeft();
if( !arraysEqual($.parseJSON(result).roomsStatusAr, roomsStatus) || !arraysEqual($.parseJSON(result).bookingQueueAr, bookingQueue) ){
//console.log("result", $.parseJSON(result).roomsStatusAr, roomsStatus)
window.open("./publicListing.php","_self")
}
sleep(1000);
//console.log("result", $.parseJSON(result).roomsStatusAr, roomsStatus)
}
});
}
timeLeft();
});
</script>
</body>
</html>