whoisonline.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Who is online list
  5. */
  6. // language files that should be included
  7. $language_file = array('index', 'registration', 'messages', 'userInfo');
  8. if (!isset($_GET['cidReq'])) {
  9. $cidReset = true;
  10. }
  11. // including necessary files
  12. require_once './main/inc/global.inc.php';
  13. if (isset($_GET['cidReq']) && strlen($_GET['cidReq']) > 0) {
  14. api_protect_course_script(true);
  15. }
  16. $_SESSION['who_is_online_counter'] = 2;
  17. $htmlHeadXtra[] = api_get_js('jquery.endless-scroll.js');
  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>
  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. $(document).ready(function (){
  29. $("input#id_btn_send_invitation").bind("click", function(){
  30. if (confirm("'.get_lang('SendMessageInvitation', '').'")) {
  31. $("#form_register_friend").submit();
  32. }
  33. });
  34. });
  35. function display_hide () {
  36. setTimeout("hide_display_message()",3000);
  37. }
  38. function hide_display_message () {
  39. $("div#display_response_id").html("");
  40. try {
  41. $("#txt_subject_id").val("");
  42. $("#txt_area_invite").val("");
  43. }catch(e) {
  44. $("#txt_area_invite").val("");
  45. }
  46. }
  47. function show_icon_edit(element_html) {
  48. ident="#edit_image";
  49. $(ident).show();
  50. }
  51. function hide_icon_edit(element_html) {
  52. ident="#edit_image";
  53. $(ident).hide();
  54. }
  55. $(document).ready(function() {
  56. $("#link_load_more_items").live("click", function() {
  57. page = $("#link_load_more_items").attr("data_link");
  58. $.ajax({
  59. beforeSend: function(objeto) {
  60. $("#display_response_id").html("'.addslashes(get_lang('Loading')).'");
  61. },
  62. type: "GET",
  63. url: "main/inc/ajax/online.ajax.php?a=load_online_user",
  64. data: "online_page_nr="+page,
  65. success: function(data) {
  66. $("#display_response_id").html("");
  67. if (data != "end") {
  68. $("#link_load_more_items").remove();
  69. var last = $("#online_grid_container li:last");
  70. last.after(data);
  71. } else {
  72. $("#link_load_more_items").remove();
  73. }
  74. }
  75. });
  76. });
  77. });
  78. </script>';
  79. if ($_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 = '".Database::escape_string(
  86. $_user['user_id']
  87. )."', chatcall_date = '".Database::escape_string(
  88. $time
  89. )."', chatcall_text = '' where (user_id = ".(int)Database::escape_string($chatid).")";
  90. $result = Database::query($sql);
  91. //redirect caller to chat
  92. header(
  93. "Location: ".api_get_path(WEB_CODE_PATH)."chat/chat.php?".api_get_cidreq(
  94. )."&origin=whoisonline&target=".Security::remove_XSS($chatid)
  95. );
  96. exit;
  97. }
  98. }
  99. // This if statement prevents users accessing the who's online feature when it has been disabled.
  100. if ((api_get_setting('showonline', 'world') == 'true' && !$_user['user_id']) || ((api_get_setting(
  101. 'showonline',
  102. 'users'
  103. ) == 'true' || api_get_setting('showonline', 'course') == 'true') && $_user['user_id'])
  104. ) {
  105. if (isset($_GET['cidReq']) && strlen($_GET['cidReq']) > 0) {
  106. $user_list = Online::who_is_online_in_this_course(
  107. 0,
  108. 9,
  109. api_get_user_id(),
  110. api_get_setting('time_limit_whosonline'),
  111. $_GET['cidReq']
  112. );
  113. } else {
  114. $user_list = Online::who_is_online(0, 9);
  115. }
  116. if (!isset($_GET['id'])) {
  117. if (api_get_setting('allow_social_tool') == 'true') {
  118. if (!api_is_anonymous()) {
  119. //this include the social menu div
  120. $social_left_content = SocialManager::show_social_menu('whoisonline');
  121. }
  122. }
  123. }
  124. if ($user_list) {
  125. if (!isset($_GET['id'])) {
  126. if (api_get_setting('allow_social_tool') == 'true') {
  127. if (!api_is_anonymous()) {
  128. $query = isset($_GET['q']) ? $_GET['q'] : null;
  129. $social_right_content .= '<div class="span9">'.UserManager::get_search_form($query).'</div>';
  130. }
  131. }
  132. $social_right_content .= SocialManager::display_user_list($user_list);
  133. }
  134. }
  135. if (isset($_GET['id'])) {
  136. if (api_get_setting('allow_social_tool') == 'true') {
  137. header("Location: ".api_get_path(WEB_CODE_PATH)."social/profile.php?u=".intval($_GET['id']));
  138. exit;
  139. } else {
  140. SocialManager::display_individual_user($_GET['id']);
  141. }
  142. }
  143. } else {
  144. api_not_allowed();
  145. exit;
  146. }
  147. $tpl = new Template(get_lang('UsersOnLineList'));
  148. if (api_get_setting('allow_social_tool') == 'true' && !api_is_anonymous()) {
  149. $tpl->set_help('Groups');
  150. $tpl->assign('social_left_content', $social_left_content);
  151. $tpl->assign('social_right_content', $social_right_content);
  152. $social_layout = $tpl->get_template('layout/social_layout.tpl');
  153. $tpl->display($social_layout);
  154. } else {
  155. $tpl->assign('header', get_lang('UsersOnLineList'));
  156. $tpl->assign('content', $social_right_content);
  157. $tpl->display_one_col_template();
  158. }