-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathallusers.php
More file actions
322 lines (284 loc) · 10.1 KB
/
Copy pathallusers.php
File metadata and controls
322 lines (284 loc) · 10.1 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
<?php
require 'config.php';
if (!isset($_SESSION['name']) && !isset($_COOKIE['name'])) {
echo "Session Error";
header("Location: login.php");
exit;
}
if (isset($_SESSION['name']) && isset($_SESSION['email'])) {
$name = $_SESSION['name'];
$email = $_SESSION['email'];
$stmt = $conn->prepare("SELECT codechef_id, leetcode_id, codeforces_id FROM profile WHERE Uemail = ?");
if ($stmt) {
$stmt->bind_param("s", $email);
$stmt->execute();
$stmt->bind_result($codechef_id, $leetcode_id, $codeforces_id);
$stmt->fetch();
$stmt->close();
} else {
die("Query preparation failed: " . $conn->error);
}
}
// We'll fetch user stats via API instead of direct SQL query
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Leaderboard - CodeKeep</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<link rel="stylesheet" href="dashboard.css">
<style>
.leaderboard-table {
width: 100%;
border-collapse: collapse;
margin-top: 20px;
background-color: #1e2130;
border-radius: 8px;
overflow: hidden;
}
.leaderboard-table th, .leaderboard-table td {
padding: 12px 15px;
text-align: left;
border-bottom: 1px solid #2d3748;
}
.leaderboard-table th {
background-color: #2d3748;
color: white;
font-weight: 600;
}
.leaderboard-table tr:hover {
background-color: #2a2e3f;
}
.rank {
font-weight: bold;
text-align: center;
width: 60px;
}
.rank-1 {
color: gold;
}
.rank-2 {
color: silver;
}
.rank-3 {
color: #cd7f32; /* bronze */
}
.total-solved {
font-weight: bold;
text-align: center;
color: #4299e1;
}
.header-with-icon {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 20px;
}
.header-with-icon i {
font-size: 24px;
color: #4299e1;
}
.platform-count {
text-align: center;
font-weight: 500;
}
.platform-header {
text-align: center;
}
.platform-logo {
font-size: 16px;
margin-right: 5px;
}
.loading-spinner {
border: 4px solid rgba(0, 0, 0, 0.1);
width: 36px;
height: 36px;
border-radius: 50%;
border-left-color: #4299e1;
animation: spin 1s linear infinite;
margin: 20px auto;
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
.loader-container {
text-align: center;
padding: 20px;
}
.back-to-dashboard-btn {
position: absolute;
top: 20px;
right: 20px;
display: inline-flex;
align-items: center;
gap: 8px;
padding: 10px 18px;
background-color: #2563eb;
color: white;
border: none;
border-radius: 8px;
cursor: pointer;
font-size: 14px;
font-weight: 500;
text-decoration: none;
transition: all 0.3s ease;
box-shadow: 0 4px 6px rgba(37, 99, 235, 0.25);
z-index: 10;
}
</style>
</head>
<body>
<!-- Sidebar -->
<div class="sidebar">
<div class="logo">
<h1><span class="logo-text"><Code<span style="color: #1a4eaf">Case></span></span></h1>
</div>
<div class="nav-menu">
<a href="dashboard.php" class="nav-item">
<i class="fas fa-home"></i>
<span>Dashboard</span>
</a>
<a href="allusers.php" class="nav-item active">
<i class="fas fa-users"></i>
<span>All Users</span>
</a>
<a href="contests.php" class="nav-item">
<i class="fas fa-calendar"></i>
<span>Contests</span>
</a>
<a href="problems.php" class="nav-item">
<i class="fas fa-code"></i>
<span>Problems</span>
</a>
<a href="notes.php" class="nav-item">
<i class="fas fa-sticky-note"></i>
<span>Notes</span>
</a>
<a href="cp_helper.php" class="nav-item">
<i class="fas fa-robot"></i>
<span>CP Helper</span>
</a>
</div>
<div class="configure-profiles">
<a href="profile.php" class="configure-btn">
<i class="fas fa-user-cog"></i>
<span>Configure Profiles</span>
</a>
</div>
<div class="user-profile">
<div class="user-avatar">
<?php echo substr($name, 0, 1); ?>
</div>
<div class="user-info">
<div class="user-name"><?php echo htmlspecialchars($name); ?></div>
</div>
<button class="logout-btn" onclick="confirmLogout()">
<i class="fas fa-sign-out-alt"></i>
</button>
</div>
</div>
<div class="extra" style="width: 220px; background-color: #171923; padding: 20px 0; display: flex; flex-direction: column; border-right: 1px solid #2d3748;"></div>
<!-- Main Content -->
<div class="main-content">
<div class="header-with-icon">
<i class="fas fa-trophy"></i>
<div>
<a href="dashboard.php" class="back-to-dashboard-btn">
<i class="fas fa-arrow-left"></i> Back to Dashboard
</a>
<h1>Leaderboard</h1>
<p>Users ranked by total problems solved across platforms</p>
</div>
</div>
<table class="leaderboard-table">
<thead>
<tr>
<th>Rank</th>
<th>Name</th>
<th>Email</th>
<th class="platform-header"><i class="platform-logo fas fa-laptop-code"></i>LeetCode</th>
<th class="platform-header"><i class="platform-logo fas fa-utensils"></i>CodeChef</th>
<th class="platform-header"><i class="platform-logo fas fa-code"></i>Codeforces</th>
<th>Total</th>
</tr>
</thead>
<tbody id="leaderboardBody">
<tr>
<td colspan="7">
<div class="loader-container">
<div class="loading-spinner"></div>
<p>Loading leaderboard data...</p>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<script>
function confirmLogout() {
let logoutConfirm = confirm("Are you sure you want to logout?");
if (logoutConfirm) {
window.location.href = 'logout.php';
}
}
// Fetch and populate leaderboard data
document.addEventListener('DOMContentLoaded', function() {
fetch('api/get_user_stats.php')
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json();
})
.then(data => {
if (data.error) {
throw new Error(data.error);
}
populateLeaderboard(data.users);
})
.catch(error => {
document.getElementById('leaderboardBody').innerHTML =
`<tr><td colspan="7" style="text-align: center; color: #f56565; padding: 20px;">
<i class="fas fa-exclamation-circle"></i> Error: ${error.message}
</td></tr>`;
});
});
function populateLeaderboard(users) {
const tbody = document.getElementById('leaderboardBody');
if (users.length === 0) {
tbody.innerHTML = '<tr><td colspan="7" style="text-align: center; padding: 20px;">No users found</td></tr>';
return;
}
let tableContent = '';
users.forEach((user, index) => {
const rank = index + 1;
const rankClass = (rank <= 3) ? `rank-${rank}` : '';
tableContent += `
<tr>
<td class="rank ${rankClass}">${rank}</td>
<td>${escapeHtml(user.name)}</td>
<td>${escapeHtml(user.email)}</td>
<td class="platform-count">${user.leetcode_solved}</td>
<td class="platform-count">${user.codechef_solved}</td>
<td class="platform-count">${user.codeforces_solved}</td>
<td class="total-solved">${user.total_solved}</td>
</tr>
`;
});
tbody.innerHTML = tableContent;
}
// Helper function to escape HTML to prevent XSS
function escapeHtml(unsafe) {
return unsafe
.replace(/&/g, "&")
.replace(/</g, "<")
.replace(/>/g, ">")
.replace(/"/g, """)
.replace(/'/g, "'");
}
</script>
</body>
</html>