live_stats.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. /* See license terms in /license.txt */
  3. $language_file = array('exercice','tracking');
  4. require_once '../inc/global.inc.php';
  5. $this_section = SECTION_COURSES;
  6. $exercise_id = (isset($_GET['exerciseId']) && !empty($_GET['exerciseId'])) ? intval($_GET['exerciseId']) : 0;
  7. // Access control
  8. api_protect_course_script(true);
  9. if (!api_is_allowed_to_edit()) {
  10. api_not_allowed();
  11. }
  12. $objExercise = new Exercise();
  13. $result = $objExercise->read($exercise_id);
  14. if (!$result) {
  15. api_not_allowed(true);
  16. }
  17. $interbreadcrumb[] = array ("url" => "exercice.php?gradebook=$gradebook", "name" => get_lang('Exercices'));
  18. $interbreadcrumb[] = array ("url" => "admin.php?exerciseId=$exercise_id","name" => $objExercise->name);
  19. //Add the JS needed to use the jqgrid
  20. $htmlHeadXtra[] = api_get_jqgrid_js();
  21. // The header.
  22. Display::display_header(get_lang('StudentsWhoAreTakingTheExerciseRightNow'));
  23. //jqgrid will use this URL to do the selects
  24. $minutes = 60;
  25. $url = api_get_path(WEB_AJAX_PATH).'exercise.ajax.php?a=get_live_stats&exercise_id='.$objExercise->id.'&minutes='.$minutes;
  26. //The order is important you need to check the the $column variable in the model.ajax.php file
  27. $columns = array(get_lang('FirstName'), get_lang('LastName'), get_lang('Time'), get_lang('QuestionsAlreadyAnswered'), get_lang('Score'));
  28. //Column config
  29. $column_model = array(
  30. array('name'=>'firstname', 'index'=>'firstname', 'width'=>'100', 'align'=>'left'),
  31. array('name'=>'lastname', 'index'=>'lastname', 'width'=>'100', 'align'=>'left'),
  32. array('name'=>'start_date', 'index'=>'start_date', 'width'=>'100', 'align'=>'left'),
  33. array('name'=>'question', 'index'=>'count_questions', 'width'=>'60', 'align'=>'left', 'sortable'=>'false'),
  34. array('name'=>'score', 'index'=>'score', 'width'=>'50', 'align'=>'left','sortable'=>'false'),
  35. );
  36. //Autowidth
  37. $extra_params['autowidth'] = 'true';
  38. //height auto
  39. $extra_params['height'] = 'auto';
  40. /*
  41. //With this function we can add actions to the jgrid (edit, delete, etc)
  42. $action_links = 'function action_formatter(cellvalue, options, rowObject) {
  43. return \'<a href="?action=edit&id=\'+options.rowId+\'">'.Display::return_icon('edit.png',get_lang('Edit'),'',ICON_SIZE_SMALL).'</a>'.
  44. '&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>'.
  45. '&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>'.
  46. '\';
  47. }';
  48. */
  49. ?>
  50. <script>
  51. function refreshGrid() {
  52. var grid = $("#live_stats");
  53. grid.trigger("reloadGrid");
  54. t = setTimeout("refreshGrid()", 10000);
  55. }
  56. $(function() {
  57. <?php
  58. echo Display::grid_js('live_stats', $url, $columns, $column_model, $extra_params, array(), null, true);
  59. ?>
  60. refreshGrid();
  61. });
  62. </script>
  63. <?php
  64. $actions = '<a href="exercise_report.php?exerciseId='.intval($_GET['exerciseId']).'">' . 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();