-
Notifications
You must be signed in to change notification settings - Fork 1
/
meeting.php
356 lines (333 loc) · 12 KB
/
meeting.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
<?php
include 'includes/session.php';
include 'includes/dbConnect.php';
include 'includes/library.php';
// login only area
if (!isLoggedIn()){
header("Location: error.php");
exit;
}
// do meeting ownership check
$meeting_id = mysqli_real_escape_string($connection, $_GET['meeting_id']);
$owner_id = getMeetingOwnerID($connection, $meeting_id);
if ($user_id == $owner_id){
$owner = true;
}
else {
$owner = false;
}
// do meeting participant check
if (!isMeetingParticipant($connection, $meeting_id, $user_id)){
header("Location: error.php?errorCode=authError");
exit;
}
else {
$meeting = getMeetingFields($connection, $meeting_id);
$mu = getMeetingUserFields($connection, $meeting_id, $user_id);
}
?>
<!DOCTYPE html>
<html>
<?php
include 'includes/header.php';
?>
<body>
<?php
include 'includes/navigationBar.php';
?>
<div class="section" style="background-image: url(assets/images/pattern.jpg);">
<div class="container overlay-meeting">
<div class="row">
<div class="col-md-12">
<h1 class="text-center">Organize Meeting</h1>
</div>
</div>
<!-- Meeting Title and Description -->
<div class="row">
<div class="col-md-12">
<?php
echo '<h3 class="text-center">';
echo $meeting['name'];
echo '</h3>';
echo '<h4 class="text-center">';
echo $meeting['description'];
echo '</h4>';
echo '<hr>';
?>
</div>
</div>
<?php
// error handling
if (isset($_GET['errorCode'])){
$errorCode = mysqli_real_escape_string($connection, $_GET['errorCode']);
echo "
<div class='row'>
<div class='col-md-12'>
<ul style='margin-left: 20px'>
<font color='#ff0000'>
";
if ($errorCode == 'finalizeError'){
echo "<li>You need to declare and select <u>1 timeslot</u> & <u>1 location</u> to finalize a meeting.</li>";
}
echo "
</font>
</ul>
<hr>
</div>
</div>
";
}
?>
<!-- Meeting Preferences -->
<div class="row">
<div class="col-md-12">
<?php
// if the meeting hasn't been finalized
if (!$meeting['finalized']){
// declared timeslots
echo '<h4>Your declared timeslots</h4>';
$mu_id = $mu['mu_id'];
$query = "SELECT * FROM mu_date_time WHERE mu_id=$mu_id";
$timeslot_list = mysqli_query($connection, $query);
$numResult = mysqli_num_rows($timeslot_list);
if (!$numResult){
echo '<b>You have no declared timeslots for this meeting.</b>';
echo '<br>';
}
else {
while ($timeslot = mysqli_fetch_array($timeslot_list, MYSQLI_ASSOC)){
if ($owner && $meeting['date_time'] == $timeslot['date_time']){
echo "<div style='background-color: #DAFF91'>";
}
else {
echo "<div>";
}
echo "<b>";
echo $timeslot['date_time'];
echo "</b>";
echo ' ';
echo "<a href='removeTimeslot.php?";
echo "meeting_id=$meeting_id&mudt_id=$timeslot[mudt_id]' class='custom-btn5 hvr-grow-shadow'>Remove</a>";
// add finalize option for owner
if ($owner){
echo "<a href='setActiveTimeslot.php?meeting_id=$meeting_id&mudt_id=$timeslot[mudt_id]' class='custom-btn5 hvr-grow-shadow'>Select</a>";
echo ' --> ';
echo getNumAttending($connection, $meeting_id, $timeslot['date_time']);
echo ' person(s) attending';
echo ' ';
if ($meeting['date_time'] == $timeslot['date_time']){
echo '--> Selected';
}
}
echo "</div>";
}
// add finalize warning message for owner
if ($owner){
echo '<br>';
echo '<font color="red">* Participants will not be able to change their accepted timeslots once you finalize the meeting.</font>';
}
}
echo '<hr>';
// declare new timeslots
echo '<h4>Declare a new timeslot</h4>';
if ($owner){
echo '<form role="form" method="post" action="declareTimeslot.php?meeting_id=';
echo $meeting_id;
echo '">';
echo '
<div class="form-group">
<label><font color="#000000">Date/Time:</font></label><br>
<div class="row">
<div class="col-sm-6">
<input type="text" class="form-control" id="datetimepicker4" name="date_time" style="color:#000;">
</div>
<script type="text/javascript">
$(function () {
$("#datetimepicker4").datetimepicker({
format: "YYYY-MM-DD HH:mm",
sideBySide: true
});
});
</script>
</div>
</div>
<div class="form-group">
<input type="submit" class="custom-btn5 hvr-grow-shadow btn-default" value="Declare" id="declare" name="declare">
</div>
</form>
';
}
else {
$query = "SELECT * FROM meeting_users WHERE meeting_id=$meeting_id && user_id=$owner_id";
$result = mysqli_query($connection, $query);
$owner_mu = mysqli_fetch_array($result);
$owner_mu_id = $owner_mu['mu_id'];
$query = "SELECT * FROM mu_date_time WHERE mu_id=$owner_mu_id";
$result = mysqli_query($connection, $query);
$i=0;
while ($row = mysqli_fetch_array($result)){
$query = "SELECT * FROM mu_date_time WHERE mu_id=$mu_id && date_time='$row[date_time]'";
$result2 = mysqli_query($connection, $query);
$exist = mysqli_num_rows($result2);
if (!$exist){
echo $row['date_time'];
echo ' ';
echo "<a href='acceptTimeslot.php?meeting_id=$meeting_id&mudt_id=$row[mudt_id]'>";
echo 'accept';
echo '</a>';
echo '<br>';
}
}
}
echo '<hr>';
echo '<h4>Meeting participants</h4>';
$query = "SELECT * FROM meeting_users WHERE meeting_id=$meeting_id";
$result = mysqli_query($connection, $query);
while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)){
$query = "SELECT * FROM users WHERE user_id=$row[user_id]";
$result2 = mysqli_query($connection, $query);
$participant = mysqli_fetch_array($result2, MYSQLI_ASSOC);
echo "<a href='viewProfile.php?target_id=$participant[user_id]'>";
echo "<b>";
echo $participant['full_name'];
echo "</b>";
echo "</a>";
if ($owner){
if ($participant['user_id'] != $owner_id){
echo ' ';
echo "<a href='removeParticipant.php?";
echo "meeting_id=$meeting_id&participant_id=$participant[user_id]' class='custom-btn5 hvr-grow-shadow'>Remove</a>";
}
else {
echo ' ';
echo "<a href='#' class='custom-btn5 hvr-grow-shadow'>Owner</a>";
}
}
echo '<br>';
}
echo '<hr>';
if ($owner){
echo '<h4>Add participants</h4>';
$query = "SELECT * FROM mu_date_time WHERE mu_id=$mu_id";
$result = mysqli_query($connection, $query);
$numResult = mysqli_num_rows($result);
if (!$numResult){
echo 'You have to declare at least one timeslot to invite your friend(s).';
}
else {
$query = "SELECT * FROM friendships WHERE user1_id=$user_id || user2_id=$user_id";
$result = mysqli_query($connection, $query);
$numResult = mysqli_num_rows($result);
if ($numResult == 0){
echo 'You have not added any friends into your friends list.';
}
else {
echo '
<form id="addParticipant" role="form" method="post" action="addParticipant.php?meeting_id=';
echo $meeting_id;
echo '" autocomplete="off">
<div class="form-group">
<div class="row">
<div class="col-sm-6">
<div class="input_container">
<input type="text" style="color:#000;" class="form-control" id="user_id" name="target_email" onkeyup="autocomplet()">
<ul id="user_list_id"></ul>
</div>
</div>
</div>
</div>
</form>';
}
}
echo '<hr>';
}
// Meeting locations
echo '<h4>Proposed meeting locations</h4>';
$query = "SELECT * FROM meeting_users WHERE meeting_id='$meeting_id' && user_id='$user_id'";
$result = mysqli_query($connection, $query);
$row = mysqli_fetch_array($result, MYSQLI_ASSOC);
if (isset($row['user_location_id'])){
$user_location_declared = true;
$user_location_id = $row['user_location_id'];
}
else {
$user_location_declared = false;
}
$query = "SELECT * FROM meeting_locations WHERE meeting_id='$meeting_id'";
$result = mysqli_query($connection, $query);
$numResult = mysqli_num_rows($result);
if (!$numResult){
echo 'No meeting locations have been suggested.';
}
else {
while ($meeting_location = mysqli_fetch_array($result, MYSQLI_ASSOC)){
$location_id = $meeting_location['location_id'];
$query = "SELECT * FROM locations WHERE location_id='$location_id'";
$result2 = mysqli_query($connection, $query);
$location = mysqli_fetch_array($result2, MYSQLI_ASSOC);
if ($owner && $meeting['location'] == $location['name']){
echo "<div style='background-color: #DAFF91'>";
}
else {
echo "<div>";
}
echo "<a href='viewLocation.php?location_id=$location_id'>";
echo $location['name'];
echo "</a>";
echo " --> ";
echo "$meeting_location[num_votes] person(s) voted this.";
if (!$user_location_declared){
echo " ";
echo "<a href='voteLocation.php?meeting_id=$meeting_id&location_id=$location_id'>";
echo "Vote";
echo "</a>";
}
else if ($user_location_declared && $user_location_id == $location['location_id']){
echo " ";
echo "You voted this.";
echo " ";
echo "<a href='unvoteLocation.php?meeting_id=$meeting_id&location_id=$location_id' class='custom-btn5 hvr-grow-shadow'>";
echo "Unvote";
echo "</a>";
}
if ($owner){
echo "<a href='setActiveLocation.php?meeting_id=$meeting_id&location_id=$location_id' class='custom-btn5 hvr-grow-shadow'>Select</a>";
if ($meeting['location'] == $location['name']){
echo ' ';
echo '--> Selected';
}
}
echo '</div>';
}
}
echo '<br>';
if (!$user_location_declared){
echo "<a href='addLocation.php?meeting_id=$meeting_id' class='custom-btn6 hvr-grow-shadow'>Suggest a new location</a>
<style>
a:hover {
text-decoration: none;
color:#000;
}
</style>";
}
if ($owner){
echo '<hr>';
echo "<a href='finalizeMeeting.php?meeting_id=$meeting_id' class='custom-btn6 hvr-grow-shadow'>Finalize Meeting</a>";
}
}
else {
$query = "SELECT location_id FROM locations WHERE name='$meeting[location]'";
$result = mysqli_query($connection, $query);
$row = mysqli_fetch_array($result, MYSQLI_ASSOC);
echo "This meeting has been finalized and scheduled to take place on <b>$meeting[date_time]</b> at <b><a href='viewLocation.php?location_id=$row[location_id]'>$meeting[location]</a></b>";
}
?>
</div>
</div>
</div>
</div>
<?php
include 'includes/footer.php';
?>
</body>
</html>