timekeeper_menu.php 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. if (!defined('e107_INIT')) {
  3. exit;
  4. }
  5. if (!e107::isInstalled('timekeeper')) {
  6. return '';
  7. }
  8. //e107::includeLan(e_PLUGIN."rss_menu/languages/".e_LANGUAGE."_admin_rss_menu.php");
  9. if (check_class("Main Admin") || check_class("Admin") || check_class("TIMEKEEPER_STUDENT")) {
  10. $sql = e107::getDb();
  11. $userName = e107::getUser()->getLoginName();
  12. $settingsHolder = $sql->retrieve('timekeeper', '*', 'username="' . $userName . '"');
  13. $sql->gen("SELECT DISTINCT subject FROM e107_tkReport WHERE `username` = '$userName'");
  14. while ($row = $sql->fetch()) {
  15. $subjects[] = $row['subject'];
  16. }
  17. //$sql->gen("SELECT * FROM (SELECT CAST((SUM(correct) / COUNT(id) * 100) AS DECIMAL (5 , 2 )) AS percent, COUNT(id) as `count`,
  18. //'Math' AS `subject` FROM e107_tkReport WHERE `username` = '$userName'
  19. //AND (`subject` = 'numbers' OR `subject` = 'numeracy')) as subjects
  20. //UNION
  21. //(SELECT CAST((SUM(correct) / COUNT(id) * 100) AS DECIMAL (5 , 2 )) AS percent, COUNT(id) as `count`,'English' AS `subject`
  22. //FROM e107_tkReport WHERE `username` = '$userName' AND `subject` = 'spelling')");
  23. $first = true;
  24. foreach ($subjects as $subject) {
  25. if($selects!=''){$selects .= ' UNION ';}
  26. $selects .= "(SELECT CAST((SUM(correct) / COUNT(id) * 100) AS DECIMAL (5 , 2 )) AS percent, COUNT(id) as `count`,'".ucfirst($subject)."' AS `subject`
  27. FROM e107_tkReport WHERE `username` = '$userName' AND `subject` = '$subject')";
  28. if($first){
  29. $selects .= " as subjects";
  30. $first = false;
  31. }
  32. }
  33. $sql->gen("SELECT * FROM $selects;");
  34. $text .= "<table style='width:100%;text-align:center;'>"
  35. . "<thead><tr><td style='text-align:left'>Subject</td><td>Score</td><td>No.Questions</td></tr></thead>"
  36. . "<tbody>";
  37. while ($row = $sql->fetch()) {
  38. if(is_numeric($row['count'])) {
  39. $text .= '<tr><td style=\'text-align:left\'>' . $row['subject'] . '</td><td>' . $row['percent'] . '%</td><td>' . $row['count'] . '</td></tr>';
  40. }
  41. }
  42. $sql->gen("SELECT COUNT(id) as cntr, CAST((SUM(correct)/COUNT(id)*100) as DECIMAL(5,2)) as percent
  43. FROM e107.`e107_tkReport` WHERE username = '$userName'
  44. AND answereddatestamp >= unix_timestamp(CURRENT_DATE())
  45. AND answereddatestamp <= unix_timestamp(CURRENT_DATE() + INTERVAL 1 DAY)");
  46. $text .= '</tbody></table>';
  47. while ($row = $sql->fetch()) {
  48. if((int)$row['cntr']==1) {
  49. $text .= '<p>' . $row['cntr'] . ' question has been answered<br/>today with ' . $row['percent'] . '% accuracy.<p>';
  50. }elseif(!(int)$row['cntr']==0) {
  51. $text .= '<p>' . $row['cntr'] . ' questions have been answered<br/>today with ' . $row['percent'] . '% accuracy.<p><br/>';
  52. if($settingsHolder['minQuestionCount']<=$row['cntr']) {
  53. $text .= '<label style="background: Darkgreen;">Games enabled</label><br/>';
  54. $currentScore = e107::getDb()->retrieve('timekeeperScore', 'timekeeper_lifetimecorrect, timekeeper_lifetimequestions, timekeeper_minutes', 'timekeeper_username="' . $this->user . '"');
  55. $text .= '<label>You have '.$currentScore['timekeeper_minutes'].' minutes remaining.</label>';
  56. }else{
  57. $text .= '<label>Games disabled</label>';
  58. }
  59. }
  60. }
  61. e107::getRender()->tablerender('Score', $text);
  62. }