chat_whoisonline.php 5.8 KB

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