whoisonlinesession.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. include_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 = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE);
  16. $tbl_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  17. /**
  18. * Header
  19. * include the HTTP, HTML headers plus the top banner
  20. */
  21. Display::display_header(get_lang('UserOnlineListSession'));
  22. ?>
  23. <br /><br />
  24. <table class="data_table" width="60%">
  25. <tr class="tableName">
  26. <td colspan="4">
  27. <strong><?php echo get_lang('UserOnlineListSession'); ?></strong>
  28. </td>
  29. </tr>
  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. $_user['user_id'] = intval($_user['user_id']);
  48. $result = Database::query("SELECT DISTINCT id,
  49. name,
  50. date_start,
  51. date_end
  52. FROM $tbl_session as session
  53. INNER JOIN $tbl_session_course_user as srcru
  54. ON srcru.id_user = ".$_user['user_id']." AND srcru.status=2
  55. AND session.id = srcru.id_session
  56. ORDER BY date_start, date_end, name");
  57. while ($session = Database:: fetch_array($result)) {
  58. $session_is_coach[$session['id']] = $session;
  59. }
  60. $result = Database::query("SELECT DISTINCT id,
  61. name,
  62. date_start,
  63. date_end
  64. FROM $tbl_session as session
  65. WHERE session.id_coach = ".$_user['user_id']."
  66. ORDER BY date_start, date_end, name");
  67. while ($session = Database:: fetch_array($result)) {
  68. $session_is_coach[$session['id']] = $session;
  69. }
  70. $students_online = array();
  71. foreach ($session_is_coach as $session) {
  72. $sql = "SELECT DISTINCT last_access.access_user_id,
  73. last_access.access_date,
  74. last_access.access_cours_code,
  75. last_access.access_session_id,
  76. ".(api_is_western_name_order() ? "CONCAT(user.firstname,' ',user.lastname)" : "CONCAT(user.lastname,' ',user.firstname)")." as name,
  77. user.email
  78. FROM ".Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_LASTACCESS)." AS last_access
  79. INNER JOIN ".Database::get_main_table(TABLE_MAIN_USER)." AS user
  80. ON user.user_id = last_access.access_user_id
  81. WHERE access_session_id='".$session['id']."'
  82. AND NOW()-access_date<1000 GROUP BY access_user_id";
  83. $result = Database::query($sql);
  84. while($user_list = Database::fetch_array($result)) {
  85. $students_online[$user_list['access_user_id']] = $user_list;
  86. }
  87. }
  88. if (count($students_online) > 0) {
  89. foreach ($students_online as $student_online) {
  90. echo "<tr>
  91. <td>
  92. ";
  93. echo $student_online['name'];
  94. echo " </td>
  95. <td align='center'>
  96. ";
  97. echo $student_online['access_cours_code'];
  98. echo " </td>
  99. <td align='center'>
  100. ";
  101. if (!empty($student_online['email'])) {
  102. echo $student_online['email'];
  103. } else {
  104. echo get_lang('NoEmail');
  105. }
  106. echo " </td>
  107. <td align='center'>
  108. ";
  109. echo '<a href="main/chat/chat.php?cidReq='.$student_online['access_cours_code'].'&id_session='.$student_online['access_session_id'].'"> -> </a>';
  110. echo " </td>
  111. </tr>
  112. ";
  113. }
  114. } else {
  115. echo ' <tr>
  116. <td colspan="4">
  117. '.get_lang('NoOnlineStudents').'
  118. </td>
  119. </tr>
  120. ';
  121. }
  122. }
  123. ?>
  124. </table>
  125. <?php
  126. /*
  127. ==============================================================================
  128. FOOTER
  129. ==============================================================================
  130. */
  131. Display::display_footer();