-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathengagement.php
284 lines (237 loc) · 8.89 KB
/
engagement.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
<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
// Start of your PHP script
$message = ""; // Initialize message variable
require_once('header.php');
$userId = $_SESSION['user'];
// User authentication check
if (!isset($_SESSION['user'])) {
header('Location: signin.php'); // Redirect to login page if not authenticated
exit();
}
$userId = $_SESSION['user']['user_id']; // Make sure 'user_id' exists in the session array.
// Initialize $joinedEvents to ensure it is always set.
$joinedEvents = [];
// If the session user is set, fetch the events they've joined.
if (isset($userId)) {
$joinedEvents = get_user_joined_events($userId); // Fetch joined events for the user
}
// Handle event creation form submission
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['createEvent'])) {
$eventName = $_POST['eventName'];
$eventDesc = $_POST['eventDesc'];
$eventLocation = $_POST['eventLocation'];
$eventDate = $_POST['eventDate'];
$createdBy = $_SESSION['user']; // Assuming user ID is stored in the session
create_event($eventName, $eventDesc, $eventLocation, $eventDate, $createdBy); // Function to create an event
}
// Handle joining an event
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['joinEvent'])) {
$eventId = $_POST['eventId'];
$userId = $_SESSION['user'];
$userId = $_SESSION['user']['user_id']; // Assuming 'user_id' is the key for the user ID in the session array
join_event($userId, $eventId); // Function to join an event
}
// Handle leaving an event
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['leaveEvent'])) {
$eventId = $_POST['eventId'];
$userId = $_SESSION['user']['user_id']; // Correctly retrieve the user ID
leave_event($userId, $eventId);
$joinedEvents = get_user_joined_events($userId); // Refresh the joined events list.
$message = "Event left successfully."; // Set the success message.
}
?>
<style>
.form-container {
max-width: 500px; /* Adjust as necessary */
margin: auto;
padding: 20px;
background-color: #f9f9f9; /* Light gray background */
border-radius: 5px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1); /* subtle shadow */
}
label {
display: block;
margin-top: 10px;
}
input[type="text"],
input[type="date"],
textarea {
width: 100%;
padding: 8px;
margin-top: 5px;
margin-bottom: 10px;
border: 1px solid #ddd;
border-radius: 4px;
}
input[type="submit"] {
background-color: #007bff; /* Bootstrap primary color */
color: white;
padding: 10px 15px;
border: none;
border-radius: 4px;
cursor: pointer;
margin-top: 10px;
}
input[type="submit"]:hover {
background-color: #0056b3; /* Darken on hover */
}
table {
border-collapse: collapse;
width: 100%;
font-size: 0.9rem; /* Adjust the font size to make text smaller */
}
th, td {
border: 1px solid black;
padding: 6px 10px; /* Reduce padding to decrease row height */
text-align: left;
}
th {
background-color: #f2f2f2;
}
.engagement-container {
display: flex;
justify-content: space-between; /* Adjust spacing as needed */
margin-top: 20px;
}
.engagement-section, .experience-section {
flex: 1;
margin: 10px; /* Add some space between the sections */
}
/* Adjustments for smaller screens */
@media (max-width: 800px) {
.engagement-container {
flex-direction: column;
}
}
</style>
<div class="engagement-section">
<div class="form-container">
<h3>Engagement</h3>
<p>To Engage with Team Members, Please, Create or Join an Event</p>
<form action="engagement.php" method="post">
<label for="eventName">Event Name:</label>
<input type="text" id="eventName" name="eventName" required placeholder="Enter event name">
<label for="eventDesc">Description:</label>
<textarea id="eventDesc" name="eventDesc" required placeholder="Describe the event"></textarea>
<label for="eventLocation">Location:</label>
<input type="text" id="eventLocation" name="eventLocation" required placeholder="Event location">
<label for="eventDate">Date:</label>
<input type="date" id="eventDate" name="eventDate" required>
<input type="submit" name="createEvent" value="Create Event">
</form>
</div>
<h5>Upcoming Events</h5>
<table>
<tr>
<th>Event Name</th>
<th>Description</th>
<th>Location</th>
<th>Date</th>
<th>Created By</th>
<th>Action</th>
</tr>
<?php
$events = get_all_events(); // Function to get all events
foreach ($events as $event) {
echo "<tr>";
echo "<td>" . htmlspecialchars($event['name']) . "</td>";
echo "<td>" . htmlspecialchars($event['description']) . "</td>";
echo "<td>" . htmlspecialchars($event['location']) . "</td>";
echo "<td>" . htmlspecialchars($event['event_date']) . "</td>";
echo "<td>" . htmlspecialchars($event['created_by']) . "</td>";
// ... Display other event details
echo '<td>';
echo '<form action="engagement.php" method="post">';
echo '<input type="hidden" name="eventId" value="' . $event['id'] . '">';
echo '<input type="submit" name="joinEvent" value="Join Event">';
echo '</form>';
echo '</td>';
echo "</tr>";
}
if (empty($events)) {
echo "<tr><td colspan='5'>No upcoming events yet.</td></tr>";
}
?>
</table>
<!-- Display the Events in a Table -->
<div>
<h5>Events You Have Joined</h5>
<table>
<tr>
<th>Event Name</th>
<th>Description</th>
<th>Location</th>
<th>Date</th>
<th>Action</th>
</tr>
<?php foreach ($joinedEvents as $event): ?>
<tr>
<td><?= htmlspecialchars($event['name']) ?></td>
<td><?= htmlspecialchars($event['description']) ?></td>
<td><?= htmlspecialchars($event['location']) ?></td>
<td><?= htmlspecialchars($event['event_date']) ?></td>
<td>
<form action="engagement.php" method="post">
<input type="hidden" name="eventId" value="<?= $event['id'] ?>">
<input type="submit" name="leaveEvent" value="Leave Event">
</form>
</td>
</tr>
<?php endforeach; ?>
<?php if (empty($joinedEvents)): ?>
<tr><td colspan="5">You have not joined any events yet.</td></tr>
<?php endif; ?>
</table>
</div> <!-- Close engagement-section -->
<!-- Display the success message here -->
<?php if (!empty($message)): ?>
<div class="alert alert-success" role="alert" style="margin-top: 20px;">
<?= htmlspecialchars($message) ?>
</div>
<?php endif; ?>
</div>
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['shareExperience'])) {
// Get the shared experience from the POST request
$experience = $_POST['experience'];
try {
// Attempt to save the experience
save_experience($experience);
// Handle success, such as sending a confirmation message to the user
} catch (Exception $e) {
// Handle error, such as informing the user they need to be logged in
$error_message = $e->getMessage();
// Show error to user or log it
}
}
// Retrieve shared experiences from the database
$sharedExperiences = get_shared_experiences(); // Function to get shared experiences
?>
<!-- Form to share experiences -->
<div>
<div class="experience-section">
<h5>Share Your Experience</h5>
<form action="engagement.php" method="post">
<label for="experience">Your Experience:</label>
<textarea id="experience" name="experience" required placeholder="Share your experience"></textarea><br>
<input type="submit" name="shareExperience" value="Share">
</form>
</div>
<!-- Display shared experiences on the wall -->
<div>
<h5>Shared Experiences</h5>
<?php if (!empty($sharedExperiences)): ?>
<ul>
</div> <!-- Close experience-section -->
<?php foreach ($sharedExperiences as $experience): ?>
<li><?= htmlspecialchars($experience['username']) ?>: <?= htmlspecialchars($experience['experience']) ?></li>
<?php endforeach; ?>
</ul>
<?php else: ?>
<p>No experiences shared yet.</p>
<?php endif; ?>
</div>
</div> <!-- Close engagement-container -->
<?php require_once('footer.php'); ?>