From 1b14267623b3dad266dd382e8f0717e8b93bf5a5 Mon Sep 17 00:00:00 2001 From: Flatlogic Bot Date: Wed, 19 Nov 2025 22:24:36 +0000 Subject: [PATCH] v4 --- admin/application_actions.php | 42 +++++ admin/applications.php | 94 ++++++++++++ admin/event_actions.php | 39 +++++ admin/events.php | 76 +++++++++ admin/index.php | 45 ++++++ apply.php | 55 +++++++ dashboard.php | 77 ++++++++++ db/migrations.php | 39 +++++ db/migrations/001_create_users_table.sql | 12 ++ db/migrations/002_create_events_table.sql | 11 ++ .../003_create_applications_table.sql | 9 ++ includes/footer.php | 13 ++ includes/header.php | 61 ++++++++ includes/session.php | 26 ++++ index.php | 144 +++++------------- login.php | 75 +++++++++ logout.php | 21 +++ signup.php | 86 +++++++++++ 18 files changed, 819 insertions(+), 106 deletions(-) create mode 100644 admin/application_actions.php create mode 100644 admin/applications.php create mode 100644 admin/event_actions.php create mode 100644 admin/events.php create mode 100644 admin/index.php create mode 100644 apply.php create mode 100644 dashboard.php create mode 100644 db/migrations.php create mode 100644 db/migrations/001_create_users_table.sql create mode 100644 db/migrations/002_create_events_table.sql create mode 100644 db/migrations/003_create_applications_table.sql create mode 100644 includes/footer.php create mode 100644 includes/header.php create mode 100644 includes/session.php create mode 100644 login.php create mode 100644 logout.php create mode 100644 signup.php diff --git a/admin/application_actions.php b/admin/application_actions.php new file mode 100644 index 0000000..a69bbd6 --- /dev/null +++ b/admin/application_actions.php @@ -0,0 +1,42 @@ +prepare('UPDATE applications SET status = ? WHERE id = ?'); + if ($stmt->execute([$new_status, $application_id])) { + $_SESSION['flash_message'] = [ + 'type' => 'success', + 'message' => 'Application status has been updated.' + ]; + } else { + $_SESSION['flash_message'] = [ + 'type' => 'danger', + 'message' => 'Failed to update application status.' + ]; + } + } else { + $_SESSION['flash_message'] = [ + 'type' => 'danger', + 'message' => 'Invalid request.' + ]; + } +} else { + $_SESSION['flash_message'] = [ + 'type' => 'danger', + 'message' => 'Invalid request method.' + ]; +} + +header('Location: applications.php'); +exit(); diff --git a/admin/applications.php b/admin/applications.php new file mode 100644 index 0000000..c19e5f9 --- /dev/null +++ b/admin/applications.php @@ -0,0 +1,94 @@ +query('SELECT a.id, a.status, a.created_at, u.name AS user_name, u.email AS user_email, e.name AS event_name + FROM applications a + JOIN users u ON a.user_id = u.id + JOIN events e ON a.event_id = e.id + ORDER BY a.created_at DESC'); +$applications = $stmt->fetchAll(); + +?> + +
+
+

Manage Applications

+
+ + + + + + +
+
+
+ + + + + + + + + + + + 0): ?> + + + + + + + + + + + + + + + +
EventApplicantSubmittedStatusActions
+
+ +
+ + + + +
+ + + +
+
+ + + +
+
No applications found.
+
+
+
+
+ + diff --git a/admin/event_actions.php b/admin/event_actions.php new file mode 100644 index 0000000..9d630b5 --- /dev/null +++ b/admin/event_actions.php @@ -0,0 +1,39 @@ +prepare('INSERT INTO events (title, description, event_date, location) VALUES (?, ?, ?, ?)'); + $stmt->execute([$title, $description, $event_date, $location]); + + header('Location: events.php'); + exit; + } + break; + + case 'toggle_open': + $id = $_GET['id'] ?? null; + if ($id) { + $stmt = $pdo->prepare('UPDATE events SET is_open = !is_open WHERE id = ?'); + $stmt->execute([$id]); + } + header('Location: events.php'); + exit; + + // Add cases for update and delete later + + default: + header('Location: events.php'); + exit; +} diff --git a/admin/events.php b/admin/events.php new file mode 100644 index 0000000..f82da2e --- /dev/null +++ b/admin/events.php @@ -0,0 +1,76 @@ +query('SELECT * FROM events ORDER BY event_date DESC'); +$events = $stmt->fetchAll(); + +require_once '../includes/header.php'; +?> + +
+
+

Manage Events

+ +
+
+
Create New Event
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+ +
+
+
+ +

Existing Events

+
+ + + + + + + + + + + + + + + + + + + + + +
TitleDateLocationOpen for ApplicationsActions
+ + + + +
+
+
+
+ + diff --git a/admin/index.php b/admin/index.php new file mode 100644 index 0000000..a23fe36 --- /dev/null +++ b/admin/index.php @@ -0,0 +1,45 @@ + + +
+
+

Admin Dashboard

+

Welcome, admin! From here you can manage events, applications, and users.

+ +
+
+
+
+
Manage Events
+

Create, edit, and view all promotional events.

+ Go to Events +
+
+
+
+
+
+
Manage Applications
+

Review and approve/reject applications from promoters.

+ Go to Applications +
+
+
+
+
+
+
Manage Users
+

View and manage all registered users.

+ Go to Users +
+
+
+
+
+
+ + diff --git a/apply.php b/apply.php new file mode 100644 index 0000000..cf9321a --- /dev/null +++ b/apply.php @@ -0,0 +1,55 @@ +prepare("SELECT id FROM applications WHERE event_id = ? AND user_id = ?"); + $stmt->execute([$event_id, $user_id]); + if ($stmt->fetch()) { + $_SESSION['flash_message'] = [ + 'type' => 'warning', + 'message' => 'You have already applied to this event.' + ]; + header('Location: index.php#events'); + exit(); + } + + // 4. Insert new application + $stmt = $pdo->prepare("INSERT INTO applications (event_id, user_id, status) VALUES (?, ?, 'pending')"); + $stmt->execute([$event_id, $user_id]); + + $_SESSION['flash_message'] = [ + 'type' => 'success', + 'message' => 'Your application has been submitted successfully!' + ]; + +} catch (PDOException $e) { + // error_log($e->getMessage()); // Log error for debugging + $_SESSION['flash_message'] = [ + 'type' => 'danger', + 'message' => 'A database error occurred. Please try again.' + ]; +} + +// 5. Redirect back to the events section +header('Location: index.php#events'); +exit(); diff --git a/dashboard.php b/dashboard.php new file mode 100644 index 0000000..72915f9 --- /dev/null +++ b/dashboard.php @@ -0,0 +1,77 @@ + + +
+

User Dashboard

+

Welcome back, . Here you can view your applications and manage your profile.

+ +
+ +

My Applications

+ + prepare( + 'SELECT a.id, a.status, a.created_at, e.name AS event_name, e.event_date + FROM applications a + JOIN events e ON a.event_id = e.id + WHERE a.user_id = ? + ORDER BY a.created_at DESC' + ); + $stmt->execute([$_SESSION['user']['id']]); + $applications = $stmt->fetchAll(); + + if (count($applications) > 0): + ?> +
+ + + + + + + + + + + + + + + + + + + +
EventEvent DateApplied OnStatus
+ + + +
+
+ +
+ You have not applied to any events yet. Find events to apply for. +
+ + +
+ + diff --git a/db/migrations.php b/db/migrations.php new file mode 100644 index 0000000..b916673 --- /dev/null +++ b/db/migrations.php @@ -0,0 +1,39 @@ +setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + + // Create migrations table if it doesn't exist + $pdo->exec("CREATE TABLE IF NOT EXISTS migrations ( + id INT AUTO_INCREMENT PRIMARY KEY, + migration VARCHAR(255) NOT NULL, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP + )"); + + // Get all executed migrations + $executedMigrations = $pdo->query("SELECT migration FROM migrations")->fetchAll(PDO::FETCH_COLUMN); + + $migrationFiles = glob(__DIR__ . '/migrations/*.sql'); + sort($migrationFiles); + + foreach ($migrationFiles as $file) { + $migrationName = basename($file); + if (!in_array($migrationName, $executedMigrations)) { + $sql = file_get_contents($file); + $pdo->exec($sql); + + // Record the migration + $stmt = $pdo->prepare("INSERT INTO migrations (migration) VALUES (?)"); + $stmt->execute([$migrationName]); + + echo "Migration successful: {$migrationName}" . PHP_EOL; + } + } + + echo "All migrations are up to date." . PHP_EOL; + +} catch (PDOException $e) { + die("Migration failed: " . $e->getMessage()); +} diff --git a/db/migrations/001_create_users_table.sql b/db/migrations/001_create_users_table.sql new file mode 100644 index 0000000..ef3fcf4 --- /dev/null +++ b/db/migrations/001_create_users_table.sql @@ -0,0 +1,12 @@ +CREATE TABLE IF NOT EXISTS users ( + id INT AUTO_INCREMENT PRIMARY KEY, + email VARCHAR(255) NOT NULL UNIQUE, + password VARCHAR(255) NOT NULL, + role ENUM('admin', 'user') NOT NULL DEFAULT 'user', + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP +); + +-- Insert the super-admin user +INSERT INTO users (email, password, role) +VALUES ('dylan@sacredhiveofficial.com', '$2y$10$o4vTWS/X7cKvcsum4aIU0.5jzbtvHqKDqrSvZ64JgKNi5r5aJBJxy', 'admin'); +-- Note: The password is "test123" diff --git a/db/migrations/002_create_events_table.sql b/db/migrations/002_create_events_table.sql new file mode 100644 index 0000000..6ac36a6 --- /dev/null +++ b/db/migrations/002_create_events_table.sql @@ -0,0 +1,11 @@ +CREATE TABLE IF NOT EXISTS events ( + id INT AUTO_INCREMENT PRIMARY KEY, + title VARCHAR(255) NOT NULL, + description TEXT, + event_date DATETIME, + location VARCHAR(255), + image_url VARCHAR(255), + is_open BOOLEAN DEFAULT TRUE, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP +); diff --git a/db/migrations/003_create_applications_table.sql b/db/migrations/003_create_applications_table.sql new file mode 100644 index 0000000..59db21f --- /dev/null +++ b/db/migrations/003_create_applications_table.sql @@ -0,0 +1,9 @@ +CREATE TABLE IF NOT EXISTS applications ( + id INT AUTO_INCREMENT PRIMARY KEY, + event_id INT NOT NULL, + user_id INT NOT NULL, + status ENUM('pending', 'approved', 'rejected') NOT NULL DEFAULT 'pending', + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + FOREIGN KEY (event_id) REFERENCES events(id) ON DELETE CASCADE, + FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE +); diff --git a/includes/footer.php b/includes/footer.php new file mode 100644 index 0000000..1f7442f --- /dev/null +++ b/includes/footer.php @@ -0,0 +1,13 @@ + + + + + + + + + \ No newline at end of file diff --git a/includes/header.php b/includes/header.php new file mode 100644 index 0000000..0bbea23 --- /dev/null +++ b/includes/header.php @@ -0,0 +1,61 @@ + + + + + + + + PromoPass - The Ultimate Festival & Event Access Pass + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/includes/session.php b/includes/session.php new file mode 100644 index 0000000..77b6b76 --- /dev/null +++ b/includes/session.php @@ -0,0 +1,26 @@ + - - - - - - PromoPass - The Ultimate Festival & Event Access Pass - - - - - - - - - - - - - - - - - - - - - +
@@ -62,58 +12,52 @@
+ + + +

Open Events

'Cosmic Meadow Festival', - 'date' => '2025-12-15', - 'location' => 'Miami, FL', - 'image' => 'https://images.pexels.com/photos/2263436/pexels-photo-2263436.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=2' - ], - [ - 'title' => 'Neon Garden Rave', - 'date' => '2025-11-28', - 'location' => 'Las Vegas, NV', - 'image' => 'https://images.pexels.com/photos/1684151/pexels-photo-1684151.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=2' - ], - [ - 'title' => 'Bass Canyon Showcase', - 'date' => '2026-01-20', - 'location' => 'Denver, CO', - 'image' => 'https://images.pexels.com/photos/2118046/pexels-photo-2118046.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=2' - ], - [ - 'title' => 'Quantum Valley Experience', - 'date' => '2026-02-10', - 'location' => 'New York, NY', - 'image' => 'https://images.pexels.com/photos/2099023/pexels-photo-2099023.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=2' - ], - [ - 'title' => 'Circuit Grounds Tour', - 'date' => '2026-03-05', - 'location' => 'Chicago, IL', - 'image' => 'https://images.pexels.com/photos/2526127/pexels-photo-2526127.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=2' - ], - [ - 'title' => 'Wasteland Arena', - 'date' => '2026-04-18', - 'location' => 'Los Angeles, CA', - 'image' => 'https://images.pexels.com/photos/2339031/pexels-photo-2339031.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=2' - ] - ]; + require_once 'db/config.php'; + + // Fetch open events from the database + $pdo = db(); + $stmt = $pdo->query('SELECT * FROM events WHERE is_open = TRUE ORDER BY event_date ASC'); + $events = $stmt->fetchAll(); + + // If user is logged in, get their applications + $user_applications = []; + if (isset($_SESSION['user_id'])) { + $app_stmt = $pdo->prepare('SELECT event_id FROM applications WHERE user_id = ?'); + $app_stmt->execute([$_SESSION['user_id']]); + $user_applications = $app_stmt->fetchAll(PDO::FETCH_COLUMN); + } foreach ($events as $event): + $imageUrl = !empty($event['image_url']) ? $event['image_url'] : 'https://images.pexels.com/photos/2263436/pexels-photo-2263436.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=2'; ?>
- Event Image + Event Image
-

- Apply Now +

+ + + + +
+ + +
+ + + Login to Apply +
@@ -122,16 +66,4 @@
- -
-
-

© PromoPass. All Rights Reserved. Built with Flatlogic.

-
-
- - - - - - - \ No newline at end of file + \ No newline at end of file diff --git a/login.php b/login.php new file mode 100644 index 0000000..da853bf --- /dev/null +++ b/login.php @@ -0,0 +1,75 @@ +prepare("SELECT * FROM users WHERE email = ?"); + $stmt->execute([$email]); + $user = $stmt->fetch(PDO::FETCH_ASSOC); + + + + if ($user && password_verify($password, $user['password'])) { + $_SESSION['user_id'] = $user['id']; + $_SESSION['user_role'] = $user['role']; + + if ($user['role'] === 'admin') { + header('Location: admin/index.php'); + } else { + header('Location: dashboard.php'); + } + exit(); + } else { + $error = 'Invalid email or password.'; + } + } catch (PDOException $e) { + $error = 'Database error. Please try again later.'; + // error_log($e->getMessage()); // It's good practice to log the actual error + } + } +} + +require_once 'includes/header.php'; +?> + +
+
+
+
+
+
+

Login

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

Don't have an account? Sign up

+
+
+
+
+
+
+ + diff --git a/logout.php b/logout.php new file mode 100644 index 0000000..0d0f649 --- /dev/null +++ b/logout.php @@ -0,0 +1,21 @@ +prepare("SELECT COUNT(*) FROM users WHERE email = ?"); + $stmt->execute([$email]); + if ($stmt->fetchColumn() > 0) { + $error = 'An account with this email already exists.'; + } else { + // Insert new user + $hashed_password = password_hash($password, PASSWORD_DEFAULT); + $stmt = $pdo->prepare("INSERT INTO users (email, password, role) VALUES (?, ?, 'user')"); + if ($stmt->execute([$email, $hashed_password])) { + $success = 'Account created successfully! You can now login.'; + } else { + $error = 'Failed to create account. Please try again.'; + } + } + } catch (PDOException $e) { + $error = 'Database error. Please try again later.'; + // error_log($e->getMessage()); + } + } +} + +require_once 'includes/header.php'; +?> + +
+
+
+
+
+
+

Sign Up

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

Already have an account? Login

+
+
+
+
+
+
+ +