whoisonline.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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(0, 9, api_get_user_id(), api_get_setting('time_limit_whosonline'), $_GET['cidReq']);
  41. } else {
  42. $user_list = who_is_online(0, 9);
  43. }
  44. /* if (!isset($_GET['id'])) {
  45. if (api_get_setting('allow_social_tool') == 'true') {
  46. if (!api_is_anonymous()) {
  47. //this include the social menu div
  48. $social_left_content = SocialManager::show_social_menu('whoisonline');
  49. }
  50. }
  51. }
  52. */
  53. if ($user_list) {
  54. if (!isset($_GET['id'])) {
  55. if (api_get_setting('allow_social_tool') == 'true') {
  56. if (!api_is_anonymous()) {
  57. $query = isset($_GET['q']) ? $_GET['q']: null;
  58. $social_search = UserManager::get_search_form($query);
  59. }
  60. }
  61. $social_right_content .= SocialManager::display_user_list($user_list);
  62. }
  63. }
  64. $whoisonline_list .= SocialManager::display_user_list($user_list);
  65. if (isset($_GET['id'])) {
  66. if (api_get_setting('allow_social_tool') == 'true' && api_user_is_login()) {
  67. header("Location: ".api_get_path(WEB_CODE_PATH)."social/profile.php?u=".intval($_GET['id']));
  68. exit;
  69. } else {
  70. $social_right_content .= SocialManager::display_individual_user($_GET['id']);
  71. }
  72. }
  73. } else {
  74. api_not_allowed();
  75. exit;
  76. }
  77. $tpl = new Template(get_lang('UsersOnLineList'));
  78. if (api_get_setting('allow_social_tool') == 'true' && !api_is_anonymous()) {
  79. $tpl->assign('whoisonline', $whoisonline_list);
  80. $tpl->assign('social_search', $social_search);
  81. $social_layout = $tpl->get_template('social/whoisonline.tpl');
  82. $tpl->display($social_layout);
  83. } else {
  84. $content = $social_right_content;
  85. $tpl->assign('header', get_lang('UsersOnLineList'));
  86. $tpl->assign('content', $content);
  87. $tpl->display_one_col_template();
  88. }