whoisonline.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Who is online list
  5. */
  6. if (!isset($_GET['cidReq'])) {
  7. $cidReset = true;
  8. }
  9. // including necessary files
  10. require_once './main/inc/global.inc.php';
  11. if (isset($_GET['cidReq']) && strlen($_GET['cidReq']) > 0) {
  12. api_protect_course_script(true);
  13. }
  14. require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php';
  15. $_SESSION['who_is_online_counter'] = 2;
  16. $htmlHeadXtra[] = api_get_js('jquery.endless-scroll.js');
  17. //social tab
  18. $this_section = SECTION_SOCIAL;
  19. // table definitions
  20. $track_user_table = Database::get_main_table(TABLE_MAIN_USER);
  21. $htmlHeadXtra[] = '<script>
  22. function show_image(image,width,height) {
  23. width = parseInt(width) + 20;
  24. height = parseInt(height) + 20;
  25. window_x = window.open(image,\'windowX\',\'width=\'+ width + \', height=\'+ height + \'\');
  26. }
  27. $(document).ready(function (){
  28. $("input#id_btn_send_invitation").bind("click", function(){
  29. if (confirm("'.get_lang('SendMessageInvitation', '').'")) {
  30. $("#form_register_friend").submit();
  31. }
  32. });
  33. });
  34. function display_hide () {
  35. setTimeout("hide_display_message()",3000);
  36. }
  37. function hide_display_message () {
  38. $("div#display_response_id").html("");
  39. try {
  40. $("#txt_subject_id").val("");
  41. $("#txt_area_invite").val("");
  42. }catch(e) {
  43. $("#txt_area_invite").val("");
  44. }
  45. }
  46. function show_icon_edit(element_html) {
  47. ident="#edit_image";
  48. $(ident).show();
  49. }
  50. function hide_icon_edit(element_html) {
  51. ident="#edit_image";
  52. $(ident).hide();
  53. }
  54. $(document).ready(function() {
  55. $("#link_load_more_items").click(function() {
  56. page = $("#link_load_more_items").attr("data_link");
  57. $.ajax({
  58. beforeSend: function(objeto) {
  59. $("#display_response_id").html("'.addslashes(get_lang('Loading')).'");
  60. },
  61. type: "GET",
  62. url: "main/inc/ajax/online.ajax.php?a=load_online_user",
  63. data: "online_page_nr="+page,
  64. success: function(data) {
  65. $("#display_response_id").html("");
  66. if (data != "end") {
  67. $("#link_load_more_items").remove();
  68. var last = $("#online_grid_container li:last");
  69. last.after(data);
  70. } else {
  71. $("#link_load_more_items").remove();
  72. }
  73. }
  74. });
  75. });
  76. });
  77. </script>';
  78. $social_right_content = null;
  79. if (isset($_GET['chatid'])) {
  80. //send out call request
  81. $time = time();
  82. $time = date("Y-m-d H:i:s", $time);
  83. $chatid = intval($_GET['chatid']);
  84. if ($_GET['chatid'] == strval(intval($_GET['chatid']))) {
  85. $sql = "update $track_user_table set chatcall_user_id = ".intval($_user['user_id']).", chatcall_date = '".Database::escape_string($time)."', chatcall_text = '' where (user_id = ".(int)Database::escape_string($chatid).")";
  86. $result = Database::query($sql);
  87. //redirect caller to chat
  88. header("Location: ".api_get_path(WEB_CODE_PATH)."chat/chat.php?".api_get_cidreq()."&origin=whoisonline&target=".Security::remove_XSS($chatid));
  89. exit;
  90. }
  91. }
  92. // This if statement prevents users accessing the who's online feature when it has been disabled.
  93. if ((api_get_setting('showonline', 'world') == 'true' && !$_user['user_id']) ||
  94. ((api_get_setting('showonline', 'users') == 'true' || api_get_setting('showonline', 'course') == 'true') && $_user['user_id'])
  95. ) {
  96. if (isset($_GET['cidReq']) && strlen($_GET['cidReq']) > 0) {
  97. $user_list = who_is_online_in_this_course(0, 9, api_get_user_id(), api_get_setting('time_limit_whosonline'), $_GET['cidReq']);
  98. } else {
  99. $user_list = who_is_online(0, 9);
  100. }
  101. if (!isset($_GET['id'])) {
  102. if (api_get_setting('allow_social_tool') == 'true') {
  103. if (!api_is_anonymous()) {
  104. //this include the social menu div
  105. $social_left_content = SocialManager::show_social_menu('whoisonline');
  106. }
  107. }
  108. }
  109. if ($user_list) {
  110. if (!isset($_GET['id'])) {
  111. if (api_get_setting('allow_social_tool') == 'true') {
  112. if (!api_is_anonymous()) {
  113. $query = isset($_GET['q']) ? $_GET['q']: null;
  114. $social_right_content .= '<div class="span9">'.UserManager::get_search_form($query).'</div>';
  115. }
  116. }
  117. $social_right_content .= SocialManager::display_user_list($user_list);
  118. }
  119. }
  120. if (isset($_GET['id'])) {
  121. if (api_get_setting('allow_social_tool') == 'true' && api_user_is_login()) {
  122. header("Location: ".api_get_path(WEB_CODE_PATH)."social/profile.php?u=".intval($_GET['id']));
  123. exit;
  124. } else {
  125. $social_right_content .= SocialManager::display_individual_user($_GET['id']);
  126. }
  127. }
  128. } else {
  129. api_not_allowed();
  130. exit;
  131. }
  132. $tpl = new Template(get_lang('UsersOnLineList'));
  133. if (api_get_setting('allow_social_tool') == 'true' && !api_is_anonymous()) {
  134. $tpl->assign('social_avatar_block', $social_left_content);
  135. $tpl->assign('social_search_block', $social_right_content);
  136. $social_layout = $tpl->get_template('social/home.tpl');
  137. $tpl->display($social_layout);
  138. } else {
  139. $content = $social_right_content;
  140. $tpl->assign('actions', $actions);
  141. $tpl->assign('message', $show_message);
  142. $tpl->assign('header', get_lang('UsersOnLineList'));
  143. $tpl->assign('content', $content);
  144. $tpl->display_one_col_template();
  145. }