-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemp.txt
More file actions
443 lines (405 loc) · 14.9 KB
/
Copy pathtemp.txt
File metadata and controls
443 lines (405 loc) · 14.9 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
<?php
require 'backend/ud/session.php'; // Load session data
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<script src="https://cdn.tailwindcss.com"></script>
<link
rel="icon"
type="image/x-icon"
href="assets/img/background/fav-logo.png"
/>
<title>CodeCraft Dashboard - Test Section</title>
<style>
@import url("https://fonts.googleapis.com/css2?family=Syne:wght@400..800&display=swap");
* {
font-family: "Syne", serif;
font-optical-sizing: auto;
font-style: normal;
}
.relative-box {
position: relative;
bottom: 14rem;
}
</style>
</head>
<body
class="bg-[url('Mask.png')] bg-cover bg-center bg-no-repeat min-h-screen font-sans"
>
<div class="flex">
<!-- Sidebar -->
<aside
class="w-1/5 shadow-lg flex flex-col justify-between h-screen sticky top-0"
>
<div class="p-6">
<!-- Logo -->
<div class="text-2xl font-bold text-purple-600 mb-10">
<img src="assets/img/background/logo.png" alt="Dashboard logo" />
</div>
<!-- Menu Links -->
<nav class="space-y-6">
<a
href="dashboard.php"
class="flex items-center space-x-4 text-purple-600"
>
<img
src="assets/img/background/document-active.png"
width="20px"
alt="Dashboard Icon"
/>
<span>Dashboard</span>
</a>
<a href="test-list.php" class="flex items-center space-x-4">
<img
src="assets/img/background/test-active.png"
width="20px"
alt="Tests Icon"
/>
<span>Tests</span>
</a>
<a href="problems.php" class="flex items-center space-x-4">
<img
src="assets/img/background/document.png"
width="20px"
alt="Courses Icon"
/>
<span>Problem Sets</span>
</a>
<a href="profile-coder.php" class="flex items-center space-x-4">
<img
src="assets/img/background/dp.png"
width="20px"
alt="Profile Icon"
/>
<span>Profile</span>
</a>
<a href="leaderboard.php" class="flex items-center space-x-4">
<img
src="assets/img/background/leaderboard.png"
width="20px"
alt="Leaderboard Icon"
/>
<span>Leaderboard</span>
</a>
<a href="inbox.php" class="flex items-center space-x-4">
<img
src="assets/img/background/chat.png"
width="20px"
alt="Chat Icon"
/>
<span>Inbox</span>
</a>
</nav>
</div>
<div class="p-6 space-y-6">
<!-- Bottom Links -->
<a href="settings.php" class="flex items-center space-x-4">
<img
src="assets/img/background/setting.png"
width="20px"
alt="Settings Icon"
/>
<span>Settings</span>
</a>
<a href="backend/logout.php" class="flex items-center space-x-4">
<img
src="assets/img/background/logout.png"
width="20px"
alt="Logout Icon"
/>
<span>Log Out</span>
</a>
</div>
</aside>
<!-- Main Content -->
<main class="flex-1 p-8">
<!-- Header -->
<header class="flex justify-between items-center mb-8">
<h1 class="text-2xl font-bold"></h1>
<div class="flex items-center space-x-4">
<div class="relative flex items-center">
<img
src="assets/img/background/search.png"
alt="Search Icon"
class="absolute left-3 w-4 h-4"
/>
<input
type="text"
placeholder="Search"
class="pl-10 pr-4 py-2 border border-gray-300 rounded-lg w-full"
/>
</div>
<img
src="assets/img/background/Bell.png"
width="20px"
alt="Notification Icon"
class="cursor-pointer"
/>
<img
src="<?php echo htmlspecialchars($userProfilePicture); ?>"
alt="Profile Icon"
class="rounded-full cursor-pointer"
style="width: 40px; height: 40px; object-fit: cover"
/>
</div>
</header>
<!-- 1st Row - Recent Solving Problems and Leaderboard -->
<div class="grid grid-cols-3 gap-8">
<!-- 1st Column: Recent Solving Problems -->
<div class="col-span-2 bg-white shadow-lg rounded-lg p-6">
<h2 class="text-xl font-semibold text-purple-600 mb-4">
Recent Solving Problems
</h2>
<div class="col-span-2">
<div class="flex space-x-4">
<div class="bg-white shadow-md rounded-lg p-4">
<img
src="assets/img/background/c.jpeg"
width="150px"
height="150px"
alt="Problem image"
class="rounded mb-3 mx-auto"
/>
<h3 class="font-semibold">Problem 1</h3>
<p class="text-gray-600 text-sm">
Short description of the problem...
</p>
<p class="text-sm text-gray-500">Language: Python</p>
<div class="flex items-center space-x-2 mt-2">
<div
class="w-16 h-16 bg-gray-200 rounded-full flex items-center justify-center"
>
<p class="font-semibold text-sm">85%</p>
</div>
<span>Accuracy</span>
</div>
</div>
<div class="bg-white shadow-md rounded-lg p-4">
<img
src="assets/img/background/c.jpeg"
width="150px"
height="150px"
alt="Problem image"
class="rounded mb-3 mx-auto"
/>
<h3 class="font-semibold">Problem 1</h3>
<p class="text-gray-600 text-sm">
Short description of the problem...
</p>
<p class="text-sm text-gray-500">Language: Python</p>
<div class="flex items-center space-x-2 mt-2">
<div
class="w-16 h-16 bg-gray-200 rounded-full flex items-center justify-center"
>
<p class="font-semibold text-sm">85%</p>
</div>
<span>Accuracy</span>
</div>
</div>
<div class="bg-white shadow-md rounded-lg p-4">
<img
src="assets/img/background/c.jpeg"
width="150px"
height="150px"
alt="Problem image"
class="rounded mb-3 mx-auto"
/>
<h3 class="font-semibold">Problem 1</h3>
<p class="text-gray-600 text-sm">
Short description of the problem...
</p>
<p class="text-sm text-gray-500">Language: Python</p>
<div class="flex items-center space-x-2 mt-2">
<div
class="w-16 h-16 bg-gray-200 rounded-full flex items-center justify-center"
>
<p class="font-semibold text-sm">85%</p>
</div>
<span>Accuracy</span>
</div>
</div>
</div>
<!-- Pagination Buttons -->
<div class="flex justify-between mt-4 md:w-[800px]">
<div
class="w-10 h-10 px-2 py-2 bg-gray-300 text-gray-700 rounded-full flex justify-center"
>
<img
src="assets/img/background/left.png"
width="20px"
alt="Left Arrow Icon"
/>
</div>
<span>Page 1 of 5</span>
<div
class="w-10 h-10 py-2 bg-gray-300 text-gray-700 rounded-full flex justify-center"
>
<img
src="assets/img/background/right.png"
width="20px"
alt="Right Arrow Icon"
/>
</div>
</div>
</div>
</div>
<div class="bg-white shadow-lg rounded-lg p-6">
<h2 class="text-xl font-semibold text-purple-600 mb-4">Leaderboard</h2>
<div class="space-y-4">
<!-- Dynamic leaderboard entries will be populated here -->
</div>
<!-- Pagination Controls -->
<div class="flex justify-between mt-4">
<button
id="prevPage"
class="w-10 h-10 px-2 py-2 bg-gray-300 text-gray-700 rounded-full flex justify-center disabled:opacity-50"
disabled
>
<img src="assets/img/background/left.png" width="20px" alt="Previous Page" />
</button>
<span id="pagination-info" class="text-gray-700">Page 1 of 5</span>
<button
id="nextPage"
class="w-10 h-10 px-2 py-2 bg-gray-300 text-gray-700 rounded-full flex justify-center disabled:opacity-50"
>
<img src="assets/img/background/right.png" width="20px" alt="Next Page" />
</button>
</div>
</div>
</div>
<div class="col-span-2 bg-white shadow-lg rounded-lg p-6">
<h2 class="text-xl font-semibold text-purple-600 mb-4">
Upcoming Coding Contests
</h2>
<div id="contests-container" class="grid grid-cols-3 gap-6">
<!-- Contests will be dynamically added here -->
</div>
<!-- Pagination (if required) -->
</div>
</main>
</div>
</body>
<script>
let currentPage = 1; // Keep track of the current page
// Fetch and populate leaderboard
async function fetchLeaderboard(page = 1, search = "") {
const url = `backend/fetch_leaderboard.php?page=${page}&search=${encodeURIComponent(search)}`;
try {
const response = await fetch(url);
const data = await response.json();
// Populate the leaderboard
populateLeaderboard(data.data);
// Update pagination info
const totalPages = data.totalPages;
document.querySelector("#pagination-info").textContent = `Page ${page} of ${totalPages}`;
// Enable/disable pagination buttons based on the current page
document.getElementById("prevPage").disabled = page <= 1;
document.getElementById("nextPage").disabled = page >= totalPages;
} catch (error) {
console.error("Error fetching leaderboard data:", error);
alert("Failed to load leaderboard. Please try again later.");
}
}
// Populate leaderboard section dynamically
function populateLeaderboard(users) {
const leaderboardContainer = document.querySelector(".space-y-4");
leaderboardContainer.innerHTML = ""; // Clear existing content
users.forEach((user, index) => {
const rankClass =
index === 0
? "bg-yellow-200"
: index === 1
? "bg-gray-200"
: index === 2
? "bg-orange-200"
: "";
const trophy =
index === 0
? "assets/img/background/trophy-gold.png"
: index === 1
? "assets/img/background/trophy-silver.png"
: index === 2
? "assets/img/background/trophy-bronze.png"
: null;
const userHTML = `
<div class="flex items-center justify-between ${rankClass} rounded-lg px-4 py-2">
<div class="flex items-center space-x-4">
<img src="${user.profilePicture || 'https://via.placeholder.com/40'}" alt="Avatar" class="w-10 h-10 rounded-full" />
<span class="font-semibold">${index + 1}. ${user.username}</span>
</div>
<div class="flex items-center space-x-2">
<span class="font-semibold text-purple-600">Solved ${user.total_problems_solved}</span>
</div>
</div>`;
leaderboardContainer.innerHTML += userHTML;
});
}
// Add event listeners for pagination buttons
document.getElementById("prevPage").addEventListener("click", () => {
if (currentPage > 1) {
currentPage--;
fetchLeaderboard(currentPage);
}
});
document.getElementById("nextPage").addEventListener("click", () => {
currentPage++;
fetchLeaderboard(currentPage);
});
// Initialize the leaderboard on page load
document.addEventListener("DOMContentLoaded", function () {
fetchLeaderboard(currentPage);
});
</script>
<script>
document.addEventListener("DOMContentLoaded", function () {
// Function to fetch contest data from the backend
fetch("backend/contest/upcoming.php")
.then((response) => {
if (!response.ok) {
throw new Error("Failed to fetch contest data.");
}
return response.json();
})
.then((contests) => {
const container = document.getElementById("contests-container");
container.innerHTML = ""; // Clear any existing content
if (contests.length === 0) {
container.innerHTML = `<p class="text-gray-500">No upcoming contests available.</p>`;
return;
}
contests.forEach((contest) => {
const contestCard = `
<div class="flex flex-col items-center space-y-4 p-4 border border-gray-300 rounded-lg">
<img
src="${contest.banner || 'https://via.placeholder.com/80'}"
alt="Contest Banner"
class="rounded-lg mb-4"
/>
<div>
<h3 class="font-semibold">${contest.contest_name}</h3>
<p class="text-gray-600 text-sm">Registration Ends: ${new Date(contest.registration_end_time).toLocaleString()}</p>
<p class="text-sm text-gray-500">${contest.description}</p>
<p class="font-semibold text-purple-600">Contest Dates: ${new Date(contest.start_time).toLocaleDateString()} - ${new Date(contest.end_time).toLocaleDateString()}</p>
</div>
<button
class="mt-4 px-6 py-2 bg-purple-400 text-white rounded-full hover:bg-purple-500"
onclick="window.location.href='upcoming-contest.php?contest_id=${contest.contest_id}'"
>
Details
</button>
</div>`;
container.innerHTML += contestCard;
});
})
.catch((error) => {
console.error("Error:", error);
const container = document.getElementById("contests-container");
container.innerHTML = `<p class="text-red-500">Failed to load contests. Please try again later.</p>`;
});
});
// Placeholder function for registering for contests
</script>
</html>