prepare('SELECT * FROM communities WHERE id = ?'); $stmt->execute([$community_id]); $community = $stmt->fetch(); if (!$community) { header('Location: communities.php'); exit; } // Fetch user role $stmt = $pdo->prepare('SELECT role FROM users WHERE id = ?'); $stmt->execute([$user_id]); $user_role = $stmt->fetchColumn(); // Handle new proposal form submission $title = $description = $end_time = ''; $errors = []; if ($_SERVER['REQUEST_METHOD'] === 'POST' && $user_role === 'leader') { $title = trim($_POST['title'] ?? ''); $description = trim($_POST['description'] ?? ''); $end_time = trim($_POST['end_time'] ?? ''); if (empty($title)) { $errors[] = 'Title is required'; } if (empty($description)) { $errors[] = 'Description is required'); } if (empty($end_time)) { $errors[] = 'End time is required'; } if (empty($errors)) { try { $stmt = $pdo->prepare('INSERT INTO proposals (community_id, user_id, title, description, end_time) VALUES (?, ?, ?, ?, ?)'); $stmt->execute([$community_id, $user_id, $title, $description, $end_time]); header('Location: proposals.php?community_id=' . $community_id); exit; } catch (PDOException $e) { $errors[] = 'Database error: ' . $e->getMessage(); } } } // Fetch proposals $stmt = $pdo->prepare('SELECT p.*, u.name as user_name FROM proposals p JOIN users u ON p.user_id = u.id WHERE p.community_id = ? ORDER BY p.created_at DESC'); $stmt->execute([$community_id]); $proposals = $stmt->fetchAll(); ?> <?php echo htmlspecialchars($community['name']); ?> Proposals - Community Hub

Proposals in

Create a New Proposal

Active Proposals

No proposals yet. Be the first to create one!

Ends

Created by: