-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdashboard.php
More file actions
178 lines (152 loc) · 6.98 KB
/
Copy pathdashboard.php
File metadata and controls
178 lines (152 loc) · 6.98 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
<?php
// Start session and check if user is logged in
if (session_status() === PHP_SESSION_NONE) {
session_start();
}
// Checks if the user is not logged in
if (!isset($_SESSION['user_id'])) {
header('Location: auth/login.php');
exit;
}
//Import database connection
require_once 'config/database.php';
//gets logged in user's ID from session
$user_id = $_SESSION['user_id'];
// Count total subjects
//prepares the SQL query
$stmt = $pdo->prepare("SELECT COUNT(*) AS total_subjects FROM subjects WHERE user_id = ?");
//execute or run the query
$stmt->execute([$user_id]);
//gets the result and stores the number inside
$subject_count = $stmt->fetch(PDO::FETCH_ASSOC)['total_subjects'];
// Count total tasks
$stmt = $pdo->prepare("SELECT COUNT(*) AS total_tasks FROM tasks WHERE user_id = ?");
$stmt->execute([$user_id]);
$total_tasks = $stmt->fetch(PDO::FETCH_ASSOC)['total_tasks'];
// Count pending tasks
$stmt = $pdo->prepare("SELECT COUNT(*) AS pending_tasks FROM tasks WHERE user_id = ? AND status = 'Pending'");
$stmt->execute([$user_id]);
$pending_tasks = $stmt->fetch(PDO::FETCH_ASSOC)['pending_tasks'];
// Count completed tasks
$stmt = $pdo->prepare("SELECT COUNT(*) AS completed_tasks FROM tasks WHERE user_id = ? AND status = 'Completed'");
$stmt->execute([$user_id]);
$completed_tasks = $stmt->fetch(PDO::FETCH_ASSOC)['completed_tasks'];
// Count high priority pending tasks
$stmt = $pdo->prepare("SELECT COUNT(*) AS high_priority_tasks FROM tasks WHERE user_id = ? AND priority = 'High' AND status = 'Pending'");
$stmt->execute([$user_id]);
$high_priority_tasks = $stmt->fetch(PDO::FETCH_ASSOC)['high_priority_tasks'];
// Get 5 pending tasks with deadlines
$stmt = $pdo->prepare("
SELECT tasks.*, subjects.subject_name
FROM tasks
LEFT JOIN subjects ON tasks.subject_id = subjects.id
WHERE tasks.user_id = ?
AND tasks.status = 'Pending'
AND tasks.deadline IS NOT NULL
ORDER BY tasks.deadline ASC
LIMIT 5
");
$stmt->execute([$user_id]);
$upcoming_tasks = $stmt->fetchAll(PDO::FETCH_ASSOC);
$page_title = 'Dashboard';
//Imports header.php
require_once 'includes/header.php';
?>
<div class="row">
<div class="col-12">
<div class="card shadow-sm border-0">
<div class="card-body p-4">
<h2 class="fw-bold mb-2">
Welcome, <?php echo htmlspecialchars($_SESSION['user_name']); ?>!
</h2>
<p class="text-muted mb-4">
This is your StudyMate dashboard. Here you can quickly view your subjects,
tasks, deadlines, and study progress.
</p>
<div class="row">
<div class="col-md-4 mb-3">
<div class="card border-0 bg-light">
<div class="card-body text-center">
<h5 class="fw-bold">Subjects</h5>
<p class="display-6 mb-0"><?php echo $subject_count; ?></p>
</div>
</div>
</div>
<div class="col-md-4 mb-3">
<div class="card border-0 bg-light">
<div class="card-body text-center">
<h5 class="fw-bold">Total Tasks</h5>
<p class="display-6 mb-0"><?php echo $total_tasks; ?></p>
</div>
</div>
</div>
<div class="col-md-4 mb-3">
<div class="card border-0 bg-light">
<div class="card-body text-center">
<h5 class="fw-bold">Pending Tasks</h5>
<p class="display-6 mb-0"><?php echo $pending_tasks; ?></p>
</div>
</div>
</div>
<div class="col-md-4 mb-3">
<div class="card border-0 bg-light">
<div class="card-body text-center">
<h5 class="fw-bold">Completed Tasks</h5>
<p class="display-6 mb-0"><?php echo $completed_tasks; ?></p>
</div>
</div>
</div>
<div class="col-md-4 mb-3">
<div class="card border-0 bg-light">
<div class="card-body text-center">
<h5 class="fw-bold">High Priority</h5>
<p class="display-6 mb-0"><?php echo $high_priority_tasks; ?></p>
</div>
</div>
</div>
</div>
<div class="mt-4 mb-4">
<h4 class="fw-bold mb-3">Upcoming Deadlines</h4>
<?php if (empty($upcoming_tasks)): ?>
<div class="alert alert-info">
No upcoming deadlines found.
</div>
<?php else: ?>
<div class="table-responsive">
<table class="table table-bordered align-middle">
<thead class="table-light">
<tr>
<th>Task</th>
<th>Subject</th>
<th>Priority</th>
<th>Deadline</th>
</tr>
</thead>
<tbody>
<!-- loop through upcoming tasks -->
<?php foreach ($upcoming_tasks as $task): ?>
<tr>
<!-- display task information -->
<td><?php echo htmlspecialchars($task['title']); ?></td>
<td><?php echo htmlspecialchars($task['subject_name'] ?? 'No subject'); ?></td>
<td><?php echo htmlspecialchars($task['priority']); ?></td>
<td><?php echo htmlspecialchars($task['deadline']); ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<?php endif; ?>
</div>
<a href="subjects/index.php" class="btn btn-secondary">
Manage Subjects
</a>
<a href="tasks/index.php" class="btn btn-outline-secondary">
Manage Tasks
</a>
</div>
</div>
</div>
</div>
<!-- imports footer.php -->
<?php require_once 'includes/footer.php'; ?>