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/assets/js/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/gositeme/domains/soundstudiopro.com/public_html/assets/js/artist-profile.js
/**
 * ARTIST PROFILE JAVASCRIPT
 * Extracted from artist_profile.php to improve performance
 */

// Global variables
let isEditMode = false;
let originalData = {};

// Global player initialization check
function waitForGlobalPlayer(callback, maxAttempts = 20) {
    if (window.globalPlayerReady && window.enhancedGlobalPlayer && typeof window.enhancedGlobalPlayer.playTrack === 'function') {
        callback();
        return;
    }

    if (maxAttempts > 0) {
        setTimeout(() => waitForGlobalPlayer(callback, maxAttempts - 1), 250);
    } else {
        if (typeof window.showNotification === 'function') {
            window.showNotification('Audio player not available. Please refresh the page.', 'error');
        }
    }
}

// Enable play buttons when global player is ready
function enablePlayButtons() {
    document.querySelectorAll('.preview-btn.play-track-btn, .action-btn.play-btn').forEach(btn => {
        btn.classList.add('ready');
        btn.disabled = false;

        const icon = btn.querySelector('i');
        if (icon && icon.className.includes('fa-spinner')) {
            icon.className = 'fas fa-play';
        }
    });

    if (typeof window.showNotification === 'function') {
        window.showNotification('🎵 Audio player ready!', 'success');
    }
}

// Simple notification system
if (typeof window.showNotification === 'undefined') {
    window.showNotification = function(message, type = 'info') {
        console.log(`[${type.toUpperCase()}] ${message}`);
        
        const notification = document.createElement('div');
        notification.style.cssText = `
            position: fixed;
            top: 20px;
            right: 20px;
            background: ${type === 'error' ? '#e74c3c' : type === 'success' ? '#27ae60' : '#3498db'};
            color: white;
            padding: 1rem 1.5rem;
            border-radius: 8px;
            z-index: 10000;
            font-size: 1.4rem;
            box-shadow: 0 4px 12px rgba(0,0,0,0.3);
            transform: translateX(100%);
            transition: transform 0.3s ease;
        `;
        notification.textContent = message;
        document.body.appendChild(notification);
        
        setTimeout(() => {
            notification.style.transform = 'translateX(0)';
        }, 100);
        
        setTimeout(() => {
            notification.style.transform = 'translateX(100%)';
            setTimeout(() => document.body.removeChild(notification), 300);
        }, 3000);
    };
}

// Profile editing functions
function toggleEditMode() {
    isEditMode = !isEditMode;
    
    if (isEditMode) {
        // Store original data
        originalData = {
            name: document.getElementById('artistNameEdit').value,
            location: document.getElementById('locationEdit').value,
            bio: document.getElementById('bioEdit').value,
            style: document.getElementById('styleEdit')?.value || '',
            genres: document.getElementById('genreInput')?.value || ''
        };
        
        // Show edit fields
        document.getElementById('artistNameDisplay').style.display = 'none';
        document.getElementById('artistNameEdit').style.display = 'block';
        document.getElementById('locationDisplay').style.display = 'none';
        document.getElementById('locationEdit').style.display = 'block';
        document.getElementById('bioDisplay').style.display = 'none';
        document.getElementById('bioEdit').style.display = 'block';
        
        // Show genre input if it exists
        const genreDisplay = document.getElementById('genreDisplay');
        const genreEdit = document.getElementById('genreEdit');
        if (genreDisplay && genreEdit) {
            genreDisplay.style.display = 'none';
            genreEdit.style.display = 'block';
        }
        
        // Show style input if it exists
        const styleDisplay = document.getElementById('styleDisplay');
        const styleEdit = document.getElementById('styleEdit');
        if (styleDisplay && styleEdit) {
            styleDisplay.style.display = 'none';
            styleEdit.style.display = 'block';
        }
        
        // Update button states
        document.getElementById('editProfileBtn').style.display = 'none';
        document.getElementById('saveProfileBtn').style.display = 'inline-flex';
        document.getElementById('cancelProfileBtn').style.display = 'inline-flex';
        
    } else {
        // Hide edit fields
        document.getElementById('artistNameDisplay').style.display = 'block';
        document.getElementById('artistNameEdit').style.display = 'none';
        document.getElementById('locationDisplay').style.display = 'block';
        document.getElementById('locationEdit').style.display = 'none';
        document.getElementById('bioDisplay').style.display = 'block';
        document.getElementById('bioEdit').style.display = 'none';
        
        // Hide genre input
        const genreDisplay = document.getElementById('genreDisplay');
        const genreEdit = document.getElementById('genreEdit');
        if (genreDisplay && genreEdit) {
            genreDisplay.style.display = 'block';
            genreEdit.style.display = 'none';
        }
        
        // Hide style input
        const styleDisplay = document.getElementById('styleDisplay');
        const styleEdit = document.getElementById('styleEdit');
        if (styleDisplay && styleEdit) {
            styleDisplay.style.display = 'block';
            styleEdit.style.display = 'none';
        }
        
        // Update button states
        document.getElementById('editProfileBtn').style.display = 'inline-flex';
        document.getElementById('saveProfileBtn').style.display = 'none';
        document.getElementById('cancelProfileBtn').style.display = 'none';
    }
}

function cancelEditMode() {
    // Restore original data
    document.getElementById('artistNameEdit').value = originalData.name;
    document.getElementById('locationEdit').value = originalData.location;
    document.getElementById('bioEdit').value = originalData.bio;
    
    if (document.getElementById('styleEdit')) {
        document.getElementById('styleEdit').value = originalData.style;
    }
    
    if (document.getElementById('genreInput')) {
        document.getElementById('genreInput').value = originalData.genres;
    }
    
    // Exit edit mode
    toggleEditMode();
}

function saveProfileChanges() {
    const name = document.getElementById('artistNameEdit').value.trim();
    const location = document.getElementById('locationEdit').value.trim();
    const bio = document.getElementById('bioEdit').value.trim();
    const musicStyle = document.getElementById('styleEdit')?.value.trim() || '';
    const genresInput = document.getElementById('genreInput')?.value.trim() || '';
    
    if (!name) {
        alert('Artist name is required!');
        return;
    }
    
    // Parse genres from comma-separated input
    const genres = genresInput.split(',').map(g => g.trim()).filter(g => g.length > 0);
    
    // Show loading state
    const saveBtn = document.getElementById('saveProfileBtn');
    const originalText = saveBtn.innerHTML;
    saveBtn.innerHTML = '<i class="fas fa-spinner fa-spin"></i> Saving...';
    saveBtn.disabled = true;
    
    fetch('/api/update_profile.php', {
        method: 'POST',
        credentials: 'include', // Include cookies for session
        headers: {
            'Content-Type': 'application/json',
        },
        body: JSON.stringify({
            name: name,
            location: location,
            bio: bio,
            music_style: musicStyle,
            genres: genres
        })
    })
    .then(response => response.json())
    .then(data => {
        if (data.success) {
            // Update display elements
            document.getElementById('locationDisplay').innerHTML = location ? `📍 ${location}` : '';
            document.getElementById('bioDisplay').innerHTML = bio ? `<p>${bio}</p>` : '';
            
            // Update genre display
            const genreDisplay = document.getElementById('genreDisplay');
            if (genreDisplay && genres.length > 0) {
                genreDisplay.innerHTML = genres.map(genre => 
                    `<span class="genre-tag">${genre}</span>`
                ).join('');
            }
            
            // Update style display
            const styleDisplay = document.getElementById('styleDisplay');
            if (styleDisplay && musicStyle) {
                styleDisplay.innerHTML = `<div class="style-text">${musicStyle}</div>`;
            }
            
            // Exit edit mode
            toggleEditMode();
            
            // Show success message
            if (typeof window.showNotification === 'function') {
                window.showNotification('Profile updated successfully!', 'success');
            }
        } else {
            throw new Error(data.error || 'Failed to update profile');
        }
    })
    .catch(error => {
        console.error('Error:', error);
        alert('Failed to save changes: ' + error.message);
    })
    .finally(() => {
        // Restore button state
        saveBtn.innerHTML = originalText;
        saveBtn.disabled = false;
    });
}

// Profile image upload
function uploadProfileImage(file) {
    const formData = new FormData();
    formData.append('profile_image', file);
    
    fetch('/api/upload_profile_image.php', {
        method: 'POST',
        credentials: 'include', // Include cookies for session
        body: formData
    })
    .then(response => response.json())
    .then(data => {
        if (data.success) {
            // Update profile image
            const avatarImage = document.getElementById('artistAvatarImage');
            const avatarDefault = document.getElementById('artistAvatarDefault');
            
            if (avatarImage) {
                avatarImage.src = data.data.image_url;
                avatarImage.style.display = 'block';
            }
            
            if (avatarDefault) {
                avatarDefault.style.display = 'none';
            }
            
            if (typeof window.showNotification === 'function') {
                window.showNotification('Profile image updated!', 'success');
            }
        } else {
            throw new Error(data.error || 'Failed to upload image');
        }
    })
    .catch(error => {
        console.error('Error:', error);
        alert('Failed to upload image: ' + error.message);
    });
}

// Initialize profile image upload
function initializeProfileImageUpload() {
    const fileInput = document.getElementById('profileImageUpload');
    const avatarContainer = document.getElementById('artistAvatarContainer');
    
    if (fileInput && avatarContainer) {
        // Show upload overlay on hover
        avatarContainer.addEventListener('mouseenter', function() {
            const overlay = document.getElementById('avatarUploadOverlay');
            if (overlay) {
                overlay.style.display = 'flex';
            }
        });
        
        avatarContainer.addEventListener('mouseleave', function() {
            const overlay = document.getElementById('avatarUploadOverlay');
            if (overlay) {
                overlay.style.display = 'none';
            }
        });
        
        // Handle file selection
        fileInput.addEventListener('change', function(e) {
            const file = e.target.files[0];
            if (file) {
                uploadProfileImage(file);
            }
        });
    }
}

// Track playback functions
function playTrack(trackId, audioUrl) {
    if (window.enhancedGlobalPlayer && typeof window.enhancedGlobalPlayer.playTrack === 'function') {
        window.enhancedGlobalPlayer.playTrack(trackId, audioUrl);
    } else {
        // Fallback to direct audio playback
        const audio = new Audio(audioUrl);
        audio.play().catch(error => {
            console.error('Playback failed:', error);
            if (typeof window.showNotification === 'function') {
                window.showNotification('Playback failed. Please try again.', 'error');
            }
        });
    }
}

// Initialize when DOM is loaded
document.addEventListener('DOMContentLoaded', function() {
    // Initialize profile image upload
    initializeProfileImageUpload();
    
    // Check if global player is ready
    if (window.globalPlayerReady && window.enhancedGlobalPlayer && typeof window.enhancedGlobalPlayer.playTrack === 'function') {
        enablePlayButtons();
        return;
    }
    
    // Wait for global player to be ready
    waitForGlobalPlayer(() => {
        enablePlayButtons();
    });
}); 

CasperSecurity Mini