36274-vm/collaborate.php
Flatlogic Bot 76b95bec18 v1
2025-11-25 15:04:51 +00:00

117 lines
5.1 KiB
PHP

<?php
require_once 'auth.php';
require_once 'db/config.php';
$pageTitle = "Collaborate - Zeal Music";
$pdo = db();
$errors = [];
$successMessage = '';
// Handle new post submission
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'create') {
$title = trim($_POST['title'] ?? '');
$description = trim($_POST['description'] ?? '');
if (empty($title) || empty($description)) {
$errors[] = "Title and description are required.";
} else {
try {
$stmt = $pdo->prepare("INSERT INTO collaborations (user_id, title, description) VALUES (?, ?, ?)");
$stmt->execute([$_SESSION['user_id'], $title, $description]);
$successMessage = "Your collaboration post has been created!";
} catch (PDOException $e) {
$errors[] = "Database error: " . $e->getMessage();
}
}
}
// Fetch all open collaboration posts
$collaborations = [];
try {
$stmt = $pdo->query("SELECT c.id, c.title, c.description, c.created_at, u.username FROM collaborations c JOIN users u ON c.user_id = u.id WHERE c.status = 'open' ORDER BY c.created_at DESC");
$collaborations = $stmt->fetchAll(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
$errors[] = "Error fetching collaboration posts: " . $e->getMessage();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><?php echo htmlspecialchars($pageTitle); ?></title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
<style>
.collab-post { background-color: #181818; border-radius: 8px; padding: 20px; margin-bottom: 20px; border: 1px solid #282828; }
.collab-post h3 { font-size: 1.3rem; margin-bottom: 10px; color: #1DB954; }
.collab-post .post-meta { font-size: 0.9rem; color: #b3b3b3; margin-bottom: 15px; }
.collab-post p { color: #e0e0e0; }
</style>
</head>
<body class="dark-theme">
<div class="page-container">
<?php include 'partials/sidebar.php'; ?>
<main class="main-content">
<header class="main-header">
<h1>Collaboration Feed</h1>
<div class="user-profile">
<i class="fa fa-user-circle"></i>
<span><?php echo htmlspecialchars($_SESSION['username']); ?></span>
</div>
</header>
<div class="content-wrapper">
<?php if ($successMessage) echo "<div class='alert alert-success'>".htmlspecialchars($successMessage)."</div>"; ?>
<?php foreach ($errors as $error) echo "<div class='alert alert-danger'>".htmlspecialchars($error)."</div>"; ?>
<!-- Create New Post Form -->
<div class="content-card mb-4">
<h2>Create a New Collaboration Post</h2>
<form action="collaborate.php" method="POST" class="upload-form" style="max-width: none;">
<input type="hidden" name="action" value="create">
<div class="form-group">
<label for="title">Title</label>
<input type="text" id="title" name="title" placeholder="E.g., 'Vocalist needed for a pop track'" required>
</div>
<div class="form-group">
<label for="description">Description</label>
<textarea id="description" name="description" rows="4" placeholder="Describe the project, what you're looking for, and include links to demos if you have them." required></textarea>
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary">Post Collaboration</button>
</div>
</form>
</div>
<!-- Collaboration Feed -->
<div class="content-card">
<h2>Open Collaborations</h2>
<?php if (empty($collaborations)):
?>
<p style="text-align: center; color: #b3b3b3; padding: 20px;">No open collaborations at the moment. Why not start one?</p>
<?php else:
foreach ($collaborations as $collab):
?>
<div class="collab-post">
<h3><?php echo htmlspecialchars($collab['title']); ?></h3>
<div class="post-meta">
Posted by <strong><?php echo htmlspecialchars($collab['username']); ?></strong> on <?php echo date("F j, Y", strtotime($collab['created_at'])); ?>
</div>
<p><?php echo nl2br(htmlspecialchars($collab['description'])); ?></p>
</div>
<?php
endforeach;
endif; ?>
</div>
</div>
</main>
</div>
<style>
textarea { width: 100%; padding: 12px 15px; background-color: #282828; border: 1px solid #404040; border-radius: 4px; color: #FFFFFF; font-size: 1rem; font-family: inherit; }
</style>
</body>
</html>