myspace.ajax.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. $courseInfo = api_get_course_info($course_code);
  16. $courseId = $courseInfo['real_id'];
  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. $courseId,
  23. $start_date,
  24. $end_date
  25. );
  26. } else {
  27. $sql_result = MySpace::get_connections_to_course(
  28. $user_id,
  29. $courseId
  30. );
  31. }
  32. $foo_print = grapher($sql_result, $start_date, $end_date, $type);
  33. echo $foo_print;
  34. break;
  35. case 'access_detail_by_date':
  36. $db = array('is_empty' => true);
  37. $start_date = isset($_REQUEST['startDate']) ? $_REQUEST['startDate'] : "";
  38. $end_date = isset($_REQUEST['endDate']) ? $_REQUEST['endDate'] : "";
  39. $user_id = isset($_REQUEST['student']) ? $_REQUEST['student'] : "";
  40. $course_code = isset($_REQUEST['course']) ? $_REQUEST['course'] : "";
  41. $type = isset($_REQUEST['type']) ? $_REQUEST['type'] : "";
  42. $courseInfo = api_get_course_info($course_code);
  43. $courseId = $courseInfo['real_id'];
  44. $sql_result = MySpace::get_connections_to_course_by_date(
  45. $user_id,
  46. $courseId,
  47. $start_date,
  48. $end_date
  49. );
  50. if (is_array($sql_result) && count($sql_result) > 0) {
  51. $db['is_empty'] = false;
  52. $db['result'] = convert_to_string($sql_result);
  53. $rst = get_stats($user_id, $courseId, $start_date, $end_date);
  54. $foo_stats = '<strong>'.get_lang('Total').': </strong>'.$rst['total'].'<br />';
  55. $foo_stats .= '<strong>'.get_lang('Average').': </strong>'.$rst['avg'].'<br />';
  56. $foo_stats .= '<strong>'.get_lang('Quantity').' : </strong>'.$rst['times'].'<br />';
  57. $db['stats'] = $foo_stats;
  58. $db['graph_result'] = grapher($sql_result, $start_date, $end_date, $type);
  59. } else {
  60. $db['result'] = Display::return_message(
  61. get_lang('NoDataAvailable'),
  62. 'warning'
  63. );
  64. $db['graph_result'] = Display::return_message(
  65. get_lang('NoDataAvailable'),
  66. 'warning'
  67. );
  68. $db['stats'] = Display::return_message(
  69. get_lang('NoDataAvailable'),
  70. 'warning'
  71. );
  72. }
  73. header('Cache-Control: no-cache');
  74. echo json_encode($db);
  75. break;
  76. }
  77. exit;