-
Notifications
You must be signed in to change notification settings - Fork 0
/
interface.php
executable file
·256 lines (208 loc) · 6.26 KB
/
interface.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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
<html>
<?php
require 'database.php';
$db_connection = new Database();
$conn = $db_connection->dbConnection();
// authenticate using attempts
// comment out if testing
if(isset($_GET["a"]) || isset($_GET["b"]))
{
$first = $_GET['a'];
$second = $_GET['b'];
$sql = $conn->prepare("SELECT * FROM attempts a, students s WHERE a.student = s.h_username AND a.student= :first AND a.session_key=:second AND a.used = 1");
$sql->bindValue(':first', $first);
$sql->bindValue(':second', $second);
$sql->execute();
if($sql->rowCount() > 0) {
// session storing current username
$row = $sql->fetch();
$_SESSION["username"] = $row["username"];
// update flag so that it cannot be used again
$update_sql = $conn->prepare("UPDATE attempts SET used = 2 WHERE student = :first AND session_key = :second");
$update_sql->bindValue(':first', $first);
$update_sql->bindValue(':second', $second);
$update_sql->execute();
echo "<script>alert('Logged in as ".$_SESSION['username']."');</script>";
}
else {
header("Location: error.php");
}
}
else
{
header("Location: error.php");
}
?>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="scripts/encryption.js"></script>
<title>Interface</title>
<style>
.overlay {
position: fixed;
width: 100%;
height: 100%;
left: 0;
top: 0;
z-index: 10;
}
.popup {
position: fixed;
bottom: 50;
left: 10;
z-index: 30;
border: 2px solid black;
padding: 10px;
}
.question {
background-color: #d6543a;
}
.quiz {
background-color: #89c0f0;
}
.quizBox {
margin-bottom: 0;
}
.quizInput {
margin-bottom: 12px;
}
div.sticky {
position: -webkit-sticky; /* Safari */
position: sticky;
position: fixed;
bottom: 10;
left: 10;
z-index: 20;
}
.close {
color: #aaaaaa;
float: right;
font-weight: bold;
}
textarea {
resize: none;
margin-left = 10;
margin-right = 10;
}
</style>
</head>
<body>
<div class = "overlay">
<embed src="Lect5Comms.pdf" type="application/pdf" width="100%" height="100%" />
</div>
<div class = "sticky">
<Button onClick = "toggleQuestionPanel();">Ask Question</button>
<Button onClick = "toggleQuizPanel();">Quiz</button>
</div>
<!--
<div class = "popup question" id = "askQn" style = "display: none">
<button class = "close" onClick = "closeQuestion();">x</button>
<p><b>Ask a question:</b></p>
<textarea rows="4" cols="50" maxlength="200"></textarea>
<br>
<br>
<button class = "close">Submit</button>
</div>
-->
<div class = "popup question" id = "askQn" style = "display: none">
<button class = "close" onClick = "closeQuestion();">x</button>
<p><b>Ask a question:</b></p>
<input type = "text" id = "Name" placeholder = "Enter name here"><br><br>
<textarea rows="4" cols="50" id = "QuestionArea" maxlength="200" placeholder = "Enter question here"></textarea>
<br>
<br>
<button class = "close" onClick="submitQuestion();">Submit</button>
</div>
<div class = "popup quiz" id = "enterQuiz" style = "display: none">
<button class = "close" onClick = "closeQuizPanel();">x</button>
<form id="quizForm" class="quizBox" method="post">
<p><b>Enter quiz code:</b></p>
<input type="text" class="quizInput" name="quizCode">
<input type="submit" value="Join Quiz Now!">
</form>
</div>
</body>
<script type='text/javascript'>
var isQuestionPanelOpen = false;
var isQuizPanelOpen = false;
function toggleQuestionPanel() {
var askPanel = document.getElementById("askQn");
isQuestionPanelOpen = !isQuestionPanelOpen;
if (isQuestionPanelOpen) {
if (isQuizPanelOpen) {
toggleQuizPanel()
}
askPanel.style.display = "block";
} else {
askPanel.style.display = "none";
}
}
function closeQuestion() {
var askPanel = document.getElementById("askQn");
askPanel.style.display = "none";
}
function toggleQuizPanel() {
var quizPanel = document.getElementById("enterQuiz");
isQuizPanelOpen = !isQuizPanelOpen;
if (isQuizPanelOpen) {
if (isQuestionPanelOpen) {
toggleQuestionPanel()
}
quizPanel.style.display = "block";
} else {
quizPanel.style.display = "none";
}
}
function closeQuizPanel() {
console.log("closing quiz panel");
var quizPanel = document.getElementById("enterQuiz");
quizPanel.style.display = "none";
}
$("#quizForm").submit(function(e){
e.preventDefault();
// convert input into md5 hash to be sent
var serialized_input = $(this).serialize()
var input = serialized_input.substring(9)
var hashedCode = sha1(input)
var req
req = $.ajax({
type: "POST",
url: "/quiz/verify_code.php",
data: "quizCode=" + hashedCode,
processData: false
});
req.always(function (response) {
if (response.status == '200') {
// console.log('http response: ' + response.status)
console.log(response.responseText)
// console.log(response)
// fix parseerror :(
alert("Success!");
var win = window.open('/quiz/q3235.php', '_blank');
win.focus();
}
else {
// console.log('Error status: ' + response.status);
// console.log("Failure!")
alert("Code is wrong!");
}
});
});
function submitQuestion() {
var name = document.getElementById('Name').value;
var question = document.getElementById('QuestionArea').value;
$.ajax({
type: 'POST',
url: 'questions/submitQuestion.php',
data: ({name:name, question: question}),
cache: false,
success: function(result){
//var arr=JSON.parse(result);
//alert(arr['name'] + " " + arr['question']);
alert(result);
}
});
}
</script>
</html>