whoisonline.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <?php // $Id: whoisonline.php 21549 2009-06-21 14:02:37Z iflorespaz $
  2. /* For licensing terms, see /chamilo_license.txt */
  3. /**
  4. ==============================================================================
  5. * Who is online list
  6. ==============================================================================
  7. */
  8. // language files that should be included
  9. $language_file = array('index', 'registration', 'messages', 'userInfo');
  10. if (!isset($_GET['cidReq'])) {
  11. $cidReset = true;
  12. }
  13. // including necessary files
  14. require_once './main/inc/global.inc.php';
  15. require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php';
  16. require_once api_get_path(LIBRARY_PATH).'usermanager.lib.php';
  17. require_once api_get_path(LIBRARY_PATH).'social.lib.php';
  18. //social tab
  19. $this_section = SECTION_SOCIAL;
  20. // table definitions
  21. $track_user_table = Database::get_main_table(TABLE_MAIN_USER);
  22. $htmlHeadXtra[] = '<script type="text/javascript">
  23. function show_image(image,width,height) {
  24. width = parseInt(width) + 20;
  25. height = parseInt(height) + 20;
  26. window_x = window.open(image,\'windowX\',\'width=\'+ width + \', height=\'+ height + \'\');
  27. }
  28. </script>';
  29. $htmlHeadXtra[] = '<script type="text/javascript" src="./main/inc/lib/javascript/jquery.js"></script>';
  30. $htmlHeadXtra[] = '<script type="text/javascript" src="./main/inc/lib/javascript/thickbox.js"></script>';
  31. $htmlHeadXtra[] = '<link rel="stylesheet" href="./main/inc/lib/javascript/thickbox.css" type="text/css" media="projection, screen">';
  32. $htmlHeadXtra[] = '<script type="text/javascript">
  33. $(document).ready(function (){
  34. $("input#id_btn_send_invitation").bind("click", function(){
  35. if (confirm("'.get_lang('SendMessageInvitation', '').'")) {
  36. $("#form_register_friend").submit();
  37. }
  38. });
  39. });
  40. function change_panel (mypanel_id,myuser_id) {
  41. $.ajax({
  42. contentType: "application/x-www-form-urlencoded",
  43. beforeSend: function(objeto) {
  44. $("#id_content_panel").html("'.get_lang('Loading', '').'"); },
  45. type: "POST",
  46. url: "main/messages/send_message.php",
  47. data: "panel_id="+mypanel_id+"&user_id="+myuser_id,
  48. success: function(datos) {
  49. $("div#id_content_panel_init").html(datos);
  50. $("div#display_response_id").html("");
  51. }
  52. });
  53. }
  54. function action_database_panel(option_id,myuser_id) {
  55. if (option_id==5) {
  56. my_txt_subject=$("#txt_subject_id").val();
  57. } else {
  58. my_txt_subject="clear";
  59. }
  60. my_txt_content=$("#txt_area_invite").val();
  61. if (my_txt_content.length==0 || my_txt_subject.length==0) {
  62. $("#display_response_id").html("&nbsp;&nbsp;&nbsp;'.get_lang('MessageEmptyMessageOrSubject', '').'");
  63. setTimeout("message_information_display()",3000);
  64. return false;
  65. }
  66. $.ajax({
  67. contentType: "application/x-www-form-urlencoded",
  68. beforeSend: function(objeto) {
  69. $("#display_response_id").html("'.get_lang('Loading', '').'"); },
  70. type: "POST",
  71. url: "main/messages/send_message.php",
  72. data: "panel_id="+option_id+"&user_id="+myuser_id+"&txt_subject="+my_txt_subject+"&txt_content="+my_txt_content,
  73. success: function(datos) {
  74. $("#display_response_id").html(datos);
  75. }
  76. });
  77. }
  78. function display_hide () {
  79. setTimeout("hide_display_message()",3000);
  80. }
  81. function message_information_display() {
  82. $("#display_response_id").html("");
  83. }
  84. function hide_display_message () {
  85. $("div#display_response_id").html("");
  86. try {
  87. $("#txt_subject_id").val("");
  88. $("#txt_area_invite").val("");
  89. }catch(e) {
  90. $("#txt_area_invite").val("");
  91. }
  92. }
  93. </script>';
  94. if ($_GET['chatid'] != '') {
  95. //send out call request
  96. $time = time();
  97. $time = date("Y-m-d H:i:s", $time);
  98. $chatid = addslashes($_GET['chatid']);
  99. if ($_GET['chatid'] == strval(intval($_GET['chatid']))) {
  100. $sql = "update $track_user_table set chatcall_user_id = '".Database::escape_string($_user['user_id'])."', chatcall_date = '".Database::escape_string($time)."', chatcall_text = '' where (user_id = ".(int)Database::escape_string($chatid).")";
  101. $result = Database::query($sql);
  102. //redirect caller to chat
  103. header("Location: ".$_configuration['code_append']."chat/chat.php?".api_get_cidreq()."&origin=whoisonline&target=".Security::remove_XSS($chatid));
  104. exit;
  105. }
  106. }
  107. // This if statement prevents users accessing the who's online feature when it has been disabled.
  108. if ((api_get_setting('showonline', 'world') == 'true' && !$_user['user_id']) || ((api_get_setting('showonline', 'users') == 'true' || api_get_setting('showonline', 'course') == 'true') && $_user['user_id'])) {
  109. if(isset($_GET['cidReq']) && strlen($_GET['cidReq']) > 0) {
  110. $user_list = who_is_online_in_this_course($_user['user_id'], api_get_setting('time_limit_whosonline'), $_GET['cidReq']);
  111. } else {
  112. $user_list = who_is_online(api_get_setting('time_limit_whosonline'));
  113. }
  114. $total = count($user_list);
  115. if (!isset($_GET['id'])) {
  116. Display::display_header(get_lang('UsersOnLineList'));
  117. if (api_get_setting('allow_social_tool') == 'true') {
  118. if (!api_is_anonymous()) {
  119. echo '<div id="social-content-left">';
  120. //this include the social menu div
  121. SocialManager::show_social_menu('whoisonline');
  122. echo '</div>';
  123. }
  124. if ($_GET['id'] == '') {
  125. //echo '<p><a class="refresh" href="javascript:window.location.reload()">'.get_lang('Refresh').'</a></p>';
  126. } /*else {
  127. if (0) {
  128. // if ($_user['user_id'] && $_GET["id"] != $_user['user_id']) {
  129. echo '<a href="'.api_get_self().'?chatid='.Security::remove_XSS($_GET['id']).'">'.get_lang('SendChatRequest').'</a>';
  130. }
  131. }*/
  132. } else {
  133. echo '<div class="actions-title">';
  134. echo get_lang('UsersOnLineList');
  135. echo '</div>';
  136. }
  137. }
  138. if ($user_list) {
  139. if (!isset($_GET['id'])) {
  140. if (api_get_setting('allow_social_tool') == 'true') {
  141. echo '<div id="social-content-right">';
  142. //this include the social menu div
  143. if (!api_is_anonymous()) {
  144. echo UserManager::get_search_form($_GET['q']);
  145. }
  146. }
  147. SocialManager::display_user_list($user_list);
  148. echo '</div>';
  149. } else {
  150. //individual user information - also displays header info
  151. SocialManager::display_individual_user(Security::remove_XSS($_GET['id']));
  152. }
  153. } elseif (isset($_GET['id'])) {
  154. Display::display_header(get_lang('UsersOnLineList'));
  155. echo '<div class="actions-title">';
  156. echo get_lang('UsersOnLineList');
  157. echo '</div>';
  158. }
  159. } else {
  160. Display::display_header(get_lang('UsersOnLineList'));
  161. Display::display_error_message(get_lang('AccessNotAllowed'));
  162. }
  163. $referer = empty($_GET['referer']) ? 'index.php' : api_htmlentities(strip_tags($_GET['referer']), ENT_QUOTES);
  164. /*
  165. ==============================================================================
  166. FOOTER
  167. ==============================================================================
  168. */
  169. Display::display_footer();