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