-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdashboard.php
More file actions
149 lines (128 loc) · 4.67 KB
/
Copy pathdashboard.php
File metadata and controls
149 lines (128 loc) · 4.67 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
<?php
session_start();
include 'db_connect.php';
if (!isset($_SESSION['username'])) {
header("Location: login.php");
exit();
}
$username = $_SESSION['username'];
$sql_user = "SELECT user_id FROM users WHERE username = ?";
$stmt_user = $conn->prepare($sql_user);
$stmt_user->bind_param("s", $username);
$stmt_user->execute();
$result_user = $stmt_user->get_result();
if ($result_user->num_rows === 0) {
echo "User not found.";
exit();
}
$user = $result_user->fetch_assoc();
$user_id = $user['user_id'];
$sql1 = "SELECT COUNT(*) as total_submissions FROM submissions WHERE user_id = ?";
$stmt1 = $conn->prepare($sql1);
$stmt1->bind_param("i", $user_id);
$stmt1->execute();
$result1 = $stmt1->get_result()->fetch_assoc();
$total_submissions = $result1['total_submissions'];
$sql2 = "SELECT COUNT(*) as total_solved FROM submissions WHERE user_id = ? AND status = 'solved'";
$stmt2 = $conn->prepare($sql2);
$stmt2->bind_param("i", $user_id);
$stmt2->execute();
$result2 = $stmt2->get_result()->fetch_assoc();
$total_solved = $result2['total_solved'];
$sql3 = "SELECT s.*, p.title FROM submissions s
JOIN problems p ON s.problem_id = p.problem_id
WHERE s.user_id = ? ORDER BY s.date_solved DESC LIMIT 5";
$stmt3 = $conn->prepare($sql3);
$stmt3->bind_param("i", $user_id);
$stmt3->execute();
$recent = $stmt3->get_result();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>DSA Tracker - Dashboard</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css">
<style>
body {
background: linear-gradient(135deg, #e0c3fc, #8ec5fc);
font-family: 'Segoe UI', sans-serif;
}
.header {
background-color: rgba(21, 101, 192, 0.9);
color: white;
padding: 15px;
text-align: center;
font-size: 26px;
font-weight: 700;
letter-spacing: 1px;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}
.dashboard {
margin-top: 40px;
background: white;
padding: 30px;
border-radius: 15px;
box-shadow: 0 8px 30px rgba(0, 0, 0, 0.1);
}
.btn-custom {
min-width: 160px;
}
</style>
</head>
<body>
<div class="header">Welcome, <?php echo htmlspecialchars($username); ?>!</div>
<div class="container dashboard mt-4">
<div class="d-flex justify-content-center gap-3 flex-wrap mb-4">
<a href="problems.php" class="btn btn-outline-primary btn-custom">📘 All Problems</a>
<a href="add_problems.php" class="btn btn-outline-success btn-custom">➕ Add Problem</a>
<a href="my_submissions.php" class="btn btn-outline-secondary btn-custom">📄 My Submissions</a>
</div>
<div class="row mb-4">
<div class="col-md-6">
<div class="card text-white bg-success">
<div class="card-body">
<h5 class="card-title">Total Problems Solved</h5>
<p class="card-text fs-4"><?php echo $total_solved; ?></p>
</div>
</div>
</div>
<div class="col-md-6">
<div class="card text-white bg-primary">
<div class="card-body">
<h5 class="card-title">Total Submissions</h5>
<p class="card-text fs-4"><?php echo $total_submissions; ?></p>
</div>
</div>
</div>
</div>
<div class="d-flex justify-content-between align-items-center">
<h4>Recent Activity</h4>
<a href="analytics.php" class="btn btn-outline-info">📊 View Analytics</a>
</div>
<table class="table table-striped mt-2">
<thead>
<tr>
<th>Problem</th>
<th>Status</th>
<th>Time Taken</th>
<th>Date Solved</th>
</tr>
</thead>
<tbody>
<?php while ($row = $recent->fetch_assoc()): ?>
<tr>
<td><?php echo htmlspecialchars($row['title']); ?></td>
<td><?php echo ucfirst($row['status']); ?></td>
<td><?php echo htmlspecialchars($row['time_taken']); ?> mins</td>
<td><?php echo htmlspecialchars($row['date_solved']); ?></td>
</tr>
<?php endwhile; ?>
</tbody>
</table>
<div class="text-center">
<a href="logout.php" class="btn btn-danger mt-3">🚪 Logout</a>
</div>
</div>
</body>
</html>