whoisonlinesession.php 3.4 KB

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