-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdoubleRepTest.php
More file actions
138 lines (125 loc) · 4.46 KB
/
doubleRepTest.php
File metadata and controls
138 lines (125 loc) · 4.46 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
<?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 Double Replacement Reactions</h1>
<?php
include 'mysql.php';
include 'mail.php';
//fetch total count from combinations table
$getCnt = dou_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 = compl(end($counter));
while ($row = mysqli_fetch_assoc($getData)) {
if($row['product1'] == $ans && $row['product2'] == $ans) {
$ans_cnt++;
}
array_push($product1_ans, $ans);
}
doub_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"]));
$counter = unserialize($_POST["cnt_array"]);
$ans = $_POST["answer"];
$ans_cnt = $_POST["ans_cnt"];
$getData = compl(end($counter));
while ($row = mysqli_fetch_assoc($getData)) {
if($row['product1'] == $ans && $row['product2'] == $ans) {
$ans_cnt++;
}
array_push($product1_ans, $row['product1']);
}
} else {
$counter = array();
$product1_ans = array();
$ans_cnt = 0;
$examNum = examId($_SESSION['username'], "doubleRep");
while ($row = mysqli_fetch_assoc($examNum)) {
if ($row['num'] != null) {
$_SESSION['examId'] = "doubleRep_" . ($row['num']+1);
} else {
$_SESSION['examId'] = "doubleRep_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 = dou($id);
if ($getData != 0) {
while ($row = mysqli_fetch_assoc($getData)) {
?>
<p>Question <?php echo sizeof($counter); ?> of <?php echo $cnt?></p>
<br>
<div class="timer">
<time id="cnt"></time>
</div>
<br>
<div align="center">
<form method="POST" action="">
<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" />
<label for="reac1"> + </label>
<input type="text" name="answer" size="20" />
<label for="reac1"> + </label>
<input type="text" name="answer" size="20" />
<br>
<br>
<?php if(sizeof($counter) < $cnt) {?>
<input type=submit name="next" value='Next Question'>
<?php } else {?>
<input type=submit name="submit" value='Submit'>
<?php }?>
<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)); ?>" />
<input type="hidden" name="ans_given" value="<?php echo base64_encode(serialize($product2_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>
<script type="text/javascript">
</script>
</html>