-
Notifications
You must be signed in to change notification settings - Fork 0
/
roomStatusResponse.php
84 lines (72 loc) · 2.21 KB
/
roomStatusResponse.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
<?php
header("Content-type:application/json");
$_SERVER['CONTENT_TYPE'] = "application/x-www-form-urlencoded";
error_reporting (E_ALL ^ E_WARNING && E_NOTICE);
//Response object
class RoomStatus {
var $classDate;
var $roomID;
var $courseName;
var $teacherFirstName;
var $teacherLastName;
var $classLength;
var $attendance;
function __construct($roomID)
{
$this->classDate = "";
$this->roomID = $roomID;
$this->courseName = "";
$this->teacherFirstName = "";
$this->teacherLastName = "";
$this->classLength = 0;
$this->attendance = 0;
}
}
//Response class
class RoomStatusResponse {
var $roomIsActive;
var $roomResponse;
function __construct ($roomID) {
$this->roomIsActive = false;
$this->roomResponse = new RoomStatus($roomID);
}
}
//Connection properties
$servername = "localhost";
$username = "root";
$password = "admin";
//Create connection
$conn = new mysqli($servername, $username, $password);
//Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
//Extract roomID from POST
$roomID = $_POST["roomID"];
//Run query for room status checking
$roomStatusQuery = "SELECT * FROM db_classroom_management.view_room_status where room_id=".$roomID;
$roomStatusQueryResult = mysqli_query($conn, $roomStatusQuery);
//Handle room status response
$numberOfRows = mysqli_num_rows($roomStatusQueryResult);
$response = new RoomStatusResponse($roomID);
if ($numberOfRows >= 1) {
$response->roomIsActive = true;
while ($row = mysqli_fetch_assoc($roomStatusQueryResult)) {
$temp = new RoomStatus($roomID);
$temp->classDate = $row['class_date'];
$temp->roomID = $row['room_id'];
$temp->courseName = $row['course_name'];
$temp->teacherFirstName = $row['teacher_first_name'];
$temp->teacherLastName = $row['teacher_last_name'];
$temp->classLength = $row['class_length'];
$temp->attendance = $row['attendance'];
if ($temp->attendance == 0) {
$temp->attendance = -1;
}
$response->roomResponse = $temp;
}
} else {
$response->roomIsActive = false;
}
echo json_encode($response);
?>