live_stats.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. /* See license terms in /license.txt */
  3. require_once '../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[] = array(
  17. "url" => "exercise.php?".api_get_cidreq(),
  18. "name" => get_lang('Exercises'),
  19. );
  20. $interbreadcrumb[] = array(
  21. "url" => "admin.php?exerciseId=$exercise_id&".api_get_cidreq(),
  22. "name" => $objExercise->name,
  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?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 = array(get_lang('FirstName'), get_lang('LastName'), get_lang('Time'), get_lang('QuestionsAlreadyAnswered'), get_lang('Score'));
  33. //Column config
  34. $column_model = array(
  35. array(
  36. 'name' => 'firstname',
  37. 'index' => 'firstname',
  38. 'width' => '100',
  39. 'align' => 'left',
  40. ),
  41. array(
  42. 'name' => 'lastname',
  43. 'index' => 'lastname',
  44. 'width' => '100',
  45. 'align' => 'left',
  46. ),
  47. array(
  48. 'name' => 'start_date',
  49. 'index' => 'start_date',
  50. 'width' => '100',
  51. 'align' => 'left',
  52. ),
  53. array(
  54. 'name' => 'question',
  55. 'index' => 'count_questions',
  56. 'width' => '60',
  57. 'align' => 'left',
  58. 'sortable' => 'false',
  59. ),
  60. array(
  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('live_stats', $url, $columns, $column_model, $extra_params, array(), null, true);
  82. ?>
  83. refreshGrid();
  84. });
  85. </script>
  86. <?php
  87. $actions = '<a href="exercise_report.php?exerciseId='.intval($_GET['exerciseId']).'&'.api_get_cidreq().'">' .
  88. Display :: return_icon('back.png', get_lang('GoBackToQuestionList'),'',ICON_SIZE_MEDIUM).'</a>';
  89. echo $actions = Display::div($actions, array('class'=> 'actions'));
  90. echo Display::grid_html('live_stats');
  91. Display::display_footer();