chat_whoisonline.php 5.9 KB

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