phpBB
Statistics
| Revision:

root / tags / release_2_0_1 / phpBB / viewonline.php

History | View | Annotate | Download (7 kB)

1 146 psotfx
<?php
2 943 thefinn
/***************************************************************************
3 932 psotfx
 *                              viewonline.php
4 943 thefinn
 *                            -------------------
5 943 thefinn
 *   begin                : Saturday, Feb 13, 2001
6 943 thefinn
 *   copyright            : (C) 2001 The phpBB Group
7 943 thefinn
 *   email                : support@phpbb.com
8 943 thefinn
 *
9 146 psotfx
 *   $Id$
10 943 thefinn
 *
11 943 thefinn
 *
12 943 thefinn
 ***************************************************************************/
13 146 psotfx
14 943 thefinn
/***************************************************************************
15 943 thefinn
 *
16 943 thefinn
 *   This program is free software; you can redistribute it and/or modify
17 943 thefinn
 *   it under the terms of the GNU General Public License as published by
18 943 thefinn
 *   the Free Software Foundation; either version 2 of the License, or
19 943 thefinn
 *   (at your option) any later version.
20 943 thefinn
 *
21 943 thefinn
 ***************************************************************************/
22 943 thefinn
23 2305 psotfx
define('IN_PHPBB', true);
24 2448 psotfx
$phpbb_root_path = './';
25 646 psotfx
include($phpbb_root_path . 'extension.inc');
26 646 psotfx
include($phpbb_root_path . 'common.'.$phpEx);
27 146 psotfx
28 146 psotfx
//
29 146 psotfx
// Start session management
30 146 psotfx
//
31 2137 psotfx
$userdata = session_pagestart($user_ip, PAGE_VIEWONLINE);
32 146 psotfx
init_userprefs($userdata);
33 146 psotfx
//
34 146 psotfx
// End session management
35 146 psotfx
//
36 146 psotfx
37 311 psotfx
//
38 2448 psotfx
// Output page header and load viewonline template
39 311 psotfx
//
40 904 psotfx
$page_title = $lang['Who_is_online'];
41 646 psotfx
include($phpbb_root_path . 'includes/page_header.'.$phpEx);
42 146 psotfx
43 311 psotfx
$template->set_filenames(array(
44 2448 psotfx
        'body' => 'viewonline_body.tpl')
45 311 psotfx
);
46 2448 psotfx
make_jumpbox('viewforum.'.$phpEx);
47 646 psotfx
48 311 psotfx
$template->assign_vars(array(
49 2448 psotfx
        'L_WHOSONLINE' => $lang['Who_is_online'],
50 2448 psotfx
        'L_ONLINE_EXPLAIN' => $lang['Online_explain'],
51 2448 psotfx
        'L_USERNAME' => $lang['Username'],
52 2448 psotfx
        'L_FORUM_LOCATION' => $lang['Forum_Location'],
53 2448 psotfx
        'L_LAST_UPDATE' => $lang['Last_updated'])
54 311 psotfx
);
55 311 psotfx
56 2137 psotfx
//
57 2137 psotfx
// Forum info
58 2137 psotfx
//
59 281 psotfx
$sql = "SELECT forum_name, forum_id
60 680 psotfx
        FROM " . FORUMS_TABLE;
61 2451 psotfx
if ( $result = $db->sql_query($sql) )
62 146 psotfx
{
63 2137 psotfx
        while( $row = $db->sql_fetchrow($result) )
64 290 psotfx
        {
65 2137 psotfx
                $forum_data[$row['forum_id']] = $row['forum_name'];
66 290 psotfx
        }
67 290 psotfx
}
68 646 psotfx
else
69 281 psotfx
{
70 2448 psotfx
        message_die(GENERAL_ERROR, 'Could not obtain user/online forums information', '', __LINE__, __FILE__, $sql);
71 146 psotfx
}
72 146 psotfx
73 904 psotfx
//
74 1260 psotfx
// Get auth data
75 1260 psotfx
//
76 1260 psotfx
$is_auth_ary = array();
77 1260 psotfx
$is_auth_ary = auth(AUTH_VIEW, AUTH_LIST_ALL, $userdata);
78 1260 psotfx
79 1260 psotfx
//
80 2137 psotfx
// Get user list
81 904 psotfx
//
82 2516 psotfx
$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 2448 psotfx
        FROM ".USERS_TABLE." u, ".SESSIONS_TABLE." s
84 2448 psotfx
        WHERE u.user_id = s.session_user_id
85 2516 psotfx
                AND s.session_time >= ".( time() - 300 ) . "
86 2448 psotfx
        ORDER BY u.username ASC, s.session_ip ASC";
87 2137 psotfx
if ( !($result = $db->sql_query($sql)) )
88 2137 psotfx
{
89 2448 psotfx
        message_die(GENERAL_ERROR, 'Could not obtain regd user/online information', '', __LINE__, __FILE__, $sql);
90 2137 psotfx
}
91 1260 psotfx
92 2465 psotfx
$guest_users = 0;
93 2465 psotfx
$registered_users = 0;
94 2465 psotfx
$hidden_users = 0;
95 698 psotfx
96 2465 psotfx
$reg_counter = 0;
97 2465 psotfx
$guest_counter = 0;
98 2465 psotfx
$prev_user = 0;
99 2473 psotfx
$prev_ip = '';
100 2137 psotfx
101 2465 psotfx
while ( $row = $db->sql_fetchrow($result) )
102 2465 psotfx
{
103 2473 psotfx
        $view_online = false;
104 2465 psotfx
105 2465 psotfx
        if ( $row['session_logged_in'] )
106 146 psotfx
        {
107 2465 psotfx
                $user_id = $row['user_id'];
108 2139 psotfx
109 2465 psotfx
                if ( $user_id != $prev_user )
110 146 psotfx
                {
111 2465 psotfx
                        $username = $row['username'];
112 1277 psotfx
113 2465 psotfx
                        $style_color = '';
114 2465 psotfx
                        if ( $row['user_level'] == ADMIN )
115 188 psotfx
                        {
116 2465 psotfx
                                $username = '<b style="color:#' . $theme['fontcolor3'] . '">' . $username . '</b>';
117 2465 psotfx
                        }
118 2465 psotfx
                        else if ( $row['user_level'] == MOD )
119 2465 psotfx
                        {
120 2465 psotfx
                                $username = '<b style="color:#' . $theme['fontcolor2'] . '">' . $username . '</b>';
121 2465 psotfx
                        }
122 904 psotfx
123 2465 psotfx
                        if ( !$row['user_allow_viewonline'] )
124 2465 psotfx
                        {
125 2473 psotfx
                                $view_online = ( $userdata['user_level'] == ADMIN ) ? true : false;
126 2465 psotfx
                                $hidden_users++;
127 904 psotfx
128 2475 psotfx
                                $username = '<i>' . $username . '</i>';
129 2465 psotfx
                        }
130 2465 psotfx
                        else
131 2465 psotfx
                        {
132 2473 psotfx
                                $view_online = true;
133 2465 psotfx
                                $registered_users++;
134 2465 psotfx
                        }
135 2139 psotfx
136 2465 psotfx
                        $which_counter = 'reg_counter';
137 2465 psotfx
                        $which_row = 'reg_user_row';
138 2465 psotfx
                        $prev_user = $user_id;
139 146 psotfx
                }
140 2465 psotfx
        }
141 2465 psotfx
        else
142 2465 psotfx
        {
143 2465 psotfx
                if ( $row['session_ip'] != $prev_ip )
144 2137 psotfx
                {
145 2516 psotfx
                        $username = $lang['Guest'];
146 2473 psotfx
                        $view_online = true;
147 2465 psotfx
                        $guest_users++;
148 2465 psotfx
149 2465 psotfx
                        $which_counter = 'guest_counter';
150 2465 psotfx
                        $which_row = 'guest_user_row';
151 2137 psotfx
                }
152 2465 psotfx
        }
153 1616 psotfx
154 2465 psotfx
        $prev_ip = $row['session_ip'];
155 2451 psotfx
156 2465 psotfx
        if ( $view_online )
157 2465 psotfx
        {
158 2516 psotfx
                if ( $row['session_page'] < 1 || !$is_auth_ary[$row['session_page']]['auth_view'] )
159 1277 psotfx
                {
160 2516 psotfx
                        switch( $row['session_page'] )
161 146 psotfx
                        {
162 2465 psotfx
                                case PAGE_INDEX:
163 2465 psotfx
                                        $location = $lang['Forum_index'];
164 2465 psotfx
                                        $location_url = "index.$phpEx";
165 2465 psotfx
                                        break;
166 2465 psotfx
                                case PAGE_POSTING:
167 2465 psotfx
                                        $location = $lang['Posting_message'];
168 2465 psotfx
                                        $location_url = "index.$phpEx";
169 2465 psotfx
                                        break;
170 2465 psotfx
                                case PAGE_LOGIN:
171 2465 psotfx
                                        $location = $lang['Logging_on'];
172 2465 psotfx
                                        $location_url = "index.$phpEx";
173 2465 psotfx
                                        break;
174 2465 psotfx
                                case PAGE_SEARCH:
175 2465 psotfx
                                        $location = $lang['Searching_forums'];
176 2465 psotfx
                                        $location_url = "search.$phpEx";
177 2465 psotfx
                                        break;
178 2465 psotfx
                                case PAGE_PROFILE:
179 2465 psotfx
                                        $location = $lang['Viewing_profile'];
180 2465 psotfx
                                        $location_url = "index.$phpEx";
181 2465 psotfx
                                        break;
182 2465 psotfx
                                case PAGE_VIEWONLINE:
183 2465 psotfx
                                        $location = $lang['Viewing_online'];
184 2465 psotfx
                                        $location_url = "viewonline.$phpEx";
185 2465 psotfx
                                        break;
186 2465 psotfx
                                case PAGE_VIEWMEMBERS:
187 2465 psotfx
                                        $location = $lang['Viewing_member_list'];
188 2465 psotfx
                                        $location_url = "memberlist.$phpEx";
189 2465 psotfx
                                        break;
190 2465 psotfx
                                case PAGE_PRIVMSGS:
191 2465 psotfx
                                        $location = $lang['Viewing_priv_msgs'];
192 2465 psotfx
                                        $location_url = "privmsg.$phpEx";
193 2465 psotfx
                                        break;
194 2465 psotfx
                                case PAGE_FAQ:
195 2465 psotfx
                                        $location = $lang['Viewing_FAQ'];
196 2465 psotfx
                                        $location_url = "faq.$phpEx";
197 2465 psotfx
                                        break;
198 2465 psotfx
                                default:
199 2465 psotfx
                                        $location = $lang['Forum_index'];
200 2465 psotfx
                                        $location_url = "index.$phpEx";
201 146 psotfx
                        }
202 2465 psotfx
                }
203 2465 psotfx
                else
204 2465 psotfx
                {
205 2516 psotfx
                        $location_url = append_sid("viewforum.$phpEx?" . POST_FORUM_URL . '=' . $row['session_page']);
206 2516 psotfx
                        $location = $forum_data[$row['session_page']];
207 2465 psotfx
                }
208 146 psotfx
209 2465 psotfx
                $row_color = ( $$which_counter % 2 ) ? $theme['td_color1'] : $theme['td_color2'];
210 2465 psotfx
                $row_class = ( $$which_counter % 2 ) ? $theme['td_class1'] : $theme['td_class2'];
211 698 psotfx
212 2465 psotfx
                $template->assign_block_vars("$which_row", array(
213 2465 psotfx
                        'ROW_COLOR' => '#' . $row_color,
214 2465 psotfx
                        'ROW_CLASS' => $row_class,
215 2465 psotfx
                        'USERNAME' => $username,
216 2516 psotfx
                        'LASTUPDATE' => create_date($board_config['default_dateformat'], $row['session_time'], $board_config['board_timezone']),
217 2465 psotfx
                        'FORUM_LOCATION' => $location,
218 646 psotfx
219 2465 psotfx
                        'U_USER_PROFILE' => append_sid("profile.$phpEx?mode=viewprofile&amp;" . POST_USERS_URL . '=' . $user_id),
220 2465 psotfx
                        'U_FORUM_LOCATION' => append_sid($location_url))
221 2465 psotfx
                );
222 2137 psotfx
223 2465 psotfx
                $$which_counter++;
224 904 psotfx
        }
225 2465 psotfx
}
226 775 psotfx
227 2465 psotfx
if( $registered_users == 0 )
228 2465 psotfx
{
229 2465 psotfx
        $l_r_user_s = $lang['Reg_users_zero_online'];
230 2465 psotfx
}
231 2465 psotfx
else if( $registered_users == 1 )
232 2465 psotfx
{
233 2465 psotfx
        $l_r_user_s = $lang['Reg_user_online'];
234 2465 psotfx
}
235 2465 psotfx
else
236 2465 psotfx
{
237 2465 psotfx
        $l_r_user_s = $lang['Reg_users_online'];
238 2465 psotfx
}
239 2137 psotfx
240 2465 psotfx
if( $hidden_users == 0 )
241 2465 psotfx
{
242 2465 psotfx
        $l_h_user_s = $lang['Hidden_users_zero_online'];
243 2465 psotfx
}
244 2465 psotfx
else if( $hidden_users == 1 )
245 2465 psotfx
{
246 2465 psotfx
        $l_h_user_s = $lang['Hidden_user_online'];
247 2465 psotfx
}
248 2465 psotfx
else
249 2465 psotfx
{
250 2465 psotfx
        $l_h_user_s = $lang['Hidden_users_online'];
251 2465 psotfx
}
252 2137 psotfx
253 2465 psotfx
if( $guest_users == 0 )
254 2465 psotfx
{
255 2465 psotfx
        $l_g_user_s = $lang['Guest_users_zero_online'];
256 2465 psotfx
}
257 2465 psotfx
else if( $guest_users == 1 )
258 2465 psotfx
{
259 2465 psotfx
        $l_g_user_s = $lang['Guest_user_online'];
260 2465 psotfx
}
261 2465 psotfx
else
262 2465 psotfx
{
263 2465 psotfx
        $l_g_user_s = $lang['Guest_users_online'];
264 2465 psotfx
}
265 775 psotfx
266 2465 psotfx
$template->assign_vars(array(
267 2465 psotfx
        'TOTAL_REGISTERED_USERS_ONLINE' => sprintf($l_r_user_s, $registered_users) . sprintf($l_h_user_s, $hidden_users),
268 2465 psotfx
        'TOTAL_GUEST_USERS_ONLINE' => sprintf($l_g_user_s, $guest_users))
269 2465 psotfx
);
270 2465 psotfx
271 2465 psotfx
if ( $registered_users + $hidden_users == 0 )
272 2465 psotfx
{
273 2138 psotfx
        $template->assign_vars(array(
274 2465 psotfx
                'L_NO_REGISTERED_USERS_BROWSING' => $lang['No_users_browsing'])
275 2138 psotfx
        );
276 2465 psotfx
}
277 2138 psotfx
278 2465 psotfx
if ( $guest_users == 0 )
279 2465 psotfx
{
280 2465 psotfx
        $template->assign_vars(array(
281 2465 psotfx
                'L_NO_GUESTS_BROWSING' => $lang['No_users_browsing'])
282 2465 psotfx
        );
283 146 psotfx
}
284 146 psotfx
285 2448 psotfx
$template->pparse('body');
286 904 psotfx
287 646 psotfx
include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
288 146 psotfx
289 1277 psotfx
?>