myspace.ajax.php 3.0 KB

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