user, * which doesn't exist in a menu file, so the minutes were always blank; * it uses the logged-in user name now * - one GROUP BY query replaces the hand-built UNION: a student with no * answers yet produced "SELECT * FROM ;" (invalid SQL) and undefined * variable notices * - a student with exactly one answer today now also gets the "games * enabled" line (the singular branch skipped it), and the unclosed

* tags are closed * - a student with no settings row no longer errors (uses the default * minimum of 100 questions that timer.php creates new rows with) * - user name escaped for SQL, subjects/values escaped for HTML, * `e107.e107_tkReport` -> MPREFIX */ if (!defined('e107_INIT')) { exit; } if (!e107::isInstalled('timekeeper')) { return ''; } if (check_class("Main Admin") || check_class("Admin") || check_class("TIMEKEEPER_STUDENT")) { $sql = e107::getDb(); $userName = e107::getUser()->getLoginName(); $u = $sql->escape($userName); $reportTable = '`' . MPREFIX . 'tkReport`'; $settingsHolder = $sql->retrieve('timekeeper', '*', 'username="' . $u . '"'); $minQuestions = is_array($settingsHolder) ? (int) $settingsHolder['minQuestionCount'] : 100; // Score per subject, all time. $sql->gen("SELECT `subject`, COUNT(id) AS `count`, CAST((SUM(correct) / COUNT(id) * 100) AS DECIMAL(5,2)) AS percent FROM $reportTable WHERE `username` = '$u' GROUP BY `subject` ORDER BY `subject`"); $subjectRows = []; while ($row = $sql->fetch()) { $subjectRows[] = $row; } $text = "" . "" . ""; foreach ($subjectRows as $row) { $text .= "'; } $text .= '
SubjectScoreNo.Questions
" . htmlspecialchars(ucfirst($row['subject']), ENT_QUOTES, 'UTF-8') . '' . htmlspecialchars($row['percent']) . '%' . (int) $row['count'] . '
'; // Today. $sql->gen("SELECT COUNT(id) AS cntr, CAST((SUM(correct)/COUNT(id)*100) AS DECIMAL(5,2)) AS percent FROM $reportTable WHERE username = '$u' AND answereddatestamp >= UNIX_TIMESTAMP(CURRENT_DATE()) AND answereddatestamp <= UNIX_TIMESTAMP(CURRENT_DATE() + INTERVAL 1 DAY)"); $today = $sql->fetch(); $answeredToday = is_array($today) ? (int) $today['cntr'] : 0; if ($answeredToday > 0) { $percent = htmlspecialchars($today['percent']); if ($answeredToday === 1) { $text .= '

1 question has been answered
today with ' . $percent . '% accuracy.


'; } else { $text .= '

' . $answeredToday . ' questions have been answered
today with ' . $percent . '% accuracy.


'; } if ($minQuestions <= $answeredToday) { $text .= '
'; $currentScore = $sql->retrieve('timekeeperScore', 'timekeeper_lifetimecorrect, timekeeper_lifetimequestions, timekeeper_minutes', 'timekeeper_username="' . $u . '"'); $minutes = is_array($currentScore) ? (int) $currentScore['timekeeper_minutes'] : 0; $text .= ''; } else { $text .= ''; } } e107::getRender()->tablerender('Score', $text); }