-
Notifications
You must be signed in to change notification settings - Fork 0
/
submitTest.php
127 lines (114 loc) · 4.54 KB
/
submitTest.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
<?php
session_start();
require('connection.php');
if(!$_SESSION["rollno"]){
header('location:index.php');
}
$questionNumber = 1;
$final = [];
$rollno = $_SESSION["rollno"];
$class = $_SESSION["class"];
$testId = $_SESSION["testId"];
$section = $_SESSION['section'];
$currentTime = $datetime->format('H:i');
function minutes($timeTaken){
$timeTaken = explode(':', $timeTaken);
return (int)($timeTaken[0]*60) + $timeTaken[1] ;
}
$startingTimem = minutes($startingTime);
$endingTimem = minutes($endingTime);
if($timeGiven <= 0){
die("This test got ended at $endingTime");
} else {
try{
if($_SERVER["REQUEST_METHOD"] =="POST"){
$totalQuestion = (int)testInput($_POST['totalQuestion']);
while (true){
$optionNumber = 0;
$questionIndex = $questionNumber-1;
if(!isset($_POST["questionNumber".$questionNumber."_0"])){
array_push($final,str_replace("@#a","a ","Not answered"));
} else {
$answer = str_replace("@#ao","ao",testInput($_POST["questionNumber".$questionNumber."_0"]));
if($answer == ''){
$answer = "Not Answered";
}
array_push($final,str_replace("@#a","a ",str_replace("@#a","a",$answer)));
}
$totalOption = testInput($_POST["optionOn_$questionNumber"]);
while(true){
if($totalOption == $optionNumber){
break;
}
$optionNumber++;
if(isset($_POST["questionNumber".$questionNumber."_$optionNumber"])){
$answer = testInput($_POST["questionNumber".$questionNumber."_$optionNumber"]);
if($final[$questionIndex] == "Not Answered"){
if($answer != "Not Answered") {
$final[$questionIndex] = $final[$questionIndex].str_replace("@#a","a",$answer);
}
} else {
$final[$questionIndex] = $final[$questionIndex].'@#ao'.str_replace("@#ao","ao",$answer);
}
}
}
$questionNumber++;
if($questionNumber == $totalQuestion){
break;
}
}
$final = join("@#a",$final);
$tableName = 'result_'.$class.'@'.$testId;
$stmt = $conn->prepare("insert into `$tableName`(`id`, `rollno`, `answer`, `section`) values(NULL,?,?,?)");
$stmt->execute([$rollno,$final,$section]);
unset($_SESSION['level']);
unset($_SESSION["rollno"]);
unset($_SESSION["class"]);
unset($_SESSION["class"]);
unset($_SESSION["testId"]);
unset($_SESSION['section']);
session_destroy();
header('location:../index.php')
echo '<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Thank you!</title>
<link rel="icon" href="assert/favico.png" type="image/png" sizes="16x16">
<style>
@font-face {
font-family: Ubuntu-Bold;
src: url(assert/Ubuntu-B.ttf);
}
img{
width:99vw;
height:90vh;
}
.title{
margin:0 auto;
font-family: Ubuntu-Bold;
color:#6699ff;
}
body{
overflow:hidden;
}
</style>
</head>
<body>
<div class="title" style="text-align:center;margin:50px;">
<h2>Your test is successfuly submit</h2>
</div>
<div class="image">
<image src="assert/done.jpg" alt="DOne" >
</div>
</body>
</html>';
} else {
die("Failed to sumbit test");
}
}catch(PDOException $e){
die("Problem to connect with db check".$e);
}
}
?>