-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpendingRequests.php
More file actions
100 lines (88 loc) · 2.8 KB
/
pendingRequests.php
File metadata and controls
100 lines (88 loc) · 2.8 KB
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
<?php
header("Content-type:application/json");
$_SERVER['CONTENT_TYPE'] = "application/x-www-form-urlencoded";
error_reporting (E_ALL ^ E_WARNING && E_NOTICE);
// Pending request class
class PendingRequest {
var $requestType;
var $userID;
var $userName;
var $courseID;
var $courseName;
var $roomID;
var $dayOfWeek;
var $slot;
var $length;
var $generalReason;
var $message;
function __construct () {
$this->requestType = "";
$this->userID = "";
$this->userName = "";
$this->courseID = "";
$this->courseName = "";
$this->roomID = "";
$this->dayOfWeek = "";
$this->slot = "";
$this->length = "";
$this->generalReason = "";
$this->message = "";
}
}
// Response class
class PendingRequestResponse {
var $successful;
var $pendingRequests;
var $requestsFound;
function __construct () {
$this->successful = false;
$this->requestsFound = false;
$this->pendingRequests = array();
}
}
//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);
}
// Get the pending requests using view_pending_requests
$pendingRequestsQ = "SELECT * FROM db_classroom_management.view_pending_requests;";
// Run query
$pendingRequestsResult = mysqli_query($conn, $pendingRequestsQ);
$requestNo = mysqli_num_rows($pendingRequestsResult);
// If requests are present, alot them in the array and return the array. Else, send unsuccessful response
$response = new PendingRequestResponse();
if ($requestNo > 0) {
$response->successful = true;
$response->requestsFound = true;
while ($row = mysqli_fetch_assoc($pendingRequestsResult)) {
// Load up the variables from each row
$temp = new PendingRequest();
$temp->requestType = $row['request_type'];
$temp->courseID = $row['course_id'];
$temp->courseName = $row['course_name'];
$temp->userID = $row['requestor'];
$temp->userName = $row['teacher_first_name'] . " " . $row['teacher_last_name'];
$temp->roomID = $row['room_id'];
$temp->dayOfWeek = $row['day_of_week'];
$temp->slot = $row['slot'];
$temp->length = $row['class_length'];
$temp->generalReason = $row['general_reason'];
$temp->message = $row['message'];
// Load up the class in the array
$response->pendingRequests[] = $temp;
}
echo (json_encode($response));
} else {
// Set requestsFound variable to false and send the reply
$response->successful = true;
$response->requestsFound = false;
echo (json_encode($response));
return;
}
?>