2 /***************************************************************************
5 * begin : Saturday, Feb 13, 2001
6 * copyright : (C) 2001 The phpBB Group
7 * email : support@phpbb.com
9 * $Id: viewonline.php,v 1.54.2.4 2005/05/06 20:50:10 acydburn Exp $
12 ***************************************************************************/
14 /***************************************************************************
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.
21 ***************************************************************************/
23 define('IN_PHPBB', true);
24 $phpbb_root_path = './';
25 include($phpbb_root_path . 'extension.inc');
26 include($phpbb_root_path . 'common.'.$phpEx);
29 // Start session management
31 $userdata = session_pagestart($user_ip, PAGE_VIEWONLINE);
32 init_userprefs($userdata);
34 // End session management
38 // Output page header and load viewonline template
40 $page_title = $lang['Who_is_Online'];
41 include($phpbb_root_path . 'includes/page_header.'.$phpEx);
43 $template->set_filenames(array(
44 'body' => 'viewonline_body.tpl')
46 make_jumpbox('viewforum.'.$phpEx);
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'])
59 $sql = "SELECT forum_name, forum_id
60 FROM " . FORUMS_TABLE;
61 if ( $result = $db->sql_query($sql) )
63 while( $row = $db->sql_fetchrow($result) )
65 $forum_data[$row['forum_id']] = $row['forum_name'];
70 message_die(GENERAL_ERROR, 'Could not obtain user/online forums information', '', __LINE__, __FILE__, $sql);
76 $is_auth_ary = array();
77 $is_auth_ary = auth(AUTH_VIEW, AUTH_LIST_ALL, $userdata);
82 $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_ip
83 FROM ".USERS_TABLE." u, ".SESSIONS_TABLE." s
84 WHERE u.user_id = s.session_user_id
85 AND s.session_time >= ".( time() - 300 ) . "
86 ORDER BY u.username ASC, s.session_ip ASC";
87 if ( !($result = $db->sql_query($sql)) )
89 message_die(GENERAL_ERROR, 'Could not obtain regd user/online information', '', __LINE__, __FILE__, $sql);
93 $registered_users = 0;
101 while ( $row = $db->sql_fetchrow($result) )
103 $view_online = false;
105 if ( $row['session_logged_in'] )
107 $user_id = $row['user_id'];
109 if ( $user_id != $prev_user )
111 $username = $row['username'];
114 if ( $row['user_level'] == ADMIN )
116 $username = '<b style="color:#' . $theme['fontcolor3'] . '">' . $username . '</b>';
118 else if ( $row['user_level'] == MOD )
120 $username = '<b style="color:#' . $theme['fontcolor2'] . '">' . $username . '</b>';
123 if ( !$row['user_allow_viewonline'] )
125 $view_online = ( $userdata['user_level'] == ADMIN ) ? true : false;
128 $username = '<i>' . $username . '</i>';
136 $which_counter = 'reg_counter';
137 $which_row = 'reg_user_row';
138 $prev_user = $user_id;
143 if ( $row['session_ip'] != $prev_ip )
145 $username = $lang['Guest'];
149 $which_counter = 'guest_counter';
150 $which_row = 'guest_user_row';
154 $prev_ip = $row['session_ip'];
158 if ( $row['session_page'] < 1 || !$is_auth_ary[$row['session_page']]['auth_view'] )
160 switch( $row['session_page'] )
163 $location = $lang['Forum_index'];
164 $location_url = "index.$phpEx";
167 $location = $lang['Posting_message'];
168 $location_url = "index.$phpEx";
171 $location = $lang['Logging_on'];
172 $location_url = "index.$phpEx";
175 $location = $lang['Searching_forums'];
176 $location_url = "search.$phpEx";
179 $location = $lang['Viewing_profile'];
180 $location_url = "index.$phpEx";
182 case PAGE_VIEWONLINE:
183 $location = $lang['Viewing_online'];
184 $location_url = "viewonline.$phpEx";
186 case PAGE_VIEWMEMBERS:
187 $location = $lang['Viewing_member_list'];
188 $location_url = "memberlist.$phpEx";
191 $location = $lang['Viewing_priv_msgs'];
192 $location_url = "privmsg.$phpEx";
195 $location = $lang['Viewing_FAQ'];
196 $location_url = "faq.$phpEx";
199 $location = $lang['Forum_index'];
200 $location_url = "index.$phpEx";
205 $location_url = append_sid("viewforum.$phpEx?" . POST_FORUM_URL . '=' . $row['session_page']);
206 $location = $forum_data[$row['session_page']];
209 $row_color = ( $$which_counter % 2 ) ? $theme['td_color1'] : $theme['td_color2'];
210 $row_class = ( $$which_counter % 2 ) ? $theme['td_class1'] : $theme['td_class2'];
212 $template->assign_block_vars("$which_row", array(
213 'ROW_COLOR' => '#' . $row_color,
214 'ROW_CLASS' => $row_class,
215 'USERNAME' => $username,
216 'LASTUPDATE' => create_date($board_config['default_dateformat'], $row['session_time'], $board_config['board_timezone']),
217 'FORUM_LOCATION' => $location,
219 'U_USER_PROFILE' => append_sid("profile.$phpEx?mode=viewprofile&" . POST_USERS_URL . '=' . $user_id),
220 'U_FORUM_LOCATION' => append_sid($location_url))
227 if( $registered_users == 0 )
229 $l_r_user_s = $lang['Reg_users_zero_online'];
231 else if( $registered_users == 1 )
233 $l_r_user_s = $lang['Reg_user_online'];
237 $l_r_user_s = $lang['Reg_users_online'];
240 if( $hidden_users == 0 )
242 $l_h_user_s = $lang['Hidden_users_zero_online'];
244 else if( $hidden_users == 1 )
246 $l_h_user_s = $lang['Hidden_user_online'];
250 $l_h_user_s = $lang['Hidden_users_online'];
253 if( $guest_users == 0 )
255 $l_g_user_s = $lang['Guest_users_zero_online'];
257 else if( $guest_users == 1 )
259 $l_g_user_s = $lang['Guest_user_online'];
263 $l_g_user_s = $lang['Guest_users_online'];
266 $template->assign_vars(array(
267 'TOTAL_REGISTERED_USERS_ONLINE' => sprintf($l_r_user_s, $registered_users) . sprintf($l_h_user_s, $hidden_users),
268 'TOTAL_GUEST_USERS_ONLINE' => sprintf($l_g_user_s, $guest_users))
271 if ( $registered_users + $hidden_users == 0 )
273 $template->assign_vars(array(
274 'L_NO_REGISTERED_USERS_BROWSING' => $lang['No_users_browsing'])
278 if ( $guest_users == 0 )
280 $template->assign_vars(array(
281 'L_NO_GUESTS_BROWSING' => $lang['No_users_browsing'])
285 $template->pparse('body');
287 include($phpbb_root_path . 'includes/page_tail.'.$phpEx);