bb
This commit is contained in:
parent
2369b242ea
commit
298521e30e
70
admin_dashboard.php
Normal file
70
admin_dashboard.php
Normal file
@ -0,0 +1,70 @@
|
||||
<?php
|
||||
session_start();
|
||||
|
||||
if (!isset($_SESSION['user_id']) || $_SESSION['role'] !== 'admin') {
|
||||
header('Location: login.php');
|
||||
exit();
|
||||
}
|
||||
|
||||
require_once 'db/config.php';
|
||||
$conn = db();
|
||||
|
||||
// Fetch pending events
|
||||
$stmt = $conn->prepare("SELECT events.*, users.name as manager_name FROM events JOIN users ON events.created_by = users.id WHERE events.status = 'pending' ORDER BY events.created_at DESC");
|
||||
$stmt->execute();
|
||||
$events = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Admin Dashboard - EventPlatform</title>
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<?php require_once './includes/header.php'; ?>
|
||||
|
||||
<div class="container mt-5">
|
||||
<h1 class="mb-4">Admin Dashboard</h1>
|
||||
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
Pending Events
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Event Name</th>
|
||||
<th>Manager</th>
|
||||
<th>Date</th>
|
||||
<th>Location</th>
|
||||
<th>Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($events as $event): ?>
|
||||
<tr>
|
||||
<td><?php echo htmlspecialchars($event['name']); ?></td>
|
||||
<td><?php echo htmlspecialchars($event['manager_name']); ?></td>
|
||||
<td><?php echo htmlspecialchars($event['date']); ?></td>
|
||||
<td><?php echo htmlspecialchars($event['location']); ?></td>
|
||||
<td>
|
||||
<a href="update_event_status.php?id=<?php echo $event['id']; ?>&status=accepted" class="btn btn-success btn-sm">Approve</a>
|
||||
<a href="update_event_status.php?id=<?php echo $event['id']; ?>&status=rejected" class="btn btn-danger btn-sm">Reject</a>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
32
buy_ticket.php
Normal file
32
buy_ticket.php
Normal file
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
session_start();
|
||||
|
||||
if (!isset($_SESSION['user_id'])) {
|
||||
header('Location: login.php');
|
||||
exit();
|
||||
}
|
||||
|
||||
if (!isset($_GET['id'])) {
|
||||
header('Location: index.php');
|
||||
exit();
|
||||
}
|
||||
|
||||
require_once 'db/config.php';
|
||||
|
||||
$event_id = $_GET['id'];
|
||||
$user_id = $_SESSION['user_id'];
|
||||
|
||||
try {
|
||||
$conn = db();
|
||||
$stmt = $conn->prepare("INSERT INTO tickets (user_id, event_id) VALUES (:user_id, :event_id)");
|
||||
$stmt->bindParam(':user_id', $user_id, PDO::PARAM_INT);
|
||||
$stmt->bindParam(':event_id', $event_id, PDO::PARAM_INT);
|
||||
$stmt->execute();
|
||||
|
||||
header('Location: my_tickets.php?success=ticket_purchased');
|
||||
exit();
|
||||
} catch (PDOException $e) {
|
||||
// Handle database error
|
||||
header('Location: event_details.php?id=' . $event_id . '&error=db_error');
|
||||
exit();
|
||||
}
|
||||
41
create_event.php
Normal file
41
create_event.php
Normal file
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
session_start();
|
||||
|
||||
if (!isset($_SESSION['user_id']) || $_SESSION['role'] !== 'manager') {
|
||||
header('Location: login.php');
|
||||
exit();
|
||||
}
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
require_once 'db/config.php';
|
||||
|
||||
$name = $_POST['name'] ?? '';
|
||||
$description = $_POST['description'] ?? '';
|
||||
$date = $_POST['date'] ?? '';
|
||||
$location = $_POST['location'] ?? '';
|
||||
$manager_id = $_SESSION['user_id'];
|
||||
|
||||
if (empty($name) || empty($description) || empty($date) || empty($location)) {
|
||||
// Handle empty fields
|
||||
header('Location: manager_dashboard.php?error=empty_fields');
|
||||
exit();
|
||||
}
|
||||
|
||||
try {
|
||||
$conn = db();
|
||||
$stmt = $conn->prepare("INSERT INTO events (name, description, date, location, status, created_by) VALUES (:name, :description, :date, :location, 'pending', :created_by)");
|
||||
$stmt->bindParam(':name', $name);
|
||||
$stmt->bindParam(':description', $description);
|
||||
$stmt->bindParam(':date', $date);
|
||||
$stmt->bindParam(':location', $location);
|
||||
$stmt->bindParam(':created_by', $manager_id, PDO::PARAM_INT);
|
||||
$stmt->execute();
|
||||
|
||||
header('Location: manager_dashboard.php?success=event_created');
|
||||
exit();
|
||||
} catch (PDOException $e) {
|
||||
// Handle database error
|
||||
header('Location: manager_dashboard.php?error=db_error');
|
||||
exit();
|
||||
}
|
||||
}
|
||||
25
db/migrations/002_create_users_table.php
Normal file
25
db/migrations/002_create_users_table.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../../db/config.php';
|
||||
|
||||
try {
|
||||
$pdo = db();
|
||||
|
||||
$sql = "
|
||||
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,
|
||||
role ENUM('user', 'manager', 'admin') NOT NULL DEFAULT 'user',
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
) ENGINE=INNODB;
|
||||
";
|
||||
|
||||
$pdo->exec($sql);
|
||||
|
||||
echo "Migration 002 completed successfully: 'users' table created." . PHP_EOL;
|
||||
|
||||
} catch (PDOException $e) {
|
||||
die("Migration 002 failed: " . $e->getMessage());
|
||||
}
|
||||
?>
|
||||
17
db/migrations/003_add_role_to_users.php
Normal file
17
db/migrations/003_add_role_to_users.php
Normal file
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../../db/config.php';
|
||||
|
||||
try {
|
||||
$conn = db();
|
||||
$sql = "ALTER TABLE users ADD COLUMN role VARCHAR(255) NOT NULL DEFAULT 'user'";
|
||||
$conn->exec($sql);
|
||||
// Set user with id 1 to be an admin
|
||||
$sql_admin = "UPDATE users SET role = 'admin' WHERE id = 1";
|
||||
$conn->exec($sql_admin);
|
||||
// Set user with id 2 to be a manager
|
||||
$sql_manager = "UPDATE users SET role = 'manager' WHERE id = 2";
|
||||
$conn->exec($sql_manager);
|
||||
echo "Migration successful: 'role' column added to 'users' table and default users updated." . PHP_EOL;
|
||||
} catch (PDOException $e) {
|
||||
echo "Migration failed: " . $e->getMessage() . PHP_EOL;
|
||||
}
|
||||
11
db/migrations/004_add_created_by_to_events.php
Normal file
11
db/migrations/004_add_created_by_to_events.php
Normal file
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../../db/config.php';
|
||||
|
||||
try {
|
||||
$conn = db();
|
||||
$sql = "ALTER TABLE events ADD COLUMN created_by INT(11) NULL, ADD FOREIGN KEY (created_by) REFERENCES users(id)";
|
||||
$conn->exec($sql);
|
||||
echo "Migration successful: 'created_by' column added to 'events' table." . PHP_EOL;
|
||||
} catch (PDOException $e) {
|
||||
echo "Migration failed: " . $e->getMessage() . PHP_EOL;
|
||||
}
|
||||
18
db/migrations/005_create_tickets_table.php
Normal file
18
db/migrations/005_create_tickets_table.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../../db/config.php';
|
||||
|
||||
try {
|
||||
$conn = db();
|
||||
$sql = "CREATE TABLE IF NOT EXISTS tickets (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
user_id INT NOT NULL,
|
||||
event_id INT NOT NULL,
|
||||
purchase_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (user_id) REFERENCES users(id),
|
||||
FOREIGN KEY (event_id) REFERENCES events(id)
|
||||
)";
|
||||
$conn->exec($sql);
|
||||
echo "Migration successful: 'tickets' table created." . PHP_EOL;
|
||||
} catch (PDOException $e) {
|
||||
echo "Migration failed: " . $e->getMessage() . PHP_EOL;
|
||||
}
|
||||
59
event_details.php
Normal file
59
event_details.php
Normal file
@ -0,0 +1,59 @@
|
||||
<?php
|
||||
session_start();
|
||||
|
||||
if (!isset($_GET['id'])) {
|
||||
header('Location: index.php');
|
||||
exit();
|
||||
}
|
||||
|
||||
require_once 'db/config.php';
|
||||
$conn = db();
|
||||
|
||||
$event_id = $_GET['id'];
|
||||
|
||||
// Fetch event details
|
||||
$stmt = $conn->prepare("SELECT * FROM events WHERE id = :id AND status = 'accepted'");
|
||||
$stmt->bindParam(':id', $event_id, PDO::PARAM_INT);
|
||||
$stmt->execute();
|
||||
$event = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
if (!$event) {
|
||||
header('Location: index.php');
|
||||
exit();
|
||||
}
|
||||
|
||||
$event_date = new DateTime($event['date']);
|
||||
|
||||
?>
|
||||
<!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($event['name']); ?> - EventPlatform</title>
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<?php require_once './includes/header.php'; ?>
|
||||
|
||||
<div class="container mt-5">
|
||||
<div class="row">
|
||||
<div class="col-md-8 offset-md-2">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<h1 class="card-title"><?php echo htmlspecialchars($event['name']); ?></h1>
|
||||
<h5 class="card-subtitle mb-2 text-muted"><?php echo $event_date->format('l, F j, Y'); ?></h5>
|
||||
<p class="card-text"><i class="bi bi-geo-alt-fill"></i> <?php echo htmlspecialchars($event['location']); ?></p>
|
||||
<p class="card-text"><?php echo nl2br(htmlspecialchars($event['description'])); ?></p>
|
||||
<a href="buy_ticket.php?id=<?php echo $event['id']; ?>" class="btn btn-primary">Buy Ticket</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
45
includes/header.php
Normal file
45
includes/header.php
Normal file
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
if (session_status() === PHP_SESSION_NONE) {
|
||||
session_start();
|
||||
}
|
||||
?>
|
||||
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
|
||||
<div class="container-fluid">
|
||||
<a class="navbar-brand" href="index.php">EventPlatform</a>
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
<div class="collapse navbar-collapse" id="navbarNav">
|
||||
<ul class="navbar-nav ms-auto">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="index.php">Home</a>
|
||||
</li>
|
||||
<?php if (isset($_SESSION['user_id'])): ?>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="my_tickets.php">My Tickets</a>
|
||||
</li>
|
||||
<?php if ($_SESSION['role'] === 'manager'): ?>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="manager_dashboard.php">Manager Dashboard</a>
|
||||
</li>
|
||||
<?php endif; ?>
|
||||
<?php if ($_SESSION['role'] === 'admin'): ?>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="admin_dashboard.php">Admin Dashboard</a>
|
||||
</li>
|
||||
<?php endif; ?>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="logout.php">Logout</a>
|
||||
</li>
|
||||
<?php else: ?>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="login.php">Login</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="register.php">Register</a>
|
||||
</li>
|
||||
<?php endif; ?>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
39
index.php
39
index.php
@ -3,7 +3,7 @@
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>EventJet - Your Gateway to Exclusive Events</title>
|
||||
<title>EventPlatform - Your Gateway to Exclusive Events</title>
|
||||
|
||||
<meta name="description" content="<?php echo htmlspecialchars($_SERVER['PROJECT_DESCRIPTION'] ?? 'Find and book tickets for the best events in town.'); ?>">
|
||||
<!-- Open Graph / Twitter Card meta tags are managed by the platform. Do not add them here. -->
|
||||
@ -18,25 +18,9 @@
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<nav class="navbar navbar-expand-lg navbar-light bg-white shadow-sm">
|
||||
<div class="container">
|
||||
<a class="navbar-brand" href="/">
|
||||
<i class="bi bi-calendar-check"></i>
|
||||
EventJet
|
||||
</a>
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
<div class="collapse navbar-collapse" id="navbarNav">
|
||||
<ul class="navbar-nav ms-auto">
|
||||
<li class="nav-item"><a class="nav-link" href="#">Home</a></li>
|
||||
<li class="nav-item"><a class="nav-link" href="#events">Events</a></li>
|
||||
<li class="nav-item"><a class="nav-link" href="#">Login</a></li>
|
||||
<li class="nav-item"><a class="nav-link btn btn-primary text-white ms-2 px-3 py-2" href="#">Register</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
<?php require_once './includes/header.php'; ?>
|
||||
|
||||
|
||||
|
||||
<main>
|
||||
<section class="hero-section text-center">
|
||||
@ -55,7 +39,7 @@
|
||||
try {
|
||||
require_once __DIR__ . '/db/config.php';
|
||||
$pdo = db();
|
||||
$stmt = $pdo->prepare("SELECT * FROM events WHERE status = 'accepted' ORDER BY event_date ASC");
|
||||
$stmt = $pdo->prepare("SELECT * FROM events WHERE status = 'accepted' ORDER BY date ASC");
|
||||
$stmt->execute();
|
||||
$events = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
@ -63,19 +47,15 @@
|
||||
echo "<p class='text-center text-muted'>No upcoming events found. Please check back later!</p>";
|
||||
} else {
|
||||
foreach ($events as $event) {
|
||||
$event_date = new DateTime($event['event_date']);
|
||||
$price = floatval($event['price']);
|
||||
$price_display = $price > 0 ? '$' . number_format($price, 2) : 'FREE';
|
||||
$price_class = $price > 0 ? '' : 'free';
|
||||
$event_date = new DateTime($event['date']);
|
||||
|
||||
echo '<div class="col-lg-4 col-md-6">
|
||||
<div class="card event-card">
|
||||
<div class="card-body position-relative">
|
||||
<div class="price-tag ' . $price_class . '">' . $price_display . '</div>
|
||||
<h5 class="card-subtitle mb-2 text-muted">' . $event_date->format('M d, Y \a\t h:i A') . '</h5>
|
||||
<h4 class="card-title mb-2">' . htmlspecialchars($event['title']) . '</h4>
|
||||
<h5 class="card-subtitle mb-2 text-muted">' . $event_date->format('M d, Y') . '</h5>
|
||||
<h4 class="card-title mb-2">' . htmlspecialchars($event['name']) . '</h4>
|
||||
<p class="card-text"><i class="bi bi-geo-alt-fill"></i> ' . htmlspecialchars($event['location']) . '</p>
|
||||
<a href="#" class="btn btn-outline-primary stretched-link">View Details</a>
|
||||
<a href="event_details.php?id=' . $event['id'] . '" class="btn btn-outline-primary stretched-link">View Details</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>';
|
||||
@ -90,7 +70,6 @@
|
||||
</div>
|
||||
</section>
|
||||
</main>
|
||||
|
||||
<footer class="footer">
|
||||
<div class="container text-center">
|
||||
<p class="text-muted mb-0">© <?php echo date("Y"); ?> EventJet. All rights reserved.</p>
|
||||
|
||||
111
login.php
Normal file
111
login.php
Normal file
@ -0,0 +1,111 @@
|
||||
<?php
|
||||
|
||||
// If user is already logged in, redirect to home page
|
||||
if (isset($_SESSION['user_id'])) {
|
||||
header("Location: index.php");
|
||||
exit();
|
||||
}
|
||||
|
||||
require_once 'db/config.php';
|
||||
|
||||
$email = '';
|
||||
$errors = [];
|
||||
|
||||
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||
$email = trim($_POST['email'] ?? '');
|
||||
$password = $_POST['password'] ?? '';
|
||||
|
||||
if (empty($email) || !filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
||||
$errors[] = 'A valid email is required.';
|
||||
}
|
||||
|
||||
if (empty($password)) {
|
||||
$errors[] = 'Password is required.';
|
||||
}
|
||||
|
||||
if (empty($errors)) {
|
||||
try {
|
||||
$pdo = db();
|
||||
$stmt = $pdo->prepare("SELECT id, name, email, password, role FROM users WHERE email = ?");
|
||||
$stmt->execute([$email]);
|
||||
$user = $stmt->fetch();
|
||||
|
||||
if ($user && password_verify($password, $user['password'])) {
|
||||
// Password is correct, start session
|
||||
$_SESSION['user_id'] = $user['id'];
|
||||
$_SESSION['user_name'] = $user['name'];
|
||||
$_SESSION['user_role'] = $user['role'];
|
||||
|
||||
// Redirect to home page
|
||||
header("Location: index.php");
|
||||
exit();
|
||||
} else {
|
||||
$errors[] = 'Invalid email or password.';
|
||||
}
|
||||
} catch (PDOException $e) {
|
||||
$errors[] = "Database error: Could not log in.";
|
||||
// In a real app, you would log this error.
|
||||
// error_log("Login failed: " . $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Login - Event Platform</title>
|
||||
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
|
||||
</head>
|
||||
<body class="bg-light">
|
||||
|
||||
<?php require_once './includes/header.php'; ?>
|
||||
|
||||
<main class="container mt-5 pt-5">
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-md-6 col-lg-5">
|
||||
<div class="card border-0 shadow-lg">
|
||||
<div class="card-body p-4 p-md-5">
|
||||
<h2 class="card-title text-center mb-4" style="font-weight: 700;">Login to Your Account</h2>
|
||||
|
||||
<?php if (!empty($errors)): ?>
|
||||
<div class="alert alert-danger" role="alert">
|
||||
<?php foreach ($errors as $error): ?>
|
||||
<p class="mb-0"><?php echo htmlspecialchars($error); ?></p>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<form action="login.php" method="POST" novalidate>
|
||||
<div class="mb-3">
|
||||
<label for="email" class="form-label">Email address</label>
|
||||
<input type="email" class="form-control" id="email" name="email" value="<?php echo htmlspecialchars($email); ?>" required>
|
||||
</div>
|
||||
<div class="mb-4">
|
||||
<label for="password" class="form-label">Password</label>
|
||||
<input type="password" class="form-control" id="password" name="password" required>
|
||||
</div>
|
||||
<div class="d-grid">
|
||||
<button type="submit" class="btn btn-primary btn-lg" style="background-color: #4F46E5;">Login</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<p class="text-center mt-4">
|
||||
Don't have an account? <a href="register.php">Sign up</a>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<footer class="text-center py-4 text-muted fixed-bottom bg-light">
|
||||
<p>© <?php echo date("Y"); ?> EventPlatform. All rights reserved.</p>
|
||||
</footer>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
23
logout.php
Normal file
23
logout.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
session_start();
|
||||
|
||||
// Unset all of the session variables.
|
||||
$_SESSION = [];
|
||||
|
||||
// If it's desired to kill the session, also delete the session cookie.
|
||||
// Note: This will destroy the session, and not just the session data!
|
||||
if (ini_get("session.use_cookies")) {
|
||||
$params = session_get_cookie_params();
|
||||
setcookie(session_name(), '', time() - 42000,
|
||||
$params["path"], $params["domain"],
|
||||
$params["secure"], $params["httponly"]
|
||||
);
|
||||
}
|
||||
|
||||
// Finally, destroy the session.
|
||||
session_destroy();
|
||||
|
||||
// Redirect to homepage
|
||||
header("Location: index.php");
|
||||
exit();
|
||||
?>
|
||||
97
manager_dashboard.php
Normal file
97
manager_dashboard.php
Normal file
@ -0,0 +1,97 @@
|
||||
<?php
|
||||
session_start();
|
||||
|
||||
if (!isset($_SESSION['user_id']) || $_SESSION['role'] !== 'manager') {
|
||||
header('Location: login.php');
|
||||
exit();
|
||||
}
|
||||
|
||||
require_once 'db/config.php';
|
||||
$conn = db();
|
||||
|
||||
$manager_id = $_SESSION['user_id'];
|
||||
|
||||
// Fetch events created by the manager
|
||||
$stmt = $conn->prepare("SELECT * FROM events WHERE created_by = :manager_id ORDER BY created_at DESC");
|
||||
$stmt->bindParam(':manager_id', $manager_id, PDO::PARAM_INT);
|
||||
$stmt->execute();
|
||||
$events = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Manager Dashboard - EventPlatform</title>
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<?php require_once './includes/header.php'; ?>
|
||||
|
||||
<div class="container mt-5">
|
||||
<h1 class="mb-4">Manager Dashboard</h1>
|
||||
|
||||
<div class="card mb-4">
|
||||
<div class="card-header">
|
||||
Create New Event
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<form action="create_event.php" method="POST">
|
||||
<div class="mb-3">
|
||||
<label for="name" class="form-label">Event Name</label>
|
||||
<input type="text" class="form-control" id="name" name="name" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="description" class="form-label">Description</label>
|
||||
<textarea class="form-control" id="description" name="description" rows="3" required></textarea>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-md-6 mb-3">
|
||||
<label for="date" class="form-label">Date</label>
|
||||
<input type="date" class="form-control" id="date" name="date" required>
|
||||
</div>
|
||||
<div class="col-md-6 mb-3">
|
||||
<label for="location" class="form-label">Location</label>
|
||||
<input type="text" class="form-control" id="location" name="location" required>
|
||||
</div>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary">Create Event</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
Your Events
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Date</th>
|
||||
<th>Location</th>
|
||||
<th>Status</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($events as $event): ?>
|
||||
<tr>
|
||||
<td><?php echo htmlspecialchars($event['name']); ?></td>
|
||||
<td><?php echo htmlspecialchars($event['date']); ?></td>
|
||||
<td><?php echo htmlspecialchars($event['location']); ?></td>
|
||||
<td><span class="badge bg-<?php echo $event['status'] === 'accepted' ? 'success' : ($event['status'] === 'rejected' ? 'danger' : 'warning'); ?>"><?php echo htmlspecialchars(ucfirst($event['status'] ?? '')); ?></span></td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
66
my_tickets.php
Normal file
66
my_tickets.php
Normal file
@ -0,0 +1,66 @@
|
||||
<?php
|
||||
session_start();
|
||||
|
||||
if (!isset($_SESSION['user_id'])) {
|
||||
header('Location: login.php');
|
||||
exit();
|
||||
}
|
||||
|
||||
require_once 'db/config.php';
|
||||
$conn = db();
|
||||
|
||||
$user_id = $_SESSION['user_id'];
|
||||
|
||||
// Fetch tickets for the user
|
||||
$stmt = $conn->prepare("SELECT events.name, events.date, events.location FROM tickets JOIN events ON tickets.event_id = events.id WHERE tickets.user_id = :user_id ORDER BY events.date ASC");
|
||||
$stmt->bindParam(':user_id', $user_id, PDO::PARAM_INT);
|
||||
$stmt->execute();
|
||||
$tickets = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>My Tickets - EventPlatform</title>
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<?php require_once './includes/header.php'; ?>
|
||||
|
||||
<div class="container mt-5">
|
||||
<h1 class="mb-4">My Tickets</h1>
|
||||
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
Your Purchased Tickets
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Event Name</th>
|
||||
<th>Date</th>
|
||||
<th>Location</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($tickets as $ticket): ?>
|
||||
<tr>
|
||||
<td><?php echo htmlspecialchars($ticket['name']); ?></td>
|
||||
<td><?php echo htmlspecialchars($ticket['date']); ?></td>
|
||||
<td><?php echo htmlspecialchars($ticket['location']); ?></td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
134
register.php
Normal file
134
register.php
Normal file
@ -0,0 +1,134 @@
|
||||
<?php
|
||||
require_once 'db/config.php';
|
||||
|
||||
$name = '';
|
||||
$email = '';
|
||||
$errors = [];
|
||||
$success_message = '';
|
||||
|
||||
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||
$name = trim($_POST['name'] ?? '');
|
||||
$email = trim($_POST['email'] ?? '');
|
||||
$password = $_POST['password'] ?? '';
|
||||
$password_confirm = $_POST['password_confirm'] ?? '';
|
||||
|
||||
if (empty($name)) {
|
||||
$errors[] = 'Name is required.';
|
||||
}
|
||||
|
||||
if (empty($email) || !filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
||||
$errors[] = 'A valid email is required.';
|
||||
} else {
|
||||
$pdo = db();
|
||||
$stmt = $pdo->prepare("SELECT id FROM users WHERE email = ?");
|
||||
$stmt->execute([$email]);
|
||||
if ($stmt->fetch()) {
|
||||
$errors[] = 'Email address is already in use.';
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($password)) {
|
||||
$errors[] = 'Password is required.';
|
||||
} elseif (strlen($password) < 8) {
|
||||
$errors[] = 'Password must be at least 8 characters long.';
|
||||
} elseif ($password !== $password_confirm) {
|
||||
$errors[] = 'Passwords do not match.';
|
||||
}
|
||||
|
||||
if (empty($errors)) {
|
||||
$hashed_password = password_hash($password, PASSWORD_DEFAULT);
|
||||
|
||||
try {
|
||||
$pdo = db();
|
||||
$stmt = $pdo->prepare("INSERT INTO users (name, email, password, role) VALUES (?, ?, ?, 'user')");
|
||||
$stmt->execute([$name, $email, $hashed_password]);
|
||||
|
||||
$success_message = 'Registration successful! You can now <a href="login.php" class="alert-link">log in</a>.';
|
||||
// Clear form fields on success
|
||||
$name = '';
|
||||
$email = '';
|
||||
|
||||
} catch (PDOException $e) {
|
||||
$errors[] = "Database error: Could not register user.";
|
||||
// In a real app, you would log this error.
|
||||
// error_log("Registration failed: " . $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Register - Event Platform</title>
|
||||
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
|
||||
</head>
|
||||
<body class="bg-light">
|
||||
|
||||
<?php require_once './includes/header.php'; ?>
|
||||
|
||||
<main class="container mt-5 pt-5">
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-md-6 col-lg-5">
|
||||
<div class="card border-0 shadow-lg">
|
||||
<div class="card-body p-4 p-md-5">
|
||||
<h2 class="card-title text-center mb-4" style="font-weight: 700;">Create Your Account</h2>
|
||||
|
||||
<?php if (!empty($errors)): ?>
|
||||
<div class="alert alert-danger" role="alert">
|
||||
<?php foreach ($errors as $error): ?>
|
||||
<p class="mb-0"><?php echo htmlspecialchars($error); ?></p>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ($success_message): ?>
|
||||
<div class="alert alert-success" role="alert">
|
||||
<?php echo $success_message; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if (!$success_message): ?>
|
||||
<form action="register.php" method="POST" novalidate>
|
||||
<div class="mb-3">
|
||||
<label for="name" class="form-label">Full Name</label>
|
||||
<input type="text" class="form-control" id="name" name="name" value="<?php echo htmlspecialchars($name); ?>" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="email" class="form-label">Email address</label>
|
||||
<input type="email" class="form-control" id="email" name="email" value="<?php echo htmlspecialchars($email); ?>" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="password" class="form-label">Password</label>
|
||||
<input type="password" class="form-control" id="password" name="password" required>
|
||||
<div class="form-text">Password must be at least 8 characters long.</div>
|
||||
</div>
|
||||
<div class="mb-4">
|
||||
<label for="password_confirm" class="form-label">Confirm Password</label>
|
||||
<input type="password" class="form-control" id="password_confirm" name="password_confirm" required>
|
||||
</div>
|
||||
<div class="d-grid">
|
||||
<button type="submit" class="btn btn-primary btn-lg" style="background-color: #4F46E5;">Register</button>
|
||||
</div>
|
||||
</form>
|
||||
<?php endif; ?>
|
||||
|
||||
<p class="text-center mt-4">
|
||||
Already have an account? <a href="login.php">Log in</a>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<footer class="text-center py-4 text-muted fixed-bottom bg-light">
|
||||
<p>© <?php echo date("Y"); ?> EventPlatform. All rights reserved.</p>
|
||||
</footer>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
31
update_event_status.php
Normal file
31
update_event_status.php
Normal file
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
session_start();
|
||||
|
||||
if (!isset($_SESSION['user_id']) || $_SESSION['role'] !== 'admin') {
|
||||
header('Location: login.php');
|
||||
exit();
|
||||
}
|
||||
|
||||
if (isset($_GET['id']) && isset($_GET['status'])) {
|
||||
require_once 'db/config.php';
|
||||
|
||||
$event_id = $_GET['id'];
|
||||
$status = $_GET['status'];
|
||||
|
||||
if ($status === 'accepted' || $status === 'rejected') {
|
||||
try {
|
||||
$conn = db();
|
||||
$stmt = $conn->prepare("UPDATE events SET status = :status WHERE id = :id");
|
||||
$stmt->bindParam(':status', $status);
|
||||
$stmt->bindParam(':id', $event_id, PDO::PARAM_INT);
|
||||
$stmt->execute();
|
||||
} catch (PDOException $e) {
|
||||
// Handle database error
|
||||
header('Location: admin_dashboard.php?error=db_error');
|
||||
exit();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
header('Location: admin_dashboard.php');
|
||||
exit();
|
||||
Loading…
x
Reference in New Issue
Block a user