Repository navigation
Expand file tree
/
Copy pathlevel3.php
More file actions
733 lines (598 loc) · 21.2 KB
/
Copy pathlevel3.php
File metadata and controls
733 lines (598 loc) · 21.2 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
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
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
<?php include "access_check.php"; ?>
<?php
$right = -1;
include "connect.php";
$sid = $_SESSION['pid'];
if (!isset($_SESSION['music_played3'])) {
echo '<script>
var introAudio = new Audio("sounds/intro.mp3");
introAudio.play();
</script>';
// Set the session variable to indicate that the music has been played
$_SESSION['music_played3'] = true;
}
$nqres = mysqli_query($conn, "SELECT count(*) from responses3 where sid='$sid';");
$qres = mysqli_fetch_array($nqres);
$q = $qres[0];
if (isset($_GET['qid'])) {
$qid = (int)$_GET['qid'];
$response = strtoupper(trim($_GET['op']));
$ans = mysqli_query($conn, "SELECT * FROM words3 where qid=$qid;");
$answer = mysqli_fetch_row($ans);
$sid = $_SESSION['pid'];
$ranswer = strtoupper($answer[1]);
$level = $answer[3];
$right = 1;
if ($level <= 3) {
$marks = 100;
}
if ($ranswer != $response) {
$marks = 0;
$right = 0;
}
$query = "insert into responses3 (sid, qid, answer,marks) values ('$sid', $qid, '$response', $marks)";
mysqli_query($conn, $query);
}
?>
<!DOCTYPE html>
<html class="sidebar-light fixed sidebar-left-collapsed">
<head>
<?php include "head.php"; ?>
<style>
{
background-size : 150%;
background-position: center;
background-repeat: no-repeat;
background-attachment: fixed;
}
/* Large screens (desktops) */
@media (min-width: 769px) {
body {
background: url('https://getwallpapers.com/wallpaper/full/e/4/6/570852.jpg') center center fixed;
}
}
/* Small screens (mobile devices) */
@media (max-width: 768px) {
body {
background: url('https://getwallpapers.com/wallpaper/full/e/4/6/570852.jpg') center center fixed;
background-size: cover;
/* Adjust other background properties as needed for mobile view */
}
}
td {
color: lightblue;
}
.ui-pnotify.red .ui-pnotify-container {
background-color: #DC143C !important;
color: #ffffff;
border: 0px;
}
.ui-pnotify.blue .ui-pnotify-container {
background-color: #0088cc !important;
color: #ffffff;
border: 0px;
}
.code {
display: inline-block;
overflow-wrap: break-word;
word-wrap: break-word;
text-align: left;
}
/* Add your CSS styles here */
.card {
margin: 20px;
padding: 20px;
border: 1px solid #ddd;
border-radius: 5px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
table {
width: 72%;
border-collapse: collapse;
margin: 20px auto;
/* Center the table horizontally */
}
/* Media query for mobile view */
@media (max-width: 768px) {
table {
width: 100%;
/* Make the table full width on smaller screens */
margin: 20px 0;
/* Remove left and right margin on smaller screens */
}
}
th,
td {
border: 2px solid black;
padding: 8px;
text-align: left;
-webkit-text-fill-color: black bold;
color: whitesmoke;
/* Set the text color */
font-weight: bold;
/* Set the text weight to bold */
text-shadow: 1px 1px 1px black;
}
th {
background-color: purple;
color: whitesmoke;
/* Set the text color to black */
font-weight: bold;
/* Increase the thickness of the text */
}
tr:hover {
background-color: black;
}
h2 {
text-align: center;
margin-top: 20px;
}
/* Add this CSS style to remove black cursor on hover */
.user-responses-section table {
cursor: default;
}
/* Add this style if you want to change the cursor color */
.user-responses-section table tr:hover {
background-color: transparent;
/* Change the background color on hover if needed */
cursor: default;
}
</style>
<!-- Include your additional styles or scripts here -->
</head>
<body>
<!-- Your existing PHP and HTML content goes here -->
<!-- ... -->
</body>
<?php
if ($right == 1) {
?>
<script>
var audio = new Audio("sounds/skanda.mp3");
audio.play();
//var audio = new Audio("sounds/claps.mp3");
//audio.play();
</script>
<?php
}
if ($right == 0) {
?>
<script>
var audio = new Audio("sounds/moye.mp3");
audio.play();
</script>
<?php
}
?>
</head>
<body>
<section class="body">
<?php include "header.php"; ?>
<div class="inner-wrapper">
<!-- start: sidebar -->
<?php include "sidebar.php"; ?>
<!-- end: sidebar -->
<section role="main" class="content-body">
<header class="page-header">
<h2 style="margin-left: 37%;">Kaun Banega Codepathi</h2>
</header>
<button id="toggleTimer" onclick="toggleTimer()">Start Timer</button>
<button id="pauseResume" onclick="pauseResumeTimer()" disabled>Pause</button>
<?php
if ($right == 1) {
?>
<div id="swinner" class="modal-block modal-header-color modal-block-primary">
<section class="card">
<header class="card-header">
<div class="card-actions">
<a href="#" class="card-action card-action-toggle" data-card-toggle></a>
<a href="#" class="card-action card-action-dismiss" data-card-dismiss></a>
</div>
<h2 class="card-title">KBC ANSWER</h2>
</header>
<div class="card-body" style='text-align:center;'>
<ul class="simple-bullet-list mb-3">
<img src="img/congrats.gif">
</ul>
<h5><b>YOUR ANSWER:</b> <?php echo $response; ?><br> <b>RIGHT ANSWER:</b> <?php echo $ranswer; ?></h5>
</div>
</section>
</div>
<?php
} else if ($right == 0) {
?>
<div id="srunner" class="modal-block modal-header-color modal-block-danger">
<section class="card">
<header class="card-header">
<div class="card-actions">
<a href="#" class="card-action card-action-toggle" data-card-toggle></a>
<a href="#" class="card-action card-action-dismiss" data-card-dismiss></a>
</div>
<h2 class="card-title">KBC ANSWER</h2>
</header>
<div class="card-body" style='text-align:center;'>
<ul class="simple-bullet-list mb-3">
<img src="img/fail.gif">
</ul>
<h5><b>YOUR ANSWER:</b> <?php echo $response; ?><br> <b>RIGHT ANSWER:</b> <?php echo $ranswer; ?></h5>
</div>
</section>
</div>
<?php
}
?>
<div id="srunner" class="modal-block modal-header-color modal-block-danger">
<section class="card">
<header class="card-header" style="background-color: purple;">
<h2 class="card-title">Your Question Goes Here:</h2>
</header>
<div class="card-body">
<?php
if ($q < 4) {
$q = $q + 1;
echo "<h4 align='center' STYLE='COLOR:RED; class='box'><B>YOUR QUESTION NO - $q</B></h4>";
$ques = mysqli_query($conn, "SELECT * FROM words3 where qid not in (select qid from responses3 where sid='$sid') AND level=2 ORDER BY RAND() LIMIT 1;");
$qrow = mysqli_fetch_array($ques);
$qid = $qrow['qid'];
$ranswer = strtoupper($qrow['answer']);
$question = $qrow['question'];
$opr = array($qrow['option1'], $qrow['option2'], $qrow['option3'], $ranswer);
shuffle($opr);
$option1 = strtoupper($opr[0]);
$option2 = strtoupper($opr[1]);
$option3 = strtoupper($opr[2]);
$option4 = strtoupper($opr[3]);
$userResponsesQuery = "SELECT qid, answer AS response, marks FROM responses3 WHERE sid='$sid'";
$userResponsesResult = mysqli_query($conn, $userResponsesQuery);
echo "<div align='center' class='box'><h4><b>Question: </b></h4></div>";
echo "<pre align='center' class='box' style='font-size: 18px;'>" . htmlspecialchars($question) . "</pre>";
echo "<div align='center' class='box'><h4><b>Level 1: </b>";
//echo "<button class='mb-1 mt-1 mr-1 btn btn-primary' onclick='spell_human($qid);'><span style='color:#000000;'><i class='fas fa-volume-up'></i> SPELL HUMAN WORD <i class='fas fa-play'></i></span></button>";
//echo "<div id='spelling'>WRITE THE CORRECT SPELLING IN THE TEXT BOX<div class='col-8'><input type='hidden' name='qid' id='qid' value='$qid'><input type='text' class='form-control' name='answer' id='answer' value='' placeholder='Your Spelling Here' style='text-transform:uppercase;' autocomplete='off' REQUIRED></div><div class='col-4'><button type='submit' class='mb-1 mt-1 mr-1 btn btn-success' onclick='check_spelling();'>Submit Spelling</button></div></div>";
echo "<div id='box'>CLICK ON THE RIGHT ANSWER</div>";
echo "<a href='level3.php?qid=$qid&op=$option1'><button type='submit' class='mb-1 mt-1 mr-1 btn btn-primary' class='box'>$option1</button></a>";
echo "<a href='level3.php?qid=$qid&op=$option2'><button type='submit' class='mb-1 mt-1 mr-1 btn btn-primary' class='box'>$option2</button></a>";
echo "<a href='level3.php?qid=$qid&op=$option3'><button type='submit' class='mb-1 mt-1 mr-1 btn btn-primary' class='box'>$option3</button></a>";
echo "<a href='level3.php?qid=$qid&op=$option4'><button type='submit' class='mb-1 mt-1 mr-1 btn btn-primary' class='box'>$option4</button></a>";
echo "</div>";
} else {
echo "<h3 style='color:red;' align='center'>YOUR LEVEL-3 KBC HAS BEEN COMPLETED!</h3>";
$totalMarks = 0; // Initialize total marks variable
$userResponsesQuery = "SELECT qid, answer AS response, marks FROM responses3 WHERE sid='$sid'";
$userResponsesResult = mysqli_query($conn, $userResponsesQuery);
while ($row = mysqli_fetch_assoc($userResponsesResult)){
$totalMarks += $row['marks']; // Accumulate marks
}
if ($totalMarks = 500) {
echo "<div align='center'>
<a href='index.php' <button id='quit' style='background-color:red; color:white; border-radius: 20px;'>Quit Here</button></a>
<a href='scoreboard.php' <button id='continue' style='background-color:green; color : white; border-radius: 20px;'>Continue</button></a>
</div>";
}
}
?>
</div>
<?php
if(isset($_GET['life2'])){
$sq = "UPDATE users SET button2=1 WHERE pid='$sid'";
$re = mysqli_query($conn, $sq);
}
?>
<div align='center' class='box'>
<?php
$sql3 = "SELECT * FROM users WHERE pid='$sid'";
$result3 = mysqli_query($conn, $sql3);
while ($row3 = mysqli_fetch_assoc($result3)) {
if ($row3['button1'] == 0) {
echo "<button type='button' class='button1 mb-1 mt-1 mr-1 btn' name='life1'>Call</button>";
}
if ($row3['button2'] == 0) {
echo "<form method='GET' action=''>";
echo "<button type='submit' class='mb-1 mt-1 mr-1 btn' name='life2'>Swap</button>";
echo "</form>";
}
if ($row3['button3'] == 0) {
echo "<button type='button' class='button3 mb-1 mt-1 mr-1 btn' name='life3'>50-50</button>";
}
}
?>
</div>
</section>
</div>
<section class="user-responses-section">
<h2>User Score</h2>
<table border="5">
<thead>
<tr>
<th>Question</th>
<th>Response</th>
<th>Marks</th>
</tr>
</thead>
<tbody>
<?php
$totalMarks = 0; // Initialize total marks variable
$userResponsesQuery = "SELECT qid, answer AS response, marks FROM responses3 WHERE sid='$sid'";
$userResponsesResult = mysqli_query($conn, $userResponsesQuery);
$s=0;
while ($row = mysqli_fetch_assoc($userResponsesResult)) {
$s++;
echo "<tr>";
echo "<td>{$s}</td>";
echo "<td>{$row['response']}</td>";
echo "<td>{$row['marks']}</td>";
echo "</tr>";
$totalMarks += $row['marks']; // Accumulate marks
}
?>
<!-- Display total marks row -->
<tr>
<td colspan="2">Total Marks:</td>
<td><?php echo $totalMarks; ?></td>
</tr>
</tbody>
</table>
<?php
if($s == 5)
{
$sql1 = "SELECT points FROM users WHERE pid='$sid'";
$result1 = mysqli_query($conn, $sql1);
// Check if the query was successful
if ($result1) {
$row = mysqli_fetch_assoc($result1);
$currentPoints = $row['points'];
// Assuming $totalMarks is a variable with some numeric value
$newTotalPoints = $currentPoints + $totalMarks;
// Update the points in the database
$sql2 = "UPDATE users SET points=$newTotalPoints WHERE pid='$sid'";
$result2 = mysqli_query($conn, $sql2);
}
}
?>
</section>
</div>
</div>
</section>
</div>
</section>
</section>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.4/jquery.min.js"></script>
<script>
$(document).ready(function () {
$(".button1").click(function () {
$(this).prop("disabled", true);
var sid = <?php echo "$sid" ?>;
$.ajax({
type: "GET",
url: "lifeline1.php", // Replace with your PHP script URL
data: { id: sid },
success: function (response) {
$("#statusContainer").html(response);
}
});
});
});
$(document).ready(function () {
$(".button3").click(function () {
var sid = <?php echo "$sid" ?>;
$.ajax({
type: "GET",
url: "lifeline3.php", // Replace with your PHP script URL
data: { id: sid },
success: function (response) {
// Handle the AJAX response
$("#statusContainer").html(response);
// Disable the button to prevent multiple clicks
$(".button3").prop("disabled", true);
// Call the function to remove two random wrong options
removeWrongOptions();
}
});
});
});
// Function to remove two random wrong options
function removeWrongOptions() {
var options = document.querySelectorAll('.box .btn-primary');
var removedIndices = [];
while (removedIndices.length < 2) {
var randIndex = Math.floor(Math.random() * options.length);
if (!removedIndices.includes(randIndex) && options[randIndex].textContent.toUpperCase() !== '<?php echo strtoupper($ranswer); ?>') {
removedIndices.push(randIndex);
}
}
removedIndices.forEach(function(index) {
options[index].style.display = 'none';
});
}
document.getElementById('quit').addEventListener('click', function() {
window.location.href = 'index.php';
});
document.getElementById('continue').addEventListener('click', function() {
window.location.href = 'scoreboard.php';
});
</script>
<script>
let startTime;
let pauseStartTime;
let pauseEndTime;
let pauseTime = 0;
let timerInterval;
// Check if there is a saved state in local storage
const savedState = JSON.parse(localStorage.getItem('timerState'));
if (savedState) {
startTime = savedState.startTime;
pauseStartTime = savedState.pauseStartTime;
pauseEndTime = savedState.pauseEndTime;
pauseTime = savedState.pauseTime;
if (startTime && !pauseStartTime) {
// Timer was running, resume it
document.getElementById('toggleTimer').innerText = 'Stop Timer';
document.getElementById('pauseResume').innerText = 'Pause';
document.getElementById('pauseResume').disabled = false;
timerInterval = setInterval(updateTimer, 1);
} else if (startTime && pauseStartTime) {
// Timer was paused, show resume button
document.getElementById('toggleTimer').innerText = 'Stop Timer';
document.getElementById('pauseResume').innerText = 'Resume';
document.getElementById('pauseResume').disabled = false;
}
}
function toggleTimer() {
if (!startTime) {
// Start or resume the timer
if (pauseStartTime && pauseEndTime) {
const pausedDuration = pauseEndTime - pauseStartTime;
pauseTime += pausedDuration;
startTime = new Date().getTime() - pauseTime;
pauseStartTime = null;
pauseEndTime = null;
} else {
startTime = new Date().getTime() - pauseTime;
}
document.getElementById('toggleTimer').innerText = 'Stop Timer';
document.getElementById('pauseResume').disabled = false;
if (!pauseStartTime) {
document.getElementById('pauseResume').innerText = 'Pause';
timerInterval = setInterval(updateTimer, 1);
} else {
document.getElementById('pauseResume').innerText = 'Resume';
}
// Save the current state in local storage
saveTimerState();
} else {
// Stop the timer
clearInterval(timerInterval);
pauseStartTime = null;
pauseEndTime = null;
const elapsedTime = new Date().getTime() - startTime;
const id = <?php echo json_encode($sid); ?>;
document.getElementById('toggleTimer').innerText = 'Start Timer';
document.getElementById('pauseResume').innerText = 'Pause';
document.getElementById('pauseResume').disabled = true;
// Send the elapsed time and timestamps to the server to store in the database
sendElapsedTime(elapsedTime, id);
startTime = null;
pauseTime = 0;
// Clear the saved state in local storage
localStorage.removeItem('timerState');
}
}
function pauseResumeTimer() {
if (!pauseStartTime) {
// Pause the timer
clearInterval(timerInterval);
pauseStartTime = new Date().getTime();
document.getElementById('pauseResume').innerText = 'Resume';
// Save the current state in local storage
saveTimerState();
} else {
// Resume the timer
pauseEndTime = new Date().getTime();
document.getElementById('pauseResume').innerText = 'Pause';
timerInterval = setInterval(updateTimer, 1);
// Save the current state in local storage
saveTimerState();
}
}
function updateTimer() {
const currentTime = new Date().getTime();
const elapsedTime = currentTime - startTime;
const seconds = Math.floor(elapsedTime / 1000);
const milliseconds = elapsedTime % 1000;
document.getElementById('timeCounter').innerText = `Time Elapsed: ${seconds} seconds ${milliseconds} milliseconds`;
// Save the current state in local storage
saveTimerState();
}
function saveTimerState() {
const timerState = {
startTime,
pauseStartTime,
pauseEndTime,
pauseTime
};
localStorage.setItem('timerState', JSON.stringify(timerState));
}
function sendElapsedTime(elapsedTime, id) {
// Using Fetch API to send data to the server
const url = `timestamp.php?elapsedTime=${elapsedTime}&id=${id}`;
fetch(url, {
method: 'GET',
headers: {
'Content-Type': 'application/json', // You can change this header if needed
},
})
.then(response => response.text())
.catch(error => {
console.error('Error:', error);
});
}
</script>
<!-- Vendor -->
<script src="vendor/jquery/jquery.js"></script>
<script src="vendor/jquery-browser-mobile/jquery.browser.mobile.js"></script>
<script src="vendor/popper/umd/popper.min.js"></script>
<script src="vendor/bootstrap/js/bootstrap.js"></script>
<script src="vendor/common/common.js"></script>
<script src="vendor/nanoscroller/nanoscroller.js"></script>
<script src="vendor/magnific-popup/jquery.magnific-popup.js"></script>
<script src="vendor/jquery-placeholder/jquery-placeholder.js"></script>
<!-- Specific Page Vendor -->
<script src="vendor/jquery-ui/jquery-ui.js"></script>
<script src="vendor/jqueryui-touch-punch/jqueryui-touch-punch.js"></script>
<script src="vendor/jquery-appear/jquery-appear.js"></script>
<script src="vendor/owl.carousel/owl.carousel.js"></script>
<!-- Theme Base, Components and Settings -->
<script src="js/theme.js"></script>
<script src="js/examples/examples.modals.js"></script>
<script src="vendor/pnotify/pnotify.custom.js"></script>
<!-- Theme Custom -->
<!--<script src="js/custom.js"></script>-->
<!--<script src="js/housie.js"></script> -->
<!-- Theme Initialization Files -->
<script src="js/theme.init.js"></script>
<script>
function spell_sound(id) {
var audio = new Audio("sounds/machine/" + id + ".mp3");
audio.play();
}
</script>
<script>
function spell_human(id) {
var audio = new Audio("sounds/human/" + id + ".mp3");
audio.play();
}
</script>
<script>
var source = new EventSource("leaderboard3.php");
source.onmessage = function(event) {
document.getElementById('lboard').innerHTML = event.data;
};
</script>
<script>
var source = new EventSource("login_alert.php");
source.onmessage = function(event) {
if (event.data != "0") {
new PNotify({
title: 'New Login!',
text: event.data,
addclass: 'red notification-primary',
icon: 'fab fa-twitter',
delay: 1000
});
}
}
</script>
<script>
/* function post_answer(qid,ans)
{
alert("hi");
alert(qid);
alert(ans);
}
*/
</script>
<br><br>
<?php include "footer.php"; ?>
</body>
</html>