myspace.ajax.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. $courseId = 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($user_id, $courseId, $start_date, $end_date);
  21. } else {
  22. $sql_result = MySpace::get_connections_to_course($user_id, $courseId);
  23. }
  24. $foo_print = grapher($sql_result, $start_date, $end_date, $type);
  25. echo $foo_print;
  26. break;
  27. case 'access_detail_by_date':
  28. $db = array('is_empty'=>true);
  29. $start_date = isset($_REQUEST['startDate'])?$_REQUEST['startDate']:"";
  30. $end_date = isset($_REQUEST['endDate'])?$_REQUEST['endDate']:"";
  31. $user_id = isset($_REQUEST['student'])?$_REQUEST['student']:"";
  32. $courseId = isset($_REQUEST['course'])?$_REQUEST['course']:"";
  33. $sql_result = get_connections_to_course_by_date($user_id, $courseId, $start_date, $end_date);
  34. if (is_array($sql_result) && count($sql_result) > 0) {
  35. $db['is_empty'] = false;
  36. $db['result'] = convert_to_string($sql_result);
  37. $rst = get_stats($user_id, $courseId, $start_date, $end_date);
  38. $foo_stats = '<strong>'.get_lang('Total').': </strong>'.$rst['total'].'<br />';
  39. $foo_stats .= '<strong>'.get_lang('Average').': </strong>'.$rst['avg'].'<br />';
  40. $foo_stats .= '<strong>'.get_lang('Quantity').' : </strong>'.$rst['times'].'<br />';
  41. $db['stats'] = $foo_stats;
  42. $db['graph_result'] = grapher($sql_result, $start_date, $end_date);
  43. } else {
  44. $db['result'] = Display::return_message(get_lang('NoDataAvailable'), 'warning');
  45. $db['graph_result'] = Display::return_message(get_lang('NoDataAvailable'), 'warning');
  46. $db['stats'] = Display::return_message(get_lang('NoDataAvailable'), 'warning');
  47. }
  48. header('Cache-Control: no-cache');
  49. echo json_encode($db); // requires: PHP >= 5.2.0, PECL json >= 1.2.0
  50. break;
  51. }
  52. exit;