phpBB
Statistics
| Revision:

root / trunk / phpBB / ucp.php

History | View | Annotate | Download (9.8 kB)

1 4950 psotfx
<?php
2 8146 acydburn
/**
3 5114 acydburn
*
4 5114 acydburn
* @package ucp
5 8146 acydburn
* @copyright (c) 2005 phpBB Group
6 11653 git-gate
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
7 5114 acydburn
*
8 5114 acydburn
*/
9 3075 thefinn
10 5114 acydburn
/**
11 5883 acydburn
* @ignore
12 5114 acydburn
*/
13 3075 thefinn
define('IN_PHPBB', true);
14 7954 acydburn
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
15 4473 psotfx
$phpEx = substr(strrchr(__FILE__, '.'), 1);
16 6015 acydburn
require($phpbb_root_path . 'common.' . $phpEx);
17 6015 acydburn
require($phpbb_root_path . 'includes/functions_user.' . $phpEx);
18 6015 acydburn
require($phpbb_root_path . 'includes/functions_module.' . $phpEx);
19 4906 acydburn
20 4950 psotfx
// Basic parameter data
21 5254 acydburn
$id         = request_var('i', '');
22 4950 psotfx
$mode        = request_var('mode', '');
23 4950 psotfx
24 10787 git-gate
if (in_array($mode, array('login', 'logout', 'confirm', 'sendpassword', 'activate')))
25 4906 acydburn
{
26 4906 acydburn
        define('IN_LOGIN', true);
27 4906 acydburn
}
28 3075 thefinn
29 4950 psotfx
// Start session management
30 5254 acydburn
$user->session_begin();
31 4950 psotfx
$auth->acl($user->data);
32 4950 psotfx
$user->setup('ucp');
33 4950 psotfx
34 6104 acydburn
// Setting a variable to let the style designer know where he is...
35 6104 acydburn
$template->assign_var('S_IN_UCP', true);
36 6104 acydburn
37 5254 acydburn
$module = new p_master();
38 8915 acydburn
$default = false;
39 4950 psotfx
40 4020 psotfx
// Basic "global" modes
41 4003 psotfx
switch ($mode)
42 4003 psotfx
{
43 4003 psotfx
        case 'activate':
44 5254 acydburn
                $module->load('ucp', 'activate');
45 5254 acydburn
                $module->display($user->lang['UCP_ACTIVATE']);
46 5790 acydburn
47 6015 acydburn
                redirect(append_sid("{$phpbb_root_path}index.$phpEx"));
48 5254 acydburn
        break;
49 5254 acydburn
50 5114 acydburn
        case 'resend_act':
51 5254 acydburn
                $module->load('ucp', 'resend');
52 5254 acydburn
                $module->display($user->lang['UCP_RESEND']);
53 5254 acydburn
        break;
54 5114 acydburn
55 4583 psotfx
        case 'sendpassword':
56 5254 acydburn
                $module->load('ucp', 'remind');
57 5254 acydburn
                $module->display($user->lang['UCP_REMIND']);
58 5254 acydburn
        break;
59 4020 psotfx
60 4003 psotfx
        case 'register':
61 5117 acydburn
                if ($user->data['is_registered'] || isset($_REQUEST['not_agreed']))
62 4003 psotfx
                {
63 6015 acydburn
                        redirect(append_sid("{$phpbb_root_path}index.$phpEx"));
64 4003 psotfx
                }
65 3650 psotfx
66 5254 acydburn
                $module->load('ucp', 'register');
67 5378 subblue
                $module->display($user->lang['REGISTER']);
68 5254 acydburn
        break;
69 3650 psotfx
70 4020 psotfx
        case 'confirm':
71 5254 acydburn
                $module->load('ucp', 'confirm');
72 5254 acydburn
        break;
73 5254 acydburn
74 4003 psotfx
        case 'login':
75 5117 acydburn
                if ($user->data['is_registered'])
76 4003 psotfx
                {
77 6015 acydburn
                        redirect(append_sid("{$phpbb_root_path}index.$phpEx"));
78 4003 psotfx
                }
79 3650 psotfx
80 6832 naderman
                login_box(request_var('redirect', "index.$phpEx"));
81 5494 acydburn
        break;
82 4003 psotfx
83 4003 psotfx
        case 'logout':
84 10801 git-gate
                if ($user->data['user_id'] != ANONYMOUS && $request->is_set('sid') && $request->variable('sid', '') === $user->session_id)
85 7593 acydburn
                {
86 7593 acydburn
                        $user->session_kill();
87 7593 acydburn
                        $user->session_begin();
88 7593 acydburn
                        $message = $user->lang['LOGOUT_REDIRECT'];
89 7593 acydburn
                }
90 7593 acydburn
                else
91 7593 acydburn
                {
92 7593 acydburn
                        $message = ($user->data['user_id'] == ANONYMOUS) ? $user->lang['LOGOUT_REDIRECT'] : $user->lang['LOGOUT_FAILED'];
93 7593 acydburn
                }
94 7593 acydburn
                meta_refresh(3, append_sid("{$phpbb_root_path}index.$phpEx"));
95 8655 acydburn
96 7593 acydburn
                $message = $message . '<br /><br />' . sprintf($user->lang['RETURN_INDEX'], '<a href="' . append_sid("{$phpbb_root_path}index.$phpEx") . '">', '</a> ');
97 7593 acydburn
                trigger_error($message);
98 7593 acydburn
99 5494 acydburn
        break;
100 4904 acydburn
101 5650 acydburn
        case 'terms':
102 5650 acydburn
        case 'privacy':
103 5650 acydburn
104 5650 acydburn
                $message = ($mode == 'terms') ? 'TERMS_OF_USE_CONTENT' : 'PRIVACY_POLICY';
105 5650 acydburn
                $title = ($mode == 'terms') ? 'TERMS_USE' : 'PRIVACY';
106 5650 acydburn
107 5650 acydburn
                if (empty($user->lang[$message]))
108 5650 acydburn
                {
109 5650 acydburn
                        if ($user->data['is_registered'])
110 5650 acydburn
                        {
111 6015 acydburn
                                redirect(append_sid("{$phpbb_root_path}index.$phpEx"));
112 5650 acydburn
                        }
113 6015 acydburn
114 5881 acydburn
                        login_box();
115 5650 acydburn
                }
116 5650 acydburn
117 5650 acydburn
                $template->set_filenames(array(
118 5650 acydburn
                        'body'                => 'ucp_agreement.html')
119 5650 acydburn
                );
120 5650 acydburn
121 6054 acydburn
                // Disable online list
122 6054 acydburn
                page_header($user->lang[$title], false);
123 5650 acydburn
124 5650 acydburn
                $template->assign_vars(array(
125 5650 acydburn
                        'S_AGREEMENT'                        => true,
126 5650 acydburn
                        'AGREEMENT_TITLE'                => $user->lang[$title],
127 5662 acydburn
                        'AGREEMENT_TEXT'                => sprintf($user->lang[$message], $config['sitename'], generate_board_url()),
128 6015 acydburn
                        'U_BACK'                                => append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=login'),
129 9668 acydburn
                        'L_BACK'                                => $user->lang['BACK_TO_LOGIN'],
130 9668 acydburn
                ));
131 6015 acydburn
132 5650 acydburn
                page_footer();
133 5650 acydburn
134 5494 acydburn
        break;
135 5114 acydburn
136 4904 acydburn
        case 'delete_cookies':
137 8655 acydburn
138 4904 acydburn
                // Delete Cookies with dynamic names (do NOT delete poll cookies)
139 4912 acydburn
                if (confirm_box(true))
140 4904 acydburn
                {
141 4912 acydburn
                        $set_time = time() - 31536000;
142 6015 acydburn
143 10801 git-gate
                        foreach ($request->variable_names(phpbb_request_interface::COOKIE) as $cookie_name)
144 4904 acydburn
                        {
145 10801 git-gate
                                $cookie_data = $request->variable($cookie_name, '', true, phpbb_request_interface::COOKIE);
146 10801 git-gate
147 10090 acydburn
                                // Only delete board cookies, no other ones...
148 10090 acydburn
                                if (strpos($cookie_name, $config['cookie_name'] . '_') !== 0)
149 10090 acydburn
                                {
150 10090 acydburn
                                        continue;
151 10090 acydburn
                                }
152 10090 acydburn
153 4912 acydburn
                                $cookie_name = str_replace($config['cookie_name'] . '_', '', $cookie_name);
154 6851 acydburn
155 6851 acydburn
                                // Polls are stored as {cookie_name}_poll_{topic_id}, cookie_name_ got removed, therefore checking for poll_
156 6851 acydburn
                                if (strpos($cookie_name, 'poll_') !== 0)
157 4912 acydburn
                                {
158 4912 acydburn
                                        $user->set_cookie($cookie_name, '', $set_time);
159 4912 acydburn
                                }
160 4904 acydburn
                        }
161 6015 acydburn
162 4912 acydburn
                        $user->set_cookie('track', '', $set_time);
163 5183 psotfx
                        $user->set_cookie('u', '', $set_time);
164 5183 psotfx
                        $user->set_cookie('k', '', $set_time);
165 4912 acydburn
                        $user->set_cookie('sid', '', $set_time);
166 4904 acydburn
167 4912 acydburn
                        // We destroy the session here, the user will be logged out nevertheless
168 5199 acydburn
                        $user->session_kill();
169 5429 subblue
                        $user->session_begin();
170 4904 acydburn
171 6015 acydburn
                        meta_refresh(3, append_sid("{$phpbb_root_path}index.$phpEx"));
172 4904 acydburn
173 6015 acydburn
                        $message = $user->lang['COOKIES_DELETED'] . '<br /><br />' . sprintf($user->lang['RETURN_INDEX'], '<a href="' . append_sid("{$phpbb_root_path}index.$phpEx") . '">', '</a>');
174 4912 acydburn
                        trigger_error($message);
175 4912 acydburn
                }
176 4912 acydburn
                else
177 4912 acydburn
                {
178 4912 acydburn
                        confirm_box(false, 'DELETE_COOKIES', '');
179 4912 acydburn
                }
180 5595 acydburn
181 6015 acydburn
                redirect(append_sid("{$phpbb_root_path}index.$phpEx"));
182 6015 acydburn
183 5494 acydburn
        break;
184 5790 acydburn
185 5790 acydburn
        case 'switch_perm':
186 5790 acydburn
187 5790 acydburn
                $user_id = request_var('u', 0);
188 5790 acydburn
189 5790 acydburn
                $sql = 'SELECT *
190 5790 acydburn
                        FROM ' . USERS_TABLE . '
191 5790 acydburn
                        WHERE user_id = ' . (int) $user_id;
192 5790 acydburn
                $result = $db->sql_query($sql);
193 5790 acydburn
                $user_row = $db->sql_fetchrow($result);
194 5790 acydburn
                $db->sql_freeresult($result);
195 5790 acydburn
196 9915 Kellanved
                if (!$auth->acl_get('a_switchperm') || !$user_row || $user_id == $user->data['user_id'] || !check_link_hash(request_var('hash', ''), 'switchperm'))
197 5790 acydburn
                {
198 6015 acydburn
                        redirect(append_sid("{$phpbb_root_path}index.$phpEx"));
199 5790 acydburn
                }
200 5790 acydburn
201 5790 acydburn
                include($phpbb_root_path . 'includes/acp/auth.' . $phpEx);
202 5790 acydburn
203 5790 acydburn
                $auth_admin = new auth_admin();
204 5790 acydburn
                if (!$auth_admin->ghost_permissions($user_id, $user->data['user_id']))
205 5790 acydburn
                {
206 6015 acydburn
                        redirect(append_sid("{$phpbb_root_path}index.$phpEx"));
207 5790 acydburn
                }
208 5790 acydburn
209 6015 acydburn
                add_log('admin', 'LOG_ACL_TRANSFER_PERMISSIONS', $user_row['username']);
210 5790 acydburn
211 6915 acydburn
                $message = sprintf($user->lang['PERMISSIONS_TRANSFERRED'], $user_row['username']) . '<br /><br />' . sprintf($user->lang['RETURN_INDEX'], '<a href="' . append_sid("{$phpbb_root_path}index.$phpEx") . '">', '</a>');
212 5790 acydburn
                trigger_error($message);
213 5790 acydburn
214 5790 acydburn
        break;
215 5790 acydburn
216 5790 acydburn
        case 'restore_perm':
217 5790 acydburn
218 5790 acydburn
                if (!$user->data['user_perm_from'] || !$auth->acl_get('a_switchperm'))
219 5790 acydburn
                {
220 6015 acydburn
                        redirect(append_sid("{$phpbb_root_path}index.$phpEx"));
221 5790 acydburn
                }
222 5790 acydburn
223 5790 acydburn
                $auth->acl_cache($user->data);
224 5790 acydburn
225 5790 acydburn
                $sql = 'SELECT username
226 5790 acydburn
                        FROM ' . USERS_TABLE . '
227 5790 acydburn
                        WHERE user_id = ' . $user->data['user_perm_from'];
228 5790 acydburn
                $result = $db->sql_query($sql);
229 5790 acydburn
                $username = $db->sql_fetchfield('username');
230 5790 acydburn
                $db->sql_freeresult($result);
231 5790 acydburn
232 5790 acydburn
                add_log('admin', 'LOG_ACL_RESTORE_PERMISSIONS', $username);
233 5790 acydburn
234 6015 acydburn
                $message = $user->lang['PERMISSIONS_RESTORED'] . '<br /><br />' . sprintf($user->lang['RETURN_INDEX'], '<a href="' . append_sid("{$phpbb_root_path}index.$phpEx") . '">', '</a>');
235 5790 acydburn
                trigger_error($message);
236 5790 acydburn
237 5790 acydburn
        break;
238 8915 acydburn
239 8915 acydburn
        default:
240 8915 acydburn
                $default = true;
241 8915 acydburn
        break;
242 3431 thefinn
}
243 3075 thefinn
244 8915 acydburn
// We use this approach because it does not impose large code changes
245 8915 acydburn
if (!$default)
246 8915 acydburn
{
247 8915 acydburn
        return true;
248 8915 acydburn
}
249 8915 acydburn
250 4003 psotfx
// Only registered users can go beyond this point
251 5117 acydburn
if (!$user->data['is_registered'])
252 4003 psotfx
{
253 5117 acydburn
        if ($user->data['is_bot'])
254 4903 acydburn
        {
255 6015 acydburn
                redirect(append_sid("{$phpbb_root_path}index.$phpEx"));
256 4903 acydburn
        }
257 4950 psotfx
258 11528 git-gate
        if ($id == 'pm' && $mode == 'view' && isset($_GET['p']))
259 11528 git-gate
        {
260 11528 git-gate
                $redirect_url = append_sid("{$phpbb_root_path}ucp.$phpEx?i=pm&p=" . request_var('p', 0));
261 11528 git-gate
                login_box($redirect_url, $user->lang['LOGIN_EXPLAIN_UCP']);
262 11528 git-gate
        }
263 11528 git-gate
264 4970 psotfx
        login_box('', $user->lang['LOGIN_EXPLAIN_UCP']);
265 4003 psotfx
}
266 3650 psotfx
267 7229 davidmj
// Instantiate module system and generate list of available modules
268 7229 davidmj
$module->list_modules('ucp');
269 3650 psotfx
270 7229 davidmj
// Check if the zebra module is set
271 7232 acydburn
if ($module->is_active('zebra', 'friends'))
272 7229 davidmj
{
273 7229 davidmj
        // Output listing of friends online
274 7229 davidmj
        $update_time = $config['load_online_time'] * 60;
275 5885 davidmj
276 11585 git-gate
        $sql_ary = array(
277 7829 kellanved
                'SELECT'        => 'u.user_id, u.username, u.username_clean, u.user_colour, MAX(s.session_time) as online_time, MIN(s.session_viewonline) AS viewonline',
278 5885 davidmj
279 7229 davidmj
                'FROM'                => array(
280 7229 davidmj
                        USERS_TABLE                => 'u',
281 11585 git-gate
                        ZEBRA_TABLE                => 'z',
282 7229 davidmj
                ),
283 5885 davidmj
284 7229 davidmj
                'LEFT_JOIN'        => array(
285 7229 davidmj
                        array(
286 7229 davidmj
                                'FROM'        => array(SESSIONS_TABLE => 's'),
287 11585 git-gate
                                'ON'        => 's.session_user_id = z.zebra_id',
288 11585 git-gate
                        ),
289 7229 davidmj
                ),
290 5885 davidmj
291 7229 davidmj
                'WHERE'                => 'z.user_id = ' . $user->data['user_id'] . '
292 7229 davidmj
                        AND z.friend = 1
293 7229 davidmj
                        AND u.user_id = z.zebra_id',
294 5957 acydburn
295 7828 kellanved
                'GROUP_BY'        => 'z.zebra_id, u.user_id, u.username_clean, u.user_colour, u.username',
296 5885 davidmj
297 7229 davidmj
                'ORDER_BY'        => 'u.username_clean ASC',
298 11585 git-gate
        );
299 3431 thefinn
300 11585 git-gate
        $sql = $db->sql_build_query('SELECT_DISTINCT', $sql_ary);
301 7229 davidmj
        $result = $db->sql_query($sql);
302 3996 psotfx
303 7229 davidmj
        while ($row = $db->sql_fetchrow($result))
304 7229 davidmj
        {
305 7828 kellanved
                $which = (time() - $update_time < $row['online_time'] && ($row['viewonline'] || $auth->acl_get('u_viewonline'))) ? 'online' : 'offline';
306 4950 psotfx
307 7229 davidmj
                $template->assign_block_vars("friends_{$which}", array(
308 7229 davidmj
                        'USER_ID'                => $row['user_id'],
309 7229 davidmj
310 7229 davidmj
                        'U_PROFILE'                => get_username_string('profile', $row['user_id'], $row['username'], $row['user_colour']),
311 7229 davidmj
                        'USER_COLOUR'        => get_username_string('colour', $row['user_id'], $row['username'], $row['user_colour']),
312 7229 davidmj
                        'USERNAME'                => get_username_string('username', $row['user_id'], $row['username'], $row['user_colour']),
313 7229 davidmj
                        'USERNAME_FULL'        => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']))
314 7229 davidmj
                );
315 7229 davidmj
        }
316 7229 davidmj
        $db->sql_freeresult($result);
317 3591 thefinn
}
318 3591 thefinn
319 7426 acydburn
// Do not display subscribed topics/forums if not allowed
320 7426 acydburn
if (!$config['allow_topic_notify'] && !$config['allow_forum_notify'])
321 7426 acydburn
{
322 7426 acydburn
        $module->set_display('main', 'subscribed', false);
323 7426 acydburn
}
324 7426 acydburn
325 11143 git-gate
// Do not display signature panel if not authed to do so
326 11143 git-gate
if (!$auth->acl_get('u_sig'))
327 11143 git-gate
{
328 11143 git-gate
        $module->set_display('profile', 'signature', false);
329 11143 git-gate
}
330 11143 git-gate
331 5254 acydburn
// Select the active module
332 5254 acydburn
$module->set_active($id, $mode);
333 5254 acydburn
334 4522 psotfx
// Load and execute the relevant module
335 5254 acydburn
$module->load_active();
336 4522 psotfx
337 5254 acydburn
// Assign data to the template engine for the list of modules
338 6015 acydburn
$module->assign_tpl_vars(append_sid("{$phpbb_root_path}ucp.$phpEx"));
339 5254 acydburn
340 6054 acydburn
// Generate the page, do not display/query online list
341 6054 acydburn
$module->display($module->get_page_title(), false);
342 5254 acydburn
343 5767 acydburn
/**
344 5767 acydburn
* Function for assigning a template var if the zebra module got included
345 5767 acydburn
*/
346 5767 acydburn
function _module_zebra($mode, &$module_row)
347 5767 acydburn
{
348 5767 acydburn
        global $template;
349 5767 acydburn
350 5767 acydburn
        $template->assign_var('S_ZEBRA_ENABLED', true);
351 7232 acydburn
352 7232 acydburn
        if ($mode == 'friends')
353 7232 acydburn
        {
354 7232 acydburn
                $template->assign_var('S_ZEBRA_FRIENDS_ENABLED', true);
355 7232 acydburn
        }
356 7232 acydburn
357 7232 acydburn
        if ($mode == 'foes')
358 7232 acydburn
        {
359 7232 acydburn
                $template->assign_var('S_ZEBRA_FOES_ENABLED', true);
360 7232 acydburn
        }
361 5767 acydburn
}