![]() Server : Apache/2 System : Linux server-15-235-50-60 5.15.0-164-generic #174-Ubuntu SMP Fri Nov 14 20:25:16 UTC 2025 x86_64 User : gositeme ( 1004) PHP Version : 8.2.29 Disable Function : exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname Directory : /home/gositeme/.cursor-server/data/User/History/-24d6c3ee/ |
<?php
// Simple Playlist Management - REDESIGNED
// Clean, working interface for managing playlists
if (!isset($pdo)) {
echo '<div style="color: red; padding: 20px;">Database connection not available.</div>';
return;
}
// Get playlist filter
$playlist_tab = $_GET['playlist_tab'] ?? 'all';
// Get tracks
$playlist_where = "mt.status = 'complete' AND mt.audio_url IS NOT NULL";
if ($playlist_tab === 'featured') {
$playlist_where .= " AND mt.is_featured = 1";
} elseif ($playlist_tab === 'vip') {
$playlist_where .= " AND mt.is_vip_sample = 1";
}
$stmt = $pdo->prepare("
SELECT mt.*, u.name as artist_name,
(SELECT COUNT(*) FROM track_plays WHERE track_id = mt.id) as play_count,
(SELECT COUNT(*) FROM track_likes WHERE track_id = mt.id) as like_count
FROM music_tracks mt
JOIN users u ON mt.user_id = u.id
WHERE $playlist_where
ORDER BY mt.playlist_order ASC, mt.created_at DESC
LIMIT 100
");
$stmt->execute();
$tracks = $stmt->fetchAll();
// Get stats
$stats = [
'total' => $pdo->query("SELECT COUNT(*) FROM music_tracks WHERE status = 'complete' AND audio_url IS NOT NULL")->fetchColumn(),
'featured' => $pdo->query("SELECT COUNT(*) FROM music_tracks WHERE status = 'complete' AND audio_url IS NOT NULL AND is_featured = 1")->fetchColumn(),
'vip' => $pdo->query("SELECT COUNT(*) FROM music_tracks WHERE status = 'complete' AND audio_url IS NOT NULL AND is_vip_sample = 1")->fetchColumn()
];
?>
<!-- SIMPLE PLAYLIST MANAGEMENT -->
<div style="background: white; border-radius: 12px; box-shadow: 0 4px 6px rgba(0,0,0,0.1); margin: 20px 0;">
<!-- Header -->
<div style="background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white; padding: 20px; border-radius: 12px 12px 0 0;">
<h2 style="margin: 0; font-size: 24px;">🎵 Playlist Management</h2>
<p style="margin: 10px 0 0 0; opacity: 0.9;">Manage Featured and VIP tracks</p>
</div>
<!-- Stats -->
<div style="padding: 20px; border-bottom: 1px solid #e5e7eb;">
<div style="display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px;">
<div style="text-align: center;">
<div style="font-size: 32px; font-weight: bold; color: #667eea;"><?= number_format($stats['total']) ?></div>
<div style="color: #6b7280;">Total Tracks</div>
</div>
<div style="text-align: center;">
<div style="font-size: 32px; font-weight: bold; color: #f59e0b;"><?= number_format($stats['featured']) ?></div>
<div style="color: #6b7280;">Featured</div>
</div>
<div style="text-align: center;">
<div style="font-size: 32px; font-weight: bold; color: #8b5cf6;"><?= number_format($stats['vip']) ?></div>
<div style="color: #6b7280;">VIP Samples</div>
</div>
</div>
</div>
<!-- Filters -->
<div style="padding: 20px; border-bottom: 1px solid #e5e7eb;">
<div style="display: flex; gap: 10px; flex-wrap: wrap;">
<a href="?tab=playlists&playlist_tab=all"
style="padding: 10px 20px; border: 2px solid #e5e7eb; border-radius: 8px; text-decoration: none; color: #374151; background: <?= $playlist_tab === 'all' ? '#667eea' : 'white' ?>; color: <?= $playlist_tab === 'all' ? 'white' : '#374151' ?>;">
📋 All Tracks (<?= number_format($stats['total']) ?>)
</a>
<a href="?tab=playlists&playlist_tab=featured"
style="padding: 10px 20px; border: 2px solid #e5e7eb; border-radius: 8px; text-decoration: none; color: #374151; background: <?= $playlist_tab === 'featured' ? '#f59e0b' : 'white' ?>; color: <?= $playlist_tab === 'featured' ? 'white' : '#374151' ?>;">
⭐ Featured (<?= number_format($stats['featured']) ?>)
</a>
<a href="?tab=playlists&playlist_tab=vip"
style="padding: 10px 20px; border: 2px solid #e5e7eb; border-radius: 8px; text-decoration: none; color: #374151; background: <?= $playlist_tab === 'vip' ? '#8b5cf6' : 'white' ?>; color: <?= $playlist_tab === 'vip' ? 'white' : '#374151' ?>;">
👑 VIP Samples (<?= number_format($stats['vip']) ?>)
</a>
</div>
</div>
<!-- Tracks -->
<div style="padding: 20px;">
<?php if (empty($tracks)): ?>
<div style="text-align: center; padding: 40px; color: #6b7280;">
<div style="font-size: 48px; margin-bottom: 16px;">🎵</div>
<h3>No tracks found</h3>
<p>No tracks match the current filter.</p>
</div>
<?php else: ?>
<?php foreach ($tracks as $track): ?>
<div style="background: white; border: 2px solid #e5e7eb; border-radius: 12px; padding: 20px; margin-bottom: 15px; display: flex; align-items: center; gap: 20px;">
<!-- Track Info -->
<div style="flex: 1;">
<div style="font-weight: 600; font-size: 18px; margin-bottom: 5px;"><?= htmlspecialchars($track['title']) ?></div>
<div style="color: #6b7280; margin-bottom: 5px;">by <?= htmlspecialchars($track['artist_name']) ?></div>
<div style="color: #9ca3af; font-size: 14px;"><?= $track['play_count'] ?> plays • <?= $track['like_count'] ?> likes</div>
</div>
<!-- Controls -->
<div style="display: flex; gap: 15px; align-items: center;">
<!-- Featured -->
<div style="text-align: center;">
<div style="font-size: 12px; color: #6b7280; margin-bottom: 5px;">Featured</div>
<label style="display: flex; align-items: center; gap: 5px; cursor: pointer;">
<input type="checkbox"
<?= $track['is_featured'] ? 'checked' : '' ?>
onchange="updateTrack(<?= $track['id'] ?>, 'featured', this.checked)"
style="width: 18px; height: 18px;">
<span style="color: #f59e0b;">⭐</span>
</label>
</div>
<!-- VIP -->
<div style="text-align: center;">
<div style="font-size: 12px; color: #6b7280; margin-bottom: 5px;">VIP</div>
<label style="display: flex; align-items: center; gap: 5px; cursor: pointer;">
<input type="checkbox"
<?= $track['is_vip_sample'] ? 'checked' : '' ?>
onchange="updateTrack(<?= $track['id'] ?>, 'vip', this.checked)"
style="width: 18px; height: 18px;">
<span style="color: #8b5cf6;">👑</span>
</label>
</div>
<!-- Order -->
<div style="text-align: center;">
<div style="font-size: 12px; color: #6b7280; margin-bottom: 5px;">Order</div>
<input type="number"
value="<?= $track['playlist_order'] ?>"
min="0" max="999"
onchange="updateOrder(<?= $track['id'] ?>, this.value)"
style="width: 60px; padding: 5px; border: 1px solid #d1d5db; border-radius: 4px; text-align: center;">
</div>
<!-- Status -->
<div id="status_<?= $track['id'] ?>" style="font-size: 12px; padding: 5px 10px; border-radius: 4px; display: none;"></div>
</div>
</div>
<?php endforeach; ?>
<?php endif; ?>
</div>
</div>
<script>
// Simple, working functions
function updateTrack(trackId, setting, value) {
console.log('Updating track:', trackId, setting, value);
const statusDiv = document.getElementById(`status_${trackId}`);
statusDiv.style.display = 'block';
statusDiv.textContent = 'Saving...';
statusDiv.style.background = '#fef3c7';
statusDiv.style.color = '#92400e';
const formData = new FormData();
formData.append('playlist_action', setting === 'featured' ? 'toggle_featured' : 'toggle_vip');
formData.append('track_id', trackId);
formData.append(setting === 'featured' ? 'is_featured' : 'is_vip', value ? '1' : '0');
// Debug: Log the form data
for (let [key, value] of formData.entries()) {
console.log(key + ': ' + value);
}
fetch('admin.php?tab=playlists&ajax=1', {
method: 'POST',
body: formData
})
.then(response => {
console.log('Response status:', response.status);
console.log('Response headers:', response.headers);
return response.text().then(text => {
console.log('Raw response:', text);
try {
return JSON.parse(text);
} catch (e) {
console.error('JSON parse error:', e);
return { success: false, error: 'Invalid JSON response' };
}
});
})
.then(data => {
console.log('Parsed response:', data);
if (data.success) {
statusDiv.textContent = '✅ Saved';
statusDiv.style.background = '#d1fae5';
statusDiv.style.color = '#065f46';
} else {
statusDiv.textContent = '❌ Failed: ' + (data.error || 'Unknown error');
statusDiv.style.background = '#fee2e2';
statusDiv.style.color = '#991b1b';
}
setTimeout(() => {
statusDiv.style.display = 'none';
}, 3000);
})
.catch(error => {
console.error('Fetch error:', error);
statusDiv.textContent = '❌ Network Error';
statusDiv.style.background = '#fee2e2';
statusDiv.style.color = '#991b1b';
setTimeout(() => {
statusDiv.style.display = 'none';
}, 3000);
});
}
function updateOrder(trackId, order) {
console.log('Updating order:', trackId, order);
const orderNum = parseInt(order);
if (isNaN(orderNum) || orderNum < 0 || orderNum > 999) {
alert('Invalid order value. Must be 0-999.');
return;
}
const statusDiv = document.getElementById(`status_${trackId}`);
statusDiv.style.display = 'block';
statusDiv.textContent = 'Saving...';
statusDiv.style.background = '#fef3c7';
statusDiv.style.color = '#92400e';
const formData = new FormData();
formData.append('playlist_action', 'update_order');
formData.append('track_id', trackId);
formData.append('order', orderNum);
fetch('admin.php?tab=playlists&ajax=1', {
method: 'POST',
body: formData
})
.then(response => response.json())
.then(data => {
if (data.success) {
statusDiv.textContent = '✅ Order saved';
statusDiv.style.background = '#d1fae5';
statusDiv.style.color = '#065f46';
} else {
statusDiv.textContent = '❌ Failed';
statusDiv.style.background = '#fee2e2';
statusDiv.style.color = '#991b1b';
}
setTimeout(() => {
statusDiv.style.display = 'none';
}, 2000);
})
.catch(error => {
console.error('Error:', error);
statusDiv.textContent = '❌ Error';
statusDiv.style.background = '#fee2e2';
statusDiv.style.color = '#991b1b';
setTimeout(() => {
statusDiv.style.display = 'none';
}, 2000);
});
}
</script>