-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpost.php
361 lines (296 loc) · 16 KB
/
post.php
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
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta content="width=device-width, initial-scale=1.0" name="viewport">
<title>What's Happening</title>
<meta content="" name="description">
<meta content="" name="keywords">
<!-- Favicons -->
<link href="assets/img/favicon.png" rel="icon">
<link href="assets/img/apple-touch-icon.png" rel="apple-touch-icon">
<!-- Google Fonts -->
<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=EB+Garamond:wght@400;500&family=Inter:wght@400;500&family=Playfair+Display:ital,wght@0,400;0,700;1,400;1,700&display=swap" rel="stylesheet">
<!-- Vendor CSS Files -->
<link href="assets/vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
<link href="assets/vendor/bootstrap-icons/bootstrap-icons.css" rel="stylesheet">
<link href="assets/vendor/swiper/swiper-bundle.min.css" rel="stylesheet">
<link href="assets/vendor/glightbox/css/glightbox.min.css" rel="stylesheet">
<link href="assets/vendor/aos/aos.css" rel="stylesheet">
<!-- Template Main CSS Files -->
<link href="assets/css/variables.css" rel="stylesheet">
<link href="assets/css/main.css" rel="stylesheet">
<!-- =======================================================
* Template Name: ZenBlog
* Updated: Jan 09 2024 with Bootstrap v5.3.2
* Template URL: https://bootstrapmade.com/zenblog-bootstrap-blog-template/ [1].
* Author: BootstrapMade.com
* License: https:///bootstrapmade.com/license/
======================================================== -->
</head>
<body>
<!-- ======= Header ======= -->
<header id="header" class="header d-flex align-items-center fixed-top">
<div class="container-fluid container-xl d-flex align-items-center justify-content-between">
<a href="index.php" class="logo d-flex align-items-center">
<!-- Uncomment the line below if you also wish to use an image logo -->
<!-- <img src="assets/img/logo.png" alt=""> -->
<h1>What's Happening</h1>
</a>
<nav id="navbar" class="navbar">
<ul>
<!-- changed some links-->
<li><a href="index.php">Home</a></li>
<li class="dropdown"><a href="events.php?target="><span>Events</span> <i class="bi bi-chevron-down dropdown-indicator"></i></a>
<!-- changed the dropdown-->
<ul>
<li><a href="events.php?target=">All Events</a></li>
<li><a href="events.php?target=Music">Music</a></li>
<li class="dropdown"><a href="events.php?target=Art%2BCulture"><span>Art+Culture</span> <i class="bi bi-chevron-down dropdown-indicator"></i></a>
<ul>
<li><a href="#">Deep Drop Down 1</a></li>
<li><a href="#">Deep Drop Down 2</a></li>
<li><a href="#">Deep Drop Down 3</a></li>
<li><a href="#">Deep Drop Down 4</a></li>
<li><a href="#">Deep Drop Down 5</a></li>
</ul>
</li>
<li><a href="events.php?target=Sports">Sports</a></li>
<li><a href="events.php?target=Food">Food</a></li>
<li><a href="events.php?target=Fund%20Raiser">Fund Raiser</a></li>
</ul>
</li>
<li><a href="groups.php">Community Groups</a></li>
<li><a href="about.php">About</a></li>
<li><a href="post.php">Post Event</a></li>
<li class="dropdown"><a href="login.php"><span>Login</span> <i class="bi bi-chevron-down dropdown-indicator"></i></a>
<ul>
<li><a href="logout.php">Logout</a></li>
</ul>
</li>
</ul>
</nav><!-- .navbar -->
<div class="position-relative">
<a href="#" class="mx-2"><span class="bi-facebook"></span></a>
<a href="#" class="mx-2"><span class="bi-twitter"></span></a>
<a href="#" class="mx-2"><span class="bi-instagram"></span></a>
<a href="#" class="mx-2 js-search-open"><span class="bi-search"></span></a>
<i class="bi bi-list mobile-nav-toggle"></i>
<!-- ======= Search Form ======= -->
<div class="search-form-wrap js-search-form-wrap">
<form action="search-result.html" class="search-form">
<span class="icon bi-search"></span>
<input type="text" placeholder="Search" class="form-control">
<button class="btn js-search-close"><span class="bi-x"></span></button>
</form>
</div><!-- End Search Form -->
</div>
</div>
</header><!-- End Header -->
<main id="main">
<section id="contact" class="contact mb-5">
<div class="container" data-aos="fade-up">
<div class="row">
<div class="col-lg-12 text-center mb-5">
<!--Changed the text from Contact to Login-->
<h1 class="page-title">Post New Event</h1>
</div>
</div>
<!--Removed the row from here-->
<div class="row">
<div class="col-lg-12 text-center mb-5">
<!--Changed the text from Contact to Login-->
<h4>
<?php
//Starting the session
session_start();
//Redirects the user to login if the session is not started yet from post
if(!(isset($_SESSION["login"])) || !($_SESSION["login"] === TRUE)){
header("location: login.php");
exit;
}
require_once 'serverlogin.php';
//Establishing the connection
$conn = mysqli_connect($db_hostname, $db_username, $db_password, $db_database);
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
//Fetching the GroupID from session variable
$groupID = $_SESSION["GroupID"];
/*
Fetching the GroupName from groups table where GroupID
equals the one fetched from the session variable
*/
$query = "SELECT GroupName FROM groups WHERE GroupID = '$groupID'";
$result = mysqli_query($conn, $query);
$output = mysqli_fetch_assoc($result);
$name = $output['GroupName'];
?>
<?php
//Displaying the group name of the group that logged in
echo $name;
?>
</h4>
</div>
</div>
<div class="form mt-5">
<form action="post.php" method="post" role="form" class="php-email-form">
<input type="text" name="eventTitle" id="eventTitle" class="form-control" placeholder="Your Event Title" required>
<input type="text" name="datetime" id="datetime" class="form-control" placeholder="Your Event Date [Format: year-month-day]" required>
<input type="text" name="time" id="time" class="form-control" placeholder="Your Event time [Format: XX:YY AM/PM]" required>
<input type="text" name="eventType" id="eventType" class="form-control" placeholder="Your Event Type" required>
<input type="text" name="image" id="image" class="form-control" placeholder="Image Name" required>
<textarea class="form-control" name="description" id ="description" rows="2" placeholder="The Event Description" required></textarea>
<div class="my-3">
<div class="loading">Loading</div>
<div class="error-message"></div>
<div class="sent-message">Your message has been sent. Thank you!</div>
</div>
<div class="text-center"><button type="submit">Submit</button></div>
</form>
<?php
$db_hostname = 'localhost';
$db_username = 'root'; // your username
$db_password = 'root'; // your password
$db_database = 'whats_happening';
//Establish connection
$conn = mysqli_connect ($db_hostname, $db_username, $db_password, $db_database);
if (!$conn) {
die("Connection failed!" . mysqli_connect_error());
}
//Fetching the information from the post.php page
$communityGroup = $name;
$eventTitle = $_POST['eventTitle'];
$date = $_POST['datetime'];
$time = $_POST['time'];
$eventType = $_POST['eventType'];
$image = $_POST['image'];
$finalLocation = "files/images/events/" . $image;
$description = $_POST['description'];
$eventDateTime = strtotime("$date $time");//[4]
//Format the submit date and time
$submitDateTime = date('Y-m-d H:i:s');//[5]
$eventDateAndTime = date('Y-m-d H:i:s', $eventDateTime);//[5]
//Getting the EventTypeID accordingly from the post.php form input from eventtype table
$eventTypeQuery = "SELECT EventTypeID FROM eventtype WHERE EventType = '$eventType'";
$eventTypeResult = mysqli_query($conn, $eventTypeQuery);
//Not using while loop because it would return one row
$eventTypeRow = mysqli_fetch_assoc($eventTypeResult);
$eventTypeId = $eventTypeRow["EventTypeID"];
//Getting the GroupID accordingly from the post.php form input from groups table
$groupQuery = "SELECT GroupID FROM groups WHERE GroupName = '$communityGroup'";
$groupResult = mysqli_query($conn, $groupQuery);
//Not using while loop because it would return one row
$groupRow = mysqli_fetch_assoc($groupResult);
$groupId = $groupRow["GroupID"];
//Fetching the current maximum EventID value and incrementing it by one
$maxEventIDQuery = "SELECT MAX(EventID) AS maxEventID FROM events";
$maxEventIDResult = mysqli_query($conn, $maxEventIDQuery);
//Not using while loop because it would return one row
$maxEventIDRow = mysqli_fetch_assoc($maxEventIDResult);
$currentEventID = $maxEventIDRow['maxEventID'];
$newEventID = $currentEventID + 1;
//Creating a prepared statement for inserting the data into the database
$statement = $conn->prepare("INSERT INTO events (EventID, EventTypeID, GroupID, EventDate, SubmitDate, EventTitle, EventImage, EventDesc) VALUES (?, ?, ?, ?, ?, ?, ?, ?)");
//Binding the parameters according to their input types
$statement->bind_param("iiisssss", $newEventID, $eventTypeId, $groupId, $eventDateAndTime, $submitDateTime, $eventTitle, $finalLocation, $description);
//Executing the prepared statement to insert the data into the table
$statement->execute();
//Closing the prepared statement
$statement->close();
//Closing the connection
$conn->close();
?>
</div><!-- End Contact Form -->
</div>
</section>
</main><!-- End #main -->
<!-- ======= Footer ======= -->
<footer id="footer" class="footer">
<div class="footer-content">
<div class="container">
<div class="row g-5">
<div class="col-lg-4">
<h3 class="footer-heading">About What's Happening</h3>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Magnam ab, perspiciatis beatae autem deleniti voluptate nulla a dolores, exercitationem eveniet libero laudantium recusandae officiis qui aliquid blanditiis omnis quae. Explicabo?</p>
<p><a href="about.php" class="footer-link-more">Learn More</a></p>
</div>
<div class="col-6 col-lg-2">
<h3 class="footer-heading">Navigation</h3>
<ul class="footer-links list-unstyled">
<!--Changed the links-->
<li><a href="index.php"><i class="bi bi-chevron-right"></i> Home</a></li>
<li><a href="events.php?target="><i class="bi bi-chevron-right"></i> Events</a></li>
<li><a href="groups.php"><i class="bi bi-chevron-right"></i> Community Groups</a></li>
<li><a href="about.php"><i class="bi bi-chevron-right"></i> About</a></li>
<li><a href="post.php"><i class="bi bi-chevron-right"></i> Post Event</a></li>
<li><a href="login.php"><i class="bi bi-chevron-right"></i> Login</a></li>
</ul>
</div>
<div class="col-6 col-lg-2">
<h3 class="footer-heading">Events</h3>
<ul class="footer-links list-unstyled">
<li><a href="events.php?target="><i class="bi bi-chevron-right"></i> All Events</a></li>
<li><a href="events.php?target=Music"><i class="bi bi-chevron-right"></i> Music</a></li>
<li><a href="events.php?target=Art%2BCulture"><i class="bi bi-chevron-right"></i> Art+Culture</a></li>
<li><a href="events.php?target=Sports"><i class="bi bi-chevron-right"></i> Sports</a></li>
<li><a href="events.php?target=Food"><i class="bi bi-chevron-right"></i> Food</a></li>
<li><a href="events.php?target=Fund%20Raiser"><i class="bi bi-chevron-right"></i> Fund Raiser</a></li>
</ul>
</div>
</div>
</div>
</div>
<div class="footer-legal">
<div class="container">
<div class="row justify-content-between">
<div class="col-md-6 text-center text-md-start mb-3 mb-md-0">
<div class="copyright">
© Copyright <strong><span>ZenBlog</span></strong>. All Rights Reserved
</div>
<div class="credits">
<!-- All the links in the footer should remain intact. -->
<!-- You can delete the links only if you purchased the pro version. -->
<!-- Licensing information: https://bootstrapmade.com/license/ -->
<!-- Purchase the pro version with working PHP/AJAX contact form: https://bootstrapmade.com/herobiz-bootstrap-business-template/ [1].-->
Designed by <a href="https://bootstrapmade.com/">BootstrapMade</a>
</div>
</div>
<div class="col-md-6">
<div class="social-links mb-3 mb-lg-0 text-center text-md-end">
<a href="#" class="twitter"><i class="bi bi-twitter"></i></a>
<a href="#" class="facebook"><i class="bi bi-facebook"></i></a>
<a href="#" class="instagram"><i class="bi bi-instagram"></i></a>
<a href="#" class="google-plus"><i class="bi bi-skype"></i></a>
<a href="#" class="linkedin"><i class="bi bi-linkedin"></i></a>
</div>
</div>
</div>
</div>
</div>
</footer>
<a href="#" class="scroll-top d-flex align-items-center justify-content-center"><i class="bi bi-arrow-up-short"></i></a>
<!-- Vendor JS Files -->
<script src="assets/vendor/bootstrap/js/bootstrap.bundle.min.js"></script>
<script src="assets/vendor/swiper/swiper-bundle.min.js"></script>
<script src="assets/vendor/glightbox/js/glightbox.min.js"></script>
<script src="assets/vendor/aos/aos.js"></script>
<!-- Template Main JS File -->
<script src="assets/js/main.js"></script>
</body>
</html>
<!--
References:
[1] "ZenBlog - Bootstrap Blog Template", <i>BOOTSTRAPMADE</i> [Online].
Available: https://bootstrapmade.com/zenblog-bootstrap-blog-template/ [Accessed: Feb. 03, 2024]
[2] "PHP date_create() Function", W3SCHOOLS [Online]. Available:
https://www.w3schools.com/php/func_date_date_create.asp [Accessed: Mar. 10, 2024]
[3] "PHP date_format() Function", W3SCHOOLS [Online]. Available:
https://www.w3schools.com/php/func_date_date_format.asp [Accessed: Mar. 10, 2024]
[4] "PHP strtotime() Function", W3SCHOOLS [Online]. Available:
https://www.w3schools.com/php/func_date_strtotime.asp [Accessed: Mar. 10, 2024]
[5] "PHP date() Function", W3SCHOOLS [Online]. Available:
https://www.w3schools.com/php/func_date_date.asp [Accessed: Mar. 10, 2024]
-->