-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprofile.php
More file actions
366 lines (338 loc) · 12.7 KB
/
profile.php
File metadata and controls
366 lines (338 loc) · 12.7 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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
<?php
require_once 'config.php';
require_once 'functions.php';
if (!isLoggedIn()) {
redirect('login.php');
}
$user_id = $_SESSION['user_id'];
$user_name = $_SESSION['user_name'];
$user_type = $_SESSION['user_type'];
$email = "";
$email_err = "";
$bio = "";
$genre = "";
// Fetch user email from the database
$sql = "SELECT ue.Email FROM UserEmail ue WHERE ue.id = ?";
if ($stmt = mysqli_prepare($conn, $sql)) {
mysqli_stmt_bind_param($stmt, "i", $user_id);
if (mysqli_stmt_execute($stmt)) {
mysqli_stmt_bind_result($stmt, $email);
mysqli_stmt_fetch($stmt);
}
mysqli_stmt_close($stmt);
}
// Fetch artist profile if user is an artist
if ($user_type == 'Artist') {
$sql = "SELECT bio, genre FROM user WHERE artist_id = ?";
if ($stmt = mysqli_prepare($conn, $sql)) {
mysqli_stmt_bind_param($stmt, "i", $user_id);
if (mysqli_stmt_execute($stmt)) {
mysqli_stmt_bind_result($stmt, $bio, $genre);
mysqli_stmt_fetch($stmt);
}
mysqli_stmt_close($stmt);
}
}
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (isset($_POST['update_email'])) {
// Update email
$email = sanitizeInput($_POST["email"]);
if (empty($email)) {
$email_err = "Please enter an email.";
} elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$email_err = "Invalid email format.";
} else {
$sql = "SELECT id FROM UserEmail WHERE Email = ? AND id != ?";
if ($stmt = mysqli_prepare($conn, $sql)) {
mysqli_stmt_bind_param($stmt, "si", $param_email, $user_id);
$param_email = $email;
if (mysqli_stmt_execute($stmt)) {
mysqli_stmt_store_result($stmt);
if (mysqli_stmt_num_rows($stmt) > 0) {
$email_err = "This email is already taken.";
} else {
$sql = "UPDATE UserEmail SET Email = ? WHERE id = ?";
if ($stmt = mysqli_prepare($conn, $sql)) {
mysqli_stmt_bind_param($stmt, "si", $param_email, $user_id);
$param_email = $email;
if (mysqli_stmt_execute($stmt)) {
echo "Email updated successfully.";
} else {
echo "Something went wrong. Please try again later.";
}
}
}
}
mysqli_stmt_close($stmt);
}
}
}
if (isset($_POST['update_profile'])) {
// Update artist profile (if applicable)
if ($user_type == 'Artist') {
$bio = sanitizeInput($_POST["bio"]);
$genre = sanitizeInput($_POST["genre"]);
// Update artist profile in the database
$sql = "UPDATE user SET bio = ?, genre = ? WHERE id = ?";
if ($stmt = mysqli_prepare($conn, $sql)) {
mysqli_stmt_bind_param($stmt, "ssi", $param_bio, $param_genre, $user_id);
$param_bio = $bio;
$param_genre = $genre;
if (mysqli_stmt_execute($stmt)) {
echo "Profile updated successfully.";
} else {
echo "Something went wrong. Please try again later.";
}
}
}
}
}
// Fetch user's liked songs (for Listeners) or uploaded songs (for Artists)
$songs = [];
if ($user_type == 'Listener') {
$sql = "SELECT s.id, s.title, s.URL, s.cover_photo_url, u.F_name, u.L_name
FROM Song s
JOIN Likes l ON s.id = l.song_id
JOIN User u ON s.artist_id = u.id
WHERE l.user_id = ?";
} else if ($user_type == 'Artist') {
$sql = "SELECT id, title, URL, approval, cover_photo_url
FROM Song
WHERE artist_id = ?";
}
if (isset($sql) && $stmt = mysqli_prepare($conn, $sql)) {
mysqli_stmt_bind_param($stmt, "i", $user_id);
if (mysqli_stmt_execute($stmt)) {
$result = mysqli_stmt_get_result($stmt);
while ($row = mysqli_fetch_assoc($result)) {
$songs[] = $row;
}
}
mysqli_stmt_close($stmt);
}
mysqli_close($conn);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Profile - Music Streaming Platform</title>
<link rel="stylesheet" href="style.css">
<style>
/* General styles */
.container {
display: flex;
flex-wrap: wrap;
}
.sidebar {
width: 100%;
max-width: 200px;
padding: 20px;
background-color: #1a1a1a;
}
.main-content {
flex: 1;
padding: 20px;
}
.logo img {
width: 100%;
height: auto;
}
.song-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
gap: 20px;
}
.song-card {
background-color: #121212;
border-radius: 10px;
padding: 15px;
box-shadow: 0 4px 6px rgba(210, 215, 211, 0.2);
transition: transform 0.3s ease;
}
.song-card:hover {
transform: translateY(-5px);
}
.song-card img {
width: 100%;
height: auto;
object-fit: cover;
border-radius: 5px;
margin-bottom: 10px;
}
.song-card h3 {
margin: 0 0 5px 0;
font-size: 18px;
}
.song-card p {
margin: 0 0 10px 0;
font-size: 14px;
color: #666;
}
/* Change the background of the audio player */
.song-card audio {
width: 100%;
margin-bottom: 10px;
border-radius: 10px;
}
/* Webkit specific controls - Chrome, Safari */
.song-card audio::-webkit-media-controls-panel {
background-color: #222; /* Dark background */
border-radius: 0px;
}
.song-card audio::-webkit-media-controls-play-button,
.song-card audio::-webkit-media-controls-pause-button {
background-color: #1DB954; /* Custom play/pause button color */
border-radius: 50%;
}
.song-card audio::-webkit-media-controls-current-time-display,
.song-card audio::-webkit-media-controls-time-remaining-display {
color: #fff; /* Custom time display text color */
}
.like-button {
background: none;
border: none;
cursor: pointer;
font-size: 20px;
transition: transform 0.2s ease;
}
.like-button:hover {
transform: scale(1.2);
}
.liked {
color: red;
}
/* Responsive styles */
@media (max-width: 768px) {
.container {
flex-direction: column;
}
.sidebar {
width: 100%;
}
.main-content {
padding: 10px;
}
}
@media (max-width: 576px) {
.song-grid {
grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
gap: 10px;
}
}
</style>
<script>
function likeSong(songId, button) {
fetch('like_song.php', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: 'song_id=' + songId
})
.then(response => response.text())
.then(data => {
button.classList.toggle('liked');
button.textContent = button.classList.contains('liked') ? '❤️' : '🤍';
})
.catch((error) => {
console.error('Error:', error);
});
}
</script>
</head>
<body>
<div class="container">
<div class="sidebar">
<div class="logo">
<img src="logo.png" alt="Phonic Hub Logo">
</div>
<nav>
<ul>
<li><a href="dashboard.php">Home</a></li>
<li><a href="profile.php">Profile</a></li>
<?php if ($user_type == 'Artist'): ?>
<li><a href="upload.php">Upload Song</a></li>
<?php endif; ?>
<?php if ($user_type == 'Admin'): ?>
<li><a href="approve_songs.php">Approve Songs</a></li>
<?php endif; ?>
<li><a href="logout.php">Logout</a></li>
</ul>
</nav>
</div>
<div class="main-content">
<h1>Profile</h1>
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post">
<div class="form-group">
<label>Name</label>
<input type="text" class="form-control" value="<?php echo htmlspecialchars($user_name); ?>" disabled>
</div>
<div class="form-group">
<label>Email</label>
<input type="email" name="email" class="form-control" value="<?php echo htmlspecialchars($email); ?>">
<span class="error"><?php echo $email_err; ?></span>
</div>
<div class="form-group">
<input type="submit" name="update_email" class="btn btn-primary" value="Update Email">
</div>
<?php if ($user_type == 'Artist'): ?>
<h2>User Profile</h2>
<div class="form-group">
<label>Bio</label>
<textarea name="bio" class="form-control"><?php echo htmlspecialchars($bio); ?></textarea>
</div>
<div class="form-group">
<label>Genre</label>
<input type="text" name="genre" class="form-control" value="<?php echo htmlspecialchars($genre); ?>">
</div>
<div class="form-group">
<input type="submit" name="update_profile" class="btn btn-primary" value="Update Profile">
</div>
<?php endif; ?>
</form>
<?php if ($user_type == 'Listener'): ?>
<h2>Your Liked Songs</h2>
<div class="song-grid">
<?php if (empty($songs)): ?>
<p>No liked songs found.</p>
<?php else: ?>
<?php foreach ($songs as $song): ?>
<div class="song-card">
<img src="<?php echo htmlspecialchars($song['cover_photo_url']); ?>" alt="Album Art">
<h3><?php echo htmlspecialchars($song['title']); ?></h3>
<p><?php echo htmlspecialchars($song['F_name'] . ' ' . $song['L_name']); ?></p>
<audio controls>
<source src="<?php echo htmlspecialchars($song['URL']); ?>" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
<button class="like-button liked" onclick="likeSong(<?php echo $song['id']; ?>, this)">❤️</button>
</div>
<?php endforeach; ?>
<?php endif; ?>
</div>
<?php elseif ($user_type == 'Artist'): ?>
<h2>Your Uploaded Songs</h2>
<div class="song-grid">
<?php if (empty($songs)): ?>
<p>No uploaded songs found.</p>
<?php else: ?>
<?php foreach ($songs as $song): ?>
<div class="song-card">
<img src="<?php echo htmlspecialchars($song['cover_photo_url']); ?>" alt="Album Art">
<h3><?php echo htmlspecialchars($song['title']); ?></h3>
<audio controls>
<source src="<?php echo htmlspecialchars($song['URL']); ?>" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
<p>Status: <?php echo $song['approval'] ? 'Approved' : 'Pending'; ?></p>
</div>
<?php endforeach; ?>
<?php endif; ?>
</div>
<?php endif; ?>
</div>
</div>
</body>
</html>