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/.cursor-server/data/User/History/1d523740/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/gositeme/.cursor-server/data/User/History/1d523740/s65Z.php
<?php
// Error handling
error_reporting(E_ALL);
ini_set('display_errors', 0);
ini_set('log_errors', 1);

register_shutdown_function(function() {
    $error = error_get_last();
    if ($error && in_array($error['type'], [E_ERROR, E_PARSE, E_CORE_ERROR, E_COMPILE_ERROR])) {
        error_log("Fatal error in catalog/index.php: " . $error['message']);
        http_response_code(500);
        echo '<!DOCTYPE html><html><head><title>Error</title></head><body style="font-family: Arial; padding: 2rem; text-align: center;"><h1>Something went wrong</h1><p>Please try again later.</p><a href="/radio/dashboard/">Go to Dashboard</a></body></html>';
        exit;
    }
});

session_start();

try {
    require_once __DIR__ . '/../../config/database.php';
    require_once __DIR__ . '/../includes/functions.php';
} catch (Exception $e) {
    error_log("Error loading dependencies in catalog/index.php: " . $e->getMessage());
    http_response_code(500);
    die('Error loading page. Please contact support.');
}

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

$station_id = $_SESSION['radio_station_id'];

try {
    $station = getRadioStation($station_id);
    
    if (!$station) {
        session_destroy();
        header('Location: /radio/login.php');
        exit;
    }
    
    $pdo = getDBConnection();
    
    if (!$pdo) {
        throw new Exception("Database connection failed");
    }
} catch (Exception $e) {
    error_log("Error in catalog/index.php: " . $e->getMessage());
    http_response_code(500);
    die('Error loading catalog. Please try again later.');
}

// Get search parameters
$search = $_GET['search'] ?? '';
$genre = $_GET['genre'] ?? '';
$page = max(1, (int)($_GET['page'] ?? 1));
$limit = 50;
$offset = ($page - 1) * $limit;

// Initialize defaults
$total = 0;
$tracks = [];
$genres = [];

try {
    // Build query - make radio_enabled optional (check if column exists)
    // If radio_enabled column doesn't exist, don't filter by it
    $where = [];
    $params = [];
    
    // Check if radio_enabled column exists
    $check_radio_enabled = false;
    try {
        $pdo->query("SELECT radio_enabled FROM music_tracks LIMIT 1");
        $check_radio_enabled = true;
    } catch (PDOException $e) {
        // Column doesn't exist, skip this filter
    }
    
    // Only filter by radio_enabled if column exists AND we want to filter
    // For now, show all complete tracks (radio_enabled is optional)
    if ($check_radio_enabled) {
        // Show tracks that are either radio_enabled OR don't have the flag set (NULL)
        $where[] = '(radio_enabled = 1 OR radio_enabled IS NULL)';
    }
    
    // Only show complete tracks
    $where[] = 'status = "complete"';

    if ($search) {
        $where[] = '(title LIKE ? OR artist_name LIKE ?)';
        $search_term = '%' . $search . '%';
        $params[] = $search_term;
        $params[] = $search_term;
    }

    if ($genre) {
        $where[] = 'genre = ?';
        $params[] = $genre;
    }

    $where_sql = implode(' AND ', $where);

    // Get total
    $count_stmt = $pdo->prepare("SELECT COUNT(*) FROM music_tracks WHERE $where_sql");
    $count_stmt->execute($params);
    $total = $count_stmt->fetchColumn();

    // Get tracks
    $sql = "SELECT 
        id, title, artist_name, genre, bpm, duration, 
        audio_url, radio_play_count
        FROM music_tracks 
        WHERE $where_sql
        ORDER BY created_at DESC
        LIMIT ? OFFSET ?";

    $stmt = $pdo->prepare($sql);
    $params[] = $limit;
    $params[] = $offset;
    $stmt->execute($params);
    $tracks = $stmt->fetchAll(PDO::FETCH_ASSOC);

    // Get unique genres for filter (don't require radio_enabled)
    $genre_stmt = $pdo->query("SELECT DISTINCT genre FROM music_tracks WHERE status = 'complete' AND genre IS NOT NULL ORDER BY genre");
    $genres = $genre_stmt->fetchAll(PDO::FETCH_COLUMN);
} catch (PDOException $e) {
    error_log("Database error in catalog: " . $e->getMessage());
    // Continue with empty results rather than crashing
    $tracks = [];
    $genres = [];
    $total = 0;
}

$page_title = 'Music Catalog - ' . htmlspecialchars($station['station_name']);
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><?= $page_title ?></title>
    <link rel="stylesheet" href="/assets/css/main.css">
    <style>
        .catalog-page {
            max-width: 1200px;
            margin: 2rem auto;
            padding: 2rem;
        }
        .search-filters {
            background: white;
            padding: 1.5rem;
            border-radius: 8px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
            margin-bottom: 2rem;
        }
        .filters-row {
            display: grid;
            grid-template-columns: 2fr 1fr auto;
            gap: 1rem;
            align-items: end;
        }
        .form-group {
            margin-bottom: 0;
        }
        .form-group label {
            display: block;
            margin-bottom: 0.5rem;
            font-weight: 600;
        }
        .form-group input,
        .form-group select {
            width: 100%;
            padding: 0.75rem;
            border: 1px solid #ddd;
            border-radius: 4px;
        }
        .btn-primary {
            background: #667eea;
            color: white;
            padding: 0.75rem 2rem;
            border: none;
            border-radius: 4px;
            cursor: pointer;
        }
        .tracks-grid {
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
            gap: 1.5rem;
        }
        .track-card {
            background: white;
            padding: 1rem;
            border-radius: 8px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
        }
        .track-card h3 {
            margin: 0 0 0.5rem 0;
            font-size: 1rem;
        }
        .track-card .artist {
            color: #666;
            font-size: 0.9rem;
        }
        .track-card .meta {
            margin-top: 0.5rem;
            font-size: 0.85rem;
            color: #999;
        }
        .pagination {
            margin-top: 2rem;
            text-align: center;
        }
        .pagination a {
            display: inline-block;
            padding: 0.5rem 1rem;
            margin: 0 0.25rem;
            background: #667eea;
            color: white;
            text-decoration: none;
            border-radius: 4px;
        }
    </style>
</head>
<body>
    <?php 
    // Try to include header, but don't fail if it doesn't exist
    $header_path = __DIR__ . '/../../includes/header.php';
    if (file_exists($header_path)) {
        try {
            include $header_path;
        } catch (Exception $e) {
            error_log("Header include error: " . $e->getMessage());
            // Fallback minimal header
            echo '<header style="padding: 1rem; background: rgba(102, 126, 234, 0.1);"><a href="/" style="color: #667eea; text-decoration: none; font-weight: 600;">SoundStudioPro</a> | <a href="/radio/dashboard/" style="color: #667eea; text-decoration: none;">Dashboard</a></header>';
        }
    } else {
        // Fallback minimal header
        echo '<header style="padding: 1rem; background: rgba(102, 126, 234, 0.1);"><a href="/" style="color: #667eea; text-decoration: none; font-weight: 600;">SoundStudioPro</a> | <a href="/radio/dashboard/" style="color: #667eea; text-decoration: none;">Dashboard</a></header>';
    }
    ?>
    
    <div class="catalog-page">
        <h1>Music Catalog</h1>
        
        <div class="search-filters">
            <form method="GET">
                <div class="filters-row">
                    <div class="form-group">
                        <label>Search</label>
                        <input type="text" name="search" value="<?= htmlspecialchars($search) ?>" placeholder="Search tracks...">
                    </div>
                    
                    <div class="form-group">
                        <label>Genre</label>
                        <select name="genre">
                            <option value="">All Genres</option>
                            <?php foreach ($genres as $g): ?>
                                <option value="<?= htmlspecialchars($g) ?>" <?= $genre === $g ? 'selected' : '' ?>>
                                    <?= htmlspecialchars($g) ?>
                                </option>
                            <?php endforeach; ?>
                        </select>
                    </div>
                    
                    <button type="submit" class="btn-primary">Search</button>
                </div>
            </form>
        </div>
        
        <div class="tracks-grid">
            <?php foreach ($tracks as $track): ?>
            <div class="track-card">
                <h3><?= htmlspecialchars($track['title']) ?></h3>
                <div class="artist"><?= htmlspecialchars($track['artist_name'] ?? 'Unknown') ?></div>
                <div class="meta">
                    <?php if ($track['genre']): ?>
                        <?= htmlspecialchars($track['genre']) ?>
                    <?php endif; ?>
                    <?php if ($track['bpm']): ?>
                        • <?= $track['bpm'] ?> BPM
                    <?php endif; ?>
                    <?php if ($track['duration']): ?>
                        • <?= gmdate('i:s', $track['duration']) ?>
                    <?php endif; ?>
                </div>
                <div class="meta" style="margin-top: 0.5rem;">
                    <small>Radio plays: <?= number_format($track['radio_play_count']) ?></small>
                </div>
            </div>
            <?php endforeach; ?>
        </div>
        
        <?php if ($total > $limit): ?>
        <div class="pagination">
            <?php if ($page > 1): ?>
                <a href="?page=<?= $page - 1 ?>&search=<?= urlencode($search) ?>&genre=<?= urlencode($genre) ?>">Previous</a>
            <?php endif; ?>
            
            <span>Page <?= $page ?> of <?= ceil($total / $limit) ?></span>
            
            <?php if ($page < ceil($total / $limit)): ?>
                <a href="?page=<?= $page + 1 ?>&search=<?= urlencode($search) ?>&genre=<?= urlencode($genre) ?>">Next</a>
            <?php endif; ?>
        </div>
        <?php endif; ?>
        
        <?php if (empty($tracks) && !empty($search)): ?>
            <div style="text-align: center; padding: 3rem; background: white; border-radius: 8px; box-shadow: 0 2px 10px rgba(0,0,0,0.1);">
                <p>No tracks found matching your search.</p>
                <a href="/radio/catalog/" style="color: #667eea; text-decoration: none;">View All Tracks</a>
            </div>
        <?php elseif (empty($tracks)): ?>
            <div style="text-align: center; padding: 3rem; background: white; border-radius: 8px; box-shadow: 0 2px 10px rgba(0,0,0,0.1);">
                <p>No tracks available in the catalog yet.</p>
            </div>
        <?php endif; ?>
    </div>
    
    <?php 
    // Try to include footer, but don't fail if it doesn't exist
    $footer_path = __DIR__ . '/../../includes/footer.php';
    if (file_exists($footer_path)) {
        try {
            include $footer_path;
        } catch (Exception $e) {
            error_log("Footer include error: " . $e->getMessage());
        }
    }
    ?>
</body>
</html>


CasperSecurity Mini