T.ME/BIBIL_0DAY
CasperSecurity


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/domains/soundstudiopro.com/public_html/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/gositeme/domains/soundstudiopro.com/public_html/profile.php
<?php
session_start();

// Check if user is logged in
if (!isset($_SESSION['user_id'])) {
    header('Location: /auth/login.php');
    exit;
}

require_once 'config/database.php';

$pdo = getDBConnection();

// Get current tab
$current_tab = $_GET['tab'] ?? 'profile';

// OPTIMIZED: Using JOINs instead of correlated subqueries for better performance
// Get user data
$stmt = $pdo->prepare("
    SELECT 
        u.*,
        up.bio,
        up.location,
        up.website,
        up.social_links,
        up.profile_image,
        up.genres,
        up.music_style,
        COUNT(mt.id) as total_tracks,
        COUNT(CASE WHEN mt.status = 'complete' THEN 1 END) as completed_tracks,
        COALESCE(follower_stats.followers_count, 0) as followers_count,
        COALESCE(following_stats.following_count, 0) as following_count
    FROM users u
    LEFT JOIN user_profiles up ON u.id = up.user_id
    LEFT JOIN music_tracks mt ON u.id = mt.user_id
    LEFT JOIN (SELECT following_id, COUNT(*) as followers_count FROM user_follows GROUP BY following_id) follower_stats ON u.id = follower_stats.following_id
    LEFT JOIN (SELECT follower_id, COUNT(*) as following_count FROM user_follows GROUP BY follower_id) following_stats ON u.id = following_stats.follower_id
    WHERE u.id = ?
    GROUP BY u.id, u.name, u.email, u.plan, u.credits, u.created_at, up.bio, up.location, up.website, up.social_links, up.profile_image, up.genres, up.music_style, follower_stats.followers_count, following_stats.following_count
");

$stmt->execute([$_SESSION['user_id']]);
$user = $stmt->fetch();

// Get user's purchases if on purchases tab
$purchases = [];
if ($current_tab === 'purchases') {
    $stmt = $pdo->prepare("
        SELECT 
            tp.id as purchase_id,
            tp.price_paid,
            tp.credits_used,
            tp.purchase_date,
            tp.download_count,
            tp.last_downloaded,
            mt.id as track_id,
            mt.title,
            mt.audio_url,
            mt.duration,
            mt.music_type,
            u.name as artist_name,
            u.id as artist_id
        FROM track_purchases tp
        JOIN music_tracks mt ON tp.track_id = mt.id
        JOIN users u ON mt.user_id = u.id
        WHERE tp.user_id = ?
        ORDER BY tp.purchase_date DESC
    ");
    
    $stmt->execute([$_SESSION['user_id']]);
    $purchases = $stmt->fetchAll();
}

// OPTIMIZED: Using JOINs instead of correlated subqueries for better performance
// Get user's tracks if on profile tab
$user_tracks = [];
if ($current_tab === 'profile') {
    $stmt = $pdo->prepare("
        SELECT 
            mt.*,
            COALESCE(like_stats.like_count, 0) as like_count,
            COALESCE(play_stats.play_count, 0) as play_count
        FROM music_tracks mt
        LEFT JOIN (SELECT track_id, COUNT(*) as like_count FROM track_likes GROUP BY track_id) like_stats ON mt.id = like_stats.track_id
        LEFT JOIN (SELECT track_id, COUNT(*) as play_count FROM track_plays GROUP BY track_id) play_stats ON mt.id = play_stats.track_id
        WHERE mt.user_id = ? AND mt.status = 'complete'
        ORDER BY mt.created_at DESC
        LIMIT 10
    ");
    
    $stmt->execute([$_SESSION['user_id']]);
    $user_tracks = $stmt->fetchAll();
}

// Get friends count for tab display
$stmt = $pdo->prepare("
    SELECT COUNT(*) 
    FROM user_friends 
    WHERE (user_id = ? OR friend_id = ?) 
    AND status = 'accepted'
");
$stmt->execute([$_SESSION['user_id'], $_SESSION['user_id']]);
$friends_count = (int)$stmt->fetchColumn();

// Get user's friends if on friends tab
$friends = [];
if ($current_tab === 'friends') {
    $stmt = $pdo->prepare("
        SELECT 
            u.id,
            u.name,
            u.email,
            up.profile_image,
            up.bio,
            up.location,
            COALESCE(track_stats.track_count, 0) as track_count,
            COALESCE(follower_stats.followers_count, 0) as followers_count,
            uf.created_at as friends_since
        FROM user_friends uf
        JOIN users u ON (
            (uf.user_id = ? AND uf.friend_id = u.id) OR 
            (uf.friend_id = ? AND uf.user_id = u.id)
        )
        LEFT JOIN user_profiles up ON u.id = up.user_id
        LEFT JOIN (SELECT user_id, COUNT(*) as track_count FROM music_tracks WHERE status = 'complete' GROUP BY user_id) track_stats ON u.id = track_stats.user_id
        LEFT JOIN (SELECT following_id, COUNT(*) as followers_count FROM user_follows GROUP BY following_id) follower_stats ON u.id = follower_stats.following_id
        WHERE (uf.user_id = ? OR uf.friend_id = ?) 
        AND uf.status = 'accepted'
        AND u.id != ?
        ORDER BY uf.updated_at DESC
    ");
    
    $stmt->execute([$_SESSION['user_id'], $_SESSION['user_id'], $_SESSION['user_id'], $_SESSION['user_id'], $_SESSION['user_id']]);
    $friends = $stmt->fetchAll();
}

// Set page variables for header
$page_title = 'My Profile - SoundStudioPro';
$page_description = 'Manage your profile, view purchases, and track your activity.';
$current_page = 'profile';

include 'includes/header.php';
?>

<main>

<style>
    .profile-container {
        max-width: 1200px;
        margin: 0 auto;
        padding: 2rem;
    }
    
    .profile-header {
        text-align: center;
        margin-bottom: 3rem;
    }
    
    .profile-title {
        font-size: 3rem;
        font-weight: 700;
        background: linear-gradient(135deg, #667eea, #764ba2);
        -webkit-background-clip: text;
        -webkit-text-fill-color: transparent;
        margin-bottom: 1rem;
    }
    
    .profile-subtitle {
        font-size: 1.4rem;
        color: #a0aec0;
    }
    
    .profile-tabs {
        display: flex;
        justify-content: center;
        margin-bottom: 3rem;
        background: rgba(255, 255, 255, 0.05);
        border-radius: 12px;
        padding: 0.5rem;
        gap: 0.5rem;
    }
    
    .profile-tab {
        padding: 1rem 2rem;
        border-radius: 8px;
        text-decoration: none;
        color: #a0aec0;
        font-weight: 600;
        transition: all 0.3s ease;
        display: flex;
        align-items: center;
        gap: 0.5rem;
    }
    
    .profile-tab:hover {
        color: white;
        background: rgba(255, 255, 255, 0.1);
    }
    
    .profile-tab.active {
        background: linear-gradient(135deg, #667eea, #764ba2);
        color: white;
    }
    
    .tab-content {
        background: rgba(255, 255, 255, 0.05);
        border-radius: 16px;
        padding: 2rem;
        border: 1px solid rgba(255, 255, 255, 0.1);
    }
    
    /* Profile Tab Styles */
    .profile-info {
        display: grid;
        grid-template-columns: 1fr 2fr;
        gap: 3rem;
        margin-bottom: 3rem;
    }
    
    .profile-avatar-section {
        text-align: center;
    }
    
    .profile-avatar {
        width: 150px;
        height: 150px;
        background: linear-gradient(135deg, #667eea, #764ba2);
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 4rem;
        color: white;
        font-weight: 600;
        margin: 0 auto 1.5rem;
    }
    
    .profile-stats {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: 1rem;
        margin-top: 2rem;
    }
    
    .stat-item {
        background: rgba(255, 255, 255, 0.05);
        padding: 1.5rem;
        border-radius: 12px;
        text-align: center;
    }
    
    .stat-number {
        font-size: 2rem;
        font-weight: 700;
        color: #667eea;
        margin-bottom: 0.5rem;
    }
    
    .stat-label {
        font-size: 1.2rem;
        color: #a0aec0;
    }
    
    .profile-details h3 {
        font-size: 2.4rem;
        color: white;
        margin-bottom: 1rem;
    }
    
    .profile-details p {
        font-size: 1.4rem;
        color: #a0aec0;
        margin-bottom: 1.5rem;
        line-height: 1.6;
    }
    
    .profile-actions {
        display: flex;
        gap: 1rem;
        margin-top: 2rem;
    }
    
    .profile-btn {
        padding: 1rem 2rem;
        border-radius: 8px;
        text-decoration: none;
        font-weight: 600;
        transition: all 0.3s ease;
    }
    
    .profile-btn.primary {
        background: linear-gradient(135deg, #667eea, #764ba2);
        color: white;
    }
    
    .profile-btn.secondary {
        background: rgba(255, 255, 255, 0.1);
        color: #a0aec0;
        border: 1px solid rgba(255, 255, 255, 0.2);
    }
    
    .profile-btn:hover {
        transform: translateY(-2px);
    }
    
    /* Purchases Tab Styles */
    .purchases-grid {
        display: grid;
        grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
        gap: 2rem;
    }
    
    .purchase-card {
        background: rgba(255, 255, 255, 0.05);
        border: 1px solid rgba(255, 255, 255, 0.1);
        border-radius: 16px;
        padding: 2rem;
        transition: all 0.3s ease;
    }
    
    .purchase-card:hover {
        transform: translateY(-5px);
        box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
        border-color: rgba(102, 126, 234, 0.3);
    }
    
    .purchase-header {
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
        margin-bottom: 1.5rem;
    }
    
    .purchase-title {
        font-size: 1.8rem;
        font-weight: 600;
        color: white;
        margin-bottom: 0.5rem;
    }
    
    .purchase-artist {
        font-size: 1.2rem;
        color: #667eea;
    }
    
    .purchase-price {
        background: linear-gradient(135deg, #48bb78, #38a169);
        color: white;
        padding: 0.5rem 1rem;
        border-radius: 8px;
        font-size: 1.2rem;
        font-weight: 600;
    }
    
    .purchase-info {
        display: flex;
        gap: 1rem;
        margin-bottom: 1.5rem;
        font-size: 1.2rem;
        color: #a0aec0;
    }
    
    .purchase-date {
        color: #a0aec0;
        font-size: 1.1rem;
        margin-bottom: 1.5rem;
    }
    
    .purchase-actions {
        display: flex;
        gap: 1rem;
    }
    
    .purchase-btn {
        flex: 1;
        padding: 1rem;
        border: none;
        border-radius: 8px;
        font-size: 1.4rem;
        font-weight: 600;
        cursor: pointer;
        transition: all 0.3s ease;
        text-decoration: none;
        text-align: center;
    }
    
    .download-btn {
        background: linear-gradient(135deg, #667eea, #764ba2);
        color: white;
    }
    
    .download-btn:hover {
        transform: translateY(-2px);
        box-shadow: 0 8px 25px rgba(102, 126, 234, 0.4);
    }
    
    .play-btn {
        background: rgba(255, 255, 255, 0.1);
        color: #a0aec0;
        border: 1px solid rgba(255, 255, 255, 0.2);
    }
    
    .play-btn:hover {
        background: rgba(255, 255, 255, 0.2);
        color: white;
    }
    
    .empty-purchases {
        text-align: center;
        padding: 4rem;
        color: #a0aec0;
    }
    
    .empty-purchases i {
        font-size: 4rem;
        margin-bottom: 1rem;
        color: #667eea;
    }
    
    .empty-purchases h3 {
        font-size: 2rem;
        color: white;
        margin-bottom: 1rem;
    }
    
    .empty-purchases p {
        font-size: 1.4rem;
        margin-bottom: 2rem;
    }
    
    .browse-btn {
        background: linear-gradient(135deg, #667eea, #764ba2);
        color: white;
        padding: 1rem 2rem;
        border-radius: 8px;
        text-decoration: none;
        font-weight: 600;
        transition: all 0.3s ease;
    }
    
    .browse-btn:hover {
        transform: translateY(-2px);
        box-shadow: 0 8px 25px rgba(102, 126, 234, 0.4);
    }
    
    /* Friends Tab Styles */
    .friends-grid {
        display: grid;
        grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
        gap: 2rem;
        margin-top: 2rem;
    }
    
    .friend-card {
        background: rgba(255, 255, 255, 0.05);
        border: 1px solid rgba(255, 255, 255, 0.1);
        border-radius: 16px;
        padding: 1.5rem;
        text-align: center;
        transition: all 0.3s ease;
        cursor: pointer;
        text-decoration: none;
        color: inherit;
        display: block;
    }
    
    .friend-card:hover {
        transform: translateY(-5px);
        box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
        border-color: rgba(102, 126, 234, 0.3);
        background: rgba(255, 255, 255, 0.08);
    }
    
    .friend-avatar {
        width: 120px;
        height: 120px;
        border-radius: 50%;
        margin: 0 auto 1rem;
        background: linear-gradient(135deg, #667eea, #764ba2);
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 3rem;
        color: white;
        font-weight: 600;
        overflow: hidden;
        border: 3px solid rgba(255, 255, 255, 0.2);
    }
    
    .friend-avatar img {
        width: 100%;
        height: 100%;
        object-fit: cover;
    }
    
    .friend-name {
        font-size: 1.6rem;
        font-weight: 600;
        color: white;
        margin-bottom: 0.5rem;
    }
    
    .friend-location {
        font-size: 1.2rem;
        color: #a0aec0;
        margin-bottom: 1rem;
    }
    
    .friend-stats {
        display: flex;
        justify-content: space-around;
        margin-top: 1rem;
        padding-top: 1rem;
        border-top: 1px solid rgba(255, 255, 255, 0.1);
    }
    
    .friend-stat {
        text-align: center;
    }
    
    .friend-stat-number {
        font-size: 1.4rem;
        font-weight: 700;
        color: #667eea;
        display: block;
    }
    
    .friend-stat-label {
        font-size: 1rem;
        color: #a0aec0;
        margin-top: 0.25rem;
    }
    
    .empty-friends {
        text-align: center;
        padding: 4rem;
        color: #a0aec0;
    }
    
    .empty-friends i {
        font-size: 4rem;
        margin-bottom: 1rem;
        color: #667eea;
    }
    
    .empty-friends h3 {
        font-size: 2rem;
        color: white;
        margin-bottom: 1rem;
    }
    
    .empty-friends p {
        font-size: 1.4rem;
        margin-bottom: 2rem;
    }
    
    /* Settings Tab Styles */
    .settings-section {
        margin-bottom: 2rem;
    }
    
    .settings-section h3 {
        font-size: 2rem;
        color: white;
        margin-bottom: 1rem;
    }
    
    .settings-section p {
        font-size: 1.4rem;
        color: #a0aec0;
        margin-bottom: 1.5rem;
    }
    
    /* Activity Tab Styles */
    .activity-item {
        background: rgba(255, 255, 255, 0.05);
        border-radius: 12px;
        padding: 1.5rem;
        margin-bottom: 1rem;
        border-left: 4px solid #667eea;
    }
    
    .activity-title {
        font-size: 1.6rem;
        color: white;
        margin-bottom: 0.5rem;
    }
    
    .activity-time {
        font-size: 1.2rem;
        color: #a0aec0;
    }
</style>

<div class="profile-container">
    <div class="profile-header">
        <h1 class="profile-title">My Profile</h1>
        <p class="profile-subtitle">Manage your account and track your activity</p>
    </div>
    
    <div class="profile-tabs">
        <a href="?tab=profile" class="profile-tab <?= $current_tab === 'profile' ? 'active' : '' ?>">
            <i class="fas fa-user"></i>
            Profile
        </a>
        <a href="?tab=friends" class="profile-tab <?= $current_tab === 'friends' ? 'active' : '' ?>">
            <i class="fas fa-users"></i>
            Friends <?= $friends_count > 0 ? '(' . $friends_count . ')' : '' ?>
        </a>
        <a href="?tab=purchases" class="profile-tab <?= $current_tab === 'purchases' ? 'active' : '' ?>">
            <i class="fas fa-shopping-bag"></i>
            Purchases
        </a>
        <a href="?tab=settings" class="profile-tab <?= $current_tab === 'settings' ? 'active' : '' ?>">
            <i class="fas fa-cog"></i>
            Settings
        </a>
        <a href="?tab=activity" class="profile-tab <?= $current_tab === 'activity' ? 'active' : '' ?>">
            <i class="fas fa-chart-line"></i>
            Activity
        </a>
    </div>
    
    <div class="tab-content">
        <?php if ($current_tab === 'profile'): ?>
            <!-- Profile Tab -->
            <div class="profile-info">
                <div class="profile-avatar-section">
                    <div class="profile-avatar">
                        <?= strtoupper(substr($user['name'], 0, 1)) ?>
                    </div>
                    <h3><?= htmlspecialchars($user['name']) ?></h3>
                    <p><?= htmlspecialchars($user['email']) ?></p>
                    <div class="profile-stats">
                        <div class="stat-item">
                            <div class="stat-number"><?= $user['completed_tracks'] ?></div>
                            <div class="stat-label">Tracks</div>
                        </div>
                        <div class="stat-item">
                            <div class="stat-number"><?= $user['followers_count'] ?></div>
                            <div class="stat-label">Followers</div>
                        </div>
                        <div class="stat-item">
                            <div class="stat-number"><?= $user['following_count'] ?></div>
                            <div class="stat-label">Following</div>
                        </div>
                    </div>
                </div>
                
                <div class="profile-details">
                    <h3>About Me</h3>
                    <p><?= $user['bio'] ? htmlspecialchars($user['bio']) : 'No bio added yet.' ?></p>
                    
                    <h3>Plan & Credits</h3>
                    <?php
                    // Check for active subscription
                    $subscription_display = null;
                    try {
                        require_once __DIR__ . '/utils/subscription_helpers.php';
                        $subscription_display = getSubscriptionInfo($_SESSION['user_id']);
                    } catch (Exception $e) {
                        error_log("Error getting subscription info in profile: " . $e->getMessage());
                        $subscription_display = null;
                    }
                    
                    if ($subscription_display && $subscription_display['status'] === 'active'):
                        $plans_config = require __DIR__ . '/config/subscription_plans.php';
                        $plan_info = isset($plans_config[$subscription_display['plan_name']]) ? $plans_config[$subscription_display['plan_name']] : null;
                    ?>
                        <p>Current Plan: <strong><?= ucfirst($subscription_display['plan_name']) ?> Subscription</strong> 
                        <?php if ($plan_info): ?>
                            <span style="color: <?= $plan_info['color'] ?>;">($<?= number_format($plan_info['price'], 2) ?>/month)</span>
                        <?php endif; ?>
                        </p>
                        <p>Subscription Status: <strong style="color: #48bb78;"><?= ucfirst($subscription_display['status']) ?></strong></p>
                        <?php if ($subscription_display['current_period_end']): ?>
                            <p>Renews: <strong><?= date('M j, Y', strtotime($subscription_display['current_period_end'])) ?></strong></p>
                        <?php endif; ?>
                    <?php else: ?>
                        <p>Current Plan: <strong><?= ucfirst($user['plan']) ?></strong></p>
                    <?php endif; ?>
                    <p>Available Credits: <strong><?= $user['credits'] ?></strong></p>
                    
                    <div class="profile-actions">
                        <a href="/utils/profile_settings.php" class="profile-btn primary">
                            <i class="fas fa-edit"></i>
                            Edit Profile
                        </a>
                        <a href="/artist_profile.php?id=<?= $_SESSION['user_id'] ?>" class="profile-btn secondary">
                            <i class="fas fa-eye"></i>
                            View Public Profile
                        </a>
                    </div>
                </div>
            </div>
            
            <?php if (!empty($user_tracks)): ?>
                <h3>Recent Tracks</h3>
                <div class="purchases-grid">
                    <?php foreach ($user_tracks as $track): ?>
                        <div class="purchase-card">
                            <div class="purchase-header">
                                <div>
                                    <div class="purchase-title"><?= htmlspecialchars($track['title']) ?></div>
                                    <div class="purchase-artist">by You</div>
                                </div>
                                <div class="purchase-price"><?= $track['duration'] ? gmdate("i:s", $track['duration']) : 'Unknown' ?></div>
                            </div>
                            <div class="purchase-info">
                                <span><i class="fas fa-play"></i> <?= $track['play_count'] ?> plays</span>
                                <span><i class="fas fa-heart"></i> <?= $track['like_count'] ?> likes</span>
                            </div>
                            <div class="purchase-actions">
                                <button class="purchase-btn play-btn" onclick="playTrack('<?= htmlspecialchars($track['audio_url']) ?>', '<?= htmlspecialchars($track['title']) ?>')">
                                    <i class="fas fa-play"></i>
                                    Play
                                </button>
                            </div>
                        </div>
                    <?php endforeach; ?>
                </div>
            <?php endif; ?>
            
        <?php elseif ($current_tab === 'friends'): ?>
            <!-- Friends Tab -->
            <?php if (empty($friends)): ?>
                <div class="empty-friends">
                    <i class="fas fa-user-friends"></i>
                    <h3>No Friends Yet</h3>
                    <p>Start connecting with other artists! Send friend requests to build your network.</p>
                    <a href="artists.php" class="browse-btn">
                        <i class="fas fa-search"></i>
                        Browse Artists
                    </a>
                </div>
            <?php else: ?>
                <div style="margin-bottom: 2rem;">
                    <h3 style="font-size: 2.4rem; color: white; margin-bottom: 0.5rem;">My Friends</h3>
                    <p style="font-size: 1.4rem; color: #a0aec0;">You have <?= $friends_count ?> friend<?= $friends_count != 1 ? 's' : '' ?></p>
                </div>
                <div class="friends-grid">
                    <?php foreach ($friends as $friend): ?>
                        <a href="/artist_profile.php?id=<?= $friend['id'] ?>" class="friend-card">
                            <div class="friend-avatar">
                                <?php if (!empty($friend['profile_image'])): ?>
                                    <img src="<?= htmlspecialchars($friend['profile_image']) ?>" alt="<?= htmlspecialchars($friend['name']) ?>">
                                <?php else: ?>
                                    <?= strtoupper(substr($friend['name'], 0, 1)) ?>
                                <?php endif; ?>
                            </div>
                            <div class="friend-name"><?= htmlspecialchars($friend['name']) ?></div>
                            <?php if (!empty($friend['location'])): ?>
                                <div class="friend-location">
                                    <i class="fas fa-map-marker-alt"></i> <?= htmlspecialchars($friend['location']) ?>
                                </div>
                            <?php endif; ?>
                            <div class="friend-stats">
                                <div class="friend-stat">
                                    <span class="friend-stat-number"><?= $friend['track_count'] ?></span>
                                    <span class="friend-stat-label">Tracks</span>
                                </div>
                                <div class="friend-stat">
                                    <span class="friend-stat-number"><?= $friend['followers_count'] ?></span>
                                    <span class="friend-stat-label">Followers</span>
                                </div>
                            </div>
                        </a>
                    <?php endforeach; ?>
                </div>
            <?php endif; ?>
            
        <?php elseif ($current_tab === 'purchases'): ?>
            <!-- Purchases Tab -->
            <?php if (empty($purchases)): ?>
                <div class="empty-purchases">
                    <i class="fas fa-music"></i>
                    <h3>No Purchases Yet</h3>
                    <p>Start building your music collection by purchasing tracks from our artists!</p>
                    <a href="artists.php" class="browse-btn">
                        <i class="fas fa-search"></i>
                        Browse Artists
                    </a>
                </div>
            <?php else: ?>
                <div class="purchases-grid">
                    <?php foreach ($purchases as $purchase): ?>
                        <div class="purchase-card">
                            <div class="purchase-header">
                                <div>
                                    <div class="purchase-title"><?= htmlspecialchars($purchase['title']) ?></div>
                                    <div class="purchase-artist">by <?= htmlspecialchars($purchase['artist_name']) ?></div>
                                </div>
                                <div class="purchase-price">$<?= number_format($purchase['price_paid'], 2) ?></div>
                            </div>
                            <div class="purchase-info">
                                <span><i class="fas fa-clock"></i> <?= $purchase['duration'] ? gmdate("i:s", $purchase['duration']) : 'Unknown' ?></span>
                                <span><i class="fas fa-music"></i> <?= ucfirst($purchase['music_type']) ?></span>
                                <span><i class="fas fa-download"></i> <?= $purchase['download_count'] ?> downloads</span>
                            </div>
                            <div class="purchase-date">
                                Purchased on <?= date('M j, Y', strtotime($purchase['purchase_date'])) ?>
                            </div>
                            <div class="purchase-actions">
                                <button class="purchase-btn play-btn" onclick="playTrack('<?= htmlspecialchars($purchase['audio_url']) ?>', '<?= htmlspecialchars($purchase['title']) ?>')">
                                    <i class="fas fa-play"></i>
                                    Play
                                </button>
                                <a href="<?= htmlspecialchars($purchase['audio_url']) ?>" download class="purchase-btn download-btn" onclick="recordDownload(<?= $purchase['purchase_id'] ?>)">
                                    <i class="fas fa-download"></i>
                                    Download
                                </a>
                            </div>
                        </div>
                    <?php endforeach; ?>
                </div>
            <?php endif; ?>
            
        <?php elseif ($current_tab === 'settings'): ?>
            <!-- Settings Tab -->
            <div class="settings-section">
                <h3>Profile Settings</h3>
                <p>Customize your profile, update your information, and manage your preferences.</p>
                <a href="/utils/profile_settings.php" class="profile-btn primary">
                    <i class="fas fa-cog"></i>
                    Go to Settings
                </a>
            </div>
            
            <div class="settings-section">
                <h3>Account Management</h3>
                <p>Manage your account, change password, and update your subscription.</p>
                <a href="/utils/profile_settings.php" class="profile-btn secondary">
                    <i class="fas fa-user-cog"></i>
                    Account Settings
                </a>
            </div>
            
        <?php elseif ($current_tab === 'activity'): ?>
            <!-- Activity Tab -->
            <div class="activity-item">
                <div class="activity-title">Profile Created</div>
                <div class="activity-time"><?= date('M j, Y', strtotime($user['created_at'])) ?></div>
            </div>
            
            <?php if ($user['completed_tracks'] > 0): ?>
                <div class="activity-item">
                    <div class="activity-title">Created <?= $user['completed_tracks'] ?> tracks</div>
                    <div class="activity-time">Latest: <?= date('M j, Y') ?></div>
                </div>
            <?php endif; ?>
            
            <?php if (!empty($purchases)): ?>
                <div class="activity-item">
                    <div class="activity-title">Purchased <?= count($purchases) ?> tracks</div>
                    <div class="activity-time">Latest: <?= date('M j, Y', strtotime($purchases[0]['purchase_date'])) ?></div>
                </div>
            <?php endif; ?>
        <?php endif; ?>
    </div>
</div>

<!-- Global player now included via footer.php -->

<script>
    function playTrack(audioUrl, title) {
        if (typeof window.playTrackWithGlobalPlayer === 'function') {
            window.playTrackWithGlobalPlayer(audioUrl, title, 'Profile Track');
        } else {
            // Fallback - no auto-play
            const audio = new Audio(audioUrl);
            // Don't auto-play - let user control
            console.log('🎵 Ready to play:', title);
        }
    }
    
    function recordDownload(purchaseId) {
        // Record download in database
        fetch('/api/record_download.php', {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json',
            },
            body: JSON.stringify({
                purchase_id: purchaseId
            })
        }).catch(error => {
            console.error('Error recording download:', error);
        });
    }
</script>

</main>

<?php include 'includes/footer.php'; ?> 

CasperSecurity Mini