-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevent.php
382 lines (337 loc) · 11.7 KB
/
event.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
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
<?php
/*
* Circle K Calendar
*
* Copyright 2012 Michigan District of Circle K
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
require_once('include/init.php');
require_once(BASE_PATH . '/lib/Log.php');
require_once(BASE_PATH . '/lib/Header.php');
require_once(BASE_PATH . '/lib/user.php');
require_once(BASE_PATH . '/lib/event.php');
require_once(BASE_PATH . '/lib/form.php');
if (!array_key_exists('event_id', $_GET)) {
echo "<p>No event id specified</p>";
goto end;
}
$event_id = intval($_GET['event_id']);
if (isset($_SESSION['user_id'])) {
$user_id = $_SESSION['user_id'];
$access_level = $_SESSION['access_level'];
} else {
$user_id = $access_level = NULL;
}
$header = new Header($mysqli);
$header->add_title('Event');
$header->include_script('form');
$header->include_script('event');
$header->include_style('jquery-ui');
$header->include_style('form');
$header->export_variable('event_id', $event_id);
$event_data = event_get_data($mysqli, $event_id);
if (!$event_data) {
$header->add_title('unknown event');
$header->render_head();
echo '<p>This event does not exist</p>';
goto end;
}
$event_data['start_ts'] = strtotime($event_data['start_time']);
$event_data['end_ts'] = strtotime($event_data['end_time']);
$header->add_title($event_data['name']);
$header->render_head();
if (isset($event_data['leader'])) {
$manager_id = intval($event_data['leader']);
$manager_name = $event_data['l_name'];
$manager_email = $event_data['l_email'];
} else {
$manager_id = intval($event_data['creator']);
$manager_name = $event_data['c_name'];
$manager_email = $event_data['c_email'];
}
$manager_name = htmlspecialchars($manager_name);
$manager_email = htmlspecialchars($manager_email);
$edit_event = false;
$manage_hours = false;
$edit_signups = false;
if (isset($user_id)) {
$edit_event = is_auth_edit_event($_SESSION, $event_data);
$edit_signups = is_auth_edit_signups($_SESSION, $event_data);
$manage_hours = is_auth_manage_hours($_SESSION, $event_data, $event_data['hours_submitted']);
}
$description = htmlspecialchars($event_data['description']);
$status = event_get_status($event_data);
if ($status !== 'open') {
$description .= " <span class='status'>(" . $status . ')</span>';
}
echo '<header>';
echo '<h1>' . $event_data['name'] . '</h1>';
echo '<p>' . $description . '</p>';
echo '</header>';
if (!($edit_event || $manage_hours)) {
switch ($status) {
case 'pending':
echo "<p>This event has not yet been posted, please check back soon for more information!</p>";
goto end;
case 'closed':
echo "<p>This event has been closed, please feel free to look at the calendar for other exciting events!</p>";
goto end;
case 'full':
echo "<p>This event has reached the maximum number of signups. We hope you are able to find another event to sign up for!</p>";
goto end;
case 'cancelled':
echo "<p>We are sorry to inform you that this event will no longer be taking place.</p>";
goto end;
}
}
$event_type = ucfirst($event_data['primary_type']);
if (isset($event_data['secondary_type']))
$event_type .= ' (' . ucfirst($event_data['secondary_type']) . ')';
echo "<div class='row'>";
echo "<div class='span6'>";
echo "<dl class='dl-horizontal'>";
echo '<dt>Start Time</dt>' . '<dd>' .date('F j g:ia', $event_data['start_ts']) . '</dd>';
echo '<dt>End Time</dt>' . '<dd>' . date('F j g:ia', $event_data['end_ts']) . '</dd>';
if ($event_data['meeting_location'])
echo '<dt>Meeting Location</dt>' . '<dd>' .
htmlspecialchars($event_data['meeting_location']) . '</dd>';
if ($event_data['location'])
echo '<dt>Event Location</dt>' . '<dd>' .
htmlspecialchars($event_data['location']) . '</dd>';
echo '<dt>Site Leader</dt>' . '<dd>' . $manager_name . " (<a href='mailto:" .
$manager_email . "'>" . $manager_email . '</a>)' . '</dd>';
if (isset($event_data['committee_name']))
echo '<dt>Committee</dt>' . '<dd>' . $event_data['committee_name'] . '</dd>';
echo '<dt>Event Type</dt>' . '<dd>' . $event_type . '</dd>';
echo '</dl>';
if (isset($_SESSION['user_id']) && $_SESSION['access_level'] >= $config->get('access_view_signups', ACCESS_MEMBER)) {
echo "<h2>Event Signups</h2>";
echo '<table class="table" id="signups">';
echo "<thead><tr><th>Name</th><th>Email</th><th>Phone</th>";
if ($event_data['driver_needed']) {
echo '<th>Seats</th>';
}
echo "<th>Notes</th>";
if ($edit_signups) {
echo "<th>Remove</th>";
}
echo '</tr></thead><tbody>';
$query = "SELECT signup_id, user_id, notes, seats,
CONCAT(first_name, ' ', last_name) AS name, email, phone
FROM signups INNER JOIN users USING(user_id)
WHERE event_id=" . $event_id . ';';
if (!($result = $mysqli->query($query))) {
Log::insert($mysqli, Log::error_mysql, $event_id, NULL, $mysqli->error);
} else {
while ($row = $result->fetch_assoc()) {
$row_class = 'signup-row' . (($row['user_id'] == $user_id) ? ' reload' : '');
$row_content = "<tr id='signup-{$row['signup_id']}' class='$row_class'>";
$row_content .= '<td>' . htmlspecialchars($row['name']) . '</td>';
$row_content .= '<td>' . htmlspecialchars($row['email']) . '</td>';
$row_content .= '<td>' . htmlspecialchars($row['phone']) . '</td>';
if ($event_data['driver_needed']) {
$row_content .= '<td>' . (($row['seats'] !== NULL)?$row['seats']:'N/A') . '</td>';
}
$row_content .= '<td>' . htmlspecialchars($row['notes']) . '</td>';
if ($edit_signups) {
$row_content .= "<td class='remove'><i class='icon-remove'></i></td>";
}
$row_content .= '</tr>';
echo $row_content;
}
}
echo '</tbody>';
echo '</table>';
$form_info = array(
array('name' => 'user_id', 'title' => 'User', 'type' => 'user'),
array('name' => 'notes', 'title' => 'Notes', 'type' => 'textarea'),
);
if ($event_data['driver_needed']) {
$form_info[] = array('name' => 'seats', 'title' => 'Seats', 'type' => 'number');
}
echo '<form class="form-horizontal" id="signup-add" action="2/signup_add.php" method="post">';
echo form_construct($form_info);
echo '<div class="form-actions">';
echo '<button type="submit" class="btn btn-primary">Add signup</button>';
echo '</div>';
echo '</form>';
}
echo "</div>"; //.span6
echo "<div class='span6'>";
$tabs = '<ul class=\'nav nav-tabs\' id=\'tabs\'>';
$tab_count = 0;
$tab_class = 'active';
if ($status === 'open') {
$tabs .= '<li class=\'' . $tab_class . '\'><a href=\'#signup\'>Signup</a></li>';
$tab_count++;
$tab_class = '';
}
if ($edit_event) {
$tabs .= '<li class=\'' . $tab_class . '\'><a href=\'#edit\'>Edit Event</a></li>';
$tab_count++;
$tab_class = '';
}
if ($manage_hours) {
$tabs .= '<li class=\'' . $tab_class . '\'><a href=\'#hours\'>Manage Event Hours</a></li>';
$tab_count++;
$tab_class = '';
}
$tabs .= '</ul>';
if ($tab_count > 1)
echo $tabs;
//the actual page content
echo "<div class='tab-content'>";
$tab_class = 'active';
//tab to display event information and signup for the event
if ($status === 'open') {
echo "<div class='tab-pane $tab_class' id='signup'>";
$tab_class = '';
if (isset($_SESSION['user_id'])) {
$result = $mysqli->query("SELECT signup_id FROM signups WHERE user_id={$_SESSION['user_id']} AND event_id=$event_id;");
if ($result->num_rows === 1) {
echo '<p>Thank you for signing up for this event! We look forward to seeing you there.</p>';
} else {
?>
<form class='form-vertical' id='event-signup' action='2/signup_add.php' method='post'>
<div class='control-group'>
<label class='control-label'>Notes</label>
<div class='controls'>
<textarea name='notes' maxlength='250' class='input-xlarge'></textarea>
</div>
</div>
<?php
if ($event_data['driver_needed']) {
?>
<div class='control-group'>
<label class='control-label'>How many people can you drive (including yourself)</label>
<div class='controls'>
<input name='seats' type='number' min='0' value='0' />
</div>
</div>
<?php
}
?>
<div class='form-actions'>
<button type='submit' class='btn btn-primary'>Sign up</button>
</div>
</form>
<?php
}
} else {
echo "<p>We are sorry but anonymous event signups are not allowed. To sign up for an event, please sign into your account.</p>";
}
echo "</div>"; //#info
}
if ($edit_event) {
echo "<div class='tab-pane $tab_class' id='edit'>";
$tab_class = '';
?>
<form class='form-horizontal' id='event-edit' action='2/event_edit.php' method='post'>
<?php
echo event_form_construct($mysqli, $event_data);
?>
<div class='form-actions'>
<button type='submit' class='btn btn-primary'>Edit Event</button>
</div>
</form>
</div>
<?php
}
if ($manage_hours) {
echo "<div class='tab-pane $tab_class' id='hours'>";
$tab_class = '';
if (!$event_data['hours_submitted']) {
$query = "SELECT user_id, CONCAT(first_name, ' ', last_name) AS name, email
FROM signups INNER JOIN users USING(user_id)
WHERE event_id=" . $event_id . ';';
if (!($result = $mysqli->query($query))) {
Log::insert($mysqli, Log::error_mysql, $event_id, NULL, $mysqli->error);
echo '<p>There has been an error retrieving event signups, feel free to add rows manually or wait for the issue to be resolved</p>';
goto finish_submit_hour_rows;
}
?>
<form id='hours-submit' action='2/hours_submit.php' method='post'>
<table class='table table-bordered'>
<thead>
<tr>
<th>Name</th>
<th>Email</th>
<th>Hours</th>
</tr>
</thead>
<tbody>
<?php
while ($row = $result->fetch_assoc()) {
$user_id = $row['user_id'];
$row_text = "<tr>";
$row_text .= '<td>' . htmlspecialchars($row['name']) . '</td>';
$row_text .= '<td>' . htmlspecialchars($row['email']) . '</td>';
$row_text .= '<td>' . '<input name=\'hours[' . $user_id . ']\' class=\'input-small\' style=\'margin-bottom: 0px;\' />' . '</td>';
$row_text .= '</tr>';
echo $row_text;
}
finish_submit_hour_rows:
?>
</tbody>
</table>
<div class='form-actions'>
<button type='submit' class='btn btn-primary'>Submit Hours</button>
</div>
</form>
<?php
} else {
$query = "SELECT user_id, CONCAT(first_name, ' ', last_name) AS name, hours_id, hours
FROM hours INNER JOIN users USING(user_id)
WHERE event_id=" . $event_id . ';';
if (!($result = $mysqli->query($query))) {
Log::insert($mysqli, Log::error_mysql, $event_id, NULL, $mysqli->error);
echo '<p>There was an error retrieving hour information, the problem will be addressed and you will be contacted with more information later.</p>';
goto finish_hours;
}
?>
<table class='table table-bordered'>
<thead>
<tr>
<th>Name</th>
<th>Hours</th>
<th>Remove</th>
</tr>
</thead>
<tbody>
<?php
while ($row = $result->fetch_assoc()) {
//TODO have the ability to edit/add rows
$hours_id = $row['hours_id'];
$row_text = "<tr id='hours-$hours_id'>";
$row_text .= '<td>' . htmlspecialchars($row['name']) . '</td>';
$row_text .= '<td>' . htmlspecialchars($row['hours']) . '</td>';
$row_text .= "<td class='remove'><i class='icon-remove'></i></td>";
$row_text .= '</tr>';
echo $row_text;
}
?>
</tbody>
</table>
<?php
}
finish_hours:
echo '</div>';
}
echo "</div>"; //.tab-content
echo "</div>"; //.span6
echo "</div>"; //.row
$header->include_js("$('#tabs a').click(function (e) { e.preventDefault(); $(this).tab('show'); });");
end:
$header->render_foot();
?>