session.ajax.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Responses to AJAX calls
  5. */
  6. $language_file = array('learnpath', 'courses', 'index','tracking','exercice', 'admin');
  7. require_once '../global.inc.php';
  8. $action = $_REQUEST['a'];
  9. switch ($action) {
  10. case 'get_user_sessions':
  11. if (api_is_platform_admin()) {
  12. $user_id = intval($_POST['user_id']);
  13. $list_sessions = SessionManager::get_sessions_by_user($user_id, true);
  14. if (!empty($list_sessions)) {
  15. foreach ($list_sessions as $session_item) {
  16. echo $session_item['session_name'].'<br />';
  17. }
  18. } else {
  19. echo get_lang('NoSessionsForThisUser');
  20. }
  21. unset($list_sessions);
  22. }
  23. break;
  24. case 'search_session':
  25. if (api_is_platform_admin()) {
  26. $results = SessionManager::get_sessions_list(
  27. array('s.name' => array('operator' => 'LIKE', 'value' => "%".$_REQUEST['q']."%"))
  28. );
  29. $results2 = array();
  30. if (!empty($results)) {
  31. foreach ($results as $item) {
  32. $item2 = array();
  33. foreach ($item as $id => $internal) {
  34. if ($id == 'id') {
  35. $item2[$id] = $internal;
  36. }
  37. if ($id == 'name') {
  38. $item2['text'] = $internal;
  39. }
  40. }
  41. $results2[] = $item2;
  42. }
  43. echo json_encode($results2);
  44. } else {
  45. echo json_encode(array());
  46. }
  47. }
  48. break;
  49. case 'search_session_all':
  50. if (api_is_platform_admin()) {
  51. $results = SessionManager::get_sessions_list(
  52. array(
  53. 's.name' => array('operator' => 'like', 'value' => "%".$_REQUEST['q']."%"),
  54. 'c.id' => array('operator' => '=', 'value' => $_REQUEST['course_id'])
  55. )
  56. );
  57. $results2 = array();
  58. if (!empty($results)) {
  59. foreach ($results as $item) {
  60. $item2 = array();
  61. foreach ($item as $id => $internal) {
  62. if ($id == 'id') {
  63. $item2[$id] = $internal;
  64. }
  65. if ($id == 'name') {
  66. $item2['text'] = $internal;
  67. }
  68. }
  69. $results2[] = $item2;
  70. }
  71. $results2[] = array('T', 'text' => 'TODOS', 'id' => 'T');
  72. echo json_encode($results2);
  73. } else {
  74. echo json_encode(array(array('T', 'text' => 'TODOS', 'id' => 'T')));
  75. }
  76. }
  77. break;
  78. case 'search_session_by_course':
  79. if (api_is_platform_admin()) {
  80. $results = SessionManager::get_sessions_list(
  81. array(
  82. 's.name' => array('operator' => 'like', 'value' => "%".$_REQUEST['q']."%"),
  83. 'c.id' => array('operator' => '=', 'value' => $_REQUEST['course_id'])
  84. )
  85. );
  86. $results2 = array();
  87. if (!empty($results)) {
  88. foreach ($results as $item) {
  89. $item2 = array();
  90. foreach ($item as $id => $internal) {
  91. if ($id == 'id') {
  92. $item2[$id] = $internal;
  93. }
  94. if ($id == 'name') {
  95. $item2['text'] = $internal;
  96. }
  97. }
  98. $results2[] = $item2;
  99. }
  100. $results2[] = array('T', 'text' => 'TODOS', 'id' => 'T');
  101. echo json_encode($results2);
  102. } else {
  103. echo json_encode(array(array('T', 'text' => 'TODOS', 'id' => 'T')));
  104. }
  105. }
  106. break;
  107. case 'my_session_statistics':
  108. if (empty($_GET['session_id'])) {
  109. api_not_allowed();
  110. }
  111. $courseCode = !empty($_GET['course']) ? $_GET['course'] : null;
  112. $sessionId = api_get_session_id();
  113. // Getting all sessions where I'm subscribed
  114. $newSessionList = UserManager::get_personal_session_course_list(api_get_user_id());
  115. $mySessionList = array();
  116. if (!empty($newSessionList)) {
  117. foreach ($newSessionList as $item) {
  118. if (!isset($item['id_session'])) {
  119. continue;
  120. }
  121. $mySessionList[] = $item['id_session'];
  122. }
  123. }
  124. // If the requested session does not exist in my list we stop the script
  125. if (!api_is_platform_admin()) {
  126. if (!in_array($sessionId, $mySessionList)) {
  127. api_not_allowed(true);
  128. }
  129. }
  130. $reportingTab = Tracking::show_user_progress(api_get_user_id(), $sessionId, null, false, false, true);
  131. if (empty($reportingTab)) {
  132. echo Display::return_message(get_lang('NoDataAvailable'), 'warning');
  133. exit;
  134. }
  135. echo $reportingTab . '<br>' . Tracking::show_course_detail(api_get_user_id(), $courseCode, $sessionId);
  136. break;
  137. default:
  138. echo '';
  139. }
  140. exit;