-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathshowMyEvents.php
More file actions
160 lines (134 loc) · 5.19 KB
/
showMyEvents.php
File metadata and controls
160 lines (134 loc) · 5.19 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
<?php
require_once('_php/config.php');
session_start();
$_SESSION['faveReturn'] = substr($_SERVER[REQUEST_URI], 1);
if (isset($_SESSION['dateFrom'])) {
$dateFrom = $_SESSION['dateFrom'];
} else {
$dateFrom = "2000-00-00 00:00:00";
}
if (isset($_SESSION['dateTo'])) {
$dateTo = $_SESSION['dateTo'];
} else {
$dateTo = "2020-12-31 23:59:59";
}
if (isset($_SESSION['selectedTags'])) {
// Query for events with selected tags
$selectedTags = implode(',', $_SESSION['selectedTags']);
/*
Slightly concerned that this will return duplicates - if an event has two
tags, and both of those tags are selected for the filter, then it may have
two rows with the same event: one for each tag.
Potential solution:
Subquery to select distinct eventIDs from event_tags where tagID in (selectedTags)
*/
$event_query = "
SELECT *
FROM event_tags
LEFT JOIN events ON events.EventID = event_tags.EventID
WHERE events.OrganiserID = " . $_SESSION['UserID'] . "
AND event_tags.TagID IN ( $selectedTags )
AND events.Start > '$dateFrom'
AND events.Start < '$dateTo'
ORDER BY Approved ASC, Start ASC";
} else {
// Query for all events
$event_query = "
SELECT *
FROM events
WHERE OrganiserID = " . $_SESSION['UserID'] . "
AND events.Start > '$dateFrom'
AND events.Start < '$dateTo'
ORDER BY Approved ASC, Start ASC";
}
$result = $connection->query($event_query);
if($result->connect_errno > 0){
die('Unable to connect to database [' . $result->connect_error . ']');
}
if(!$result){
echo "no result";
} else if(mysqli_num_rows($result) == 0) {
echo '<h4>No Events Found</h4>';
} else {
echo '<div class = "accordion">';
while ($row = $result->fetch_assoc()) {
// Format dates
$start = strtotime($row['Start']);
$startDate = date('l jS F Y', $start);
$startTime = date('H:i', $start);
$end = date_add($start, date_interval_create_from_date_string($row['Duration'] . " hours"));
$endDate = date('l jS F Y', $end);
$endTime = date('H:i', $end);
// Event Summary Section
echo '<section class = "eventSummarySection">';
// Event type and title
if ($row['Type'] == 0) {
$type = "Seminar: ";
} else if ($row['Type'] == 1) {
$type = "Course: ";
} else {
$type = "Conference: ";
}
echo '<h3>' . $type . $row['Name'] . '</h3>';
// Event image
echo '<img src=' . $row['ImageLink'] . ' alt = "Img1" class= "eventImage">';
// Approval status
if ($row['Approved'] == NULL) {
$approval = "Pending Approval";
} else if ($row['Approved'] == 0) {
$approval = "Not Approved";
} else {
$approval = "Approved";
}
echo '<div class="approvalDetails">';
echo '<div class="eventApprovalStatus eventApprovalStatusText">' . $approval . '</div>';
if ($approval == "Approved") {
$noFaves = $connection->query("SELECT DISTINCT UserID FROM favourites WHERE EventID = " . $row['EventID']);
$noAdds = $connection->query("SELECT DISTINCT UserID FROM calendar_adds WHERE EventID = " .$row['EventID']);
echo '<div class="infoForOrganiser">';
echo '<div class="noFavourites">' . mysqli_num_rows($noFaves) . ' favourites</div>';
echo '<div class="noCalendarAdds">' . mysqli_num_rows($noAdds) . ' calendar adds</div>';
echo '</div>';
}
echo '</div>';
// Event summary details
echo '<ul class="eventSummaryDetails">';
echo ' <li>' . $row['Speaker'] . '</li>';
echo ' <li>' . $row['Location'] . '</li>';
echo ' <li><div class="address">' . $row['Postcode'] . '</div></li>';
echo ' <li>' . $startTime . '</li>';
echo ' <li>' . $startDate . '</li>';
echo '</ul>';
echo '</section>';
// Further Details Section
$price = ($row['Cost'] == 0) ? 'Free' : '£' . $row['Cost'];
echo '<div class="furtherDetails">';
// Price
echo '<p>' . $price . '</p>';
echo '<p>' . $row['Description'] . '</p>';
// Tags
$current_id = $row['EventID'];
$tag_query = "SELECT * FROM event_tags JOIN tags ON event_tags.TagID = tags.TagID
WHERE event_tags.EventID = " . $current_id;
$tag_result = $connection->query($tag_query);
$tag_names = array();
foreach ($tag_result as $res) {
array_push($tag_names, $res['TagName']);
}
if (!(sizeof($tag_names) == 0)) {
$tag_list = "Tags: " . implode(", ", $tag_names);
} else {
$tag_list = "No tags";
}
echo '<p>' . $tag_list . '</p>';
// Link
echo '<p>
<a href=' . $row['InfoLink'] . ' class="linkToEventSite">More information</a>
</p>';
// Map
echo '<div class="map"></div>';
echo '</div>';
}
echo '</div>';
}
?>