-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
350 lines (337 loc) · 18.6 KB
/
index.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
<?php
include 'data.php';
include 'config.php';
$config = new TutorManagerConfig();
function locationNameToCode() {// special helper function for the location dropdown.
$location = htmlspecialchars($_GET['location']);
if ($location == 'Library') {
return 'L';
}
else if ($location == 'Student Center') {
return 'S';
}
else if ($location == 'Beckley') {
return 'B';
}
}
function generateTableCell($day, $timeSlot) {// generate the actual text to go in each table cell
$selection = selectTutorsByTime($day, $timeSlot, $timeSlot + 1);
$L = false;// used to tell if that location has already been entered.
$S = false;
$B = false;
$text = '';
foreach ($selection as $tutor) {
if (in_array(htmlspecialchars($_GET['course']), $tutor->courses) || htmlspecialchars($_GET['course']) == 'all' || htmlspecialchars($_GET['course']) == NULL) {// return based on value of course selection menu
if ($tutor->location == locationNameToCode() || htmlspecialchars($_GET['location']) == 'all' || htmlspecialchars($_GET['location']) == NULL) {// check if location matches selections in location selection menu
if (htmlspecialchars($_GET['tutor']) == ($tutor->firstName . ' ' . mb_substr($tutor->lastName, 0, 1, 'utf-8')) || htmlspecialchars($_GET['tutor']) == 'all' || htmlspecialchars($_GET['tutor']) == NULL) {// search by tutor name
if ($tutor->location == 'L' && !$L){//these are pretty ugly and could be combined with the locationNameToCode() function somehow.
if (!(!$L && !$S && !$B)) {// don't put newline before first location, otherwise put newline
$text .= '<br>';
}
$text .= '<b style="font-size: 1.3rem;"><a onclick="showLocationModal(\'L\')">Library:</a></b><br>';
$L = true;
}
else if ($tutor->location == 'S' && !$S){
if (!(!$L && !$S && !$B)) {// don't put newline before first location, otherwise put newline
$text .= '<br>';
}
$text .= '<b style="font-size: 1.3rem;"><a onclick="showLocationModal(\'S\')">Student Center Lounge:</a></b><br>';
$S = true;
}
else if ($tutor->location == 'B' && !$B){
if (!(!$L && !$S && !$B)) {// don't put newline before first location, otherwise put newline
$text .= '<br>';
}
$text .= '<b style="font-size: 1.3rem;"><a onclick="showLocationModal(\'B\')">Beckley Campus:</a></b><br>';
$B = true;
}
else {
mb_substr($text, 0, 3, 'utf-8');
}
$text .= '<b><a onclick="showNameModal(\'' . $tutor->firstName . '\',\'' . mb_substr($tutor->lastName, 0, 1, 'utf-8') . '\')">' . $tutor->firstName . ' ' . mb_substr($tutor->lastName, 0, 1, 'utf-8') . ':</a></b> ';
if ($tutor->studyGroupName != NULL) {
$text .= '<div class="ui red label">' . $tutor->studyGroupName . "</div>";
}
else {
foreach ($tutor->courses as $course) {
if ($course != NULL) {
$text .= ' ' . $course . ',';
}
}
}
$text = rtrim($text, ',');// remove trailing commas.
$text .= '<br>';
}
}
}
}
$text = rtrim($text, '<br>');//remove trailing <br>
return $text;
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.4.1/semantic.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.4.1/semantic.js"></script>
<script>
function showLocationModal(locationCode) {
if (locationCode == 'L') {
$('.ui.modal.library')
.modal('show')
;
}
else if (locationCode == 'S') {
$('.ui.modal.studentCenter')
.modal('show')
;
}
else if (locationCode == 'B') {
$('.ui.modal.beckley')
.modal('show')
;
}
}
function showNameModal(firstName, lastInitial) {
$('.ui.modal.' + firstName + lastInitial)
.modal('show')
;
}
</script>
<style>
a {
color: black;
}
a:hover {
color: black;
text-decoration: underline;
}
u {
text-decoration: underline;
}
.ui.medium.image {
height: 300px;
width: 300px;
}
</style>
<title>TutorManager</title>
</head>
<body>
<div class="ui container" style="margin-top: 1.5em; margin-bottom: 1.5em;">
<h1 class="ui header"><?php echo $config->semesterName ?> Drop-In Tutoring Schedule</h1>
<div class="ui segment">
<div class="ui segment">
<?php
echo $config->pageText;
?>
</div>
<div class="ui segment">
<form action="" method="get">
<button class="ui icon button" type="submit" style="margin-right: 0.7rem;"><i class="search icon"></i></button>
<select class="ui selection dropdown" name="course">
<option value="all">All Courses</option>
<?php
foreach (getAllCourses() as $course) {
echo '<option ';
if (htmlspecialchars($_GET['course']) == $course) {
echo 'selected';
}
echo " value=\"$course\">$course</option>";
}
?>
</select>
<select class="ui selection dropdown" name="location">
<option value="all">All Locations</option>
<option <?php if (htmlspecialchars($_GET['location']) == 'Library') {echo 'selected';} ?> value="Library">Library</option>
<option <?php if (htmlspecialchars($_GET['location']) == 'Student Center') {echo 'selected';} ?> value="Student Center">Student Center Study Lounge</option>
<option <?php if (htmlspecialchars($_GET['location']) == 'Beckley') {echo 'selected';} ?> value="Beckley">Beckley Campus</option>
</select>
<select class="ui selection dropdown" name="tutor">
<option value="all">All Tutors</option>
<?php
foreach (getAllTutors() as $tutor) {
echo '<option ';
if (htmlspecialchars($_GET['tutor']) == $tutor->firstName . ' ' . mb_substr($tutor->lastName, 0, 1, 'utf-8')) {
echo 'selected';
}
echo ' value="' . $tutor->firstName . ' ' . mb_substr($tutor->lastName, 0, 1, 'utf-8') . '">' . $tutor->firstName . ' ' . mb_substr($tutor->lastName, 0, 1, 'utf-8') . '</option>';
}
?>
</select>
</form>
</div>
<table class="ui unstackable celled striped definition table">
<thead>
<tr>
<th class="one wide"></th>
<th class="three wide center aligned">Monday</th>
<th class="three wide center aligned">Tuesday</th>
<th class="three wide center aligned">Wednesday</th>
<th class="three wide center aligned">Thursday</th>
</tr>
</thead>
<tbody>
<?php
for ($i = 10; $i <= 22; $i++) {// i = hour (24-hr time)
echo "<tr>
<td class=\"center aligned\">" . ltrim(date('h:i', strtotime($i . ':00')), '0') . "</td>
<td>" . generateTableCell('M', $i) . "</td>
<td>" . generateTableCell('T', $i) . "</td>
<td>" . generateTableCell('W', $i) . "</td>
<td>" . generateTableCell('R', $i) . "</td>
</tr>";
}
?>
</tbody>
</table>
<div class="ui segment">
<h2>Alternate Tutoring Opportunities:</h2>
<?php
$selection = selectTutorsByTime("F", 10, 22);
$L = false;// used to tell if that location has already been entered.
$S = false;
$B = false;
$text = '';
foreach ($selection as $tutor) {
if (in_array(htmlspecialchars($_GET['course']), $tutor->courses) || htmlspecialchars($_GET['course']) == 'all' || htmlspecialchars($_GET['course']) == NULL) {// return based on value of course selection menu
if ($tutor->location == locationNameToCode() || htmlspecialchars($_GET['location']) == 'all' || htmlspecialchars($_GET['location']) == NULL) {// check if location matches selections in location selection menu
if (htmlspecialchars($_GET['tutor']) == ($tutor->firstName . ' ' . mb_substr($tutor->lastName, 0, 1, 'utf-8')) || htmlspecialchars($_GET['tutor']) == 'all' || htmlspecialchars($_GET['tutor']) == NULL) {// search by tutor name
if ($tutor->location == 'L' && !$L){//these are pretty ugly and could be combined with the locationNameToCode() function somehow.
if (!(!$L && !$S && !$B)) {// don't put newline before first location, otherwise put newline
$text .= '<br>';
}
$text .= '<b style="font-size: 1.3rem;"><a onclick="showLocationModal(\'L\')">Library:</a></b><br>';
$L = true;
}
else if ($tutor->location == 'S' && !$S){
if (!(!$L && !$S && !$B)) {// don't put newline before first location, otherwise put newline
$text .= '<br>';
}
$text .= '<b style="font-size: 1.3rem;"><a onclick="showLocationModal(\'S\')">Student Center Lounge:</a></b><br>';
$S = true;
}
else if ($tutor->location == 'B' && !$B){
if (!(!$L && !$S && !$B)) {// don't put newline before first location, otherwise put newline
$text .= '<br>';
}
$text .= '<b style="font-size: 1.3rem;"><a onclick="showLocationModal(\'B\')">Beckley Campus:</a></b><br>';
$B = true;
}
else {
mb_substr($text, 0, 3, 'utf-8');
}
$text .= '<b><a onclick="showNameModal(\'' . $tutor->firstName . '\',\'' . mb_substr($tutor->lastName, 0, 1, 'utf-8') . '\')">' . $tutor->firstName . ' ' . mb_substr($tutor->lastName, 0, 1, 'utf-8') . ':</a></b> ';
foreach ($tutor->times as $timeSlot) {
$text .= $timeSlot->startTime . ":00 - " . $timeSlot->endTime . ":00, ";
}
$text = rtrim($text, ', ');// remove trailing commas.
$text .= "<br>";
if ($tutor->studyGroupName != NULL) {
$text .= $tutor->studyGroupName;
}
else {
foreach ($tutor->courses as $course) {
if ($course != NULL) {
$text .= ' ' . $course . ',';
}
}
}
$text = rtrim($text, ',');// remove trailing commas.
$text .= '<br>';
}
}
}
}
$text = rtrim($text, '<br>');//remove trailing <br>
echo $text;
?>
</div>
</div>
</div>
<!-- modals -->
<!-- need a way to reduce duplication between these modals. Something like Angular would be ideal but unfortunately this project wasn't build with it from the ground up and it would be wasteful to use it just for this. PHP function is another option but also could get ugly with HTML involved. Need to come back to this later. -->
<div class="ui longer modal library">
<i class="close icon"></i>
<div class="header">
Library
</div>
<div class="image content">
<img class="ui medium rounded image" src="data/locations/library/image.jpg">
<div class="description">
<p><?php echo file_get_contents('data/locations/library/description.txt');?></p>
</div>
</div>
</div>
<div class="ui longer modal studentCenter">
<i class="close icon"></i>
<div class="header">
Student Center
</div>
<div class="image content">
<img class="ui medium rounded image" src="data/locations/studentCenter/image.jpg">
<div class="description">
<p><?php echo file_get_contents('data/locations/studentCenter/description.txt');?></p>
</div>
</div>
</div>
<div class="ui longer modal beckley">
<i class="close icon"></i>
<div class="header">
Beckley
</div>
<div class="image content">
<img class="ui medium rounded image" src="data/locations/beckley/image.jpg">
<div class="description">
<p><?php echo file_get_contents('data/locations/beckley/description.txt');?></p>
</div>
</div>
</div>
<!-- tutor description modals -->
<!-- these are even worse than the previous ones since they don't load data from the server and involve a lot of duplication. In reality, Angular would be best here but the angular file would still be bigger than all of these put together and would require a complete re-write of much of the project.-->
<?php
foreach (getAllTutors() as $tutor) {
$courses = '';
foreach ($tutor->courses as $course) {// generate list of courses
if ($course != NULL) {
$courses .= ' ' . $course . ',';
}
}
$courses = rtrim($courses, ',');// remove trailing commas.
$times = '';
foreach ($tutor->times as $timeSlot) {// generate list of timeslots
if ($timeSlot->day == 'M') {
$times .= 'Monday ';
}
else if ($timeSlot->day == 'T') {
$times .= 'Tuesday ';
}
else if ($timeSlot->day == 'W') {
$times .= 'Wednesday ';
}
else if ($timeSlot->day == 'R') {
$times .= 'Thursday ';
}
$times .= ltrim(date('h:i A', strtotime($timeSlot->startTime . ':00')), '0') . ' - ' . ltrim(date('h:i A', strtotime($timeSlot->endTime . ':00')), '0') . '<br>';//make times look pretty
}
echo '
<div class="ui longer modal ' . $tutor->firstName . mb_substr($tutor->lastName, 0, 1, 'utf-8') . '">
<i class="close icon"></i>
<div class="header">
' . $tutor->firstName . ' ' . mb_substr($tutor->lastName, 0, 1, 'utf-8') . '.
</div>
<div class="image content">
<img class="ui medium rounded image" src="data/tutors/' . $tutor->firstName . mb_substr($tutor->lastName, 0, 1, 'utf-8') . '.jpg">
<div class="description">
<div class="ui header">Courses</div>
<p>' . $courses . '</p>
<div class="ui header">Tutoring Times</div>
<p>' . $times . '</p>
</div>
</div>
</div>';
}
?>
</body>
</html>