![]() 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/-381e93fd/ |
<?php
// Enable error reporting for debugging
error_reporting(E_ALL);
ini_set('display_errors', 1);
session_start();
// ALWAYS check if user is logged in - no exceptions
if (!isset($_SESSION['user_id'])) {
header('Location: /auth/login.php');
exit;
}
// Handle AJAX requests
$is_ajax = isset($_GET['ajax']) && $_GET['ajax'] == '1';
// Include database configuration
require_once 'config/database.php';
// Get user data
try {
$user = getUserById($_SESSION['user_id'] ?? 0);
$user_name = $user['name'] ?? 'User';
$user_email = $_SESSION['user_email'] ?? '';
$credits = $_SESSION['credits'] ?? 5;
$plan = $_SESSION['plan'] ?? 'free';
} catch (Exception $e) {
echo "Error getting user data: " . $e->getMessage();
exit;
}
// Get comprehensive user statistics
try {
$pdo = getDBConnection();
} catch (Exception $e) {
echo "Error connecting to database: " . $e->getMessage();
exit;
}
// Get fresh dashboard data (no caching)
// Get user's music tracks
$music_history = getUserMusicTracks($_SESSION['user_id'] ?? 0, 50);
// Calculate advanced statistics
$total_tracks = count($music_history);
$completed_tracks = count(array_filter($music_history, function($m) { return $m['status'] === 'complete'; }));
$processing_tracks = count(array_filter($music_history, function($m) { return $m['status'] === 'processing'; }));
$failed_tracks = count(array_filter($music_history, function($m) { return $m['status'] === 'failed'; }));
// Calculate total duration
$total_duration = 0;
$music_types = [];
$recent_activity = [];
foreach ($music_history as $track) {
if ($track['status'] === 'complete' && isset($track['duration'])) {
$total_duration += $track['duration'];
}
if (isset($track['music_type'])) {
$music_types[$track['music_type']] = ($music_types[$track['music_type']] ?? 0) + 1;
}
$recent_activity[] = [
'type' => 'music_created',
'title' => $track['title'],
'date' => $track['created_at'],
'status' => $track['status']
];
}
// Get credit transaction history (last 10)
$credit_history = [];
try {
$stmt = $pdo->prepare("
SELECT * FROM credit_transactions
WHERE user_id = ?
ORDER BY created_at DESC
LIMIT 10
");
$stmt->execute([$_SESSION['user_id'] ?? 0]);
$credit_history = $stmt->fetchAll();
} catch (Exception $e) {
// Credit history table might not exist yet
}
// Calculate user level based on activity
$user_level = 1;
$xp = $completed_tracks * 10 + $total_duration;
if ($xp >= 1000) $user_level = 5;
elseif ($xp >= 500) $user_level = 4;
elseif ($xp >= 200) $user_level = 3;
elseif ($xp >= 50) $user_level = 2;
// Get favorite tracks (most played)
$favorite_tracks = array_slice($music_history, 0, 5);
// Set page variables for header
$page_title = 'Dashboard - SoundStudioPro';
$page_description = 'Your comprehensive SoundStudioPro dashboard - Create, manage, and discover AI-generated music.';
$current_page = 'dashboard';
// Include header only for full page loads
if (!$is_ajax) {
include 'includes/header.php';
} else {
// For AJAX requests, wrap content in the proper container structure
echo '<div class="container" id="pageContainer">';
}
?>
<div class="main-content">
<style>
/* Dashboard-specific styles */
/* Global player compatibility */
body {
padding-bottom: 120px; /* Extra space for enhanced global player */
}
.main-content {
min-height: calc(100vh - 120px); /* Ensure content doesn't overlap player */
}
/* Hero Section */
.hero {
padding: 15rem 0 10rem;
text-align: center;
color: white;
background: linear-gradient(135deg, #0a0a0a 0%, #1a1a1a 50%, #0a0a0a 100%);
position: relative;
overflow: hidden;
}
.hero::before {
content: '';
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><defs><pattern id="grid" width="10" height="10" patternUnits="userSpaceOnUse"><path d="M 10 0 L 0 0 0 10" fill="none" stroke="rgba(102,126,234,0.1)" stroke-width="0.5"/></pattern></defs><rect width="100" height="100" fill="url(%23grid)"/></svg>');
opacity: 0.3;
}
.hero-content {
max-width: 90rem;
margin: 0 auto;
position: relative;
z-index: 2;
}
.hero-badge {
display: inline-block;
background: linear-gradient(135deg, rgba(102, 126, 234, 0.2), rgba(118, 75, 162, 0.2));
color: #667eea;
padding: 1.2rem 2.4rem;
border-radius: 50px;
font-size: 1.4rem;
font-weight: 600;
margin-bottom: 3rem;
backdrop-filter: blur(10px);
border: 1px solid rgba(102, 126, 234, 0.3);
animation: pulse 2s infinite;
}
@keyframes pulse {
0%, 100% { transform: scale(1); }
50% { transform: scale(1.05); }
}
.hero-title {
font-size: 6.4rem;
font-weight: 900;
line-height: 1.1;
margin-bottom: 2.4rem;
background: linear-gradient(135deg, #ffffff, #667eea, #764ba2);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
animation: gradientShift 3s ease-in-out infinite;
}
@keyframes gradientShift {
0%, 100% { background-position: 0% 50%; }
50% { background-position: 100% 50%; }
}
.hero-subtitle {
font-size: 2rem;
font-weight: 400;
margin-bottom: 4rem;
opacity: 0.9;
max-width: 70rem;
margin-left: auto;
margin-right: auto;
color: #a0aec0;
}
/* User Level Badge */
.user-level-badge {
display: inline-flex;
align-items: center;
gap: 1rem;
background: linear-gradient(135deg, #667eea, #764ba2);
color: white;
padding: 1rem 2rem;
border-radius: 50px;
font-size: 1.4rem;
font-weight: 600;
margin-bottom: 2rem;
backdrop-filter: blur(10px);
}
.level-icon {
font-size: 2rem;
}
/* Buttons */
.btn {
display: inline-flex;
align-items: center;
gap: 1rem;
padding: 1.5rem 3rem;
border-radius: 16px;
font-size: 1.6rem;
font-weight: 600;
text-decoration: none;
transition: all 0.3s ease;
border: none;
cursor: pointer;
position: relative;
overflow: hidden;
}
.btn-primary {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
box-shadow: 0 10px 30px rgba(102, 126, 234, 0.3);
}
.btn-primary:hover {
transform: translateY(-3px);
box-shadow: 0 20px 50px rgba(102, 126, 234, 0.4);
}
.btn-secondary {
background: rgba(255, 255, 255, 0.1);
color: white;
border: 2px solid rgba(255, 255, 255, 0.2);
backdrop-filter: blur(10px);
}
.btn-secondary:hover {
background: rgba(255, 255, 255, 0.2);
transform: translateY(-3px);
border-color: rgba(255, 255, 255, 0.3);
}
.btn-success {
background: linear-gradient(135deg, #48bb78, #38a169);
color: white;
box-shadow: 0 8px 20px rgba(72, 187, 120, 0.3);
}
.btn-success:hover {
transform: translateY(-2px);
box-shadow: 0 12px 25px rgba(72, 187, 120, 0.4);
}
.btn-small {
padding: 1rem 2rem;
font-size: 1.4rem;
border-radius: 12px;
}
/* Enhanced play button states for global player integration */
.play-track-btn {
position: relative;
overflow: hidden;
transition: all 0.3s ease;
}
.play-track-btn.playing {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
color: white !important;
box-shadow: 0 0 20px rgba(102, 126, 234, 0.5);
animation: playingPulse 2s ease-in-out infinite;
}
.play-track-btn.playing i {
animation: playingIcon 1s ease-in-out infinite alternate;
}
@keyframes playingPulse {
0%, 100% { box-shadow: 0 0 20px rgba(102, 126, 234, 0.5); }
50% { box-shadow: 0 0 30px rgba(102, 126, 234, 0.8); }
}
@keyframes playingIcon {
0% { transform: scale(1); }
100% { transform: scale(1.1); }
}
/* Dashboard Content */
.dashboard-content {
background: linear-gradient(135deg, #1a1a1a 0%, #2d2d2d 100%);
padding: 6rem 0;
padding-bottom: 100px;
border-radius: 40px 40px 0 0;
margin-top: -4rem;
position: relative;
z-index: 10;
}
.dashboard-container {
max-width: 120rem;
margin: 0 auto;
}
/* Dashboard Grid */
.dashboard-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 4rem;
margin-bottom: 4rem;
}
.dashboard-main {
display: flex;
flex-direction: column;
gap: 4rem;
}
.dashboard-sidebar {
display: flex;
flex-direction: column;
gap: 3rem;
}
/* Quick Actions */
.quick-actions {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
gap: 2rem;
margin-bottom: 4rem;
}
.action-card {
background: rgba(255, 255, 255, 0.05);
padding: 3rem;
border-radius: 20px;
backdrop-filter: blur(20px);
border: 1px solid rgba(255, 255, 255, 0.1);
transition: all 0.3s ease;
text-align: center;
text-decoration: none;
color: white;
}
.action-card:hover {
transform: translateY(-5px);
border-color: rgba(102, 126, 234, 0.3);
box-shadow: 0 20px 60px rgba(102, 126, 234, 0.2);
color: white;
}
.action-icon {
font-size: 3rem;
color: #667eea;
margin-bottom: 1.5rem;
}
.action-title {
font-size: 2rem;
font-weight: 700;
margin-bottom: 1rem;
color: white;
}
.action-description {
color: #a0aec0;
font-size: 1.4rem;
margin-bottom: 1.5rem;
line-height: 1.5;
}
.action-btn {
background: linear-gradient(135deg, #667eea, #764ba2);
color: white;
border: none;
padding: 1rem 2rem;
border-radius: 12px;
font-weight: 600;
font-size: 1.3rem;
cursor: pointer;
transition: all 0.3s ease;
text-decoration: none;
display: inline-flex;
align-items: center;
gap: 0.8rem;
}
.action-btn:hover {
transform: translateY(-2px);
box-shadow: 0 10px 30px rgba(102, 126, 234, 0.4);
}
/* Stats Section */
.stats-section {
margin-bottom: 4rem;
}
.section-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 3rem;
}
.section-title {
font-size: 3.2rem;
font-weight: 700;
color: white;
}
.section-subtitle {
font-size: 1.6rem;
color: #a0aec0;
}
.section-actions {
display: flex;
gap: 1rem;
}
.stats-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 2rem;
}
.stat-card {
background: rgba(255, 255, 255, 0.05);
padding: 2.5rem;
border-radius: 16px;
backdrop-filter: blur(20px);
border: 1px solid rgba(255, 255, 255, 0.1);
text-align: center;
transition: all 0.3s ease;
}
.stat-card:hover {
transform: translateY(-3px);
border-color: rgba(102, 126, 234, 0.3);
box-shadow: 0 15px 40px rgba(102, 126, 234, 0.1);
}
.stat-icon {
font-size: 2.4rem;
color: #667eea;
margin-bottom: 1rem;
}
.stat-number {
font-size: 3.6rem;
font-weight: 900;
color: #667eea;
margin-bottom: 0.5rem;
}
.stat-label {
color: #a0aec0;
font-size: 1.4rem;
font-weight: 500;
}
.stat-change {
font-size: 1.2rem;
margin-top: 0.5rem;
}
.stat-change.positive {
color: #10b981;
}
.stat-change.negative {
color: #ef4444;
}
/* Progress Bars */
.progress-section {
background: rgba(255, 255, 255, 0.05);
padding: 2.5rem;
border-radius: 16px;
backdrop-filter: blur(20px);
border: 1px solid rgba(255, 255, 255, 0.1);
margin-bottom: 3rem;
}
.progress-item {
margin-bottom: 2rem;
}
.progress-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 1rem;
}
.progress-label {
font-size: 1.4rem;
font-weight: 600;
color: white;
}
.progress-value {
font-size: 1.4rem;
color: #a0aec0;
}
.progress-bar {
width: 100%;
height: 8px;
background: rgba(255, 255, 255, 0.1);
border-radius: 4px;
overflow: hidden;
}
.progress-fill {
height: 100%;
background: linear-gradient(90deg, #667eea, #764ba2);
border-radius: 4px;
transition: width 0.3s ease;
}
/* Recent Activity */
.activity-section {
background: rgba(255, 255, 255, 0.05);
padding: 2.5rem;
border-radius: 16px;
backdrop-filter: blur(20px);
border: 1px solid rgba(255, 255, 255, 0.1);
}
.activity-item {
display: flex;
align-items: center;
gap: 1.5rem;
padding: 1.5rem 0;
border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}
.activity-item:last-child {
border-bottom: none;
}
.activity-icon {
width: 4rem;
height: 4rem;
border-radius: 50%;
background: linear-gradient(135deg, #667eea, #764ba2);
display: flex;
align-items: center;
justify-content: center;
font-size: 1.6rem;
color: white;
}
.activity-content {
flex: 1;
}
.activity-title {
font-size: 1.4rem;
font-weight: 600;
color: white;
margin-bottom: 0.5rem;
}
.activity-time {
font-size: 1.2rem;
color: #a0aec0;
}
.activity-status {
padding: 0.5rem 1rem;
border-radius: 20px;
font-size: 1.2rem;
font-weight: 600;
}
.status-complete {
background: rgba(16, 185, 129, 0.2);
color: #10b981;
}
.status-processing {
background: rgba(245, 158, 11, 0.2);
color: #f59e0b;
}
.status-failed {
background: rgba(239, 68, 68, 0.2);
color: #ef4444;
}
/* Recent Music */
.recent-music {
margin-bottom: 4rem;
}
.music-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
gap: 2rem;
}
.music-card {
background: rgba(255, 255, 255, 0.05);
padding: 2.5rem;
border-radius: 16px;
backdrop-filter: blur(20px);
border: 1px solid rgba(255, 255, 255, 0.1);
transition: all 0.3s ease;
}
.music-card.enhanced {
padding: 2rem;
}
.music-card:hover {
transform: translateY(-3px);
border-color: rgba(102, 126, 234, 0.3);
box-shadow: 0 15px 40px rgba(102, 126, 234, 0.1);
}
/* Track Artwork */
.track-artwork {
margin: 0 0 1.5rem 0;
text-align: center;
}
.artwork-image {
width: 100%;
height: 160px;
object-fit: cover;
border-radius: 12px;
box-shadow: 0 8px 25px rgba(0, 0, 0, 0.3);
transition: transform 0.3s ease;
}
.artwork-image:hover {
transform: scale(1.02);
}
.music-header {
display: flex;
justify-content: space-between;
align-items: flex-start;
margin-bottom: 1.5rem;
}
.music-title {
font-size: 1.8rem;
font-weight: 700;
color: white;
margin-bottom: 0.5rem;
}
.music-prompt {
color: #a0aec0;
font-size: 1.3rem;
line-height: 1.4;
}
.music-details {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 1.5rem;
font-size: 1.3rem;
color: #a0aec0;
}
.music-details-enhanced {
margin-bottom: 2rem;
}
.detail-row {
display: flex;
justify-content: space-between;
align-items: center;
padding: 0.8rem 0;
border-bottom: 1px solid rgba(255, 255, 255, 0.05);
font-size: 1.3rem;
color: #a0aec0;
}
.detail-row:last-child {
border-bottom: none;
}
.detail-row span {
display: flex;
align-items: center;
gap: 0.8rem;
}
.detail-row i {
color: #667eea;
width: 16px;
}
.music-actions {
display: flex;
gap: 1rem;
}
/* Credit History */
.credit-history {
background: rgba(255, 255, 255, 0.05);
padding: 2.5rem;
border-radius: 16px;
backdrop-filter: blur(20px);
border: 1px solid rgba(255, 255, 255, 0.1);
}
.credit-item {
display: flex;
justify-content: space-between;
align-items: center;
padding: 1rem 0;
border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}
.credit-item:last-child {
border-bottom: none;
}
.credit-info {
flex: 1;
}
.credit-description {
font-size: 1.4rem;
font-weight: 600;
color: white;
margin-bottom: 0.5rem;
}
.credit-date {
font-size: 1.2rem;
color: #a0aec0;
}
.credit-amount {
font-size: 1.6rem;
font-weight: 700;
}
.credit-amount.positive {
color: #10b981;
}
.credit-amount.negative {
color: #ef4444;
}
/* Empty State */
.empty-state {
text-align: center;
padding: 4rem 0;
color: #a0aec0;
}
.empty-icon {
font-size: 6rem;
margin-bottom: 2rem;
opacity: 0.5;
}
.empty-title {
font-size: 2.4rem;
color: white;
margin-bottom: 1rem;
}
.empty-description {
font-size: 1.6rem;
color: #a0aec0;
margin-bottom: 3rem;
}
/* Lyrics Section */
.lyrics-section {
margin: 2rem 0;
padding: 1.5rem;
background: rgba(255, 255, 255, 0.03);
border-radius: 12px;
border: 1px solid rgba(255, 255, 255, 0.05);
}
.lyrics-section h4 {
color: #667eea;
font-size: 1.6rem;
margin-bottom: 1rem;
display: flex;
align-items: center;
gap: 0.8rem;
}
.lyrics-content {
max-height: 200px;
overflow-y: auto;
}
.lyrics-content pre {
background: rgba(255, 255, 255, 0.05);
padding: 1.2rem;
border-radius: 8px;
font-size: 1.2rem;
line-height: 1.6;
color: #e2e8f0;
white-space: pre-wrap;
word-wrap: break-word;
margin: 0;
font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}
.lyrics-content::-webkit-scrollbar {
width: 6px;
}
.lyrics-content::-webkit-scrollbar-track {
background: rgba(255, 255, 255, 0.05);
border-radius: 3px;
}
.lyrics-content::-webkit-scrollbar-thumb {
background: rgba(102, 126, 234, 0.5);
border-radius: 3px;
}
.lyrics-content::-webkit-scrollbar-thumb:hover {
background: rgba(102, 126, 234, 0.7);
}
/* Responsive Design */
@media (max-width: 1024px) {
.dashboard-grid {
grid-template-columns: 1fr;
gap: 3rem;
}
}
@media (max-width: 768px) {
html { font-size: 56.25%; }
.hero-title { font-size: 4.8rem; }
.hero-subtitle { font-size: 1.8rem; }
.section-title { font-size: 2.8rem; }
.quick-actions {
grid-template-columns: 1fr;
}
.stats-grid {
grid-template-columns: repeat(2, 1fr);
}
.music-grid {
grid-template-columns: 1fr;
}
.dashboard-container {
padding: 0 2rem;
}
}
@media (max-width: 480px) {
html { font-size: 50%; }
.hero-title { font-size: 4rem; }
.hero-subtitle { font-size: 1.6rem; }
.section-title { font-size: 2.4rem; }
.stats-grid {
grid-template-columns: 1fr;
}
.action-card { padding: 2rem; }
.music-card { padding: 2rem; }
.dashboard-container {
padding: 0 1.5rem;
}
}
</style>
<!-- Hero Section -->
<section class="hero">
<div class="container">
<div class="hero-content">
<?php if (isset($_GET['message']) && $_GET['message'] === 'logged_in_as_user'): ?>
<div class="success-notification" style="background: linear-gradient(135deg, #27ae60, #2ecc71); color: white; padding: 1.5rem 2rem; border-radius: 12px; margin-bottom: 2rem; text-align: center; backdrop-filter: blur(10px); border: 1px solid rgba(39, 174, 96, 0.3);">
<div style="font-size: 1.6rem; font-weight: 600; margin-bottom: 0.5rem;">
✅ Successfully logged in as <?php echo htmlspecialchars($_GET['user_name'] ?? 'user'); ?>
</div>
<div style="font-size: 1.2rem; opacity: 0.9;">
You can now view and manage this user's account
</div>
</div>
<?php endif; ?>
<div class="hero-badge">🎵 Welcome Back, <?php echo htmlspecialchars($user_name); ?>!</div>
<div class="user-level-badge">
<span class="level-icon">⭐</span>
<span>Level <?php echo $user_level; ?> Creator</span>
</div>
<h1 class="hero-title">Your Music Creation Hub</h1>
<p class="hero-subtitle">Track your progress, manage your library, and create amazing AI-generated music with cutting-edge technology.</p>
<div class="hero-actions">
<a href="/#create" class="btn btn-primary">🎵 Create New Music</a>
<a href="/library.php" class="btn btn-secondary">View My Library</a>
</div>
</div>
</div>
</section>
<!-- Dashboard Content -->
<section class="dashboard-content">
<div class="container">
<div class="dashboard-container">
<!-- Quick Actions -->
<div class="quick-actions">
<a href="/#create" class="action-card">
<div class="action-icon">🎵</div>
<div class="action-title">Create Music</div>
<div class="action-description">Generate original AI music with custom prompts and styles</div>
<div class="action-btn">
<i class="fas fa-plus"></i> Start Creating
</div>
</a>
<a href="/#create" class="action-card">
<div class="action-icon">📝</div>
<div class="action-title">Generate Lyrics</div>
<div class="action-description">Create song lyrics with AI assistance</div>
<div class="action-btn">
<i class="fas fa-pen"></i> Write Lyrics
</div>
</a>
<a href="/#create" class="action-card">
<div class="action-icon">🎬</div>
<div class="action-title">Music Videos</div>
<div class="action-description">Create stunning music videos with AI visuals</div>
<div class="action-btn">
<i class="fas fa-video"></i> Make Video
</div>
</a>
<a href="/artists.php" class="action-card">
<div class="action-icon">👥</div>
<div class="action-title">Discover Artists</div>
<div class="action-description">Explore music from talented creators</div>
<div class="action-btn">
<i class="fas fa-users"></i> Browse Artists
</div>
</a>
</div>
<!-- Dashboard Grid -->
<div class="dashboard-grid">
<div class="dashboard-main">
<!-- Stats Section -->
<div class="stats-section">
<div class="section-header">
<div>
<h2 class="section-title">Your Music Stats</h2>
<p class="section-subtitle">Track your progress and achievements</p>
</div>
<div class="section-actions">
<a href="/library.php" class="btn btn-small btn-secondary">View All</a>
</div>
</div>
<div class="stats-grid">
<div class="stat-card">
<div class="stat-icon">🎵</div>
<div class="stat-number"><?php echo $total_tracks; ?></div>
<div class="stat-label">Total Tracks</div>
<div class="stat-change positive">+<?php echo $completed_tracks; ?> completed</div>
</div>
<div class="stat-card">
<div class="stat-icon">⏱️</div>
<div class="stat-number"><?php echo round($total_duration / 60, 1); ?></div>
<div class="stat-label">Total Minutes</div>
<div class="stat-change positive"><?php echo $total_duration; ?> seconds</div>
</div>
<div class="stat-card">
<div class="stat-icon">💎</div>
<div class="stat-number"><?php echo $credits; ?></div>
<div class="stat-label">Credits Left</div>
<div class="stat-change"><?php echo ucfirst($plan); ?> plan</div>
</div>
<div class="stat-card">
<div class="stat-icon">⭐</div>
<div class="stat-number"><?php echo $user_level; ?></div>
<div class="stat-label">Creator Level</div>
<div class="stat-change positive"><?php echo $xp; ?> XP</div>
</div>
</div>
</div>
<!-- Recent Music -->
<div class="recent-music">
<div class="section-header">
<div>
<h2 class="section-title">Recent Music</h2>
<p class="section-subtitle">Your latest AI-generated tracks</p>
</div>
<div class="section-actions">
<a href="/library.php" class="btn btn-small btn-secondary">View All</a>
</div>
</div>
<div class="music-grid">
<?php if (empty($music_history)): ?>
<div class="empty-state" style="grid-column: 1 / -1;">
<div class="empty-icon">🎵</div>
<h3 class="empty-title">No music yet</h3>
<p class="empty-description">Start creating your first AI-generated music!</p>
<a href="/#create" class="btn btn-primary">
<i class="fas fa-plus"></i> Create Your First Track
</a>
</div>
<?php else: ?>
<?php foreach (array_slice($music_history, 0, 6) as $music): ?>
<?php
// Parse metadata for enhanced information
$metadata = json_decode($music['metadata'] ?? '{}', true);
$audio_data = $metadata['data']['data'][0] ?? null;
$image_url = $audio_data['image_url'] ?? null;
$genre = $audio_data['tags'] ?? $metadata['genre'] ?? null;
$model = $audio_data['model_name'] ?? $metadata['model_name'] ?? 'V3';
?>
<div class="music-card enhanced">
<?php if ($image_url): ?>
<div class="track-artwork">
<img src="<?php echo htmlspecialchars($image_url); ?>" alt="Track Artwork" class="artwork-image">
</div>
<?php endif; ?>
<div class="music-header">
<div>
<div class="music-title"><?php echo htmlspecialchars($music['title']); ?></div>
<div class="music-prompt"><?php echo htmlspecialchars(substr($music['prompt'], 0, 80)) . (strlen($music['prompt']) > 80 ? '...' : ''); ?></div>
</div>
<div class="activity-status status-<?php echo $music['status']; ?>">
<?php echo ucfirst($music['status']); ?>
</div>
</div>
<div class="music-details-enhanced">
<div class="detail-row">
<span><i class="fas fa-clock"></i> <?php echo $music['duration']; ?>s</span>
<span><i class="fas fa-calendar"></i> <?php echo date('M j, Y', strtotime($music['created_at'])); ?></span>
</div>
<?php if ($genre || $model): ?>
<div class="detail-row">
<?php if ($genre): ?>
<span><i class="fas fa-tag"></i> <?php echo htmlspecialchars($genre); ?></span>
<?php endif; ?>
<?php if ($model): ?>
<span><i class="fas fa-cog"></i> <?php echo htmlspecialchars($model); ?></span>
<?php endif; ?>
</div>
<?php endif; ?>
</div>
<?php if ($audio_data && !empty($audio_data['prompt'])): ?>
<div class="lyrics-section">
<h4><i class="fas fa-music"></i> Lyrics</h4>
<div class="lyrics-content">
<pre><?php echo htmlspecialchars($audio_data['prompt']); ?></pre>
</div>
</div>
<?php endif; ?>
<div class="music-actions">
<?php if ($music['status'] === 'complete' && $music['audio_url']): ?>
<button class="btn-small btn-primary play-track-btn"
data-audio-url="<?php echo htmlspecialchars($music['audio_url']); ?>"
data-title="<?php echo htmlspecialchars($music['title']); ?>"
data-artist="<?php echo htmlspecialchars($user_name); ?>"
data-track-id="<?php echo $music['id']; ?>">
<i class="fas fa-play"></i> Play
</button>
<a href="<?php echo htmlspecialchars($music['audio_url']); ?>" class="btn-small btn-secondary" download>
<i class="fas fa-download"></i> Download
</a>
<?php else: ?>
<span class="btn-small btn-secondary">
<i class="fas fa-spinner fa-spin"></i> Processing
</span>
<?php endif; ?>
</div>
</div>
<?php endforeach; ?>
<?php endif; ?>
</div>
</div>
</div>
<div class="dashboard-sidebar">
<!-- Progress Section -->
<div class="progress-section">
<h3 class="section-title" style="margin-bottom: 2rem;">Progress Overview</h3>
<div class="progress-item">
<div class="progress-header">
<span class="progress-label">Completion Rate</span>
<span class="progress-value"><?php echo $total_tracks > 0 ? round(($completed_tracks / $total_tracks) * 100) : 0; ?>%</span>
</div>
<div class="progress-bar">
<div class="progress-fill" style="width: <?php echo $total_tracks > 0 ? ($completed_tracks / $total_tracks) * 100 : 0; ?>%"></div>
</div>
</div>
<div class="progress-item">
<div class="progress-header">
<span class="progress-label">Next Level</span>
<span class="progress-value"><?php echo $user_level < 5 ? $user_level + 1 : 'Max'; ?></span>
</div>
<div class="progress-bar">
<?php
$next_level_xp = $user_level < 5 ? ($user_level * 200) : 1000;
$progress = min(100, ($xp / $next_level_xp) * 100);
?>
<div class="progress-fill" style="width: <?php echo $progress; ?>%"></div>
</div>
</div>
<div class="progress-item">
<div class="progress-header">
<span class="progress-label">Credits Usage</span>
<span class="progress-value"><?php echo $credits; ?> remaining</span>
</div>
<div class="progress-bar">
<div class="progress-fill" style="width: <?php echo max(0, 100 - ($credits / 5) * 100); ?>%"></div>
</div>
</div>
</div>
<!-- Recent Activity -->
<div class="activity-section">
<h3 class="section-title" style="margin-bottom: 2rem;">Recent Activity</h3>
<?php if (empty($recent_activity)): ?>
<div class="empty-state">
<div class="empty-icon">📝</div>
<h4 class="empty-title">No activity yet</h4>
<p class="empty-description">Start creating music to see your activity here</p>
</div>
<?php else: ?>
<?php foreach (array_slice($recent_activity, 0, 5) as $activity): ?>
<div class="activity-item">
<div class="activity-icon">🎵</div>
<div class="activity-content">
<div class="activity-title"><?php echo htmlspecialchars($activity['title']); ?></div>
<div class="activity-time"><?php echo date('M j, g:i A', strtotime($activity['date'])); ?></div>
</div>
<div class="activity-status status-<?php echo $activity['status']; ?>">
<?php echo ucfirst($activity['status']); ?>
</div>
</div>
<?php endforeach; ?>
<?php endif; ?>
</div>
<!-- Credit History -->
<?php if (!empty($credit_history)): ?>
<div class="credit-history">
<h3 class="section-title" style="margin-bottom: 2rem;">Credit History</h3>
<?php foreach ($credit_history as $transaction): ?>
<div class="credit-item">
<div class="credit-info">
<div class="credit-description"><?php echo htmlspecialchars($transaction['description'] ?? 'Credit transaction'); ?></div>
<div class="credit-date"><?php echo date('M j, g:i A', strtotime($transaction['created_at'])); ?></div>
</div>
<div class="credit-amount <?php echo $transaction['amount'] > 0 ? 'positive' : 'negative'; ?>">
<?php echo $transaction['amount'] > 0 ? '+' : ''; ?><?php echo $transaction['amount']; ?>
</div>
</div>
<?php endforeach; ?>
</div>
<?php endif; ?>
</div>
</div>
</div>
</div>
</section>
</div>
<?php if (isset($_GET['ajax'])): ?>
</div>
<?php endif; ?>
<script>
// Dashboard-specific functionality
// Setup play button event listeners with AJAX interference prevention
document.addEventListener('DOMContentLoaded', function() {
document.querySelectorAll('.play-track-btn').forEach(button => {
button.addEventListener('click', function(e) {
e.preventDefault();
e.stopPropagation();
e.stopImmediatePropagation();
const audioUrl = this.getAttribute('data-audio-url');
const title = this.getAttribute('data-title');
const artist = this.getAttribute('data-artist');
const trackId = this.getAttribute('data-track-id');
console.log('🎵 Play button clicked:', { audioUrl, title, artist, trackId });
// Validate audio URL
if (!audioUrl || audioUrl === 'NULL' || audioUrl === 'null') {
alert('This track is not available for playback.');
return;
}
// Clear all 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 the enhanced global player
if (typeof window.enhancedGlobalPlayer !== 'undefined' && typeof window.enhancedGlobalPlayer.playTrack === 'function') {
window.enhancedGlobalPlayer.playTrack(audioUrl, title, artist);
console.log('🎵 Dashboard: Track sent to enhanced global player -', title);
// Store reference for global player callbacks
window.currentDashboardPlayButton = this;
window.currentDashboardTrackId = trackId;
} else if (typeof window.playTrack === 'function') {
window.playTrack(audioUrl, title, artist);
console.log('🎵 Dashboard: Track sent via universal playTrack -', title);
} else {
console.error('🎵 Enhanced global player not available');
alert('Player not available. Please refresh the page.');
// Reset button state
this.classList.remove('playing');
this.innerHTML = '<i class="fas fa-play"></i> Play';
}
});
});
});
// Auto-refresh stats every 30 seconds
setInterval(() => {
// Refresh page data if needed
if (document.visibilityState === 'visible') {
// Could implement AJAX refresh here
}
}, 30000);
// Add smooth animations
document.addEventListener('DOMContentLoaded', function() {
// Animate stats on load
const statNumbers = document.querySelectorAll('.stat-number');
statNumbers.forEach(stat => {
const finalValue = parseInt(stat.textContent);
let currentValue = 0;
const increment = finalValue / 50;
const timer = setInterval(() => {
currentValue += increment;
if (currentValue >= finalValue) {
stat.textContent = finalValue;
clearInterval(timer);
} else {
stat.textContent = Math.floor(currentValue);
}
}, 20);
});
});
</script>
<?php
// Include footer (AJAX navigation removed - always include footer)
include 'includes/footer.php';
?>