-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_run.php
222 lines (204 loc) · 9.2 KB
/
test_run.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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
<?php require_once('include/top.php');
if (!isset($_SESSION['username'])) {
header('Location: login.php');
}
$session_role6 = $_SESSION['role'];
?>
<?php require_once('include/config.php'); ?>
<?php require_once('server.php'); ?>
<?php include_once('dao/quizDao.php');?>
<?php
$asmnt_name = $_GET['assessment_name'];
$quizDao = new quizDao($db);
//$b = $_GET['module'];
if ($_GET['page'] == "create_assessment") {
$quizDao->createAssessment($asmnt_name, $_GET['module'], '1' );
}
if ($_GET['page'] == "mc") {
if ($_GET['question_content']) {
//echo $_GET['question_content'];
$sql = "INSERT INTO registration.questions (content, type, assessment_id)
SELECT '${_GET['question_content']}','mc', assmnt.id
from registration.assessments assmnt where name= '$asmnt_name'";
if ($db->query($sql) === TRUE) {
//New record created successfullyully<br>";
} else {
echo "Error: " . $sql . "<br>" . $db->error;
}
//$conn->close();
$question_id= $db->insert_id;
echo "question id: ", $question_id, "<br>";
$correct_answer = $_GET['correct_input'] == 'r1' ? "y" : "n";
$sql_answer = "INSERT INTO registration.answers (answer, correct, question_id, assessment_id)
SELECT '${_GET['mc_1']}', '$correct_answer', $question_id, assmnt.id
from registration.assessments assmnt where name= '$asmnt_name'";
if ($db->query($sql_answer) === TRUE) {
//New record created successfullyully";
} else {
echo "Error: " . $sql_answer . "<br>" . $db->error;
}
$correct_answer = $_GET['correct_input'] == 'r2' ? "y" : "n";
$sql_answer = "INSERT INTO registration.answers (answer, correct, question_id, assessment_id)
SELECT '${_GET['mc_2']}', '$correct_answer', $question_id, assmnt.id
from registration.assessments assmnt where name= '$asmnt_name'";
if ($db->query($sql_answer) === TRUE) {
//New record created successfullyully";
} else {
echo "Error: " . $sql_answer . "<br>" . $db->error;
}
$correct_answer = $_GET['correct_input'] == 'r3' ? "y" : "n";
$sql_answer = "INSERT INTO registration.answers (answer, correct, question_id, assessment_id)
SELECT '${_GET['mc_3']}', '$correct_answer', $question_id, assmnt.id
from registration.assessments assmnt where name= '$asmnt_name'";
if ($db->query($sql_answer) === TRUE) {
//New record created successfullyully";
} else {
echo "Error: " . $sql_answer . "<br>" . $db->error;
}
$correct_answer = $_GET['correct_input'] == 'r4' ? "y" : "n";
$sql_answer = "INSERT INTO registration.answers (answer, correct, question_id, assessment_id)
SELECT '${_GET['mc_4']}', '$correct_answer', $question_id, assmnt.id
from registration.assessments assmnt where name= '$asmnt_name'";
if ($db->query($sql_answer) === TRUE) {
//New record created successfullyully";
} else {
echo "Error: " . $sql_answer . "<br>" . $db->error;
}
}
}
else if ($_GET['page'] == "fill") {
if ($_GET['question_content']) {
//echo $_GET['question_content'];
$sql = "INSERT INTO registration.questions (content, type, assessment_id)
SELECT '${_GET['question_content']}','fi', assmnt.id
from registration.assessments assmnt where name= '$asmnt_name'";
//echo $sql;
if ($db->query($sql) === TRUE) {
//New record created successfullyully<br>";
} else {
echo "Error: " . $sql . "<br>" . $db->error;
}
//$conn->close();
$question_id= $db->insert_id;
echo "question id: ", $question_id, "<br>";
$sql_answer = "INSERT INTO registration.answers (answer, correct, question_id, assessment_id)
SELECT '${_GET['option_blank']}','y', $question_id, assmnt.id
from registration.assessments assmnt where name= '$asmnt_name'";
//echo $sql_answer;
//echo $sql;
if ($db->query($sql_answer) === TRUE) {
//New record created successfullyully";
} else {
echo "Error: " . $sql_answer . "<br>" . $db->error;
}
}
}
?>
</head>
<body>
<div id="wrapper">
<?php require_once('include/header.php'); ?>
<div class="container-fluid body-section">
<div class="row">
<div class="col-md-3">
<?php require_once('include/left-sidebar.php'); ?>
<table class="table">
<tbody>
<?php
if ($session_role6 == 'instructor') {
?>
<tr>
<td>
<form action="mc_q.php">
<input type="submit" value="Multiple Choice" name="submit_mc" class="btn btn-primary">
<input type="hidden" name="assessment_name" value= "<?php echo $_GET['assessment_name'] ?>" >
</form>
</td>
<td>
<form action="fill_in.php">
<input type="submit" value="Fill in the blank" name="submit_fill_in" class="btn btn-primary">
<input type="hidden" name="assessment_name" value= "<?php echo $_GET['assessment_name'] ?>" >
</form>
</td>
</tr>
<tr>
<td colspan=2 align="center">
<form action="allreports.php">
<input type="submit" value="Done" name="submit_done" class="btn btn-primary">
</form>
</td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
<div class="col-md-9">
<?php
$query = "select module_name from registration.modules where id = ".$_GET['module'].";";
if ($result = $db->query($query)) {
/* fetch associative array */
while ($row = $result->fetch_assoc()) {
$b = $row['module_name'];
}
/* free result set */
$result->free();
}
?>
<h1><i class="fa fa-graduation-cap" aria-hidden="true"></i> <?php echo $_GET['assessment_name'] ?> <br><small><?php echo $b ?></small></h1>
<hr>
<ol class="breadcrumb">
<li><a href="home.php"><i class="fa fa-tachometer"></i> Dashboard</a></li>
<li><a href="assessments.php">Assessments</a></li>
<li class="active"><?php echo $_GET['assessment_name'] ?></li>
</ol>
</div>
<div class="col-md-6">
<form action="test_result.php">
<?php
$assessment_id = 0;
$i=0;
$query = "select a.name, q.content, q.type, q.assessment_id, q.id from registration.questions
q join registration.assessments a on a.id = q.assessment_id where a.name ='$asmnt_name'";
if ($result = $db->query($query)) {
/* fetch associative array */
while ($row = $result->fetch_assoc()) {
$i++;
?>
<div class="form-group">
<label for="num"><?=$i?>.</label>
<label for="question"><?=$row['content']?></label>
<?php
// checking what type of questions mc or fill_in
$answer_query = "select id, answer, correct from registration.answers where question_id=$row[id]";
if ($answer_result = $db->query($answer_query)) {
/* fetch associative array */
while ($answer_row = $answer_result->fetch_assoc()) {
if ($row['type'] == "mc") {?>
<div class="radio">
<label><input type="radio" name="question_<?=$row['id']?>"
<?=$answer_row['correct']=='y'?"checked=\"true\"":"" ?> value="<?=$answer_row['answer']?>">
<?=$answer_row['answer']?>
</label>
</div>
<?php }
else if ($row['type'] == "fi"){?>
<input type="text" name="question_<?=$row['id']?>" class="form-control" id="q1">
<?php }
}
}
$answer_result->free();?>
</div>
<?php
$assessment_id = $row['assessment_id'];
}
/* free result set */
$result->free();
}
?>
<input type="submit" value="Submit Test" name="submit_test" class="btn btn-primary">
<input type="hidden" name="assessment_name" value= "<?php echo $_GET['assessment_name'] ?>" >
<input type="hidden" name="assessment_id" value= "<?php echo $assessment_id ?>" >
</form>
</div>
</div>
<?php require_once('include/footer.php'); ?>