Rev Author Line No. Line
130 kaklik 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.4 2005/05/06 20:50:10 acydburn 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 $forum_data[$row['forum_id']] = $row['forum_name'];
66 }
67 }
68 else
69 {
70 message_die(GENERAL_ERROR, 'Could not obtain user/online forums information', '', __LINE__, __FILE__, $sql);
71 }
72  
73 //
74 // Get auth data
75 //
76 $is_auth_ary = array();
77 $is_auth_ary = auth(AUTH_VIEW, AUTH_LIST_ALL, $userdata);
78  
79 //
80 // Get user list
81 //
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)) )
88 {
89 message_die(GENERAL_ERROR, 'Could not obtain regd user/online information', '', __LINE__, __FILE__, $sql);
90 }
91  
92 $guest_users = 0;
93 $registered_users = 0;
94 $hidden_users = 0;
95  
96 $reg_counter = 0;
97 $guest_counter = 0;
98 $prev_user = 0;
99 $prev_ip = '';
100  
101 while ( $row = $db->sql_fetchrow($result) )
102 {
103 $view_online = false;
104  
105 if ( $row['session_logged_in'] )
106 {
107 $user_id = $row['user_id'];
108  
109 if ( $user_id != $prev_user )
110 {
111 $username = $row['username'];
112  
113 $style_color = '';
114 if ( $row['user_level'] == ADMIN )
115 {
116 $username = '<b style="color:#' . $theme['fontcolor3'] . '">' . $username . '</b>';
117 }
118 else if ( $row['user_level'] == MOD )
119 {
120 $username = '<b style="color:#' . $theme['fontcolor2'] . '">' . $username . '</b>';
121 }
122  
123 if ( !$row['user_allow_viewonline'] )
124 {
125 $view_online = ( $userdata['user_level'] == ADMIN ) ? true : false;
126 $hidden_users++;
127  
128 $username = '<i>' . $username . '</i>';
129 }
130 else
131 {
132 $view_online = true;
133 $registered_users++;
134 }
135  
136 $which_counter = 'reg_counter';
137 $which_row = 'reg_user_row';
138 $prev_user = $user_id;
139 }
140 }
141 else
142 {
143 if ( $row['session_ip'] != $prev_ip )
144 {
145 $username = $lang['Guest'];
146 $view_online = true;
147 $guest_users++;
148  
149 $which_counter = 'guest_counter';
150 $which_row = 'guest_user_row';
151 }
152 }
153  
154 $prev_ip = $row['session_ip'];
155  
156 if ( $view_online )
157 {
158 if ( $row['session_page'] < 1 || !$is_auth_ary[$row['session_page']]['auth_view'] )
159 {
160 switch( $row['session_page'] )
161 {
162 case PAGE_INDEX:
163 $location = $lang['Forum_index'];
164 $location_url = "index.$phpEx";
165 break;
166 case PAGE_POSTING:
167 $location = $lang['Posting_message'];
168 $location_url = "index.$phpEx";
169 break;
170 case PAGE_LOGIN:
171 $location = $lang['Logging_on'];
172 $location_url = "index.$phpEx";
173 break;
174 case PAGE_SEARCH:
175 $location = $lang['Searching_forums'];
176 $location_url = "search.$phpEx";
177 break;
178 case PAGE_PROFILE:
179 $location = $lang['Viewing_profile'];
180 $location_url = "index.$phpEx";
181 break;
182 case PAGE_VIEWONLINE:
183 $location = $lang['Viewing_online'];
184 $location_url = "viewonline.$phpEx";
185 break;
186 case PAGE_VIEWMEMBERS:
187 $location = $lang['Viewing_member_list'];
188 $location_url = "memberlist.$phpEx";
189 break;
190 case PAGE_PRIVMSGS:
191 $location = $lang['Viewing_priv_msgs'];
192 $location_url = "privmsg.$phpEx";
193 break;
194 case PAGE_FAQ:
195 $location = $lang['Viewing_FAQ'];
196 $location_url = "faq.$phpEx";
197 break;
198 default:
199 $location = $lang['Forum_index'];
200 $location_url = "index.$phpEx";
201 }
202 }
203 else
204 {
205 $location_url = append_sid("viewforum.$phpEx?" . POST_FORUM_URL . '=' . $row['session_page']);
206 $location = $forum_data[$row['session_page']];
207 }
208  
209 $row_color = ( $$which_counter % 2 ) ? $theme['td_color1'] : $theme['td_color2'];
210 $row_class = ( $$which_counter % 2 ) ? $theme['td_class1'] : $theme['td_class2'];
211  
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,
218  
219 'U_USER_PROFILE' => append_sid("profile.$phpEx?mode=viewprofile&amp;" . POST_USERS_URL . '=' . $user_id),
220 'U_FORUM_LOCATION' => append_sid($location_url))
221 );
222  
223 $$which_counter++;
224 }
225 }
226  
227 if( $registered_users == 0 )
228 {
229 $l_r_user_s = $lang['Reg_users_zero_online'];
230 }
231 else if( $registered_users == 1 )
232 {
233 $l_r_user_s = $lang['Reg_user_online'];
234 }
235 else
236 {
237 $l_r_user_s = $lang['Reg_users_online'];
238 }
239  
240 if( $hidden_users == 0 )
241 {
242 $l_h_user_s = $lang['Hidden_users_zero_online'];
243 }
244 else if( $hidden_users == 1 )
245 {
246 $l_h_user_s = $lang['Hidden_user_online'];
247 }
248 else
249 {
250 $l_h_user_s = $lang['Hidden_users_online'];
251 }
252  
253 if( $guest_users == 0 )
254 {
255 $l_g_user_s = $lang['Guest_users_zero_online'];
256 }
257 else if( $guest_users == 1 )
258 {
259 $l_g_user_s = $lang['Guest_user_online'];
260 }
261 else
262 {
263 $l_g_user_s = $lang['Guest_users_online'];
264 }
265  
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))
269 );
270  
271 if ( $registered_users + $hidden_users == 0 )
272 {
273 $template->assign_vars(array(
274 'L_NO_REGISTERED_USERS_BROWSING' => $lang['No_users_browsing'])
275 );
276 }
277  
278 if ( $guest_users == 0 )
279 {
280 $template->assign_vars(array(
281 'L_NO_GUESTS_BROWSING' => $lang['No_users_browsing'])
282 );
283 }
284  
285 $template->pparse('body');
286  
287 include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
288  
289 ?>