live_stats.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. /* See license terms in /license.txt */
  3. require_once __DIR__.'/../inc/global.inc.php';
  4. $this_section = SECTION_COURSES;
  5. $exercise_id = (isset($_GET['exerciseId']) && !empty($_GET['exerciseId'])) ? intval($_GET['exerciseId']) : 0;
  6. // Access control
  7. api_protect_course_script(true);
  8. if (!api_is_allowed_to_edit()) {
  9. api_not_allowed();
  10. }
  11. $objExercise = new Exercise();
  12. $result = $objExercise->read($exercise_id);
  13. if (!$result) {
  14. api_not_allowed(true);
  15. }
  16. $interbreadcrumb[] = [
  17. "url" => "exercise.php?".api_get_cidreq(),
  18. "name" => get_lang('Exercises'),
  19. ];
  20. $interbreadcrumb[] = [
  21. "url" => "admin.php?exerciseId=$exercise_id&".api_get_cidreq(),
  22. "name" => $objExercise->selectTitle(true),
  23. ];
  24. //Add the JS needed to use the jqgrid
  25. $htmlHeadXtra[] = api_get_jqgrid_js();
  26. // The header.
  27. Display::display_header(get_lang('StudentsWhoAreTakingTheExerciseRightNow'));
  28. //jqgrid will use this URL to do the selects
  29. $minutes = 60;
  30. $url = api_get_path(WEB_AJAX_PATH).'exercise.ajax.php?'.api_get_cidreq().'&a=get_live_stats&exercise_id='.$objExercise->id.'&minutes='.$minutes;
  31. //The order is important you need to check the the $column variable in the model.ajax.php file
  32. $columns = [get_lang('FirstName'), get_lang('LastName'), get_lang('Time'), get_lang('QuestionsAlreadyAnswered'), get_lang('Score')];
  33. //Column config
  34. $column_model = [
  35. [
  36. 'name' => 'firstname',
  37. 'index' => 'firstname',
  38. 'width' => '100',
  39. 'align' => 'left',
  40. ],
  41. [
  42. 'name' => 'lastname',
  43. 'index' => 'lastname',
  44. 'width' => '100',
  45. 'align' => 'left',
  46. ],
  47. [
  48. 'name' => 'start_date',
  49. 'index' => 'start_date',
  50. 'width' => '100',
  51. 'align' => 'left',
  52. ],
  53. [
  54. 'name' => 'question',
  55. 'index' => 'count_questions',
  56. 'width' => '60',
  57. 'align' => 'left',
  58. 'sortable' => 'false',
  59. ],
  60. [
  61. 'name' => 'score',
  62. 'index' => 'score',
  63. 'width' => '50',
  64. 'align' => 'left',
  65. 'sortable' => 'false',
  66. ],
  67. ];
  68. //Autowidth
  69. $extra_params['autowidth'] = 'true';
  70. //height auto
  71. $extra_params['height'] = 'auto';
  72. ?>
  73. <script>
  74. function refreshGrid() {
  75. var grid = $("#live_stats");
  76. grid.trigger("reloadGrid");
  77. t = setTimeout("refreshGrid()", 10000);
  78. }
  79. $(function() {
  80. <?php
  81. echo Display::grid_js(
  82. 'live_stats',
  83. $url,
  84. $columns,
  85. $column_model,
  86. $extra_params,
  87. [],
  88. null,
  89. true
  90. );
  91. ?>
  92. refreshGrid();
  93. });
  94. </script>
  95. <?php
  96. $actions = '<a href="exercise_report.php?exerciseId='.intval($_GET['exerciseId']).'&'.api_get_cidreq().'">'.
  97. Display::return_icon('back.png', get_lang('GoBackToQuestionList'), '', ICON_SIZE_MEDIUM).'</a>';
  98. echo $actions = Display::div($actions, ['class' => 'actions']);
  99. echo Display::grid_html('live_stats');
  100. Display::display_footer();