-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQuiz.php
367 lines (323 loc) · 11.4 KB
/
Quiz.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
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
<?php
session_start();
include("config/db.php");
// Redirect to login if user is not logged in
if (!isset($_SESSION['user_id'])) {
header("location: login.php");
exit();
}
include("include/header.php");
//! Fetch all quiz lessons
$sql = "SELECT * FROM quizlessons";
$result = mysqli_query($con, $sql);
if (!$result) {
die('Error: ' . mysqli_error($con));
}
$quizLessons = [];
while ($row = mysqli_fetch_assoc($result)) {
$quizLessons[] = $row;
}
//! Fetch unlocked lessons for the current user
$userId = $_SESSION['user_id'];
$unlockedLessons = [];
$sql_unlocked = "SELECT lesson_id FROM lesson_unlocks WHERE user_id = $userId";
$result_unlocked = mysqli_query($con, $sql_unlocked);
if ($result_unlocked) {
while ($row = mysqli_fetch_assoc($result_unlocked)) {
$unlockedLessons[] = $row['lesson_id'];
}
}
//* Define the vertical and horizontal gaps
$verticalGap = 40;
$horizontalGap = 30;
?>
<body>
<div class="container mt-5">
<div class="row justify-content-center">
<div class="col-12">
<div class="quiz-container d-flex flex-column align-items-center">
<div class="chapters" onclick="location.href='chapters.php'" onmouseover=" hoverLesson1(this)" onmouseout="unhoverLesson1(this)" ">
<span class=" quiz-lesson-title">Chapters</span>
</div>
<?php
$prevXPos = 0;
$prevYPos = 0;
$direction = 1; // 1 for right, -1 for left
?>
<?php foreach ($quizLessons as $i => $quizLesson) : ?>
<?php
// Calculate positions for a snake-like pattern
$xPos = $prevXPos + ($direction * $horizontalGap);
$yPos = $i * $verticalGap;
$prevXPos = $xPos;
$prevYPos = $yPos;
// Alternate the direction after every two lessons
if (($i + 1) % 2 === 0) {
$direction *= -1;
}
// Determine the color based on user status
$lessonColor = "#4D555A"; // Default color
if (empty($unlockedLessons)) { // New user
if ($i === 0) {
$lessonColor = "orange"; // First lesson for new user
}
} else { // Existing user
if (in_array($quizLesson['qlesson_id'], $unlockedLessons)) {
$lessonColor = "green"; // Unlocked lesson
} elseif ($i === (count($unlockedLessons))) {
$lessonColor = "orange"; // Next lesson after last unlocked
}
}
// Determine the content to display (number or lock icon)
$content = ($lessonColor === "#4D555A") ? "<i class='fas fa-lock'></i>" : ($i + 1);
?>
<div class="quiz-lesson" onclick="showDialogueBox('<?php echo $quizLesson['qlesson_id']; ?>', '<?php echo $quizLesson['title']; ?>', event)" onmouseover="hoverLesson(this)" onmouseout="unhoverLesson(this)" style="top: <?php echo $yPos; ?>vh; left: <?php echo $xPos; ?>vw; z-index: <?php echo $i + 1; ?>; background-color: <?php echo $lessonColor; ?>">
<span class="quiz-lesson-number"><?php echo $content; ?></span>
<span class="quiz-lesson-title"><?php echo $quizLesson['title']; ?></span>
</div>
<?php endforeach; ?>
<audio id="dialogue-sound" preload="auto">
<source src="assets\Japan\pop_up001.mp3" type="audio/mpeg">
</audio>
</div>
</div>
</div>
</div>
<!-- Placeholder div for jQuery dialog -->
<div id="quiz-dialogue-box" class="dialogue-box" style="display: none;">
<div id="dialogue-box-arrow" class="dialogue-box-arrow"></div>
<div id="dialogue-content" class="ui-dialog-content"></div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/js/toastr.min.js"></script>
<?php if (isset($_SESSION['notification'])) : ?>
<script>
// Set toastr options before displaying the error message
toastr.options = {
"positionClass": "toast-bottom-left", // Change position to top center
"preventDuplicates": true // Prevent duplicate toasts
};
toastr.warning("<?php echo $_SESSION['notification']; ?>");
</script>
<?php unset($_SESSION['notification']); ?>
<?php endif; ?>
<style>
body {
background-color: white;
}
/* scroll bar hiden */
body::-webkit-scrollbar {
display: none;
}
.quiz-container {
position: relative;
margin-top: 5vh;
margin-left: 20vh;
}
.chapters {
border-radius: 50%;
width: 11vw;
height: 11vw;
background-color: rgba(128, 128, 0, 0.7);
box-shadow: 0px 5px 15px rgba(0, 0, 0, 0.3);
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
cursor: pointer;
transition: box-shadow 0.3s, transform 0.3s;
position: absolute;
transform: translate(300%, -20%);
}
.chapters:hover {
box-shadow: 0px 5px 15px rgba(0, 0, 0, 0.6);
}
.quiz-lesson {
border-radius: 50%;
width: 17vw;
height: 17vw;
box-shadow: 0px 5px 15px rgba(0, 0, 0, 0.3);
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
cursor: pointer;
transition: box-shadow 0.3s, transform 0.3s;
position: absolute;
transform: translateX(-50%);
}
.quiz-lesson:hover {
box-shadow: 0px 5px 15px rgba(0, 0, 0, 0.6);
}
.quiz-lesson-number {
font-size: 3vw;
font-weight: bold;
color: #fff;
}
.quiz-lesson-title {
font-size: 2vw;
text-align: center;
color: #fff;
}
/* Custom CSS for the dialogue box */
.ui-dialog.ui-widget.ui-widget-content.ui-corner-all.ui-front.ui-dialog-buttons.ui-draggable.ui-resizable.dialogue-box {
border: 2px solid #90d93f;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
}
/* title bar */
.ui-dialog-titlebar {
background: #b0de78;
color: #fff;
font-weight: bold;
padding: 10px;
}
/* close button */
.ui-dialog-titlebar-close {
display: none;
}
/* dialogue content */
.ui-dialog-content {
background: #F9F9F9;
color: #222;
font-size: 16px;
padding: 20px;
}
/* the button container */
#button-container {
display: flex;
justify-content: center;
margin-top: 10px;
}
/* buttons */
#button-container button {
background: #90d93f;
border: none;
border-radius: 5px;
color: #fff;
cursor: pointer;
font-size: 14px;
margin: 5px;
padding: 10px 20px;
transition: 0.3s;
}
/* buttons when hovered */
#button-container button:hover {
background: #b0de78;
transform: scale(1.1);
}
/* buttons when disabled */
#button-container button:disabled {
background: #ccc;
color: #999;
cursor: not-allowed;
}
/* Custom CSS for the cancel button */
.ui-dialog .ui-dialog-buttonpane .ui-dialog-buttonset button:last-of-type {
background: #ff6b6b;
/* Change the background color of the cancel button */
color: #fff;
/* Change the text color of the cancel button */
border: none;
/* Remove the border of the cancel button */
border-radius: 5px;
/* Add some rounded corners to the cancel button */
cursor: pointer;
/* Change the cursor to a pointer when hovering over the cancel button */
font-size: 14px;
/* Change the font size of the cancel button */
padding: 10px 20px;
/* Add some padding to the cancel button */
transition: 0.3s;
/* Add some transition effect to the cancel button */
}
/* Custom CSS for the cancel button when hovered */
.ui-dialog .ui-dialog-buttonpane .ui-dialog-buttonset button:last-of-type:hover {
background: #ff8f8f;
/* Change the background color of the cancel button when hovered */
transform: scale(1.1);
/* Make the cancel button slightly larger when hovered */
}
/* Custom CSS for the cancel button when disabled */
.ui-dialog .ui-dialog-buttonpane .ui-dialog-buttonset button:last-of-type:disabled {
background: #ccc;
/* Change the background color of the cancel button when disabled */
color: #999;
/* Change the text color of the cancel button when disabled */
cursor: not-allowed;
/* Change the cursor to a not-allowed sign when hovering over the disabled cancel button */
}
</style>
<script>
function hoverLesson1(element) {
element.style.backgroundColor = "rgba(34, 139, 34, 0.6)";
}
function unhoverLesson1(element) {
element.style.backgroundColor = "rgba(128, 128, 0, 0.7)";
}
function hoverLesson(element) {
//! baki hei karna abhi
}
function unhoverLesson(element) {
//! baki hei karna abhi
}
function showDialogueBox(lessonId, lessonTitle, event) {
var lessonElement = event.currentTarget;
var lessonColor = $(lessonElement).css('background-color');
// Fetch last attempt time and time limit using AJAX
var userId = <?php echo $_SESSION['user_id']; ?>;
$.ajax({
type: "POST",
url: "get_last_attempt_time.php", // PHP file to handle the AJAX request
data: {
userId: userId,
lessonId: lessonId
},
success: function(response) {
var data = JSON.parse(response);
var lastAttemptTime = data.lastAttemptTime;
var timeLimit = data.timeLimit;
// Create the dialog content including last attempt time and time limit
var dialogueContent = "<p>Last Attempt Time: " + lastAttemptTime + "</p>";
dialogueContent += "<p>Time Limit: " + timeLimit + " minutes</p><br>";
dialogueContent += "<p>Start the quiz:</p><div id='button-container'><button id='start-quiz-btn'>Start " + lessonTitle + " Quiz</button></div>";
// Create the dialog box dynamically and append it to the placeholder div
var dialogueBox = $('<div></div>')
.html(dialogueContent)
.dialog({
autoOpen: false,
modal: true,
title: lessonTitle + ' Quiz',
closeOnEscape: false, // Prevent closing dialog on pressing ESC key
showCloseButton: false, // Hide the close button in the title bar
close: function() {
$(this).dialog('destroy').remove();
},
buttons: [{
text: "Cancel",
click: function() {
$(this).dialog("close");
}
}]
});
// Set button state based on lesson color
if (lessonColor === 'rgb(0, 128, 0)' || lessonColor === 'rgb(255, 165, 0)') {
dialogueBox.find("#start-quiz-btn").prop("disabled", false);
dialogueBox.find("#start-quiz-btn").click(function() {
window.location.href = 'quiz_page.php?qlesson_id=' + lessonId;
});
} else {
dialogueBox.find("#start-quiz-btn").prop("disabled", true);
}
// Open the dialog box
dialogueBox.dialog('open');
document.getElementById('dialogue-sound').play();
},
error: function(xhr, status, error) {
console.error(error);
// Handle error
}
});
}
</script>
</body>
</html>