-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathevents.php
More file actions
129 lines (120 loc) · 5.51 KB
/
events.php
File metadata and controls
129 lines (120 loc) · 5.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<?php
$dbConfigPath = __DIR__ . '/dbconfig.php';
require_once $dbConfigPath;
$search = isset($_GET['search']) ? $_GET['search'] : '';
$sort = isset($_GET['sort']) ? $_GET['sort'] : 'date_desc';
$query = "SELECT * FROM events";
$conditions = [];
if (!empty($search)) {
$searchEscaped = $conn->real_escape_string($search);
$conditions[] = "event_name LIKE '%$searchEscaped%' OR location LIKE '%$searchEscaped%'";
}
if (!empty($conditions)) {
$query .= " WHERE " . implode(" AND ", $conditions);
}
if ($sort === 'date_desc') {
$query .= " ORDER BY created_at DESC, id DESC";
} elseif ($sort === 'date_asc') {
$query .= " ORDER BY created_at ASC, id ASC";
} elseif ($sort === 'name_asc') {
$query .= " ORDER BY event_name ASC";
} elseif ($sort === 'name_desc') {
$query .= " ORDER BY event_name DESC";
} else {
$query .= " ORDER BY created_at DESC, id DESC";
}
$result = $conn->query($query);
$events = [];
if ($result) {
while ($row = $result->fetch_assoc()) {
$events[] = $row;
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Events Dashboard - Carolinian Events</title>
<link rel="stylesheet" href="style.css">
<link href="https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@300;400;500;600;700;800&display=swap" rel="stylesheet">
</head>
<body>
<nav class="navbar scrolled" id="navbar">
<div class="nav-container">
<a href="index.php" class="brand">Carolinian<span>Events</span></a>
<div class="nav-links">
<a href="index.php">Home</a>
<a href="view.php">Events Dashboard</a>
</div>
</div>
</nav>
<div class="dashboard-container">
<div class="dashboard-header reveal">
<h1>Events Dashboard</h1>
<a href="create.php" class="btn btn-primary">+ Add New Event</a>
</div>
<div class="dashboard-controls reveal stagger-1">
<form method="GET" action="events.php" class="controls-form">
<div class="control-group">
<input type="text" name="search" class="search-input" placeholder="Search events..." value="<?= htmlspecialchars($search) ?>">
</div>
<div class="control-group">
<select name="sort" class="sort-select" onchange="this.form.submit()">
<option value="date_desc" <?= $sort == 'date_desc' ? 'selected' : '' ?>>Newest First</option>
<option value="date_asc" <?= $sort == 'date_asc' ? 'selected' : '' ?>>Oldest First</option>
<option value="name_asc" <?= $sort == 'name_asc' ? 'selected' : '' ?>>Name A-Z</option>
<option value="name_desc" <?= $sort == 'name_desc' ? 'selected' : '' ?>>Name Z-A</option>
</select>
</div>
<noscript><button type="submit" class="btn btn-secondary noscript-apply">Apply</button></noscript>
</form>
</div>
<div class="table-container reveal stagger-2">
<table class="events-table">
<thead>
<tr>
<th>#</th>
<th>Event Name</th>
<th>Date & Time</th>
<th>Location</th>
<th>Category</th>
<th>Status</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php if (empty($events)): ?>
<tr>
<td colspan="7" class="empty-row">No events found.</td>
</tr>
<?php else: ?>
<?php foreach ($events as $index => $event): ?>
<tr>
<td data-label="#"><?= $index + 1 ?></td>
<td data-label="Event Name" class="event-name-cell"><?= htmlspecialchars($event['event_name']) ?></td>
<td data-label="Date & Time">
<?= date('M d, Y', strtotime($event['event_date'])) ?><br>
<small class="time-muted"><?= date('h:i A', strtotime($event['event_time'])) ?></small>
</td>
<td data-label="Location"><?= htmlspecialchars($event['location']) ?></td>
<td data-label="Category"><?= htmlspecialchars($event['category']) ?></td>
<td data-label="Status">
<span class="status-badge status-<?= $event['status'] ?>"><?= $event['status'] ?></span>
</td>
<td data-label="Actions" class="action-links">
<a href="view.php?id=<?= $event['id'] ?>" class="action-view">View</a>
<a href="update.php?id=<?= $event['id'] ?>" class="action-edit">Edit</a>
<a href="#" onclick="confirmDelete(<?= $event['id'] ?>)" class="action-delete">Delete</a>
</td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</tbody>
</table>
</div>
</div>
<script src="script.js"></script>
</body>
</html>