-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanswer_sheet.php
executable file
·103 lines (93 loc) · 2.93 KB
/
answer_sheet.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
<!DOCTYPE html>
<html lang="en">
<head>
</head>
<?php include('header.php') ?>
<?php include('auth.php') ?>
<?php include('db_connect.php') ?>
<?php
$quiz = $conn->query("SELECT * FROM quiz_list where id =".$_GET['id']." order by RAND()")->fetch_array();
?>
<title><?php echo $quiz['title'] ?> | Answer Sheet</title>
</head>
<body>
<style>
li.answer{
cursor: pointer;
}
li.answer:hover{
background: #00c4ff3d;
}
li.answer input:checked{
background: #00c4ff3d;
}
</style>
<?php include('nav_bar.php') ?>
<div class="container-fluid admin">
<div class="col-md-12 alert alert-primary"><?php echo $quiz['title'] ?> | <?php echo $quiz['qpoints'] .' Points Each Question' ?></div>
<br>
<div class="card">
<div class="card-body">
<form action="" id="answer-sheet">
<input type="hidden" name="user_id" value="<?php echo $_SESSION['login_id'] ?>">
<input type="hidden" name="quiz_id" value="<?php echo $quiz['id'] ?>">
<input type="hidden" name="qpoints" value="<?php echo $quiz['qpoints'] ?>">
<?php
$question = $conn->query("SELECT * FROM questions where qid = '".$quiz['id']."' order by order_by asc ");
$i = 1 ;
while($row =$question->fetch_assoc()){
$opt = $conn->query("SELECT * FROM question_opt where question_id = '".$row['id']."' order by RAND() ");
?>
<ul class="q-items list-group mt-4 mb-4">
<li class="q-field list-group-item">
<strong><?php echo ($i++). '. '; ?> <?php echo $row['question'] ?></strong>
<input type="hidden" name="question_id[<?php echo $row['id'] ?>]" value="<?php echo $row['id'] ?>">
<br>
<ul class='list-group mt-4 mb-4'>
<?php while($orow = $opt->fetch_assoc()){ ?>
<li class="answer list-group-item">
<label><input type="radio" name="option_id[<?php echo $row['id'] ?>]" value="<?php echo $orow['id'] ?>"> <?php echo $orow['option_txt'] ?></label>
</li>
<?php } ?>
</ul>
</li>
</ul>
<?php } ?>
<button class="btn btn-block btn-primary">Submit</button>
</form>
</div>
</div>
</div>
</body>
<script>
$(document).ready(function(){
$('.answer').each(function(){
$(this).click(function(){
$(this).find('input[type="radio"]').prop('checked',true)
$(this).css('background','#00c4ff3d')
$(this).siblings('li').css('background','white')
})
})
$('#answer-sheet').submit(function(e){
e.preventDefault()
$('#answer-sheet [type="submit"]').attr('disabled',true)
$('#answer-sheet [type="submit"]').html('Saving...')
$.ajax({
url:'submit_answer.php',
method:'POST',
data:$(this).serialize(),
error:err=>console.log(err),
success:function(resp){
if(typeof resp != undefined){
resp = JSON.parse(resp)
if(resp.status == 1){
alert('You completed the quiz your score is '+resp.score)
location.replace('view_answer.php?id=<?php echo $_GET['id'] ?>')
}
}
}
})
})
})
</script>
</html>