-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathViewQuiz.php
206 lines (178 loc) · 8.75 KB
/
ViewQuiz.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
<?php
require_once 'sidebar.php';
renderSideBar((isset($_POST['mode']))?"hostedQuizStats":"myResults");
require_once 'backend/connector.php';
function getQuestionTableFromInt($s){
$a = array(0=>array("TextQns","tqid"), 1=>array("TextQns","tqid"), 2=>array("CheckboxQns","cbqid"), 3=> array("MCQ","mid"));
return $a[$s];
}
function getQuestionTypeInt($s){
$a = array(3=>"radio",2=>"checkbox",1=>"loose_text",0=>"strict_text");
return $a[$s];
}
function getUserAnswer($qnsid, $sort){
global $conn;
$uid = $_SESSION['uid'];
if(isset($_POST['mode'])){
$uid = $_POST['uid'];
}
$stmt = $conn->prepare("SELECT * FROM Answers WHERE qnsid = ? AND userid = ?");
$stmt->bind_param('ii', $qnsid, $uid);
if ($stmt->execute() == TRUE) {
$result = $stmt->get_result();
$row = $result->fetch_assoc();
if($sort == true){
$ansArray = explode(",",$row['ans']);
unset($ansArray[count($ansArray)-1]);
sort($ansArray);
$row['ans'] = implode(",",$ansArray);
}
return $row;
}
return "";
}
if(!isset($_POST['qid'])){
header("Location: http://{$_SERVER['SERVER_NAME']}/QuizKeeper/myResults.php");
}
$postData = explode(",",$_POST['qid']);
$qid = $postData[0];
$totalUsers = $postData[1];
$stmt = $conn->prepare("SELECT Quiz.qid as qid,title,description,fromdate,todate,count(Questions.qnsid) as qcount FROM Quiz,Questions where Quiz.qid=Questions.qid and Quiz.qid=? GROUP BY Quiz.qid");
$stmt->bind_param('i',$qid);
if($stmt->execute()==TRUE) {
$result = $stmt->get_result();
$row = $result->fetch_assoc();
/*-------------------FETCH QUESTIONS OF THIS QUIZ--------------------------*/
$questionStmt = $conn->prepare("SELECT * FROM Questions WHERE qid=?");
$questionStmt->bind_param('i',$qid);
$obtainedMarks = 0;
$totalMarks = 0;
$questionsDetails = array();
if($questionStmt->execute() == TRUE){
$q_result = $questionStmt->get_result();
while($q_row = $q_result->fetch_assoc()){
$tempQ = $q_row;
$totalMarks += $q_row['marks'];
$q_table = getQuestionTableFromInt($q_row['type']);
$query = "SELECT * FROM " . $q_table[0] . " WHERE " . $q_table[1] . " = ?";
$qt_stmt = $conn->prepare($query);
$qt_stmt->bind_param("i", $q_row['xid']);
if ($qt_stmt->execute() === TRUE) {
$singleResult = $qt_stmt->get_result();
while($singleQ = $singleResult->fetch_assoc()){
if(isset($singleQ['correctans'])) {
$ansArray = explode(",",$singleQ['correctans']);
sort($ansArray);
$tempQ['true_answer'] = implode(",",$ansArray);
}
else
$tempQ['true_answer'] = ($q_row['type'] == 0)?$singleQ['ans']:"<span class='badge badge-info'>MANUAL EVALUATION</span>";
$ans = getUserAnswer($q_row['qnsid'],($q_row['type'] == 2)?true:false);
$tempQ['type'] = $q_row['type'];
$tempQ['mark'] = $q_row['marks'];
$tempQ['user_answer'] = $ans['ans'];
$tempQ['question'] = $singleQ['qns'];
$tempQ['ansid'] = $ans['ansid'];
$tempQ['obtain_mark'] = 0;
$tempQ['marks_granted'] = $ans['marks_granted'];
if($ans['marks_granted'] == TRUE || $tempQ['user_answer'] == $tempQ['true_answer']){
$obtainedMarks += $q_row['marks'];
$tempQ['obtain_mark'] = $q_row['marks'];
}
if(strlen($tempQ['user_answer']) == 0) $tempQ['user_answer'] = "<span class='badge badge-info'>Not Attempted</span>";
// print_r($tempQ);
}
array_push($questionsDetails, $tempQ);
}
}
}
?>
<script src="js/controller.js"></script>
<div class="content ml-3 mr-3">
<h3><span class="badge badge-success"><?php echo $row['title'];?></span></h3>
<div class="row justify-content-center">
<div class="col-lg-4 col-md-4 col-sm-12">
<div class="card card-stats">
<div class="card-header card-header-success card-header-icon p-2">
<div class="card-icon">
<i class="material-icons">quiz</i>
</div>
<p class="card-category">Questions</p>
<h3 class="card-title">
<?php echo $row['qcount']; ?>
</h3>
</div>
</div>
</div>
<div class="col-lg-4 col-md-4 col-sm-12">
<div class="card card-stats">
<div class="card-header card-header-success card-header-icon p-2">
<div class="card-icon">
<i class="material-icons">verified</i>
</div>
<p class="card-category">Marks obtained</p>
<h3 class="card-title">
<?php echo $obtainedMarks."/".$totalMarks; ?>
</h3>
</div>
</div>
</div>
<div class="col-lg-4 col-md-4 col-sm-12">
<div class="card card-stats">
<div class="card-header card-header-success card-header-icon p-2">
<div class="card-icon">
<i class="material-icons">people</i>
</div>
<p class="card-category">Total Users Attempted</p>
<h3 class="card-title">
<?php echo $totalUsers; ?>
</h3>
</div>
</div>
</div>
</div>
<div class="row justify-content-center mt-5">
<div class="card">
<div class="card-header card-header-info">
<h4 class="card-title">Evaluation Details <?php if(isset($_POST['mode'])) echo " of ".$_POST['uname']; ?></h4>
<p class="card-category">Check and compare your answers with correct one</p>
</div>
<div class="card-body table-responsive">
<table class="table table-striped table-hover">
<thead class="text-info">
<tr><th>No</th>
<th>Question</th>
<th>Correct Answer</th>
<th>Your Answer</th>
<th>Marks</th>
</tr></thead>
<tbody>
<?php
$start = 1;
foreach ($questionsDetails as $ui_question){
?>
<td><?php echo $start; $start++; ?></td>
<td><?php echo $ui_question['question'] ?></td>
<td><?php echo $ui_question['true_answer']; ?></td>
<td style="background:<?php echo
($ui_question['type'] != 1)?($ui_question['marks_granted'] == TRUE || $ui_question['user_answer'] == $ui_question['true_answer'])?'#198754':'#dc3545' : '#fd7e14'?> " class="text-white"><?php echo $ui_question['user_answer']; ?></td>
<td>
<span class="badge <?php echo ($ui_question['obtain_mark'] == 0)?'badge-danger':'badge-success
'?>">
<span id="marks_<?php echo $ui_question['ansid'];?>"> <?php echo $ui_question['obtain_mark']?></span> <?php echo "/".$ui_question['mark']; ?>
</span>
<?php if(isset($_POST['mode']) && $ui_question['type'] == 1 && $ui_question['marks_granted'] == FALSE){ ?>
<button class="btn btn-sm btn-success" onclick="updateManualQuestion(<?php echo $ui_question['ansid']?>,<?php echo $ui_question['mark']?>)">give marks</button>
<?php }?>
</td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
<?php
}
?>