myspace.ajax.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. // Access restrictions.
  9. $is_allowedToTrack = api_is_platform_admin(true, true) ||
  10. api_is_allowed_to_create_course() || api_is_course_tutor();
  11. if (!$is_allowedToTrack) {
  12. exit;
  13. }
  14. switch ($action) {
  15. // At this date : 23/02/2017, a minor review can't determine where is used this case 'access_detail'
  16. case 'access_detail':
  17. $user_id = intval($_REQUEST['student']);
  18. $course_code = Security::remove_XSS($_REQUEST['course']);
  19. $type = Security::remove_XSS($_REQUEST['type']);
  20. $range = Security::remove_XSS($_REQUEST['range']);
  21. $sessionId = isset($_REQUEST['session_id']) ? $_REQUEST['session_id'] : 0;
  22. $courseInfo = api_get_course_info($course_code);
  23. if ($range == 1) {
  24. $start_date = Security::remove_XSS($_REQUEST['sd']);
  25. $end_date = Security::remove_XSS($_REQUEST['ed']);
  26. $sql_result = MySpace::get_connections_to_course_by_date(
  27. $user_id,
  28. $courseInfo,
  29. $sessionId,
  30. $start_date,
  31. $end_date
  32. );
  33. } else {
  34. $sql_result = MySpace::get_connections_to_course(
  35. $user_id,
  36. $courseInfo,
  37. $sessionId
  38. );
  39. }
  40. $foo_print = grapher($sql_result, $start_date, $end_date, $type);
  41. echo $foo_print;
  42. break;
  43. case 'access_detail_by_date':
  44. $db = ['is_empty' => true];
  45. $start_date = isset($_REQUEST['startDate']) ? $_REQUEST['startDate'] : '';
  46. $end_date = isset($_REQUEST['endDate']) ? $_REQUEST['endDate'] : '';
  47. $user_id = isset($_REQUEST['student']) ? $_REQUEST['student'] : '';
  48. $course_code = isset($_REQUEST['course']) ? $_REQUEST['course'] : '';
  49. $type = isset($_REQUEST['type']) ? $_REQUEST['type'] : '';
  50. $sessionId = isset($_REQUEST['session_id']) ? $_REQUEST['session_id'] : 0;
  51. $courseInfo = api_get_course_info($course_code);
  52. $sql_result = MySpace::get_connections_to_course_by_date(
  53. $user_id,
  54. $courseInfo,
  55. $sessionId,
  56. $start_date,
  57. $end_date
  58. );
  59. if (is_array($sql_result) && count($sql_result) > 0) {
  60. $db['is_empty'] = false;
  61. $db['result'] = convert_to_string($sql_result);
  62. $rst = get_stats(
  63. $user_id,
  64. $courseInfo,
  65. $sessionId,
  66. $start_date,
  67. $end_date
  68. );
  69. $foo_stats = '<strong>'.get_lang('Total').': </strong>'.$rst['total'].'<br />';
  70. $foo_stats .= '<strong>'.get_lang('Average').': </strong>'.$rst['avg'].'<br />';
  71. $foo_stats .= '<strong>'.get_lang('Quantity').' : </strong>'.$rst['times'].'<br />';
  72. $db['stats'] = $foo_stats;
  73. $db['graph_result'] = grapher($sql_result, $start_date, $end_date, $type);
  74. } else {
  75. $db['result'] = Display::return_message(
  76. get_lang('No data available'),
  77. 'warning'
  78. );
  79. $db['graph_result'] = Display::return_message(
  80. get_lang('No data available'),
  81. 'warning'
  82. );
  83. $db['stats'] = Display::return_message(
  84. get_lang('No data available'),
  85. 'warning'
  86. );
  87. }
  88. header('Cache-Control: no-cache');
  89. echo json_encode($db);
  90. break;
  91. }
  92. exit;