-
Notifications
You must be signed in to change notification settings - Fork 0
/
bg_updates.php
57 lines (42 loc) · 2.13 KB
/
bg_updates.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
<?php
/* ********************************************** *
* Updating Room Status *
* (Current time > end time = Session End) *
* (Current Time >= start time = In Use) *
* *********************************************** */
//connect to database
include_once ('dbcons.php');
//set Timezone
date_default_timezone_set('Singapore');
//get current date
$currentDate = date('Y-m-d');
//get current time
$currentTime = date('H:i');
/******************** Current Updates ******************/
//Booked to In Use
$query = "SELECT `session` , `room_num` FROM `booking` WHERE `date` = '".$currentDate."' ";
$query_run = mysqli_query($conn, $query);
if(mysqli_num_rows($query_run) > 0){
while($row = mysqli_fetch_array($query_run)){
$room_ID = $row['room_num'];
$dbSession = $row['session'];
$startTime = substr($dbSession, 0,5); //assigning start time
$endTime = substr($dbSession, -5); //assigning end time
if(strcmp($startTime, $currentTime) <= 0){
$query2 = "UPDATE `booking` SET `status` = 'In Use' WHERE `room_num` = '".$room_ID."' AND `date` = '".$currentDate."' AND `session` = '".$dbSession."' ";
mysqli_query($conn, $query2);
}
if(strcmp($endTime, $currentTime) <= 0){
$query2 = "UPDATE `booking` SET `status` = 'Session End' WHERE `room_num` = '".$room_ID."' AND `date` = '".$currentDate."' AND `session` = '".$dbSession."' ";
mysqli_query($conn, $query2);
}
}
}
/******************** End Of Current Updates ******************/
/******************** Day Before Updates ******************/
$query = "UPDATE `booking` SET `status` = 'Session End' WHERE `date` < '".$currentDate."' ";
mysqli_query($conn, $query);
/******************** End Of Day Before Updates ******************/
//Disconnect From Database
mysqli_close($conn);
?>