-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAdmin_playlist_list.php
141 lines (131 loc) · 5.41 KB
/
Admin_playlist_list.php
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
<?php
session_start();
// Include database connection
$conn = require __DIR__ . "/db_connection.php";
// Initialize variable to store playlists data
$playlists = [];
// Fetch playlist data
$sql = "SELECT playlist_id, playlist_name, created_at, playlist_image FROM playlist";
$result = $conn->query($sql);
// Check if query execution was successful
if ($result) {
// Fetch all rows as associative array
$playlists = $result->fetch_all(MYSQLI_ASSOC);
} else {
// Query execution failed
echo "Error: " . $sql . "<br>" . $conn->error;
}
// Close connection
$conn->close();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Admin - Playlist List</title>
<link rel="stylesheet" href="Admin_list.css">
<style>
.playlist-image {
max-width: 100%;
max-height: 45px;
width: auto;
height: auto;
display: block;
margin-top: 10px;
object-fit: contain;
align-items: center;
}
</style>
</head>
<body>
<div class="container">
<aside class="sidebar">
<div class="navbar">
<div class="navbar-logo">
<img src="assets/pic/Inspirational_Quote_Instagram_Post_1.png" alt="Logo" class="navbar-image">
<span>IKUN MUSIC</span>
</div>
<div class="navbar-links-container">
<a href="Admin_dashboard.php" class="navbar-link">Dashboard</a>
<a href="Admin_playlist_list.php" class="navbar-link">Playlist List</a>
<a href="Admin_song_list.php" class="navbar-link">Song List</a>
<a href="Admin_edit_comment.php" class="navbar-link">Comment List</a>
<a href="Admin_artist_list.php" class="navbar-link">Artist List</a>
<a href="Admin_user_list.php" class="navbar-link">Users List</a>
</div>
<a href="index.php" class="logout">Logout</a> <!-- Replace with your logout page -->
</div>
</aside>
<main class="main-content">
<h1>Playlist List</h1>
<button id="addNewBtn">Add New</button>
<table>
<thead>
<tr>
<th>ID</th>
<th>Playlist Name</th>
<th>Created At</th>
<th>Playlist Image</th>
<th>Action</th>
</tr>
</thead>
<tbody id="playlistList">
<?php foreach ($playlists as $playlist): ?>
<tr>
<td><?php echo $playlist['playlist_id']; ?></td>
<td><?php echo $playlist['playlist_name']; ?></td>
<td><?php echo $playlist['created_at']; ?></td>
<td>
<?php if (!empty($playlist['playlist_image'])): ?>
<?php
$image_path = $playlist['playlist_image'];
?>
<img src="<?php echo htmlspecialchars($image_path); ?>" alt="Playlist Image" class="playlist-image">
<?php else: ?>
No image available
<?php endif; ?>
</td>
<td class="action-buttons">
<button class="manage" onclick="managePlaylist(<?php echo $playlist['playlist_id']; ?>)">📂</button>
<button class="delete" onclick="deletePlaylist(<?php echo $playlist['playlist_id']; ?>)">🗑️</button>
</td>
</tr>
<?php endforeach; ?>
<?php if (empty($playlist)): ?>
<tr><td colspan="6">No playlists found</td></tr>
<?php endif; ?>
</tbody>
</table>
</main>
</div>
<script>
function editPlaylist(id) {
window.location.href = `Admin_edit_playlist.php?id=${id}`;
}
function deletePlaylist(id) {
if (confirm('Are you sure you want to delete this playlist?')) {
// Send AJAX request to delete playlist
var xhr = new XMLHttpRequest();
xhr.open('POST', 'Admin_delete_playlist.php', true);
xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
xhr.onload = function() {
if (xhr.status === 200) {
// Refresh the page after deletion
window.location.reload();
} else {
alert('Failed to delete playlist. Please try again.');
}
};
xhr.send('playlist_id=' + id);
}
}
function managePlaylist(id) {
window.location.href = `Admin_manage_playlist.php?id=${id}`;
}
document.getElementById('addNewBtn').addEventListener('click', function() {
window.location.href = 'Admin_upload_playlist.php'; // Navigate to the upload playlist page
});
</script>
</body>
</html>