-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcombinationTest.php
More file actions
149 lines (127 loc) · 4.17 KB
/
combinationTest.php
File metadata and controls
149 lines (127 loc) · 4.17 KB
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
<?php
error_reporting(0);
session_start();
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Sign-In</title>
<link href="css/default.css" rel="stylesheet">
<script type="text/javascript" src="js/script.js"> </script>
</head>
<body id="body-color" onload="secondPassed();">
<h1>Test on Combinations Reactions</h1>
<?php
include 'mysql.php';
include 'mail.php';
// fetch total count from combinations table
$getCnt = reactants_count();
// $cnt = mysqli_fetch_assoc($getCnt);
while ($r = mysqli_fetch_assoc($getCnt)) {
$cnt = $r['count'];
}
if (isset($_POST['submit'])) {
$counter = unserialize($_POST["cnt_array"]);
$product1_ans = unserialize(base64_decode($_POST["ans_given"]));
$ans = $_POST["answer"];
$ans_cnt = $_POST["ans_cnt"];
$getData = questions(end($counter));
while ($row = mysqli_fetch_assoc($getData)) {
if ($row['product1'] == $ans) {
$ans_cnt ++;
}
array_push($product1_ans, $ans);
}
combinations_review($_SESSION['username'], $_SESSION['examId'], implode(',', $counter), implode(',', $product1_ans), '', '');
sendEmail($_SESSION['username'], $_SESSION['examId']);
session_destroy();
echo '<script type="text/javascript">
alert("you have got ' . $ans_cnt . ' out of ' . $cnt . '");
var arr = "<?php echo serialize($counter); ?>";
window.location.href = "resultPage.php?id=questions&cnt_array=' . serialize($counter) . '";
</script>';
}
if (isset($_POST['next'])) {
$counter = unserialize($_POST["cnt_array"]);
$product1_ans = unserialize(base64_decode($_POST["ans_given"]));
$ans = $_POST["answer"];
$ans_cnt = $_POST["ans_cnt"];
$getData = questions(end($counter));
while ($row = mysqli_fetch_assoc($getData)) {
if ($row['product1'] == $ans) {
$ans_cnt ++;
}
array_push($product1_ans, $ans);
}
} else {
$counter = array();
$product1_ans = array();
$ans_cnt = 0;
$examNum = examId($_SESSION['username'], "combination");
while ($row = mysqli_fetch_assoc($examNum)) {
if ($row['num'] != null) {
$_SESSION['examId'] = "combination_" . ($row['num']+1);
} else {
$_SESSION['examId'] = "combination_1";
}
}
}
// to genearate random number
$id = rand(1, $cnt);
// if id is already read then regenrate random number
while ((in_array($id, $counter)) && (sizeof($counter) < $cnt)) {
$id = rand(1, $cnt);
}
array_push($counter, $id);
// fetch question from combination table
$getData = questions($id);
if ($getData != 0) {
while ($row = mysqli_fetch_assoc($getData)) {
?>
<p>Question <?php echo sizeof($counter); ?> of <?php echo $cnt?></p>
<br>
<br>
<div class="timer">
<time id="cnt"></time>
</div>
<div align="center">
<form method="POST" action="" name="form1">
<label for="reac1"> <?php echo $row['reactant1'] ?>
</label> <label for="reac1"> + </label> <label
for="reac2"> <?php echo $row['reactant2'] ?>
</label> <label for="reac1"> = </label> <input
type="text" name="answer" size="20" /> <br> <br> <br>
<?php if(sizeof($counter) < $cnt) {?>
<br></br> <input type=submit name="next" value='Next Question'>
<?php } else {?>
<input type=submit name="submit" value='Submit'>
<?php }?>
<input type="hidden" name="id" /> <input type="hidden"
name="cnt_array" value="<?php echo serialize($counter); ?>" /> <input
type="hidden" name="ans_cnt" value="<?php echo $ans_cnt; ?>" /> <input
type="hidden" name="ans_given"
value="<?php echo base64_encode(serialize($product1_ans)); ?>" />
</form>
</div>
<?php
}
}
?>
<br>
<!--<p hidden>abcdefghijklmnopqrstuvwxyz</p>
<p><b>Instructions:</b></p>-->
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<p style="text-align: left">Instructions : Write your answer in the
provided block against question and select 'Next question' button to
move to next question in the test.</p>
</body>
</html>