diff --git a/assets/css/custom.css b/assets/css/custom.css new file mode 100644 index 0000000..2f3d681 --- /dev/null +++ b/assets/css/custom.css @@ -0,0 +1,122 @@ + +body { + background-color: #121212; + background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='100' height='100' viewBox='0 0 100 100'%3E%3Cg fill='%231a1a1a' fill-opacity='0.4'%3E%3Crect x='0' y='0' width='100' height='1'/%3E%3Crect x='0' y='0' width='1' height='100'/%3E%3C/g%3E%3C/svg%3E"); + color: #FFFFFF; + font-family: 'Roboto', sans-serif; +} + +.card-neon { + background: rgba(255, 255, 255, 0.05); + backdrop-filter: blur(10px); + -webkit-backdrop-filter: blur(10px); + border: 1px solid rgba(255, 255, 255, 0.2); + border-radius: 16px; + box-shadow: 0 4px 30px rgba(0, 0, 0, 0.1); + transition: background 0.3s ease, box-shadow 0.3s ease; +} + +.card-neon:hover { + background: rgba(255, 255, 255, 0.1); + box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2); +} + +/* Typography */ +h1, h2, h3, h4, h5 { + font-family: 'Poppins', sans-serif; + font-weight: 700; +} + +h1 { + font-size: 3rem; +} + +h2 { + font-size: 2.25rem; +} + +/* Animations */ +.card-neon { + animation: fadeIn 0.5s ease-in-out; +} + +@keyframes fadeIn { + from { + opacity: 0; + transform: translateY(20px); + } + to { + opacity: 1; + transform: translateY(0); + } +} + +.btn-primary:hover, +.btn-secondary:hover, +.list-group-item-action:hover { + transform: translateY(-3px); + transition: transform 0.3s ease; +} + +.hero { + background: linear-gradient(rgba(0, 0, 0, 0.7), rgba(0, 0, 0, 0.7)), url('https://images.pexels.com/photos/159888/pexels-photo-159888.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1'); + background-size: cover; + background-position: center; + color: white; + padding: 100px 0; + text-align: center; +} + +.hero h1 { + font-family: 'Poppins', sans-serif; + font-weight: 700; + font-size: 3.5rem; +} + +.hero p { + font-size: 1.25rem; + margin-bottom: 30px; +} + +.btn-primary { + background: linear-gradient(45deg, #FF4B2B, #FF416C); + border: none; + padding: 15px 30px; + font-size: 1.2rem; + font-weight: 600; + transition: transform 0.3s ease; +} + +.btn-primary:hover { + transform: translateY(-3px); +} + +.btn-secondary { + background-color: transparent; + border: 2px solid white; + padding: 15px 30px; + font-size: 1.2rem; + font-weight: 600; + color: white; + transition: background-color 0.3s ease, color 0.3s ease; +} + +.btn-secondary:hover { + background-color: white; + color: #121212; +} + +.features { + padding: 80px 0; +} + +.feature-icon { + font-size: 3rem; + color: #FF4B2B; +} + +.footer { + background-color: #1E1E1E; + padding: 40px 0; + color: #A0A0A0; +} diff --git a/communities.php b/communities.php new file mode 100644 index 0000000..5d8e791 --- /dev/null +++ b/communities.php @@ -0,0 +1,77 @@ + +query('SELECT * FROM communities ORDER BY name'); +$communities = $stmt->fetchAll(); + +?> + + + + + + Communities - Community Hub + + + + + + + + +
+
+

Welcome to the Communities Page

+
+ +
+
+
+
+

Explore and engage with your local community.

+ +
+
+
+ +
+
+
+ + + + + + + + \ No newline at end of file diff --git a/db/migrate.php b/db/migrate.php new file mode 100644 index 0000000..85fb952 --- /dev/null +++ b/db/migrate.php @@ -0,0 +1,22 @@ +exec($sql); + echo "Migration successful: " . basename($file) . "\n"; + } catch (PDOException $e) { + echo "Migration failed for " . basename($file) . ": " . $e->getMessage() . "\n"; + } + } +} + +run_migrations(); + diff --git a/db/migrations/001_create_users_table.sql b/db/migrations/001_create_users_table.sql new file mode 100644 index 0000000..2c708a1 --- /dev/null +++ b/db/migrations/001_create_users_table.sql @@ -0,0 +1,10 @@ + +CREATE TABLE IF NOT EXISTS `users` ( + `id` INT AUTO_INCREMENT PRIMARY KEY, + `name` VARCHAR(255) NOT NULL, + `email` VARCHAR(255) NOT NULL UNIQUE, + `password` VARCHAR(255) NOT NULL, + `city` VARCHAR(255) NOT NULL, + `role` ENUM('member', 'leader') NOT NULL DEFAULT 'member', + `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP +); diff --git a/db/migrations/002_create_communities_table.sql b/db/migrations/002_create_communities_table.sql new file mode 100644 index 0000000..2809b26 --- /dev/null +++ b/db/migrations/002_create_communities_table.sql @@ -0,0 +1,8 @@ + +CREATE TABLE IF NOT EXISTS `communities` ( + `id` INT AUTO_INCREMENT PRIMARY KEY, + `name` VARCHAR(255) NOT NULL UNIQUE, + `leader_id` INT NOT NULL, + `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + FOREIGN KEY (`leader_id`) REFERENCES `users`(`id`) +); diff --git a/db/migrations/003_create_community_members_table.sql b/db/migrations/003_create_community_members_table.sql new file mode 100644 index 0000000..b5aa922 --- /dev/null +++ b/db/migrations/003_create_community_members_table.sql @@ -0,0 +1,9 @@ + +CREATE TABLE IF NOT EXISTS `community_members` ( + `id` INT AUTO_INCREMENT PRIMARY KEY, + `user_id` INT NOT NULL, + `community_id` INT NOT NULL, + `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + FOREIGN KEY (`user_id`) REFERENCES `users`(`id`), + FOREIGN KEY (`community_id`) REFERENCES `communities`(`id`) +); diff --git a/db/migrations/004_create_discussions_table.sql b/db/migrations/004_create_discussions_table.sql new file mode 100644 index 0000000..ae61840 --- /dev/null +++ b/db/migrations/004_create_discussions_table.sql @@ -0,0 +1,21 @@ + +CREATE TABLE IF NOT EXISTS `discussions` ( + `id` INT AUTO_INCREMENT PRIMARY KEY, + `community_id` INT NOT NULL, + `user_id` INT NOT NULL, + `title` VARCHAR(255) NOT NULL, + `content` TEXT NOT NULL, + `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + FOREIGN KEY (`community_id`) REFERENCES `communities`(`id`), + FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) +); + +CREATE TABLE IF NOT EXISTS `discussion_replies` ( + `id` INT AUTO_INCREMENT PRIMARY KEY, + `discussion_id` INT NOT NULL, + `user_id` INT NOT NULL, + `content` TEXT NOT NULL, + `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + FOREIGN KEY (`discussion_id`) REFERENCES `discussions`(`id`), + FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) +); diff --git a/db/migrations/005_create_proposals_table.sql b/db/migrations/005_create_proposals_table.sql new file mode 100644 index 0000000..02053f9 --- /dev/null +++ b/db/migrations/005_create_proposals_table.sql @@ -0,0 +1,24 @@ + +CREATE TABLE IF NOT EXISTS `proposals` ( + `id` INT AUTO_INCREMENT PRIMARY KEY, + `community_id` INT NOT NULL, + `user_id` INT NOT NULL, + `title` VARCHAR(255) NOT NULL, + `description` TEXT NOT NULL, + `end_time` TIMESTAMP NOT NULL, + `status` ENUM('active', 'resolved') NOT NULL DEFAULT 'active', + `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + FOREIGN KEY (`community_id`) REFERENCES `communities`(`id`), + FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) +); + +CREATE TABLE IF NOT EXISTS `proposal_votes` ( + `id` INT AUTO_INCREMENT PRIMARY KEY, + `proposal_id` INT NOT NULL, + `user_id` INT NOT NULL, + `vote` ENUM('up', 'down') NOT NULL, + `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + UNIQUE KEY `user_proposal_vote` (`user_id`, `proposal_id`), + FOREIGN KEY (`proposal_id`) REFERENCES `proposals`(`id`), + FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) +); diff --git a/db/migrations/006_create_events_table.sql b/db/migrations/006_create_events_table.sql new file mode 100644 index 0000000..291c798 --- /dev/null +++ b/db/migrations/006_create_events_table.sql @@ -0,0 +1,25 @@ + +CREATE TABLE IF NOT EXISTS `events` ( + `id` INT AUTO_INCREMENT PRIMARY KEY, + `community_id` INT NOT NULL, + `user_id` INT NOT NULL, + `title` VARCHAR(255) NOT NULL, + `description` TEXT NOT NULL, + `start_time` TIMESTAMP NOT NULL, + `end_time` TIMESTAMP NOT NULL, + `location` VARCHAR(255) NOT NULL, + `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + FOREIGN KEY (`community_id`) REFERENCES `communities`(`id`), + FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) +); + +CREATE TABLE IF NOT EXISTS `event_rsvps` ( + `id` INT AUTO_INCREMENT PRIMARY KEY, + `event_id` INT NOT NULL, + `user_id` INT NOT NULL, + `rsvp` ENUM('attending', 'not_attending') NOT NULL, + `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + UNIQUE KEY `user_event_rsvp` (`user_id`, `event_id`), + FOREIGN KEY (`event_id`) REFERENCES `events`(`id`), + FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) +); diff --git a/db/migrations/007_create_messages_table.sql b/db/migrations/007_create_messages_table.sql new file mode 100644 index 0000000..5b89163 --- /dev/null +++ b/db/migrations/007_create_messages_table.sql @@ -0,0 +1,11 @@ + +CREATE TABLE IF NOT EXISTS `messages` ( + `id` INT AUTO_INCREMENT PRIMARY KEY, + `sender_id` INT NOT NULL, + `recipient_id` INT NOT NULL, + `content` TEXT NOT NULL, + `is_read` BOOLEAN NOT NULL DEFAULT FALSE, + `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + FOREIGN KEY (`sender_id`) REFERENCES `users`(`id`), + FOREIGN KEY (`recipient_id`) REFERENCES `users`(`id`) +); diff --git a/delete_discussion.php b/delete_discussion.php new file mode 100644 index 0000000..d656d33 --- /dev/null +++ b/delete_discussion.php @@ -0,0 +1,51 @@ + +prepare('SELECT community_id, user_id FROM discussions WHERE id = ?'); +$stmt->execute([$discussion_id]); +$discussion = $stmt->fetch(); + +if (!$discussion) { + 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(); + +// Check if user is authorized to delete +if ($discussion['user_id'] != $user_id && $user_role != 'leader') { + header('Location: discussion.php?id=' . $discussion_id); + exit; +} + +// Delete replies first +$stmt = $pdo->prepare('DELETE FROM discussion_replies WHERE discussion_id = ?'); +$stmt->execute([$discussion_id]); + +// Delete discussion +$stmt = $pdo->prepare('DELETE FROM discussions WHERE id = ?'); +$stmt->execute([$discussion_id]); + +header('Location: discussions.php?community_id=' . $discussion['community_id']); +exit; diff --git a/delete_reply.php b/delete_reply.php new file mode 100644 index 0000000..9191b8d --- /dev/null +++ b/delete_reply.php @@ -0,0 +1,47 @@ + +prepare('SELECT discussion_id, user_id FROM discussion_replies WHERE id = ?'); +$stmt->execute([$reply_id]); +$reply = $stmt->fetch(); + +if (!$reply) { + 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(); + +// Check if user is authorized to delete +if ($reply['user_id'] != $user_id && $user_role != 'leader') { + header('Location: discussion.php?id=' . $reply['discussion_id']); + exit; +} + +// Delete reply +$stmt = $pdo->prepare('DELETE FROM discussion_replies WHERE id = ?'); +$stmt->execute([$reply_id]); + +header('Location: discussion.php?id=' . $reply['discussion_id']); +exit; diff --git a/discussion.php b/discussion.php new file mode 100644 index 0000000..015c30c --- /dev/null +++ b/discussion.php @@ -0,0 +1,162 @@ + +prepare('SELECT d.*, u.name as user_name, c.name as community_name, c.id as community_id FROM discussions d JOIN users u ON d.user_id = u.id JOIN communities c ON d.community_id = c.id WHERE d.id = ?'); +$stmt->execute([$discussion_id]); +$discussion = $stmt->fetch(); + +if (!$discussion) { + header('Location: communities.php'); + exit; +} + +// Fetch user role in the community +$stmt = $pdo->prepare('SELECT role FROM users WHERE id = ?'); +$stmt->execute([$user_id]); +$user_role = $stmt->fetchColumn(); + +// Handle new reply form submission +$content = ''; +$errors = []; +if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['content'])) { + $content = trim($_POST['content']); + + if (empty($content)) { + $errors[] = 'Reply content cannot be empty'; + } + + if (empty($errors)) { + try { + $stmt = $pdo->prepare('INSERT INTO discussion_replies (discussion_id, user_id, content) VALUES (?, ?, ?)'); + $stmt->execute([$discussion_id, $user_id, $content]); + header('Location: discussion.php?id=' . $discussion_id); + exit; + } catch (PDOException $e) { + $errors[] = 'Database error: ' . $e->getMessage(); + } + } +} + +// Fetch replies +$stmt = $pdo->prepare('SELECT dr.*, u.name as user_name FROM discussion_replies dr JOIN users u ON dr.user_id = u.id WHERE dr.discussion_id = ? ORDER BY dr.created_at ASC'); +$stmt->execute([$discussion_id]); +$replies = $stmt->fetchAll(); + +?> + + + + + + <?php echo htmlspecialchars($discussion['title']); ?> - Community Hub + + + + + + + +
+
+
+
+

+ in by on +
+
+

+ +
+ Edit + Delete +
+ +
+
+ +

Replies

+
+ +

No replies yet. Be the first to reply!

+ + +
+
+

+ by on + +
+ Edit + Delete +
+ +
+
+ + +
+ +
+
+

Post a Reply

+ +
+ +

+ +
+ +
+
+ + +
+ +
+
+
+
+
+ + + + + + + diff --git a/discussions.php b/discussions.php new file mode 100644 index 0000000..51773b7 --- /dev/null +++ b/discussions.php @@ -0,0 +1,202 @@ + +prepare('SELECT * FROM communities WHERE id = ?'); +$stmt->execute([$community_id]); +$community = $stmt->fetch(); + +if (!$community) { + header('Location: communities.php'); + exit; +} + +// Handle new discussion form submission +$title = $content = ''; +$errors = []; +if ($_SERVER['REQUEST_METHOD'] === 'POST') { + $title = trim($_POST['title'] ?? ''); + $content = trim($_POST['content'] ?? ''); + + if (empty($title)) { + $errors[] = 'Title is required'; + } + if (empty($content)) { + $errors[] = 'Content is required'; + } + + if (empty($errors)) { + try { + $stmt = $pdo->prepare('INSERT INTO discussions (community_id, user_id, title, content) VALUES (?, ?, ?, ?)'); + $stmt->execute([$community_id, $user_id, $title, $content]); + header('Location: discussions.php?community_id=' . $community_id); + exit; + } catch (PDOException $e) { + $errors[] = 'Database error: ' . $e->getMessage(); + } + } +} + +// Search +$search = isset($_GET['search']) ? trim($_GET['search']) : ''; + +// Pagination +$limit = 10; +$page = isset($_GET['page']) ? (int)$_GET['page'] : 1; +$offset = ($page - 1) * $limit; + +// Build where clause for search +$where_clause = 'WHERE d.community_id = ?'; +$params = [$community_id]; +if (!empty($search)) { + $where_clause .= ' AND (d.title LIKE ? OR d.content LIKE ?)'; + $params[] = '%' . $search . '%'; + $params[] = '%' . $search . '%'; +} + +// Fetch total number of discussions +$stmt = $pdo->prepare('SELECT COUNT(*) FROM discussions d ' . $where_clause); +$stmt->execute($params); +$total_discussions = $stmt->fetchColumn(); +$total_pages = ceil($total_discussions / $limit); + +// Fetch discussions for the current page +$sql = 'SELECT d.*, u.name as user_name FROM discussions d JOIN users u ON d.user_id = u.id ' . $where_clause . ' ORDER BY d.created_at DESC LIMIT ? OFFSET ?'; +$stmt = $pdo->prepare($sql); +$params[] = $limit; +$params[] = $offset; + +foreach ($params as $key => $value) { + $stmt->bindValue($key + 1, $value, is_int($value) ? PDO::PARAM_INT : PDO::PARAM_STR); +} + +$stmt->execute(); +$discussions = $stmt->fetchAll(); + +?> + + + + + + <?php echo htmlspecialchars($community['name']); ?> Discussions - Community Hub + + + + + + + +
+
+

Discussions in

+ +
+
+

Start a New Discussion

+ +
+ +

+ +
+ +
+
+ + +
+
+ + +
+ +
+
+
+ +

Existing Discussions

+ +
+ +
+ + +
+
+ +
+ +

No discussions found.

+ + + +
+
+ +
+

Started by:

+
+ + +
+ + +
+
+ + + + + + + diff --git a/edit_discussion.php b/edit_discussion.php new file mode 100644 index 0000000..dff8162 --- /dev/null +++ b/edit_discussion.php @@ -0,0 +1,135 @@ + +prepare('SELECT * FROM discussions WHERE id = ?'); +$stmt->execute([$discussion_id]); +$discussion = $stmt->fetch(); + +if (!$discussion) { + 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(); + +// Check if user is authorized to edit +if ($discussion['user_id'] != $user_id && $user_role != 'leader') { + header('Location: discussion.php?id=' . $discussion_id); + exit; +} + +$title = $discussion['title']; +$content = $discussion['content']; +$errors = []; + +if ($_SERVER['REQUEST_METHOD'] === 'POST') { + $title = trim($_POST['title'] ?? ''); + $content = trim($_POST['content'] ?? ''); + + if (empty($title)) { + $errors[] = 'Title is required'; + } + if (empty($content)) { + $errors[] = 'Content is required'; + } + + if (empty($errors)) { + try { + $stmt = $pdo->prepare('UPDATE discussions SET title = ?, content = ? WHERE id = ?'); + $stmt->execute([$title, $content, $discussion_id]); + header('Location: discussion.php?id=' . $discussion_id); + exit; + } catch (PDOException $e) { + $errors[] = 'Database error: ' . $e->getMessage(); + } + } +} + +?> + + + + + + Edit Discussion - Community Hub + + + + + + + +
+
+

Edit Discussion

+
+
+ +
+ +

+ +
+ +
+
+ + +
+
+ + +
+ + Cancel +
+
+
+
+
+ + + + + + + diff --git a/edit_reply.php b/edit_reply.php new file mode 100644 index 0000000..f849093 --- /dev/null +++ b/edit_reply.php @@ -0,0 +1,126 @@ + +prepare('SELECT * FROM discussion_replies WHERE id = ?'); +$stmt->execute([$reply_id]); +$reply = $stmt->fetch(); + +if (!$reply) { + 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(); + +// Check if user is authorized to edit +if ($reply['user_id'] != $user_id && $user_role != 'leader') { + header('Location: discussion.php?id=' . $reply['discussion_id']); + exit; +} + +$content = $reply['content']; +$errors = []; + +if ($_SERVER['REQUEST_METHOD'] === 'POST') { + $content = trim($_POST['content'] ?? ''); + + if (empty($content)) { + $errors[] = 'Content is required'; + } + + if (empty($errors)) { + try { + $stmt = $pdo->prepare('UPDATE discussion_replies SET content = ? WHERE id = ?'); + $stmt->execute([$content, $reply_id]); + header('Location: discussion.php?id=' . $reply['discussion_id']); + exit; + } catch (PDOException $e) { + $errors[] = 'Database error: ' . $e->getMessage(); + } + } +} + +?> + + + + + + Edit Reply - Community Hub + + + + + + + +
+
+

Edit Reply

+
+
+ +
+ +

+ +
+ +
+
+ + +
+ + Cancel +
+
+
+
+
+ + + + + + + diff --git a/event.php b/event.php new file mode 100644 index 0000000..e4d6295 --- /dev/null +++ b/event.php @@ -0,0 +1,150 @@ + +prepare('SELECT e.*, u.name as user_name, c.name as community_name FROM events e JOIN users u ON e.user_id = u.id JOIN communities c ON e.community_id = c.id WHERE e.id = ?'); +$stmt->execute([$event_id]); +$event = $stmt->fetch(); + +if (!$event) { + header('Location: communities.php'); + exit; +} + +// Handle RSVP +if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['rsvp'])) { + $rsvp = $_POST['rsvp']; + if (in_array($rsvp, ['attending', 'not_attending'])) { + try { + // Check if user has already RSVPed + $stmt = $pdo->prepare('SELECT id FROM event_rsvps WHERE user_id = ? AND event_id = ?'); + $stmt->execute([$user_id, $event_id]); + if ($stmt->fetch()) { + // Update existing RSVP + $stmt = $pdo->prepare('UPDATE event_rsvps SET rsvp = ? WHERE user_id = ? AND event_id = ?'); + $stmt->execute([$rsvp, $user_id, $event_id]); + } else { + // Insert new RSVP + $stmt = $pdo->prepare('INSERT INTO event_rsvps (event_id, user_id, rsvp) VALUES (?, ?, ?)'); + $stmt->execute([$event_id, $user_id, $rsvp]); + } + header('Location: event.php?id=' . $event_id); + exit; + } catch (PDOException $e) { + $errors[] = 'Database error: ' . $e->getMessage(); + } + } +} + +// Fetch RSVPs +$stmt = $pdo->prepare('SELECT rsvp, COUNT(*) as count FROM event_rsvps WHERE event_id = ? GROUP BY rsvp'); +$stmt->execute([$event_id]); +$rsvps = $stmt->fetchAll(PDO::FETCH_KEY_PAIR); + +$attending = $rsvps['attending'] ?? 0; +$not_attending = $rsvps['not_attending'] ?? 0; + +// Check if the current user has RSVPed +$stmt = $pdo->prepare('SELECT rsvp FROM event_rsvps WHERE user_id = ? AND event_id = ?'); +$stmt->execute([$user_id, $event_id]); +$user_rsvp = $stmt->fetchColumn(); + +?> + + + + + + <?php echo htmlspecialchars($event['title']); ?> - Community Hub + + + + + + + +
+
+
+
+

+ in by on +
+
+

+

Starts:

+

Ends:

+

Location:

+
+
+ +

RSVPs

+
+
+

Attending

+

+
+
+

Not Attending

+

+
+
+ +
+
+

RSVP

+
+ + +
+
+ + +
+
+
+ +
+
+ + + + + + + diff --git a/events.php b/events.php new file mode 100644 index 0000000..aab343a --- /dev/null +++ b/events.php @@ -0,0 +1,173 @@ + +prepare('SELECT * FROM communities WHERE id = ?'); +$stmt->execute([$community_id]); +$community = $stmt->fetch(); + +if (!$community) { + header('Location: communities.php'); + exit; +} + +// Handle new event form submission +$title = $description = $start_time = $end_time = $location = ''; +$errors = []; +if ($_SERVER['REQUEST_METHOD'] === 'POST') { + $title = trim($_POST['title'] ?? ''); + $description = trim($_POST['description'] ?? ''); + $start_time = trim($_POST['start_time'] ?? ''); + $end_time = trim($_POST['end_time'] ?? ''); + $location = trim($_POST['location'] ?? ''); + + if (empty($title)) { + $errors[] = 'Title is required'; + } + if (empty($description)) { + $errors[] = 'Description is required'; + } + if (empty($start_time)) { + $errors[] = 'Start time is required'; + } + if (empty($end_time)) { + $errors[] = 'End time is required'; + } + if (empty($location)) { + $errors[] = 'Location is required'; + } + + if (empty($errors)) { + try { + $stmt = $pdo->prepare('INSERT INTO events (community_id, user_id, title, description, start_time, end_time, location) VALUES (?, ?, ?, ?, ?, ?, ?)'); + $stmt->execute([$community_id, $user_id, $title, $description, $start_time, $end_time, $location]); + header('Location: events.php?community_id=' . $community_id); + exit; + } catch (PDOException $e) { + $errors[] = 'Database error: ' . $e->getMessage(); + } + } +} + +// Fetch events +$stmt = $pdo->prepare('SELECT e.*, u.name as user_name FROM events e JOIN users u ON e.user_id = u.id WHERE e.community_id = ? ORDER BY e.start_time DESC'); +$stmt->execute([$community_id]); +$events = $stmt->fetchAll(); + +?> + + + + + + <?php echo htmlspecialchars($community['name']); ?> Events - Community Hub + + + + + + + +
+
+

Events in

+ +
+
+

Create a New Event

+ +
+ +

+ +
+ +
+
+ + +
+
+ + +
+
+
+ + +
+
+ + +
+
+
+ + +
+ +
+
+
+ +

Upcoming Events

+
+ +

No events yet. Be the first to create one!

+ + + +
+
+ +
+

Location:

+

Created by:

+
+ + +
+
+
+ + + + + + + diff --git a/index.php b/index.php index 7205f3d..af48f18 100644 --- a/index.php +++ b/index.php @@ -1,150 +1,83 @@ - - + + - - - New Style - - - - - - - - - - - - - - - - - - - + + + Community Hub + + + - -
-
-

Analyzing your requirements and generating your website…

-
- Loading… -
-

AI is collecting your requirements and applying the first changes.

-

This page will update automatically as the plan is implemented.

-

Runtime: PHP — UTC

+ + +
- + + +
+
+
+

Build Your Community. Shape Your City.

+

The platform where neighbors connect, leaders emerge, and real change starts with one discussion.

+ Join Your City + Explore Communities +
+
+ +
+
+
+
+
+ +
+

Connect

+

Join communities in your city and connect with your neighbors.

+
+
+
+ +
+

Discuss

+

Start and participate in discussions about topics that matter to you.

+
+
+
+ +
+

Organize

+

Create events and proposals to drive real change in your community.

+
+
+
+
+
+ + + + - + \ No newline at end of file diff --git a/login.php b/login.php new file mode 100644 index 0000000..89ee94e --- /dev/null +++ b/login.php @@ -0,0 +1,117 @@ + +prepare('SELECT * FROM users WHERE email = ?'); + $stmt->execute([$email]); + $user = $stmt->fetch(); + + if ($user && password_verify($password, $user['password'])) { + $_SESSION['user_id'] = $user['id']; + header('Location: communities.php'); + exit; + } else { + $errors[] = 'Invalid email or password'; + } + } catch (PDOException $e) { + $errors[] = 'Database error: ' . $e->getMessage(); + } + } +} +?> + + + + + + Login - Community Hub + + + + + + + + + +
+
+
+
+
+
+

Login to Your Account

+ +
+ +

+ +
+ +
+
+ + +
+
+ + +
+
+ +
+
+
+
+
+
+
+
+ + + + + + + \ No newline at end of file diff --git a/logout.php b/logout.php new file mode 100644 index 0000000..215a7e2 --- /dev/null +++ b/logout.php @@ -0,0 +1,7 @@ + +prepare('SELECT * FROM users WHERE id = ?'); +$stmt->execute([$user_id]); +$user = $stmt->fetch(); + +// Fetch user's communities +$stmt = $pdo->prepare('SELECT c.* FROM communities c JOIN community_members cm ON c.id = cm.community_id WHERE cm.user_id = ?'); +$stmt->execute([$user_id]); +$communities = $stmt->fetchAll(); + +// Fetch user's discussions +$stmt = $pdo->prepare('SELECT * FROM discussions WHERE user_id = ? ORDER BY created_at DESC'); +$stmt->execute([$user_id]); +$discussions = $stmt->fetchAll(); + +$name = $user['name']; +$city = $user['city']; +$errors = []; + +if ($_SERVER['REQUEST_METHOD'] === 'POST') { + $name = trim($_POST['name'] ?? ''); + $city = trim($_POST['city'] ?? ''); + + if (empty($name)) { + $errors[] = 'Name is required'; + } + if (empty($city)) { + $errors[] = 'City is required'; + } + + if (empty($errors)) { + try { + $stmt = $pdo->prepare('UPDATE users SET name = ?, city = ? WHERE id = ?'); + $stmt->execute([$name, $city, $user_id]); + header('Location: profile.php'); + exit; + } catch (PDOException $e) { + $errors[] = 'Database error: ' . $e->getMessage(); + } + } +} + +?> + + + + + + Your Profile - Community Hub + + + + + + + +
+
+

Your Profile

+
+
+
+
+

Your Information

+

Name:

+

Email:

+

City:

+

Role:

+
+
+
+
+

Edit Profile

+ +
+ +

+ +
+ +
+
+ + +
+
+ + +
+ +
+
+
+
+
+
+
+

Your Communities

+
+ +

You are not a member of any communities yet.

+ + + + + + + +
+
+
+
+
+

Your Discussions

+
+ +

You have not started any discussions yet.

+ + + + + + + +
+
+
+
+
+
+
+ + + + + + + diff --git a/proposal.php b/proposal.php new file mode 100644 index 0000000..170aace --- /dev/null +++ b/proposal.php @@ -0,0 +1,152 @@ + +prepare('SELECT p.*, u.name as user_name, c.name as community_name FROM proposals p JOIN users u ON p.user_id = u.id JOIN communities c ON p.community_id = c.id WHERE p.id = ?'); +$stmt->execute([$proposal_id]); +$proposal = $stmt->fetch(); + +if (!$proposal) { + header('Location: communities.php'); + exit; +} + +// Handle voting +if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['vote'])) { + $vote = $_POST['vote']; + if (in_array($vote, ['up', 'down'])) { + try { + // Check if user has already voted + $stmt = $pdo->prepare('SELECT id FROM proposal_votes WHERE user_id = ? AND proposal_id = ?'); + $stmt->execute([$user_id, $proposal_id]); + if ($stmt->fetch()) { + // Update existing vote + $stmt = $pdo->prepare('UPDATE proposal_votes SET vote = ? WHERE user_id = ? AND proposal_id = ?'); + $stmt->execute([$vote, $user_id, $proposal_id]); + } else { + // Insert new vote + $stmt = $pdo->prepare('INSERT INTO proposal_votes (proposal_id, user_id, vote) VALUES (?, ?, ?)'); + $stmt->execute([$proposal_id, $user_id, $vote]); + } + header('Location: proposal.php?id=' . $proposal_id); + exit; + } catch (PDOException $e) { + $errors[] = 'Database error: ' . $e->getMessage(); + } + } +} + +// Fetch votes +$stmt = $pdo->prepare('SELECT vote, COUNT(*) as count FROM proposal_votes WHERE proposal_id = ? GROUP BY vote'); +$stmt->execute([$proposal_id]); +$votes = $stmt->fetchAll(PDO::FETCH_KEY_PAIR); + +$up_votes = $votes['up'] ?? 0; +$down_votes = $votes['down'] ?? 0; + +// Check if the current user has voted +$stmt = $pdo->prepare('SELECT vote FROM proposal_votes WHERE user_id = ? AND proposal_id = ?'); +$stmt->execute([$user_id, $proposal_id]); +$user_vote = $stmt->fetchColumn(); + +?> + + + + + + <?php echo htmlspecialchars($proposal['title']); ?> - Community Hub + + + + + + + +
+
+
+
+

+ in by on +
+
+

+

Voting ends:

+
+
+ +

Voting

+
+
+

Upvotes

+

+
+
+

Downvotes

+

+
+
+ + time()): ?> +
+
+

Cast Your Vote

+
+ + +
+
+ + +
+
+
+ +
Voting on this proposal has ended.
+ + +
+
+ + + + + + + diff --git a/proposals.php b/proposals.php new file mode 100644 index 0000000..d4daf32 --- /dev/null +++ b/proposals.php @@ -0,0 +1,161 @@ + +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:

+
+ + +
+
+
+ + + + + + + diff --git a/signup.php b/signup.php new file mode 100644 index 0000000..f910cff --- /dev/null +++ b/signup.php @@ -0,0 +1,188 @@ + +prepare('SELECT id FROM users WHERE email = ?'); + $stmt->execute([$email]); + if ($stmt->fetch()) { + $errors[] = 'User with this email already exists'; + } else { + $pdo->beginTransaction(); + + // Check if community for the city exists + $stmt = $pdo->prepare('SELECT id FROM communities WHERE name = ?'); + $stmt->execute([$city]); + $community = $stmt->fetch(); + + $role = 'member'; + if (!$community) { + $role = 'leader'; + } + + // Insert the new user + $hashed_password = password_hash($password, PASSWORD_DEFAULT); + $stmt = $pdo->prepare('INSERT INTO users (name, email, password, city, role) VALUES (?, ?, ?, ?, ?)'); + $stmt->execute([$name, $email, $hashed_password, $city, $role]); + $user_id = $pdo->lastInsertId(); + + if ($role === 'leader') { + $stmt = $pdo->prepare('INSERT INTO communities (name, leader_id) VALUES (?, ?)'); + $stmt->execute([$city, $user_id]); + $community_id = $pdo->lastInsertId(); + } else { + $community_id = $community['id']; + } + + // Add user to community + $stmt = $pdo->prepare('INSERT INTO community_members (user_id, community_id) VALUES (?, ?)'); + $stmt->execute([$user_id, $community_id]); + + $pdo->commit(); + + $_SESSION['user_id'] = $user_id; + header('Location: communities.php'); + exit; + } + } catch (PDOException $e) { + if ($pdo->inTransaction()) { + $pdo->rollBack(); + } + $errors[] = 'Database error: ' . $e->getMessage(); + } + } +} +?> + + + + + + Sign Up - Community Hub + + + + + + + + + +
+
+
+
+
+
+

Create Your Account

+ +
+ +

+ +
+ +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ +
+
+
+
+
+
+
+
+ + + + + + + + \ No newline at end of file