myspace.ajax.php 3.0 KB

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