live_stats.php 3.9 KB

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