whoisonlinesession.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Shows who is online in a specific session
  5. * @todo move this inside web/users/online-in-course
  6. * @package chamilo.main
  7. */
  8. /**
  9. * Initialization
  10. */
  11. // name of the language file that needs to be included
  12. $language_file = array ('index', 'chat', 'tracking');
  13. require_once './main/inc/global.inc.php';
  14. api_block_anonymous_users();
  15. if (isset($_REQUEST['session_id'])) {
  16. $session_id = intval($_REQUEST['session_id']);
  17. } else {
  18. $session_id = api_get_session_id();
  19. }
  20. if (empty($session_id)) {
  21. api_not_allowed(true);
  22. }
  23. Display::display_header(get_lang('UserOnlineListSession'));
  24. echo Display::page_header(get_lang('UserOnlineListSession'));
  25. ?>
  26. <br /><br />
  27. <table class="data_table">
  28. <tr>
  29. <th>
  30. <?php echo get_lang('Name'); ?>
  31. </th>
  32. <th>
  33. <?php echo get_lang('InCourse'); ?>
  34. </th>
  35. <th>
  36. <?php echo get_lang('Email'); ?>
  37. </th>
  38. <th>
  39. <?php echo get_lang('Chat'); ?>
  40. </th>
  41. </tr>
  42. <?php
  43. $session_is_coach = array();
  44. if (isset($_user['user_id']) && $_user['user_id'] != '') {
  45. $session_is_coach = SessionManager::get_sessions_coached_by_user(api_get_user_id());
  46. $students_online = array();
  47. $now = api_get_utc_datetime();
  48. $time_limit = api_get_setting('time_limit_whosonline');
  49. $online_time = time() - $time_limit*60;
  50. $current_date = api_get_utc_datetime($online_time);
  51. foreach ($session_is_coach as $session) {
  52. $sql = "SELECT DISTINCT last_access.access_user_id,
  53. last_access.access_date,
  54. last_access.c_id,
  55. last_access.access_session_id,
  56. course.code,
  57. ".(api_is_western_name_order() ? "CONCAT(user.firstname,' ',user.lastname)" : "CONCAT(user.lastname,' ',user.firstname)")." as name,
  58. user.email
  59. FROM ".Database::get_main_table(TABLE_STATISTIC_TRACK_E_LASTACCESS)." AS last_access
  60. INNER JOIN ".Database::get_main_table(TABLE_MAIN_USER)." AS user
  61. ON user.user_id = last_access.access_user_id
  62. INNER JOIN ".Database::get_main_table(TABLE_MAIN_COURSE)." AS course
  63. ON course.id = last_access.c_id
  64. WHERE access_session_id='".$session['id']."' AND access_date >= '$current_date'
  65. GROUP BY access_user_id";
  66. $result = Database::query($sql);
  67. while($user_list = Database::fetch_array($result)) {
  68. $students_online[$user_list['access_user_id']] = $user_list;
  69. }
  70. }
  71. if (count($students_online) > 0) {
  72. foreach ($students_online as $student_online) {
  73. echo "<tr><td>";
  74. echo $student_online['name'];
  75. echo "</td><td align='center'>";
  76. echo $student_online['code'];
  77. echo "</td><td align='center'>";
  78. if (api_get_setting('show_email_addresses') == 'true') {
  79. if (!empty($student_online['email'])) {
  80. echo $student_online['email'];
  81. } else {
  82. echo get_lang('NoEmail');
  83. }
  84. }
  85. echo " </td>
  86. <td align='center'>
  87. ";
  88. echo '<a target="_blank" class="btn" href="main/chat/chat.php?cidReq='.$student_online['code'].'&id_session='.$student_online['access_session_id'].'">
  89. '.get_lang('Chat').'
  90. </a>';
  91. echo " </td>
  92. </tr>
  93. ";
  94. }
  95. } else {
  96. echo ' <tr>
  97. <td colspan="4">
  98. '.get_lang('NoOnlineStudents').'
  99. </td>
  100. </tr>
  101. ';
  102. }
  103. }
  104. ?>
  105. </table>
  106. <?php
  107. Display::display_footer();