live_stats.php 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 = 'exercice';
  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. $objExercise = new Exercise();
  12. $result = $objExercise->read($exercise_id);
  13. if (!$result) {
  14. api_not_allowed(true);
  15. }
  16. $interbreadcrumb[] = array ("url" => "exercice.php?gradebook=$gradebook", "name" => get_lang('Exercices'));
  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_jquery_ui_js(true);
  20. // The header.
  21. Display::display_header($tool_name);
  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('Date'), get_lang('QuestionsDone'), 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'=>'100', 'align'=>'left'),
  33. array('name'=>'score', 'index'=>'score', 'width'=>'100', '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'),'',22).'</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'),'',22).'</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'),'',22).'</a>'.
  45. '\';
  46. }';
  47. */
  48. ?>
  49. <script>
  50. $(function() {
  51. <?php
  52. echo Display::grid_js('live_stats', $url, $columns, $column_model, $extra_params, array(), $action_links,true);
  53. ?>
  54. });
  55. </script>
  56. <?php
  57. echo '<h2>'.$objExercise->name.'</h2>';
  58. echo Display::grid_html('live_stats');
  59. Display::display_footer();