2
////Returns a quiz object
3
////Parameters: (POST) objectID, quizNr, qVarNr, courseName, courseOccasion, login, password
4
////Returns: objectData
7
//Check if the sent login name is the same as the one stored in the session
8
if($_POST['loginName']==$_SESSION['loginName'] && $_POST['courseName']==$_SESSION['courseName'] && $_POST['quizNr']==$_SESSION['quizNr']){
10
//Prevents browsers (IE) from caching the response
11
header('Cache-Control: no-cache, must-revalidate');
12
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
13
//header('Content-type: application/json');
14
header('Content-type: application/json; charset=utf-8');
16
include "../../php/dbconnect.php";
18
//Check if the student is a praticipant of the course
19
$queryString="SELECT COUNT(*)
20
FROM Student, StudentCourseRegistration
21
WHERE Student.ssn=StudentCourseRegistration.studentSsn
22
AND Student.loginName=:LOGIN
24
AND courseOccasion=:COCCASION;";
25
$stmt = $pdo->prepare($queryString);
26
$stmt->bindParam(':LOGIN', $_POST['loginName']);
27
$stmt->bindParam(':CNAME', $_POST['courseName']);
28
$stmt->bindParam(':COCCASION', $_POST['courseOccasion']);
31
if($stmt->fetchColumn()==1) { //Student is registered for the course - COUNT result read from the first column of the next unread row (i.e. the first row)
33
//Check if quiz is open
34
$queryString="SELECT Quiz.opening, Quiz.closing
37
AND Quiz.courseName=:CNAME;";
38
$stmt = $pdo->prepare($queryString);
39
$stmt->bindParam(':QNR', $_POST['quizNr']);
40
$stmt->bindParam(':CNAME', $_POST['courseName']);
42
$quizDateTimes=$stmt->fetch(PDO::FETCH_ASSOC);
44
$now = new DateTime();
45
$opening = new DateTime($quizDateTimes['opening']);
46
$closing = new DateTime($quizDateTimes['closing']);
48
if($now<$opening) { //Quiz is not open yet
49
echo json_encode(array('Error' => 'Requested quiz is not open yet'));
51
} else if($now>$closing) { //Quiz is closed
52
echo json_encode(array('Error' => 'Requested quiz is closed'));
54
} // else continue (Not the best coding practice...)
56
} else { //Quiz does not exist
57
echo json_encode(array('Error' => 'Requested quiz does not exist'));
61
//Fetch quiz variant nr
62
$queryString="SELECT AssignedQuizzes.qVarNr
64
WHERE AssignedQuizzes.ssn=(SELECT Student.ssn FROM Student WHERE Student.ssn=AssignedQuizzes.ssn AND Student.loginName=:LOGIN)
65
AND AssignedQuizzes.quizNr=:QNR
66
AND AssignedQuizzes.quizCourseName=:CNAME
67
AND AssignedQuizzes.courseOccasion=:COCCASION;";
68
$stmt = $pdo->prepare($queryString);
69
$stmt->bindParam(':LOGIN', $_POST['loginName']);
70
$stmt->bindParam(':QNR', $_POST['quizNr']);
71
$stmt->bindParam(':CNAME', $_POST['courseName']);
72
$stmt->bindParam(':COCCASION', $_POST['courseOccasion']);
75
$quizAssignmentData=$stmt->fetch(PDO::FETCH_ASSOC);
76
$qVarNr=$quizAssignmentData['qVarNr'];
78
$queryString="SELECT QuizVariantObject.objectData
79
FROM QuizVariantObject
80
WHERE QuizVariantObject.id=:OID AND QuizVariantObject.quizNr=:QNR AND QuizVariantObject.qVarNr=:QVNR AND QuizVariantObject.quizCourseName=:CNAME;";
81
$stmt = $pdo->prepare($queryString);
82
$stmt->bindParam(':OID', $_POST['objectID']);
83
$stmt->bindParam(':QNR', $_POST['quizNr']);
84
$stmt->bindParam(':QVNR', $qVarNr);
85
$stmt->bindParam(':CNAME', $_POST['courseName']);
88
$quizVariantObject=$stmt->fetch(PDO::FETCH_ASSOC);
90
if(count($quizVariantObject)>0) {
91
$quizVariantObject['objectData']=htmlspecialchars_decode($quizVariantObject['objectData']);
92
echo json_encode($quizVariantObject);
95
echo json_encode(array('Error' => 'Object not found'));
99
echo json_encode(array('Error' => 'Student not registered for this course (or incorrect password was sent)'));
102
} else { //Sent login name does not match the login name stored in the session
103
echo json_encode(array('Error' => 'Sent login name does not match stored login name'));
b'\\ No newline at end of file'