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/private_html/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/gositeme/domains/soundstudiopro.com/private_html/admin.php
<?php
// Define admin context to prevent double validation
define('ADMIN_CONTEXT', true);

// Include security functions
require_once 'includes/security.php';

// Validate admin access
validateAdminAccess();

// Rate limiting for admin panel
if (!checkRateLimit('admin_access', 50, 60)) {
    http_response_code(429);
    die('Too many admin access attempts. Please wait before trying again.');
}

// Debug output (only in development)
if (defined('DEBUG_MODE') && DEBUG_MODE) {
    error_reporting(E_ALL);
    ini_set('display_errors', 1);
}

// Handle AJAX requests
$is_ajax = isset($_GET['ajax']) && $_GET['ajax'] == '1';

require_once 'config/database.php';

// Handle AJAX playlist requests FIRST (before any HTML output)
if ($is_ajax && isset($_POST['playlist_action'])) {
    // Clear any output buffers and prevent any HTML output
    while (ob_get_level()) {
        ob_end_clean();
    }
    
    // Set JSON header immediately
    header('Content-Type: application/json');
    header('Cache-Control: no-cache, must-revalidate');
    
    $response = ['success' => false, 'error' => 'Unknown action'];
    
    try {
        $pdo = getDBConnection();
        
        switch ($_POST['playlist_action']) {
            case 'toggle_featured':
                $track_id = intval($_POST['track_id']);
                $is_featured = isset($_POST['is_featured']) && $_POST['is_featured'] == '1' ? 1 : 0;
                $stmt = $pdo->prepare("UPDATE music_tracks SET is_featured = ? WHERE id = ?");
                $result = $stmt->execute([$is_featured, $track_id]);
                if ($result) {
                    $response = ['success' => true, 'message' => 'Featured status updated'];
                } else {
                    $response = ['success' => false, 'error' => 'Database update failed'];
                }
                break;
                
            case 'toggle_vip':
                $track_id = intval($_POST['track_id']);
                // Explicitly handle both checked (1) and unchecked (0) states
                $is_vip = (isset($_POST['is_vip']) && ($_POST['is_vip'] === '1' || $_POST['is_vip'] === 1)) ? 1 : 0;
                
                if ($is_vip == 1) {
                    // When ticking VIP, automatically set order to the next available number
                    $order_stmt = $pdo->query("SELECT COALESCE(MAX(playlist_order), 0) + 1 as next_order FROM music_tracks WHERE is_vip_sample = 1");
                    $order_result = $order_stmt->fetch(PDO::FETCH_ASSOC);
                    $new_order = $order_result['next_order'] ?? 1;
                    
                    $stmt = $pdo->prepare("UPDATE music_tracks SET is_vip_sample = ?, playlist_order = ? WHERE id = ?");
                    $result = $stmt->execute([$is_vip, $new_order, $track_id]);
                    
                    if ($result) {
                        $response = ['success' => true, 'message' => 'VIP status updated', 'is_vip' => $is_vip, 'order' => $new_order];
                    } else {
                        $response = ['success' => false, 'error' => 'Database update failed'];
                    }
                } else {
                    // When unticking VIP, just remove VIP status (keep order for reference)
                    $stmt = $pdo->prepare("UPDATE music_tracks SET is_vip_sample = ? WHERE id = ?");
                    $result = $stmt->execute([$is_vip, $track_id]);
                    
                    if ($result) {
                        $response = ['success' => true, 'message' => 'VIP status removed', 'is_vip' => $is_vip];
                    } else {
                        $response = ['success' => false, 'error' => 'Database update failed'];
                    }
                }
                break;
                
            case 'update_order':
                $track_id = intval($_POST['track_id']);
                $order = intval($_POST['order']);
                if ($order < 0 || $order > 999) {
                    $response = ['success' => false, 'error' => 'Invalid order value'];
                    break;
                }
                $stmt = $pdo->prepare("UPDATE music_tracks SET playlist_order = ? WHERE id = ?");
                $result = $stmt->execute([$order, $track_id]);
                if ($result) {
                    $response = ['success' => true, 'message' => 'Order updated'];
                } else {
                    $response = ['success' => false, 'error' => 'Database update failed'];
                }
                break;
                
            default:
                $response = ['success' => false, 'error' => 'Invalid action: ' . $_POST['playlist_action']];
        }
    } catch (Exception $e) {
        $response = ['success' => false, 'error' => 'Database error: ' . $e->getMessage()];
    }
    
    // Ensure clean output
    echo json_encode($response);
    exit;
}

// Optimize database performance (runs once per admin session)
if (!isset($_SESSION['db_optimized'])) {
    optimizeDatabasePerformance();
    $_SESSION['db_optimized'] = true;
}

// Cache cleanup disabled during development

$pdo = getDBConnection();

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

// Redirect to metadata resync tool if requested
if ($current_tab === 'metadata') {
    header('Location: admin_metadata_resync.php');
    exit;
}

// Get basic statistics
$overall_stats = $pdo->query("
    SELECT 
        COUNT(*) as total_tracks,
        COUNT(CASE WHEN status = 'complete' THEN 1 END) as completed,
        COUNT(CASE WHEN status = 'processing' THEN 1 END) as processing,
        COUNT(CASE WHEN status = 'failed' THEN 1 END) as failed
    FROM music_tracks
")->fetch();

$user_stats = $pdo->query("
    SELECT 
        COUNT(*) as total_users,
        COUNT(CASE WHEN is_admin = 1 THEN 1 END) as admin_users,
        SUM(credits) as total_credits
    FROM users
")->fetch();

// Database connection is already established
// Individual tab files will handle their own data queries

// Set page variables for header
$page_title = 'Admin Control Panel - SoundStudioPro';
$page_description = 'Simplified admin dashboard for system management';
$current_page = 'admin';

// 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">';
}
?>

<style>
    /* Admin Panel Styles */
    .admin-panel {
        background: linear-gradient(135deg, #0a0a0a 0%, #1a1a1a 100%);
        min-height: 100vh;
        padding: 2rem 0;
        margin-top: 8rem;
    }
    
    .admin-container {
        max-width: 1400px;
        margin: 0 auto;
        padding: 0 2rem;
    }
    
    .admin-header {
        text-align: center;
        margin-bottom: 3rem;
        color: white;
    }
    
    .admin-title {
        font-size: 4rem;
        font-weight: 900;
        margin-bottom: 1rem;
        background: linear-gradient(135deg, #667eea, #764ba2);
        -webkit-background-clip: text;
        -webkit-text-fill-color: transparent;
        background-clip: text;
    }
    
    .admin-subtitle {
        font-size: 1.8rem;
        color: #a0aec0;
    }
    
    .admin-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;
        flex-wrap: wrap;
    }
    
    .admin-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.8rem;
        white-space: nowrap;
    }
    
    .admin-tab:hover {
        color: white;
        background: rgba(255, 255, 255, 0.1);
        transform: translateY(-2px);
    }
    
    .admin-tab.active {
        background: linear-gradient(135deg, #667eea, #764ba2);
        color: white;
    }
    
    .admin-tab i {
        font-size: 1.6rem;
    }
    
    .tab-content {
        background: rgba(255, 255, 255, 0.05);
        border-radius: 16px;
        padding: 2rem;
        border: 1px solid rgba(255, 255, 255, 0.1);
        margin-bottom: 3rem;
    }
    
    .stats-grid {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
        gap: 2rem;
        margin-bottom: 3rem;
    }
    
    .stat-card {
        background: rgba(255, 255, 255, 0.05);
        border: 1px solid rgba(255, 255, 255, 0.1);
        border-radius: 16px;
        padding: 2rem;
        text-align: center;
        color: white;
    }
    
    .stat-number {
        font-size: 3rem;
        font-weight: 900;
        color: #667eea;
        margin-bottom: 0.5rem;
    }
    
    .stat-label {
        font-size: 1.4rem;
        color: #a0aec0;
    }
    
    .data-table {
        width: 100%;
        border-collapse: collapse;
        margin-top: 2rem;
    }
    
    .data-table th,
    .data-table td {
        padding: 1.5rem;
        text-align: left;
        border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    }
    
    .data-table th {
        background: rgba(255, 255, 255, 0.05);
        font-weight: 600;
        color: #667eea;
        font-size: 1.4rem;
    }
    
    .data-table td {
        color: #e2e8f0;
        font-size: 1.4rem;
    }
    
    .data-table tr:hover {
        background: rgba(255, 255, 255, 0.02);
    }
    
    .btn {
        display: inline-flex;
        align-items: center;
        gap: 0.8rem;
        padding: 1rem 2rem;
        border-radius: 8px;
        font-size: 1.4rem;
        font-weight: 600;
        text-decoration: none;
        transition: all 0.3s ease;
        border: none;
        cursor: pointer;
        margin: 0.5rem;
    }
    
    .btn-primary {
        background: linear-gradient(135deg, #667eea, #764ba2);
        color: white;
    }
    
    .btn-primary:hover {
        transform: translateY(-2px);
        box-shadow: 0 10px 20px rgba(102, 126, 234, 0.3);
    }
    
    .btn-secondary {
        background: rgba(255, 255, 255, 0.1);
        color: white;
        border: 1px solid rgba(255, 255, 255, 0.2);
    }
    
    .btn-secondary:hover {
        background: rgba(255, 255, 255, 0.2);
    }
    
    .btn-danger {
        background: linear-gradient(135deg, #f56565, #e53e3e);
        color: white;
    }
    
    .btn-danger:hover {
        transform: translateY(-2px);
        box-shadow: 0 10px 20px rgba(245, 101, 101, 0.3);
    }
    
    .btn-success {
        background: linear-gradient(135deg, #48bb78, #38a169);
        color: white;
    }
    
    .btn-success:hover {
        transform: translateY(-2px);
        box-shadow: 0 10px 20px rgba(72, 187, 120, 0.3);
    }
    
    .btn-warning {
        background: linear-gradient(135deg, #f59e0b, #d97706);
        color: white;
    }
    
    .btn-warning:hover {
        transform: translateY(-2px);
        box-shadow: 0 10px 20px rgba(245, 158, 11, 0.3);
    }
    
    .status-badge {
        padding: 0.4rem 1.2rem;
        border-radius: 20px;
        font-size: 1.2rem;
        font-weight: 600;
    }
    
    .status-complete {
        background: rgba(72, 187, 120, 0.2);
        color: #48bb78;
        border: 1px solid rgba(72, 187, 120, 0.3);
    }
    
    .status-processing {
        background: rgba(245, 158, 11, 0.2);
        color: #f59e0b;
        border: 1px solid rgba(245, 158, 11, 0.3);
    }
    
    .status-failed {
        background: rgba(245, 101, 101, 0.2);
        color: #f56565;
        border: 1px solid rgba(245, 101, 101, 0.3);
    }
    
    .status-admin {
        background: rgba(102, 126, 234, 0.2);
        color: #667eea;
        border: 1px solid rgba(102, 126, 234, 0.3);
    }
    
    .status-user {
        background: rgba(160, 174, 192, 0.2);
        color: #a0aec0;
        border: 1px solid rgba(160, 174, 192, 0.3);
    }
    
    .plan-badge {
        font-weight: 600;
    }
    
    .plan-free {
        background: rgba(160, 174, 192, 0.2);
        color: #a0aec0;
        border: 1px solid rgba(160, 174, 192, 0.3);
    }
    
    .plan-starter {
        background: rgba(72, 187, 120, 0.2);
        color: #48bb78;
        border: 1px solid rgba(72, 187, 120, 0.3);
    }
    
    .plan-pro {
        background: rgba(102, 126, 234, 0.2);
        color: #667eea;
        border: 1px solid rgba(102, 126, 234, 0.3);
    }
    
    .btn-sm {
        padding: 0.6rem 1rem;
        font-size: 1.2rem;
        margin: 0.2rem;
    }
    
    .action-buttons {
        display: flex;
        gap: 0.5rem;
        flex-wrap: wrap;
    }
    
    .search-input {
        width: 100%;
        max-width: 400px;
        padding: 1rem 1.5rem;
        background: rgba(255, 255, 255, 0.1);
        border: 1px solid rgba(255, 255, 255, 0.2);
        border-radius: 8px;
        color: white;
        font-size: 1.4rem;
        margin-bottom: 2rem;
    }
    
    .search-input::placeholder {
        color: #a0aec0;
    }
    
    .section-header {
        margin-bottom: 3rem;
    }
    
    .section-header h2 {
        font-size: 2.4rem;
        color: white;
        margin-bottom: 1rem;
        display: flex;
        align-items: center;
        gap: 1rem;
    }
    
    .section-header p {
        font-size: 1.4rem;
        color: #a0aec0;
    }
    
    /* Mobile tab selector */
    .admin-tabs-mobile {
        display: none;
    }
    
    .admin-tabs-mobile select {
        width: 100%;
        padding: 1.2rem 1.5rem;
        background: rgba(255, 255, 255, 0.1);
        border: 1px solid rgba(255, 255, 255, 0.2);
        border-radius: 12px;
        color: white;
        font-size: 1.6rem;
        font-weight: 600;
        cursor: pointer;
        appearance: none;
        background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
        background-repeat: no-repeat;
        background-position: right 1.5rem center;
        background-size: 20px;
        padding-right: 4rem;
    }
    
    .admin-tabs-mobile select option {
        background: #1a1a1a;
        color: white;
        padding: 1rem;
    }
    
    /* User card layout for mobile */
    .user-cards-mobile {
        display: none;
    }
    
    .user-card {
        background: rgba(255, 255, 255, 0.05);
        border: 1px solid rgba(255, 255, 255, 0.1);
        border-radius: 16px;
        padding: 1.5rem;
        margin-bottom: 1.5rem;
    }
    
    .user-card-header {
        display: flex;
        align-items: center;
        gap: 1rem;
        margin-bottom: 1rem;
        padding-bottom: 1rem;
        border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    }
    
    .user-card-avatar {
        width: 50px;
        height: 50px;
        background: linear-gradient(135deg, #667eea, #764ba2);
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        font-weight: bold;
        color: white;
        font-size: 1.8rem;
        flex-shrink: 0;
    }
    
    .user-card-info {
        flex: 1;
        min-width: 0;
    }
    
    .user-card-name {
        font-weight: 600;
        color: white;
        font-size: 1.6rem;
        margin-bottom: 0.3rem;
        word-break: break-word;
    }
    
    .user-card-email {
        color: #60a5fa;
        font-size: 1.3rem;
        word-break: break-all;
    }
    
    .user-card-details {
        display: flex;
        flex-direction: column;
        gap: 0.8rem;
        margin-bottom: 1.5rem;
    }
    
    .user-card-row {
        display: flex;
        justify-content: space-between;
        align-items: center;
        font-size: 1.3rem;
    }
    
    .user-card-label {
        color: #a0aec0;
    }
    
    .user-card-value {
        color: #e2e8f0;
        text-align: right;
        word-break: break-word;
        max-width: 60%;
    }
    
    .user-card-actions {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: 0.8rem;
        margin-top: 1rem;
    }
    
    .user-card-actions .btn {
        margin: 0;
        padding: 1rem;
        font-size: 1.3rem;
        min-height: 50px;
        justify-content: center;
    }
    
    @media (max-width: 768px) {
        .admin-panel {
            padding: 1rem 0;
            margin-top: 6rem;
        }
        
        .admin-container {
            padding: 0 1rem;
        }
        
        .admin-title {
            font-size: 2.8rem;
        }
        
        .admin-subtitle {
            font-size: 1.4rem;
        }
        
        /* Hide desktop tabs, show mobile selector */
        .admin-tabs {
            display: none;
        }
        
        .admin-tabs-mobile {
            display: block;
            margin-bottom: 2rem;
        }
        
        .tab-content {
            padding: 1.5rem;
            overflow-x: hidden;
        }
        
        .stats-grid {
            grid-template-columns: repeat(2, 1fr);
            gap: 1rem;
        }
        
        .stat-card {
            padding: 1.5rem;
        }
        
        .stat-number {
            font-size: 2.4rem;
        }
        
        .stat-label {
            font-size: 1.2rem;
        }
        
        /* Hide tables on mobile, show cards */
        .table-container {
            display: none;
        }
        
        .user-cards-mobile {
            display: block;
        }
        
        .data-table {
            display: none;
        }
        
        .action-buttons {
            display: flex;
            flex-wrap: wrap;
            gap: 0.5rem;
        }
        
        .btn-sm {
            padding: 0.6rem 1rem;
            font-size: 1.2rem;
            min-width: 44px;
            min-height: 44px;
        }
        
        .search-input {
            width: 100%;
            padding: 1.2rem;
            font-size: 1.6rem;
            margin-bottom: 1.5rem;
        }
    }
    
    @media (max-width: 480px) {
        .admin-title {
            font-size: 2.2rem;
        }
        
        .admin-tab {
            padding: 0.6rem 1rem;
            font-size: 1.1rem;
            min-width: 100%;
        }
        
        .stats-grid {
            grid-template-columns: 1fr;
        }
        
        .table-container {
            margin: 1rem -1rem;
            padding: 0 1rem;
            width: calc(100% + 2rem);
        }
        
        .table-container .data-table {
            min-width: 800px;
            font-size: 1.1rem;
        }
        
        .data-table th,
        .data-table td {
            padding: 0.8rem 0.6rem;
            font-size: 1.1rem;
        }
    }
</style>

<div class="admin-panel">
    <div class="admin-container">
        <div class="admin-header">
            <h1 class="admin-title">👑 Admin Control Panel</h1>
            <p class="admin-subtitle">Simplified system management dashboard</p>
        </div>
        
        <!-- Admin Tabs (Desktop) -->
        <div class="admin-tabs">
            <a href="?tab=dashboard" class="admin-tab <?= $current_tab === 'dashboard' ? 'active' : '' ?>">
                <i class="fas fa-tachometer-alt"></i>
                Dashboard
            </a>
            <a href="?tab=users" class="admin-tab <?= $current_tab === 'users' ? 'active' : '' ?>">
                <i class="fas fa-users"></i>
                User Management
            </a>
            <a href="?tab=user-accounts" class="admin-tab <?= $current_tab === 'user-accounts' ? 'active' : '' ?>">
                <i class="fas fa-list"></i>
                User Accounts List
            </a>
            <a href="?tab=tracks" class="admin-tab <?= $current_tab === 'tracks' ? 'active' : '' ?>">
                <i class="fas fa-music"></i>
                Track Management
            </a>
            <a href="?tab=playlists" class="admin-tab <?= $current_tab === 'playlists' ? 'active' : '' ?>">
                <i class="fas fa-list-music"></i>
                Playlist Management
            </a>
            <a href="?tab=orphaned" class="admin-tab <?= $current_tab === 'orphaned' ? 'active' : '' ?>">
                <i class="fas fa-exclamation-triangle"></i>
                Orphaned Tracks
            </a>
            <a href="?tab=analytics" class="admin-tab <?= $current_tab === 'analytics' ? 'active' : '' ?>">
                <i class="fas fa-chart-line"></i>
                Analytics
            </a>
            <a href="?tab=metadata" class="admin-tab <?= $current_tab === 'metadata' ? 'active' : '' ?>">
                <i class="fas fa-database"></i>
                Metadata Sync
            </a>
            <a href="?tab=missing-tracks" class="admin-tab <?= $current_tab === 'missing-tracks' ? 'active' : '' ?>">
                <i class="fas fa-download"></i>
                Sync Missing Tracks
            </a>
            <a href="?tab=track-status-verify" class="admin-tab <?= $current_tab === 'track-status-verify' ? 'active' : '' ?>">
                <i class="fas fa-check-circle"></i>
                Track Status Verify
            </a>
            <a href="admin_batch_analyze_tracks.php" class="admin-tab">
                <i class="fas fa-wave-square"></i>
                Batch Audio Analysis
            </a>
            <a href="?tab=system" class="admin-tab <?= $current_tab === 'system' ? 'active' : '' ?>">
                <i class="fas fa-server"></i>
                System
            </a>
            <a href="?tab=settings" class="admin-tab <?= $current_tab === 'settings' ? 'active' : '' ?>">
                <i class="fas fa-cog"></i>
                Settings
            </a>
            <a href="?tab=api" class="admin-tab <?= $current_tab === 'api' ? 'active' : '' ?>">
                <i class="fas fa-plug"></i>
                API
            </a>
            <a href="?tab=payment" class="admin-tab <?= $current_tab === 'payment' ? 'active' : '' ?>">
                <i class="fas fa-credit-card"></i>
                Payment
            </a>
            <a href="?tab=purchases" class="admin-tab <?= $current_tab === 'purchases' ? 'active' : '' ?>">
                <i class="fas fa-shopping-cart"></i>
                Purchases & Sales
            </a>
            <a href="?tab=purchase-validation" class="admin-tab <?= $current_tab === 'purchase-validation' ? 'active' : '' ?>">
                <i class="fas fa-shield-alt"></i>
                Purchase Validation
            </a>
            <a href="admin_purchase_tracker.php" class="admin-tab <?= $current_tab === 'purchase-tracker' ? 'active' : '' ?>">
                <i class="fas fa-search-dollar"></i>
                Purchase Tracker
            </a>
            <a href="?tab=social" class="admin-tab <?= $current_tab === 'social' ? 'active' : '' ?>">
                <i class="fas fa-share-alt"></i>
                Social Media
            </a>
            <a href="?tab=webhooks" class="admin-tab <?= $current_tab === 'webhooks' ? 'active' : '' ?>">
                <i class="fas fa-link"></i>
                Webhooks
            </a>
            <a href="?tab=api-logs" class="admin-tab <?= $current_tab === 'api-logs' ? 'active' : '' ?>">
                <i class="fas fa-list-alt"></i>
                API Logs
            </a>
            <a href="?tab=subscriptions" class="admin-tab <?= $current_tab === 'subscriptions' ? 'active' : '' ?>">
                <i class="fas fa-sync-alt"></i>
                Subscriptions
            </a>
            <a href="?tab=credits" class="admin-tab <?= $current_tab === 'credits' ? 'active' : '' ?>">
                <i class="fas fa-coins"></i>
                Credits Management
            </a>
            <a href="?tab=pricing" class="admin-tab <?= $current_tab === 'pricing' ? 'active' : '' ?>">
                <i class="fas fa-dollar-sign"></i>
                Pricing
            </a>
            <a href="?tab=site-settings" class="admin-tab <?= $current_tab === 'site-settings' ? 'active' : '' ?>">
                <i class="fas fa-cogs"></i>
                Site Settings
            </a>
            <a href="?tab=email" class="admin-tab <?= $current_tab === 'email' ? 'active' : '' ?>">
                <i class="fas fa-envelope"></i>
                Email Management
            </a>
            <a href="?tab=testing" class="admin-tab <?= $current_tab === 'testing' ? 'active' : '' ?>">
                <i class="fas fa-tools"></i>
                Testing Tools
            </a>
            <a href="?tab=image-compression" class="admin-tab <?= $current_tab === 'image-compression' ? 'active' : '' ?>">
                <i class="fas fa-compress"></i>
                Image Compression
            </a>
            <a href="?tab=variations-fix" class="admin-tab <?= $current_tab === 'variations-fix' ? 'active' : '' ?>">
                <i class="fas fa-layer-group"></i>
                Variations Fix
            </a>
            <a href="?tab=variations-diagnostic" class="admin-tab <?= $current_tab === 'variations-diagnostic' ? 'active' : '' ?>">
                <i class="fas fa-microscope"></i>
                Variations Diagnostic
            </a>
            <a href="?tab=security" class="admin-tab <?= $current_tab === 'security' ? 'active' : '' ?>">
                <i class="fas fa-shield-alt"></i>
                Security Overview
            </a>
            <a href="?tab=security-detailed" class="admin-tab <?= $current_tab === 'security-detailed' ? 'active' : '' ?>">
                <i class="fas fa-search"></i>
                Detailed Security
            </a>
            <a href="?tab=online-users" class="admin-tab <?= $current_tab === 'online-users' ? 'active' : '' ?>">
                <i class="fas fa-circle" style="color: #48bb78;"></i>
                Online Users
            </a>
        </div>
        
        <!-- Mobile Tab Selector -->
        <div class="admin-tabs-mobile">
            <select onchange="if (this.value === 'batch-analyze') { window.location.href = 'admin_batch_analyze_tracks.php'; } else if (this.value === 'purchase-tracker') { window.location.href = 'admin_purchase_tracker.php'; } else { window.location.href = '?tab=' + this.value; }">
                <option value="dashboard" <?= $current_tab === 'dashboard' ? 'selected' : '' ?>>📊 Dashboard</option>
                <option value="users" <?= $current_tab === 'users' ? 'selected' : '' ?>>👥 User Management</option>
                <option value="user-accounts" <?= $current_tab === 'user-accounts' ? 'selected' : '' ?>>📋 User Accounts List</option>
                <option value="tracks" <?= $current_tab === 'tracks' ? 'selected' : '' ?>>🎵 Track Management</option>
                <option value="playlists" <?= $current_tab === 'playlists' ? 'selected' : '' ?>>🎼 Playlist Management</option>
                <option value="orphaned" <?= $current_tab === 'orphaned' ? 'selected' : '' ?>>⚠️ Orphaned Tracks</option>
                <option value="analytics" <?= $current_tab === 'analytics' ? 'selected' : '' ?>>📈 Analytics</option>
                <option value="metadata" <?= $current_tab === 'metadata' ? 'selected' : '' ?>>💾 Metadata Sync</option>
                <option value="missing-tracks" <?= $current_tab === 'missing-tracks' ? 'selected' : '' ?>>⬇️ Sync Missing Tracks</option>
                <option value="track-status-verify" <?= $current_tab === 'track-status-verify' ? 'selected' : '' ?>>✅ Track Status Verify</option>
                <option value="batch-analyze" <?= $current_tab === 'batch-analyze' ? 'selected' : '' ?>>🎵 Batch Audio Analysis</option>
                <option value="system" <?= $current_tab === 'system' ? 'selected' : '' ?>>🖥️ System</option>
                <option value="settings" <?= $current_tab === 'settings' ? 'selected' : '' ?>>⚙️ Settings</option>
                <option value="api" <?= $current_tab === 'api' ? 'selected' : '' ?>>🔌 API</option>
                <option value="payment" <?= $current_tab === 'payment' ? 'selected' : '' ?>>💳 Payment</option>
                <option value="purchases" <?= $current_tab === 'purchases' ? 'selected' : '' ?>>🛒 Purchases & Sales</option>
                <option value="purchase-validation" <?= $current_tab === 'purchase-validation' ? 'selected' : '' ?>>🛡️ Purchase Validation</option>
                <option value="social" <?= $current_tab === 'social' ? 'selected' : '' ?>>📱 Social Media</option>
                <option value="webhooks" <?= $current_tab === 'webhooks' ? 'selected' : '' ?>>🔗 Webhooks</option>
                <option value="api-logs" <?= $current_tab === 'api-logs' ? 'selected' : '' ?>>📝 API Logs</option>
                <option value="subscriptions" <?= $current_tab === 'subscriptions' ? 'selected' : '' ?>>🔄 Subscriptions</option>
                <option value="pricing" <?= $current_tab === 'pricing' ? 'selected' : '' ?>>💰 Pricing</option>
                <option value="site-settings" <?= $current_tab === 'site-settings' ? 'selected' : '' ?>>🔧 Site Settings</option>
                <option value="email" <?= $current_tab === 'email' ? 'selected' : '' ?>>📧 Email Management</option>
                <option value="testing" <?= $current_tab === 'testing' ? 'selected' : '' ?>>🛠️ Testing Tools</option>
                <option value="image-compression" <?= $current_tab === 'image-compression' ? 'selected' : '' ?>>🗜️ Image Compression</option>
                <option value="variations-fix" <?= $current_tab === 'variations-fix' ? 'selected' : '' ?>>🎵 Variations Fix</option>
                <option value="security" <?= $current_tab === 'security' ? 'selected' : '' ?>>🔒 Security Overview</option>
                <option value="security-detailed" <?= $current_tab === 'security-detailed' ? 'selected' : '' ?>>🔍 Detailed Security</option>
                <option value="online-users" <?= $current_tab === 'online-users' ? 'selected' : '' ?>>🟢 Online Users</option>
                <option value="track-status-verify" <?= $current_tab === 'track-status-verify' ? 'selected' : '' ?>>✅ Track Status Verify</option>
                <option value="radio-live" <?= $current_tab === 'radio-live' ? 'selected' : '' ?>>📻 Live Radio Management</option>
            </select>
        </div>
        
        <!-- Tab Content -->
        <div class="tab-content">
            <?php if ($current_tab === 'dashboard'): ?>
                <?php include 'admin_includes/dashboard.php'; ?>
            <?php elseif ($current_tab === 'users'): ?>
                <?php include 'admin_includes/users.php'; ?>
            <?php elseif ($current_tab === 'user-accounts'): ?>
                <?php include 'admin_includes/user_accounts_list.php'; ?>
            <?php elseif ($current_tab === 'tracks'): ?>
                <?php include 'admin_includes/tracks.php'; ?>
            <?php elseif ($current_tab === 'playlists'): ?>
                <?php include 'admin_includes/playlists.php'; ?>
            <?php elseif ($current_tab === 'orphaned'): ?>
                <?php include 'admin_includes/orphaned_tracks.php'; ?>
            <?php elseif ($current_tab === 'analytics'): ?>
                <?php include 'admin_includes/analytics.php'; ?>
            <?php elseif ($current_tab === 'missing-tracks'): ?>
                <?php include 'admin/sync_missing_tracks.php'; ?>
            <?php elseif ($current_tab === 'system'): ?>
                <?php include 'admin_includes/system.php'; ?>
            <?php elseif ($current_tab === 'settings'): ?>
                <?php include 'admin_includes/settings.php'; ?>
            <?php elseif ($current_tab === 'api'): ?>
                <?php include 'admin_includes/api.php'; ?>
            <?php elseif ($current_tab === 'payment'): ?>
                <?php include 'admin_includes/payment.php'; ?>
            <?php elseif ($current_tab === 'purchases'): ?>
                <?php include 'admin_includes/purchases.php'; ?>
            <?php elseif ($current_tab === 'purchase-validation'): ?>
                <?php include 'admin_includes/purchase_validation.php'; ?>
            <?php elseif ($current_tab === 'social'): ?>
                <?php include 'admin_includes/social.php'; ?>
            <?php elseif ($current_tab === 'webhooks'): ?>
                <?php include 'admin_includes/webhooks.php'; ?>
            <?php elseif ($current_tab === 'api-logs'): ?>
                <?php include 'admin_includes/api-logs.php'; ?>
            <?php elseif ($current_tab === 'subscriptions'): ?>
                <?php include 'admin_includes/subscription_management.php'; ?>
            <?php elseif ($current_tab === 'credits'): ?>
                <?php include 'admin_includes/credits_management.php'; ?>
            <?php elseif ($current_tab === 'pricing'): ?>
                <?php include 'admin_includes/track_pricing.php'; ?>
            <?php elseif ($current_tab === 'site-settings'): ?>
                <?php include 'admin_includes/site_settings.php'; ?>
            <?php elseif ($current_tab === 'email'): ?>
                <?php include 'admin_includes/email_management.php'; ?>
            <?php elseif ($current_tab === 'testing'): ?>
                <?php include 'admin_includes/testing_tools.php'; ?>
            <?php elseif ($current_tab === 'image-compression'): ?>
                <?php include 'admin_includes/image_compression.php'; ?>
            <?php elseif ($current_tab === 'variations-fix'): ?>
                <?php include 'admin_includes/variations_fix.php'; ?>
            <?php elseif ($current_tab === 'variations-diagnostic'): ?>
                <?php include 'admin_includes/variations_diagnostic.php'; ?>
            <?php elseif ($current_tab === 'security'): ?>
                <?php include 'admin_includes/security_intelligence.php'; ?>
            <?php elseif ($current_tab === 'security-detailed'): ?>
                <?php include 'admin_includes/security_detailed.php'; ?>
            <?php elseif ($current_tab === 'online-users'): ?>
                
            <?php elseif ($current_tab === 'radio-live'): ?>
                <?php include 'admin_includes/radio_live.php'; ?><?php include 'admin_includes/online_users.php'; ?>
            <?php elseif ($current_tab === 'track-status-verify'): ?>
                <?php include 'admin_includes/track_status_verify.php'; ?>
            <?php endif; ?>
        </div>
    </div>
</div>

<script>
    // User search functionality
    document.getElementById('userSearch')?.addEventListener('input', function() {
        const query = this.value.toLowerCase();
        const rows = document.querySelectorAll('.data-table tbody tr');
        
        rows.forEach(row => {
            const text = row.textContent.toLowerCase();
            row.style.display = text.includes(query) ? '' : 'none';
        });
    });
    
    // Track search functionality
    document.getElementById('trackSearch')?.addEventListener('input', function() {
        const query = this.value.toLowerCase();
        const rows = document.querySelectorAll('.data-table tbody tr');
        
        rows.forEach(row => {
            const text = row.textContent.toLowerCase();
            row.style.display = text.includes(query) ? '' : 'none';
        });
    });
    
    // Enhanced admin functions
    function editUser(userId) {
        console.log('🎵 editUser called with userId:', userId);
        
        // Open user edit modal
        const userRow = document.querySelector(`tr[data-user-id="${userId}"]`);
        if (!userRow) {
            console.error('❌ User row not found for ID:', userId);
            alert('User not found');
            return;
        }
        
        const userName = userRow.querySelector('.user-name').textContent;
        const userEmail = userRow.querySelector('.user-email').textContent;
        const userCredits = userRow.querySelector('.user-credits').textContent;
        
        console.log('🎵 User data:', { userName, userEmail, userCredits });
        
        const newCredits = prompt(`Edit credits for ${userName} (${userEmail}):`, userCredits.replace(' Credits', ''));
        
        console.log('🎵 New credits value:', newCredits);
        
        if (newCredits !== null && !isNaN(newCredits)) {
            console.log('🎵 Sending API request...');
            
            // Send AJAX request to update user
            fetch(`admin_api.php?action=update_user&user_id=${userId}&credits=${newCredits}`)
                .then(response => {
                    console.log('🎵 API response status:', response.status);
                    return response.json();
                })
                .then(data => {
                    console.log('🎵 API response data:', data);
                    if (data.success) {
                        alert('User updated successfully!');
                        location.reload();
                    } else {
                        alert('Error updating user: ' + data.error);
                    }
                })
                .catch(error => {
                    console.error('❌ API error:', error);
                    alert('Error updating user: ' + error);
                });
        } else {
            console.log('🎵 User cancelled or invalid input');
        }
    }
    
    function loginAsUser(userId) {
        if (confirm('Are you sure you want to login as this user? This will log you out of admin mode.')) {
            fetch(`admin_api.php?action=login_as_user&user_id=${userId}`)
                .then(response => response.json())
                .then(data => {
                    if (data.success) {
                        // Use AJAX navigation to preserve global player
                if (window.ajaxNavigation) {
                    window.ajaxNavigation.navigateToPage('/library.php');
                } else {
                    window.location.href = '/library.php';
                }
                    } else {
                        alert('Error logging in as user: ' + data.error);
                    }
                })
                .catch(error => {
                    alert('Error logging in as user: ' + error);
                });
        }
    }
    
    function makeAdmin(userId) {
        if (confirm('Are you sure you want to make this user an admin?')) {
            fetch(`admin_api.php?action=make_admin&user_id=${userId}`)
                .then(response => response.json())
                .then(data => {
                    if (data.success) {
                        alert('User is now an admin!');
                        location.reload();
                    } else {
                        alert('Error making user admin: ' + data.error);
                    }
                })
                .catch(error => {
                    alert('Error making user admin: ' + error);
                });
        }
    }
    
    function removeAdmin(userId) {
        if (confirm('Are you sure you want to remove admin privileges from this user?')) {
            fetch(`admin_api.php?action=remove_admin&user_id=${userId}`)
                .then(response => response.json())
                .then(data => {
                    if (data.success) {
                        alert('Admin privileges removed!');
                        location.reload();
                    } else {
                        alert('Error removing admin privileges: ' + data.error);
                    }
                })
                .catch(error => {
                    alert('Error removing admin privileges: ' + error);
                });
        }
    }
    
    function deleteUser(userId) {
        fetch(`admin_api.php?action=delete_user&user_id=${userId}`)
            .then(response => response.json())
            .then(data => {
                if (data.success) {
                    alert('User deleted successfully!');
                    location.reload();
                } else {
                    alert('Error deleting user: ' + data.error);
                }
            })
            .catch(error => {
                alert('Error deleting user: ' + error);
            });
    }
    
    function playTrack(trackId) {
        alert(`Playing track ${trackId} - Feature coming soon!`);
    }
    
    function editTrack(trackId) {
        alert(`Edit track ${trackId} - Feature coming soon!`);
    }
    
    // deleteTrack function is defined in admin_includes/tracks.php
    // Do not override it here - it makes proper API calls
    
    function changePassword(userId, userEmail) {
        const newPassword = prompt(`Enter new password for ${userEmail}:`);
        if (newPassword === null) {
            return; // User cancelled
        }
        
        if (newPassword.length < 6) {
            alert('Password must be at least 6 characters long');
            return;
        }
        
        if (confirm(`Are you sure you want to change the password for ${userEmail}?`)) {
            fetch(`admin_api.php?action=change_password&user_id=${userId}`, {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/x-www-form-urlencoded',
                },
                body: `new_password=${encodeURIComponent(newPassword)}`
            })
            .then(response => response.json())
            .then(data => {
                if (data.success) {
                    alert('Password changed successfully!');
                    location.reload();
                } else {
                    alert('Error changing password: ' + data.error);
                }
            })
            .catch(error => {
                alert('Error changing password: ' + error);
            });
        }
    }
    
    function upgradeToPro(userId, userEmail) {
        if (confirm(`Upgrade ${userEmail} to Pro plan?`)) {
            fetch(`admin_api.php?action=upgrade_to_pro&user_id=${userId}`)
            .then(response => response.json())
            .then(data => {
                if (data.success) {
                    alert('User upgraded to Pro plan successfully!');
                    location.reload();
                } else {
                    alert('Error upgrading user: ' + data.error);
                }
            })
            .catch(error => {
                alert('Error upgrading user: ' + error);
            });
        }
    }
</script>

<?php 
// Ensure $is_ajax is defined
if (!isset($is_ajax)) {
    $is_ajax = false;
}

// Include footer only for full page loads
if (!$is_ajax) {
    include 'includes/footer.php';
} else {
    // For AJAX requests, close the container
    echo '</div>';
}
?> 

CasperSecurity Mini