forked from shreyasgangwar/Education-Portal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstdtest1.php
218 lines (204 loc) · 12.5 KB
/
stdtest1.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
<?php
/*
* **************************************************
* ** Online Examination System ***
* **---------------------------------------------***
* ** License: GNU General Public License V.3 ***
* ** Author: Manjunath Baddi ***
* ** Title: Test Environment Preparation ***
* **************************************************
*/
error_reporting(0);
session_start();
include_once 'oesdb.php';
if (!isset($_SESSION['stdname'])) {
$_GLOBALS['message'] = "Session Timeout.Click here to <a href=\"index.php\">Re-LogIn</a>";
} else if (isset($_SESSION['starttime'])) {
header('Location: t.php');
} else if (isset($_REQUEST['logout'])) {
//Log out and redirect login page
unset($_SESSION['stdname']);
header('Location: index.php');
} else if (isset($_REQUEST['dashboard'])) {
//redirect to dashboard
//
header('Location: stdwelcome.php');
} else if (isset($_REQUEST['starttest'])) {
//Prepare the parameters needed for Test Conducter and redirect to test conducter
if (!empty($_REQUEST['tc'])) {
$result = executeQuery("select DECODE(testcode,'oespass') as tcode from test where testid=" . $_SESSION['testid'] . ";");
if ($r = mysql_fetch_array($result)) {
if (strcmp(htmlspecialchars_decode($r['tcode'], ENT_QUOTES), htmlspecialchars($_REQUEST['tc'], ENT_QUOTES)) != 0) {
$display = true;
$_GLOBALS['message'] = "You have entered an Invalid Test Code.Try again.";
} else {
//now prepare parameters for Test Conducter and redirect to it.
//first step: Insert the questions into table
$result = executeQuery("select * from question where testid=" . $_SESSION['testid'] . " order by qnid;");
if (mysql_num_rows($result) == 0) {
$_GLOBALS['message'] = "Tests questions cannot be selected.Please Try after some time!";
} else {
// executeQuery("COMMIT");
$error = false;
// executeQuery("delimiter |");
/* if (!executeQuery("create event " . $_SESSION['stdname'] . time() . "
ON SCHEDULE AT (select endtime from studenttest where stdid=" . $_SESSION['stdid'] . " and testid=" . $_SESSION['testid'] . ") + INTERVAL (select duration from test where testid=" . $_SESSION['testid'] . ") MINUTE
DO update studenttest set correctlyanswered=(select count(*) from studentquestion as sq,question as q where sq.qnid=q.qnid and sq.testid=q.testid and sq.answered='answered' and sq.stdanswer=q.correctanswer and sq.stdid=" . $_SESSION['stdid'] . " and sq.testid=" . $_SESSION['testid'] . "),status='over' where stdid=" . $_SESSION['stdid'] . " and testid=" . $_SESSION['testid'] . "|"))
$_GLOBALS['message'] = "error" . mysql_error();
executeQuery("delimiter ;");*/
if (!executeQuery("insert into studenttest values(" . $_SESSION['stdid'] . "," . $_SESSION['testid'] . ",(select CURRENT_TIMESTAMP),date_add((select CURRENT_TIMESTAMP),INTERVAL (select duration from test where testid=" . $_SESSION['testid'] . ") MINUTE),0,'inprogress')"))
$_GLOBALS['message'] = "error" . mysql_error();
else {
while ($r = mysql_fetch_array($result)) {
if (!executeQuery("insert into studentquestion values(" . $_SESSION['stdid'] . "," . $_SESSION['testid'] . "," . $r['qnid'] . ",'unanswered',NULL)")) {
$_GLOBALS['message'] = "Failure while preparing questions for you.Try again";
$error = true;
}
}
if ($error == true) {
// executeQuery("rollback;");
} else {
$result = executeQuery("select totalquestions,duration from test where testid=" . $_SESSION['testid'] . ";");
$r = mysql_fetch_array($result);
$_SESSION['tqn'] = htmlspecialchars_decode($r['totalquestions'], ENT_QUOTES);
$_SESSION['duration'] = htmlspecialchars_decode($r['duration'], ENT_QUOTES);
$result = executeQuery("select DATE_FORMAT(starttime,'%Y-%m-%d %H:%i:%s') as startt,DATE_FORMAT(endtime,'%Y-%m-%d %H:%i:%s') as endt from studenttest where testid=" . $_SESSION['testid'] . " and stdid=" . $_SESSION['stdid'] . ";");
$r = mysql_fetch_array($result);
$_SESSION['starttime'] = $r['startt'];
$_SESSION['endtime'] = $r['endt'];
$_SESSION['qn'] = 1;
$_SESSION['no'] = 1;
header('Location: t.php');
}
}
}
}
} else {
$display = true;
$_GLOBALS['message'] = "You have entered an Invalid Test Code.Try again.";
}
} else {
$display = true;
$_GLOBALS['message'] = "Enter the Test Code First!";
}
} else if (isset($_REQUEST['testcode'])) {
//test code preparation
if ($r = mysql_fetch_array($result = executeQuery("select testid from test where testname='" . htmlspecialchars($_REQUEST['testcode'], ENT_QUOTES) . "';"))) {
$_SESSION['testname'] = $_REQUEST['testcode'];
$_SESSION['testid'] = $r['testid'];
}
} else if (isset($_REQUEST['savem'])) {
//updating the modified values
if (empty($_REQUEST['cname']) || empty($_REQUEST['password']) || empty($_REQUEST['email'])) {
$_GLOBALS['message'] = "Some of the required Fields are Empty.Therefore Nothing is Updated";
} else {
$query = "update student set stdname='" . htmlspecialchars($_REQUEST['cname'], ENT_QUOTES) . "', stdpassword=ENCODE('" . htmlspecialchars($_REQUEST['password'], ENT_QUOTES) . "','oespass'),emailid='" . htmlspecialchars($_REQUEST['email'], ENT_QUOTES) . "',contactno='" . htmlspecialchars($_REQUEST['contactno'], ENT_QUOTES) . "',address='" . htmlspecialchars($_REQUEST['address'], ENT_QUOTES) . "',city='" . htmlspecialchars($_REQUEST['city'], ENT_QUOTES) . "',pincode='" . htmlspecialchars($_REQUEST['pin'], ENT_QUOTES) . "' where stdid='" . $_REQUEST['student'] . "';";
if (!@executeQuery($query))
$_GLOBALS['message'] = mysql_error();
else
$_GLOBALS['message'] = "Your Profile is Successfully Updated.";
}
closedb();
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>SRM-Offered Tests</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta http-equiv="CACHE-CONTROL" content="NO-CACHE"/>
<meta http-equiv="PRAGMA" content="NO-CACHE"/>
<meta name="ROBOTS" content="NONE"/>
<link rel="stylesheet" type="text/css" href="oes.css"/>
<script type="text/javascript" src="validate.js" ></script>
</head>
<body >
<?php
if ($_GLOBALS['message']) {
echo "<div class=\"message\">" . $_GLOBALS['message'] . "</div>";
}
?>
<div id="container">
<div class="header">
<img style="margin:10px 2px 2px 10px;float:left;" height="80" width="100" src="images/vlogo.png" alt="OES"/><h3 class="headtext"> SRM Exam Portal </h3><h4 style="color:#ffffff;text-align:center;margin:0 0 5px 5px;"><i></i></h4>
</div>
<form id="stdtest" action="stdtest1.php" method="post">
<div class="menubar">
<ul id="menu">
<?php
if (isset($_SESSION['stdname'])) {
// Navigations
?>
<li><input type="submit" value="LogOut" name="logout" class="subbtn" title="Log Out"/></li>
<li><input type="submit" value="DashBoard" name="dashboard" class="subbtn" title="Dash Board"/></li>
</ul>
</div>
<div class="page">
<?php
if (isset($_REQUEST['testcode'])) {
echo "<div class=\"pmsg\" style=\"text-align:center;\">What is the Code of " . $_SESSION['testname'] . " ? </div>";
} else {
echo "<div class=\"pmsg\" style=\"text-align:center;\">Offered Tests</div>";
}
?>
<?php
if (isset($_REQUEST['testcode']) || $display == true) {
?>
<table cellpadding="30" cellspacing="10">
<tr>
<td>Enter Test Code</td>
<td><input type="text" tabindex="1" name="tc" value="" size="16" /></td>
<td><div class="help"><b>Note:</b><br/>Once you press start test<br/>button timer will be started</div></td>
</tr>
<tr>
<td colspan="3">
<input type="submit" tabindex="3" value="Start Test" name="starttest" class="subbtn" />
</td>
</tr>
</table>
<?php
} else {
$result = executeQuery("select t.*,s.subname from test as t, subject as s where s.subid=t.subid and CURRENT_TIMESTAMP<t.testto and t.totalquestions=(select count(*) from question where testid=t.testid) and NOT EXISTS(select stdid,testid from studenttest where testid=t.testid and stdid=" . $_SESSION['stdid'] . ");");
if (mysql_num_rows($result) == 0) {
echo"<h3 style=\"color:#0000cc;text-align:center;\">Sorry...! For this moment, You have not Offered to take any tests.</h3>";
} else {
//editing components
?>
<table cellpadding="30" cellspacing="10" class="datatable">
<tr>
<th>Test Name</th>
<th>Test Description</th>
<th>Subject Name</th>
<th>Duration</th>
<th>Total Questions</th>
<th>Take Test</th>
</tr>
<?php
while ($r = mysql_fetch_array($result)) {
$i = $i + 1;
if ($i % 2 == 0) {
echo "<tr class=\"alt\">";
} else {
echo "<tr>";
}
echo "<td>" . htmlspecialchars_decode($r['testname'], ENT_QUOTES) . "</td><td>" . htmlspecialchars_decode($r['testdesc'], ENT_QUOTES) . "</td><td>" . htmlspecialchars_decode($r['subname'], ENT_QUOTES)
. "</td><td>" . htmlspecialchars_decode($r['duration'], ENT_QUOTES) . "</td><td>" . htmlspecialchars_decode($r['totalquestions'], ENT_QUOTES) . "</td>"
. "<td class=\"tddata\"><a title=\"Start Test\" href=\"stdtest1.php?testcode=" . htmlspecialchars_decode($r['testname'], ENT_QUOTES) . "\"><img src=\"images/starttest.png\" height=\"30\" width=\"40\" alt=\"Start Test\" /></a></td></tr>";
}
?>
</table>
<?php
}
closedb();
}
}
?>
</div>
</form>
<div id="footer">
<p style="font-size:70%;color:#ffffff;"> Developed By-<b>Advanced Tribe</b><br/> </p>
</div>
</div>
</body>
</html>