prepare('SELECT * FROM communities WHERE id = ?'); $stmt->execute([$community_id]); $community = $stmt->fetch(); if (!$community) { echo "Community not found."; exit; } // Fetch user role $stmt = $pdo->prepare('SELECT role FROM users WHERE id = ?'); $stmt->execute([$user_id]); $user_role = $stmt->fetchColumn(); if ($_SERVER['REQUEST_METHOD'] === 'POST') { if (!empty($_POST['title']) && !empty($_POST['description'])) { $title = $_POST['title']; $description = $_POST['description']; $end_time = !empty($_POST['end_time']) ? date('Y-m-d H:i:s', strtotime($_POST['end_time'])) : date('Y-m-d H:i:s', strtotime('+7 days')); try { $stmt = $pdo->prepare("INSERT INTO proposals (user_id, community_id, title, description, end_time) VALUES (?, ?, ?, ?, ?)"); $stmt->execute([$user_id, $community_id, $title, $description, $end_time]); // Send email notification require_once __DIR__ . '/mail/MailService.php'; $user_stmt = $pdo->prepare('SELECT email, name FROM users WHERE id = ?'); $user_stmt->execute([$user_id]); $user = $user_stmt->fetch(); if ($user) { $to = $user['email']; $subject = "Proposal Created: " . $title; $html_content = "
Title: {$title}
Community: {$community['name']}
"; $text_content = "Your new proposal '{$title}' has been created in the community '{$community['name']}'."; MailService::sendMail($to, $subject, $html_content, $text_content); } header("Location: proposals.php?community_id=$community_id"); exit; } catch (PDOException $e) { echo "Error: " . $e->getMessage(); exit; } } else { echo "Title and description are required."; exit; } } ?>