chat_whoisonline.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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 = intval($_SESSION['_gid']);
  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 = intval($_GET['showPic']);
  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,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 FROM $tbl_user t1, $tbl_chat_connected t2, $tbl_session_course_user t3
  58. WHERE
  59. t2.c_id = $course_id AND
  60. t1.user_id=t2.user_id AND t3.id_user=t2.user_id AND
  61. t3.id_session = '".$session_id."' AND
  62. t3.c_id = '".$course_id."' AND t2.last_connection>'".$date_inter."' $extra_condition
  63. ORDER BY username";
  64. $result = Database::query($query);
  65. while ($learner = Database::fetch_array($result)) {
  66. $users[$learner['user_id']] = $learner;
  67. }
  68. // select session coach
  69. $query = "SELECT DISTINCT t1.user_id,username,firstname,lastname,picture_uri
  70. FROM $tbl_user t1,$tbl_chat_connected t2,$tbl_session t3
  71. WHERE t2.c_id = $course_id AND
  72. 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";
  73. $result = Database::query($query);
  74. if ($coach = Database::fetch_array($result)) {
  75. $users[$coach['user_id']] = $coach;
  76. }
  77. // select session course coach
  78. $query = "SELECT DISTINCT t1.user_id,username,firstname,lastname,picture_uri
  79. FROM $tbl_user t1,$tbl_chat_connected t2,$tbl_session_course_user t3
  80. WHERE
  81. t2.c_id = $course_id AND
  82. t1.user_id=t2.user_id
  83. AND t3.id_user=t2.user_id AND t3.status=2
  84. AND t3.id_session = '".$session_id."'
  85. AND t3.c_id = '".api_get_course_int_id()."'
  86. AND t2.last_connection>'".$date_inter."' $extra_condition ORDER BY username";
  87. $result = Database::query($query);
  88. $course_coaches = array();
  89. while ($coaches = Database::fetch_array($result)) {
  90. //$course_coaches[] = $coaches['user_id'];
  91. $users[$coaches['user_id']] = $coaches;
  92. }
  93. //if ($coach = Database::fetch_array($result))
  94. // $users[$coach['user_id']] = $coach;
  95. }
  96. $user_id = $enreg['user_id'];
  97. require 'header_frame.inc.php';
  98. ?>
  99. <table border="0" cellpadding="0" cellspacing="0" width="100%" class="data_table">
  100. <tr><th colspan="2"><?php echo get_lang('Connected'); ?></th></tr>
  101. <?php
  102. foreach ($users as & $user) {
  103. if (empty($session_id)) {
  104. $status = $user['status'];
  105. } else {
  106. $status = CourseManager::is_course_teacher($user['user_id'], api_get_course_int_id()) ? 1 : 5;
  107. }
  108. $user_image = UserManager::get_user_picture_path_by_id($user['user_id'], 'web', false, true);
  109. $file_url = $user_image['dir'].$user_image['file'];
  110. ?>
  111. <tr>
  112. <td width="1%" valign="top"><img src="<?php echo $file_url;?>" border="0" width="22" alt="" /></td>
  113. <td width="99%"><?php if ($status == 1) echo Display::return_icon('teachers.gif', get_lang('Teacher'), array('height' => '11')).' '; else echo Display::return_icon('students.gif', get_lang('Student'), array('height' => '11')); ?><a <?php if ($status == 1) echo 'class="master"'; ?> name="user_<?php echo $user['user_id']; ?>" href="<?php echo api_get_self(); ?>?<?php echo api_get_cidreq(); ?>&showPic=<?php if ($showPic == $user['user_id']) echo '0'; else echo $user['user_id']; ?>#user_<?php echo $user['user_id']; ?>"><?php echo api_get_person_name($user['firstname'], $user['lastname']); ?></a></td>
  114. </tr>
  115. <?php
  116. if ($showPic == $user['user_id']) { ?>
  117. <tr>
  118. <td colspan="2" align="center"><img src="<?php echo $file_url; ?>" border="0" width="100" alt="" /></td>
  119. </tr>
  120. <?php
  121. }
  122. }
  123. unset($users);
  124. ?>
  125. </table>
  126. <?php
  127. }
  128. require 'footer_frame.inc.php';