-
Notifications
You must be signed in to change notification settings - Fork 0
/
checkStatus.php
296 lines (243 loc) · 9.74 KB
/
checkStatus.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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
<?include_once("global.php");?>
<?
$noBooking = true;
if(isset($_GET["room"])){
$noBooking = false;
$room = $_GET["room"];
$query = "select
b.studentId, b.dateTimeTaken, b.expiry
from lib_bookings b inner join lib_room r on b.bookingId = r.bookingId where r.room = '$room' and r.status!='free'
";
$result = $con->query($query);
if ($result->num_rows > 0)
{
while($row = $result->fetch_assoc())
{
$studentId= $row['studentId'];
$dateTimeTaken= $row['dateTimeTaken'];
$expiry= $row['expiry'];
?>
<script>var expiryTime = <?echo $expiry?></script>
<?
//page visit
//check if entry
$query = "select * from lib_pageVisits where studentId='$studentId'";
$result = $con->query($query);
if ($result->num_rows > 0)
{
while($row = $result->fetch_assoc())
{
//update by 1
$sql="update lib_pageVisits set count=count+1 where studentId='$studentId'";
if(!mysqli_query($con,$sql))
{
echo"can not";
}
}
}
else{
//create entry
$sql="insert into lib_pageVisits(studentId, count) values ('$studentId', 1)";
if(!mysqli_query($con,$sql))
{
echo"can not";
}
}
}
}
else{
$noBooking = true;
}
date_default_timezone_set("Asia/Karachi");
$dateTimeTaken = substr($dateTimeTaken, 11, 5).substr($dateTimeTaken, -2);
$expiry = date("d-m-Y:h:i:sa", $expiry);
$expiry = substr($expiry, 11, 5).substr($expiry, -2);
//$expiry = strtotime($dateTimeTaken);
}
//number of rooms booked uptil now
$query = "select
*
from lib_bookings where studentId='$studentId' order by id desc
";
$result = $con->query($query);
?>
<!DOCTYPE html>
<html lang="en">
<?php include("./phpParts/head.php")?>
<body class="" onload="startTime()">
<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>
<div class="main-panel">
<!-- Navbar -->
<!-- End Navbar -->
<div class="content">
<div class="container-fluid">
<div class="row">
<div class="col-md-12">
<div class="alert alert-success" role="alert" id="notfSuccess" style="display:none;">
<b>Notification turned on!</b> <span id="studentIdBox"></span>
</div>
<?php
$actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}";
?>
<script>
document.getElementById("studentIdBox").innerHTML ="<p style='font-size: 13px;'>All notifications for "+localStorage.getItem("studentId")+" will be sent to you. To change the ID associated, <a href='./changeNotfId.php?retUrl=<?echo $actual_link?>' style='color: #801b00;'>click here.</a><p>"//localStorage.getItem("studentId");
</script>
<div class="card" align="center">
<div class="card-header card-header-primary">
<h4 class="card-title ">Room - <?echo $room?></h4>
</div>
<div class="card-body" align="center">
<div class="table-responsive" align="center">
<? if($noBooking==false){?>
<div style="margin:12px; " align="center" class="text-center">
<h4>Booked by: <?echo $studentId?></h4>
<h4>Booking time: <?echo $dateTimeTaken?></h4>
<h4>Expires at: <?echo $expiry?></h4>
<p id="bookTimeLeft">time left</p>
<button id="onNotfBtn" onclick="yes()" class="btn btn-primary">Keep me notified!</button>
<p id="wait5Sec" style="display:none;">Please wait 5 seconds. Your request is being processed.</p>
</div>
<?
}else{
echo"No booking found.";
}
?>
</div>
</div>
</div>
<? if($noBooking==false){?>
<div class="card">
<div class="card-header card-header-primary">
<h4 class="card-title ">Past Bookings of <?echo $studentId?></h4>
<p class="card-category">Find all the past bookings here</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>
Date
</th>
<th>
Time
</th>
<th>
Occupants
</th>
</thead>
<tbody>
<?php
if ($result->num_rows > 0)
{
while($row = $result->fetch_assoc())
{
echo"<tr>";
echo "<td>".$row['room']."</td>";
echo "<td>".substr($row['dateTimeTaken'],0,10)."</td>";
echo "<td>".substr($row['dateTimeTaken'],-10)."</td>";
echo "<td>".$row['nStudents']."</td>";
echo "</tr>";
}
}
?>
</tbody>
</table>
</div>
</div>
</div>
<?}?>
</div>
</div>
</div>
</div>
<form action="" id="tokenForm" method="post" style="display:none;">
<input id="tokenValue" name="token">
<input id="studentId" name="studentId">
</form>
<?php include("./phpParts/footer.php")?>
<?php include("./profiles/push_button.php")?>
<script>
//changing clock
function startTime() {
//expiry
var timeInt = expiryTime- Math.trunc(new Date().getTime()/1000) ;
//console.log("expiryTime", timeInt)
d = Number(timeInt);
var expired = false;
if (d>=0){
d=d
expired = false
}
else{
d = -(d);
expired = true
}
var h = Math.floor(d / 3600);
var m = Math.floor(d % 3600 / 60);
var s = Math.floor(d % 3600 % 60);
var hDisplay = h > 0 ? h + (h == 1 ? " hour, " : " hours,") : " ";
var mDisplay = m > 0 ? m + (m == 1 ? " minute, " : " minutes ") : " ";
timeInt = hDisplay + mDisplay;
if (expired==false){
document.getElementById('bookTimeLeft').innerHTML =timeInt+" to expire."
}
else{
document.getElementById('bookTimeLeft').style.color ="red"
document.getElementById('bookTimeLeft').innerHTML ="Expired "+timeInt+" ago."
}
var t = setTimeout(startTime, 500);
}
//turn button off
//console.log("token expiry:", (new Date().getTime() / 1000), Number(localStorage.getItem("tokenExpiry")))
if(((new Date().getTime() / 1000)<Number(localStorage.getItem("tokenExpiry")))&&(localStorage.getItem("tokenExpiry")!=null)){
document.getElementById("onNotfBtn").style.display="none";
document.getElementById("notfSuccess").style.display="block";
//console.log("hide buttton");
}
else{
document.getElementById("onNotfBtn").style.display="block";
document.getElementById("notfSuccess").style.display="none";
console.log("show buttton");
}
//console.log("--<?echo $studentId?>")
document.getElementById("studentId").value = "<?echo $studentId?>";
</script>
</body>
<?
//enter token
if(isset($_POST["token"])){
$token= $_POST["token"];
//$studentId= $_POST["studentId"];
?>
<script>
document.getElementById("notfSuccess").style.display='block';
localStorage.setItem("studentId", "<?echo $studentId?>");
console.log("-<?echo $studentId?>")
</script>
<?
//check if entry
$query = "select * from lib_pushTokens where studentId='$studentId' and token='$token'";
$result = $con->query($query);
if ($result->num_rows > 0)
{
}
else{
//create entry
$sql="insert into lib_pushTokens(studentId, token) values ('$studentId', '$token')";
if(!mysqli_query($con,$sql))
{
echo"can not";
}
}
}
?>
</html>