whoisonlinesession.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. include_once './main/inc/global.inc.php';
  8. api_block_anonymous_users();
  9. $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
  10. $tbl_session_course_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  11. /**
  12. * Header
  13. * include the HTTP, HTML headers plus the top banner
  14. */
  15. Display::display_header(get_lang('UserOnlineListSession'));
  16. ?>
  17. <br /><br />
  18. <table class="data_table" width="60%">
  19. <tr class="tableName">
  20. <td colspan="4">
  21. <strong><?php echo get_lang('UserOnlineListSession'); ?></strong>
  22. </td>
  23. </tr>
  24. <tr>
  25. <th>
  26. <?php echo get_lang('Name'); ?>
  27. </th>
  28. <th>
  29. <?php echo get_lang('InCourse'); ?>
  30. </th>
  31. <th>
  32. <?php echo get_lang('Email'); ?>
  33. </th>
  34. <th>
  35. <?php echo get_lang('Chat'); ?>
  36. </th>
  37. </tr>
  38. <?php
  39. $session_is_coach = array();
  40. if (isset($_user['user_id']) && $_user['user_id'] != '') {
  41. $_user['user_id'] = intval($_user['user_id']);
  42. $sql = "SELECT DISTINCT session.id,
  43. name,
  44. access_start_date,
  45. access_end_date
  46. FROM $tbl_session as session
  47. INNER JOIN $tbl_session_course_user as srcru
  48. ON
  49. srcru.user_id = ".$_user['user_id']." AND
  50. srcru.status=2 AND
  51. session.id = srcru.session_id
  52. ORDER BY access_start_date, access_end_date, name";
  53. $result = Database::query($sql);
  54. while ($session = Database:: fetch_array($result)) {
  55. $session_is_coach[$session['id']] = $session;
  56. }
  57. $sql = "SELECT DISTINCT session.id,
  58. name,
  59. access_start_date,
  60. access_end_date
  61. FROM $tbl_session as session
  62. WHERE session.id_coach = ".$_user['user_id']."
  63. ORDER BY access_start_date, access_end_date, name";
  64. $result = Database::query($sql);
  65. while ($session = Database:: fetch_array($result)) {
  66. $session_is_coach[$session['id']] = $session;
  67. }
  68. if (empty($time_limit)) {
  69. $time_limit = api_get_setting('time_limit_whosonline');
  70. } else {
  71. $time_limit = 60;
  72. }
  73. $online_time = time() - $time_limit * 60;
  74. $current_date = api_get_utc_datetime($online_time);
  75. $students_online = array();
  76. foreach ($session_is_coach as $session) {
  77. $sql = "SELECT DISTINCT last_access.access_user_id,
  78. last_access.access_date,
  79. last_access.c_id,
  80. last_access.access_session_id,
  81. ".(api_is_western_name_order() ? "CONCAT(user.firstname,' ',user.lastname)" : "CONCAT(user.lastname,' ',user.firstname)")." as name,
  82. user.email
  83. FROM ".Database::get_main_table(TABLE_STATISTIC_TRACK_E_LASTACCESS)." AS last_access
  84. INNER JOIN ".Database::get_main_table(TABLE_MAIN_USER)." AS user
  85. ON user.user_id = last_access.access_user_id
  86. WHERE access_session_id='".$session['id']."'
  87. AND access_date >= '$current_date'
  88. GROUP BY access_user_id";
  89. $result = Database::query($sql);
  90. while ($user_list = Database::fetch_array($result)) {
  91. $students_online[$user_list['access_user_id']] = $user_list;
  92. }
  93. }
  94. if (count($students_online) > 0) {
  95. foreach ($students_online as $student_online) {
  96. echo "<tr>
  97. <td>
  98. ";
  99. echo $student_online['name'];
  100. echo " </td>
  101. <td align='center'>
  102. ";
  103. $courseInfo = api_get_course_info_by_id($student_online['c_id']);
  104. echo $courseInfo['title'];
  105. echo " </td>
  106. <td align='center'>
  107. ";
  108. if (!empty($student_online['email'])) {
  109. echo $student_online['email'];
  110. } else {
  111. echo get_lang('NoEmail');
  112. }
  113. echo " </td>
  114. <td align='center'>
  115. ";
  116. echo '<a href="main/chat/chat.php?cidReq='.$courseInfo['code'].'&id_session='.$student_online['access_session_id'].'"> -> </a>';
  117. echo " </td>
  118. </tr>
  119. ";
  120. }
  121. } else {
  122. echo ' <tr>
  123. <td colspan="4">
  124. '.get_lang('NoOnlineStudents').'
  125. </td>
  126. </tr>
  127. ';
  128. }
  129. }
  130. ?>
  131. </table>
  132. <?php
  133. Display::display_footer();