This repository has been archived by the owner on Sep 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sessions.php
59 lines (48 loc) · 1.81 KB
/
sessions.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
<?php
/*
Retrieves available classroom sessions for a course, given the course ID
Client must determine whether the session is full by evaluating NumEnrolled == MaxCapacity
Andrew Park - 20/07/2016
*/
header('Access-Control-Allow-Origin: *');
require "config.php";
$list_sessions = array();
$conn = mssql_connect($host, $username, $password)
or die("Unable to connect to mssql");
$selected = mssql_select_db($db_name, $conn)
or die("Could not select CCRS db");
if (isset($_GET["id"])) {
$q = "
DECLARE @sid INTEGER
DECLARE @num INTEGER
DECLARE @now DateTime
SET @now = GETDATE()
SELECT SessionID, StartDate, Location, MaxCapacity INTO #Tmp
FROM tblSessions
WHERE StartDate > @now AND Status = 1 AND CourseID = " . $_GET["id"] .
"
ALTER TABLE #Tmp ADD NumEnrolled INTEGER
DECLARE C CURSOR
LOCAL STATIC READ_ONLY FORWARD_ONLY
FOR
SELECT SessionID FROM tblSessions WHERE StartDate > @now AND Status = 1 AND CourseID = " . $_GET["id"] .
"
OPEN C
FETCH NEXT FROM C INTO @sid
WHILE @@FETCH_STATUS = 0 BEGIN
SET @num = (SELECT COUNT(*) FROM tblRegisterlist WHERE SessionID = @sid)
UPDATE #Tmp SET NumEnrolled = @num WHERE SessionID = @sid
FETCH NEXT FROM C INTO @sid
END
CLOSE C
SELECT * FROM #Tmp
";
$result = mssql_query($q);
while ($row = mssql_fetch_assoc($result)) {
array_push($list_sessions, $row);
}
echo json_encode($list_sessions);
} else {
echo "No course ID supplied";
}
?>