-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathevent_management.php
More file actions
345 lines (290 loc) · 9.93 KB
/
event_management.php
File metadata and controls
345 lines (290 loc) · 9.93 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
<?php
session_start();
require_once('db.php');
// Check if user is logged in and has the correct user type
if (!isset($_SESSION['user_id'])) {
// Redirect to login page if not logged in
header('Location: login.php');
exit;
}
// Additionally, check for the user type to be 'Patron'
if (!isset($_SESSION['user_type']) || $_SESSION['user_type'] !== 'Patron') {
// Redirect to the main page or a not authorized notification page
header('Location: index.php'); // Adjust the redirection target as necessary
exit;
}
// Pagination variables
$eventsPerPage = 5; // Number of events to display per page
$page = isset($_GET['page']) ? $_GET['page'] : 1; // Current page, default is 1
// To calculate the offset for SQL query
$offset = ($page - 1) * $eventsPerPage;
// Get the logged-in user's full name
$userID = $_SESSION['user_id'];
$stmt = $db->prepare("SELECT full_name FROM users WHERE id = :id");
$stmt->bindParam(':id', $userID, PDO::PARAM_INT);
$stmt->execute();
$user = $stmt->fetch(PDO::FETCH_ASSOC);
$fullName = $user['full_name'];
// Get filter parameters
$startDate = isset($_GET['startDate']) ? $_GET['startDate'] : null;
$endDate = isset($_GET['endDate']) ? $_GET['endDate'] : null;
// To build the WHERE clause for date filtering
$whereClause = "WHERE organizing_party = :fullName";
if ($startDate && $endDate) {
$whereClause .= " AND event_date BETWEEN :startDate AND :endDate";
} elseif ($startDate) {
$whereClause .= " AND event_date >= :startDate";
} elseif ($endDate) {
$whereClause .= " AND event_date <= :endDate";
}
// Retrieve events for the current page with filtering
$stmt = $db->prepare("SELECT * FROM events $whereClause LIMIT :offset, :limit");
$stmt->bindParam(':fullName', $fullName, PDO::PARAM_STR);
if ($startDate) {
$stmt->bindParam(':startDate', $startDate, PDO::PARAM_STR);
}
if ($endDate) {
$stmt->bindParam(':endDate', $endDate, PDO::PARAM_STR);
}
$stmt->bindParam(':offset', $offset, PDO::PARAM_INT);
$stmt->bindParam(':limit', $eventsPerPage, PDO::PARAM_INT);
$stmt->execute();
$events = $stmt->fetchAll(PDO::FETCH_ASSOC);
// Count total number of events with filtering
$totalEventsStmt = $db->prepare("SELECT COUNT(*) FROM events $whereClause");
$totalEventsStmt->bindParam(':fullName', $fullName, PDO::PARAM_STR);
if ($startDate) {
$totalEventsStmt->bindParam(':startDate', $startDate, PDO::PARAM_STR);
}
if ($endDate) {
$totalEventsStmt->bindParam(':endDate', $endDate, PDO::PARAM_STR);
}
$totalEventsStmt->execute();
$totalEvents = $totalEventsStmt->fetchColumn();
// To calculate total number of pages
$totalPages = ceil($totalEvents / $eventsPerPage);
// To check if the user is logged in and their type
$isLoggedIn = isset($_SESSION['user_id']) && $_SESSION['user_type'] === 'Patron';
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="TemplateMo">
<link
href="https://fonts.googleapis.com/css?family=Roboto:100,100i,300,300i,400,400i,500,500i,700,700i,900,900i&display=swap"
rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css"
integrity="sha512-iecdLmaskl7CVkqkXNQ/ZH/XLlvWZOJyj7Yy7tcenmpD1ypASozpmT/E0iPtmFIB46ZmdtAc9eNBvH0H/ZpiBw=="
crossorigin="anonymous" referrerpolicy="no-referrer" />
<title>Mingle:: APIIT's Blog</title>
<!-- Bootstrap core CSS -->
<link href="vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
<!-- Bootstrap core JavaScript -->
<script src="vendor/jquery/jquery.min.js"></script>
<script src="vendor/bootstrap/js/bootstrap.bundle.min.js"></script>
<!-- Additional CSS Files -->
<link rel="stylesheet" href="assets/css/fontawesome.css">
<link rel="stylesheet" href="assets/css/templatemo-stand-blog.css">
<link rel="stylesheet" href="assets/css/owl.css">
<style>
.header-1 {
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}
.event-container {
max-width: 1200px;
margin: 20px auto;
margin-bottom: 5%;
padding: 20px;
background-color: #fff;
border-radius: 5px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
h2 {
text-align: center;
}
table {
width: 100%;
border-collapse: collapse;
margin-top: 20px;
}
th,
td {
border: 1px solid #ddd;
padding: 8px;
text-align: left;
}
th {
background-color: #f2f2f2;
}
tr:nth-child(even) {
background-color: #f9f9f9;
}
.action-btns a {
display: inline-block;
margin-right: 5px;
padding: 5px 10px;
text-decoration: none;
color: #fff;
border-radius: 3px;
transition: background-color 0.3s ease;
}
.action-btns a.edit-btn {
background-color: #007bff;
}
.action-btns a.delete-btn {
background-color: #dc3545;
}
.action-btns a:hover {
background-color: #0d7b99;
}
.add-event-btn {
display: block;
margin: 20px auto;
padding: 10px 20px;
background-color: #0d7b99;
color: #fff;
border: none;
border-radius: 5px;
cursor: pointer;
transition: background-color 0.3s ease;
text-decoration: none;
text-align: center;
width: 150px;
}
.add-event-btn:hover {
color: #0d7b99;
background-color: #fff;
border: 1px solid #0d7b99;
border-color: #0d7b99;
}
/* pagination css */
.pagination {
margin-top: 20px;
text-align: center;
}
.pagination a {
color: #007bff;
padding: 8px 16px;
text-decoration: none;
transition: background-color 0.3s;
border: 1px solid #007bff;
margin: 0 5px;
border-radius: 5px;
}
.pagination a.active {
background-color: #007bff;
color: #fff;
}
.pagination a:hover:not(.active) {
background-color: #f2f2f2;
}
/* Filter form styling */
form {
margin-bottom: 20px;
text-align: center;
}
label {
margin-right: 10px;
}
input[type="date"] {
padding: 8px;
border-radius: 5px;
border: 1px solid #ccc;
}
button[type="submit"] {
padding: 8px 16px;
border: none;
border-radius: 5px;
cursor: pointer;
transition: background-color 0.3s;
margin-top: 10px;
color: #0d7b99;
background-color: #fff;
border: 1px solid #0d7b99;
border-color: #0d7b99;
}
/* Media queries */
@media (max-width: 768px) {
.table-responsive {
overflow-x: auto;
}
table th, table td {
white-space: nowrap;
}
}
</style>
</head>
<body>
<?php include 'header.php'; ?>
<div class="heading-page header-text">
<!-- to get the space between the header and event management -->
</div>
<div class="event-container">
<h2>Event Management</h2>
<a href="add_event.php" class="add-event-btn">Add Event</a>
<form action="" method="get">
<label for="startDate">Start Date:</label>
<input type="date" id="startDate" name="startDate">
<label for="endDate">End Date:</label>
<input type="date" id="endDate" name="endDate">
<button type="submit">Filter</button>
</form>
<div class="table-responsive">
<table class="table table-bordered">
<table>
<thead>
<tr>
<th>Event Name</th>
<th>Date</th>
<th>Time</th>
<th>Venue</th>
<th>Organizing Club</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php foreach ($events as $event): ?>
<tr>
<td><?php echo $event['name']; ?></td>
<td><?php echo $event['event_date']; ?></td>
<td><?php echo $event['event_time']; ?></td>
<td><?php echo $event['venue']; ?></td>
<td><?php echo $event['organizing_party']; ?></td>
<td class="action-btns">
<!-- Edit button with link to edit_event.php -->
<a href="edit_event.php?id=<?php echo $event['id']; ?>" class="edit-btn">Edit</a>
<!-- Delete button with link to delete_event.php and confirmation dialog -->
<a href="delete_event.php?id=<?php echo $event['id']; ?>" class="delete-btn"
onclick="return confirm('Are you sure you want to delete this event?')">Delete</a>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
<!-- Pagination links -->
<?php if ($totalPages > 1): ?>
<div class="pagination">
<!-- Previous page link -->
<?php if ($page > 1): ?>
<a href="?page=<?php echo $page - 1; ?>">Previous</a>
<?php endif; ?>
<!-- Page number links -->
<?php for ($i = 1; $i <= $totalPages; $i++): ?>
<a href="?page=<?php echo $i; ?>" <?php if ($page == $i) echo 'class="active"'; ?>><?php echo $i; ?></a>
<?php endfor; ?>
<!-- Next page link -->
<?php if ($page < $totalPages): ?>
<a href="?page=<?php echo $page + 1; ?>">Next</a>
<?php endif; ?>
</div>
<?php endif; ?>
</div>
<!-- footer -->
<?php include 'footer.php'; ?>
</body>
</html>