-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
280 lines (249 loc) · 13 KB
/
index.php
File metadata and controls
280 lines (249 loc) · 13 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
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
session_start();
include_once('cas-go.php');
include_once('../../connectFiles/connect_fb.php');
function e($value)
{
return htmlspecialchars((string) $value, ENT_QUOTES, 'UTF-8');
}
$page = isset($_GET['page']) ? $_GET['page'] : 'instructions';
$passage_id = isset($_GET['passage_id']) ? (int) $_GET['passage_id'] : null;
$has_passage = $passage_id !== null;
$title = 'Reading Fluency Builder';
$passage_name = '';
$source = '';
$passage_html = '';
$wordcount = 0;
$vocabulary_html = '';
$timed_reading_wpm = 'N/A';
$timed_reading_time = 'N/A';
$scrolled_reading = 'N/A';
$comprehension_quiz = 'N/A';
if ($has_passage) {
$_SESSION['passage_id'] = $passage_id;
$passage_query = $fb_db->prepare('SELECT * FROM Passages WHERE passage_id = ?');
$passage_query->bind_param('i', $passage_id);
$passage_query->execute();
$passage_results = $passage_query->get_result();
if ($row = $passage_results->fetch_assoc()) {
$passage_name = $row['title'];
$title = 'Reading Fluency Builder - ' . $passage_name;
$source = $row['source'];
$passage_html = $row['passage_text'];
$wordcount = (int) $row['length'];
$vocabulary_html = (string) $row['vocabulary'];
}
$scores_query = $fb_db->prepare('SELECT * FROM Scores WHERE netid = ? AND passage_id = ?');
$scores_query->bind_param('si', $_SESSION['netid'], $passage_id);
$scores_query->execute();
$scores_results = $scores_query->get_result();
if (!$scores_results->fetch_assoc()) {
$insert_score = $fb_db->prepare('INSERT INTO Scores (netid, passage_id, date_modified) VALUES (?, ?, NOW())');
$insert_score->bind_param('si', $_SESSION['netid'], $passage_id);
$insert_score->execute();
}
$scores_query = $fb_db->prepare('SELECT * FROM Scores WHERE netid = ? AND passage_id = ?');
$scores_query->bind_param('si', $_SESSION['netid'], $passage_id);
$scores_query->execute();
$scores_results = $scores_query->get_result();
if ($score = $scores_results->fetch_assoc()) {
$timed_reading_wpm = $score['timed_reading_wpm'] ?: 'N/A';
$timed_reading_time = $score['timed_reading_time'] ?: 'N/A';
$scrolled_reading = $score['scrolled_reading'] ?: 'N/A';
$comprehension_quiz = $score['comprehension_quiz'] ?: 'N/A';
}
}
$editor = isset($_SESSION['editor']) && (int) $_SESSION['editor'] === 1;
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title><?php echo e($title); ?></title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Atkinson+Hyperlegible:wght@400;700&family=Source+Sans+3:wght@400;600;700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="style.css">
</head>
<body>
<header class="topbar">
<div class="topbar__left">
<button id="menuToggle" type="button" class="icon-btn" aria-controls="nav-panel" aria-expanded="false" aria-label="Toggle reading list">
<img src="images/open.png" alt="">
</button>
<h1 class="app-title"><?php echo e($has_passage ? $title : 'Reading Fluency Builder'); ?></h1>
</div>
<div id="user-btn" class="user-menu">
<?php echo $id; ?>
<div id="drop-down" class="user-dropdown" hidden>
<p class="welcome">Welcome, <?php echo e($_SESSION['preferredFirstName']); ?>!</p>
<?php if ($editor): ?>
<a href="editors/new_passage.php"><img class="icon" src="images/new.png" alt="">New Passage</a>
<?php if ($has_passage): ?>
<a href="editors/edit.php?passage_id=<?php echo e($passage_id); ?>"><img class="icon" src="images/edit.png" alt="">Edit Passage</a>
<?php endif; ?>
<?php endif; ?>
<?php if ($has_passage): ?>
<section id="stats" aria-live="polite">
<h2>Your Scores</h2>
<p><strong>Timed Reading:</strong> <span class="timed_reading">Time: <?php echo e($timed_reading_time); ?> WPM: <?php echo e($timed_reading_wpm); ?></span></p>
<p><strong>Scrolled Reading WPM:</strong> <span class="scrolled_reading"><?php echo e($scrolled_reading); ?></span></p>
<p><strong>Quiz Score:</strong> <span class="comprehension_quiz"><?php echo e($comprehension_quiz); ?></span></p>
<button id="email_results" type="button" class="btn popup_link">Email Results</button>
</section>
<?php endif; ?>
</div>
</div>
</header>
<main id="main" class="layout">
<aside id="nav-panel" class="panel" aria-label="Passage navigation">
<label for="search" class="sr-only">Search passages</label>
<input id="search" type="search" autocomplete="off" placeholder="Search passages">
<ul id="search-results" class="search-results" role="listbox" hidden></ul>
<nav aria-label="Reading list">
<?php include_once('list.php'); ?>
</nav>
</aside>
<section id="content" class="content-area">
<nav id="navbar" class="tab-nav" aria-label="Reading tools" <?php echo $has_passage ? '' : 'hidden'; ?>>
<button type="button" id="reading-btn" class="nav-btn" data-page="reading">Reading</button>
<button type="button" id="scroller-btn" class="nav-btn" data-page="scroller">Scrolled Reading</button>
<button type="button" id="timer-btn" class="nav-btn" data-page="timer">Timed Reading</button>
<button type="button" id="quiz-btn" class="nav-btn" data-page="quiz">Quiz</button>
<button type="button" id="vocab-btn" class="nav-btn" data-page="vocab">Vocabulary</button>
</nav>
<div id="page" class="page-wrap">
<section class="page" id="instructions">
<h2>Welcome to Reading Fluency Builder</h2>
<p>Use the reading list to select a passage. After selecting one, use the tabs above to practice.</p>
<p><strong>Reading</strong> shows the full passage. <strong>Scrolled Reading</strong> auto-scrolls at your selected WPM. <strong>Timed Reading</strong> tracks pace. <strong>Quiz</strong> checks comprehension. <strong>Vocabulary</strong> shows key words.</p>
</section>
<section class="page" id="reading">
<article class="text-content"><?php echo $passage_html ?: '<p>Select a passage to begin.</p>'; ?></article>
<?php if ($source): ?>
<p class="source-note">This passage comes from <?php echo e($source); ?>.</p>
<?php endif; ?>
</section>
<section class="page" id="scroller">
<div class="block">
<div id="window" class="scroll-window" aria-live="off">
<div id="scrollPassage" class="scroll-passage"><?php echo $passage_html; ?></div>
</div>
<label for="userSpeed" class="field-label">Rate (WPM)</label>
<input id="userSpeed" type="number" inputmode="numeric" min="100" value="300">
<div class="btn-row">
<button class="btn" id="go" type="button">Go</button>
<a class="btn btn--subtle" id="reset-scroller" href="index.php?passage_id=<?php echo e($passage_id); ?>&page=scroller">Reset</a>
</div>
</div>
</section>
<section class="page" id="timer">
<p class="instructions">Press Start, read the passage, then press Stop.</p>
<div class="btn-row btn-row--sticky">
<button class="btn" id="start-timer" type="button">Start</button>
<button class="btn" id="stop-timer" type="button" hidden>Stop</button>
<a class="btn btn--subtle" id="timer-results" href="index.php?passage_id=<?php echo e($passage_id); ?>&page=timer" hidden>Reset</a>
</div>
<article class="text-content"><?php echo $passage_html; ?></article>
</section>
<section class="page" id="quiz">
<?php
if ($has_passage) {
$query_quiz = $fb_db->prepare('SELECT * FROM Questions WHERE passage_id = ? ORDER BY question_order ASC');
$query_quiz->bind_param('i', $passage_id);
$query_quiz->execute();
$quiz_results = $query_quiz->get_result();
while ($q = $quiz_results->fetch_assoc()) {
$question_name = 'question_' . (int) $q['question_id'];
$answers = [
['value' => 'correct', 'text' => $q['correct_answer'], 'class' => 'correct-answer'],
['value' => 'incorrect', 'text' => $q['distractor_1'], 'class' => ''],
['value' => 'incorrect', 'text' => $q['distractor_2'], 'class' => ''],
['value' => 'incorrect', 'text' => $q['distractor_3'], 'class' => ''],
];
if ($q['correct_answer'] === 'True') {
$answers = [$answers[0], $answers[1]];
} elseif ($q['correct_answer'] === 'False') {
$answers = [$answers[1], $answers[0]];
} else {
shuffle($answers);
}
$answers = array_values(array_filter($answers, function ($answer) {
return trim((string) $answer['text']) !== '';
}));
if (count($answers) === 0) {
continue;
}
echo "<fieldset class='question-box'><legend class='stem'>" . e($q['question_text']) . "</legend>";
foreach ($answers as $answer) {
echo "<label class='answer " . e($answer['class']) . "'><input type='radio' name='" . e($question_name) . "' value='" . e($answer['value']) . "'> " . e($answer['text']) . "</label>";
}
echo '</fieldset>';
}
}
?>
<div class="btn-row">
<button id="check-answers" class="btn" type="button">Check Answers</button>
</div>
</section>
<section class="page" id="vocab">
<?php
if ($vocabulary_html === '' && $has_passage) {
$query_vocab = $fb_db->prepare('SELECT * FROM Vocabulary WHERE passage_id = ? ORDER BY word ASC');
$query_vocab->bind_param('i', $passage_id);
$query_vocab->execute();
$vocab_results = $query_vocab->get_result();
while ($vocab = $vocab_results->fetch_assoc()) {
echo "<p class='vocab'><strong>" . e($vocab['word']) . "</strong> - " . e($vocab['definition']);
if ($vocab['example']) {
echo '<br><em>' . e($vocab['example']) . '</em>';
}
echo '</p>';
}
} else {
echo $vocabulary_html;
}
?>
</section>
</div>
</section>
</main>
<footer id="footer" class="footer">
<div>
<a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/4.0/">
<img alt="Creative Commons License" src="https://i.creativecommons.org/l/by-nc-sa/4.0/88x31.png">
</a>
</div>
<div id="attribution">
<span>Developed by Ben McMurry</span>
<span>English Language Center, BYU</span>
</div>
</footer>
<div id="invisible-background" class="overlay" hidden></div>
<section id="email_results_popup" class="popup" role="dialog" aria-modal="true" aria-labelledby="email-results-title" hidden>
<button class="close_popup" type="button" aria-label="Close">x</button>
<h2 id="email-results-title">Email Results</h2>
<p>Please enter the email address you wish to send the results to.</p>
<form id="email_results_form">
<input type="hidden" name="netid" value="<?php echo e($_SESSION['netid']); ?>">
<input type="hidden" name="passage_id" value="<?php echo e($passage_id); ?>">
<label for="email">Email</label>
<input type="email" id="email" name="email" required>
</form>
<button class="btn" id="send_email" type="button">Send Email</button>
<div id="sent" class="response" role="status" aria-live="polite"></div>
</section>
<script>
window.APP_CONFIG = {
page: <?php echo json_encode($page); ?>,
passageId: <?php echo json_encode($passage_id); ?>,
wordCount: <?php echo json_encode($wordcount); ?>
};
</script>
<script src="js/app.js"></script>
</body>
</html>