-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
68 lines (60 loc) · 1.98 KB
/
Copy pathindex.php
File metadata and controls
68 lines (60 loc) · 1.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
<?php
require_once './includes/config.php';
require_once './includes/navbar.php';
$pdo = new PDO(
"mysql:host=" . DB_HOST . ";port=" . DB_PORT . ";dbname=" . DB_NAME,
DB_USER,
DB_PASS
);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// Function to get recent songs with song URI
function getRecentSongs($pdo, $limit = 5) {
$stmt = $pdo->prepare(
"SELECT song, artist, played_at, song_uri
FROM playbacks
ORDER BY played_at DESC
LIMIT :limit"
);
$stmt->bindValue(':limit', (int)$limit, PDO::PARAM_INT);
$stmt->execute();
return $stmt->fetchAll(PDO::FETCH_ASSOC);
}
$recentSongs = getRecentSongs($pdo);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Dashboard</title>
<link rel="stylesheet" href="./assets/css/styles.css">
</head>
<body>
<header>
<div class="navbar">
<div class="menu">Menu</div>
<div class="nav-links">
<?php renderNavbar("index.php"); ?>
</div>
</div>
</header>
<div class="main-content">
<h1>Welcome to Your Music Dashboard</h1>
<p>Explore your listening habits, top songs, streaks, and more!</p>
<h2>Recent Songs</h2>
<ul>
<?php foreach ($recentSongs as $song): ?>
<li>
<!-- Use the formatted song_uri -->
<a href="./search.php?song=<?= htmlspecialchars(formatSongUri($song['song_uri'])) ?>" class="spotify-link">
<?= htmlspecialchars($song['song']) ?> by <?= htmlspecialchars($song['artist']) ?>
</a>
(Played on: <?= convertToLocalTimeZone($song['played_at']) ?>)
</li>
<?php endforeach; ?>
</ul>
<p>Click on the navigation links above to explore other sections.</p>
</div>
<script src="./assets/js/script.js"></script>
</body>
</html>