whoisonlinesession.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Shows who is online in a specific session.
  5. *
  6. * @package chamilo.main
  7. */
  8. require_once './main/inc/global.inc.php';
  9. api_block_anonymous_users();
  10. $userId = api_get_user_id();
  11. if (empty($userId)) {
  12. api_not_allowed(true);
  13. }
  14. $sessionId = api_get_session_id();
  15. if (empty($sessionId)) {
  16. api_not_allowed(true);
  17. }
  18. $allow = api_is_platform_admin(true) ||
  19. api_is_coach($sessionId, null, false) ||
  20. SessionManager::isUserSubscribedAsStudent($sessionId, api_get_user_id());
  21. if (!$allow) {
  22. api_not_allowed(true);
  23. }
  24. $maxNumberItems = 20;
  25. $sessionInfo = api_get_session_info($sessionId);
  26. Display::display_header(get_lang('Online users list'));
  27. echo Display::page_header($sessionInfo['name']);
  28. function getUsers(
  29. $from,
  30. $numberItems,
  31. $column,
  32. $direction,
  33. $getCount = false
  34. ) {
  35. $sessionId = api_get_session_id();
  36. $from = (int) $from;
  37. $numberItems = (int) $numberItems;
  38. $urlCondition = '';
  39. $urlJoin = '';
  40. if (api_is_multiple_url_enabled()) {
  41. $accessUrlUser = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
  42. $urlId = api_get_current_access_url_id();
  43. $urlJoin = " INNER JOIN $accessUrlUser a ON (a.user_id = user.id) ";
  44. $urlCondition = " AND a.access_url_id = $urlId ";
  45. }
  46. if (empty($time_limit)) {
  47. $time_limit = api_get_setting('time_limit_whosonline');
  48. } else {
  49. $time_limit = 60;
  50. }
  51. $online_time = time() - $time_limit * 60;
  52. $current_date = api_get_utc_datetime($online_time);
  53. if ($getCount) {
  54. $sql = "SELECT
  55. count(DISTINCT last_access.login_user_id) count
  56. FROM ".Database::get_main_table(TABLE_STATISTIC_TRACK_E_ONLINE)." AS last_access
  57. INNER JOIN ".Database::get_main_table(TABLE_MAIN_USER)." AS user
  58. ON user.id = last_access.login_user_id
  59. $urlJoin
  60. WHERE
  61. session_id ='".$sessionId."' AND
  62. login_date >= '$current_date'
  63. $urlCondition";
  64. $result = Database::query($sql);
  65. $result = Database::fetch_array($result);
  66. return $result['count'];
  67. }
  68. $sql = "SELECT DISTINCT
  69. last_access.login_user_id,
  70. last_access.c_id
  71. FROM ".Database::get_main_table(TABLE_STATISTIC_TRACK_E_ONLINE)." AS last_access
  72. INNER JOIN ".Database::get_main_table(TABLE_MAIN_USER)." AS user
  73. ON user.id = last_access.login_user_id
  74. $urlJoin
  75. WHERE
  76. session_id ='".$sessionId."' AND
  77. login_date >= '$current_date'
  78. $urlCondition
  79. GROUP BY login_user_id
  80. LIMIT $from, $numberItems";
  81. $studentsOnline = [];
  82. $result = Database::query($sql);
  83. while ($user_list = Database::fetch_array($result)) {
  84. $studentsOnline[$user_list['login_user_id']] = $user_list;
  85. }
  86. return $studentsOnline;
  87. }
  88. function getCountUsers()
  89. {
  90. return getUsers(0, 0, 0, 0, true);
  91. }
  92. $table = new SortableTable(
  93. 'users',
  94. 'getCountUsers',
  95. 'getUsers',
  96. '1',
  97. $maxNumberItems
  98. );
  99. $table->set_header(0, get_lang('Name'), false);
  100. $table->set_header(1, get_lang('In course'), false);
  101. $table->set_column_filter(0, 'user_filter');
  102. $table->set_column_filter(1, 'course_filter');
  103. $table->display();
  104. function user_filter($userId, $urlParams, $row)
  105. {
  106. $userInfo = api_get_user_info($userId);
  107. return $userInfo['complete_name_with_message_link'];
  108. }
  109. function course_filter($courseId, $urlParams, $row)
  110. {
  111. $sessionId = api_get_session_id();
  112. $courseInfo = api_get_course_info_by_id($courseId);
  113. return Display::url(
  114. $courseInfo['title'],
  115. $courseInfo['course_public_url'].'?id_session='.$sessionId,
  116. ['target' => '_blank']
  117. ).
  118. '&nbsp;'.
  119. Display::url(
  120. get_lang('Chat'),
  121. 'main/chat/chat.php?cidReq='.$courseInfo['code'].'&id_session='.$sessionId,
  122. ['target' => '_blank', 'class' => 'btn btn-primary']
  123. );
  124. }
  125. Display::display_footer();