-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd_event.php
More file actions
303 lines (249 loc) · 10.7 KB
/
Copy pathadd_event.php
File metadata and controls
303 lines (249 loc) · 10.7 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
<?php
session_start();
// Ensure the user is an admin
if (!isset($_SESSION['user_id']) || $_SESSION['role'] !== 'admin') {
header("Location: login.php");
exit();
}
// Database connection details
$servername = "localhost";
$db_username = "root";
$db_password = "";
$dbname = "zoo_website";
// Create connection
$conn = mysqli_connect($servername, $db_username, $db_password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
// Handle form submission for adding a new event
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['add_event'])) {
$event_name = $_POST['event_name'];
$event_date = $_POST['event_date'];
$event_time = $_POST['event_time'];
$ticket_price = $_POST['ticket_price'];
$availability = $_POST['availability'];
$event_image = $_FILES['event_image'];
// Handle image upload
if ($event_image['error'] === UPLOAD_ERR_OK) {
// Read the image file content
$image_tmp_name = $event_image['tmp_name'];
$image_content = file_get_contents($image_tmp_name);
if (!$image_content) {
echo "<script>alert('Failed to read image content.'); window.history.back();</script>";
exit();
}
} else {
// Log and display detailed error messages
switch ($event_image['error']) {
case UPLOAD_ERR_INI_SIZE:
case UPLOAD_ERR_FORM_SIZE:
$error_message = "The uploaded file exceeds the maximum allowed size.";
break;
case UPLOAD_ERR_PARTIAL:
$error_message = "The uploaded file was only partially uploaded.";
break;
case UPLOAD_ERR_NO_FILE:
$error_message = "No file was uploaded.";
break;
case UPLOAD_ERR_NO_TMP_DIR:
$error_message = "Missing a temporary folder.";
break;
case UPLOAD_ERR_CANT_WRITE:
$error_message = "Failed to write file to disk.";
break;
case UPLOAD_ERR_EXTENSION:
$error_message = "File upload stopped by extension.";
break;
default:
$error_message = "Unknown upload error.";
break;
}
error_log("Upload error: " . $error_message, 0);
echo "<script>alert('$error_message'); window.history.back();</script>";
exit();
}
$sql = "INSERT INTO events (event_name, event_date, event_time, ticket_price, availability, event_image)
VALUES (?, ?, ?, ?, ?, ?)";
$stmt = mysqli_prepare($conn, $sql);
if ($stmt === false) {
die("MySQL prepare statement error: " . mysqli_error($conn));
}
mysqli_stmt_bind_param($stmt, 'sssdis', $event_name, $event_date, $event_time, $ticket_price, $availability, $image_content);
if (mysqli_stmt_execute($stmt)) {
header("Location: manage_events.php?event_added=true"); // Redirect to the events management page
exit();
} else {
error_log("Failed to execute statement: " . mysqli_stmt_error($stmt), 0);
echo "<script>alert('Failed to add event. Please try again.'); window.history.back();</script>";
}
mysqli_stmt_close($stmt);
mysqli_close($conn);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Add Event</title>
<!-- Font Awesome for Icons -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.6.0/css/all.min.css" crossorigin="anonymous" referrerpolicy="no-referrer" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
<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=Dancing+Script:wght@400..700&family=Sevillana&display=swap" rel="stylesheet"><link rel="stylesheet" href="style/index.css">
<link rel="stylesheet" href="style/index.css">
<link rel="stylesheet" href="style/add_event.css">
<link rel="stylesheet" href="style/scroll up music.css">
<link rel="stylesheet" href="style/ticket-btn.css">
<link rel="stylesheet" href="style/map-btn.css">
<link rel="stylesheet" href="style/loader.css">
<script src="js/loader.js" defer></script>
<script src="js/audio.js" defer></script>
<script src="js/upbtn.js" defer></script>
<style>
/* Import desired fonts from Google Fonts */
@import url('https://fonts.googleapis.com/css2?family=Pacifico&family=Bree+Serif&family=Lobster&display=swap');
@keyframes blink {
0% {
opacity: 1;
}
50% {
opacity: 0;
}
100% {
opacity: 1;
}
}
h1 {
font-size: 70px !important; /* Force the font size to apply */
color: #ffcc00;
text-align: center;
font-family: 'Pacifico', 'Lobster', 'Bree Serif', 'Arial', sans-serif; /* Multiple fonts for fallback */
margin-top: 1px;
padding: 1px;
border-radius: 1px;
display: inline-block;
text-shadow:
0 0 1px #000000,
0 0 10px #fffef9,
0 0 20px #ECDFCC,
0 0 30px #ffffff,
0 0 40px #ECDFCC,
0 0 50px #ffffff;
animation: blink 0.09s infinite; /* Adjusted animation for a smoother effect */
}
</style>
</head>
<?php
// Get the current page name
$current_page = basename($_SERVER['PHP_SELF']);
?>
<body>
<header>
<div class="header-container">
<a href="admin_dashboard.php" class="logo">
<img src="img/logo.png" alt="Zoo Parc Logo">
</a>
<div class="title-nav">
<h1>Zoo Parc
</h1>
<nav>
<ul>
<li><a href="admin_dashboard.php" class="nav-btn">Home</a></li>
<li>
<div class="nav-item home-item">
<a href="manage_events.php" class="home-button"style="color: #ffcc00;">Events</a>
<div class="animal-animation">
<img src="img/lion.gif" class="animal" alt="lion Animation">
</div>
</div>
</li>
<li><a href="manage_bookings.php" class="nav-btn">Bookings</a></li>
<li><a href="manage_users.php" class="nav-btn">Users</a></li>
<li><a href="view_ticket_payments.php" class="nav-btn">Tickets</a></li>
<li><a href="reports.php" class="nav-btn">Reports</a></li>
<li><a href="logout.php" class="nav-btn logout-btn">Logout</a></li>
</ul>
</nav>
</div>
</div>
</header>
<div id="loader">
<img src="img/logo.png" alt="Zoo Parc Logo">
<p>Loading, please wait...</p>
</div>
<main>
<a href="manage_events.php" class="btn-bp"> Manage Event</a> <br> <br>
<h2>Add New Event</h2>
<form action="add_event.php" method="POST" enctype="multipart/form-data">
<label for="event_name">Event Name:</label>
<input type="text" id="event_name" name="event_name" required>
<label for="event_date">Event Date:</label>
<input type="date" id="event_date" name="event_date" required>
<label for="event_time">Event Time:</label>
<input type="time" id="event_time" name="event_time" required>
<label for="ticket_price">Ticket Price:</label>
<input type="number" step="0.01" id="ticket_price" name="ticket_price" min="10" required>
<label for="availability">Availability:</label>
<input type="number" id="availability" name="availability" min="1" required>
<label for="event_image">Event Image:</label>
<input type="file" name="event_image" id="event_image" required>
<button type="submit" name="add_event">Add Event</button>
</form>
</main>
</body>
<!-- Enhanced Footer -->
<footer
class="footer">
<div class="footer-content">
</div>
<div class="footer-section links">
</div>
</div>
<br>
<div class="footer-bottom">
<div class="footer-section about">
<div class="social-icons">
<p class="footer-head"><i class="fas fa-leaf icon"></i>
Zoo Parc - The Zoological Park
<i class="fas fa-paw icon"></i> <br></p>
<p>Together, we CAN make a difference! If you'd like to help our wildlife charity,
there are lots of ways you can do so... THANK YOU for your ongoing SUPPORT.</p>
<p>Zoo Parc is home to over 31,000 animals across 128 acres of lush gardens.
Come explore and learn about wildlife and conservation efforts.</p> <br>
<a href="#"><i class="fab fa-facebook"></i></a>
<a href="#"><i class="fab fa-instagram"></i></a>
<a href="#"><i class="fab fa-twitter"></i></a>
<a href="#"><i class="fab fa-google-plus"></i></a>
<a href="#"><i class="fab fa-youtube"></i></a>
<p> © 2024 Zoo Parc - The Zoological Park |
Designed by<a href="https://www.instagram.com/luna.layl_/" class="btn-su"
target="_blank" >Sumalka Kodithuwakku<i class="fab fa-pagelines icon-lv" id="icon-lv"></i></a></p>
</div>
</div>
</div>
<div class="quick-links">
<p> Quick - Links
<a href="#" class="quick-link-btn">Home</a>|
<a href="add_event.php" class="quick-link-btn">Add Event</a>|
<a href="view_member_payments.php" class="quick-link-btn">View Tickets</a>|
<a href="edit_user.php" class="quick-link-btn">Edit Member's Info</a> </p>
</div>
</footer>
<!-- Scroll to Top Button -->
<div class="scroll-to-top" id="scrollToTop">
<a href="#top" class="scroll-btn">
<i class="fas fa-chevron-up"></i>
</a>
</div>
<!-- Floating Audio Control -->
<div id="audio-control">
<button id="musicPlaying">▶</button> <!-- Play Icon -->
<audio id="background-music" loop>
<source src="images/mp3.mp3" type="audio/mpeg">
browser not support the audio
</audio>
</div>
</html>