-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdashboard.php
More file actions
203 lines (184 loc) · 7.94 KB
/
dashboard.php
File metadata and controls
203 lines (184 loc) · 7.94 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
<?php
require_once __DIR__ . '/auth/_guard.php';
require_once __DIR__ . '/config/constants.php';
require_once __DIR__ . '/config/db.php';
require_login();
$activities = db_get_activities();
$user = current_user();
// FEATURE 1: Onboarding Hook
$pdo = db_connect();
// Check if onboarding is skipped or done in session to avoid DB hit every time?
// For now, DB hit is safer and fast enough.
$stmtOnb = $pdo->prepare("SELECT id FROM onboarding_attempts WHERE user_id = :uid LIMIT 1");
$stmtOnb->execute(['uid' => $user['id']]);
if (!$stmtOnb->fetch()) {
redirect('/onboarding_test.php');
}
// Defensive coding for stats
$stats = db_get_report_stats($user['id']) ?? [];
$streak = $stats['study_streak'] ?? 0;
// Safe weak topic extraction
$weakTopic = 'None yet';
if (!empty($stats['weak_topics']) && is_array($stats['weak_topics'])) {
$weakTopic = array_key_first($stats['weak_topics']);
}
// Ensure string for display usage
$weakTopic = (string) $weakTopic;
require_once __DIR__ . '/templates/header.php';
?>
<!-- Onboarding / Welcome Toast -->
<?php if (isset($_GET['onboarding_complete'])): ?>
<div id="welcome-toast" class="theme-toast visible" style="background: var(--primary); color: white;">
🎉 <strong>Welcome aboard!</strong> Your starting level is
<strong><?= htmlspecialchars($_GET['level'] ?? 'A1') ?></strong>.
</div>
<script>
setTimeout(() => {
const t = document.getElementById('welcome-toast');
if (t) {
t.style.opacity = '0';
setTimeout(() => t.remove(), 500);
}
}, 5000);
</script>
<?php endif; ?>
<!-- HERO SECTION -->
<div class="section">
<div style="margin-bottom: 24px;">
<?php
$quotes = [
"Small steps every day lead to big results 🚀",
"You’re only one quiz away from your next badge 💎",
"Consistency beats intensity. Keep going 💪",
"Learning is a marathon, not a sprint 🏃♂️",
"Mistakes are proof that you are trying 🧠"
];
$quote = $quotes[array_rand($quotes)];
?>
<h2>Running Dashboard 🏃♂️</h2>
<p class="muted">Welcome back, <?= htmlspecialchars($user['name']) ?>. <?= $quote ?></p>
</div>
<div class="grid">
<!-- Streak Card -->
<div class="stat-card">
<div class="stat-icon">🔥</div>
<div class="stat-info">
<div class="label">Day Streak</div>
<div class="value"><?= $streak ?></div>
</div>
</div>
<!-- Today's Goal -->
<?php
require_once __DIR__ . '/services/gamification.php';
$goalProgress = db_get_todays_goal_progress($user['id']);
$gDone = $goalProgress['done'];
$gTotal = $goalProgress['total'];
$gPercent = ($gTotal > 0) ? ($gDone / $gTotal) * 100 : 0;
$gRemaining = $gTotal - $gDone;
?>
<div class="card">
<div style="display:flex; justify-content:space-between; margin-bottom:8px;">
<span class="muted" style="font-size:0.85rem; text-transform:uppercase; font-weight:700;">Today's Goal</span>
<span style="font-weight:700; color:var(--secondary-dark);"><?= $gDone ?> / <?= $gTotal ?> Tasks</span>
</div>
<div class="progress-track" style="margin-left: 0; background: var(--bg-body);">
<div class="progress-fill" style="width:<?= $gPercent ?>%; background:var(--secondary);"></div>
</div>
<p style="font-size:0.85rem; margin-top:12px; margin-bottom:0;" class="muted">
<?php if ($gRemaining > 0): ?>
Complete <?= $gRemaining ?> more activit<?= $gRemaining !== 1 ? 'ies' : 'y' ?> to reach your daily goal.
<?php else: ?>
🎉 All goals completed for today! Great job.
<?php endif; ?>
</p>
</div>
<!-- Weakest Topic & Resume -->
<div class="card" style="display:flex; flex-direction:column; gap:20px; padding:20px;">
<!-- 1. Resume Panel (Top) -->
<div class="card-resume-gradient"
style="padding:24px; border-radius:12px; display:flex; flex-direction:column; justify-content:center; align-items:start; width:100%; background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%); box-shadow: 0 10px 20px rgba(99, 102, 241, 0.3); color: white;">
<div style="font-weight:700; font-size:1.1rem; margin-bottom:4px; color:#fff;">Ready to learn?</div>
<div style="opacity:0.9; font-size:0.9rem; margin-bottom:16px; color:#fff;">Continue where you left off.</div>
<a href="<?= BASE_URL ?>/activity/quiz.php" class="btn resume-quiz-btn">
Resume Quiz <i>→</i>
</a>
</div>
<!-- 2. Focus Area (Bottom) -->
<div style="display:flex; align-items:center; gap:20px;">
<div class="stat-icon" style="background:var(--secondary-soft); color:var(--secondary);">🎯</div>
<div class="stat-info">
<div class="label">Focus Area</div>
<div class="value" style="font-size:1.2rem; text-transform:capitalize;">
<?= htmlspecialchars(str_replace('_', ' ', (string) $weakTopic)) ?>
</div>
</div>
</div>
</div>
</div>
<section class="section">
<h3>Activity Selection</h3>
<?php if (empty($activities)): ?>
<div class="card">
<p class="muted">No activities available yet.</p>
</div>
<?php else: ?>
<div class="grid">
<?php foreach ($activities as $act): ?>
<?php
$actId = (int) ($act['id'] ?? 0);
$actType = $act['activity_type'] ?? 'unknown';
$actTitle = $act['title'] ?? 'Activity';
$actDesc = $act['description'] ?? '';
$actEnabled = (bool) ($act['is_enabled'] ?? false);
$actLink = BASE_URL . '/activity/' . $actType . '.php?activity_id=' . $actId;
?>
<div class="card">
<div class="card-title"><?php echo htmlspecialchars($actTitle); ?></div>
<div class="card-desc"><?php echo htmlspecialchars($actDesc); ?></div>
<?php if ($actEnabled): ?>
<a class="btn btn-primary" href="<?php echo htmlspecialchars($actLink); ?>">
Start <?php echo htmlspecialchars(ucfirst($actType)); ?>
</a>
<?php else: ?>
<span class="btn" aria-disabled="true" style="opacity:0.6; cursor:not-allowed;">Yakında</span>
<?php endif; ?>
</div>
<?php endforeach; ?>
</div>
<?php endif; ?>
</section>
<section class="section">
<h3>Reports</h3>
<div class="card">
<ul class="dashboard-action-list">
<li><a href="<?php echo BASE_URL; ?>/reports/weekly.php">Weekly Report</a></li>
<li><a href="<?php echo BASE_URL; ?>/reports/history.php">History</a></li>
<li><a href="<?php echo BASE_URL; ?>/results/report.php">Detailed Report 📊</a></li>
</ul>
</div>
</section>
</div>
<section class="section">
<h3>Tools</h3>
<div class="card">
<ul class="dashboard-action-list">
<li><a href="<?php echo BASE_URL; ?>/recommendations.php">Recommended Next Activity</a></li>
<li><a href="<?php echo BASE_URL; ?>/help/chatbot.php">Help Chatbot</a></li>
<li><a href="<?php echo BASE_URL; ?>/activity/resume.php">Resume Unfinished Activity</a></li>
<li><a href="<?php echo BASE_URL; ?>/reports/preferences.php">Notification Preferences</a></li>
</ul>
</div>
</section>
<?php if ((current_user()['role'] ?? '') === ROLE_ADMIN): ?>
<section class="section">
<h3>Admin Panel</h3>
<div class="card">
<ul class="dashboard-action-list">
<li><a href="<?php echo BASE_URL; ?>/admin/users.php">Manage Users</a></li>
<li><a href="<?php echo BASE_URL; ?>/admin/ai_logs.php">AI Feedback Logs</a></li>
<li><a href="<?php echo BASE_URL; ?>/admin/notifications.php">Notification Defaults</a></li>
</ul>
</div>
</section>
<?php endif; ?>
<?php require_once __DIR__ . '/templates/footer.php'; ?>