141 lines
3.6 KiB
PHP
141 lines
3.6 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
session_set_cookie_params(['path' => '/']);
|
|
session_start();
|
|
|
|
// If the user is not logged in, redirect to the login page
|
|
if (!isset($_SESSION['user'])) {
|
|
header('Location: login.php');
|
|
exit;
|
|
}
|
|
|
|
$eventsJson = file_get_contents('events.json');
|
|
$events = json_decode($eventsJson, true);
|
|
|
|
$eventId = $_GET['id'] ?? null;
|
|
|
|
if ($eventId === null || !isset($events[$eventId])) {
|
|
// Redirect to index if event not found
|
|
header('Location: index.php');
|
|
exit;
|
|
}
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
// Delete the event
|
|
unset($events[$eventId]);
|
|
|
|
// Re-index the array to prevent issues with json_encode
|
|
$events = array_values($events);
|
|
|
|
file_put_contents('events.json', json_encode($events, JSON_PRETTY_PRINT));
|
|
|
|
header('Location: index.php');
|
|
exit;
|
|
}
|
|
|
|
$event = $events[$eventId];
|
|
|
|
?>
|
|
<!doctype html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="utf-8" />
|
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
<title>Delete Event</title>
|
|
<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;700&display=swap" rel="stylesheet">
|
|
<style>
|
|
:root {
|
|
--bg-color-start: #6a11cb;
|
|
--bg-color-end: #2575fc;
|
|
--text-color: #ffffff;
|
|
--card-bg-color: rgba(255, 255, 255, 0.05);
|
|
--card-border-color: rgba(255, 255, 255, 0.2);
|
|
--button-text-color: #2575fc;
|
|
--danger-color: #ff4d4d;
|
|
}
|
|
body {
|
|
margin: 0;
|
|
font-family: 'Inter', sans-serif;
|
|
background: linear-gradient(45deg, var(--bg-color-start), var(--bg-color-end));
|
|
color: var(--text-color);
|
|
display: flex;
|
|
justify-content: center;
|
|
align-items: center;
|
|
min-height: 100vh;
|
|
text-align: center;
|
|
}
|
|
main {
|
|
padding: 2rem;
|
|
width: 80%;
|
|
max-width: 600px;
|
|
}
|
|
.card {
|
|
background: var(--card-bg-color);
|
|
border: 1px solid var(--card-border-color);
|
|
border-radius: 16px;
|
|
padding: 2rem;
|
|
backdrop-filter: blur(20px);
|
|
-webkit-backdrop-filter: blur(20px);
|
|
box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.1);
|
|
text-align: left;
|
|
}
|
|
h1 {
|
|
font-size: 2rem;
|
|
font-weight: 700;
|
|
margin-bottom: 1rem;
|
|
}
|
|
p {
|
|
margin-bottom: 2rem;
|
|
}
|
|
.event-details {
|
|
background: rgba(0,0,0,0.1);
|
|
padding: 1rem;
|
|
border-radius: 8px;
|
|
margin-bottom: 2rem;
|
|
}
|
|
.event-title {
|
|
font-weight: 700;
|
|
}
|
|
.actions {
|
|
display: flex;
|
|
justify-content: flex-end;
|
|
gap: 1rem;
|
|
}
|
|
button, a {
|
|
text-decoration: none;
|
|
border: none;
|
|
padding: 1rem 2rem;
|
|
border-radius: 8px;
|
|
cursor: pointer;
|
|
font-weight: 700;
|
|
transition: background-color 0.3s, color 0.3s;
|
|
}
|
|
.delete-btn {
|
|
background-color: var(--danger-color);
|
|
color: var(--text-color);
|
|
}
|
|
.cancel-link {
|
|
background-color: var(--text-color);
|
|
color: var(--button-text-color);
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<main>
|
|
<div class="card">
|
|
<h1>Delete Event</h1>
|
|
<p>Are you sure you want to delete this event? This action cannot be undone.</p>
|
|
<div class="event-details">
|
|
<div class="event-title"><?= htmlspecialchars($event['title']) ?></div>
|
|
<div><?= htmlspecialchars($event['time']) ?></div>
|
|
</div>
|
|
<form method="POST" class="actions">
|
|
<a href="index.php" class="cancel-link">Cancel</a>
|
|
<button type="submit" class="delete-btn">Yes, Delete</button>
|
|
</form>
|
|
</div>
|
|
</main>
|
|
</body>
|
|
</html>
|