-
Notifications
You must be signed in to change notification settings - Fork 0
/
question.php
169 lines (124 loc) · 5.25 KB
/
question.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
<!-- Connecting to the Database -->
<?php
include 'includes/dbc.php';
include 'includes/question-backend.php';
// Running question-backend.php code:
$lessonName = getLessonName($quizID); // setting the lesson name
// $quizID = $_GET['id']; // storing the subject id: used for generating questions
// Loading quiz: Checking if the user has started the quiz
if (isset($_POST['questionNum'])) { // if the questionNum is set, quiz must be in progress
$score = $_POST['score']; // storing the players score
// Loading the next qustion
if ($questionNum < 10) {
$currentQuestion = $questions[$questionNum];
} else if ($questionNum = 10) {
$currentQuestion = $questions[$questionNum-1];
}
}
// Starting a quiz: generate questions, assign current question
else {
$_SESSION['answerList'] = []; // resetting the answer list session var
$_SESSION['score'] = 0; // resetting the score
$questions = getQuestions($quizID); // generating the question pool using the subject id
$currentQuestion = $questions[$questionNum]; // setting first question from pool
}
// Setting session vairables
$_SESSION['questions'] = $questions; // setting questions array as a session vairable
// TESTING: Itterating through the questions array
foreach($questions as $q) {
$qID = GetQuestionID($q); // getting the questions id
// echo $qID . " - " . $q . "<br>"; // printing the question with ID
}
// Setting the current questions id and text
?>
<!-- Start of HTML Page -->
<!DOCTYPE html>
<html lang="en">
<!-- Constants.php should incude: Site title & other constants -->
<?php include 'includes/constants.php'; ?>
<head>
<title><?php echo $title ?></title>
<?php include 'includes/head.php'; ?>
<?php // include 'includes/scripts.php'; TESTING: do we need this in the head of the page? ?>
<script type="text/javascript" src="js/progress-bar.js"></script>
</head>
<body>
<div id="background-image"></div>
<div id="body-wrapper">
<?php include 'includes/header.php'; ?>
<div class="title-page">
<div id="title-container">
<!-- Printing the lesson subject name to the page -->
<h1 class="lesson-title"><?php echo $lessonName; ?></h1>
<pre class="score-text"><?php echo "Score: " . $_SESSION['score'] ?></pre>
</div>
</div>
<div class="question-content-wrapper">
<div class="question-container">
<!-- Printing the current question to the page -->
<p id="question-text"><?php echo $currentQuestion; ?></p>
</div>
<?php
// Vairables:
$questionText = $currentQuestion;
$questionID = getQuestionID($currentQuestion);
// Checking the question type
$qT = checkQuestionType($currentQuestion); //
// Multi-choice ONLY question
if ($qT['questionType'] == 'multi') {
$type = $qT['questionType'];
include 'includes/multi-choice.php';
}
// Text-box ONLY question
else if ($qT['questionType'] == 'text') {
$type = $qT['questionType'];
include 'includes/text-box.php';
}
// Both question types
else {
$randQuestionType = mt_rand(1, 2); // generate a random number between 1 & 2
// Assigning 1 : multi-choice and 2 : text-box
if ($randQuestionType == 1) {
$type = "multi";
include 'includes/multi-choice.php';
}
else {
$type = "text";
include 'includes/text-box.php';
}
}
include 'includes/results-loading.php';
// Setting data for JS-Info
if (!isset($randQuestionType)) {
$randQuestionType = 0;
}
?>
</div>
<div class="progress-wrapper-overide">
<div class="progress-wrapper">
<div class="progress">
<div class="progress-done" data-done="<?php echo $progress; ?>"></div>
</div>
<p class="progress-text"></p>
<form id="next-question-form" name="question" action="question.php?id=<?php echo $quizID ?>" method="post">
<input class="hidden user-answer" name="userAnswer" value="">
<input class="hidden next-question" name="questionNum" value="<?php echo $questionNum; ?>">
<input class="hidden score" name="score" value="<?php echo $score; ?>">
<input class="hidden progress" name="progress" value="<?php echo $progress; ?>">
<button type="button" id="next-question" name="" value="" onClick="validateForm()">Next Question</button>
</form>
</div>
</div>
</div>
<div class="hidden js-info" style="display: flex; flex-direction: column; align-items: center;">
<div class="hidden lesson-id"><?php echo $quizID ?></div>
<div class="hidden questions-length"><?php echo count($questions); ?></div> <?php echo 'count($questions): ' . count($questions); ?>
<div class="hidden question-num"><?php echo $questionNum; ?></div> <?php echo '$questionsNum: ' . $questionNum; ?>
<div class="question-type"><?php echo $type; ?></div>
<div class="hidden correct-answers"><?php allCorrectAnswers($questionID); ?></div>
<div class="hidden question-array"><?php foreach($questions as $q) {echo "$q~";} ?></div>
</div>
<?php include 'includes/scripts.php'; ?>
<script type="text/javascript" src="js/quiz-pages.js"></script>
</body>
</html>