193 lines
7.1 KiB
PHP
193 lines
7.1 KiB
PHP
<?php
|
|
session_start();
|
|
require_once 'db/config.php';
|
|
|
|
// If the user is not logged in as admin, redirect to the login page.
|
|
if (!isset($_SESSION['user']) || $_SESSION['user'] !== 'admin') {
|
|
header('Location: login.php');
|
|
exit;
|
|
}
|
|
|
|
$attendee = null;
|
|
$message = '';
|
|
|
|
if (!isset($_GET['id']) && $_SERVER['REQUEST_METHOD'] !== 'POST') {
|
|
header('Location: admin.php');
|
|
exit;
|
|
}
|
|
|
|
$id = $_GET['id'] ?? $_POST['id'];
|
|
|
|
try {
|
|
$pdo = db();
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
// Update logic
|
|
$fields = ['first_name', 'last_name', 'email', 'company', 'how_did_you_hear', 'consented'];
|
|
$sql = 'UPDATE attendees SET ';
|
|
$params = [];
|
|
foreach ($fields as $field) {
|
|
if (isset($_POST[$field])) {
|
|
$sql .= "$field = ?, ";
|
|
$params[] = $_POST[$field];
|
|
}
|
|
}
|
|
$sql = rtrim($sql, ', ') . ' WHERE id = ?';
|
|
$params[] = $_POST['id'];
|
|
|
|
$stmt = $pdo->prepare($sql);
|
|
$stmt->execute($params);
|
|
header('Location: admin.php');
|
|
exit;
|
|
}
|
|
|
|
// Fetch logic
|
|
$stmt = $pdo->prepare('SELECT * FROM attendees WHERE id = ?');
|
|
$stmt->execute([$id]);
|
|
$attendee = $stmt->fetch(PDO::FETCH_ASSOC);
|
|
|
|
if (!$attendee) {
|
|
header('Location: admin.php');
|
|
exit;
|
|
}
|
|
|
|
} catch (PDOException $e) {
|
|
die("Database error: " . $e->getMessage());
|
|
}
|
|
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Edit Attendee</title>
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<link rel="preconnect" href="https://fonts.googleapis.com">
|
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
|
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&family=Space+Grotesk:wght@500;700&display=swap" rel="stylesheet">
|
|
<style>
|
|
:root {
|
|
--bg-start: #0b2083;
|
|
--bg-end: #1029a0;
|
|
--surface: rgba(11, 32, 131, 0.40);
|
|
--line: rgba(221, 226, 253, 0.18);
|
|
--text-main: #f3f9ff;
|
|
--text-soft: #dde2fd;
|
|
--accent: #2c4bd1;
|
|
--accent-strong: #1029a0;
|
|
--accent-soft: #bbc8fb;
|
|
--font-body: "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
|
|
--font-display: "Space Grotesk", "Inter", system-ui, sans-serif;
|
|
--button-shadow: 0 16px 30px rgba(11, 32, 131, 0.28);
|
|
}
|
|
body {
|
|
font-family: var(--font-body);
|
|
background:
|
|
radial-gradient(circle at top left, rgba(221, 226, 253, 0.22), transparent 28%),
|
|
linear-gradient(135deg, var(--bg-start) 0%, #1029a0 55%, var(--bg-end) 100%);
|
|
color: var(--text-main);
|
|
min-height: 100vh;
|
|
}
|
|
.container {
|
|
max-width: 700px;
|
|
padding-top: 3rem;
|
|
padding-bottom: 3rem;
|
|
}
|
|
h1 {
|
|
color: var(--text-main);
|
|
font-family: var(--font-display);
|
|
font-weight: 700;
|
|
letter-spacing: -0.04em;
|
|
margin-bottom: 1.5rem;
|
|
}
|
|
.form-label,
|
|
.btn {
|
|
font-family: var(--font-display);
|
|
}
|
|
form {
|
|
background: var(--surface);
|
|
border: 1px solid var(--line);
|
|
border-radius: 22px;
|
|
padding: 1.75rem;
|
|
box-shadow: 0 25px 60px rgba(3, 11, 25, 0.4);
|
|
backdrop-filter: blur(16px);
|
|
}
|
|
.form-label,
|
|
.form-check-label {
|
|
color: var(--text-soft);
|
|
}
|
|
.form-control {
|
|
background: rgba(221, 226, 253, 0.08);
|
|
border-color: rgba(221, 226, 253, 0.18);
|
|
color: var(--text-main);
|
|
}
|
|
.form-control:focus {
|
|
background: rgba(221, 226, 253, 0.10);
|
|
color: var(--text-main);
|
|
border-color: rgba(44, 75, 209, 0.65);
|
|
box-shadow: 0 0 0 0.2rem rgba(187, 200, 251, 0.18);
|
|
}
|
|
.btn {
|
|
border-radius: 14px;
|
|
font-weight: 700;
|
|
letter-spacing: 0.03em;
|
|
transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
|
|
}
|
|
.btn:hover {
|
|
transform: translateY(-1px);
|
|
}
|
|
.btn-primary {
|
|
background: linear-gradient(135deg, var(--accent) 0%, var(--accent-strong) 100%);
|
|
border: 1px solid rgba(221, 226, 253, 0.14);
|
|
box-shadow: var(--button-shadow);
|
|
}
|
|
.btn-secondary {
|
|
background: rgba(221, 226, 253, 0.12);
|
|
border-color: rgba(221, 226, 253, 0.22);
|
|
color: var(--text-main);
|
|
}
|
|
.btn-secondary:hover {
|
|
background: rgba(221, 226, 253, 0.18);
|
|
border-color: rgba(221, 226, 253, 0.32);
|
|
box-shadow: 0 14px 26px rgba(11, 32, 131, 0.18);
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="container">
|
|
<h1 class="mb-4">Edit Attendee #<?= htmlspecialchars($attendee['id']) ?></h1>
|
|
<form method="POST">
|
|
<input type="hidden" name="id" value="<?= htmlspecialchars($attendee['id']) ?>">
|
|
<div class="mb-3">
|
|
<label for="first_name" class="form-label">First Name</label>
|
|
<input type="text" class="form-control" id="first_name" name="first_name" value="<?= htmlspecialchars($attendee['first_name']) ?>">
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="last_name" class="form-label">Last Name</label>
|
|
<input type="text" class="form-control" id="last_name" name="last_name" value="<?= htmlspecialchars($attendee['last_name']) ?>">
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="email" class="form-label">Email</label>
|
|
<input type="email" class="form-control" id="email" name="email" value="<?= htmlspecialchars($attendee['email']) ?>">
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="company" class="form-label">Company</label>
|
|
<input type="text" class="form-control" id="company" name="company" value="<?= htmlspecialchars($attendee['company']) ?>">
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="how_did_you_hear" class="form-label">How did you hear?</label>
|
|
<input type="text" class="form-control" id="how_did_you_hear" name="how_did_you_hear" value="<?= htmlspecialchars($attendee['how_did_you_hear']) ?>">
|
|
</div>
|
|
<div class="mb-3 form-check">
|
|
<input type="hidden" name="consented" value="0">
|
|
<input type="checkbox" class="form-check-input" id="consented" name="consented" value="1" <?= $attendee['consented'] ? 'checked' : '' ?>>
|
|
<label class="form-check-label" for="consented">Consented</label>
|
|
</div>
|
|
<button type="submit" class="btn btn-primary">Save Changes</button>
|
|
<a href="admin.php" class="btn btn-secondary">Cancel</a>
|
|
</form>
|
|
</div>
|
|
</body>
|
|
</html>
|