whoisonlinesession.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
  16. $tbl_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  17. if (isset($_REQUEST['session_id'])) {
  18. $session_id = intval($_REQUEST['session_id']);
  19. } else {
  20. $session_id = api_get_session_id();
  21. }
  22. if (empty($session_id)) {
  23. api_not_allowed(true);
  24. }
  25. Display::display_header(get_lang('UserOnlineListSession'));
  26. echo Display::page_header(get_lang('UserOnlineListSession'));
  27. ?>
  28. <br /><br />
  29. <table class="data_table">
  30. <tr>
  31. <th>
  32. <?php echo get_lang('Name'); ?>
  33. </th>
  34. <th>
  35. <?php echo get_lang('InCourse'); ?>
  36. </th>
  37. <th>
  38. <?php echo get_lang('Email'); ?>
  39. </th>
  40. <th>
  41. <?php echo get_lang('Chat'); ?>
  42. </th>
  43. </tr>
  44. <?php
  45. $session_is_coach = array();
  46. if (isset($_user['user_id']) && $_user['user_id'] != '') {
  47. $session_is_coach = SessionManager::get_sessions_coached_by_user(api_get_user_id());
  48. $students_online = array();
  49. $now = api_get_utc_datetime();
  50. $time_limit = api_get_setting('time_limit_whosonline');
  51. $online_time = time() - $time_limit*60;
  52. $current_date = api_get_utc_datetime($online_time);
  53. foreach ($session_is_coach as $session) {
  54. $sql = "SELECT DISTINCT last_access.access_user_id,
  55. last_access.access_date,
  56. last_access.access_cours_code,
  57. last_access.access_session_id,
  58. ".(api_is_western_name_order() ? "CONCAT(user.firstname,' ',user.lastname)" : "CONCAT(user.lastname,' ',user.firstname)")." as name,
  59. user.email
  60. FROM ".Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_LASTACCESS)." AS last_access
  61. INNER JOIN ".Database::get_main_table(TABLE_MAIN_USER)." AS user
  62. ON user.user_id = last_access.access_user_id
  63. WHERE access_session_id='".$session['id']."'
  64. AND access_date >= '$current_date' GROUP BY access_user_id";
  65. $result = Database::query($sql);
  66. while($user_list = Database::fetch_array($result)) {
  67. $students_online[$user_list['access_user_id']] = $user_list;
  68. }
  69. }
  70. if (count($students_online) > 0) {
  71. foreach ($students_online as $student_online) {
  72. echo "<tr><td>";
  73. echo $student_online['name'];
  74. echo "</td><td align='center'>";
  75. echo $student_online['access_cours_code'];
  76. echo "</td><td align='center'>";
  77. if (api_get_setting('show_email_addresses') == 'true') {
  78. if (!empty($student_online['email'])) {
  79. echo $student_online['email'];
  80. } else {
  81. echo get_lang('NoEmail');
  82. }
  83. }
  84. echo " </td>
  85. <td align='center'>
  86. ";
  87. echo '<a target="_blank" class="btn" href="main/chat/chat.php?cidReq='.$student_online['access_cours_code'].'&id_session='.$student_online['access_session_id'].'">
  88. '.get_lang('Chat').'
  89. </a>';
  90. echo " </td>
  91. </tr>
  92. ";
  93. }
  94. } else {
  95. echo ' <tr>
  96. <td colspan="4">
  97. '.get_lang('NoOnlineStudents').'
  98. </td>
  99. </tr>
  100. ';
  101. }
  102. }
  103. ?>
  104. </table>
  105. <?php
  106. Display::display_footer();