tk_stats_page.php 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. if (!defined('e107_INIT')) {
  3. require_once('../../class2.php');
  4. }
  5. if (!e107::isInstalled('timekeeper')) {
  6. return '';
  7. }
  8. $sql = e107::getDb();
  9. $userName = filter_input(INPUT_GET, 'user',FILTER_SANITIZE_SPECIAL_CHARS);
  10. $ext = vartrue(filter_input(INPUT_GET, 'extended', FILTER_VALIDATE_BOOL ),false);
  11. $settingsHolder = $sql->retrieve('timekeeper', '*', 'username="' . $userName . '"');
  12. if(count($settingsHolder)==0)
  13. {
  14. exit;
  15. }
  16. $sql->gen("SELECT DISTINCT subject FROM e107_tkReport WHERE `username` = '$userName'");
  17. while ($row = $sql->fetch()) {
  18. $subjects[] = $row['subject'];
  19. }
  20. $first = true;
  21. foreach ($subjects as $subject) {
  22. if($selects!=''){$selects .= ' UNION ';}
  23. $selects .= "(SELECT CAST((SUM(correct) / COUNT(id) * 100) AS DECIMAL (5 , 2 )) AS percent, COUNT(id) as `count`,'".ucfirst($subject)."' AS `subject`
  24. FROM e107_tkReport WHERE `username` = '$userName' AND `subject` = '$subject')";
  25. if($first){
  26. $selects .= " as subjects";
  27. $first = false;
  28. }
  29. }
  30. $sql->gen("SELECT * FROM $selects;");
  31. $text = '<div ><h1>Score for '.$userName.'</h1>';
  32. $text .= "<table style='width:100%;text-align:center;'>"
  33. . "<thead><tr><td style='text-align:left'>Subject</td><td>Score</td><td>No.Questions</td></tr></thead>"
  34. . "<tbody>";
  35. while ($row = $sql->fetch()) {
  36. if(is_numeric($row['count'])) {
  37. $text .= '<tr><td style=\'text-align:left\'>' . $row['subject'] . '</td><td>' . $row['percent'] . '%</td><td>' . $row['count'] . '</td></tr>';
  38. }
  39. }
  40. $sql->gen("SELECT COUNT(id) as cntr, CAST((SUM(correct)/COUNT(id)*100) as DECIMAL(5,2)) as percent
  41. FROM e107.`e107_tkReport` WHERE username = '$userName'
  42. AND answereddatestamp >= unix_timestamp(CURRENT_DATE())
  43. AND answereddatestamp <= unix_timestamp(CURRENT_DATE() + INTERVAL 1 DAY)");
  44. $text .= '</tbody></table>';
  45. while ($row = $sql->fetch()) {
  46. if((int)$row['cntr']==1) {
  47. $text .= '<p>' . $row['cntr'] . ' question has been answered<br/>today with ' . $row['percent'] . '% accuracy.<p>';
  48. }elseif(!(int)$row['cntr']==0) {
  49. $text .= '<p>' . $row['cntr'] . ' questions have been answered<br/>today with ' . $row['percent'] . '% accuracy.<p><br/>';
  50. if($settingsHolder['minQuestionCount']<=$row['cntr']) {
  51. $text .= '<label style="background: darkgreen;">Games enabled</label><br/>';
  52. $currentScore = e107::getDb()->retrieve('timekeeperScore', 'timekeeper_lifetimecorrect, timekeeper_lifetimequestions, timekeeper_minutes', 'timekeeper_username="' . $userName . '"');
  53. $text .= '<label>You have '.$currentScore['timekeeper_minutes'].' minutes remaining.</label>';
  54. }else{
  55. $text .= '<label>Games disabled</label>';
  56. }
  57. }
  58. }
  59. $text .= '</div>';
  60. if($ext)
  61. {
  62. print_r('hi');
  63. }
  64. echo '<head><meta http-equiv="refresh" content="60"></head><body style="background-color: #1a0000;color:white;">'.$text.'</body>';