0.2 Read events from file and add/delete events
This commit is contained in:
parent
5af5075ae6
commit
8e8aeb4a48
@ -1,56 +0,0 @@
|
||||
<?php
|
||||
session_start();
|
||||
|
||||
if (!isset($_SESSION['user'])) {
|
||||
header('Location: login.php');
|
||||
exit;
|
||||
}
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Dashboard</title>
|
||||
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="d-flex justify-content-between align-items-center pt-3 pb-2 mb-3 border-bottom">
|
||||
<h1 class="h2">Dashboard</h1>
|
||||
<a href="logout.php" class="btn btn-outline-primary">Logout</a>
|
||||
</div>
|
||||
|
||||
<h2>Welcome, <?php echo htmlspecialchars($_SESSION['user']['name']); ?>!</h2>
|
||||
|
||||
<div class="mt-4">
|
||||
<h3>Event Schedule</h3>
|
||||
<p><em>(Coming soon)</em></p>
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">#</th>
|
||||
<th scope="col">Event</th>
|
||||
<th scope="col">Date</th>
|
||||
<th scope="col">Time</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<th scope="row">1</th>
|
||||
<td>Team Meeting</td>
|
||||
<td>2025-09-01</td>
|
||||
<td>10:00 AM</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">2</th>
|
||||
<td>Project Deadline</td>
|
||||
<td>2025-09-05</td>
|
||||
<td>5:00 PM</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
141
delete_event.php
Normal file
141
delete_event.php
Normal file
@ -0,0 +1,141 @@
|
||||
<?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>
|
||||
143
edit_event.php
Normal file
143
edit_event.php
Normal file
@ -0,0 +1,143 @@
|
||||
<?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;
|
||||
$event = null;
|
||||
|
||||
if ($eventId !== null && isset($events[$eventId])) {
|
||||
$event = $events[$eventId];
|
||||
} else {
|
||||
// Redirect to index if event not found
|
||||
header('Location: index.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
// Update the event
|
||||
$events[$eventId]['title'] = $_POST['title'] ?? $event['title'];
|
||||
$events[$eventId]['time'] = $_POST['time'] ?? $event['time'];
|
||||
$events[$eventId]['details'] = $_POST['details'] ?? $event['details'];
|
||||
|
||||
file_put_contents('events.json', json_encode($events, JSON_PRETTY_PRINT));
|
||||
|
||||
header('Location: index.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
?>
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<title>Edit 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;
|
||||
--input-bg-color: rgba(255, 255, 255, 0.1);
|
||||
}
|
||||
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: 2rem;
|
||||
}
|
||||
.form-group {
|
||||
margin-bottom: 1.5rem;
|
||||
}
|
||||
label {
|
||||
display: block;
|
||||
margin-bottom: 0.5rem;
|
||||
font-weight: 700;
|
||||
}
|
||||
input, textarea {
|
||||
width: 100%;
|
||||
padding: 1rem;
|
||||
border-radius: 8px;
|
||||
border: 1px solid var(--card-border-color);
|
||||
background-color: var(--input-bg-color);
|
||||
color: var(--text-color);
|
||||
font-family: 'Inter', sans-serif;
|
||||
}
|
||||
button {
|
||||
background-color: var(--text-color);
|
||||
color: var(--button-text-color);
|
||||
border: none;
|
||||
padding: 1rem 2rem;
|
||||
border-radius: 8px;
|
||||
cursor: pointer;
|
||||
font-weight: 700;
|
||||
transition: background-color 0.3s, color 0.3s;
|
||||
}
|
||||
button:hover {
|
||||
background-color: #f0f0f0;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<main>
|
||||
<div class="card">
|
||||
<h1>Edit Event</h1>
|
||||
<form method="POST">
|
||||
<div class="form-group">
|
||||
<label for="title">Event Title</label>
|
||||
<input type="text" id="title" name="title" value="<?= htmlspecialchars($event['title']) ?>" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="time">Event Time</label>
|
||||
<input type="text" id="time" name="time" value="<?= htmlspecialchars($event['time']) ?>" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="details">Event Details</label>
|
||||
<textarea id="details" name="details" rows="4" required><?= htmlspecialchars($event['details']) ?></textarea>
|
||||
</div>
|
||||
<button type="submit">Update Event</button>
|
||||
</form>
|
||||
</div>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
18
events.json
Normal file
18
events.json
Normal file
@ -0,0 +1,18 @@
|
||||
|
||||
[
|
||||
{
|
||||
"title": "Team Stand-up",
|
||||
"time": "Today, 9:00 AM",
|
||||
"details": "Daily check-in to sync on progress and blockers."
|
||||
},
|
||||
{
|
||||
"title": "Design Review",
|
||||
"time": "Today, 1:00 PM",
|
||||
"details": "Review the new dashboard mockups and provide feedback."
|
||||
},
|
||||
{
|
||||
"title": "Deployment",
|
||||
"time": "Today, 4:00 PM",
|
||||
"details": "Deploy the latest changes to the staging environment."
|
||||
}
|
||||
]
|
||||
146
index.php
146
index.php
@ -3,24 +3,21 @@ declare(strict_types=1);
|
||||
session_set_cookie_params(['path' => '/']);
|
||||
session_start();
|
||||
|
||||
if (isset($_SESSION['user'])) {
|
||||
header('Location: dashboard.php');
|
||||
// If the user is not logged in, redirect to the login page
|
||||
if (!isset($_SESSION['user'])) {
|
||||
header('Location: login.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
@ini_set('display_errors', '1');
|
||||
@error_reporting(E_ALL);
|
||||
@date_default_timezone_set('UTC');
|
||||
$user = $_SESSION['user'];
|
||||
|
||||
$phpVersion = PHP_VERSION;
|
||||
$now = date('Y-m-d H:i:s');
|
||||
?>
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<title>New Style</title>
|
||||
<title>Dashboard</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">
|
||||
@ -29,8 +26,9 @@ $now = date('Y-m-d H:i:s');
|
||||
--bg-color-start: #6a11cb;
|
||||
--bg-color-end: #2575fc;
|
||||
--text-color: #ffffff;
|
||||
--card-bg-color: rgba(255, 255, 255, 0.01);
|
||||
--card-border-color: rgba(255, 255, 255, 0.1);
|
||||
--card-bg-color: rgba(255, 255, 255, 0.05);
|
||||
--card-border-color: rgba(255, 255, 255, 0.2);
|
||||
--button-text-color: #2575fc;
|
||||
}
|
||||
body {
|
||||
margin: 0;
|
||||
@ -42,26 +40,11 @@ $now = date('Y-m-d H:i:s');
|
||||
align-items: center;
|
||||
min-height: 100vh;
|
||||
text-align: center;
|
||||
overflow: hidden;
|
||||
position: relative;
|
||||
}
|
||||
body::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 100 100"><path d="M-10 10L110 10M10 -10L10 110" stroke-width="1" stroke="rgba(255,255,255,0.05)"/></svg>');
|
||||
animation: bg-pan 20s linear infinite;
|
||||
z-index: -1;
|
||||
}
|
||||
@keyframes bg-pan {
|
||||
0% { background-position: 0% 0%; }
|
||||
100% { background-position: 100% 100%; }
|
||||
}
|
||||
main {
|
||||
padding: 2rem;
|
||||
width: 80%;
|
||||
max-width: 960px;
|
||||
}
|
||||
.card {
|
||||
background: var(--card-bg-color);
|
||||
@ -72,41 +55,104 @@ $now = date('Y-m-d H:i:s');
|
||||
-webkit-backdrop-filter: blur(20px);
|
||||
box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
.header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 2rem;
|
||||
}
|
||||
h1 {
|
||||
font-size: 3rem;
|
||||
font-size: 2rem;
|
||||
font-weight: 700;
|
||||
margin: 0 0 1rem;
|
||||
letter-spacing: -1px;
|
||||
margin: 0;
|
||||
text-align: left;
|
||||
}
|
||||
p {
|
||||
margin: 0.5rem 0;
|
||||
font-size: 1.1rem;
|
||||
a.logout {
|
||||
color: var(--text-color);
|
||||
text-decoration: none;
|
||||
border: 1px solid var(--card-border-color);
|
||||
padding: 0.75rem 1.5rem;
|
||||
border-radius: 8px;
|
||||
transition: background-color 0.3s, color 0.3s;
|
||||
}
|
||||
code {
|
||||
background: rgba(0,0,0,0.2);
|
||||
padding: 2px 6px;
|
||||
border-radius: 4px;
|
||||
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
|
||||
a.logout:hover {
|
||||
background-color: var(--text-color);
|
||||
color: var(--button-text-color);
|
||||
}
|
||||
footer {
|
||||
position: absolute;
|
||||
bottom: 1rem;
|
||||
font-size: 0.8rem;
|
||||
opacity: 0.7;
|
||||
.schedule {
|
||||
text-align: left;
|
||||
}
|
||||
h2 {
|
||||
font-size: 1.5rem;
|
||||
margin-bottom: 1rem;
|
||||
border-bottom: 1px solid var(--card-border-color);
|
||||
padding-bottom: 0.5rem;
|
||||
}
|
||||
.event {
|
||||
background: rgba(0,0,0,0.1);
|
||||
padding: 1rem;
|
||||
border-radius: 8px;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
.event-title {
|
||||
font-weight: 700;
|
||||
}
|
||||
.event-time {
|
||||
font-size: 0.9rem;
|
||||
opacity: 0.8;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
.event-actions {
|
||||
margin-top: 1rem;
|
||||
}
|
||||
.event-actions a {
|
||||
color: var(--text-color);
|
||||
text-decoration: none;
|
||||
border: 1px solid var(--card-border-color);
|
||||
padding: 0.5rem 1rem;
|
||||
border-radius: 8px;
|
||||
transition: background-color 0.3s, color 0.3s;
|
||||
margin-right: 0.5rem;
|
||||
}
|
||||
.event-actions a:hover {
|
||||
background-color: var(--text-color);
|
||||
color: var(--button-text-color);
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<main>
|
||||
<div class="card">
|
||||
<h1>Welcome!</h1>
|
||||
<p>Your project is ready to conquer the peaks.</p>
|
||||
<p>PHP version: <code><?= htmlspecialchars($phpVersion) ?></code></p>
|
||||
<p><a href="logout.php">Logout</a></p>
|
||||
<div class="header">
|
||||
<h1>Welcome, <?= htmlspecialchars($user['name']) ?>!</h1>
|
||||
<a href="logout.php" class="logout">Logout</a>
|
||||
</div>
|
||||
|
||||
<div class="schedule">
|
||||
<h2>Event Schedule</h2>
|
||||
<?php
|
||||
$eventsJson = file_get_contents('events.json');
|
||||
$events = json_decode($eventsJson, true);
|
||||
|
||||
if (json_last_error() === JSON_ERROR_NONE && !empty($events)) {
|
||||
foreach ($events as $index => $event) {
|
||||
echo '<div class="event">';
|
||||
echo '<div class="event-title">' . htmlspecialchars($event['title']) . '</div>';
|
||||
echo '<div class="event-time">' . htmlspecialchars($event['time']) . '</div>';
|
||||
echo '<p>' . htmlspecialchars($event['details']) . '</p>';
|
||||
echo '<div class="event-actions">';
|
||||
echo '<a href="edit_event.php?id=' . $index . '">Edit</a>';
|
||||
echo '<a href="delete_event.php?id=' . $index . '">Delete</a>';
|
||||
echo '</div>';
|
||||
echo '</div>';
|
||||
}
|
||||
} else {
|
||||
echo '<p>No events scheduled.</p>';
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</main>
|
||||
<footer>
|
||||
Page updated: <?= htmlspecialchars($now) ?> (UTC)
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
||||
@ -12,7 +12,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
// Dummy authentication
|
||||
if ($username === 'admin' && $password === 'password') {
|
||||
$_SESSION['user'] = ['name' => 'Admin'];
|
||||
header('Location: dashboard.php');
|
||||
header('Location: index.php');
|
||||
exit;
|
||||
} else {
|
||||
$error = 'Invalid username or password';
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user