-
Notifications
You must be signed in to change notification settings - Fork 6
/
student_test.php
374 lines (357 loc) · 9.57 KB
/
student_test.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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
<?php
session_start();
$Exam_id=$_SESSION['Exam_id'];
$Stu_exam=$_SESSION['Stu_exam'];
if($Exam_id==true)
{
?>
<!DOCTYPE html>
<html>
<head>
<title>Test Home</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!--===============================================================================================-->
<link rel="icon" type="image/png" href="images/icons/favicon.ico"/>
<!--===============================================================================================-->
<link rel="stylesheet" type="text/css" href="vendor/bootstrap/css/bootstrap.min.css">
<!--===============================================================================================-->
<link rel="stylesheet" type="text/css" href="fonts/font-awesome-4.7.0/css/font-awesome.min.css">
<!--===============================================================================================-->
<link rel="stylesheet" type="text/css" href="vendor/animate/animate.css">
<!--===============================================================================================-->
<link rel="stylesheet" type="text/css" href="vendor/css-hamburgers/hamburgers.min.css">
<!--===============================================================================================-->
<!--<link rel="stylesheet" type="text/css" href="vendor/select2/select2.min.css">-->
<!--===============================================================================================-->
<link rel="stylesheet" type="text/css" href="css/util.css">
<link rel="stylesheet" type="text/css" href="css/main.css">
<link rel="stylesheet" type="text/css" href="css/stud_test.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script>
var no_ques;
var ans_string="";
var radiobtn="z";
function formatTime(seconds) {
var h = Math.floor(seconds / 3600),
m = Math.floor(seconds / 60) % 60,
s = seconds % 60;
if (h < 10) h = "0" + h;
if (m < 10) m = "0" + m;
if (s < 10) s = "0" + s;
return h + ":" + m + ":" + s;
}
var count = 20;//give the duration of timer here
var counter = setInterval(timer, 1000);
function timer() {
count--;
//if (count < 0) return clearInterval(counter);
if (count == 0)
{
storeans();
alert("Test Has Ended..!!!");
window.location.href="php/calculate_result.php";
}
document.getElementById('timer').innerHTML = formatTime(count);
}
function fun(a,b)
{
var variab;
var elem;
if(a==0)
a=1;
if(a<=no_ques)
{
for(i=1;i<=b;i++)
{
if(i!=a)
{
variab='form'+i;
elem=document.getElementById(variab);
elem.style.display = "none";
}
else
{
variab='form'+a;
elem=document.getElementById(variab);
elem.style.display = "block";
}
}
}
}
function fun2(x)
{
l=ans_string.length;
ans_string=ans_string.substring(0,x)+radiobtn+ans_string.substring(x+1,l);
radiobtn="z";
console.log(ans_string);
}
function colorc(x)
{
y="btn"+(x+1);
//console.log(y);
elem2=document.getElementById(y);
elem2.style.backgroundColor="#4CAF50";
elem2.style.color="white";
}
function unselect(x)
{
y="btn"+(x+1);
ans_string=ans_string.substring(0,x)+"f"+ans_string.substring(x+1,l);
console.log(ans_string);
elem2=document.getElementById(y);
elem2.style.backgroundColor="white";
elem2.style.color="black";
}
function unselectradio(x)
{
var ele = document.getElementsByName("indoor-outdoor"+x);
for(var i=0;i<ele.length;i++)
ele[i].checked = false;
}
function clicka()
{
radiobtn="a";
}
function clickb()
{
radiobtn="b";
}
function clickc()
{
radiobtn="c";
}
function clickd()
{
radiobtn="d";
}
function storeans()
{
sessionStorage.setItem("ans", ans_string);
}
document.onkeydown = function(event)
{
/*switch (event.keyCode) {
case 116: //F5 button
event.returnValue = false;
event.keyCode = 0;
return false;
case 82: //R button
if (event.ctrlKey) {
event.returnValue = false;
event.keyCode = 0;
return false;
}
case 27: //esc button
if (event.ctrlKey) {
event.returnValue = false;
event.keyCode = 0;
return false;
}
} */
}
var ss=2;
document.addEventListener('contextmenu', event => event.preventDefault());
$(document).keyup(function(e){
if(e.which==122 && ss!=0){
ss=ss-1;
e.preventDefault();//kill anything that browser may have assigned to it by default
//do what ever you wish here :)
if(ss==1)
{
alert('F11 pressed again and test will be ended ☺☺!!');
}
return false;
}
else if(e.which==122)
{
alert("bye bye");
sessionStorage.setItem("ans", ans_string);
window.open("./php/calculate_result.php","_self");
}
});
</script>
<style>
.questionl
{
overflow-y:scroll;
overflow-x:scroll;
}
.button-pane
{
width: 230px;
height: 500px;
overflow-y:scroll;
overflow-x:hidden;
margin-left:20px;
}
.btn_ques{
width:50px;
height:33px;
font-size: 24px;
border: 2px groove #4CAF50;
margin: 2px;
}
.btn_ques:hover{
background-color: #4CAF50;
color: white;
}
.btn_ques:onmouseleave{
background-color:white;
color:black;
}
#navcolor{
background-color:black;
}
#bbtn{
margin-left:36px;
}
</style>
</head>
<body onload="fun(1,1000)">
<nav class="navbar navbar-inverse" id="navcolor">
<div class="container-fluid">
<a href="#" class="navbar-left"><img src="images/logom.png"></a>
<div class="navbar-header">
<a class="navbar-brand" style="color:white">Test Has Started.. All the Best</a>
</div>
<div id="timerstuff" >
<ul class="nav navbar-nav">
<li class="active">
<div style="color:white">
<b>Time left</b>
<p id="timer" style="color:white"></p></li>
</ul>
<a href="php/calculate_result.php" onclick="storeans();">
<button class="btn btn-danger navbar-btn" id="bbtn" >End Test</button>
</a>
</div>
</div>
</nav>
<div>
<div class="button-pane" id="navai" style="position:fixed;height:560px;">
<?php
//echo "Hello";
$con=mysqli_connect("172.31.100.41","quizmnnit","quizportal123","dbquizmnnit");
//$examid = $_POST['email'];
$query="SELECT * FROM `Test_Info` WHERE Exam_id='$Exam_id' ";
$result=mysqli_query($con,$query);
$row=mysqli_fetch_assoc($result);
$nos=$row['No_Ques'];
echo "<script>
no_ques=$nos;
</script>";
for($x=1;$x<=$nos;$x++)
{?>
<script>
ans_string+="f";
</script>
<?php}
//echo "the result is ".$nos;
for($x=1;$x<=$nos;$x++)
{ ?>
<button type="submit" class="btn_ques" onclick="fun(<?= $x ?>,<?= $nos ?>)" id="btn<?= $x ?>"><?= $x ?></button>
<?php
if($x%3==0)
echo "<br>";
}
mysqli_close($con);
?>
</div >
<div id="questions">
<div class="questionl" id="rcorners35">
<div class="container-fluid well" >
<?php
$con=mysqli_connect("172.31.100.41","quizmnnit","quizportal123","dbquizmnnit");
//$examid = $_POST['email'];
$tb="question_" . $Exam_id;
$query="SELECT * FROM `$tb`";
if($result=mysqli_query($con,$query))
{?>
<?php
while($row=mysqli_fetch_assoc($result))
{
$qid=$row['Qid'];
$question=$row['Question'];
$opa=$row['OpA'];
$opb=$row['OpB'];
$opc=$row['OpC'];
$opd=$row['OpD'];
?>
<form class="div_ques" id="form<?= $qid ?>" >
<div class="row">
<div class="col-sm-12 well" style="background-color:#b3ffb3">
<p>Q<?= $qid ?>. <?= $question ?></p>
</div>
</div>
<div class="row well" style="background-color:#DCDCDC"><!--#BDFBFF-->
<div class="col-sm-12">
<label><input type="radio"name="indoor-outdoor<?= $qid ?>" onclick="clicka(); fun2(<?= $qid-1 ?>); colorc(<?= $qid-1 ?>);"><?= $opa ?></label>
</div>
</div>
<div class="row well" style="background-color:#DCDCDC">
<div class="col-sm-12">
<label><input type="radio"name="indoor-outdoor<?= $qid ?>" onclick="clickb(); fun2(<?= $qid-1 ?>); colorc(<?= $qid-1 ?>);"><?= $opb ?></label>
</div>
</div>
<div class="row well" style="background-color:#DCDCDC">
<div class="col-sm-12">
<label><input type="radio"name="indoor-outdoor<?= $qid ?>" onclick="clickc(); fun2(<?= $qid-1 ?>); colorc(<?= $qid-1 ?>);"><?= $opc ?></label>
</div>
</div>
<div class="row well" style="background-color:#DCDCDC">
<div class="col-sm-12" >
<label><input type="radio"name="indoor-outdoor<?= $qid ?>" onclick="clickd(); fun2(<?= $qid-1 ?>); colorc(<?= $qid-1 ?>)"><?= $opd ?></label>
</div>
</div>
<br>
<div class="row">
<div class="col-sm-4">
<div class="row">
<div class="col-sm-4">
<button class="btn btn-block btn-primary" type='button' onclick="fun(<?= $qid-1 ?>,<?= $qid ?>)">Previous</button>
</div>
<div class="col-sm-4"></div>
<div class="col-sm-4"></div>
</div>
</div>
<div class="col-sm-4">
<div class="row">
<div class="col-sm-4"></div>
<div class="col-sm-4">
<button class="btn btn-block btn-danger" type='button' onclick="unselect(<?= $qid-1 ?>); unselectradio(<?= $qid ?>);">Undo</button>
</div>
<div class="col-sm-4"></div>
</div>
</div><div class="col-sm-4">
<div class="row">
<div class="col-sm-4"></div>
<div class="col-sm-4"></div>
<div class="col-sm-4">
<button class="btn btn-block btn-primary" type='button' onclick="fun(<?= $qid+1 ?>,<?= $qid+1 ?>)">Next</button>
</div>
</div>
</div>
</div>
</form>
<?php
}
}
mysqli_close($con);
?>
</div ><!--div in which forms of questions-->
</div><!-- questionl-->
</div><!--questions-->
</div><!--buttonpane+question pane-->
</body>
<!--<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>-->
</html>
<?php
}
else
{
header('locaion:./student.php');
}
?>