whoisonline.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. $_SESSION['who_is_online_counter'] = 2;
  15. $this_section = SECTION_SOCIAL;
  16. // table definitions
  17. $track_user_table = Database::get_main_table(TABLE_MAIN_USER);
  18. $social_right_content = null;
  19. $whoisonline_list = null;
  20. $social_search = '';
  21. /* if (isset($_GET['chatid'])) {
  22. //send out call request
  23. $time = time();
  24. $time = date("Y-m-d H:i:s", $time);
  25. $chatid = intval($_GET['chatid']);
  26. if ($_GET['chatid'] == strval(intval($_GET['chatid']))) {
  27. $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).")";
  28. $result = Database::query($sql);
  29. //redirect caller to chat
  30. header("Location: ".api_get_path(WEB_CODE_PATH)."chat/chat.php?".api_get_cidreq()."&origin=whoisonline&target=".Security::remove_XSS($chatid));
  31. exit;
  32. }
  33. }
  34. */
  35. // This if statement prevents users accessing the who's online feature when it has been disabled.
  36. if ((api_get_setting('showonline', 'world') == 'true' && !$_user['user_id']) ||
  37. ((api_get_setting('showonline', 'users') == 'true' || api_get_setting('showonline', 'course') == 'true') && $_user['user_id'])
  38. ) {
  39. if (isset($_GET['cidReq']) && strlen($_GET['cidReq']) > 0) {
  40. $user_list = who_is_online_in_this_course(
  41. 0,
  42. 12,
  43. api_get_user_id(),
  44. api_get_setting('time_limit_whosonline'),
  45. $_GET['cidReq']
  46. );
  47. } else {
  48. $user_list = who_is_online(0, 12);
  49. }
  50. /* if (!isset($_GET['id'])) {
  51. if (api_get_setting('allow_social_tool') == 'true') {
  52. if (!api_is_anonymous()) {
  53. //this include the social menu div
  54. $social_left_content = SocialManager::show_social_menu('whoisonline');
  55. }
  56. }
  57. }
  58. */
  59. if ($user_list) {
  60. if (!isset($_GET['id'])) {
  61. if (api_get_setting('allow_social_tool') == 'true') {
  62. if (!api_is_anonymous()) {
  63. $query = isset($_GET['q']) ? $_GET['q']: null;
  64. $social_search = UserManager::get_search_form($query);
  65. }
  66. }
  67. $social_right_content .= SocialManager::display_user_list($user_list);
  68. }
  69. }
  70. $whoisonline_list .= SocialManager::display_user_list($user_list);
  71. if (isset($_GET['id'])) {
  72. if (api_get_setting('allow_social_tool') == 'true' && api_user_is_login()) {
  73. header("Location: ".api_get_path(WEB_CODE_PATH)."social/profile.php?u=".intval($_GET['id']));
  74. exit;
  75. } else {
  76. $social_right_content .= SocialManager::display_individual_user($_GET['id']);
  77. }
  78. }
  79. } else {
  80. api_not_allowed();
  81. exit;
  82. }
  83. $tpl = new Template(get_lang('UsersOnLineList'));
  84. if (api_get_setting('allow_social_tool') == 'true' && !api_is_anonymous()) {
  85. $tpl->assign('whoisonline', $whoisonline_list);
  86. $tpl->assign('social_search', $social_search);
  87. } else {
  88. $tpl->assign('whoisonline', $social_right_content);
  89. }
  90. $social_layout = $tpl->get_template('social/whoisonline.tpl');
  91. $tpl->display($social_layout);