myspace.ajax.php 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Responses to AJAX calls
  5. */
  6. require_once __DIR__.'/../global.inc.php';
  7. $action = $_GET['a'];
  8. switch ($action) {
  9. // At this date : 23/02/2017, a minor review can't determine where is used this case 'access_detail'
  10. case 'access_detail':
  11. $user_id = intval($_REQUEST['student']);
  12. $course_code = Security::remove_XSS($_REQUEST['course']);
  13. $type = Security::remove_XSS($_REQUEST['type']);
  14. $range = Security::remove_XSS($_REQUEST['range']);
  15. $sessionId = isset($_REQUEST['session_id']) ? $_REQUEST['session_id'] : 0;
  16. $courseInfo = api_get_course_info($course_code);
  17. if ($range == 1) {
  18. $start_date = Security::remove_XSS($_REQUEST['sd']);
  19. $end_date = Security::remove_XSS($_REQUEST['ed']);
  20. $sql_result = MySpace::get_connections_to_course_by_date(
  21. $user_id,
  22. $courseInfo,
  23. $sessionId,
  24. $start_date,
  25. $end_date
  26. );
  27. } else {
  28. $sql_result = MySpace::get_connections_to_course(
  29. $user_id,
  30. $courseInfo,
  31. $sessionId
  32. );
  33. }
  34. $foo_print = grapher($sql_result, $start_date, $end_date, $type);
  35. echo $foo_print;
  36. break;
  37. case 'access_detail_by_date':
  38. $db = array('is_empty' => true);
  39. $start_date = isset($_REQUEST['startDate']) ? $_REQUEST['startDate'] : '';
  40. $end_date = isset($_REQUEST['endDate']) ? $_REQUEST['endDate'] : '';
  41. $user_id = isset($_REQUEST['student']) ? $_REQUEST['student'] : '';
  42. $course_code = isset($_REQUEST['course']) ? $_REQUEST['course'] : '';
  43. $type = isset($_REQUEST['type']) ? $_REQUEST['type'] : '';
  44. $sessionId = isset($_REQUEST['session_id']) ? $_REQUEST['session_id'] : 0;
  45. $courseInfo = api_get_course_info($course_code);
  46. $sql_result = MySpace::get_connections_to_course_by_date(
  47. $user_id,
  48. $courseInfo,
  49. $sessionId,
  50. $start_date,
  51. $end_date
  52. );
  53. if (is_array($sql_result) && count($sql_result) > 0) {
  54. $db['is_empty'] = false;
  55. $db['result'] = convert_to_string($sql_result);
  56. $rst = get_stats(
  57. $user_id,
  58. $courseInfo,
  59. $sessionId,
  60. $start_date,
  61. $end_date
  62. );
  63. $foo_stats = '<strong>'.get_lang('Total').': </strong>'.$rst['total'].'<br />';
  64. $foo_stats .= '<strong>'.get_lang('Average').': </strong>'.$rst['avg'].'<br />';
  65. $foo_stats .= '<strong>'.get_lang('Quantity').' : </strong>'.$rst['times'].'<br />';
  66. $db['stats'] = $foo_stats;
  67. $db['graph_result'] = grapher($sql_result, $start_date, $end_date, $type);
  68. } else {
  69. $db['result'] = Display::return_message(
  70. get_lang('NoDataAvailable'),
  71. 'warning'
  72. );
  73. $db['graph_result'] = Display::return_message(
  74. get_lang('NoDataAvailable'),
  75. 'warning'
  76. );
  77. $db['stats'] = Display::return_message(
  78. get_lang('NoDataAvailable'),
  79. 'warning'
  80. );
  81. }
  82. header('Cache-Control: no-cache');
  83. echo json_encode($db);
  84. break;
  85. }
  86. exit;