![]() 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/648fda30/ |
<?php
// Get user's tracks with detailed stats
$tracks_query = $pdo->prepare("
SELECT
mt.*,
COALESCE(like_count.count, 0) as likes,
COALESCE(play_count.count, 0) as plays,
COALESCE(comment_count.count, 0) as comments,
COALESCE(sales_count.count, 0) as sales,
COALESCE(sales_revenue.revenue, 0) as revenue
FROM music_tracks mt
LEFT JOIN (
SELECT track_id, COUNT(*) as count
FROM track_likes
GROUP BY track_id
) like_count ON mt.id = like_count.track_id
LEFT JOIN (
SELECT track_id, COUNT(*) as count
FROM track_plays
GROUP BY track_id
) play_count ON mt.id = play_count.track_id
LEFT JOIN (
SELECT track_id, COUNT(*) as count
FROM track_comments
GROUP BY track_id
) comment_count ON mt.id = comment_count.track_id
LEFT JOIN (
SELECT track_id, COUNT(*) as count
FROM sales
GROUP BY track_id
) sales_count ON mt.id = sales_count.track_id
LEFT JOIN (
SELECT track_id, SUM(amount) as revenue
FROM sales
GROUP BY track_id
) sales_revenue ON mt.id = sales_revenue.track_id
WHERE mt.user_id = ?
ORDER BY mt.created_at DESC
");
$tracks_query->execute([$user_id]);
$user_tracks = $tracks_query->fetchAll();
?>
<div class="content-section">
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 2rem;">
<h2><i class="fas fa-music"></i> My Tracks (<?= count($user_tracks) ?>)</h2>
<a href="index.php" class="btn btn-primary">
<i class="fas fa-plus"></i> Create New Track
</a>
</div>
<?php if (empty($user_tracks)): ?>
<div style="text-align: center; padding: 3rem; color: #a0aec0;">
<i class="fas fa-music" style="font-size: 4rem; margin-bottom: 1rem; opacity: 0.3;"></i>
<h3>No tracks yet</h3>
<p>Create your first track to get started!</p>
<a href="index.php" class="btn btn-primary" style="margin-top: 1rem;">
<i class="fas fa-plus"></i> Create Track
</a>
</div>
<?php else: ?>
<div class="tracks-grid">
<?php foreach ($user_tracks as $track): ?>
<div class="track-item">
<!-- Track Thumbnail -->
<div class="track-thumbnail">
<?php if (!empty($track['cover_image'])): ?>
<img src="<?= htmlspecialchars($track['cover_image']) ?>" alt="Cover" style="width: 100%; height: 100%; object-fit: cover; border-radius: 12px;">
<?php else: ?>
<i class="fas fa-music"></i>
<?php endif; ?>
</div>
<!-- Track Info -->
<div class="track-info">
<div class="track-title"><?= htmlspecialchars($track['title'] ?: 'Untitled Track') ?></div>
<div class="track-meta">
<div>Status:
<span style="color: <?= $track['status'] === 'complete' ? '#48bb78' : '#ed8936' ?>;">
<?= ucfirst($track['status']) ?>
</span>
</div>
<div>Created: <?= date('M j, Y', strtotime($track['created_at'])) ?></div>
<?php if ($track['price'] > 0): ?>
<div>Price: $<?= number_format($track['price'], 2) ?></div>
<?php else: ?>
<div style="color: #4299e1;">Free Track</div>
<?php endif; ?>
</div>
<div class="track-stats">
<span><i class="fas fa-play"></i> <?= number_format($track['plays']) ?></span>
<span><i class="fas fa-heart"></i> <?= number_format($track['likes']) ?></span>
<span><i class="fas fa-comment"></i> <?= number_format($track['comments']) ?></span>
<span><i class="fas fa-shopping-cart"></i> <?= number_format($track['sales']) ?></span>
</div>
</div>
<!-- Track Revenue -->
<div style="text-align: center;">
<div style="font-size: 1.5rem; font-weight: bold; color: #48bb78;">
$<?= number_format($track['revenue'] * (1 - $commission_rate), 2) ?>
</div>
<div style="font-size: 0.9rem; color: #a0aec0;">Your Earnings</div>
<?php if ($track['revenue'] > 0): ?>
<div style="font-size: 0.8rem; color: #cbd5e0; margin-top: 0.25rem;">
Total: $<?= number_format($track['revenue'], 2) ?>
</div>
<?php endif; ?>
</div>
<!-- Track Actions -->
<div class="track-actions">
<?php if ($track['status'] === 'complete' && !empty($track['audio_url'])): ?>
<button class="btn btn-success play-track-btn"
data-audio-url="<?= htmlspecialchars($track['audio_url']) ?>"
data-title="<?= htmlspecialchars($track['title']) ?>"
data-artist="<?= htmlspecialchars($user['name']) ?>">
<i class="fas fa-play"></i> Play
</button>
<?php endif; ?>
<button class="btn btn-primary"
onclick="editTrack(
<?= $track['id'] ?>,
'<?= htmlspecialchars($track['title'], ENT_QUOTES) ?>',
'<?= htmlspecialchars($track['prompt'], ENT_QUOTES) ?>',
<?= $track['price'] ?>,
<?= $track['is_public'] ?? 0 ?>
)">
<i class="fas fa-edit"></i> Edit
</button>
<button class="btn btn-warning" onclick="duplicateTrack(<?= $track['id'] ?>)">
<i class="fas fa-copy"></i> Duplicate
</button>
<?php if ($track['status'] === 'complete'): ?>
<button class="btn" onclick="toggleVisibility(<?= $track['id'] ?>, <?= $track['is_public'] ?? 0 ?>)">
<i class="fas fa-eye<?= ($track['is_public'] ?? 0) ? '' : '-slash' ?>"></i>
<?= ($track['is_public'] ?? 0) ? 'Public' : 'Private' ?>
</button>
<?php endif; ?>
</div>
</div>
<?php endforeach; ?>
</div>
<?php endif; ?>
</div>
<script>
// Enhanced track management functions
function duplicateTrack(trackId) {
if (confirm('Create a duplicate of this track?')) {
fetch('api_track_management.php', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ action: 'duplicate', track_id: trackId })
})
.then(response => response.json())
.then(data => {
if (data.success) {
location.reload();
} else {
alert('Failed to duplicate track: ' + (data.message || 'Unknown error'));
}
})
.catch(error => {
console.error('Duplicate error:', error);
alert('Failed to duplicate track');
});
}
}
function toggleVisibility(trackId, currentVisibility) {
const newVisibility = currentVisibility ? 0 : 1;
const action = newVisibility ? 'make public' : 'make private';
if (confirm(`Are you sure you want to ${action} this track?`)) {
fetch('api_track_management.php', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
action: 'toggle_visibility',
track_id: trackId,
visibility: newVisibility
})
})
.then(response => response.json())
.then(data => {
if (data.success) {
location.reload();
} else {
alert('Failed to update visibility: ' + (data.message || 'Unknown error'));
}
})
.catch(error => {
console.error('Visibility error:', error);
alert('Failed to update track visibility');
});
}
}
// Enhanced play button functionality for artist dashboard
document.addEventListener('DOMContentLoaded', function() {
const playButtons = document.querySelectorAll('.play-track-btn');
playButtons.forEach(button => {
button.addEventListener('click', function(e) {
e.preventDefault();
const audioUrl = this.getAttribute('data-audio-url');
const title = this.getAttribute('data-title');
const artist = this.getAttribute('data-artist');
if (!audioUrl) {
alert('Audio not available');
return;
}
// Clear other playing states
document.querySelectorAll('.play-track-btn').forEach(btn => {
btn.classList.remove('playing');
btn.innerHTML = '<i class="fas fa-play"></i> Play';
});
// Set this button as playing
this.classList.add('playing');
this.innerHTML = '<i class="fas fa-pause"></i> Playing';
// Use global player
if (typeof window.enhancedGlobalPlayer !== 'undefined') {
window.enhancedGlobalPlayer.playTrack(audioUrl, title, artist);
} else if (typeof window.playTrack === 'function') {
window.playTrack(audioUrl, title, artist);
} else {
alert('Player not available');
this.classList.remove('playing');
this.innerHTML = '<i class="fas fa-play"></i> Play';
}
});
});
});
</script>