home *** CD-ROM | disk | FTP | other *** search
/ PC World 2005 April / PCWorld_2005-04_cd.bin / akce / web / phpbb2plus / phpBB2_plus_1.52.exe / phpBB2 / viewonline.php < prev    next >
PHP Script  |  2004-07-18  |  10KB  |  367 lines

  1. <?php
  2. /***************************************************************************
  3.  *                              viewonline.php
  4.  *                            -------------------
  5.  *   begin                : Saturday, Feb 13, 2001
  6.  *   copyright            : (C) 2001 The phpBB Group
  7.  *   email                : support@phpbb.com
  8.  *
  9.  *   $Id: viewonline.php,v 1.54.2.2 2002/12/02 10:53:42 bartvb Exp $
  10.  *
  11.  *
  12.  ***************************************************************************/
  13.  
  14. /***************************************************************************
  15.  *
  16.  *   This program is free software; you can redistribute it and/or modify
  17.  *   it under the terms of the GNU General Public License as published by
  18.  *   the Free Software Foundation; either version 2 of the License, or
  19.  *   (at your option) any later version.
  20.  *
  21.  ***************************************************************************/
  22.  
  23. define('IN_PHPBB', true);
  24. $phpbb_root_path = './';
  25. include($phpbb_root_path . 'extension.inc');
  26. include($phpbb_root_path . 'common.'.$phpEx);
  27.  
  28. //
  29. // Start session management
  30. //
  31. $userdata = session_pagestart($user_ip, PAGE_VIEWONLINE);
  32. init_userprefs($userdata);
  33. //
  34. // End session management
  35. //
  36.  
  37. //
  38. // Output page header and load viewonline template
  39. //
  40. $page_title = $lang['Who_is_Online'];
  41. include($phpbb_root_path . 'includes/page_header.'.$phpEx);
  42.  
  43. $template->set_filenames(array(
  44.     'body' => 'viewonline_body.tpl')
  45. );
  46. make_jumpbox('viewforum.'.$phpEx);
  47.  
  48. $template->assign_vars(array(
  49.     'L_WHOSONLINE' => $lang['Who_is_Online'],
  50.     'L_ONLINE_EXPLAIN' => $lang['Online_explain'],
  51.     'L_USERNAME' => $lang['Username'],
  52.     'L_FORUM_LOCATION' => $lang['Forum_Location'],
  53.     'L_LAST_UPDATE' => $lang['Last_updated'])
  54. );
  55.  
  56. //
  57. // Forum info
  58. //
  59. $sql = "SELECT forum_name, forum_id
  60.     FROM " . FORUMS_TABLE;
  61. if ( $result = $db->sql_query($sql) )
  62. {
  63.     while( $row = $db->sql_fetchrow($result) )
  64.     {
  65.         //-- mod : categories hierarchy --------------------------------------------------------------------
  66. //-- delete
  67. //        $forum_data[$row['forum_id']] = $row['forum_name'];
  68. //-- add
  69.         $forum_data[$row['forum_id']] = get_object_lang(POST_FORUM_URL . $row['forum_id'], 'name');
  70. //-- fin mod : categories hierarchy ----------------------------------------------------------------
  71.  
  72.     }
  73. }
  74. else
  75. {
  76.     message_die(GENERAL_ERROR, 'Could not obtain user/online forums information', '', __LINE__, __FILE__, $sql);
  77. }
  78.  
  79. //
  80. // Get auth data
  81. //
  82. $is_auth_ary = array();
  83. $is_auth_ary = auth(AUTH_VIEW, AUTH_LIST_ALL, $userdata);
  84.  
  85. //
  86. // Get user list
  87. //
  88. $sql = "SELECT u.user_id, u.username, u.user_allow_viewonline, u.user_level, s.session_logged_in, s.session_time, s.session_page, s.session_topic, s.session_ip
  89.     FROM ".USERS_TABLE." u, ".SESSIONS_TABLE." s
  90.     WHERE u.user_id = s.session_user_id
  91.         AND s.session_time >= ".( time() - 300 ) . "
  92.     ORDER BY u.username ASC, s.session_ip ASC";
  93. if ( !($result = $db->sql_query($sql)) )
  94. {
  95.     message_die(GENERAL_ERROR, 'Could not obtain regd user/online information', '', __LINE__, __FILE__, $sql);
  96. }
  97.  
  98. $guest_users = 0;
  99. $registered_users = 0;
  100. $hidden_users = 0;
  101.  
  102. $reg_counter = 0;
  103. $guest_counter = 0;
  104. $prev_user = 0;
  105. $prev_ip = '';
  106.  
  107. while ( $row = $db->sql_fetchrow($result) )
  108. {
  109.     $view_online = false;
  110.  
  111.     if ( $row['session_logged_in'] ) 
  112.     {
  113.         $user_id = $row['user_id'];
  114.  
  115.         if ( $user_id != $prev_user )
  116.         {
  117.             include_once($phpbb_root_path.'includes/functions_color_groups.'.$phpEx);
  118.             $username = color_group_colorize_name($user_id, true);
  119.  
  120.             if ( !$row['user_allow_viewonline'] )
  121.             {
  122.                 $view_online = ( $userdata['user_level'] == ADMIN ) ? true : false;
  123.                 $hidden_users++;
  124.  
  125.                 $username = '<i>' . $username . '</i>';
  126.             }
  127.             else
  128.             {
  129.                 $view_online = true;
  130.                 $registered_users++;
  131.             }
  132.  
  133.             $which_counter = 'reg_counter';
  134.             $which_row = 'reg_user_row';
  135.             $prev_user = $user_id;
  136.         }
  137.     }
  138.     else
  139.     {
  140.         if ( $row['session_ip'] != $prev_ip )
  141.         {
  142.             $username = $lang['Guest'];
  143.             $view_online = true;
  144.             $guest_users++;
  145.     
  146.             $which_counter = 'guest_counter';
  147.             $which_row = 'guest_user_row';
  148.         }
  149.     }
  150.  
  151.     $prev_ip = $row['session_ip'];
  152.  
  153.     if ( $view_online )
  154.     {
  155.         if ( $row['session_page'] < 1 || !$is_auth_ary[$row['session_page']]['auth_view'] )
  156.         {
  157.             switch( $row['session_page'] )
  158.             {
  159.                 case PAGE_INDEX:
  160.                     $location = $lang['Forum_index'];
  161.                     $location_url = "index.$phpEx";
  162.                     break;
  163.                 case PAGE_POSTING:
  164.                     $location = $lang['Posting_message'];
  165.                     $location_url = "index.$phpEx";
  166.                     break;
  167.                 case PAGE_LOGIN:
  168.                     $location = $lang['Logging_on'];
  169.                     $location_url = "index.$phpEx";
  170.                     break;
  171.                 case PAGE_SEARCH:
  172.                     $location = $lang['Searching_forums'];
  173.                     $location_url = "search.$phpEx";
  174.                     break;
  175.                 case PAGE_PROFILE:
  176.                     $location = $lang['Viewing_profile'];
  177.                     $location_url = "index.$phpEx";
  178.                     break;
  179.                 case PAGE_VIEWONLINE:
  180.                     $location = $lang['Viewing_online'];
  181.                     $location_url = "viewonline.$phpEx";
  182.                     break;
  183.                 case PAGE_VIEWMEMBERS:
  184.                     $location = $lang['Viewing_member_list'];
  185.                     $location_url = "memberlist.$phpEx";
  186.                     break;
  187.                 case PAGE_PRIVMSGS:
  188.                     $location = $lang['Viewing_priv_msgs'];
  189.                     $location_url = "privmsg.$phpEx";
  190.                     break;
  191.                 case PAGE_FAQ:
  192.                     $location = $lang['Viewing_FAQ'];
  193.                     $location_url = "faq.$phpEx";
  194.                     break;
  195.                 case PAGE_SHOUTBOX:
  196.                     $location = $lang['Shoutbox'];
  197.                     $location_url = "shoutbox_max.$phpEx";
  198.                     break;    
  199.                 case PAGE_STAFF:
  200.                     $location = $lang['Staff'];
  201.                     $location_url = "staff.$phpEx";
  202.                     break;    
  203.                 case PAGE_ALBUM:
  204.                     $location = "Album Index";
  205.                     $location_url = "album.$phpEx";
  206.                     break;
  207.                 case PAGE_ALBUM_PERSONAL:
  208.                     $location = "Viewing Personal Album of a user";
  209.                     $location_url = "album_personal_index.$phpEx";
  210.                     break;
  211.                 case PAGE_ALBUM_PICTURE:
  212.                     $location = "Viewing Pictures or Posting/Reading comments in the Album";
  213.                     $location_url = "album_showpage.$phpEx";
  214.                     break;
  215.                 case PAGE_ALBUM_SEARCH:
  216.                     $location = "Searching the Album";
  217.                     $location_url = "album_search.$phpEx";
  218.                     break;
  219.                 case PAGE_DOWNLOAD:
  220.                     $location = $lang['Viewing_Download'];
  221.                     $location_url = "dload.$phpEx";
  222.                     break;    
  223.                 // Start add - Complete banner MOD
  224. case PAGE_REDIRECT: 
  225.     require_once($phpbb_root_path . 'language/lang_' . $board_config['default_lang'] . '/lang_banner.' . $phpEx);
  226.  
  227.     if ($row['session_topic'])
  228.     {
  229.         $sql = "SELECT banner_description FROM " . BANNERS_TABLE . " WHERE banner_id=" . $row['session_topic'];
  230.         if ( $result2 = $db->sql_query($sql) )
  231.         {
  232.             $banner_data = $db->sql_fetchrow($result2);
  233.         }
  234.         else
  235.         {    
  236.             message_die(GENERAL_ERROR, 'Could not obtain redirect online information', '', __LINE__, __FILE__, $sql);
  237.         }
  238.         $location_url = append_sid("redirect.$phpEx?banner_id=" . $row['session_topic']);
  239.         $location = $lang['Left_via_banner'] .' --> '.$banner_data['banner_description'];
  240.     } else
  241.     {
  242.         $location_url = "";
  243.         $location = $lang['Left_via_banner'];
  244.     }
  245.     break;
  246. // End add - Complete banner MOD    
  247.                 // Start add - Who viewed a topic MOD
  248.                 case PAGE_TOPIC_VIEW: 
  249.                 $location = $lang['Topic_view_count']; 
  250.                 $location_url = "topic_view_users.$phpEx"; 
  251.                 break;
  252.                 // End add - Who viewed a topic MOD
  253.                 default:
  254.                     $location = $lang['Forum_index'];
  255.                     $location_url = "index.$phpEx";
  256.             }
  257.         }
  258.         else
  259.         {
  260.             // Start replacement - Topic in Who is online MOD
  261. if ($row['session_topic'])
  262. {
  263.     //
  264.     // Topic info
  265.     //
  266.     $sql = "SELECT topic_title FROM " . TOPICS_TABLE . " WHERE topic_id=" . $row['session_topic'];
  267.     if ( $result2 = $db->sql_query($sql) )
  268.     {
  269.         $topic_title = $db->sql_fetchrow($result2);
  270.     }
  271.     else
  272.     {    
  273.         message_die(GENERAL_ERROR, 'Could not obtain user/online forums information', '', __LINE__, __FILE__, $sql);
  274.     }
  275.     $location_url = append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . '=' . $row['session_topic']);
  276.     $location = $forum_data[$row['session_page']] .' -> '.$topic_title['topic_title'];
  277. } else 
  278. {
  279.     $location_url = append_sid("viewforum.$phpEx?" . POST_FORUM_URL . '=' . $row['session_page']);
  280.     $location = $forum_data[$row['session_page']];
  281. }
  282. // End replacement - Topic in Who is online MOD
  283.  
  284.         }
  285.  
  286.         $row_color = ( $$which_counter % 2 ) ? $theme['td_color1'] : $theme['td_color2'];
  287.         $row_class = ( $$which_counter % 2 ) ? $theme['td_class1'] : $theme['td_class2'];
  288.  
  289.         $template->assign_block_vars("$which_row", array(
  290.             'ROW_COLOR' => '#' . $row_color,
  291.             'ROW_CLASS' => $row_class,
  292.             'USERNAME' => $username,
  293.             'LASTUPDATE' => create_date($board_config['default_dateformat'], $row['session_time'], $board_config['board_timezone']),
  294.             'FORUM_LOCATION' => $location,
  295.  
  296.             'U_USER_PROFILE' => append_sid("profile.$phpEx?mode=viewprofile&" . POST_USERS_URL . '=' . $user_id),
  297.             'U_FORUM_LOCATION' => append_sid($location_url))
  298.         );
  299.  
  300.         $$which_counter++;
  301.     }
  302. }
  303.  
  304. if( $registered_users == 0 )
  305. {
  306.     $l_r_user_s = $lang['Reg_users_zero_online'];
  307. }
  308. else if( $registered_users == 1 )
  309. {
  310.     $l_r_user_s = $lang['Reg_user_online'];
  311. }
  312. else
  313. {
  314.     $l_r_user_s = $lang['Reg_users_online'];
  315. }
  316.  
  317. if( $hidden_users == 0 )
  318. {
  319.     $l_h_user_s = $lang['Hidden_users_zero_online'];
  320. }
  321. else if( $hidden_users == 1 )
  322. {
  323.     $l_h_user_s = $lang['Hidden_user_online'];
  324. }
  325. else
  326. {
  327.     $l_h_user_s = $lang['Hidden_users_online'];
  328. }
  329.  
  330. if( $guest_users == 0 )
  331. {
  332.     $l_g_user_s = $lang['Guest_users_zero_online'];
  333. }
  334. else if( $guest_users == 1 )
  335. {
  336.     $l_g_user_s = $lang['Guest_user_online'];
  337. }
  338. else
  339. {
  340.     $l_g_user_s = $lang['Guest_users_online'];
  341. }
  342.  
  343. $template->assign_vars(array(
  344.     'TOTAL_REGISTERED_USERS_ONLINE' => sprintf($l_r_user_s, $registered_users) . sprintf($l_h_user_s, $hidden_users), 
  345.     'TOTAL_GUEST_USERS_ONLINE' => sprintf($l_g_user_s, $guest_users))
  346. );
  347.  
  348. if ( $registered_users + $hidden_users == 0 )
  349. {
  350.     $template->assign_vars(array(
  351.         'L_NO_REGISTERED_USERS_BROWSING' => $lang['No_users_browsing'])
  352.     );
  353. }
  354.  
  355. if ( $guest_users == 0 )
  356. {
  357.     $template->assign_vars(array(
  358.         'L_NO_GUESTS_BROWSING' => $lang['No_users_browsing'])
  359.     );
  360. }
  361.  
  362. $template->pparse('body');
  363.  
  364. include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
  365.  
  366. ?>
  367.