-
Notifications
You must be signed in to change notification settings - Fork 0
/
UploadForm.php
350 lines (316 loc) · 12.4 KB
/
UploadForm.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
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
<?php
session_start();
if (isset($_SESSION["user_id"])) {
$conn = require __DIR__ . "/db_connection.php";
$sql = "SELECT name, profile_image FROM users WHERE user_id = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("i", $_SESSION["user_id"]);
$stmt->execute();
$stmt->bind_result($name, $profile_image);
$stmt->fetch();
$stmt->close();
}
if (!empty($profile_image)) {
if (strpos($profile_image, 'uploads/') === 0) {
$image_path = $profile_image;
} elseif (strpos($profile_image, '../uploads/') === 0) {
$image_path = substr($profile_image, 3);
} else {
$image_path = 'uploads/profile/' . $profile_image;
}
} else {
$image_path = 'assets/pic/default.jpg';
}
// Fetch artist list
$artists_sql = "SELECT artist_id, artist_name FROM artist";
$artists_result = $conn->query($artists_sql);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Upload a Song</title>
<link rel="stylesheet" href="assets/css/upload_song.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;700&display=swap" rel="stylesheet">
<style>
.navbar-link:hover {
color: #7700ff;
}
.navbar-link:hover i {
color: #7700ff;
}
#logout {
color: #ffffff;
transition: color 0.3s;
}
#logout:hover {
color: #ff0000;
}
#logout:hover .fas {
color: #ff0000;
}
.toast {
visibility: hidden;
min-width: 300px;
margin-left: -150px;
background-color: #d4edda;
color: #155724;
text-align: left;
border-radius: 5px;
padding: 16px;
position: fixed;
z-index: 1001;
left: 50%;
bottom: 30px;
font-size: 17px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
display: flex;
align-items: center;
}
.toast.show {
visibility: visible;
-webkit-animation: fadein 0.5s, fadeout 0.5s 3.5s;
animation: fadein 0.5s, fadeout 0.5s 3.5s;
}
@-webkit-keyframes fadein {
from {bottom: 0; opacity: 0;}
to {bottom: 30px; opacity: 1;}
}
@keyframes fadein {
from {bottom: 0; opacity: 0;}
to {bottom: 30px; opacity: 1;}
}
@-webkit-keyframes fadeout {
from {bottom: 30px; opacity: 1;}
to {bottom: 0; opacity: 0;}
}
@keyframes fadeout {
from {bottom: 30px; opacity: 1;}
to {bottom: 0; opacity: 0;}
}
.toast .icon {
margin-right: 10px;
font-size: 20px;
}
.toast .close {
margin-left: auto;
cursor: pointer;
}
.popup-form {
display: none;
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
z-index: 1002;
background-color: white;
border: 1px solid #ddd;
border-radius: 10px;
padding: 20px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
width: 80%;
max-width: 600px;
}
.popup-form h2 {
margin-top: 0;
}
.popup-form label {
display: block;
margin-top: 10px;
}
.popup-form input[type="text"],
.popup-form input[type="email"],
.popup-form input[type="url"],
.popup-form input[type="file"] {
width: 100%;
padding: 10px;
margin-top: 5px;
}
.popup-form button {
margin-top: 20px;
padding: 10px 20px;
background-color: #7700ff;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
font-family: 'Poppins', sans-serif;
}
.popup-form button:hover {
background-color: #2980b9;
}
.popup-form .close-button {
position: absolute;
top: 10px;
right: 10px;
font-size: 20px;
background: none;
border: none;
cursor: pointer;
outline: none;
color: black;
}
.overlay {
display: none;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
z-index: 1001;
}
</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="User_Home.php" class="navbar-link"><i class="fas fa-home"></i> Home</a>
<a href="user_playlist.php" class="navbar-link"><i class="fas fa-music"></i> My Playlist</a>
<a href="Help_and_Support.html" class="navbar-link"><i class="fas fa-question-circle"></i> Help & Support</a>
<a href="About_Us.html" class="navbar-link"><i class="fas fa-info-circle"></i> About Us</a>
<a href="UploadForm.php" class="navbar-link"><i class="fas fa-space-shuttle"></i> Ikun Space</a>
<a href="logout.php" class="navbar-link" id="logout"><i class="fas fa-sign-out-alt"></i> Logout</a>
</div>
<div class="navbar-user">
<img src="<?php echo htmlspecialchars($image_path); ?>" alt="User Image">
<span><a href="User_Profile.php" class="profile-link"><?php echo htmlspecialchars($name); ?></a></span>
</div>
</div>
</aside>
<main class="main-content">
<h1>Upload a Song</h1>
<form id="uploadForm" enctype="multipart/form-data">
<label for="songTitle">Song Title<span class="required">*</span></label>
<input type="text" id="songTitle" name="songTitle" required>
<label for="artist_id">Select Artist</label>
<select id="artist_id" name="artist_id">
<option value="">Select an artist</option>
<?php while ($artist = $artists_result->fetch_assoc()): ?>
<option value="<?php echo $artist['artist_id']; ?>"><?php echo htmlspecialchars($artist['artist_name']); ?></option>
<?php endwhile; ?>
</select>
<button type="button" onclick="openPopup()">Add New Artist</button>
<label for="language">Language</label>
<select id="language" name="language">
<option value="english">English</option>
<option value="chinese">Chinese</option>
<option value="korean">Korean</option>
<option value="japanese">Japanese</option>
<option value="malay">Malay</option>
</select>
<label for="categories">Categories<span class="required">*</span></label>
<input type="text" id="categories" name="categories" required>
<label for="releaseDate">Release Date</label>
<input type="date" id="releaseDate" name="releaseDate" required>
<label for="mp3Upload">MP3 Upload<span class="required">*</span></label>
<input type="file" id="mp3Upload" name="mp3Upload" accept="audio/mp3" required>
<label for="profilePictureUpload">Profile Picture Upload</label>
<input type="file" id="profilePictureUpload" name="profilePictureUpload" accept="image/*">
<label for="backgroundPictureUpload">Background Picture Upload</label>
<input type="file" id="backgroundPictureUpload" name="backgroundPictureUpload" accept="image/*">
<button type="submit" id="submitButton">Add Song</button>
</form>
</main>
</div>
<!-- Popup Form for New Artist -->
<div class="overlay" id="overlay"></div>
<div class="popup-form" id="popupForm">
<button class="close-button" onclick="closePopup()">×</button>
<h2>Add New Artist</h2>
<form id="newArtistForm">
<label for="newArtistName">Artist Name<span class="required">*</span></label>
<input type="text" id="newArtistName" name="newArtistName" required>
<label for="newArtistEmail">Artist Email</label>
<input type="email" id="newArtistEmail" name="newArtistEmail">
<label for="newArtistYouTube">Artist YouTube Link</label>
<input type="url" id="newArtistYouTube" name="newArtistYouTube">
<label for="newArtistPhoto">Artist Photo</label>
<input type="file" id="newArtistPhoto" name="newArtistPhoto" accept="image/*">
<button type="submit">Add Artist</button>
<button type="button" onclick="closePopup()">Cancel</button>
</form>
</div>
<!-- Toast Notification -->
<div id="toast" class="toast">
<span class="icon"><i class="fas fa-check-circle"></i></span>
<span class="message"></span>
<span class="close" onclick="hideToast()">×</span>
</div>
<script>
function showToast(message) {
var toast = document.getElementById("toast");
toast.querySelector(".message").innerText = message;
toast.className = "toast show";
setTimeout(function(){ hideToast(); }, 4000); // Show toast for 4 seconds
}
function hideToast() {
var toast = document.getElementById("toast");
toast.className = toast.className.replace("show", "");
}
function openPopup() {
document.getElementById("overlay").style.display = "block";
document.getElementById("popupForm").style.display = "block";
}
function closePopup() {
document.getElementById("overlay").style.display = "none";
document.getElementById("popupForm").style.display = "none";
}
document.getElementById('uploadForm').addEventListener('submit', function(event) {
event.preventDefault();
let formData = new FormData(this);
let submitButton = document.getElementById('submitButton');
// Show loading spinner and disable button
submitButton.disabled = true;
submitButton.innerHTML = 'Uploading...';
// AJAX request to Upload.php
let xhr = new XMLHttpRequest();
xhr.open('POST', 'Upload.php', true);
xhr.onreadystatechange = function() {
if (xhr.readyState === 4) {
showToast(xhr.responseText);
// Hide loading spinner and enable button
submitButton.disabled = false;
submitButton.innerHTML = 'Add Song';
}
};
xhr.send(formData);
});
document.getElementById('newArtistForm').addEventListener('submit', function(event) {
event.preventDefault();
let formData = new FormData(this);
// AJAX request to add new artist
let xhr = new XMLHttpRequest();
xhr.open('POST', 'AddArtist.php', true);
xhr.onreadystatechange = function() {
if (xhr.readyState === 4) {
let response = JSON.parse(xhr.responseText);
if (response.status === 'success') {
// Update the artist dropdown list
let artistSelect = document.getElementById('artist_id');
let newOption = document.createElement('option');
newOption.value = response.artist_id;
newOption.textContent = response.artist_name;
artistSelect.appendChild(newOption);
// Show success message
showToast(response.message);
// Close the popup
closePopup();
} else {
// Show error message
showToast(response.message);
}
}
};
xhr.send(formData);
});
</script>
</body>
</html>