-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquizehome.php
141 lines (123 loc) · 5.82 KB
/
quizehome.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
<?php
session_start();
if(isset($_GET['question'])){
$question= preg_replace('/[^0-9]/',"", $_GET['question']);
$next=$question + 1;
$prev=$question - 1;
if(isset($_SESSION['question']) && $_SESSION['question']== $question){
echo 'sorry, cheating is not allowed keep it moving <a href="quizhome.php?question='.$next.'">Continuse</a> ';
exit();
}
if($prev!=0){
if(isset($_SESSION['question']) && $_SESSION['question']== $question){
echo 'sorry, cheating is not allowed keep it moving <a href="quizhome.php?question='.$prev.'">Continuse</a> ';
exit();
}
}
}
?>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script type="text/javascript">
function countDown(secs,elem)
{
var element= document.getElementById(elem);
element.innerHTML="You have <font color=red>"+secs+"</font> seconds remaning";
if(secs<1){
var xhr=new XMLHttpRequest();
var url="userAnswer.php";
var vars="radio=0"+"$qid="+<?php echo $question; ?>;
xhr.open("POST",url,true);
xhr.setRequestHeader("content-type", "application/x-www-form-urlencoded");
xhr.onreadystatechange= function(){
if(xhr.readyState==4 && xhr.status==200){
alert("your time is up");
clearTimeout(timer);
}
}
xhr.send(vars);
document.getElementById('counter_status').innerHTML="";
document.getElementById('btnSpan').innerHTML='<h2>Time up</h2>';
document.getElementById('btnSpan').innerHTML +='<a href="quizehome.php?question=<?php echo $next; ?>">click here now</a>';
}
secs--;
var timer=setTimeout('countDown('+secs+',"'+elem+'")',1000);
}
</script>
<script type="text/javascript">
function getQuestion(){
var hr=new XMLHttpRequest();
hr.onreadystatechange=function (){
if(hr.readyState==4 && hr.status==200){
var response= hr.responseText.split("|");
if(response[0]== "finished"){
document.getElementById('status').innerHTML=response[1];
}
var nums= hr.responseText.split(",");
document.getElementById('question').innerHTML=nums[0];
document.getElementById('answers').innerHTML=nums[1];
document.getElementById('answers').innerHTML +=nums[2];
}
}
hr.open("GET","questions.php?question="+ <?php echo $question; ?>,true);
hr.send();
}
</script>
<script type="text/javascript">
function x(){
var rads=document.getElementsByName("answer");
for(var i=0;i<rads.length; i++){
if(rads[i].checked){
var val=rads[i].value;
return val;
}
}
}
function post_answer(){
var p=new XMLHttpRequest();
var id= document.getElementById('qid').value;
var url="userAnswer.php";
var vars="qid="+id+"&radio="+parseInt(x());
console.log(vars);
p.open("POST",url,true);
p.setRequestHeader("content-type", "application/x-www-form-urlencoded");
p.send(vars);
p.onreadystatechange= function (){
if(p.readyState==4 && p.status==200){
document.getElementById("status").innerHTML="";
var url='quizehome.php?question=<?php echo $next ?>';
window.location=url;
}
}
//document.getElementById("status").innerHTML="processing";
}
</script>
<script>
window.oncontextmenu= function (){
return false;
}
</script>
<!-- meta -->
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<link rel="stylesheet" href="css/materialize.min.css"/>
<link href="http://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet" />
<script src="js/jquery-2.1.1.min.js"></script>
<script src="js/materialize.min.js"></script>
</head>
<body bgcolor="#eeeeee" onload="getQuestion()">
<nav style="background-color:#212121;">
<div class="nav-wrapper">
<a href="#" class="brand-logo center">Quiz</a>
</div>
</nav>
<div id="status">
<div id="counter_status" style="margin-left:35%;font-family:Comic Sans MS;font-size:190%;margin-top:5%;"></div>
<center><div id="question" style="font-family:Comic Sans MS;"></div></center>
<div id="answers" style="margin-left:45%;font-family:Comic Sans MS;margin-top:7%;"></div>
</div>
<!-- change 200 to 20 -->
<script type="text/javascript">countDown(50,"counter_status");</script>
</body>
</html>