whoisonline.php 5.7 KB

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