forked from al3ko/254Vent
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalender.php
More file actions
374 lines (323 loc) · 9.55 KB
/
calender.php
File metadata and controls
374 lines (323 loc) · 9.55 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
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
<?php
session_start();
if (!isset($_SESSION["user_id"])) {
header("Location: login.html");
exit;
}
$user_id = $_SESSION["user_id"];
// Database connection
$conn = new mysqli("localhost", "root", "QWE123!@#qwe", "univent", 3307);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Get all registered events for the user
$sql =
SELECT p.title, p.venue, p.event_date, p.start_time, p.end_time
FROM event_registrations er
JOIN posts p ON er.event_id = p.id
WHERE er.user_id = ?
ORDER BY p.event_date, p.start_time
";
$stmt = $conn->prepare($sql);
if ($stmt === false) {
die("Error preparing statement: " . $conn->error);
}
$stmt->bind_param("i", $user_id);
if (!$stmt->execute()) {
die("Error executing statement: " . $stmt->error);
}
$result = $stmt->get_result();
$registeredEvents = [];
while ($row = $result->fetch_assoc()) {
$date = $row['event_date'];
$registeredEvents[$date][] = [
'title' => $row['title'],
'venue' => $row['venue'],
'start_time' => date('h:i A', strtotime($row['start_time'])),
'end_time' => date('h:i A', strtotime($row['end_time']))
];
}
$stmt->close();
$conn->close();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>UniVENT – Calendar</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css"/>
<style>
* {
margin: 0; padding: 0; box-sizing: border-box;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
body {
background: #e6decf;
color: #333;
}
#header {
background: #191970;
padding: 0.25rem 1.2rem;
border-radius: 20px;
margin: 1rem auto;
max-width: 1200px;
display: flex;
justify-content: space-between;
align-items: center;
box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}
#header h1 a {
color: #fff;
font-size: 1.6rem;
text-decoration: none;
font-weight: bold;
}
.nav-links {
display: flex;
gap: 0.8rem;
}
.nav-links a {
color: #f0f0f0;
text-decoration: none;
font-weight: 500;
padding: 0.3rem 0.6rem;
border-radius: 5px;
font-size: 0.9rem;
transition: background-color 0.3s;
}
.nav-links a:hover {
background: #4682b4;
color: #fff;
}
.calendar-container {
max-width: 900px;
margin: 2rem auto;
background: white;
padding: 2rem;
border-radius: 10px;
box-shadow: 0 5px 15px rgba(0,0,0,0.1);
}
.calendar-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 1rem;
}
.calendar-header h1 {
font-size: 1.8rem;
}
.calendar-header button {
background: #FFA500;
color: white;
border: none;
padding: 0.5rem 1rem;
border-radius: 5px;
cursor: pointer;
transition: background 0.3s;
}
.calendar-header button:hover {
background: #e69500;
}
.weekdays,
.calendar-grid {
display: grid;
grid-template-columns: repeat(7, 1fr);
gap: 0.5rem;
}
.weekdays div {
text-align: center;
padding: 0.5rem;
font-weight: bold;
background: #f4f4f4;
border-radius: 5px;
}
.calendar-grid div {
text-align: center;
padding: 0.5rem;
background: #fffaf0;
border: 1px solid #e0dcd0;
border-radius: 5px;
position: relative;
cursor: pointer;
transition: all 0.2s;
height: 60px;
display: flex;
flex-direction: column;
justify-content: center;
}
.calendar-grid div:hover {
transform: scale(1.05);
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}
.calendar-grid div.highlight {
background: #87ceeb;
color: #fff;
font-weight: bold;
}
.calendar-grid div.highlight::after {
content: '';
position: absolute;
bottom: 5px;
left: 50%;
transform: translateX(-50%);
width: 6px;
height: 6px;
background: #191970;
border-radius: 50%;
}
.calendar-grid div.multi-event::after {
width: 12px;
border-radius: 3px;
}
.event-details {
margin-top: 2rem;
padding: 1.5rem;
background: #f8f9fa;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.event-details h2 {
color: #191970;
margin-bottom: 1rem;
border-bottom: 2px solid #FFA500;
padding-bottom: 0.5rem;
}
.event-date-header {
color: #191970;
font-size: 1.2rem;
margin-bottom: 1rem;
padding-bottom: 0.5rem;
border-bottom: 1px solid #ddd;
}
.event-item {
margin-bottom: 1.5rem;
padding: 1rem;
background: white;
border-radius: 6px;
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
.event-item h3 {
color: #4682b4;
margin-bottom: 0.5rem;
}
.event-item p {
margin: 0.3rem 0;
color: #555;
}
.event-time {
font-weight: bold;
color: #FFA500;
}
.no-events {
color: #666;
font-style: italic;
text-align: center;
padding: 1rem;
}
</style>
</head>
<body>
<header id="header">
<h1><a href="homepage.php">UniVENT</a></h1>
<nav class="nav-links">
<a href="homepage.php">Home</a>
<a href="events.php">Events</a>
<a href="calender.php">Calendar</a>
<a href="profile.php">Profile</a>
</nav>
</header>
<div class="calendar-container">
<div class="calendar-header">
<button id="prev-month"><</button>
<h1 id="current-month">Loading...</h1>
<button id="next-month">></button>
</div>
<div class="weekdays">
<div>Sun</div><div>Mon</div><div>Tue</div><div>Wed</div><div>Thu</div><div>Fri</div><div>Sat</div>
</div>
<div class="calendar-grid" id="calendar-grid"></div>
<div class="event-details" id="event-details">
<h2>Event Details</h2>
<div id="events-container">
<p class="no-events">Click on a highlighted date to view events</p>
</div>
</div>
</div>
<script>
const registeredEvents = <?= json_encode($registeredEvents) ?>;
const calendarGrid = document.getElementById("calendar-grid");
const monthLabel = document.getElementById("current-month");
const prevBtn = document.getElementById("prev-month");
const nextBtn = document.getElementById("next-month");
const eventsContainer = document.getElementById("events-container");
let dateObj = new Date();
function renderCalendar() {
const Y = dateObj.getFullYear(), M = dateObj.getMonth();
const firstDay = new Date(Y, M, 1).getDay();
const daysInM = new Date(Y, M + 1, 0).getDate();
monthLabel.textContent = `${dateObj.toLocaleString('default',{month:'long'})} ${Y}`;
calendarGrid.innerHTML = '';
// Empty cells for days before the first of the month
for (let i = 0; i < firstDay; i++) {
calendarGrid.appendChild(document.createElement('div'));
}
// Cells for each day of the month
for (let d = 1; d <= daysInM; d++) {
const dateStr = `${Y}-${String(M+1).padStart(2,'0')}-${String(d).padStart(2,'0')}`;
const cell = document.createElement('div');
cell.textContent = d;
cell.dataset.date = dateStr;
if (registeredEvents[dateStr]) {
cell.classList.add('highlight');
if (registeredEvents[dateStr].length > 1) {
cell.classList.add('multi-event');
}
cell.addEventListener('click', () => showEvents(dateStr));
}
calendarGrid.appendChild(cell);
}
}
function showEvents(dateStr) {
const events = registeredEvents[dateStr];
if (!events || events.length === 0) {
eventsContainer.innerHTML = '<p class="no-events">No events for this date</p>';
return;
}
let html = `
<div class="event-date-header">
${new Date(dateStr).toLocaleDateString('en-US', {
weekday: 'long',
month: 'long',
day: 'numeric',
year: 'numeric'
})}
</div>
`;
events.forEach(event => {
html += `
<div class="event-item">
<h3>${event.title}</h3>
<p><strong>Venue:</strong> ${event.venue}</p>
<p class="event-time"><strong>Time:</strong> ${event.start_time} - ${event.end_time}</p>
</div>
`;
});
eventsContainer.innerHTML = html;
}
// Event listeners for month navigation
prevBtn.addEventListener('click', () => {
dateObj.setMonth(dateObj.getMonth() - 1);
renderCalendar();
eventsContainer.innerHTML = '<p class="no-events">Click on a highlighted date to view events</p>';
});
nextBtn.addEventListener('click', () => {
dateObj.setMonth(dateObj.getMonth() + 1);
renderCalendar();
eventsContainer.innerHTML = '<p class="no-events">Click on a highlighted date to view events</p>';
});
// Initial render
renderCalendar();
</script>
</body>
</html>