live_stats.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 ("url" => "exercise.php?gradebook=$gradebook", "name" => get_lang('Exercises'));
  17. $interbreadcrumb[] = array ("url" => "admin.php?exerciseId=$exercise_id","name" => $objExercise->name);
  18. //Add the JS needed to use the jqgrid
  19. $htmlHeadXtra[] = api_get_jqgrid_js();
  20. // The header.
  21. Display::display_header(get_lang('StudentsWhoAreTakingTheExerciseRightNow'));
  22. //jqgrid will use this URL to do the selects
  23. $minutes = 60;
  24. $url = api_get_path(WEB_AJAX_PATH).'exercise.ajax.php?a=get_live_stats&exercise_id='.$objExercise->id.'&minutes='.$minutes;
  25. //The order is important you need to check the the $column variable in the model.ajax.php file
  26. $columns = array(get_lang('FirstName'), get_lang('LastName'), get_lang('Time'), get_lang('QuestionsAlreadyAnswered'), get_lang('Score'));
  27. //Column config
  28. $column_model = array(
  29. array('name'=>'firstname', 'index'=>'firstname', 'width'=>'100', 'align'=>'left'),
  30. array('name'=>'lastname', 'index'=>'lastname', 'width'=>'100', 'align'=>'left'),
  31. array('name'=>'start_date', 'index'=>'start_date', 'width'=>'100', 'align'=>'left'),
  32. array('name'=>'question', 'index'=>'count_questions', 'width'=>'60', 'align'=>'left', 'sortable'=>'false'),
  33. array('name'=>'score', 'index'=>'score', 'width'=>'50', 'align'=>'left','sortable'=>'false'),
  34. );
  35. //Autowidth
  36. $extra_params['autowidth'] = 'true';
  37. //height auto
  38. $extra_params['height'] = 'auto';
  39. /*
  40. //With this function we can add actions to the jgrid (edit, delete, etc)
  41. $action_links = 'function action_formatter(cellvalue, options, rowObject) {
  42. return \'<a href="?action=edit&id=\'+options.rowId+\'">'.Display::return_icon('edit.png',get_lang('Edit'),'',ICON_SIZE_SMALL).'</a>'.
  43. '&nbsp;<a onclick="javascript:if(!confirm('."\'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES))."\'".')) return false;" href="?action=copy&id=\'+options.rowId+\'">'.Display::return_icon('copy.png',get_lang('Copy'),'',ICON_SIZE_SMALL).'</a>'.
  44. '&nbsp;<a onclick="javascript:if(!confirm('."\'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES))."\'".')) return false;" href="?action=delete&id=\'+options.rowId+\'">'.Display::return_icon('delete.png',get_lang('Delete'),'',ICON_SIZE_SMALL).'</a>'.
  45. '\';
  46. }';
  47. */
  48. ?>
  49. <script>
  50. function refreshGrid() {
  51. var grid = $("#live_stats");
  52. grid.trigger("reloadGrid");
  53. t = setTimeout("refreshGrid()", 10000);
  54. }
  55. $(function() {
  56. <?php
  57. echo Display::grid_js('live_stats', $url, $columns, $column_model, $extra_params, array(), null, true);
  58. ?>
  59. refreshGrid();
  60. });
  61. </script>
  62. <?php
  63. $actions = '<a href="exercise_report.php?exerciseId='.intval($_GET['exerciseId']).'&'.api_get_cidreq().'">' .
  64. Display :: return_icon('back.png', get_lang('GoBackToQuestionList'),'',ICON_SIZE_MEDIUM).'</a>';
  65. echo $actions = Display::div($actions, array('class'=> 'actions'));
  66. //echo Display::page_header($objExercise->name);
  67. //echo Display::page_header(get_lang('StudentsWhoAreTakingTheExerciseRightNow'));
  68. echo Display::grid_html('live_stats');
  69. Display::display_footer();