chat_whoisonline.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use ChamiloSession as Session;
  4. use Chamilo\CoreBundle\Framework\Container;
  5. /**
  6. * Shows the list of connected users
  7. *
  8. * @author Olivier Brouckaert
  9. * @package chamilo.chat
  10. */
  11. define('FRAME', 'online');
  12. //require_once '../inc/global.inc.php';
  13. $course = api_get_course_id();
  14. $courseInfo = api_get_course_info();
  15. $group_id = api_get_group_id();
  16. $session_id = api_get_session_id();
  17. $user_id = api_get_user_id();
  18. $group_condition = " AND to_group_id = '$group_id'";
  19. $extra_condition = '';
  20. if (!empty($group_id)) {
  21. $extra_condition = $group_condition;
  22. }
  23. if (!empty($course)) {
  24. $showPic = isset($_GET['showPic']) ? intval($_GET['showPic']) : null;
  25. $tbl_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER);
  26. $tbl_session_course_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  27. $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
  28. $tbl_session_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
  29. $tbl_user = Database::get_main_table(TABLE_MAIN_USER);
  30. $tbl_chat_connected = Database::get_course_table(TABLE_CHAT_CONNECTED);
  31. $query = "SELECT username FROM $tbl_user WHERE user_id='".$user_id."'";
  32. $result = Database::query($query);
  33. list($pseudo_user) = Database::fetch_array($result);
  34. $isAllowed = !(empty($pseudo_user));
  35. $isMaster = api_is_course_admin();
  36. $date_inter = api_get_utc_datetime(time() - 120);
  37. $users = array();
  38. $course_id = api_get_course_int_id();
  39. if (empty($session_id)) {
  40. $sql = "SELECT DISTINCT
  41. t1.user_id,
  42. username,
  43. firstname,
  44. lastname,
  45. picture_uri,
  46. email,
  47. t3.status
  48. FROM $tbl_user t1, $tbl_chat_connected t2, $tbl_course_user t3
  49. WHERE
  50. t2.c_id = $course_id AND
  51. t1.user_id=t2.user_id AND
  52. t3.user_id=t2.user_id AND
  53. t3.relation_type<>".COURSE_RELATION_TYPE_RRHH." AND
  54. t3.c_id = '".$courseInfo['real_id']."' AND
  55. t2.last_connection>'".$date_inter."' $extra_condition
  56. ORDER BY username";
  57. $result = Database::query($sql);
  58. $users = Database::store_result($result);
  59. } else {
  60. $session_condition = api_get_session_condition($session_id, true, false, 't3.session_id');
  61. // select learners
  62. $query = "SELECT DISTINCT t1.user_id,username,firstname,lastname,picture_uri,email
  63. FROM $tbl_user t1, $tbl_chat_connected t2, $tbl_session_course_user t3
  64. WHERE
  65. t2.c_id = $course_id AND
  66. t1.user_id=t2.user_id AND t3.user_id=t2.user_id AND
  67. t3.session_id = '".$session_id."' AND
  68. t3.c_id = '".$courseInfo['real_id']."' AND
  69. t2.last_connection>'".$date_inter."' $session_condition
  70. ORDER BY username";
  71. $result = Database::query($query);
  72. while ($learner = Database::fetch_array($result)) {
  73. $users[$learner['user_id']] = $learner;
  74. }
  75. // select session coach
  76. $query = "SELECT DISTINCT t1.user_id,username,firstname,lastname,picture_uri,email
  77. FROM $tbl_user t1,$tbl_chat_connected t2,$tbl_session t3
  78. WHERE
  79. t2.c_id = $course_id AND
  80. t1.user_id=t2.user_id AND
  81. t3.id_coach=t2.user_id AND
  82. t3.id = '".$session_id."' AND
  83. t2.last_connection > '".$date_inter."'
  84. $extra_condition
  85. ORDER BY username";
  86. $result = Database::query($query);
  87. if ($coach = Database::fetch_array($result)) {
  88. $users[$coach['user_id']] = $coach;
  89. }
  90. // select session course coach
  91. $query = "SELECT DISTINCT t1.user_id,username,firstname,lastname,picture_uri,email
  92. FROM $tbl_user t1,$tbl_chat_connected t2,$tbl_session_course_user t3
  93. WHERE
  94. t2.c_id = $course_id AND
  95. t1.user_id=t2.user_id
  96. AND t3.user_id =t2.user_id AND t3.status=2
  97. AND t3.session_id = '".$session_id."'
  98. AND t3.c_id = '".$course_id."'
  99. AND t2.last_connection>'".$date_inter."' $extra_condition
  100. ORDER BY username";
  101. $result = Database::query($query);
  102. $course_coaches = array();
  103. while ($coaches = Database::fetch_array($result)) {
  104. $users[$coaches['user_id']] = $coaches;
  105. }
  106. }
  107. require 'header_frame.inc.php';
  108. ?>
  109. <div class="user-connected">
  110. <div id="user-online-scroll" class="user-online">
  111. <div class="title"><?php echo get_lang('Users'); ?> <?php echo get_lang('Connected'); ?></div>
  112. <div class="scrollbar"><div class="track"><div class="thumb"><div class="end"></div></div></div></div>
  113. <div class="scrollbar-inner viewport"><div id="hidden" class="overview">
  114. <ul class="profile list-group">
  115. <?php
  116. foreach ($users as & $user) {
  117. if (empty($session_id)) {
  118. $status = $user['status'];
  119. } else {
  120. $status = CourseManager::is_course_teacher($user['user_id'], api_get_course_id()) ? 1 : 5;
  121. }
  122. $fileUrl = UserManager::getUserPicture($user['user_id'], USER_IMAGE_SIZE_MEDIUM);
  123. $url_user_profile=api_get_path(WEB_CODE_PATH).'social/profile.php?u='.$user['user_id'].'&';
  124. ?>
  125. <li class="list-group-item">
  126. <img src="<?php echo $fileUrl;?>" border="0" width="50" alt="" class="user-image-chat" />
  127. <div class="user-name">
  128. <a href="<?php echo $url_user_profile; ?>" target="_blank">
  129. <?php echo api_get_person_name($user['firstname'], $user['lastname']); ?>
  130. </a>
  131. <?php
  132. if ($status == 1) {
  133. echo Display::return_icon('teachers.gif', get_lang('Teacher'), array('height' => '18'));
  134. } else {
  135. echo Display::return_icon('students.gif', get_lang('Student'), array('height' => '18'));
  136. }
  137. ?>
  138. </div>
  139. <div class="user-email"><?php echo $user['username']; ?></div>
  140. </li>
  141. <?php
  142. }
  143. unset($users);
  144. ?>
  145. </ul>
  146. </div></div></div></div>
  147. <?php
  148. }
  149. require 'footer_frame.inc.php';
  150. // Hide headers
  151. Container::$legacyTemplate = 'layout_one_col_no_content.html.twig';