-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsession_process.php
126 lines (107 loc) · 5.74 KB
/
session_process.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
<?php
session_start();
//Connect to Database
include_once ("dbcons.php");
/* ****************************************************************** *
* Load Table Rows *
* ****************************************************************** */
//Initialize the sessioned data
$date = $_SESSION['selectedDate'];
$roomID = $_SESSION['roomNum'];
$roomName = $_SESSION['roomName'];
//set default time zone and fetches current time
date_default_timezone_set("Singapore");
$currentTime = date("H:i");
$currentDate = date("Y-m-d");
//set all existing session
$sessionList = Array("08:00 - 09:00", "09:00 - 10:00", "10:00 - 11:00", "11:00 - 12:00", "12:00 - 13:00", "13:00 - 14:00",
"14:00 - 15:00", "15:00 - 16:00", "16:00 - 17:00", "17:00 - 18:00", "18:00 - 19:00", "19:00 - 20:00",
"20:00 - 21:00", "21:00 - 22:00", "22:00 - 23:00", "23:00 - 00:00", "00:00 - 01:00", "01:00 - 02:00",
"02:00 - 03:00", "03:00 - 04:00", "04:00 - 05:00", "05:00 - 06:00", "06:00 - 07:00", "07:00 - 08:00");
//set array to store db values
$dbStatus = Array();
$dbSession = Array();
$query = "SELECT `status`, `session` FROM `booking` WHERE `room_num` = '".$roomID."' AND `date` = '".$date."' ";
$query_run = mysqli_query($conn, $query);
if(mysqli_num_rows($query_run) > 0){
while($row = mysqli_fetch_array($query_run)){
array_push($dbStatus, $row['status']);
array_push($dbSession, $row['session']);
}
}
//loops based on size of existing session
for($i = 0; $i < sizeof($sessionList); $i++){
//Check if there is data for selected date session
if(!empty($dbSession)){
//boolean expression to indicate whether the existing session and fetched session matched or not
$matched = false;
//looping based on size of fetched data from database
for($idb = 0; $idb < sizeof($dbSession); $idb++){
//determine whether the session matched with fetched session from db
if(strcmp($sessionList[$i], $dbSession[$idb]) == 0){
//boolean expressions became true when existing ssession and fetched session match
$matched = true;
break;
}
}
if($matched)
{
echo ' <tr>
<td>' . $date. '</td>
<td>' . $dbSession[$idb]. '</td> <input type="hidden" name="book[session]['.$i.']" value="'.$dbSession[$idb].'">
<td>' .$dbStatus[$idb]. '</td>
<td><input type="checkbox" name="book[chk]['.$i.']" disabled></input></td>
</tr>';
}
else{
$endTime = substr($sessionList[$i], -5);
if(strcmp($endTime, $currentTime) <= 0 AND $date == $currentDate){
echo ' <tr>
<td>' . $date. '</td>
<td>' . $sessionList[$i]. '</td> <input type="hidden" name="book[session]['.$i.']" value="'.$sessionList[$i].'">
<td>Session End</td>
<td><input type="checkbox" name="book[chk]['.$i.']" disabled></input></td>
</tr>';
}
else{
echo ' <tr>
<td>' . $date. '</td>
<td>' . $sessionList[$i]. '</td> <input type="hidden" name="book[session]['.$i.']" value="'.$sessionList[$i].'">
<td>Available</td>
<td><input type="checkbox" name="book[chk]['.$i.']"></input></td>
</tr>';
}
}
}
else{
$endTime = substr($sessionList[$i], -5);
if(strcmp($endTime, $currentTime) <= 0 AND $date == $currentDate){
echo ' <tr>
<td>' . $date. '</td>
<td>' . $sessionList[$i]. '</td> <input type="hidden" name="book[session]['.$i.']" value="'.$sessionList[$i].'">
<td>Session End</td>
<td><input type="checkbox" name="book[chk]['.$i.']" disabled></input></td>
</tr>';
}
else{
echo ' <tr>
<td>' . $date. '</td>
<td>' . $sessionList[$i]. '</td> <input type="hidden" name="book[session]['.$i.']" value="'.$sessionList[$i].'">
<td>Available</td>
<td><input type="checkbox" name="book[chk]['.$i.']"></input></td>
</tr>';
}
}
}
//Hidden Values
echo '
<input type="hidden" name="book[roomID]['.$i.']" value="'.$roomID.'">
<input type="hidden" name="book[roomName]['.$i.']" value="'.$roomName.'">
<input type="hidden" name="book[date]['.$i.']" value="'.$date.'">
';
/* ****************************************************************** *
* End Of Load Table Rows *
* ******************************************************************* */
//Disconnect From Database
mysqli_close($conn);
?>