session.ajax.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Responses to AJAX calls
  5. */
  6. require_once '../global.inc.php';
  7. $action = $_REQUEST['a'];
  8. switch ($action) {
  9. case 'get_user_sessions':
  10. if (api_is_platform_admin()) {
  11. $user_id = intval($_POST['user_id']);
  12. $list_sessions = SessionManager::get_sessions_by_user($user_id, true);
  13. if (!empty($list_sessions)) {
  14. foreach ($list_sessions as $session_item) {
  15. echo $session_item['session_name'] . '<br />';
  16. }
  17. } else {
  18. echo get_lang('NoSessionsForThisUser');
  19. }
  20. unset($list_sessions);
  21. }
  22. break;
  23. case 'search_session':
  24. if (api_is_platform_admin()) {
  25. $sessions = SessionManager::get_sessions_list(
  26. [
  27. 's.name' => [
  28. 'operator' => 'LIKE',
  29. 'value' => "%" . $_REQUEST['q'] . "%"
  30. ]
  31. ]
  32. );
  33. $list = [
  34. 'items' => []
  35. ];
  36. if (empty($sessions)) {
  37. echo json_encode([]);
  38. break;
  39. }
  40. foreach ($sessions as $session) {
  41. $list['items'][] = [
  42. 'id' => $session['id'],
  43. 'text' => $session['name']
  44. ];
  45. }
  46. echo json_encode($list);
  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 'get_description':
  108. if (isset($_GET['session'])) {
  109. $sessionInfo = api_get_session_info($_GET['session']);
  110. echo '<h2>'.$sessionInfo['name'].'</h2>';
  111. echo '<div class="home-course-intro"><div class="page-course"><div class="page-course-intro">';
  112. echo $sessionInfo['show_description'] == 1 ? $sessionInfo['description'] : get_lang('None');
  113. echo '</div></div></div>';
  114. }
  115. break;
  116. case 'search_general_coach':
  117. header('Content-Type: application/json');
  118. if (api_is_anonymous()) {
  119. echo '';
  120. break;
  121. }
  122. $list = [
  123. 'items' => []
  124. ];
  125. $entityManager = Database::getManager();
  126. $usersRepo = $entityManager->getRepository('ChamiloUserBundle:User');
  127. $users = $usersRepo->searchUsersByStatus($_GET['q'], COURSEMANAGER);
  128. foreach ($users as $user) {
  129. $list['items'][] = [
  130. 'id' => $user->getId(),
  131. 'text' => $user->getCompleteName()
  132. ];
  133. }
  134. echo json_encode($list);
  135. break;
  136. default:
  137. echo '';
  138. }
  139. exit;